feat(emacs): add lean-flycheck-turn-on/off/toggle

This commit is contained in:
Soonho Kong 2014-08-07 13:48:08 -07:00
parent b684af5cdb
commit 88ef5d68f9
2 changed files with 60 additions and 24 deletions

View file

@ -4,29 +4,65 @@
;; Author: Soonho Kong ;; Author: Soonho Kong
;; ;;
(when lean-use-flycheck (defvar-local lean-flycheck-initialized nil
(require 'flycheck) "Return true if lean-flycheck has been initialized")
(setq-local lean-lmake-name "lmake") (defvar-local lean-flycheck-lmake-name "lmake"
(setq-local lean-lmake-options "--flycheck") "lmake name")
(eval (defvar-local lean-flycheck-lmake-options "--flycheck"
`(flycheck-define-checker lean-checker-file "flycheck option for lean")
"A Lean syntax checker (file)."
:command (,(lean-get-executable lean-lmake-name) ,lean-lmake-options source-inplace) (defun lean-flycheck-init ()
:error-patterns "Initialize lean-flychek checker"
((error line-start "FLYCHECK_BEGIN ERROR\n" (unless lean-flycheck-initialized
(file-name) ":" line ":" column ": error: " (require 'flycheck)
(minimal-match (eval
(message (one-or-more (one-or-more not-newline) "\n") )) `(flycheck-define-checker lean-checker-file
"FLYCHECK_END" line-end) "A Lean syntax checker (file)."
(warning line-start "FLYCHECK_BEGIN WARNING\n" :command (,(lean-get-executable lean-flycheck-lmake-name)
(file-name) ":" line ":" column ": warning " ,lean-flycheck-lmake-options
source-inplace)
:error-patterns
((error line-start "FLYCHECK_BEGIN ERROR\n"
(file-name) ":" line ":" column ": error: "
(minimal-match (minimal-match
(message (one-or-more (one-or-more not-newline) "\n") )) (message (one-or-more (one-or-more not-newline) "\n") ))
"FLYCHECK_END" line-end)) "FLYCHECK_END" line-end)
:modes (lean-mode) (warning line-start "FLYCHECK_BEGIN WARNING\n"
:predicate (file-name) ":" line ":" column ": warning "
(lambda () (and buffer-file-name (minimal-match
(string= "lean" (file-name-extension buffer-file-name)))))) (message (one-or-more (one-or-more not-newline) "\n") ))
(add-to-list 'flycheck-checkers 'lean-checker-file) "FLYCHECK_END" line-end))
(add-hook 'lean-mode-hook '(lambda () (flycheck-mode t)))) :modes (lean-mode)
:predicate
(lambda () (and buffer-file-name
(string= "lean" (file-name-extension buffer-file-name))))))
(add-to-list 'flycheck-checkers 'lean-checker-file)
(setq lean-flycheck-initialized t)))
(defun lean-flycheck-turn-on ()
(interactive)
(unless lean-flycheck-use
(when (interactive-p)
(message "use flycheck in lean-mode"))
(setq lean-flycheck-use t))
(lean-flycheck-init)
(flycheck-mode t))
(defun lean-flycheck-turn-off ()
(interactive)
(when lean-flycheck-use
(when (interactive-p)
(message "no flycheck in lean-mode")))
(flycheck-mode 0)
(setq lean-flycheck-use nil))
(defun lean-flycheck-toggle-use ()
(interactive)
(if lean-flycheck-use
(lean-flycheck-turn-off)
(lean-flycheck-turn-on)))
(add-hook 'lean-mode-hook '(lambda ()
(when lean-flycheck-use (lean-flycheck-turn-on))))
(provide 'lean-flycheck) (provide 'lean-flycheck)

View file

@ -30,7 +30,7 @@
:group 'lean :group 'lean
:type 'string) :type 'string)
(defcustom lean-use-flycheck t (defcustom lean-flycheck-use t
"Use flycheck for lean." "Use flycheck for lean."
:group 'lean :group 'lean
:type 'boolean) :type 'boolean)