neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

zimbu.vim (7613B)


      1 " Vim filetype plugin file
      2 " Language:	Zimbu
      3 " Maintainer:	The Vim Project <https://github.com/vim/vim>
      4 " Last Change:	2025 Jun 08
      5 " Former Maintainer:	Bram Moolenaar <Bram@vim.org>
      6 " Note:	Zimbu was the programming language invented by Bram,
      7 "	but it seems to be lost by now
      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 
     21 let b:undo_ftplugin = "setl fo< com< cms< ofu< efm< tw< et< sts< sw<"
     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.
     34 setlocal comments=sO:#\ -,mO:#\ \ ,exO:#/,s:/*,m:\ ,ex:*/,:#=,:#-,:#%,:#
     35 setlocal commentstring=#\ %s
     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.
     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
     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)
     52  if v:char != ' ' && v:char != "\r" && v:char != "\x1b" && v:char != '.' && v:char != ')' && v:char != '}' && v:char != ','
     53    " no space or dot after the typed text
     54    let g:got_char = v:char
     55    return a:what
     56  endif
     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)
     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 
     97 iabbr <buffer> <expr> alias GCUpperSpace("alias")
     98 iabbr <buffer> <expr> arg GCUpperDot("arg")
     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")
    104 iabbr <buffer> <expr> interface GCUpperSpace("interface")
    105 iabbr <buffer> <expr> implements GCUpperSpace("implements")
    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 
    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 
    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>
    195  let b:undo_ftplugin ..=
    196 \ " | silent! exe 'nunmap <buffer> [['" ..
    197 \ " | silent! exe 'nunmap <buffer> ]]'"
    198 endif
    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