-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathvim_clojure_highlight.vim
70 lines (58 loc) · 1.66 KB
/
vim_clojure_highlight.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
" vim-clojure-highlight
function! s:is_cljs()
return expand('%:e') == 'cljs'
endfunction
function! s:session_exists()
return exists('g:fireplace_nrepl_sessions') && len(g:fireplace_nrepl_sessions)
endfunction
function! s:evalparse(cmd)
if !s:is_cljs()
return fireplace#evalparse(a:cmd)
endif
" NOTE: evalparse doesn't seem to work in cljs
" due to the {'session': 0} opts (weird).
let cmd = printf(g:fireplace#reader, a:cmd)
let resp = fireplace#session_eval(cmd)
if !empty(resp)
return eval(resp)
else
return ''
endif
endfunction
function! s:require(force)
if !a:force && s:evalparse("(nil? (find-ns 'vim-clojure-highlight))") == 0
return 0
endif
let ext = expand('%:e')
if ext != 'cljs' && ext != 'clj'
let ext = 'clj'
endif
let file = globpath(&runtimepath, 'autoload/vim_clojure_highlight.' . ext)
let buf = join(readfile(file), "\n")
if s:is_cljs()
call fireplace#session_eval('(ns vim-clojure-highlight) (do ' . buf . ')')
else
call fireplace#session_eval('(do ' . buf . ')')
endif
return 1
endfunction
" temporary, to force-reload the vim-clojure-highlight ns
function! vim_clojure_highlight#require()
return s:require(1)
endfunction
" Pass zero explicitly to prevent highlighting local vars
function! vim_clojure_highlight#syntax_match_references(...)
if !s:session_exists() | return | endif
try
call s:require(0)
let ns = "'" . fireplace#ns()
let opts = (a:0 > 0 && !a:1) ? ' :local-vars false' : ''
if s:is_cljs()
let ns = ns . ' (ns-publics ' . ns . ')'
endif
execute s:evalparse("(vim-clojure-highlight/ns-syntax-command " . ns . opts . ")")
let &syntax = &syntax
catch /.*/
endtry
endfunction
" vim:noet:sw=8:ts=8