diff --git a/autoload/vim_clojure_highlight.vim b/autoload/vim_clojure_highlight.vim deleted file mode 100644 index 95df568..0000000 --- a/autoload/vim_clojure_highlight.vim +++ /dev/null @@ -1,30 +0,0 @@ -" vim-clojure-highlight - -function! s:session_exists() - return exists('g:fireplace_nrepl_sessions') && len(g:fireplace_nrepl_sessions) -endfunction - -function! s:require() - if fireplace#evalparse("(find-ns 'vim-clojure-highlight)") ==# '' - let buf = join(readfile(globpath(&runtimepath, 'autoload/vim_clojure_highlight.clj')), "\n") - call fireplace#session_eval('(do ' . buf . ')') - endif -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() - - let ns = "'" . fireplace#ns() - let opts = (a:0 > 0 && !a:1) ? ' :local-vars false' : '' - - execute fireplace#evalparse("(vim-clojure-highlight/ns-syntax-command " . ns . opts . ")") - let &syntax = &syntax - catch /./ - endtry -endfunction - -" vim:noet:sw=8:ts=8 diff --git a/autoload/vim_clojure_highlight.clj b/clj/async_clj_highlight.clj similarity index 98% rename from autoload/vim_clojure_highlight.clj rename to clj/async_clj_highlight.clj index 384df5f..60ff836 100644 --- a/autoload/vim_clojure_highlight.clj +++ b/clj/async_clj_highlight.clj @@ -1,4 +1,4 @@ -(ns vim-clojure-highlight +(ns async-clj-highlight (:require [clojure.set :as set] [clojure.string :as string]) (:import (clojure.lang MultiFn))) @@ -68,7 +68,7 @@ (ns-aliases ns))) (defn var-type [v] - (let [f @v m (meta v)] + (let [_ @v m (meta v)] (cond (clojure-core? v) (core-symbol->syntax-group (:name m)) (:macro m) "clojureMacro" (fn-var? v) "clojureFunc" diff --git a/lua/cljhl/init.lua b/lua/cljhl/init.lua new file mode 100644 index 0000000..f941dcf --- /dev/null +++ b/lua/cljhl/init.lua @@ -0,0 +1,66 @@ +-- luacheck: globals vim +local acid = require("acid") +local log = require("acid.log").msg +local connections = require("acid.connections") +local commands = require("acid.commands") +local eval = require("acid.ops").eval + +local cljhl = {} + +local conn_to_key = function(conn) + return tostring(conn[1]) .. ":" .. tostring(conn[2]) +end + +cljhl.cache = {} + +cljhl.apply = function(msg) + if msg.status ~= nil then + return + elseif msg.err ~= nil then + log("Can't apply highlight.", msg.err) + return + end + vim.api.nvim_call_function("AsyncCljHighlightExec", {msg.value}) +end + +cljhl.highlight = function(ns) + ns = ns or vim.api.nvim_call_function("AcidGetNs", {}) + if ns == nil then + return + end + + local opts = "" + if vim.api.nvim_get_var("clojure_highlight_local_vars") == 0 then + opts = " :local-vars false" + end + + local payload = eval{code = "(ns-syntax-command '" .. ns .. opts ..")", ns = "async-clj-highlight"} + acid.run(payload:with_handler(cljhl.apply)) +end + +cljhl.preload = function(ns) + ns = ns or vim.api.nvim_call_function("AcidGetNs", {}) + + if ns == nil then + return + end + + local pwd = vim.api.nvim_call_function("getcwd", {}) + local conn = connections.attempt_get(pwd) + local key = conn_to_key(conn) + + if cljhl.cache[key] ~= nil then + cljhl.highlight(ns) + else + local cmd = commands.preload{files = {"clj/async_clj_highlight.clj"}}[1] + acid.run(cmd:with_handler(function(data) + if data.status then + return + end + cljhl.cache[key] = true + cljhl.highlight(ns) + end, conn)) + end +end + +return cljhl diff --git a/plugin/async_clj_highlight.vim b/plugin/async_clj_highlight.vim new file mode 100644 index 0000000..3633f1d --- /dev/null +++ b/plugin/async_clj_highlight.vim @@ -0,0 +1,19 @@ +" vim-clojure-highlight + +if !exists('g:clojure_highlight_local_vars') + let g:clojure_highlight_local_vars = 1 +endif + +function! AsyncCljHighlightExec(value) + exec eval(a:value) + let &syntax = &syntax +endfunction + +command! -bar -bang ClojureAsyncHighlight call luaeval("require('cljhl').preload()") + +augroup async_clj_highlight + autocmd! + autocmd User AcidLoadedAllNSs ClojureAsyncHighlight + autocmd User AcidRequired ClojureAsyncHighlight +augroup END + diff --git a/plugin/vim_clojure_highlight.vim b/plugin/vim_clojure_highlight.vim deleted file mode 100644 index 589ba99..0000000 --- a/plugin/vim_clojure_highlight.vim +++ /dev/null @@ -1,36 +0,0 @@ -" vim-clojure-highlight - -if !exists('g:clojure_highlight_references') - let g:clojure_highlight_references = 1 -endif - -if !exists('g:clojure_highlight_local_vars') - let g:clojure_highlight_local_vars = 1 -endif - -function! s:syntax_match_references() - if g:clojure_highlight_references - call vim_clojure_highlight#syntax_match_references(g:clojure_highlight_local_vars) - endif -endfunction - -function! s:toggle_clojure_highlight_references() - let g:clojure_highlight_references = !g:clojure_highlight_references - - if g:clojure_highlight_references - call s:syntax_match_references() - else - unlet! b:clojure_syntax_keywords b:clojure_syntax_without_core_keywords - let &syntax = &syntax - endif -endfunction - -augroup vim_clojure_highlight - autocmd! - autocmd BufRead *.clj ClojureHighlightReferences -augroup END - -command! -bar ToggleClojureHighlightReferences call s:toggle_clojure_highlight_references() -command! -bar ClojureHighlightReferences call s:syntax_match_references() - -" vim:noet:sw=8:ts=8