|
1 | 1 | " vim-clojure-highlight
|
2 | 2 |
|
3 |
| -if !exists('g:clojure_highlight_references') |
4 |
| - let g:clojure_highlight_references = 1 |
5 |
| -endif |
6 |
| - |
7 | 3 | if !exists('g:clojure_highlight_local_vars')
|
8 | 4 | let g:clojure_highlight_local_vars = 1
|
9 | 5 | endif
|
10 | 6 |
|
11 |
| -function! s:disable_acid_log() |
12 |
| - if exists('b:acid_log_messages') |
13 |
| - let b:acid_old_log_value = b:acid_log_messages |
14 |
| - else |
15 |
| - let b:acid_log_messages = 0 |
16 |
| - endif |
17 |
| -endfunction |
18 |
| - |
19 |
| -function! s:restore_acid_log() |
20 |
| - if exists('b:acid_old_log_value') |
21 |
| - let b:acid_log_messages = b:acid_old_log_value |
22 |
| - unlet b:acid_old_log_value |
23 |
| - else |
24 |
| - unlet b:acid_log_messages |
25 |
| - endif |
26 |
| -endfunction |
27 |
| - |
28 |
| -function! s:silent_acid_send(data, handler_fn) |
29 |
| - call s:disable_acid_log() |
30 |
| - echom "Disabled log: ".b:acid_log_messages |
31 |
| - call AcidSendNrepl(a:data, 'VimFn', a:handler_fn) |
32 |
| - call s:restore_acid_log() |
33 |
| -endfunction |
34 |
| - |
35 |
| -function! AsyncCljHighlightExec(msg) |
36 |
| - let fst = a:msg[0] |
37 |
| - if get(fst, 'value', '') !=# '' |
38 |
| - exec eval(fst.value) |
39 |
| - let &syntax = &syntax |
40 |
| - let b:async_clj_updated_highlight = 1 |
41 |
| - elseif get(fst, 'err', '') !=# '' |
42 |
| - echohl ErrorMSG |
43 |
| - echo fst.err |
44 |
| - echohl NONE |
45 |
| - endif |
46 |
| -endfunction |
47 |
| - |
48 |
| -function! AsyncCljRequestHighlight(...) |
49 |
| - if a:0 > 0 && get(a:1[0], 'err', 0) |
50 |
| - echohl ErrorMSG |
51 |
| - echo a:1[0].err |
52 |
| - echohl NONE |
53 |
| - return |
54 |
| - endif |
55 |
| - |
56 |
| - let ns = AcidGetNs() |
57 |
| - let opts = g:clojure_highlight_local_vars ? '' : ' :local-vars false' |
58 |
| - call s:silent_acid_send({"op": "eval", "code": "(async-clj-highlight/ns-syntax-command '" . ns . opts . ")"}, 'AsyncCljHighlightExec') |
| 7 | +function! AsyncCljHighlightExec(value) |
| 8 | + exec eval(a:value) |
| 9 | + let &syntax = &syntax |
59 | 10 | endfunction
|
60 | 11 |
|
61 |
| -function! AsyncCljHighlightPrepare(msg) |
62 |
| - let exists = a:msg[0].value |
63 |
| - if exists =~ 'nil' |
64 |
| - let buf = join(readfile(globpath(&runtimepath, 'clj/async_clj_highlight.clj')), "\n") |
65 |
| - call s:silent_acid_send({'op': 'eval', 'code': "(do ". buf . ")"}, 'AsyncCljRequestHighlight') |
66 |
| - endif |
67 |
| - call AsyncCljRequestHighlight() |
68 |
| -endfunction |
69 |
| - |
70 |
| -function! s:syntax_match_references(bang) |
71 |
| - if g:clojure_highlight_references && (a:bang || !exists('b:b:async_clj_updated_highlight')) |
72 |
| - call s:silent_acid_send({'op': 'eval', 'code': "(find-ns 'async-clj-highlight)"}, 'AsyncCljHighlightPrepare') |
73 |
| - endif |
74 |
| -endfunction |
75 |
| - |
76 |
| -function! s:toggle_clojure_highlight_references() |
77 |
| - let g:clojure_highlight_references = !g:clojure_highlight_references |
78 |
| - |
79 |
| - if g:clojure_highlight_references |
80 |
| - call s:syntax_match_references(0) |
81 |
| - else |
82 |
| - unlet! b:clojure_syntax_keywords b:clojure_syntax_without_core_keywords |
83 |
| - let &syntax = &syntax |
84 |
| - endif |
85 |
| -endfunction |
| 12 | +command! -bar -bang ClojureAsyncHighlight call luaeval("require('cljhl').preload()") |
86 | 13 |
|
87 | 14 | augroup async_clj_highlight
|
88 | 15 | autocmd!
|
89 |
| - autocmd User AcidRequired ClojureHighlightReferences |
| 16 | + autocmd User AcidLoadedAllNSs ClojureAsyncHighlight |
| 17 | + autocmd User AcidRequired ClojureAsyncHighlight |
90 | 18 | augroup END
|
91 | 19 |
|
92 |
| -command! -bar ToggleClojureHighlightReferences call s:toggle_clojure_highlight_references() |
93 |
| -command! -bar -bang ClojureHighlightReferences call s:syntax_match_references(<bang>0) |
94 |
| - |
95 |
| -map <plug>AsyncCljDoHighlight :ClojureHighlightReferences!<CR> |
0 commit comments