blob: 9d9fa6f40691dc3cf055ed6ff8b54834ba48f7fa [file] [log] [blame]
Bram Moolenaar1aeaf8c2012-05-18 13:46:39 +02001" Vim filetype plugin file
2" Language: Zimbu
3" Maintainer: Bram Moolenaar <Bram@vim.org>
Bram Moolenaar71b6d332022-09-10 13:13:14 +01004" Last Change: 2022 Sep 07
Bram Moolenaar1aeaf8c2012-05-18 13:46:39 +02005
6" Only do this when not done yet for this buffer
7if exists("b:did_ftplugin")
8 finish
9endif
10
11" Don't load another plugin for this buffer
12let b:did_ftplugin = 1
13
14" Using line continuation here.
15let s:cpo_save = &cpo
16set cpo-=C
17
Bram Moolenaar8e52a592012-05-18 21:49:28 +020018let 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 +020019
20" Set 'formatoptions' to break comment lines but not other lines,
21" and insert the comment leader when hitting <CR> or using "o".
22setlocal fo-=t fo+=croql
23
24" Set completion with CTRL-X CTRL-O to autoloaded function.
25if exists('&ofu')
26 setlocal ofu=ccomplete#Complete
27endif
28
29" Set 'comments' to format dashed lists in comments.
30" And to keep Zudocu comment characters.
Bram Moolenaar71b6d332022-09-10 13:13:14 +010031setlocal comments=sO:#\ -,mO:#\ \ ,exO:#/,s:/*,m:\ ,ex:*/,:#=,:#-,:#%,:#
Bram Moolenaar1aeaf8c2012-05-18 13:46:39 +020032
33setlocal errorformat^=%f\ line\ %l\ col\ %c:\ %m,ERROR:\ %m
34
35" When the matchit plugin is loaded, this makes the % command skip parens and
36" braces in comments.
Bram Moolenaar519cc552021-11-16 19:18:26 +000037if exists("loaded_matchit") && !exists("b:match_words")
38 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\>\)'
39 let b:match_skip = 's:comment\|string\|zimbuchar'
40 let b:undo_ftplugin ..= " | unlet! b:match_words b:match_skip"
41endif
Bram Moolenaar1aeaf8c2012-05-18 13:46:39 +020042
43setlocal tw=78
44setlocal et sts=2 sw=2
45
46" Does replace when a dot, space or closing brace is typed.
47func! GCUpperDot(what)
Bram Moolenaard09acef2012-09-21 14:54:30 +020048 if v:char != ' ' && v:char != "\r" && v:char != "\x1b" && v:char != '.' && v:char != ')' && v:char != '}' && v:char != ','
Bram Moolenaar1aeaf8c2012-05-18 13:46:39 +020049 " no space or dot after the typed text
50 let g:got_char = v:char
51 return a:what
52 endif
Bram Moolenaard09acef2012-09-21 14:54:30 +020053 return GCUpperCommon(a:what)
54endfunc
55
56" Does not replace when a dot is typed.
57func! GCUpper(what)
58 if v:char != ' ' && v:char != "\r" && v:char != "\x1b" && v:char != ')' && v:char != ','
59 " no space or other "terminating" character after the typed text
60 let g:got_char = v:char
61 return a:what
62 endif
63 return GCUpperCommon(a:what)
64endfunc
65
66" Only replaces when a space is typed.
67func! GCUpperSpace(what)
68 if v:char != ' '
69 " no space after the typed text
70 let g:got_char = v:char
71 return a:what
72 endif
73 return GCUpperCommon(a:what)
74endfunc
75
76func! GCUpperCommon(what)
77 let col = col(".") - strlen(a:what)
Bram Moolenaar1aeaf8c2012-05-18 13:46:39 +020078 if col > 1 && getline('.')[col - 2] != ' '
79 " no space before the typed text
80 let g:got_char = 999
81 return a:what
82 endif
83 let synName = synIDattr(synID(line("."), col(".") - 2, 1), "name")
84 if synName =~ 'Comment\|String\|zimbuCregion\|\<c'
85 " inside a comment or C code
86 let g:got_char = 777
87 return a:what
88 endif
89 let g:got_char = 1111
90 return toupper(a:what)
91endfunc
92
Bram Moolenaar1aeaf8c2012-05-18 13:46:39 +020093iabbr <buffer> <expr> alias GCUpperSpace("alias")
94iabbr <buffer> <expr> arg GCUpperDot("arg")
Bram Moolenaar1aeaf8c2012-05-18 13:46:39 +020095iabbr <buffer> <expr> break GCUpper("break")
96iabbr <buffer> <expr> case GCUpperSpace("case")
97iabbr <buffer> <expr> catch GCUpperSpace("catch")
98iabbr <buffer> <expr> check GCUpperDot("check")
99iabbr <buffer> <expr> class GCUpperSpace("class")
Bram Moolenaard09acef2012-09-21 14:54:30 +0200100iabbr <buffer> <expr> interface GCUpperSpace("interface")
101iabbr <buffer> <expr> implements GCUpperSpace("implements")
Bram Moolenaar1aeaf8c2012-05-18 13:46:39 +0200102iabbr <buffer> <expr> shared GCUpperSpace("shared")
103iabbr <buffer> <expr> continue GCUpper("continue")
104iabbr <buffer> <expr> default GCUpper("default")
105iabbr <buffer> <expr> extends GCUpper("extends")
106iabbr <buffer> <expr> do GCUpper("do")
107iabbr <buffer> <expr> else GCUpper("else")
108iabbr <buffer> <expr> elseif GCUpperSpace("elseif")
109iabbr <buffer> <expr> enum GCUpperSpace("enum")
110iabbr <buffer> <expr> exit GCUpper("exit")
111iabbr <buffer> <expr> false GCUpper("false")
112iabbr <buffer> <expr> fail GCUpper("fail")
113iabbr <buffer> <expr> finally GCUpper("finally")
114iabbr <buffer> <expr> for GCUpperSpace("for")
115iabbr <buffer> <expr> func GCUpperSpace("func")
116iabbr <buffer> <expr> if GCUpperSpace("if")
117iabbr <buffer> <expr> import GCUpperSpace("import")
118iabbr <buffer> <expr> in GCUpperSpace("in")
119iabbr <buffer> <expr> io GCUpperDot("io")
120iabbr <buffer> <expr> main GCUpper("main")
121iabbr <buffer> <expr> module GCUpperSpace("module")
122iabbr <buffer> <expr> new GCUpper("new")
123iabbr <buffer> <expr> nil GCUpper("nil")
124iabbr <buffer> <expr> ok GCUpper("ok")
125iabbr <buffer> <expr> proc GCUpperSpace("proc")
126iabbr <buffer> <expr> proceed GCUpper("proceed")
127iabbr <buffer> <expr> return GCUpper("return")
128iabbr <buffer> <expr> step GCUpperSpace("step")
129iabbr <buffer> <expr> switch GCUpperSpace("switch")
130iabbr <buffer> <expr> sys GCUpperDot("sys")
131iabbr <buffer> <expr> this GCUpperDot("this")
132iabbr <buffer> <expr> throw GCUpperSpace("throw")
133iabbr <buffer> <expr> try GCUpper("try")
134iabbr <buffer> <expr> to GCUpperSpace("to")
135iabbr <buffer> <expr> true GCUpper("true")
136iabbr <buffer> <expr> until GCUpperSpace("until")
137iabbr <buffer> <expr> while GCUpperSpace("while")
138iabbr <buffer> <expr> repeat GCUpper("repeat")
139
Bram Moolenaar519cc552021-11-16 19:18:26 +0000140let b:undo_ftplugin ..=
141 \ " | iunabbr <buffer> alias" ..
142 \ " | iunabbr <buffer> arg" ..
143 \ " | iunabbr <buffer> break" ..
144 \ " | iunabbr <buffer> case" ..
145 \ " | iunabbr <buffer> catch" ..
146 \ " | iunabbr <buffer> check" ..
147 \ " | iunabbr <buffer> class" ..
148 \ " | iunabbr <buffer> interface" ..
149 \ " | iunabbr <buffer> implements" ..
150 \ " | iunabbr <buffer> shared" ..
151 \ " | iunabbr <buffer> continue" ..
152 \ " | iunabbr <buffer> default" ..
153 \ " | iunabbr <buffer> extends" ..
154 \ " | iunabbr <buffer> do" ..
155 \ " | iunabbr <buffer> else" ..
156 \ " | iunabbr <buffer> elseif" ..
157 \ " | iunabbr <buffer> enum" ..
158 \ " | iunabbr <buffer> exit" ..
159 \ " | iunabbr <buffer> false" ..
160 \ " | iunabbr <buffer> fail" ..
161 \ " | iunabbr <buffer> finally" ..
162 \ " | iunabbr <buffer> for" ..
163 \ " | iunabbr <buffer> func" ..
164 \ " | iunabbr <buffer> if" ..
165 \ " | iunabbr <buffer> import" ..
166 \ " | iunabbr <buffer> in" ..
167 \ " | iunabbr <buffer> io" ..
168 \ " | iunabbr <buffer> main" ..
169 \ " | iunabbr <buffer> module" ..
170 \ " | iunabbr <buffer> new" ..
171 \ " | iunabbr <buffer> nil" ..
172 \ " | iunabbr <buffer> ok" ..
173 \ " | iunabbr <buffer> proc" ..
174 \ " | iunabbr <buffer> proceed" ..
175 \ " | iunabbr <buffer> return" ..
176 \ " | iunabbr <buffer> step" ..
177 \ " | iunabbr <buffer> switch" ..
178 \ " | iunabbr <buffer> sys" ..
179 \ " | iunabbr <buffer> this" ..
180 \ " | iunabbr <buffer> throw" ..
181 \ " | iunabbr <buffer> try" ..
182 \ " | iunabbr <buffer> to" ..
183 \ " | iunabbr <buffer> true" ..
184 \ " | iunabbr <buffer> until" ..
185 \ " | iunabbr <buffer> while" ..
186 \ " | iunabbr <buffer> repeat"
187
Bram Moolenaarf0b03c42017-12-17 17:17:07 +0100188if !exists("no_plugin_maps") && !exists("no_zimbu_maps")
189 nnoremap <silent> <buffer> [[ m`:call ZimbuGoStartBlock()<CR>
190 nnoremap <silent> <buffer> ]] m`:call ZimbuGoEndBlock()<CR>
Bram Moolenaar519cc552021-11-16 19:18:26 +0000191 let b:undo_ftplugin ..=
192 \ " | silent! exe 'nunmap <buffer> [['" ..
193 \ " | silent! exe 'nunmap <buffer> ]]'"
Bram Moolenaarf0b03c42017-12-17 17:17:07 +0100194endif
Bram Moolenaar1aeaf8c2012-05-18 13:46:39 +0200195
196" Using a function makes sure the search pattern is restored
197func! ZimbuGoStartBlock()
198 ?^\s*\(FUNC\|PROC\|MAIN\|ENUM\|CLASS\|INTERFACE\)\>
199endfunc
200func! ZimbuGoEndBlock()
201 /^\s*\(FUNC\|PROC\|MAIN\|ENUM\|CLASS\|INTERFACE\)\>
202endfunc
203
204
205let &cpo = s:cpo_save
206unlet s:cpo_save