blob: 2ce08e5ca44dab7113101f4a6e6ea06384ad30aa [file] [log] [blame]
Bram Moolenaar1aeaf8c2012-05-18 13:46:39 +02001" Vim filetype plugin file
2" Language: Zimbu
Christian Brabandte978b452023-08-13 10:33:05 +02003" Maintainer: The Vim Project <https://github.com/vim/vim>
4" Last Change: 2023 Aug 10
5" Former Maintainer: Bram Moolenaar <Bram@vim.org>
Bram Moolenaar1aeaf8c2012-05-18 13:46:39 +02006
7" Only do this when not done yet for this buffer
8if exists("b:did_ftplugin")
9 finish
10endif
11
12" Don't load another plugin for this buffer
13let b:did_ftplugin = 1
14
15" Using line continuation here.
16let s:cpo_save = &cpo
17set cpo-=C
18
Bram Moolenaar8e52a592012-05-18 21:49:28 +020019let b:undo_ftplugin = "setl fo< com< ofu< efm< tw< et< sts< sw< | if has('vms') | setl isk< | endif"
Bram Moolenaar1aeaf8c2012-05-18 13:46:39 +020020
21" Set 'formatoptions' to break comment lines but not other lines,
22" and insert the comment leader when hitting <CR> or using "o".
23setlocal fo-=t fo+=croql
24
25" Set completion with CTRL-X CTRL-O to autoloaded function.
26if exists('&ofu')
27 setlocal ofu=ccomplete#Complete
28endif
29
30" Set 'comments' to format dashed lists in comments.
31" And to keep Zudocu comment characters.
Bram Moolenaar71b6d332022-09-10 13:13:14 +010032setlocal comments=sO:#\ -,mO:#\ \ ,exO:#/,s:/*,m:\ ,ex:*/,:#=,:#-,:#%,:#
Bram Moolenaar1aeaf8c2012-05-18 13:46:39 +020033
34setlocal errorformat^=%f\ line\ %l\ col\ %c:\ %m,ERROR:\ %m
35
36" When the matchit plugin is loaded, this makes the % command skip parens and
37" braces in comments.
Bram Moolenaar519cc552021-11-16 19:18:26 +000038if exists("loaded_matchit") && !exists("b:match_words")
39 let b:match_words = '\(^\s*\)\@<=\(MODULE\|CLASS\|INTERFACE\|BITS\|ENUM\|SHARED\|FUNC\|REPLACE\|DEFINE\|PROC\|EQUAL\|MAIN\|IF\|GENERATE_IF\|WHILE\|REPEAT\|WITH\|DO\|FOR\|SWITCH\|TRY\)\>\|{\s*$:\(^\s*\)\@<=\(ELSE\|ELSEIF\|GENERATE_ELSE\|GENERATE_ELSEIF\|CATCH\|FINALLY\)\>:\(^\s*\)\@<=\(}\|\<UNTIL\>\)'
40 let b:match_skip = 's:comment\|string\|zimbuchar'
41 let b:undo_ftplugin ..= " | unlet! b:match_words b:match_skip"
42endif
Bram Moolenaar1aeaf8c2012-05-18 13:46:39 +020043
44setlocal tw=78
45setlocal et sts=2 sw=2
46
47" Does replace when a dot, space or closing brace is typed.
48func! GCUpperDot(what)
Bram Moolenaard09acef2012-09-21 14:54:30 +020049 if v:char != ' ' && v:char != "\r" && v:char != "\x1b" && v:char != '.' && v:char != ')' && v:char != '}' && v:char != ','
Bram Moolenaar1aeaf8c2012-05-18 13:46:39 +020050 " no space or dot after the typed text
51 let g:got_char = v:char
52 return a:what
53 endif
Bram Moolenaard09acef2012-09-21 14:54:30 +020054 return GCUpperCommon(a:what)
55endfunc
56
57" Does not replace when a dot is typed.
58func! GCUpper(what)
59 if v:char != ' ' && v:char != "\r" && v:char != "\x1b" && v:char != ')' && v:char != ','
60 " no space or other "terminating" character after the typed text
61 let g:got_char = v:char
62 return a:what
63 endif
64 return GCUpperCommon(a:what)
65endfunc
66
67" Only replaces when a space is typed.
68func! GCUpperSpace(what)
69 if v:char != ' '
70 " no space after the typed text
71 let g:got_char = v:char
72 return a:what
73 endif
74 return GCUpperCommon(a:what)
75endfunc
76
77func! GCUpperCommon(what)
78 let col = col(".") - strlen(a:what)
Bram Moolenaar1aeaf8c2012-05-18 13:46:39 +020079 if col > 1 && getline('.')[col - 2] != ' '
80 " no space before the typed text
81 let g:got_char = 999
82 return a:what
83 endif
84 let synName = synIDattr(synID(line("."), col(".") - 2, 1), "name")
85 if synName =~ 'Comment\|String\|zimbuCregion\|\<c'
86 " inside a comment or C code
87 let g:got_char = 777
88 return a:what
89 endif
90 let g:got_char = 1111
91 return toupper(a:what)
92endfunc
93
Bram Moolenaar1aeaf8c2012-05-18 13:46:39 +020094iabbr <buffer> <expr> alias GCUpperSpace("alias")
95iabbr <buffer> <expr> arg GCUpperDot("arg")
Bram Moolenaar1aeaf8c2012-05-18 13:46:39 +020096iabbr <buffer> <expr> break GCUpper("break")
97iabbr <buffer> <expr> case GCUpperSpace("case")
98iabbr <buffer> <expr> catch GCUpperSpace("catch")
99iabbr <buffer> <expr> check GCUpperDot("check")
100iabbr <buffer> <expr> class GCUpperSpace("class")
Bram Moolenaard09acef2012-09-21 14:54:30 +0200101iabbr <buffer> <expr> interface GCUpperSpace("interface")
102iabbr <buffer> <expr> implements GCUpperSpace("implements")
Bram Moolenaar1aeaf8c2012-05-18 13:46:39 +0200103iabbr <buffer> <expr> shared GCUpperSpace("shared")
104iabbr <buffer> <expr> continue GCUpper("continue")
105iabbr <buffer> <expr> default GCUpper("default")
106iabbr <buffer> <expr> extends GCUpper("extends")
107iabbr <buffer> <expr> do GCUpper("do")
108iabbr <buffer> <expr> else GCUpper("else")
109iabbr <buffer> <expr> elseif GCUpperSpace("elseif")
110iabbr <buffer> <expr> enum GCUpperSpace("enum")
111iabbr <buffer> <expr> exit GCUpper("exit")
112iabbr <buffer> <expr> false GCUpper("false")
113iabbr <buffer> <expr> fail GCUpper("fail")
114iabbr <buffer> <expr> finally GCUpper("finally")
115iabbr <buffer> <expr> for GCUpperSpace("for")
116iabbr <buffer> <expr> func GCUpperSpace("func")
117iabbr <buffer> <expr> if GCUpperSpace("if")
118iabbr <buffer> <expr> import GCUpperSpace("import")
119iabbr <buffer> <expr> in GCUpperSpace("in")
120iabbr <buffer> <expr> io GCUpperDot("io")
121iabbr <buffer> <expr> main GCUpper("main")
122iabbr <buffer> <expr> module GCUpperSpace("module")
123iabbr <buffer> <expr> new GCUpper("new")
124iabbr <buffer> <expr> nil GCUpper("nil")
125iabbr <buffer> <expr> ok GCUpper("ok")
126iabbr <buffer> <expr> proc GCUpperSpace("proc")
127iabbr <buffer> <expr> proceed GCUpper("proceed")
128iabbr <buffer> <expr> return GCUpper("return")
129iabbr <buffer> <expr> step GCUpperSpace("step")
130iabbr <buffer> <expr> switch GCUpperSpace("switch")
131iabbr <buffer> <expr> sys GCUpperDot("sys")
132iabbr <buffer> <expr> this GCUpperDot("this")
133iabbr <buffer> <expr> throw GCUpperSpace("throw")
134iabbr <buffer> <expr> try GCUpper("try")
135iabbr <buffer> <expr> to GCUpperSpace("to")
136iabbr <buffer> <expr> true GCUpper("true")
137iabbr <buffer> <expr> until GCUpperSpace("until")
138iabbr <buffer> <expr> while GCUpperSpace("while")
139iabbr <buffer> <expr> repeat GCUpper("repeat")
140
Bram Moolenaar519cc552021-11-16 19:18:26 +0000141let b:undo_ftplugin ..=
142 \ " | iunabbr <buffer> alias" ..
143 \ " | iunabbr <buffer> arg" ..
144 \ " | iunabbr <buffer> break" ..
145 \ " | iunabbr <buffer> case" ..
146 \ " | iunabbr <buffer> catch" ..
147 \ " | iunabbr <buffer> check" ..
148 \ " | iunabbr <buffer> class" ..
149 \ " | iunabbr <buffer> interface" ..
150 \ " | iunabbr <buffer> implements" ..
151 \ " | iunabbr <buffer> shared" ..
152 \ " | iunabbr <buffer> continue" ..
153 \ " | iunabbr <buffer> default" ..
154 \ " | iunabbr <buffer> extends" ..
155 \ " | iunabbr <buffer> do" ..
156 \ " | iunabbr <buffer> else" ..
157 \ " | iunabbr <buffer> elseif" ..
158 \ " | iunabbr <buffer> enum" ..
159 \ " | iunabbr <buffer> exit" ..
160 \ " | iunabbr <buffer> false" ..
161 \ " | iunabbr <buffer> fail" ..
162 \ " | iunabbr <buffer> finally" ..
163 \ " | iunabbr <buffer> for" ..
164 \ " | iunabbr <buffer> func" ..
165 \ " | iunabbr <buffer> if" ..
166 \ " | iunabbr <buffer> import" ..
167 \ " | iunabbr <buffer> in" ..
168 \ " | iunabbr <buffer> io" ..
169 \ " | iunabbr <buffer> main" ..
170 \ " | iunabbr <buffer> module" ..
171 \ " | iunabbr <buffer> new" ..
172 \ " | iunabbr <buffer> nil" ..
173 \ " | iunabbr <buffer> ok" ..
174 \ " | iunabbr <buffer> proc" ..
175 \ " | iunabbr <buffer> proceed" ..
176 \ " | iunabbr <buffer> return" ..
177 \ " | iunabbr <buffer> step" ..
178 \ " | iunabbr <buffer> switch" ..
179 \ " | iunabbr <buffer> sys" ..
180 \ " | iunabbr <buffer> this" ..
181 \ " | iunabbr <buffer> throw" ..
182 \ " | iunabbr <buffer> try" ..
183 \ " | iunabbr <buffer> to" ..
184 \ " | iunabbr <buffer> true" ..
185 \ " | iunabbr <buffer> until" ..
186 \ " | iunabbr <buffer> while" ..
187 \ " | iunabbr <buffer> repeat"
188
Bram Moolenaarf0b03c42017-12-17 17:17:07 +0100189if !exists("no_plugin_maps") && !exists("no_zimbu_maps")
190 nnoremap <silent> <buffer> [[ m`:call ZimbuGoStartBlock()<CR>
191 nnoremap <silent> <buffer> ]] m`:call ZimbuGoEndBlock()<CR>
Bram Moolenaar519cc552021-11-16 19:18:26 +0000192 let b:undo_ftplugin ..=
193 \ " | silent! exe 'nunmap <buffer> [['" ..
194 \ " | silent! exe 'nunmap <buffer> ]]'"
Bram Moolenaarf0b03c42017-12-17 17:17:07 +0100195endif
Bram Moolenaar1aeaf8c2012-05-18 13:46:39 +0200196
197" Using a function makes sure the search pattern is restored
198func! ZimbuGoStartBlock()
199 ?^\s*\(FUNC\|PROC\|MAIN\|ENUM\|CLASS\|INTERFACE\)\>
200endfunc
201func! ZimbuGoEndBlock()
202 /^\s*\(FUNC\|PROC\|MAIN\|ENUM\|CLASS\|INTERFACE\)\>
203endfunc
204
205
206let &cpo = s:cpo_save
207unlet s:cpo_save