vim

Fork of vim, an acceptable text editor
git clone git://git.laack.co/vim.git
Log | Files | Refs | README | LICENSE

just.vim (1381B)


      1 " Vim indent file
      2 " Language:	Justfile
      3 " Maintainer:	Peter Benjamin <@pbnj>
      4 " Last Change:	2025 Jan 19
      5 " Credits:	The original author, Noah Bogart <https://github.com/NoahTheDuke/vim-just/>
      6 
      7 " Only load this indent file when no other was loaded yet.
      8 if exists("b:did_indent")
      9   finish
     10 endif
     11 let b:did_indent = 1
     12 
     13 setlocal indentexpr=GetJustfileIndent()
     14 setlocal indentkeys=0},0),!^F,o,O,0=''',0=\"\"\"
     15 
     16 let b:undo_indent = "setlocal indentexpr< indentkeys<"
     17 
     18 if exists("*GetJustfileIndent")
     19   finish
     20 endif
     21 
     22 function GetJustfileIndent()
     23   if v:lnum < 2
     24     return 0
     25   endif
     26 
     27   let prev_line = getline(v:lnum - 1)
     28   let last_indent = indent(v:lnum - 1)
     29 
     30   if getline(v:lnum) =~ "\\v^\\s+%([})]|'''$|\"\"\"$)"
     31     return last_indent - shiftwidth()
     32   elseif prev_line =~ '\V#'
     33     return last_indent
     34   elseif prev_line =~ "\\v%([:{(]|^.*\\S.*%([^']'''|[^\"]\"\"\"))\\s*$"
     35     return last_indent + shiftwidth()
     36   elseif prev_line =~ '\\$'
     37     if v:lnum == 2 || getline(v:lnum - 2) !~ '\\$'
     38       if prev_line =~ '\v:\=@!'
     39         return last_indent + shiftwidth() + shiftwidth()
     40       else
     41         return last_indent + shiftwidth()
     42       endif
     43     endif
     44   elseif v:lnum > 2 && getline(v:lnum - 2) =~ '\\$'
     45     return last_indent - shiftwidth()
     46   elseif prev_line =~ '\v:\s*%(\h|\()' && prev_line !~ '\V:='
     47     return last_indent + shiftwidth()
     48   endif
     49 
     50   return last_indent
     51 endfunction