slige/editors/vim/indent/slige.vim

24 lines
885 B
VimL
Raw Normal View History

2024-12-12 12:35:05 +00:00
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