Commit f03f1416 authored by Juri Linkov's avatar Juri Linkov
Browse files

* lisp/textmodes/flyspell.el (flyspell-check-changes): New user option.

(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).
parent bd6b64e0
Pipeline #28509 failed with stages
in 115 minutes and 4 seconds
......@@ -1129,6 +1129,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
......
......@@ -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 ... */
;;*---------------------------------------------------------------------*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment