blob: 2e3138edf825f5fecabbb534a65f0ab90b6a1638 [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 Moolenaarf0b03c42017-12-17 17:17:07 +01004" Last Change: 2017 Dec 05
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.
31setlocal comments=sO:#\ -,mO:#\ \ ,:#=,:#-,:#%,:#
32
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 Moolenaard09acef2012-09-21 14:54:30 +020037let 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\>\)'
Bram Moolenaar1aeaf8c2012-05-18 13:46:39 +020038
39let b:match_skip = 's:comment\|string\|zimbuchar'
40
41setlocal tw=78
42setlocal et sts=2 sw=2
43
44" Does replace when a dot, space or closing brace is typed.
45func! GCUpperDot(what)
Bram Moolenaard09acef2012-09-21 14:54:30 +020046 if v:char != ' ' && v:char != "\r" && v:char != "\x1b" && v:char != '.' && v:char != ')' && v:char != '}' && v:char != ','
Bram Moolenaar1aeaf8c2012-05-18 13:46:39 +020047 " no space or dot after the typed text
48 let g:got_char = v:char
49 return a:what
50 endif
Bram Moolenaard09acef2012-09-21 14:54:30 +020051 return GCUpperCommon(a:what)
52endfunc
53
54" Does not replace when a dot is typed.
55func! GCUpper(what)
56 if v:char != ' ' && v:char != "\r" && v:char != "\x1b" && v:char != ')' && v:char != ','
57 " no space or other "terminating" character after the typed text
58 let g:got_char = v:char
59 return a:what
60 endif
61 return GCUpperCommon(a:what)
62endfunc
63
64" Only replaces when a space is typed.
65func! GCUpperSpace(what)
66 if v:char != ' '
67 " no space after the typed text
68 let g:got_char = v:char
69 return a:what
70 endif
71 return GCUpperCommon(a:what)
72endfunc
73
74func! GCUpperCommon(what)
75 let col = col(".") - strlen(a:what)
Bram Moolenaar1aeaf8c2012-05-18 13:46:39 +020076 if col > 1 && getline('.')[col - 2] != ' '
77 " no space before the typed text
78 let g:got_char = 999
79 return a:what
80 endif
81 let synName = synIDattr(synID(line("."), col(".") - 2, 1), "name")
82 if synName =~ 'Comment\|String\|zimbuCregion\|\<c'
83 " inside a comment or C code
84 let g:got_char = 777
85 return a:what
86 endif
87 let g:got_char = 1111
88 return toupper(a:what)
89endfunc
90
Bram Moolenaar1aeaf8c2012-05-18 13:46:39 +020091iabbr <buffer> <expr> alias GCUpperSpace("alias")
92iabbr <buffer> <expr> arg GCUpperDot("arg")
Bram Moolenaar1aeaf8c2012-05-18 13:46:39 +020093iabbr <buffer> <expr> break GCUpper("break")
94iabbr <buffer> <expr> case GCUpperSpace("case")
95iabbr <buffer> <expr> catch GCUpperSpace("catch")
96iabbr <buffer> <expr> check GCUpperDot("check")
97iabbr <buffer> <expr> class GCUpperSpace("class")
Bram Moolenaard09acef2012-09-21 14:54:30 +020098iabbr <buffer> <expr> interface GCUpperSpace("interface")
99iabbr <buffer> <expr> implements GCUpperSpace("implements")
Bram Moolenaar1aeaf8c2012-05-18 13:46:39 +0200100iabbr <buffer> <expr> shared GCUpperSpace("shared")
101iabbr <buffer> <expr> continue GCUpper("continue")
102iabbr <buffer> <expr> default GCUpper("default")
103iabbr <buffer> <expr> extends GCUpper("extends")
104iabbr <buffer> <expr> do GCUpper("do")
105iabbr <buffer> <expr> else GCUpper("else")
106iabbr <buffer> <expr> elseif GCUpperSpace("elseif")
107iabbr <buffer> <expr> enum GCUpperSpace("enum")
108iabbr <buffer> <expr> exit GCUpper("exit")
109iabbr <buffer> <expr> false GCUpper("false")
110iabbr <buffer> <expr> fail GCUpper("fail")
111iabbr <buffer> <expr> finally GCUpper("finally")
112iabbr <buffer> <expr> for GCUpperSpace("for")
113iabbr <buffer> <expr> func GCUpperSpace("func")
114iabbr <buffer> <expr> if GCUpperSpace("if")
115iabbr <buffer> <expr> import GCUpperSpace("import")
116iabbr <buffer> <expr> in GCUpperSpace("in")
117iabbr <buffer> <expr> io GCUpperDot("io")
118iabbr <buffer> <expr> main GCUpper("main")
119iabbr <buffer> <expr> module GCUpperSpace("module")
120iabbr <buffer> <expr> new GCUpper("new")
121iabbr <buffer> <expr> nil GCUpper("nil")
122iabbr <buffer> <expr> ok GCUpper("ok")
123iabbr <buffer> <expr> proc GCUpperSpace("proc")
124iabbr <buffer> <expr> proceed GCUpper("proceed")
125iabbr <buffer> <expr> return GCUpper("return")
126iabbr <buffer> <expr> step GCUpperSpace("step")
127iabbr <buffer> <expr> switch GCUpperSpace("switch")
128iabbr <buffer> <expr> sys GCUpperDot("sys")
129iabbr <buffer> <expr> this GCUpperDot("this")
130iabbr <buffer> <expr> throw GCUpperSpace("throw")
131iabbr <buffer> <expr> try GCUpper("try")
132iabbr <buffer> <expr> to GCUpperSpace("to")
133iabbr <buffer> <expr> true GCUpper("true")
134iabbr <buffer> <expr> until GCUpperSpace("until")
135iabbr <buffer> <expr> while GCUpperSpace("while")
136iabbr <buffer> <expr> repeat GCUpper("repeat")
137
Bram Moolenaarf0b03c42017-12-17 17:17:07 +0100138if !exists("no_plugin_maps") && !exists("no_zimbu_maps")
139 nnoremap <silent> <buffer> [[ m`:call ZimbuGoStartBlock()<CR>
140 nnoremap <silent> <buffer> ]] m`:call ZimbuGoEndBlock()<CR>
141endif
Bram Moolenaar1aeaf8c2012-05-18 13:46:39 +0200142
143" Using a function makes sure the search pattern is restored
144func! ZimbuGoStartBlock()
145 ?^\s*\(FUNC\|PROC\|MAIN\|ENUM\|CLASS\|INTERFACE\)\>
146endfunc
147func! ZimbuGoEndBlock()
148 /^\s*\(FUNC\|PROC\|MAIN\|ENUM\|CLASS\|INTERFACE\)\>
149endfunc
150
151
152let &cpo = s:cpo_save
153unlet s:cpo_save