]> git.eshelyaron.com Git - emacs.git/commitdiff
Protect Flymake's eager checks against commands like fill-paragraph
authorJoão Távora <joaotavora@gmail.com>
Fri, 22 Sep 2017 00:31:23 +0000 (01:31 +0100)
committerJoão Távora <joaotavora@gmail.com>
Mon, 2 Oct 2017 23:59:25 +0000 (00:59 +0100)
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.

lisp/progmodes/flymake.el

index 6cc503ad639ea43682416a0592a5f02eb4081b95..cbe917e67087add77b4ea84046178921c9ac63de 100644 (file)
@@ -476,6 +476,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
@@ -539,7 +550,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 ()
@@ -591,9 +602,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")