PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/vim/ftplugin/clojure.vim

https://github.com/rgeoghegan/personal
Vim Script | 147 lines | 97 code | 34 blank | 16 comment | 12 complexity | 2228e5490d7724f342e0ab758997e19a MD5 | raw file
  1. " Vim filetype plugin file
  2. " Language: Clojure
  3. " Maintainer: Meikel Brandmeyer <mb@kotka.de>
  4. " Only do this when not done yet for this buffer
  5. if exists("b:did_ftplugin")
  6. finish
  7. endif
  8. let b:did_ftplugin = 1
  9. let s:cpo_save = &cpo
  10. set cpo&vim
  11. let b:undo_ftplugin = "setlocal fo< com< cms< cpt< isk< def<"
  12. setlocal iskeyword+=?,-,*,!,+,/,=,<,>,.,:
  13. setlocal define=^\\s*(def\\(-\\|n\\|n-\\|macro\\|struct\\|multi\\)?
  14. " Set 'formatoptions' to break comment lines but not other lines,
  15. " and insert the comment leader when hitting <CR> or using "o".
  16. setlocal formatoptions-=t formatoptions+=croql
  17. setlocal commentstring=;%s
  18. " Set 'comments' to format dashed lists in comments.
  19. setlocal comments=sO:;\ -,mO:;\ \ ,n:;
  20. " Take all directories of the CLOJURE_SOURCE_DIRS environment variable
  21. " and add them to the path option.
  22. if has("win32") || has("win64")
  23. let s:delim = ";"
  24. else
  25. let s:delim = ":"
  26. endif
  27. for dir in split($CLOJURE_SOURCE_DIRS, s:delim)
  28. call vimclojure#AddPathToOption(dir . "/**", 'path')
  29. endfor
  30. " When the matchit plugin is loaded, this makes the % command skip parens and
  31. " braces in comments.
  32. let b:match_words = &matchpairs
  33. let b:match_skip = 's:comment\|string\|character'
  34. " Win32 can filter files in the browse dialog
  35. if has("gui_win32") && !exists("b:browsefilter")
  36. let b:browsefilter = "Clojure Source Files (*.clj)\t*.clj\n" .
  37. \ "Jave Source Files (*.java)\t*.java\n" .
  38. \ "All Files (*.*)\t*.*\n"
  39. endif
  40. for ns in [ "clojure.core", "clojure.inspector", "clojure.java.browse",
  41. \ "clojure.java.io", "clojure.java.javadoc", "clojure.java.shell",
  42. \ "clojure.main", "clojure.pprint", "clojure.repl", "clojure.set",
  43. \ "clojure.stacktrace", "clojure.string", "clojure.template",
  44. \ "clojure.test", "clojure.test.tap", "clojure.test.junit",
  45. \ "clojure.walk", "clojure.xml", "clojure.zip" ]
  46. call vimclojure#AddCompletions(ns)
  47. endfor
  48. " Define toplevel folding if desired.
  49. function! ClojureGetFoldingLevelWorker() dict
  50. execute self.lineno
  51. if vimclojure#util#SynIdName() =~ 'clojureParen\d' && vimclojure#util#Yank('l', 'normal! "lyl') == '('
  52. return 1
  53. endif
  54. if searchpairpos('(', '', ')', 'bWr', 'vimclojure#util#SynIdName() !~ "clojureParen\\d"') != [0, 0]
  55. return 1
  56. endif
  57. return 0
  58. endfunction
  59. function! ClojureGetFoldingLevel(lineno)
  60. let closure = {
  61. \ 'lineno' : a:lineno,
  62. \ 'f' : function("ClojureGetFoldingLevelWorker")
  63. \ }
  64. return vimclojure#WithSavedPosition(closure)
  65. endfunction
  66. " Disabled for now. Too slow (and naive).
  67. if exists("g:clj_want_folding") && g:clj_want_folding == 1 && 0 == 1
  68. setlocal foldexpr=ClojureGetFoldingLevel(v:lnum)
  69. setlocal foldmethod=expr
  70. endif
  71. try
  72. call vimclojure#InitBuffer()
  73. catch /.*/
  74. " We swallow a failure here. It means most likely that the
  75. " server is not running.
  76. echohl WarningMsg
  77. echomsg v:exception
  78. echohl None
  79. endtry
  80. call vimclojure#MapPlug("n", "aw", "AddToLispWords")
  81. call vimclojure#MapPlug("n", "tr", "ToggleParenRainbow")
  82. call vimclojure#MapPlug("n", "lw", "DocLookupWord")
  83. call vimclojure#MapPlug("n", "li", "DocLookupInteractive")
  84. call vimclojure#MapPlug("n", "jw", "JavadocLookupWord")
  85. call vimclojure#MapPlug("n", "ji", "JavadocLookupInteractive")
  86. call vimclojure#MapPlug("n", "fd", "FindDoc")
  87. call vimclojure#MapPlug("n", "mw", "MetaLookupWord")
  88. call vimclojure#MapPlug("n", "mi", "MetaLookupInteractive")
  89. call vimclojure#MapPlug("n", "sw", "SourceLookupWord")
  90. call vimclojure#MapPlug("n", "si", "SourceLookupInteractive")
  91. call vimclojure#MapPlug("n", "gw", "GotoSourceWord")
  92. call vimclojure#MapPlug("n", "gi", "GotoSourceInteractive")
  93. call vimclojure#MapPlug("n", "rf", "RequireFile")
  94. call vimclojure#MapPlug("n", "rF", "RequireFileAll")
  95. call vimclojure#MapPlug("n", "rt", "RunTests")
  96. call vimclojure#MapPlug("n", "me", "MacroExpand")
  97. call vimclojure#MapPlug("n", "m1", "MacroExpand1")
  98. call vimclojure#MapPlug("n", "ef", "EvalFile")
  99. call vimclojure#MapPlug("n", "el", "EvalLine")
  100. call vimclojure#MapPlug("v", "eb", "EvalBlock")
  101. call vimclojure#MapPlug("n", "et", "EvalToplevel")
  102. call vimclojure#MapPlug("n", "ep", "EvalParagraph")
  103. call vimclojure#MapPlug("n", "sr", "StartRepl")
  104. call vimclojure#MapPlug("n", "sR", "StartLocalRepl")
  105. if exists("b:vimclojure_namespace")
  106. setlocal omnifunc=vimclojure#OmniCompletion
  107. augroup VimClojure
  108. au!
  109. autocmd CursorMovedI <buffer> if pumvisible() == 0 | pclose | endif
  110. augroup END
  111. endif
  112. call vimclojure#MapPlug("n", "p", "CloseResultBuffer")
  113. let &cpo = s:cpo_save