blob: d7f82b118fb30b91b70e16c134ea329a09455c90 [file] [log] [blame]
Peter Benjamin72755b32025-01-20 21:56:41 +01001" 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.
8if exists("b:did_indent")
9 finish
10endif
11let b:did_indent = 1
12
13setlocal indentexpr=GetJustfileIndent()
14setlocal indentkeys=0},0),!^F,o,O,0=''',0=\"\"\"
15
16let b:undo_indent = "setlocal indentexpr< indentkeys<"
17
18if exists("*GetJustfileIndent")
19 finish
20endif
21
22function 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
51endfunction