citadel

My dotfiles, scripts and nix configs
git clone git://jb55.com/citadel
Log | Files | Refs | README | LICENSE

clojure.vim (5839B)


      1 " Vim filetype plugin file
      2 " Language:     Clojure
      3 " Maintainer:   Meikel Brandmeyer <mb@kotka.de>
      4 
      5 " Only do this when not done yet for this buffer
      6 if exists("b:did_ftplugin")
      7 	finish
      8 endif
      9 
     10 let b:did_ftplugin = 1
     11 
     12 let s:cpo_save = &cpo
     13 set cpo&vim
     14 
     15 let b:undo_ftplugin = "setlocal fo< com< cms< cpt< isk< def<"
     16 
     17 setlocal iskeyword+=?,-,*,!,+,/,=,<,>,.
     18 
     19 setlocal define=^\\s*(def\\(-\\|n\\|n-\\|macro\\|struct\\|multi\\)?
     20 
     21 " Set 'formatoptions' to break comment lines but not other lines,
     22 " and insert the comment leader when hitting <CR> or using "o".
     23 setlocal formatoptions-=t formatoptions+=croql
     24 setlocal commentstring=;%s
     25 
     26 " Set 'comments' to format dashed lists in comments.
     27 setlocal comments=sO:;\ -,mO:;\ \ ,n:;
     28 
     29 " Take all directories of the CLOJURE_SOURCE_DIRS environment variable
     30 " and add them to the path option.
     31 if has("win32") || has("win64")
     32 	let s:delim = ";"
     33 else
     34 	let s:delim = ":"
     35 endif
     36 for dir in split($CLOJURE_SOURCE_DIRS, s:delim)
     37 	call vimclojure#AddPathToOption(dir . "/**", 'path')
     38 endfor
     39 
     40 " When the matchit plugin is loaded, this makes the % command skip parens and
     41 " braces in comments.
     42 let b:match_words = &matchpairs
     43 let b:match_skip = 's:comment\|string\|character'
     44 
     45 " Win32 can filter files in the browse dialog
     46 if has("gui_win32") && !exists("b:browsefilter")
     47 	let b:browsefilter = "Clojure Source Files (*.clj)\t*.clj\n" .
     48 				\ "Jave Source Files (*.java)\t*.java\n" .
     49 				\ "All Files (*.*)\t*.*\n"
     50 endif
     51 
     52 for ns in ['clojure.core', 'clojure.set', 'clojure.xml', 'clojure.zip']
     53 	call vimclojure#AddCompletions(ns)
     54 endfor
     55 
     56 " Define toplevel folding if desired.
     57 function! ClojureGetFoldingLevel(lineno)
     58 	let closure = { 'lineno' : a:lineno }
     59 
     60 	function closure.f() dict
     61 		execute self.lineno
     62 
     63 		if vimclojure#SynIdName() =~ 'clojureParen\d' && vimclojure#Yank('l', 'normal! "lyl') == '('
     64 			return 1
     65 		endif
     66 
     67 		if searchpairpos('(', '', ')', 'bWr', 'vimclojure#SynIdName() !~ "clojureParen\\d"') != [0, 0]
     68 			return 1
     69 		endif
     70 
     71 		return 0
     72 	endfunction
     73 
     74 	return vimclojure#WithSavedPosition(closure)
     75 endfunction
     76 
     77 " Disabled for now. Too slow (and naive).
     78 if exists("g:clj_want_folding") && g:clj_want_folding == 1 && 0 == 1
     79 	setlocal foldexpr=ClojureGetFoldingLevel(v:lnum)
     80 	setlocal foldmethod=expr
     81 endif
     82 
     83 call vimclojure#InitBuffer()
     84 
     85 if exists("b:vimclojure_namespace")
     86 	call vimclojure#MakePlug("n", "DocLookupWord", 'vimclojure#DocLookup(expand("<cword>"))')
     87 	call vimclojure#MakePlug("n", "DocLookupInteractive", 'vimclojure#DocLookup(input("Symbol to look up: "))')
     88 	call vimclojure#MakePlug("n", "JavadocLookupWord", 'vimclojure#JavadocLookup(expand("<cword>"))')
     89 	call vimclojure#MakePlug("n", "JavadocLookupInteractive", 'vimclojure#JavadocLookup(input("Class to lookup: "))')
     90 	call vimclojure#MakePlug("n", "FindDoc", 'vimclojure#FindDoc())')
     91 
     92 	call vimclojure#MapPlug("n", "lw", "DocLookupWord")
     93 	call vimclojure#MapPlug("n", "li", "DocLookupInteractive")
     94 	call vimclojure#MapPlug("n", "jw", "JavadocLookupWord")
     95 	call vimclojure#MapPlug("n", "ji", "JavadocLookupInteractive")
     96 	call vimclojure#MapPlug("n", "fd", "FindDoc")
     97 
     98 	call vimclojure#MakePlug("n", "MetaLookupWord", 'vimclojure#MetaLookup(expand("<cword>"))')
     99 	call vimclojure#MakePlug("n", "MetaLookupInteractive", 'vimclojure#MetaLookup(input("Symbol to look up: "))')
    100 
    101 	call vimclojure#MapPlug("n", "mw", "MetaLookupWord")
    102 	call vimclojure#MapPlug("n", "mi", "MetaLookupInteractive")
    103 
    104 	call vimclojure#MakePlug("n", "SourceLookupWord", 'vimclojure#SourceLookup(expand("<cword>"))')
    105 	call vimclojure#MakePlug("n", "SourceLookupInteractive", 'vimclojure#SourceLookup(input("Symbol to look up: "))')
    106 
    107 	call vimclojure#MapPlug("n", "sw", "SourceLookupWord")
    108 	call vimclojure#MapPlug("n", "si", "SourceLookupInteractive")
    109 
    110 	call vimclojure#MakePlug("n", "GotoSourceWord", 'vimclojure#GotoSource(expand("<cword>"))')
    111 	call vimclojure#MakePlug("n", "GotoSourceInteractive", 'vimclojure#GotoSource(input("Symbol to go to: "))')
    112 
    113 	call vimclojure#MapPlug("n", "gw", "GotoSourceWord")
    114 	call vimclojure#MapPlug("n", "gi", "GotoSourceInteractive")
    115 
    116 	call vimclojure#MakePlug("n", "RequireFile", 'vimclojure#RequireFile(0)')
    117 	call vimclojure#MakePlug("n", "RequireFileAll", 'vimclojure#RequireFile(1)')
    118 
    119 	call vimclojure#MapPlug("n", "rf", "RequireFile")
    120 	call vimclojure#MapPlug("n", "rF", "RequireFileAll")
    121 
    122 	call vimclojure#MakePlug("n", "MacroExpand",  'vimclojure#MacroExpand(0)')
    123 	call vimclojure#MakePlug("n", "MacroExpand1", 'vimclojure#MacroExpand(1)')
    124 
    125 	call vimclojure#MapPlug("n", "me", "MacroExpand")
    126 	call vimclojure#MapPlug("n", "m1", "MacroExpand1")
    127 
    128 	call vimclojure#MakePlug("n", "EvalFile",      'vimclojure#EvalFile()')
    129 	call vimclojure#MakePlug("n", "EvalLine",      'vimclojure#EvalLine()')
    130 	call vimclojure#MakePlug("v", "EvalBlock",     'vimclojure#EvalBlock()')
    131 	call vimclojure#MakePlug("n", "EvalToplevel",  'vimclojure#EvalToplevel()')
    132 	call vimclojure#MakePlug("n", "EvalParagraph", 'vimclojure#EvalParagraph()')
    133 
    134 	call vimclojure#MapPlug("n", "ef", "EvalFile")
    135 	call vimclojure#MapPlug("n", "el", "EvalLine")
    136 	call vimclojure#MapPlug("v", "eb", "EvalBlock")
    137 	call vimclojure#MapPlug("n", "et", "EvalToplevel")
    138 	call vimclojure#MapPlug("n", "ep", "EvalParagraph")
    139 
    140 	call vimclojure#MakePlug("n", "StartRepl", 'vimclojure#Repl.New()')
    141 	call vimclojure#MapPlug("n", "sr", "StartRepl")
    142 
    143 	inoremap <Plug>ClojureReplEnterHook <Esc>:call b:vimclojure_repl.enterHook()<CR>
    144 	inoremap <Plug>ClojureReplUpHistory <C-O>:call b:vimclojure_repl.upHistory()<CR>
    145 	inoremap <Plug>ClojureReplDownHistory <C-O>:call b:vimclojure_repl.downHistory()<CR>
    146 
    147 	nnoremap <Plug>ClojureClosePreview :pclose!<CR>
    148 	call vimclojure#MapPlug("n", "p", "ClosePreview")
    149 
    150 	setlocal omnifunc=vimclojure#OmniCompletion
    151 
    152 	augroup VimClojure
    153 		autocmd CursorMovedI <buffer> if pumvisible() == 0 | pclose | endif
    154 	augroup END
    155 endif
    156 
    157 let &cpo = s:cpo_save