From bd93f4890946365a85a0a56c73c3172fe2a675c8 Mon Sep 17 00:00:00 2001
From: Henry Kupty <hkupty@gmail.com>
Date: Mon, 27 Mar 2017 16:09:52 -0300
Subject: [PATCH 01/19] Async highlight with acid

---
 autoload/vim_clojure_highlight.vim | 39 ++++++++++++++++--------------
 1 file changed, 21 insertions(+), 18 deletions(-)

diff --git a/autoload/vim_clojure_highlight.vim b/autoload/vim_clojure_highlight.vim
index 95df568..ef8103a 100644
--- a/autoload/vim_clojure_highlight.vim
+++ b/autoload/vim_clojure_highlight.vim
@@ -1,30 +1,33 @@
 " vim-clojure-highlight
 
-function! s:session_exists()
-	return exists('g:fireplace_nrepl_sessions') && len(g:fireplace_nrepl_sessions)
+function! AsyncCljHighlightHandle(msg)
+  let exists = a:msg[0]['value']
+  if exists =~ 'nil'
+      let buf = join(readfile(globpath(&runtimepath, 'autoload/vim_clojure_highlight.clj')), "\n")
+      call AcidSendNrepl({'op': 'eval', 'code': "(do ". buf . ")"}, 'Ignore')
+  endif
 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
+function! AsyncCljHighlightRequire()
+  call AcidSendNrepl({'op': 'eval', 'code': "(find-ns 'vim-clojure-highlight)"}, 'VimFn', 'AsyncCljHighlightHandle')
+endfunction
+
+function! AsyncCljHighlightExec(msg)
+  let highlight = a:msg[0]['value']
+  exec highlight
 endfunction
 
 " Pass zero explicitly to prevent highlighting local vars
 function! vim_clojure_highlight#syntax_match_references(...)
-	if !s:session_exists() | return | endif
+  if !s:session_exists() | return | endif
 
-	try
-		call s:require()
+  try
+    call s:require()
 
-		let ns = "'" . fireplace#ns()
-		let opts = (a:0 > 0 && !a:1) ? ' :local-vars false' : ''
+    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
+    execute AcidSendNrepl({"op": "eval", "code": "(vim-clojure-highlight/ns-syntax-command " . ns . opts . ")"}, 'VimFn', 'AsyncCljHighlightExec')
+    let &syntax = &syntax
+  catch /./
+  endtry
 endfunction
-
-" vim:noet:sw=8:ts=8

From 45e261be8c8b7513a4116878adc7012c709b5960 Mon Sep 17 00:00:00 2001
From: Henry Kupty <hkupty@gmail.com>
Date: Mon, 27 Mar 2017 16:10:17 -0300
Subject: [PATCH 02/19] Simplify

---
 autoload/vim_clojure_highlight.vim | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/autoload/vim_clojure_highlight.vim b/autoload/vim_clojure_highlight.vim
index ef8103a..b86002a 100644
--- a/autoload/vim_clojure_highlight.vim
+++ b/autoload/vim_clojure_highlight.vim
@@ -8,10 +8,6 @@ function! AsyncCljHighlightHandle(msg)
   endif
 endfunction
 
-function! AsyncCljHighlightRequire()
-  call AcidSendNrepl({'op': 'eval', 'code': "(find-ns 'vim-clojure-highlight)"}, 'VimFn', 'AsyncCljHighlightHandle')
-endfunction
-
 function! AsyncCljHighlightExec(msg)
   let highlight = a:msg[0]['value']
   exec highlight
@@ -22,7 +18,7 @@ function! vim_clojure_highlight#syntax_match_references(...)
   if !s:session_exists() | return | endif
 
   try
-    call s:require()
+    call AcidSendNrepl({'op': 'eval', 'code': "(find-ns 'vim-clojure-highlight)"}, 'VimFn', 'AsyncCljHighlightHandle')
 
     let opts = (a:0 > 0 && !a:1) ? ' :local-vars false' : ''
 

From b566c9ff9ebbece7095b7fdaa3a3d31a004d50aa Mon Sep 17 00:00:00 2001
From: Henry Kupty <hkupty@gmail.com>
Date: Mon, 27 Mar 2017 16:13:53 -0300
Subject: [PATCH 03/19] Cleanup

---
 autoload/vim_clojure_highlight.vim | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/autoload/vim_clojure_highlight.vim b/autoload/vim_clojure_highlight.vim
index b86002a..c3b03d1 100644
--- a/autoload/vim_clojure_highlight.vim
+++ b/autoload/vim_clojure_highlight.vim
@@ -11,19 +11,14 @@ endfunction
 function! AsyncCljHighlightExec(msg)
   let highlight = a:msg[0]['value']
   exec highlight
+  let &syntax = &syntax
 endfunction
 
 " Pass zero explicitly to prevent highlighting local vars
 function! vim_clojure_highlight#syntax_match_references(...)
-  if !s:session_exists() | return | endif
-
-  try
     call AcidSendNrepl({'op': 'eval', 'code': "(find-ns 'vim-clojure-highlight)"}, 'VimFn', 'AsyncCljHighlightHandle')
 
     let opts = (a:0 > 0 && !a:1) ? ' :local-vars false' : ''
 
     execute AcidSendNrepl({"op": "eval", "code": "(vim-clojure-highlight/ns-syntax-command " . ns . opts . ")"}, 'VimFn', 'AsyncCljHighlightExec')
-    let &syntax = &syntax
-  catch /./
-  endtry
 endfunction

From cf61f272feed6660cdac9528b5dbdeb513f76fd2 Mon Sep 17 00:00:00 2001
From: Henry Kupty <hkupty@gmail.com>
Date: Mon, 27 Mar 2017 16:16:12 -0300
Subject: [PATCH 04/19] Chain Everythin

---
 autoload/vim_clojure_highlight.vim | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/autoload/vim_clojure_highlight.vim b/autoload/vim_clojure_highlight.vim
index c3b03d1..417a213 100644
--- a/autoload/vim_clojure_highlight.vim
+++ b/autoload/vim_clojure_highlight.vim
@@ -5,6 +5,11 @@ function! AsyncCljHighlightHandle(msg)
   if exists =~ 'nil'
       let buf = join(readfile(globpath(&runtimepath, 'autoload/vim_clojure_highlight.clj')), "\n")
       call AcidSendNrepl({'op': 'eval', 'code': "(do ". buf . ")"}, 'Ignore')
+      let opts = (a:0 > 0 && !a:1) ? ' :local-vars false' : ''
+
+      let ns = AcidGetNs()
+
+      call AcidSendNrepl({"op": "eval", "code": "(vim-clojure-highlight/ns-syntax-command " . ns . opts . ")"}, 'VimFn', 'AsyncCljHighlightExec')
   endif
 endfunction
 
@@ -17,8 +22,4 @@ endfunction
 " Pass zero explicitly to prevent highlighting local vars
 function! vim_clojure_highlight#syntax_match_references(...)
     call AcidSendNrepl({'op': 'eval', 'code': "(find-ns 'vim-clojure-highlight)"}, 'VimFn', 'AsyncCljHighlightHandle')
-
-    let opts = (a:0 > 0 && !a:1) ? ' :local-vars false' : ''
-
-    execute AcidSendNrepl({"op": "eval", "code": "(vim-clojure-highlight/ns-syntax-command " . ns . opts . ")"}, 'VimFn', 'AsyncCljHighlightExec')
 endfunction

From 46ac39c38b90c12605288cf3bcc42fed0b0e91a8 Mon Sep 17 00:00:00 2001
From: Henry Kupty <hkupty@gmail.com>
Date: Mon, 27 Mar 2017 16:18:12 -0300
Subject: [PATCH 05/19] Rename and long

---
 autoload/vim_clojure_highlight.vim | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/autoload/vim_clojure_highlight.vim b/autoload/vim_clojure_highlight.vim
index 417a213..ee162a7 100644
--- a/autoload/vim_clojure_highlight.vim
+++ b/autoload/vim_clojure_highlight.vim
@@ -14,8 +14,9 @@ function! AsyncCljHighlightHandle(msg)
 endfunction
 
 function! AsyncCljHighlightExec(msg)
-  let highlight = a:msg[0]['value']
-  exec highlight
+  let ret = a:msg[0]['value']
+  echom ret
+  exec ret
   let &syntax = &syntax
 endfunction
 

From 88f040680dec87c278f1e9481a0220d0fc58b625 Mon Sep 17 00:00:00 2001
From: Henry Kupty <hkupty@gmail.com>
Date: Mon, 27 Mar 2017 17:26:39 -0300
Subject: [PATCH 06/19] Asynchronously working

---
 autoload/vim_clojure_highlight.vim | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/autoload/vim_clojure_highlight.vim b/autoload/vim_clojure_highlight.vim
index ee162a7..c2d302c 100644
--- a/autoload/vim_clojure_highlight.vim
+++ b/autoload/vim_clojure_highlight.vim
@@ -5,18 +5,15 @@ function! AsyncCljHighlightHandle(msg)
   if exists =~ 'nil'
       let buf = join(readfile(globpath(&runtimepath, 'autoload/vim_clojure_highlight.clj')), "\n")
       call AcidSendNrepl({'op': 'eval', 'code': "(do ". buf . ")"}, 'Ignore')
-      let opts = (a:0 > 0 && !a:1) ? ' :local-vars false' : ''
-
-      let ns = AcidGetNs()
-
-      call AcidSendNrepl({"op": "eval", "code": "(vim-clojure-highlight/ns-syntax-command " . ns . opts . ")"}, 'VimFn', 'AsyncCljHighlightExec')
   endif
+    let opts = (a:0 > 0 && !a:1) ? ' :local-vars false' : ''
+    let ns = AcidGetNs()
+    call AcidSendNrepl({"op": "eval", "code": "(vim-clojure-highlight/ns-syntax-command '" . ns . opts . ")"}, 'VimFn', 'AsyncCljHighlightExec')
 endfunction
 
 function! AsyncCljHighlightExec(msg)
   let ret = a:msg[0]['value']
-  echom ret
-  exec ret
+  exec eval(ret)
   let &syntax = &syntax
 endfunction
 

From 2393eaf9f79b33f5d18485bff4c46997ac2349a3 Mon Sep 17 00:00:00 2001
From: Henry Kupty <hkupty@gmail.com>
Date: Mon, 27 Mar 2017 17:29:40 -0300
Subject: [PATCH 07/19] Move fn

---
 autoload/vim_clojure_highlight.vim | 17 -----------
 plugin/vim_clojure_highlight.vim   | 47 ++++++++++++++++++++----------
 2 files changed, 31 insertions(+), 33 deletions(-)

diff --git a/autoload/vim_clojure_highlight.vim b/autoload/vim_clojure_highlight.vim
index c2d302c..12eba2e 100644
--- a/autoload/vim_clojure_highlight.vim
+++ b/autoload/vim_clojure_highlight.vim
@@ -1,22 +1,5 @@
 " vim-clojure-highlight
 
-function! AsyncCljHighlightHandle(msg)
-  let exists = a:msg[0]['value']
-  if exists =~ 'nil'
-      let buf = join(readfile(globpath(&runtimepath, 'autoload/vim_clojure_highlight.clj')), "\n")
-      call AcidSendNrepl({'op': 'eval', 'code': "(do ". buf . ")"}, 'Ignore')
-  endif
-    let opts = (a:0 > 0 && !a:1) ? ' :local-vars false' : ''
-    let ns = AcidGetNs()
-    call AcidSendNrepl({"op": "eval", "code": "(vim-clojure-highlight/ns-syntax-command '" . ns . opts . ")"}, 'VimFn', 'AsyncCljHighlightExec')
-endfunction
-
-function! AsyncCljHighlightExec(msg)
-  let ret = a:msg[0]['value']
-  exec eval(ret)
-  let &syntax = &syntax
-endfunction
-
 " Pass zero explicitly to prevent highlighting local vars
 function! vim_clojure_highlight#syntax_match_references(...)
     call AcidSendNrepl({'op': 'eval', 'code': "(find-ns 'vim-clojure-highlight)"}, 'VimFn', 'AsyncCljHighlightHandle')
diff --git a/plugin/vim_clojure_highlight.vim b/plugin/vim_clojure_highlight.vim
index 589ba99..1896303 100644
--- a/plugin/vim_clojure_highlight.vim
+++ b/plugin/vim_clojure_highlight.vim
@@ -1,36 +1,51 @@
 " vim-clojure-highlight
 
 if !exists('g:clojure_highlight_references')
-	let g:clojure_highlight_references = 1
+  let g:clojure_highlight_references = 1
 endif
 
 if !exists('g:clojure_highlight_local_vars')
-	let g:clojure_highlight_local_vars = 1
+  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
+  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
+  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
+  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
+function! AsyncCljHighlightHandle(msg)
+  let exists = a:msg[0]['value']
+  if exists =~ 'nil'
+      let buf = join(readfile(globpath(&runtimepath, 'autoload/vim_clojure_highlight.clj')), "\n")
+      call AcidSendNrepl({'op': 'eval', 'code': "(do ". buf . ")"}, 'Ignore')
+  endif
+    let opts = (a:0 > 0 && !a:1) ? ' :local-vars false' : ''
+    let ns = AcidGetNs()
+    call AcidSendNrepl({"op": "eval", "code": "(vim-clojure-highlight/ns-syntax-command '" . ns . opts . ")"}, 'VimFn', 'AsyncCljHighlightExec')
+endfunction
+
+function! AsyncCljHighlightExec(msg)
+  let ret = a:msg[0]['value']
+  exec eval(ret)
+  let &syntax = &syntax
+endfunction

From b6d7552bb4660b462bd7cfb99c13cf45a498d0e0 Mon Sep 17 00:00:00 2001
From: Henry Kupty <hkupty@gmail.com>
Date: Mon, 27 Mar 2017 18:36:30 -0300
Subject: [PATCH 08/19] Avoid errors to explode

---
 plugin/vim_clojure_highlight.vim | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/plugin/vim_clojure_highlight.vim b/plugin/vim_clojure_highlight.vim
index 1896303..71910e0 100644
--- a/plugin/vim_clojure_highlight.vim
+++ b/plugin/vim_clojure_highlight.vim
@@ -45,7 +45,13 @@ function! AsyncCljHighlightHandle(msg)
 endfunction
 
 function! AsyncCljHighlightExec(msg)
-  let ret = a:msg[0]['value']
-  exec eval(ret)
-  let &syntax = &syntax
+  let fst = a:msg[0]
+  if get(fst, 'value', '') !=# ''
+    exec eval(fst.value)
+    let &syntax = &syntax
+  elseif get(fst, 'err', '') !=# ''
+    echohl ErrorMSG
+    echo fst.err
+    echohl NONE
+  endif
 endfunction

From b745b821882aeea36c71588bb6ca9ada836ff5c2 Mon Sep 17 00:00:00 2001
From: Henry Kupty <hkupty@gmail.com>
Date: Mon, 27 Mar 2017 19:06:19 -0300
Subject: [PATCH 09/19] Hook last part into

---
 plugin/vim_clojure_highlight.vim | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/plugin/vim_clojure_highlight.vim b/plugin/vim_clojure_highlight.vim
index 71910e0..f9509cb 100644
--- a/plugin/vim_clojure_highlight.vim
+++ b/plugin/vim_clojure_highlight.vim
@@ -33,15 +33,29 @@ augroup END
 command! -bar ToggleClojureHighlightReferences call s:toggle_clojure_highlight_references()
 command! -bar ClojureHighlightReferences call s:syntax_match_references()
 
+function! AsyncCljRequestHighlight(...)
+  if a:0 > 0
+    let fst = a:1
+    if get(fst, 'err', '') !=# ''
+      echohl ErrorMSG
+      echo fst.err
+      echohl NONE
+      return
+    endif
+  endif
+
+  let ns = AcidGetNs()
+  let opts = g:clojure_highlight_local_vars ? '' : ' :local-vars false'
+  call AcidSendNrepl({"op": "eval", "code": "(vim-clojure-highlight/ns-syntax-command '" . ns . opts . ")"}, 'VimFn', 'AsyncCljHighlightExec')
+endfunction
+
 function! AsyncCljHighlightHandle(msg)
   let exists = a:msg[0]['value']
   if exists =~ 'nil'
       let buf = join(readfile(globpath(&runtimepath, 'autoload/vim_clojure_highlight.clj')), "\n")
-      call AcidSendNrepl({'op': 'eval', 'code': "(do ". buf . ")"}, 'Ignore')
+      call AcidSendNrepl({'op': 'eval', 'code': "(do ". buf . ")"}, 'VimFn', 'AsyncCljRequestHighlight')
   endif
-    let opts = (a:0 > 0 && !a:1) ? ' :local-vars false' : ''
-    let ns = AcidGetNs()
-    call AcidSendNrepl({"op": "eval", "code": "(vim-clojure-highlight/ns-syntax-command '" . ns . opts . ")"}, 'VimFn', 'AsyncCljHighlightExec')
+  call AsyncCljRequestHighlight()
 endfunction
 
 function! AsyncCljHighlightExec(msg)

From 49b22d76066b18037925e91091af88755fd2b1aa Mon Sep 17 00:00:00 2001
From: Henry Kupty <hkupty@gmail.com>
Date: Mon, 27 Mar 2017 20:51:50 -0300
Subject: [PATCH 10/19] Rename and restructure

---
 autoload/vim_clojure_highlight.vim            |  6 --
 .../async_clj_highlight.clj                   |  2 +-
 ..._highlight.vim => async_clj_highlight.vim} | 65 ++++++++++---------
 3 files changed, 34 insertions(+), 39 deletions(-)
 delete mode 100644 autoload/vim_clojure_highlight.vim
 rename autoload/vim_clojure_highlight.clj => clj/async_clj_highlight.clj (99%)
 rename plugin/{vim_clojure_highlight.vim => async_clj_highlight.vim} (80%)

diff --git a/autoload/vim_clojure_highlight.vim b/autoload/vim_clojure_highlight.vim
deleted file mode 100644
index 12eba2e..0000000
--- a/autoload/vim_clojure_highlight.vim
+++ /dev/null
@@ -1,6 +0,0 @@
-" vim-clojure-highlight
-
-" Pass zero explicitly to prevent highlighting local vars
-function! vim_clojure_highlight#syntax_match_references(...)
-    call AcidSendNrepl({'op': 'eval', 'code': "(find-ns 'vim-clojure-highlight)"}, 'VimFn', 'AsyncCljHighlightHandle')
-endfunction
diff --git a/autoload/vim_clojure_highlight.clj b/clj/async_clj_highlight.clj
similarity index 99%
rename from autoload/vim_clojure_highlight.clj
rename to clj/async_clj_highlight.clj
index 384df5f..a97c4c6 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)))
diff --git a/plugin/vim_clojure_highlight.vim b/plugin/async_clj_highlight.vim
similarity index 80%
rename from plugin/vim_clojure_highlight.vim
rename to plugin/async_clj_highlight.vim
index f9509cb..79a7341 100644
--- a/plugin/vim_clojure_highlight.vim
+++ b/plugin/async_clj_highlight.vim
@@ -8,31 +8,18 @@ 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
+function! AsyncCljHighlightExec(msg)
+  let fst = a:msg[0]
+  if get(fst, 'value', '') !=# ''
+    exec eval(fst.value)
     let &syntax = &syntax
+  elseif get(fst, 'err', '') !=# ''
+    echohl ErrorMSG
+    echo fst.err
+    echohl NONE
   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()
-
 function! AsyncCljRequestHighlight(...)
   if a:0 > 0
     let fst = a:1
@@ -46,26 +33,40 @@ function! AsyncCljRequestHighlight(...)
 
   let ns = AcidGetNs()
   let opts = g:clojure_highlight_local_vars ? '' : ' :local-vars false'
-  call AcidSendNrepl({"op": "eval", "code": "(vim-clojure-highlight/ns-syntax-command '" . ns . opts . ")"}, 'VimFn', 'AsyncCljHighlightExec')
+  call AcidSendNrepl({"op": "eval", "code": "(async-clj-highlight/ns-syntax-command '" . ns . opts . ")"}, 'VimFn', 'AsyncCljHighlightExec')
 endfunction
 
-function! AsyncCljHighlightHandle(msg)
+function! AsyncCljHighlightPrepare(msg)
   let exists = a:msg[0]['value']
   if exists =~ 'nil'
-      let buf = join(readfile(globpath(&runtimepath, 'autoload/vim_clojure_highlight.clj')), "\n")
+      let buf = join(readfile(globpath(&runtimepath, 'clj/async_clj_highlight.clj')), "\n")
       call AcidSendNrepl({'op': 'eval', 'code': "(do ". buf . ")"}, 'VimFn', 'AsyncCljRequestHighlight')
   endif
   call AsyncCljRequestHighlight()
 endfunction
 
-function! AsyncCljHighlightExec(msg)
-  let fst = a:msg[0]
-  if get(fst, 'value', '') !=# ''
-    exec eval(fst.value)
+function! s:syntax_match_references()
+  if g:clojure_highlight_references
+    call AcidSendNrepl({'op': 'eval', 'code': "(find-ns 'vim-clojure-highlight)"}, 'VimFn', 'AsyncCljHighlightPrepare')
+  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
-  elseif get(fst, 'err', '') !=# ''
-    echohl ErrorMSG
-    echo fst.err
-    echohl NONE
   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()
+

From 92a0c3b811d250287240ece55c5c9b4ad27da6d9 Mon Sep 17 00:00:00 2001
From: Henry Kupty <hkupty@gmail.com>
Date: Tue, 28 Mar 2017 17:29:01 -0300
Subject: [PATCH 11/19] Enhancements

---
 plugin/async_clj_highlight.vim | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/plugin/async_clj_highlight.vim b/plugin/async_clj_highlight.vim
index 79a7341..d8c4c45 100644
--- a/plugin/async_clj_highlight.vim
+++ b/plugin/async_clj_highlight.vim
@@ -21,14 +21,11 @@ function! AsyncCljHighlightExec(msg)
 endfunction
 
 function! AsyncCljRequestHighlight(...)
-  if a:0 > 0
-    let fst = a:1
-    if get(fst, 'err', '') !=# ''
-      echohl ErrorMSG
-      echo fst.err
-      echohl NONE
-      return
-    endif
+  if a:0 > 0 && get(a:1[0], 'err', 0)
+    echohl ErrorMSG
+    echo a:1[0].err
+    echohl NONE
+    return
   endif
 
   let ns = AcidGetNs()
@@ -37,7 +34,7 @@ function! AsyncCljRequestHighlight(...)
 endfunction
 
 function! AsyncCljHighlightPrepare(msg)
-  let exists = a:msg[0]['value']
+  let exists = a:msg[0].value
   if exists =~ 'nil'
       let buf = join(readfile(globpath(&runtimepath, 'clj/async_clj_highlight.clj')), "\n")
       call AcidSendNrepl({'op': 'eval', 'code': "(do ". buf . ")"}, 'VimFn', 'AsyncCljRequestHighlight')
@@ -47,7 +44,7 @@ endfunction
 
 function! s:syntax_match_references()
   if g:clojure_highlight_references
-    call AcidSendNrepl({'op': 'eval', 'code': "(find-ns 'vim-clojure-highlight)"}, 'VimFn', 'AsyncCljHighlightPrepare')
+    call AcidSendNrepl({'op': 'eval', 'code': "(find-ns 'async-clj-highlight)"}, 'VimFn', 'AsyncCljHighlightPrepare')
   endif
 endfunction
 

From 492691360ee38b4bf955a1e5d53bb30cb5a7ecbd Mon Sep 17 00:00:00 2001
From: Henry Kupty <hkupty@gmail.com>
Date: Tue, 28 Mar 2017 17:29:45 -0300
Subject: [PATCH 12/19] Run after acid finished requiring current file

---
 plugin/async_clj_highlight.vim | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/plugin/async_clj_highlight.vim b/plugin/async_clj_highlight.vim
index d8c4c45..0609477 100644
--- a/plugin/async_clj_highlight.vim
+++ b/plugin/async_clj_highlight.vim
@@ -59,11 +59,10 @@ function! s:toggle_clojure_highlight_references()
   endif
 endfunction
 
-augroup vim_clojure_highlight
+augroup async_clj_highlight
   autocmd!
-  autocmd BufRead *.clj ClojureHighlightReferences
+  autocmd User AcidRequired ClojureHighlightReferences
 augroup END
 
 command! -bar ToggleClojureHighlightReferences call s:toggle_clojure_highlight_references()
 command! -bar ClojureHighlightReferences call s:syntax_match_references()
-

From 99e39b57d6ac3d1725971f33bff8671263cdc655 Mon Sep 17 00:00:00 2001
From: Henry Kupty <hkupty@gmail.com>
Date: Wed, 29 Mar 2017 14:54:50 -0300
Subject: [PATCH 13/19] Don't saturate the nrepl with several requests

---
 plugin/async_clj_highlight.vim | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/plugin/async_clj_highlight.vim b/plugin/async_clj_highlight.vim
index 0609477..1ca0de1 100644
--- a/plugin/async_clj_highlight.vim
+++ b/plugin/async_clj_highlight.vim
@@ -13,6 +13,7 @@ function! AsyncCljHighlightExec(msg)
   if get(fst, 'value', '') !=# ''
     exec eval(fst.value)
     let &syntax = &syntax
+    let b:async_clj_updated_highlight = 1
   elseif get(fst, 'err', '') !=# ''
     echohl ErrorMSG
     echo fst.err
@@ -42,8 +43,8 @@ function! AsyncCljHighlightPrepare(msg)
   call AsyncCljRequestHighlight()
 endfunction
 
-function! s:syntax_match_references()
-  if g:clojure_highlight_references
+function! s:syntax_match_references(bang)
+  if g:clojure_highlight_references && (a:bang || !exists('b:b:async_clj_updated_highlight'))
     call AcidSendNrepl({'op': 'eval', 'code': "(find-ns 'async-clj-highlight)"}, 'VimFn', 'AsyncCljHighlightPrepare')
   endif
 endfunction
@@ -64,5 +65,5 @@ augroup async_clj_highlight
   autocmd User AcidRequired ClojureHighlightReferences
 augroup END
 
-command! -bar ToggleClojureHighlightReferences call s:toggle_clojure_highlight_references()
-command! -bar ClojureHighlightReferences call s:syntax_match_references()
+command! -bar       ToggleClojureHighlightReferences call s:toggle_clojure_highlight_references()
+command! -bar -bang ClojureHighlightReferences call s:syntax_match_references(<bang>)

From d188858271e38669b2401d559aefa5f77c2e88d6 Mon Sep 17 00:00:00 2001
From: Henry Kupty <hkupty@gmail.com>
Date: Wed, 29 Mar 2017 14:55:58 -0300
Subject: [PATCH 14/19] Allow force highlight to be mapped

---
 plugin/async_clj_highlight.vim | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/plugin/async_clj_highlight.vim b/plugin/async_clj_highlight.vim
index 1ca0de1..ca695ce 100644
--- a/plugin/async_clj_highlight.vim
+++ b/plugin/async_clj_highlight.vim
@@ -67,3 +67,5 @@ augroup END
 
 command! -bar       ToggleClojureHighlightReferences call s:toggle_clojure_highlight_references()
 command! -bar -bang ClojureHighlightReferences call s:syntax_match_references(<bang>)
+
+map <plug>AsyncCljDoHighlight :ClojureHighlightReferences!<CR>

From b4251031a5b710a9410eb39d8986d89910db4104 Mon Sep 17 00:00:00 2001
From: Henry Kupty <hkupty@gmail.com>
Date: Wed, 29 Mar 2017 14:59:04 -0300
Subject: [PATCH 15/19] Missing 0s

---
 plugin/async_clj_highlight.vim | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/plugin/async_clj_highlight.vim b/plugin/async_clj_highlight.vim
index ca695ce..14e125d 100644
--- a/plugin/async_clj_highlight.vim
+++ b/plugin/async_clj_highlight.vim
@@ -53,7 +53,7 @@ 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()
+    call s:syntax_match_references(0)
   else
     unlet! b:clojure_syntax_keywords b:clojure_syntax_without_core_keywords
     let &syntax = &syntax
@@ -66,6 +66,6 @@ augroup async_clj_highlight
 augroup END
 
 command! -bar       ToggleClojureHighlightReferences call s:toggle_clojure_highlight_references()
-command! -bar -bang ClojureHighlightReferences call s:syntax_match_references(<bang>)
+command! -bar -bang ClojureHighlightReferences call s:syntax_match_references(<bang>0)
 
 map <plug>AsyncCljDoHighlight :ClojureHighlightReferences!<CR>

From 20e706407b81451f1f4922c07ccf65be6ee0f56a Mon Sep 17 00:00:00 2001
From: Henry Kupty <hkupty@gmail.com>
Date: Mon, 3 Apr 2017 19:03:36 -0300
Subject: [PATCH 16/19] Silent highlight

---
 plugin/async_clj_highlight.vim | 28 +++++++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)

diff --git a/plugin/async_clj_highlight.vim b/plugin/async_clj_highlight.vim
index 14e125d..850280d 100644
--- a/plugin/async_clj_highlight.vim
+++ b/plugin/async_clj_highlight.vim
@@ -8,6 +8,28 @@ if !exists('g:clojure_highlight_local_vars')
   let g:clojure_highlight_local_vars = 1
 endif
 
+function! s:disable_acid_log()
+  if exists('b:acid_log_messages')
+    let b:acid_old_log_value = b:acid_log_messages
+  else
+    let b:acid_log_messages = 0
+  endif
+endfunction
+
+function! s:restore_acid_log()
+  if exists('b:acid_old_log_value')
+    let b:acid_log_messages = b:acid_old_log_value
+  else
+    unlet b:acid_log_messages
+  endif
+endfunction
+
+function! s:silent_acid_send(data, handler_fn)
+  call s:disable_acid_log()
+  call AcidSendNrepl(a:data, 'VimFn', a:handler_fn)
+  call s:restore_acid_log()
+endfunction
+
 function! AsyncCljHighlightExec(msg)
   let fst = a:msg[0]
   if get(fst, 'value', '') !=# ''
@@ -31,21 +53,21 @@ function! AsyncCljRequestHighlight(...)
 
   let ns = AcidGetNs()
   let opts = g:clojure_highlight_local_vars ? '' : ' :local-vars false'
-  call AcidSendNrepl({"op": "eval", "code": "(async-clj-highlight/ns-syntax-command '" . ns . opts . ")"}, 'VimFn', 'AsyncCljHighlightExec')
+  call s:silen_acid_send({"op": "eval", "code": "(async-clj-highlight/ns-syntax-command '" . ns . opts . ")"}, 'AsyncCljHighlightExec')
 endfunction
 
 function! AsyncCljHighlightPrepare(msg)
   let exists = a:msg[0].value
   if exists =~ 'nil'
       let buf = join(readfile(globpath(&runtimepath, 'clj/async_clj_highlight.clj')), "\n")
-      call AcidSendNrepl({'op': 'eval', 'code': "(do ". buf . ")"}, 'VimFn', 'AsyncCljRequestHighlight')
+      call s:silen_acid_send({'op': 'eval', 'code': "(do ". buf . ")"}, 'AsyncCljRequestHighlight')
   endif
   call AsyncCljRequestHighlight()
 endfunction
 
 function! s:syntax_match_references(bang)
   if g:clojure_highlight_references && (a:bang || !exists('b:b:async_clj_updated_highlight'))
-    call AcidSendNrepl({'op': 'eval', 'code': "(find-ns 'async-clj-highlight)"}, 'VimFn', 'AsyncCljHighlightPrepare')
+    call s:silen_acid_send({'op': 'eval', 'code': "(find-ns 'async-clj-highlight)"}, 'AsyncCljHighlightPrepare')
   endif
 endfunction
 

From 589f4c53e9b6d9d3df140d6bb94cd907c25fbec3 Mon Sep 17 00:00:00 2001
From: Henry Kupty <hkupty@gmail.com>
Date: Mon, 3 Apr 2017 19:06:15 -0300
Subject: [PATCH 17/19] Debug

---
 plugin/async_clj_highlight.vim | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/plugin/async_clj_highlight.vim b/plugin/async_clj_highlight.vim
index 850280d..5f68265 100644
--- a/plugin/async_clj_highlight.vim
+++ b/plugin/async_clj_highlight.vim
@@ -19,6 +19,7 @@ endfunction
 function! s:restore_acid_log()
   if exists('b:acid_old_log_value')
     let b:acid_log_messages = b:acid_old_log_value
+    unlet b:acid_old_log_value
   else
     unlet b:acid_log_messages
   endif
@@ -26,6 +27,7 @@ endfunction
 
 function! s:silent_acid_send(data, handler_fn)
   call s:disable_acid_log()
+  echom "Disabled log: ".b:acid_log_messages
   call AcidSendNrepl(a:data, 'VimFn', a:handler_fn)
   call s:restore_acid_log()
 endfunction

From c91fb589f0f817fe4b821f66c05287f24f9e996c Mon Sep 17 00:00:00 2001
From: Henry Kupty <hkupty@gmail.com>
Date: Mon, 3 Apr 2017 19:08:20 -0300
Subject: [PATCH 18/19] Fix typo

---
 plugin/async_clj_highlight.vim | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/plugin/async_clj_highlight.vim b/plugin/async_clj_highlight.vim
index 5f68265..c32c82a 100644
--- a/plugin/async_clj_highlight.vim
+++ b/plugin/async_clj_highlight.vim
@@ -55,21 +55,21 @@ function! AsyncCljRequestHighlight(...)
 
   let ns = AcidGetNs()
   let opts = g:clojure_highlight_local_vars ? '' : ' :local-vars false'
-  call s:silen_acid_send({"op": "eval", "code": "(async-clj-highlight/ns-syntax-command '" . ns . opts . ")"}, 'AsyncCljHighlightExec')
+  call s:silent_acid_send({"op": "eval", "code": "(async-clj-highlight/ns-syntax-command '" . ns . opts . ")"}, 'AsyncCljHighlightExec')
 endfunction
 
 function! AsyncCljHighlightPrepare(msg)
   let exists = a:msg[0].value
   if exists =~ 'nil'
       let buf = join(readfile(globpath(&runtimepath, 'clj/async_clj_highlight.clj')), "\n")
-      call s:silen_acid_send({'op': 'eval', 'code': "(do ". buf . ")"}, 'AsyncCljRequestHighlight')
+      call s:silent_acid_send({'op': 'eval', 'code': "(do ". buf . ")"}, 'AsyncCljRequestHighlight')
   endif
   call AsyncCljRequestHighlight()
 endfunction
 
 function! s:syntax_match_references(bang)
   if g:clojure_highlight_references && (a:bang || !exists('b:b:async_clj_updated_highlight'))
-    call s:silen_acid_send({'op': 'eval', 'code': "(find-ns 'async-clj-highlight)"}, 'AsyncCljHighlightPrepare')
+    call s:silent_acid_send({'op': 'eval', 'code': "(find-ns 'async-clj-highlight)"}, 'AsyncCljHighlightPrepare')
   endif
 endfunction
 

From d69aa1e76a5e691d35cf1ef64460f0ab0fd4f516 Mon Sep 17 00:00:00 2001
From: Henry Kupty <hkupty@gmail.com>
Date: Mon, 1 Apr 2019 18:21:40 +0200
Subject: [PATCH 19/19] Migrate to lua

---
 clj/async_clj_highlight.clj    |  2 +-
 lua/cljhl/init.lua             | 66 +++++++++++++++++++++++++
 plugin/async_clj_highlight.vim | 88 +++-------------------------------
 3 files changed, 73 insertions(+), 83 deletions(-)
 create mode 100644 lua/cljhl/init.lua

diff --git a/clj/async_clj_highlight.clj b/clj/async_clj_highlight.clj
index a97c4c6..60ff836 100644
--- a/clj/async_clj_highlight.clj
+++ b/clj/async_clj_highlight.clj
@@ -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
index c32c82a..3633f1d 100644
--- a/plugin/async_clj_highlight.vim
+++ b/plugin/async_clj_highlight.vim
@@ -1,95 +1,19 @@
 " 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:disable_acid_log()
-  if exists('b:acid_log_messages')
-    let b:acid_old_log_value = b:acid_log_messages
-  else
-    let b:acid_log_messages = 0
-  endif
-endfunction
-
-function! s:restore_acid_log()
-  if exists('b:acid_old_log_value')
-    let b:acid_log_messages = b:acid_old_log_value
-    unlet b:acid_old_log_value
-  else
-    unlet b:acid_log_messages
-  endif
-endfunction
-
-function! s:silent_acid_send(data, handler_fn)
-  call s:disable_acid_log()
-  echom "Disabled log: ".b:acid_log_messages
-  call AcidSendNrepl(a:data, 'VimFn', a:handler_fn)
-  call s:restore_acid_log()
-endfunction
-
-function! AsyncCljHighlightExec(msg)
-  let fst = a:msg[0]
-  if get(fst, 'value', '') !=# ''
-    exec eval(fst.value)
-    let &syntax = &syntax
-    let b:async_clj_updated_highlight = 1
-  elseif get(fst, 'err', '') !=# ''
-    echohl ErrorMSG
-    echo fst.err
-    echohl NONE
-  endif
-endfunction
-
-function! AsyncCljRequestHighlight(...)
-  if a:0 > 0 && get(a:1[0], 'err', 0)
-    echohl ErrorMSG
-    echo a:1[0].err
-    echohl NONE
-    return
-  endif
-
-  let ns = AcidGetNs()
-  let opts = g:clojure_highlight_local_vars ? '' : ' :local-vars false'
-  call s:silent_acid_send({"op": "eval", "code": "(async-clj-highlight/ns-syntax-command '" . ns . opts . ")"}, 'AsyncCljHighlightExec')
+function! AsyncCljHighlightExec(value)
+  exec eval(a:value)
+  let &syntax = &syntax
 endfunction
 
-function! AsyncCljHighlightPrepare(msg)
-  let exists = a:msg[0].value
-  if exists =~ 'nil'
-      let buf = join(readfile(globpath(&runtimepath, 'clj/async_clj_highlight.clj')), "\n")
-      call s:silent_acid_send({'op': 'eval', 'code': "(do ". buf . ")"}, 'AsyncCljRequestHighlight')
-  endif
-  call AsyncCljRequestHighlight()
-endfunction
-
-function! s:syntax_match_references(bang)
-  if g:clojure_highlight_references && (a:bang || !exists('b:b:async_clj_updated_highlight'))
-    call s:silent_acid_send({'op': 'eval', 'code': "(find-ns 'async-clj-highlight)"}, 'AsyncCljHighlightPrepare')
-  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(0)
-  else
-    unlet! b:clojure_syntax_keywords b:clojure_syntax_without_core_keywords
-    let &syntax = &syntax
-  endif
-endfunction
+command! -bar -bang ClojureAsyncHighlight call luaeval("require('cljhl').preload()")
 
 augroup async_clj_highlight
   autocmd!
-  autocmd User AcidRequired ClojureHighlightReferences
+  autocmd User AcidLoadedAllNSs ClojureAsyncHighlight
+  autocmd User AcidRequired ClojureAsyncHighlight
 augroup END
 
-command! -bar       ToggleClojureHighlightReferences call s:toggle_clojure_highlight_references()
-command! -bar -bang ClojureHighlightReferences call s:syntax_match_references(<bang>0)
-
-map <plug>AsyncCljDoHighlight :ClojureHighlightReferences!<CR>
