zimbu.vim 7.3 KB

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