]> git.eshelyaron.com Git - emacs.git/commitdiff
flyspell.el: block less
authorEshel Yaron <me@eshelyaron.com>
Tue, 19 Nov 2024 18:43:09 +0000 (19:43 +0100)
committerEshel Yaron <me@eshelyaron.com>
Tue, 19 Nov 2024 18:43:09 +0000 (19:43 +0100)
lisp/textmodes/flyspell.el

index 7bf9cb1ae9d8e3bd55efdf77da57838cd1644291..2d9fe432e0a13f5af4f629ef864e8d37371826f7 100644 (file)
@@ -810,6 +810,13 @@ Mostly we check word delimiters."
              (let ((pos (point)))
                (or (>= pos start) (<= pos stop) (= pos (1+ stop))))))))
 
+(defcustom flyspell-blocking-delay nil
+  "Whether to block Emacs while Flyspell waits after a delayed command."
+  :type 'boolean
+  :version "30.1")
+
+(defvar flyspell--timer nil)
+
 ;;*---------------------------------------------------------------------*/
 ;;*    flyspell-check-word-p ...                                        */
 ;;*---------------------------------------------------------------------*/
@@ -844,7 +851,15 @@ Mostly we check word delimiters."
        ;; The current command is not delayed, that
        ;; is that we must check the word now.
        (and (not unread-command-events)
-            (sit-for flyspell-delay)))
+             (if flyspell-blocking-delay
+                 (sit-for flyspell-delay)
+               (setq flyspell--timer
+                     (run-with-idle-timer
+                      flyspell-delay nil
+                      (lambda (buffer)
+                        (when (eq (current-buffer) buffer) (flyspell-word)))
+                      (current-buffer)))
+               nil)))
        (t t)))
      (t t))))
 
@@ -955,6 +970,7 @@ Mostly we check word delimiters."
 (defun flyspell-post-command-hook ()
   "The `post-command-hook' used by flyspell to check a word on-the-fly."
   (interactive)
+  (when (timerp flyspell--timer) (cl-callf cancel-timer flyspell--timer))
   (when flyspell-mode
     (with-local-quit
       (let ((command this-command)
@@ -1179,7 +1195,7 @@ spell-check."
                  (set-process-query-on-exit-flag ispell-process nil)
                   ;; Wait until ispell has processed word.
                   (while (progn
-                           (accept-process-output ispell-process)
+                           (accept-process-output ispell-process 1)
                            (not (string= "" (car ispell-filter)))))
                   ;; (ispell-send-string "!\n")
                   ;; back to terse mode.