3 " Maintainer: Bram Moolenaar <Bram@vim.org>
4 " Last Change: 2012 Sep 08
6 " Only load this indent file when no other was loaded.
7 if exists("b:did_indent")
12 setlocal ai nolisp nocin
13 setlocal indentexpr=GetZimbuIndent(v:lnum)
14 setlocal indentkeys=0{,0},!^F,o,O,0=ELSE,0=ELSEIF,0=CASE,0=DEFAULT,0=FINALLY
16 " We impose recommended defaults: no Tabs, 'shiftwidth' = 2
19 let b:undo_indent = "setl et< sw< ai< indentkeys< indentexpr="
21 " Only define the function once.
22 if exists("*GetZimbuIndent")
29 " Come here when loading the script the first time.
31 let s:maxoff = 50 " maximum number of lines to look backwards for ()
33 func GetZimbuIndent(lnum)
34 let prevLnum = prevnonblank(a:lnum - 1)
36 " This is the first non-empty line, use zero indent.
40 " Taken from Python indenting:
41 " If the previous line is inside parenthesis, use the indent of the starting
43 " Trick: use the non-existing "dummy" variable to break out of the loop when
45 call cursor(prevLnum, 1)
46 let parlnum = searchpair('(\|{\|\[', '', ')\|}\|\]', 'nbW',
47 \ "line('.') < " . (prevLnum - s:maxoff) . " ? dummy :"
48 \ . " synIDattr(synID(line('.'), col('.'), 1), 'name')"
49 \ . " =~ '\\(Comment\\|String\\|Char\\)$'")
51 let plindent = indent(parlnum)
52 let plnumstart = parlnum
54 let plindent = indent(prevLnum)
55 let plnumstart = prevLnum
59 " When inside parenthesis: If at the first line below the parenthesis add
60 " two 'shiftwidth', otherwise same as previous line.
64 call cursor(a:lnum, 1)
65 let p = searchpair('(\|{\|\[', '', ')\|}\|\]', 'bW',
66 \ "line('.') < " . (a:lnum - s:maxoff) . " ? dummy :"
67 \ . " synIDattr(synID(line('.'), col('.'), 1), 'name')"
68 \ . " =~ '\\(Comment\\|String\\|Char\\)$'")
71 " When the start is inside parenthesis, only indent one 'shiftwidth'.
72 let pp = searchpair('(\|{\|\[', '', ')\|}\|\]', 'bW',
73 \ "line('.') < " . (a:lnum - s:maxoff) . " ? dummy :"
74 \ . " synIDattr(synID(line('.'), col('.'), 1), 'name')"
75 \ . " =~ '\\(Comment\\|String\\|Char\\)$'")
77 return indent(prevLnum) + &sw
79 return indent(prevLnum) + &sw * 2
82 return indent(prevLnum)
87 let prevline = getline(prevLnum)
88 let thisline = getline(a:lnum)
90 " If this line is not a comment and the previous one is then move the
91 " previous line further back.
92 if thisline !~ '^\s*#'
93 while prevline =~ '^\s*#'
94 let prevLnum = prevnonblank(prevLnum - 1)
96 " Only comment lines before this, no indent
99 let prevline = getline(prevLnum)
100 let plindent = indent(prevLnum)
104 if prevline =~ '^\s*\(IF\|\|ELSEIF\|ELSE\|GENERATE_IF\|\|GENERATE_ELSEIF\|GENERATE_ELSE\|WHILE\|REPEAT\|TRY\|CATCH\|FINALLY\|FOR\|DO\|SWITCH\|CASE\|DEFAULT\|FUNC\|VIRTUAL\|ABSTRACT\|DEFINE\|REPLACE\|FINAL\|PROC\|MAIN\|NEW\|ENUM\|CLASS\|INTERFACE\|BITS\|MODULE\|SHARED\)\>'
107 if thisline =~ '^\s*\(}\|ELSEIF\>\|ELSE\>\|CATCH\|FINALLY\|GENERATE_ELSEIF\>\|GENERATE_ELSE\>\|UNTIL\>\)'
110 if thisline =~ '^\s*\(CASE\>\|DEFAULT\>\)' && prevline !~ '^\s*SWITCH\>'
114 " line up continued comment that started after some code
115 " String something # comment comment
117 if a:lnum == prevLnum + 1 && thisline =~ '^\s*#' && prevline !~ '^\s*#'
118 let n = match(prevline, '#')
127 let &cpo = s:cpo_save