Bram Moolenaar | 1aeaf8c | 2012-05-18 13:46:39 +0200 | [diff] [blame] | 1 | " Vim filetype plugin file |
| 2 | " Language: Zimbu |
Christian Brabandt | e978b45 | 2023-08-13 10:33:05 +0200 | [diff] [blame] | 3 | " Maintainer: The Vim Project <https://github.com/vim/vim> |
Riley Bruins | 85f0711 | 2025-06-12 22:05:31 +0200 | [diff] [blame] | 4 | " Last Change: 2025 Jun 08 |
Christian Brabandt | e978b45 | 2023-08-13 10:33:05 +0200 | [diff] [blame] | 5 | " Former Maintainer: Bram Moolenaar <Bram@vim.org> |
Riley Bruins | 85f0711 | 2025-06-12 22:05:31 +0200 | [diff] [blame] | 6 | " Note: Zimbu was the programming language invented by Bram, |
| 7 | " but it seems to be lost by now |
Bram Moolenaar | 1aeaf8c | 2012-05-18 13:46:39 +0200 | [diff] [blame] | 8 | |
| 9 | " Only do this when not done yet for this buffer |
| 10 | if exists("b:did_ftplugin") |
| 11 | finish |
| 12 | endif |
| 13 | |
| 14 | " Don't load another plugin for this buffer |
| 15 | let b:did_ftplugin = 1 |
| 16 | |
| 17 | " Using line continuation here. |
| 18 | let s:cpo_save = &cpo |
| 19 | set cpo-=C |
| 20 | |
Riley Bruins | 85f0711 | 2025-06-12 22:05:31 +0200 | [diff] [blame] | 21 | let b:undo_ftplugin = "setl fo< com< cms< ofu< efm< tw< et< sts< sw< | if has('vms') | setl isk< | endif" |
Bram Moolenaar | 1aeaf8c | 2012-05-18 13:46:39 +0200 | [diff] [blame] | 22 | |
| 23 | " Set 'formatoptions' to break comment lines but not other lines, |
| 24 | " and insert the comment leader when hitting <CR> or using "o". |
| 25 | setlocal fo-=t fo+=croql |
| 26 | |
| 27 | " Set completion with CTRL-X CTRL-O to autoloaded function. |
| 28 | if exists('&ofu') |
| 29 | setlocal ofu=ccomplete#Complete |
| 30 | endif |
| 31 | |
| 32 | " Set 'comments' to format dashed lists in comments. |
| 33 | " And to keep Zudocu comment characters. |
Bram Moolenaar | 71b6d33 | 2022-09-10 13:13:14 +0100 | [diff] [blame] | 34 | setlocal comments=sO:#\ -,mO:#\ \ ,exO:#/,s:/*,m:\ ,ex:*/,:#=,:#-,:#%,:# |
Riley Bruins | 85f0711 | 2025-06-12 22:05:31 +0200 | [diff] [blame] | 35 | setlocal commentstring=#\ %s |
Bram Moolenaar | 1aeaf8c | 2012-05-18 13:46:39 +0200 | [diff] [blame] | 36 | |
| 37 | setlocal 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 Moolenaar | 519cc55 | 2021-11-16 19:18:26 +0000 | [diff] [blame] | 41 | if 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" |
| 45 | endif |
Bram Moolenaar | 1aeaf8c | 2012-05-18 13:46:39 +0200 | [diff] [blame] | 46 | |
| 47 | setlocal tw=78 |
| 48 | setlocal et sts=2 sw=2 |
| 49 | |
| 50 | " Does replace when a dot, space or closing brace is typed. |
| 51 | func! GCUpperDot(what) |
Bram Moolenaar | d09acef | 2012-09-21 14:54:30 +0200 | [diff] [blame] | 52 | if v:char != ' ' && v:char != "\r" && v:char != "\x1b" && v:char != '.' && v:char != ')' && v:char != '}' && v:char != ',' |
Bram Moolenaar | 1aeaf8c | 2012-05-18 13:46:39 +0200 | [diff] [blame] | 53 | " no space or dot after the typed text |
| 54 | let g:got_char = v:char |
| 55 | return a:what |
| 56 | endif |
Bram Moolenaar | d09acef | 2012-09-21 14:54:30 +0200 | [diff] [blame] | 57 | return GCUpperCommon(a:what) |
| 58 | endfunc |
| 59 | |
| 60 | " Does not replace when a dot is typed. |
| 61 | func! 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) |
| 68 | endfunc |
| 69 | |
| 70 | " Only replaces when a space is typed. |
| 71 | func! 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) |
| 78 | endfunc |
| 79 | |
| 80 | func! GCUpperCommon(what) |
| 81 | let col = col(".") - strlen(a:what) |
Bram Moolenaar | 1aeaf8c | 2012-05-18 13:46:39 +0200 | [diff] [blame] | 82 | 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) |
| 95 | endfunc |
| 96 | |
Bram Moolenaar | 1aeaf8c | 2012-05-18 13:46:39 +0200 | [diff] [blame] | 97 | iabbr <buffer> <expr> alias GCUpperSpace("alias") |
| 98 | iabbr <buffer> <expr> arg GCUpperDot("arg") |
Bram Moolenaar | 1aeaf8c | 2012-05-18 13:46:39 +0200 | [diff] [blame] | 99 | iabbr <buffer> <expr> break GCUpper("break") |
| 100 | iabbr <buffer> <expr> case GCUpperSpace("case") |
| 101 | iabbr <buffer> <expr> catch GCUpperSpace("catch") |
| 102 | iabbr <buffer> <expr> check GCUpperDot("check") |
| 103 | iabbr <buffer> <expr> class GCUpperSpace("class") |
Bram Moolenaar | d09acef | 2012-09-21 14:54:30 +0200 | [diff] [blame] | 104 | iabbr <buffer> <expr> interface GCUpperSpace("interface") |
| 105 | iabbr <buffer> <expr> implements GCUpperSpace("implements") |
Bram Moolenaar | 1aeaf8c | 2012-05-18 13:46:39 +0200 | [diff] [blame] | 106 | iabbr <buffer> <expr> shared GCUpperSpace("shared") |
| 107 | iabbr <buffer> <expr> continue GCUpper("continue") |
| 108 | iabbr <buffer> <expr> default GCUpper("default") |
| 109 | iabbr <buffer> <expr> extends GCUpper("extends") |
| 110 | iabbr <buffer> <expr> do GCUpper("do") |
| 111 | iabbr <buffer> <expr> else GCUpper("else") |
| 112 | iabbr <buffer> <expr> elseif GCUpperSpace("elseif") |
| 113 | iabbr <buffer> <expr> enum GCUpperSpace("enum") |
| 114 | iabbr <buffer> <expr> exit GCUpper("exit") |
| 115 | iabbr <buffer> <expr> false GCUpper("false") |
| 116 | iabbr <buffer> <expr> fail GCUpper("fail") |
| 117 | iabbr <buffer> <expr> finally GCUpper("finally") |
| 118 | iabbr <buffer> <expr> for GCUpperSpace("for") |
| 119 | iabbr <buffer> <expr> func GCUpperSpace("func") |
| 120 | iabbr <buffer> <expr> if GCUpperSpace("if") |
| 121 | iabbr <buffer> <expr> import GCUpperSpace("import") |
| 122 | iabbr <buffer> <expr> in GCUpperSpace("in") |
| 123 | iabbr <buffer> <expr> io GCUpperDot("io") |
| 124 | iabbr <buffer> <expr> main GCUpper("main") |
| 125 | iabbr <buffer> <expr> module GCUpperSpace("module") |
| 126 | iabbr <buffer> <expr> new GCUpper("new") |
| 127 | iabbr <buffer> <expr> nil GCUpper("nil") |
| 128 | iabbr <buffer> <expr> ok GCUpper("ok") |
| 129 | iabbr <buffer> <expr> proc GCUpperSpace("proc") |
| 130 | iabbr <buffer> <expr> proceed GCUpper("proceed") |
| 131 | iabbr <buffer> <expr> return GCUpper("return") |
| 132 | iabbr <buffer> <expr> step GCUpperSpace("step") |
| 133 | iabbr <buffer> <expr> switch GCUpperSpace("switch") |
| 134 | iabbr <buffer> <expr> sys GCUpperDot("sys") |
| 135 | iabbr <buffer> <expr> this GCUpperDot("this") |
| 136 | iabbr <buffer> <expr> throw GCUpperSpace("throw") |
| 137 | iabbr <buffer> <expr> try GCUpper("try") |
| 138 | iabbr <buffer> <expr> to GCUpperSpace("to") |
| 139 | iabbr <buffer> <expr> true GCUpper("true") |
| 140 | iabbr <buffer> <expr> until GCUpperSpace("until") |
| 141 | iabbr <buffer> <expr> while GCUpperSpace("while") |
| 142 | iabbr <buffer> <expr> repeat GCUpper("repeat") |
| 143 | |
Bram Moolenaar | 519cc55 | 2021-11-16 19:18:26 +0000 | [diff] [blame] | 144 | let 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 Moolenaar | f0b03c4 | 2017-12-17 17:17:07 +0100 | [diff] [blame] | 192 | if !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 Moolenaar | 519cc55 | 2021-11-16 19:18:26 +0000 | [diff] [blame] | 195 | let b:undo_ftplugin ..= |
| 196 | \ " | silent! exe 'nunmap <buffer> [['" .. |
| 197 | \ " | silent! exe 'nunmap <buffer> ]]'" |
Bram Moolenaar | f0b03c4 | 2017-12-17 17:17:07 +0100 | [diff] [blame] | 198 | endif |
Bram Moolenaar | 1aeaf8c | 2012-05-18 13:46:39 +0200 | [diff] [blame] | 199 | |
| 200 | " Using a function makes sure the search pattern is restored |
| 201 | func! ZimbuGoStartBlock() |
| 202 | ?^\s*\(FUNC\|PROC\|MAIN\|ENUM\|CLASS\|INTERFACE\)\> |
| 203 | endfunc |
| 204 | func! ZimbuGoEndBlock() |
| 205 | /^\s*\(FUNC\|PROC\|MAIN\|ENUM\|CLASS\|INTERFACE\)\> |
| 206 | endfunc |
| 207 | |
| 208 | |
| 209 | let &cpo = s:cpo_save |
| 210 | unlet s:cpo_save |