vim-nomsu/indent/nomsu.vim

43 lines
940 B
VimL
Raw Permalink Normal View History

2017-09-12 23:00:42 -07:00
" Language: Nomsu
" Maintainer: Bruce Hill <bruce@bruce-hill.com>
" License: WTFPL
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
setlocal autoindent
setlocal indentexpr=GetNomsuIndent()
2019-04-06 13:20:57 -07:00
setlocal indentkeys+=0],0),1),1.
2017-09-12 23:00:42 -07:00
" Only define the function once.
if exists("*GetNomsuIndent")
finish
endif
function! GetNomsuIndent()
let line = getline(v:lnum)
let current_ind = indent(v:lnum)
let previousNum = prevnonblank(v:lnum - 1)
let previous = getline(previousNum)
let ind = indent(previousNum)
" TODO: don't auto-indent inside a multi-line comment?
if previous =~ '\%([{[(:]\|("\)$' && previous !~ '^\s*#'
2017-09-12 23:00:42 -07:00
let ind += &tabstop
endif
" TODO: dedent to matching parens, don't just dedent once
2019-04-06 13:20:57 -07:00
if line =~ '^\s*\%([\])}]\|")\|\.\.\)'
"let ind -= &tabstop
return current_ind - &tabstop
2017-09-12 23:00:42 -07:00
endif
if ind == indent(previousNum)
return current_ind
endif
return ind
endfunction