From: João Távora Date: Fri, 22 Sep 2017 00:31:23 +0000 (+0100) Subject: Protect Flymake's eager checks against commands like fill-paragraph X-Git-Tag: emacs-26.0.90~56^2^2~23 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=b0bb181f9359aff07b09b919b8af397ef39d6784;p=emacs.git Protect Flymake's eager checks against commands like fill-paragraph If flymake-start-syntax-check-on-newline is t, check should start as soon as a newline is seen by after-change-functions. But don't rush it: since the buffer state might not be final, we might end up with invalid diagnostic regions after some commands silently insert and delete newlines (looking at you, fill-paragraph). * lisp/progmodes/flymake.el (flymake-after-change-function): Pass `deferred' to flymake--start-syntax-check. (flymake--start-syntax-check): Take optional `deferred' arg. --- diff --git a/lisp/progmodes/flymake.el b/lisp/progmodes/flymake.el index b32e799e672..b5abf5c6ffe 100644 --- a/lisp/progmodes/flymake.el +++ b/lisp/progmodes/flymake.el @@ -475,6 +475,17 @@ If TYPE doesn't declare PROP in either (flymake-report-status "" "") (flymake-report-status (format "%d/%d" err-count warn-count) ""))))) +(defun flymake--start-syntax-check (&optional deferred) + (cl-labels ((start + () + (remove-hook 'post-command-hook #'start 'local) + (setq flymake-check-start-time (float-time)) + (flymake-proc-start-syntax-check))) + (if (and deferred + this-command) + (add-hook 'post-command-hook #'start 'append 'local) + (start)))) + ;;;###autoload (define-minor-mode flymake-mode nil :group 'flymake :lighter flymake-mode-line @@ -538,7 +549,7 @@ If TYPE doesn't declare PROP in either (let((new-text (buffer-substring start stop))) (when (and flymake-start-syntax-check-on-newline (equal new-text "\n")) (flymake-log 3 "starting syntax check as new-line has been seen") - (flymake--start-syntax-check)) + (flymake--start-syntax-check 'deferred)) (setq flymake-last-change-time (float-time)))) (defun flymake-after-save-hook () @@ -590,9 +601,6 @@ If TYPE doesn't declare PROP in either (provide 'flymake) -(defun flymake--start-syntax-check () - (flymake-proc-start-syntax-check)) - (declare-function flymake-proc-start-syntax-check "flymake-proc") (declare-function flymake-can-syntax-check-file "flymake-proc")