emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] scratch/flymake-refactor-cleaner-for-emacs-26 0a4e420 16/3


From: João Távora
Subject: [Emacs-diffs] scratch/flymake-refactor-cleaner-for-emacs-26 0a4e420 16/39: Protect Flymake's eager checks against commands like fill-paragraph
Date: Mon, 2 Oct 2017 20:12:23 -0400 (EDT)

branch: scratch/flymake-refactor-cleaner-for-emacs-26
commit 0a4e420a66ad3e40d2c6df995ca9189e137f9590
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>

    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.
---
 lisp/progmodes/flymake.el | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/lisp/progmodes/flymake.el b/lisp/progmodes/flymake.el
index 6cc503a..cbe917e 100644
--- a/lisp/progmodes/flymake.el
+++ b/lisp/progmodes/flymake.el
@@ -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")
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]