From 0dfa6f8b4aaa825a2587fa36f30bf9f55918ff3d Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Fri, 22 Nov 2024 08:17:25 +0100 Subject: [PATCH] New option 'flyspell-delay-use-timer' * lisp/textmodes/flyspell.el (flyspell-delay-use-timer): New user option. (flyspell--timer): New variable. (flyspell-check-word-p): Use them. (flyspell-post-command-hook): Disable timer. (flyspell-word): Pass non-nil SECONDS argument to 'accept-process-output' to permit quitting. (bug#74437) --- lisp/textmodes/flyspell.el | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/lisp/textmodes/flyspell.el b/lisp/textmodes/flyspell.el index 09d4e8a8d1a..5fcb83efb57 100644 --- a/lisp/textmodes/flyspell.el +++ b/lisp/textmodes/flyspell.el @@ -810,6 +810,18 @@ flyspell-check-changed-word-p (let ((pos (point))) (or (>= pos start) (<= pos stop) (= pos (1+ stop)))))))) +(defcustom flyspell-delay-use-timer nil + "Whether Flyspell should use a timer for waiting after a delayed command. + +If this is non-nil, Flyspell sets up a timer for checking the word at +point `flyspell-delay' seconds after you invoke a delayed command. +Otherwise, if this option is nil, Flyspell uses `sit-for' to wait for +that duration instead." + :type 'boolean + :version "31.1") + +(defvar flyspell--timer nil) + ;;*---------------------------------------------------------------------*/ ;;* flyspell-check-word-p ... */ ;;*---------------------------------------------------------------------*/ @@ -844,7 +856,16 @@ flyspell-check-word-p ;; 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 (not flyspell-delay-use-timer) + (sit-for flyspell-delay) + (setq flyspell--timer + (run-with-idle-timer + flyspell-delay nil + (lambda (buffer) + (when (eq (current-buffer) buffer) + (flyspell-word nil nil t))) + (current-buffer))) + nil))) (t t))) (t t)))) @@ -955,6 +976,7 @@ flyspell-debug-signal-changed-checked (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 +1201,7 @@ flyspell-word (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. -- 2.46.2