]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/textmodes/flyspell.el (flyspell-check-changes): New user option.
authorJuri Linkov <juri@linkov.net>
Thu, 14 Mar 2024 18:11:33 +0000 (20:11 +0200)
committerEshel Yaron <me@eshelyaron.com>
Fri, 15 Mar 2024 09:05:04 +0000 (10:05 +0100)
(flyspell--mode-on): Add flyspell-check-changes to post-command-hook
when flyspell-check-changes is non-nil.
(flyspell--mode-off): Remove flyspell-check-changes from post-command-hook.
(flyspell-check-changes): New function (bug#61874).

(cherry picked from commit f03f14165ed51148b72b431ac99c4a4829bb1a7f)

etc/NEWS
lisp/textmodes/flyspell.el

index c4c3726e928bcbc6565a133ce97b456b19985b5d..4556ad148ef9144080c67ffe98ccc7072a75322a 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1227,6 +1227,11 @@ distracting and easily confused with actual code, or a significant
 early aid that relieves you from moving the buffer or reaching for the
 mouse to consult an error message.
 
+** Flyspell
+
+*** New user option 'flyspell-check-changes'.
+It checks only edited text.
+
 ** JS mode.
 The binding 'M-.' has been removed from the major mode keymaps in
 'js-mode' and 'js-ts-mode', having it default to the global binding
index de59294e9f001309ab7fd3492ca98a336a155f76..d64e4d601f72a7f72fe65eb57eb7cf0aaf382d1e 100644 (file)
@@ -288,6 +288,12 @@ If this variable is nil, all regions are treated as small."
   "The key binding for flyspell auto correction."
   :type 'key-sequence)
 
+(defcustom flyspell-check-changes nil
+  "Check only on moving point from the edited word.
+Unlike the default behavior, don't check when moving point without editing."
+  :type 'boolean
+  :version "30.1")
+
 ;;*---------------------------------------------------------------------*/
 ;;*    Mode specific options                                            */
 ;;*    -------------------------------------------------------------    */
@@ -610,7 +616,9 @@ are both non-nil."
   (flyspell-accept-buffer-local-defs 'force)
   (flyspell-delay-commands)
   (flyspell-deplacement-commands)
-  (add-hook 'post-command-hook (function flyspell-post-command-hook) t t)
+  (if flyspell-check-changes
+      (add-hook 'post-command-hook (function flyspell-check-changes) t t)
+    (add-hook 'post-command-hook (function flyspell-post-command-hook) t t))
   (add-hook 'pre-command-hook (function flyspell-pre-command-hook) t t)
   (add-hook 'after-change-functions 'flyspell-after-change-function nil t)
   (add-hook 'hack-local-variables-hook
@@ -709,6 +717,7 @@ has been used, the current word is not checked."
 ;;;###autoload
 (defun flyspell--mode-off ()
   "Turn Flyspell mode off."
+  (remove-hook 'post-command-hook (function flyspell-check-changes) t)
   (remove-hook 'post-command-hook (function flyspell-post-command-hook) t)
   (remove-hook 'pre-command-hook (function flyspell-pre-command-hook) t)
   (remove-hook 'after-change-functions 'flyspell-after-change-function t)
@@ -990,6 +999,22 @@ Mostly we check word delimiters."
             (setq flyspell-changes (cdr flyspell-changes))))
         (setq flyspell-previous-command command)))))
 
+(defun flyspell-check-changes ()
+  "The `post-command-hook' used by flyspell to check only edits.
+It checks only on moving point from the edited word,
+not when moving point without editing."
+  (when flyspell-mode
+    (with-local-quit
+      (when (consp flyspell-changes)
+        (let ((start (car (car flyspell-changes)))
+              (stop  (cdr (car flyspell-changes)))
+              (word (save-excursion (flyspell-get-word))))
+          (unless (and word (<= (nth 1 word) start) (>= (nth 2 word) stop))
+            (save-excursion
+              (goto-char start)
+              (flyspell-word))
+            (setq flyspell-changes nil)))))))
+
 ;;*---------------------------------------------------------------------*/
 ;;*    flyspell-notify-misspell ...                                     */
 ;;*---------------------------------------------------------------------*/