zimbu.vim 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. " Vim filetype plugin file
  2. " Language: Zimbu
  3. " Maintainer: Bram Moolenaar <Bram@vim.org>
  4. " Last Change: 2017 Dec 05
  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<"
  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:#\ \ ,:#=,:#-,:#%,:#
  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. 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\>\)'
  29. let b:match_skip = 's:comment\|string\|zimbuchar'
  30. setlocal tw=78
  31. setlocal et sts=2 sw=2
  32. " Does replace when a dot, space or closing brace is typed.
  33. func! GCUpperDot(what)
  34. if v:char != ' ' && v:char != "\r" && v:char != "\x1b" && v:char != '.' && v:char != ')' && v:char != '}' && v:char != ','
  35. " no space or dot after the typed text
  36. let g:got_char = v:char
  37. return a:what
  38. endif
  39. return GCUpperCommon(a:what)
  40. endfunc
  41. " Does not replace when a dot is typed.
  42. func! GCUpper(what)
  43. if v:char != ' ' && v:char != "\r" && v:char != "\x1b" && v:char != ')' && v:char != ','
  44. " no space or other "terminating" character after the typed text
  45. let g:got_char = v:char
  46. return a:what
  47. endif
  48. return GCUpperCommon(a:what)
  49. endfunc
  50. " Only replaces when a space is typed.
  51. func! GCUpperSpace(what)
  52. if v:char != ' '
  53. " no space 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. func! GCUpperCommon(what)
  60. let col = col(".") - strlen(a:what)
  61. if col > 1 && getline('.')[col - 2] != ' '
  62. " no space before the typed text
  63. let g:got_char = 999
  64. return a:what
  65. endif
  66. let synName = synIDattr(synID(line("."), col(".") - 2, 1), "name")
  67. if synName =~ 'Comment\|String\|zimbuCregion\|\<c'
  68. " inside a comment or C code
  69. let g:got_char = 777
  70. return a:what
  71. endif
  72. let g:got_char = 1111
  73. return toupper(a:what)
  74. endfunc
  75. iabbr <buffer> <expr> alias GCUpperSpace("alias")
  76. iabbr <buffer> <expr> arg GCUpperDot("arg")
  77. iabbr <buffer> <expr> break GCUpper("break")
  78. iabbr <buffer> <expr> case GCUpperSpace("case")
  79. iabbr <buffer> <expr> catch GCUpperSpace("catch")
  80. iabbr <buffer> <expr> check GCUpperDot("check")
  81. iabbr <buffer> <expr> class GCUpperSpace("class")
  82. iabbr <buffer> <expr> interface GCUpperSpace("interface")
  83. iabbr <buffer> <expr> implements GCUpperSpace("implements")
  84. iabbr <buffer> <expr> shared GCUpperSpace("shared")
  85. iabbr <buffer> <expr> continue GCUpper("continue")
  86. iabbr <buffer> <expr> default GCUpper("default")
  87. iabbr <buffer> <expr> extends GCUpper("extends")
  88. iabbr <buffer> <expr> do GCUpper("do")
  89. iabbr <buffer> <expr> else GCUpper("else")
  90. iabbr <buffer> <expr> elseif GCUpperSpace("elseif")
  91. iabbr <buffer> <expr> enum GCUpperSpace("enum")
  92. iabbr <buffer> <expr> exit GCUpper("exit")
  93. iabbr <buffer> <expr> false GCUpper("false")
  94. iabbr <buffer> <expr> fail GCUpper("fail")
  95. iabbr <buffer> <expr> finally GCUpper("finally")
  96. iabbr <buffer> <expr> for GCUpperSpace("for")
  97. iabbr <buffer> <expr> func GCUpperSpace("func")
  98. iabbr <buffer> <expr> if GCUpperSpace("if")
  99. iabbr <buffer> <expr> import GCUpperSpace("import")
  100. iabbr <buffer> <expr> in GCUpperSpace("in")
  101. iabbr <buffer> <expr> io GCUpperDot("io")
  102. iabbr <buffer> <expr> main GCUpper("main")
  103. iabbr <buffer> <expr> module GCUpperSpace("module")
  104. iabbr <buffer> <expr> new GCUpper("new")
  105. iabbr <buffer> <expr> nil GCUpper("nil")
  106. iabbr <buffer> <expr> ok GCUpper("ok")
  107. iabbr <buffer> <expr> proc GCUpperSpace("proc")
  108. iabbr <buffer> <expr> proceed GCUpper("proceed")
  109. iabbr <buffer> <expr> return GCUpper("return")
  110. iabbr <buffer> <expr> step GCUpperSpace("step")
  111. iabbr <buffer> <expr> switch GCUpperSpace("switch")
  112. iabbr <buffer> <expr> sys GCUpperDot("sys")
  113. iabbr <buffer> <expr> this GCUpperDot("this")
  114. iabbr <buffer> <expr> throw GCUpperSpace("throw")
  115. iabbr <buffer> <expr> try GCUpper("try")
  116. iabbr <buffer> <expr> to GCUpperSpace("to")
  117. iabbr <buffer> <expr> true GCUpper("true")
  118. iabbr <buffer> <expr> until GCUpperSpace("until")
  119. iabbr <buffer> <expr> while GCUpperSpace("while")
  120. iabbr <buffer> <expr> repeat GCUpper("repeat")
  121. if !exists("no_plugin_maps") && !exists("no_zimbu_maps")
  122. nnoremap <silent> <buffer> [[ m`:call ZimbuGoStartBlock()<CR>
  123. nnoremap <silent> <buffer> ]] m`:call ZimbuGoEndBlock()<CR>
  124. endif
  125. " Using a function makes sure the search pattern is restored
  126. func! ZimbuGoStartBlock()
  127. ?^\s*\(FUNC\|PROC\|MAIN\|ENUM\|CLASS\|INTERFACE\)\>
  128. endfunc
  129. func! ZimbuGoEndBlock()
  130. /^\s*\(FUNC\|PROC\|MAIN\|ENUM\|CLASS\|INTERFACE\)\>
  131. endfunc
  132. let &cpo = s:cpo_save
  133. unlet s:cpo_save