blob: 1b5caf6a3bd9d9e17ada40ea5ee73e246783b127 [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>
Riley Bruins85f07112025-06-12 22:05:31 +02004" Last Change: 2025 Jun 08
Christian Brabandte978b452023-08-13 10:33:05 +02005" Former Maintainer: Bram Moolenaar <Bram@vim.org>
Riley Bruins85f07112025-06-12 22:05:31 +02006" Note: Zimbu was the programming language invented by Bram,
7" but it seems to be lost by now
Bram Moolenaar1aeaf8c2012-05-18 13:46:39 +02008
9" Only do this when not done yet for this buffer
10if exists("b:did_ftplugin")
11 finish
12endif
13
14" Don't load another plugin for this buffer
15let b:did_ftplugin = 1
16
17" Using line continuation here.
18let s:cpo_save = &cpo
19set cpo-=C
20
Riley Bruins85f07112025-06-12 22:05:31 +020021let b:undo_ftplugin = "setl fo< com< cms< ofu< efm< tw< et< sts< sw< | if has('vms') | setl isk< | endif"
Bram Moolenaar1aeaf8c2012-05-18 13:46:39 +020022
23" Set 'formatoptions' to break comment lines but not other lines,
24" and insert the comment leader when hitting <CR> or using "o".
25setlocal fo-=t fo+=croql
26
27" Set completion with CTRL-X CTRL-O to autoloaded function.
28if exists('&ofu')
29 setlocal ofu=ccomplete#Complete
30endif
31
32" Set 'comments' to format dashed lists in comments.
33" And to keep Zudocu comment characters.
Bram Moolenaar71b6d332022-09-10 13:13:14 +010034setlocal comments=sO:#\ -,mO:#\ \ ,exO:#/,s:/*,m:\ ,ex:*/,:#=,:#-,:#%,:#
Riley Bruins85f07112025-06-12 22:05:31 +020035setlocal commentstring=#\ %s
Bram Moolenaar1aeaf8c2012-05-18 13:46:39 +020036
37setlocal errorformat^=%f\ line\ %l\ col\ %c:\ %m,ERROR:\ %m
38
39" When the matchit plugin is loaded, this makes the % command skip parens and
40" braces in comments.
Bram Moolenaar519cc552021-11-16 19:18:26 +000041if exists("loaded_matchit") && !exists("b:match_words")
42 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\>\)'
43 let b:match_skip = 's:comment\|string\|zimbuchar'
44 let b:undo_ftplugin ..= " | unlet! b:match_words b:match_skip"
45endif
Bram Moolenaar1aeaf8c2012-05-18 13:46:39 +020046
47setlocal tw=78
48setlocal et sts=2 sw=2
49
50" Does replace when a dot, space or closing brace is typed.
51func! GCUpperDot(what)
Bram Moolenaard09acef2012-09-21 14:54:30 +020052 if v:char != ' ' && v:char != "\r" && v:char != "\x1b" && v:char != '.' && v:char != ')' && v:char != '}' && v:char != ','
Bram Moolenaar1aeaf8c2012-05-18 13:46:39 +020053 " no space or dot after the typed text
54 let g:got_char = v:char
55 return a:what
56 endif
Bram Moolenaard09acef2012-09-21 14:54:30 +020057 return GCUpperCommon(a:what)
58endfunc
59
60" Does not replace when a dot is typed.
61func! GCUpper(what)
62 if v:char != ' ' && v:char != "\r" && v:char != "\x1b" && v:char != ')' && v:char != ','
63 " no space or other "terminating" character after the typed text
64 let g:got_char = v:char
65 return a:what
66 endif
67 return GCUpperCommon(a:what)
68endfunc
69
70" Only replaces when a space is typed.
71func! GCUpperSpace(what)
72 if v:char != ' '
73 " no space after the typed text
74 let g:got_char = v:char
75 return a:what
76 endif
77 return GCUpperCommon(a:what)
78endfunc
79
80func! GCUpperCommon(what)
81 let col = col(".") - strlen(a:what)
Bram Moolenaar1aeaf8c2012-05-18 13:46:39 +020082 if col > 1 && getline('.')[col - 2] != ' '
83 " no space before the typed text
84 let g:got_char = 999
85 return a:what
86 endif
87 let synName = synIDattr(synID(line("."), col(".") - 2, 1), "name")
88 if synName =~ 'Comment\|String\|zimbuCregion\|\<c'
89 " inside a comment or C code
90 let g:got_char = 777
91 return a:what
92 endif
93 let g:got_char = 1111
94 return toupper(a:what)
95endfunc
96
Bram Moolenaar1aeaf8c2012-05-18 13:46:39 +020097iabbr <buffer> <expr> alias GCUpperSpace("alias")
98iabbr <buffer> <expr> arg GCUpperDot("arg")
Bram Moolenaar1aeaf8c2012-05-18 13:46:39 +020099iabbr <buffer> <expr> break GCUpper("break")
100iabbr <buffer> <expr> case GCUpperSpace("case")
101iabbr <buffer> <expr> catch GCUpperSpace("catch")
102iabbr <buffer> <expr> check GCUpperDot("check")
103iabbr <buffer> <expr> class GCUpperSpace("class")
Bram Moolenaard09acef2012-09-21 14:54:30 +0200104iabbr <buffer> <expr> interface GCUpperSpace("interface")
105iabbr <buffer> <expr> implements GCUpperSpace("implements")
Bram Moolenaar1aeaf8c2012-05-18 13:46:39 +0200106iabbr <buffer> <expr> shared GCUpperSpace("shared")
107iabbr <buffer> <expr> continue GCUpper("continue")
108iabbr <buffer> <expr> default GCUpper("default")
109iabbr <buffer> <expr> extends GCUpper("extends")
110iabbr <buffer> <expr> do GCUpper("do")
111iabbr <buffer> <expr> else GCUpper("else")
112iabbr <buffer> <expr> elseif GCUpperSpace("elseif")
113iabbr <buffer> <expr> enum GCUpperSpace("enum")
114iabbr <buffer> <expr> exit GCUpper("exit")
115iabbr <buffer> <expr> false GCUpper("false")
116iabbr <buffer> <expr> fail GCUpper("fail")
117iabbr <buffer> <expr> finally GCUpper("finally")
118iabbr <buffer> <expr> for GCUpperSpace("for")
119iabbr <buffer> <expr> func GCUpperSpace("func")
120iabbr <buffer> <expr> if GCUpperSpace("if")
121iabbr <buffer> <expr> import GCUpperSpace("import")
122iabbr <buffer> <expr> in GCUpperSpace("in")
123iabbr <buffer> <expr> io GCUpperDot("io")
124iabbr <buffer> <expr> main GCUpper("main")
125iabbr <buffer> <expr> module GCUpperSpace("module")
126iabbr <buffer> <expr> new GCUpper("new")
127iabbr <buffer> <expr> nil GCUpper("nil")
128iabbr <buffer> <expr> ok GCUpper("ok")
129iabbr <buffer> <expr> proc GCUpperSpace("proc")
130iabbr <buffer> <expr> proceed GCUpper("proceed")
131iabbr <buffer> <expr> return GCUpper("return")
132iabbr <buffer> <expr> step GCUpperSpace("step")
133iabbr <buffer> <expr> switch GCUpperSpace("switch")
134iabbr <buffer> <expr> sys GCUpperDot("sys")
135iabbr <buffer> <expr> this GCUpperDot("this")
136iabbr <buffer> <expr> throw GCUpperSpace("throw")
137iabbr <buffer> <expr> try GCUpper("try")
138iabbr <buffer> <expr> to GCUpperSpace("to")
139iabbr <buffer> <expr> true GCUpper("true")
140iabbr <buffer> <expr> until GCUpperSpace("until")
141iabbr <buffer> <expr> while GCUpperSpace("while")
142iabbr <buffer> <expr> repeat GCUpper("repeat")
143
Bram Moolenaar519cc552021-11-16 19:18:26 +0000144let b:undo_ftplugin ..=
145 \ " | iunabbr <buffer> alias" ..
146 \ " | iunabbr <buffer> arg" ..
147 \ " | iunabbr <buffer> break" ..
148 \ " | iunabbr <buffer> case" ..
149 \ " | iunabbr <buffer> catch" ..
150 \ " | iunabbr <buffer> check" ..
151 \ " | iunabbr <buffer> class" ..
152 \ " | iunabbr <buffer> interface" ..
153 \ " | iunabbr <buffer> implements" ..
154 \ " | iunabbr <buffer> shared" ..
155 \ " | iunabbr <buffer> continue" ..
156 \ " | iunabbr <buffer> default" ..
157 \ " | iunabbr <buffer> extends" ..
158 \ " | iunabbr <buffer> do" ..
159 \ " | iunabbr <buffer> else" ..
160 \ " | iunabbr <buffer> elseif" ..
161 \ " | iunabbr <buffer> enum" ..
162 \ " | iunabbr <buffer> exit" ..
163 \ " | iunabbr <buffer> false" ..
164 \ " | iunabbr <buffer> fail" ..
165 \ " | iunabbr <buffer> finally" ..
166 \ " | iunabbr <buffer> for" ..
167 \ " | iunabbr <buffer> func" ..
168 \ " | iunabbr <buffer> if" ..
169 \ " | iunabbr <buffer> import" ..
170 \ " | iunabbr <buffer> in" ..
171 \ " | iunabbr <buffer> io" ..
172 \ " | iunabbr <buffer> main" ..
173 \ " | iunabbr <buffer> module" ..
174 \ " | iunabbr <buffer> new" ..
175 \ " | iunabbr <buffer> nil" ..
176 \ " | iunabbr <buffer> ok" ..
177 \ " | iunabbr <buffer> proc" ..
178 \ " | iunabbr <buffer> proceed" ..
179 \ " | iunabbr <buffer> return" ..
180 \ " | iunabbr <buffer> step" ..
181 \ " | iunabbr <buffer> switch" ..
182 \ " | iunabbr <buffer> sys" ..
183 \ " | iunabbr <buffer> this" ..
184 \ " | iunabbr <buffer> throw" ..
185 \ " | iunabbr <buffer> try" ..
186 \ " | iunabbr <buffer> to" ..
187 \ " | iunabbr <buffer> true" ..
188 \ " | iunabbr <buffer> until" ..
189 \ " | iunabbr <buffer> while" ..
190 \ " | iunabbr <buffer> repeat"
191
Bram Moolenaarf0b03c42017-12-17 17:17:07 +0100192if !exists("no_plugin_maps") && !exists("no_zimbu_maps")
193 nnoremap <silent> <buffer> [[ m`:call ZimbuGoStartBlock()<CR>
194 nnoremap <silent> <buffer> ]] m`:call ZimbuGoEndBlock()<CR>
Bram Moolenaar519cc552021-11-16 19:18:26 +0000195 let b:undo_ftplugin ..=
196 \ " | silent! exe 'nunmap <buffer> [['" ..
197 \ " | silent! exe 'nunmap <buffer> ]]'"
Bram Moolenaarf0b03c42017-12-17 17:17:07 +0100198endif
Bram Moolenaar1aeaf8c2012-05-18 13:46:39 +0200199
200" Using a function makes sure the search pattern is restored
201func! ZimbuGoStartBlock()
202 ?^\s*\(FUNC\|PROC\|MAIN\|ENUM\|CLASS\|INTERFACE\)\>
203endfunc
204func! ZimbuGoEndBlock()
205 /^\s*\(FUNC\|PROC\|MAIN\|ENUM\|CLASS\|INTERFACE\)\>
206endfunc
207
208
209let &cpo = s:cpo_save
210unlet s:cpo_save