Skip to content

Instantly share code, notes, and snippets.



Created Dec 11, 2014
What would you like to do?
Preliminary flycheck support for Clojure using Cider and Eastwood
;;; clj-fly.el --- Flycheck: Clojure support -*- lexical-binding: t; -*-
;;; Commentary:
;;; So far, this only invokes eastwood. It works best if flycheck-pos-tip is used, so as not to clash with Cider doc messages.
;;; Code:
(require 'cider-client)
(require 'flycheck)
(defun parse-eastwood (s)
"Parse an output line from eastwood: S."
(let ((r "^\\([^[:space:]]+\\)\\:\\([[:digit:]]+\\)\\:\\([[:digit:]]+\\)\\:[[:space:]]*\\(.*\\)")
;(s "bar:foo:bleh whee")
(if (string-match r s)
;;(mapcar (lambda (n) (match-string n s)) '(1 2 3 4))
(match-string 1 s) ;; file
(string-to-number (match-string 2 s)) ;; line
(string-to-number (match-string 3 s)) ;; col
(match-string 4 s) ;; msg
(defun flycheck-clj-cider-start (checker callback)
"Begin flychecking, with CHECKER and CALLBACK."
(let* ((buffer (current-buffer))
(ns (cider-current-ns))
(cmd (format "(do (require 'eastwood.lint)(eastwood.lint/eastwood {:source-paths [\"src\"] :namespaces ['%s] } ))"
(errors ()))
;;(message "here i am in start: %s" cmd)
(cider-eval cmd
(lambda (_buffer _value)
;;(message (prin1-to-string errors))
(funcall callback 'finished errors))
(lambda (_buffer out)
(mapc (lambda (w) (pcase-let* ((`(,file ,line ,column ,msg) w))
(flycheck-error-new-at line column 'error msg
:checker checker
:buffer buffer
:filename (buffer-file-name buffer)
(delq nil (mapcar 'parse-eastwood (split-string out "\n"))))
(lambda (_buffer err))
(flycheck-define-generic-checker 'clojure-cider-checker
"A syntax checker for Clojure using Cider"
:start #'flycheck-clj-cider-start
:modes '(clojure-mode)
(add-to-list 'flycheck-checkers 'clojure-cider-checker)
(provide 'clj-fly)
;;; clj-fly.el ends here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment