fix(emacs/lean-flycheck): fix bug in advice for lean-flycheck-try-parse-error-with-pattern

I provided an "advice" for 'flycheck-try-parse-error-with-pattern'
function to change its behavior, namely to increase error-columns by
one.

Bug
===

The problem is that it doesn't consider the case where the pattern is
not matched and ends up with "err = nil". For this case,
"(flycheck-error-column err)" generates an exception if executed. The
whole error parsing process stops immediately.

This causes a problem when we have more than one error-patterns, which
is the case when we enable 'error' and 'warning' patterns.

Fix
===

Fix is simple: check err before executing (flycheck-error-column err)

-            (col (flycheck-error-column err)))
+            (col (and err (flycheck-error-column err))))
This commit is contained in:
Soonho Kong 2014-11-24 05:06:51 -05:00
parent d81a6259e8
commit fe638f0ee7

View file

@ -29,25 +29,15 @@
"A Lean syntax checker."
:command ,(lean-flycheck-command)
:error-patterns
;; ((error line-start "FLYCHECK_BEGIN ERROR" (? "\r") "\n"
;; (file-name) ":" line ":" (? column ":") " error: "
;; (minimal-match
;; (message (+ (+ not-newline) (? "\r") "\n")))
;; "FLYCHECK_END" line-end)
;; (warning line-start "FLYCHECK_BEGIN WARNING" (? "\r") "\n"
;; (file-name) ":" line ":" (? column ":") " warning "
;; (minimal-match
;; (message (+ (* not-newline) (? "\r") "\n") ))
;; "FLYCHECK_END" line-end))
((error line-start "FLYCHECK_BEGIN ERROR" (? "\r") "\n"
(file-name) ":" line ":" (? column ":") " error: "
(minimal-match
(message (one-or-more (zero-or-more not-newline) (? "\r") "\n")))
"FLYCHECK_END" (? "\r") line-end)
(warning line-start "FLYCHECK_BEGIN WARNING" (? "\r") "\n"
(file-name) ":" line ":" (? column ":") " warning "
(file-name) ":" line ":" (? column ":") " warning: "
(minimal-match
(message (one-or-more (one-or-more not-newline) (? "\r") "\n")))
(message (one-or-more (zero-or-more not-newline) (? "\r") "\n")))
"FLYCHECK_END" (? "\r") line-end))
:modes (lean-mode)))
(add-to-list 'flycheck-checkers 'lean-checker))
@ -79,7 +69,7 @@
(after lean-flycheck-try-parse-error-with-pattern activate)
"Add 1 to error-column."
(let* ((err ad-return-value)
(col (flycheck-error-column err)))
(col (and err (flycheck-error-column err))))
(when (and (string= major-mode "lean-mode") col)
(setf (flycheck-error-column ad-return-value) (1+ col))))))