zimbu.vim 7.3 KB

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