annotate runtime/indent/zimbu.vim @ 18486:9d887cad7315

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