mirror of
https://git.sfja.dk/Mikkel/slige.git
synced 2025-01-18 13:06:30 +00:00
24 lines
885 B
VimL
24 lines
885 B
VimL
setlocal indentexpr=SligeIndent()
|
|
|
|
function! SligeIndent()
|
|
let line = getline(v:lnum)
|
|
let previousNum = prevnonblank(v:lnum - 1)
|
|
let previous = getline(previousNum)
|
|
|
|
if previous =~ "(" && previous !~ ")" && (line !~ ")" || line !~ "%)")
|
|
return indent(previousNum) + &shiftwidth
|
|
elseif (line =~ ")" || line =~ "%)") && line !~ "("
|
|
return indent(previousNum) - &shiftwidth
|
|
elif previous =~ "{" && previous !~ "}" && (line !~ "}" || line !~ "%}")
|
|
return indent(previousNum) + &shiftwidth
|
|
elseif (line =~ "}" || line =~ "%}") && line !~ "{"
|
|
return indent(previousNum) - &shiftwidth
|
|
elif previous =~ "[" && previous !~ "]" && (line !~ "]" || line !~ "%]")
|
|
return indent(previousNum) + &shiftwidth
|
|
elseif (line =~ "]" || line =~ "%]") && line !~ "["
|
|
return indent(previousNum) - &shiftwidth
|
|
else
|
|
return indent(previousNum)
|
|
endif
|
|
endfunction
|