comparison runtime/indent/zimbu.vim @ 3513:1b584a6f446c

Updated runtime files.
author Bram Moolenaar <bram@vim.org>
date Fri, 18 May 2012 13:46:39 +0200
parents
children dd6c2497c997
comparison
equal deleted inserted replaced
3512:5ad05e745fda 3513:1b584a6f446c
1 " Vim indent file
2 " Language: Zimbu
3 " Maintainer: Bram Moolenaar <Bram@vim.org>
4 " Last Change: 2012 May 17
5
6 " Only load this indent file when no other was loaded.
7 if exists("b:did_indent")
8 finish
9 endif
10 let b:did_indent = 1
11
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
15
16 " We impose recommended defaults: no Tabs, 'shiftwidth' = 2
17 setlocal sw=2 et
18
19 let b:undo_indent = "setl et< ai< indentexpr="
20
21 " Only define the function once.
22 if exists("*GetZimbuIndent")
23 finish
24 endif
25
26 " Come here when loading the script the first time.
27
28 let s:maxoff = 50 " maximum number of lines to look backwards for ()
29
30 func GetZimbuIndent(lnum)
31 let prevLnum = prevnonblank(a:lnum - 1)
32 if prevLnum == 0
33 " This is the first non-empty line, use zero indent.
34 return 0
35 endif
36
37 " Taken from Python indenting:
38 " If the previous line is inside parenthesis, use the indent of the starting
39 " line.
40 " Trick: use the non-existing "dummy" variable to break out of the loop when
41 " going too far back.
42 call cursor(prevLnum, 1)
43 let parlnum = searchpair('(\|{\|\[', '', ')\|}\|\]', 'nbW',
44 \ "line('.') < " . (prevLnum - s:maxoff) . " ? dummy :"
45 \ . " synIDattr(synID(line('.'), col('.'), 1), 'name')"
46 \ . " =~ '\\(Comment\\|String\\|Char\\)$'")
47 if parlnum > 0
48 let plindent = indent(parlnum)
49 let plnumstart = parlnum
50 else
51 let plindent = indent(prevLnum)
52 let plnumstart = prevLnum
53 endif
54
55
56 " When inside parenthesis: If at the first line below the parenthesis add
57 " two 'shiftwidth', otherwise same as previous line.
58 " i = (a
59 " + b
60 " + c)
61 call cursor(a:lnum, 1)
62 let p = searchpair('(\|{\|\[', '', ')\|}\|\]', 'bW',
63 \ "line('.') < " . (a:lnum - s:maxoff) . " ? dummy :"
64 \ . " synIDattr(synID(line('.'), col('.'), 1), 'name')"
65 \ . " =~ '\\(Comment\\|String\\|Char\\)$'")
66 if p > 0
67 if p == prevLnum
68 " When the start is inside parenthesis, only indent one 'shiftwidth'.
69 let pp = searchpair('(\|{\|\[', '', ')\|}\|\]', 'bW',
70 \ "line('.') < " . (a:lnum - s:maxoff) . " ? dummy :"
71 \ . " synIDattr(synID(line('.'), col('.'), 1), 'name')"
72 \ . " =~ '\\(Comment\\|String\\|Char\\)$'")
73 if pp > 0
74 return indent(prevLnum) + &sw
75 endif
76 return indent(prevLnum) + &sw * 2
77 endif
78 if plnumstart == p
79 return indent(prevLnum)
80 endif
81 return plindent
82 endif
83
84 let prevline = getline(prevLnum)
85 let thisline = getline(a:lnum)
86
87 " If this line is not a comment and the previous one is then move the
88 " previous line further back.
89 if thisline !~ '^\s*#'
90 while prevline =~ '^\s*#'
91 let prevLnum = prevnonblank(prevLnum - 1)
92 if prevLnum == 0
93 " Only comment lines before this, no indent
94 return 0
95 endif
96 let prevline = getline(prevLnum)
97 let plindent = indent(prevLnum)
98 endwhile
99 endif
100
101 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\|BITS\|MODULE\|SHARED\)\>'
102 let plindent += &sw
103 endif
104 if thisline =~ '^\s*\(}\|ELSEIF\>\|ELSE\>\|CATCH\|FINALLY\|GENERATE_ELSEIF\>\|GENERATE_ELSE\>\|UNTIL\>\)'
105 let plindent -= &sw
106 endif
107 if thisline =~ '^\s*\(CASE\>\|DEFAULT\>\)' && prevline !~ '^\s*SWITCH\>'
108 let plindent -= &sw
109 endif
110
111 " line up continued comment that started after some code
112 " String something # comment comment
113 " # comment
114 if a:lnum == prevLnum + 1 && thisline =~ '^\s*#' && prevline !~ '^\s*#'
115 let n = match(prevline, '#')
116 if n > 1
117 let plindent = n
118 endif
119 endif
120
121 return plindent
122 endfunc
123