code / vim-nomsu

Lines141 vim script136 Markdown5
(42 lines)
1 " Language: Nomsu
2 " Maintainer: Bruce Hill <bruce@bruce-hill.com>
3 " License: WTFPL
5 if exists("b:did_indent")
6 finish
7 endif
9 let b:did_indent = 1
11 setlocal autoindent
12 setlocal indentexpr=GetNomsuIndent()
13 setlocal indentkeys+=0],0),1),1.
15 " Only define the function once.
16 if exists("*GetNomsuIndent")
17 finish
18 endif
20 function! GetNomsuIndent()
21 let line = getline(v:lnum)
22 let current_ind = indent(v:lnum)
23 let previousNum = prevnonblank(v:lnum - 1)
24 let previous = getline(previousNum)
25 let ind = indent(previousNum)
27 " TODO: don't auto-indent inside a multi-line comment?
28 if previous =~ '\%([{[(:]\|("\)$' && previous !~ '^\s*#'
29 let ind += &tabstop
30 endif
32 " TODO: dedent to matching parens, don't just dedent once
33 if line =~ '^\s*\%([\])}]\|")\|\.\.\)'
34 "let ind -= &tabstop
35 return current_ind - &tabstop
36 endif
38 if ind == indent(previousNum)
39 return current_ind
40 endif
41 return ind
42 endfunction