feat(emacs/lean-flycheck): override flycheck-try-parse-error-with-pattern

For lean-mode, we override flycheck-try-parse-error-with-pattern to
increase column number by 1. It uses defadvice.
This commit is contained in:
Soonho Kong 2014-08-14 11:21:09 -07:00
parent be8ee8b3c0
commit 99e77db8ad

View file

@ -68,4 +68,33 @@
(add-hook 'lean-mode-hook '(lambda ()
(when lean-flycheck-use (lean-flycheck-turn-on))))
(defun lean-flycheck-try-parse-error-with-pattern (err pattern)
"Try to parse a single ERR with a PATTERN.
Return the parsed error if PATTERN matched ERR, or nil
otherwise."
(let ((regexp (car pattern))
(level (cdr pattern)))
(when (string-match regexp err)
(let ((filename (match-string 1 err))
(line (match-string 2 err))
(column (match-string 3 err))
(message (match-string 4 err)))
(flycheck-error-new
:filename (unless (string-empty-p filename) filename)
:line (flycheck-string-to-number-safe line)
:column (let ((col (flycheck-string-to-number-safe column)))
(if (= col 0) 1 col))
:message (unless (string-empty-p message) message)
:level level)))))
(eval-after-load "flycheck.el"
'(defadvice flycheck-try-parse-error-with-pattern
(after lean-flycheck-try-parse-error-with-pattern activate)
"Add 1 to error-column."
(let* ((err ad-return-value)
(col (flycheck-error-column err)))
(when (and (string= major-mode "lean-mode") col)
(setf (flycheck-error-column ad-return-value) (1+ col))))))
(provide 'lean-flycheck)