Skip to content

Instantly share code, notes, and snippets.

@eraserhd
Created April 4, 2018 20:58
Show Gist options
  • Save eraserhd/04efc2767f6c04aa232f6465c8f3d79d to your computer and use it in GitHub Desktop.
Save eraserhd/04efc2767f6c04aa232f6465c8f3d79d to your computer and use it in GitHub Desktop.
sign define compile_error text=xx texthl=ErrorMsg
function! Tapi_ClearSourceErrors(bufnum, arg)
silent! sign unplace 1
endfunction
function! Tapi_SourceError(bufnum, data)
execute "sign place 1 name=compile_error line=" . a:data[1] . " file=" . a:data[0]
endfunction
(defn- send-to-vim
[data]
{:pre [(sequential? data)]}
(when (System/getenv "VIMRUNTIME")
(print (str "\u001B]51;" (json/generate-string data) "\u0007"))))
(defn- find-source
[filename]
(or (->> (clojure.string/split (System/getProperty "java.class.path") #":")
(map #(str % "/" filename))
(filter #(.exists (io/as-file %)))
first)
filename))
(defn- nice-compile-error
[error]
(send-to-vim ["call" "Tapi_ClearSourceErrors" []])
(if (instance? clojure.lang.Compiler$CompilerException error)
(do
(println (str "\u001B[1;31m" (.getMessage error) "\u001B[0m"))
(send-to-vim ["call" "Tapi_SourceError" [(find-source (.-source error)) (.-line error)]])
:compile-error)
error))
(def refresh (comp nice-compile-error clojure.tools.namespace.repl/refresh))
(def refresh-all (comp nice-compile-error clojure.tools.namespace.repl/refresh-all))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment