aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoão Távora2017-10-09 11:12:57 +0100
committerJoão Távora2017-10-09 11:12:57 +0100
commit11b37b4a9f3a032f307ff644ed76b31c3133f718 (patch)
treeee6512e8668ab0455d2c47da68432530a7464e93
parent36ed9a9ede7057dbd30492ae88aab3b5b8c8f23a (diff)
downloademacs-11b37b4a9f3a032f307ff644ed76b31c3133f718.tar.gz
emacs-11b37b4a9f3a032f307ff644ed76b31c3133f718.zip
Be lazy when starting Flymake checks
Don't start the check immediately if the buffer is not being displayed. Wait until it is, using window-configuration-change-hook. This enables the user to batch-enable flymake-mode on many buffers and not have that operation exhaust system resources for checking each one. Likewise, an editing or save operation in a currently non-displayed buffer does not immediately start a check. * lisp/progmodes/flymake.el (flymake-start-on-flymake-mode): Rename from flymake-start-syntax-check-on-find-file. (flymake-start-syntax-check-on-find-file): Obsolete alias for flymake-start-on-flymake-mode. (flymake-start): Redesign. Affect the global post-command-hook and local window-configuraiton-change-hook. (flymake--schedule-timer-maybe) (flymake-after-change-function, flymake-after-save-hook): Pass t to flymake-start. * test/lisp/progmodes/flymake-tests.el (flymake-tests--call-with-fixture) (dummy-backends, recurrent-backend): Start flymake check explicitly and immediately.
-rw-r--r--lisp/progmodes/flymake.el89
-rw-r--r--test/lisp/progmodes/flymake-tests.el12
2 files changed, 68 insertions, 33 deletions
diff --git a/lisp/progmodes/flymake.el b/lisp/progmodes/flymake.el
index 4c4d6aef322..27ec7a1f124 100644
--- a/lisp/progmodes/flymake.el
+++ b/lisp/progmodes/flymake.el
@@ -123,10 +123,14 @@ If nil, never start checking buffer automatically like this."
123(make-obsolete-variable 'flymake-gui-warnings-enabled 123(make-obsolete-variable 'flymake-gui-warnings-enabled
124 "it no longer has any effect." "26.1") 124 "it no longer has any effect." "26.1")
125 125
126(defcustom flymake-start-syntax-check-on-find-file t 126(defcustom flymake-start-on-flymake-mode t
127 "Start syntax check on find file." 127 "Start syntax check when `pflymake-mode'is enabled.
128Specifically, start it when the buffer is actually displayed."
128 :type 'boolean) 129 :type 'boolean)
129 130
131(define-obsolete-variable-alias 'flymake-start-syntax-check-on-find-file
132 'flymake-start-on-flymake-mode "26.1")
133
130(defcustom flymake-log-level -1 134(defcustom flymake-log-level -1
131 "Obsolete and ignored variable." 135 "Obsolete and ignored variable."
132 :type 'integer) 136 :type 'integer)
@@ -670,33 +674,59 @@ If it is running also stop it."
670 (flymake--disable-backend backend err))))) 674 (flymake--disable-backend backend err)))))
671 675
672(defun flymake-start (&optional deferred force) 676(defun flymake-start (&optional deferred force)
673 "Start a syntax check. 677 "Start a syntax check for the current buffer.
674Start it immediately, or after current command if DEFERRED is 678DEFERRED is a list of symbols designating conditions to wait for
675non-nil. With optional FORCE run even disabled backends. 679before actually starting the check. If it is nil (the list is
680empty), start it immediately, else defer the check to when those
681conditions are met. Currently recognized conditions are
682`post-command', for waiting until the current command is over,
683`on-display', for waiting until the buffer is actually displayed
684in a window. If DEFERRED is t, wait for all known conditions.
685
686With optional FORCE run even disabled backends.
676 687
677Interactively, with a prefix arg, FORCE is t." 688Interactively, with a prefix arg, FORCE is t."
678 (interactive (list nil current-prefix-arg)) 689 (interactive (list nil current-prefix-arg))
679 (cl-labels 690 (let ((deferred (if (eq t deferred)
680 ((start 691 '(post-command on-display)
681 () 692 deferred))
682 (remove-hook 'post-command-hook #'start 'local) 693 (buffer (current-buffer)))
683 (setq flymake-check-start-time (float-time)) 694 (cl-labels
684 (run-hook-wrapped 695 ((start-post-command
685 'flymake-diagnostic-functions 696 ()
686 (lambda (backend) 697 (remove-hook 'post-command-hook #'start-post-command
687 (cond 698 nil)
688 ((and (not force) 699 (with-current-buffer buffer
689 (flymake--with-backend-state backend state 700 (flymake-start (remove 'post-command deferred) force)))
690 (flymake--backend-state-disabled state))) 701 (start-on-display
691 (flymake-log :debug "Backend %s is disabled, not starting" 702 ()
692 backend)) 703 (remove-hook 'window-configuration-change-hook #'start-on-display
704 'local)
705 (flymake-start (remove 'on-display deferred) force)))
706 (cond ((and (memq 'post-command deferred)
707 this-command)
708 (add-hook 'post-command-hook
709 #'start-post-command
710 'append nil))
711 ((and (memq 'on-display deferred)
712 (not (get-buffer-window (current-buffer))))
713 (add-hook 'window-configuration-change-hook
714 #'start-on-display
715 'append 'local))
693 (t 716 (t
694 (flymake--run-backend backend))) 717 (setq flymake-check-start-time (float-time))
695 nil)))) 718 (run-hook-wrapped
696 (if (and deferred 719 'flymake-diagnostic-functions
697 this-command) 720 (lambda (backend)
698 (add-hook 'post-command-hook #'start 'append 'local) 721 (cond
699 (start)))) 722 ((and (not force)
723 (flymake--with-backend-state backend state
724 (flymake--backend-state-disabled state)))
725 (flymake-log :debug "Backend %s is disabled, not starting"
726 backend))
727 (t
728 (flymake--run-backend backend)))
729 nil)))))))
700 730
701(defvar flymake-mode-map 731(defvar flymake-mode-map
702 (let ((map (make-sparse-keymap))) map) 732 (let ((map (make-sparse-keymap))) map)
@@ -714,8 +744,7 @@ Interactively, with a prefix arg, FORCE is t."
714 744
715 (setq flymake--backend-state (make-hash-table)) 745 (setq flymake--backend-state (make-hash-table))
716 746
717 (when flymake-start-syntax-check-on-find-file 747 (when flymake-start-on-flymake-mode (flymake-start t)))
718 (flymake-start)))
719 748
720 ;; Turning the mode OFF. 749 ;; Turning the mode OFF.
721 (t 750 (t
@@ -748,7 +777,7 @@ Do it only if `flymake-no-changes-timeout' is non-nil."
748 (flymake-log 777 (flymake-log
749 :debug "starting syntax check after idle for %s seconds" 778 :debug "starting syntax check after idle for %s seconds"
750 flymake-no-changes-timeout) 779 flymake-no-changes-timeout)
751 (flymake-start)) 780 (flymake-start t))
752 (setq flymake-timer nil)))) 781 (setq flymake-timer nil))))
753 (current-buffer))))) 782 (current-buffer)))))
754 783
@@ -770,13 +799,13 @@ Do it only if `flymake-no-changes-timeout' is non-nil."
770 (let((new-text (buffer-substring start stop))) 799 (let((new-text (buffer-substring start stop)))
771 (when (and flymake-start-syntax-check-on-newline (equal new-text "\n")) 800 (when (and flymake-start-syntax-check-on-newline (equal new-text "\n"))
772 (flymake-log :debug "starting syntax check as new-line has been seen") 801 (flymake-log :debug "starting syntax check as new-line has been seen")
773 (flymake-start 'deferred)) 802 (flymake-start t))
774 (flymake--schedule-timer-maybe))) 803 (flymake--schedule-timer-maybe)))
775 804
776(defun flymake-after-save-hook () 805(defun flymake-after-save-hook ()
777 (when flymake-mode 806 (when flymake-mode
778 (flymake-log :debug "starting syntax check as buffer was saved") 807 (flymake-log :debug "starting syntax check as buffer was saved")
779 (flymake-start))) 808 (flymake-start t)))
780 809
781(defun flymake-kill-buffer-hook () 810(defun flymake-kill-buffer-hook ()
782 (when flymake-timer 811 (when flymake-timer
diff --git a/test/lisp/progmodes/flymake-tests.el b/test/lisp/progmodes/flymake-tests.el
index 5e042f2b082..0b29b6a9715 100644
--- a/test/lisp/progmodes/flymake-tests.el
+++ b/test/lisp/progmodes/flymake-tests.el
@@ -73,7 +73,9 @@ SEVERITY-PREDICATE is used to setup
73 (when sev-pred-supplied-p 73 (when sev-pred-supplied-p
74 (setq-local flymake-proc-diagnostic-type-pred severity-predicate)) 74 (setq-local flymake-proc-diagnostic-type-pred severity-predicate))
75 (goto-char (point-min)) 75 (goto-char (point-min))
76 (unless flymake-mode (flymake-mode 1)) 76 (let ((flymake-start-on-flymake-mode nil))
77 (unless flymake-mode (flymake-mode 1)))
78 (flymake-start)
77 (flymake-tests--wait-for-backends) 79 (flymake-tests--wait-for-backends)
78 (funcall fn))) 80 (funcall fn)))
79 (and buffer 81 (and buffer
@@ -230,7 +232,9 @@ SEVERITY-PREDICATE is used to setup
230 'crashing-backend 232 'crashing-backend
231 )) 233 ))
232 (flymake-wrap-around nil)) 234 (flymake-wrap-around nil))
233 (flymake-mode) 235 (let ((flymake-start-on-flymake-mode nil))
236 (flymake-mode))
237 (flymake-start)
234 238
235 (flymake-tests--assert-set (flymake-running-backends) 239 (flymake-tests--assert-set (flymake-running-backends)
236 (error-backend warning-backend panicking-backend) 240 (error-backend warning-backend panicking-backend)
@@ -299,7 +303,9 @@ SEVERITY-PREDICATE is used to setup
299 (let ((flymake-diagnostic-functions 303 (let ((flymake-diagnostic-functions
300 (list 'eager-backend)) 304 (list 'eager-backend))
301 (flymake-wrap-around nil)) 305 (flymake-wrap-around nil))
302 (flymake-mode) 306 (let ((flymake-start-on-flymake-mode nil))
307 (flymake-mode))
308 (flymake-start)
303 (flymake-tests--assert-set (flymake-running-backends) 309 (flymake-tests--assert-set (flymake-running-backends)
304 (eager-backend) ()) 310 (eager-backend) ())
305 (cl-loop until tick repeat 4 do (sleep-for 0.2)) 311 (cl-loop until tick repeat 4 do (sleep-for 0.2))