From fe638f0ee7119dbe5e67de3f1d4dbf70c1bf3cc7 Mon Sep 17 00:00:00 2001 From: Soonho Kong Date: Mon, 24 Nov 2014 05:06:51 -0500 Subject: [PATCH] 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)))) --- src/emacs/lean-flycheck.el | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/src/emacs/lean-flycheck.el b/src/emacs/lean-flycheck.el index 35307b102..a4c672878 100644 --- a/src/emacs/lean-flycheck.el +++ b/src/emacs/lean-flycheck.el @@ -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))))))