summaryrefslogtreecommitdiff
path: root/lisp/textmodes
diff options
context:
space:
mode:
authorLars Ingebrigtsen <larsi@gnus.org>2022-08-25 16:20:07 +0200
committerLars Ingebrigtsen <larsi@gnus.org>2022-08-25 16:20:07 +0200
commit7464640d2ac6a0342c4134aad15ba8e96ba1a40c (patch)
tree6f8c6dc781aea0e8625d779aa1b0f97c168e4c6e /lisp/textmodes
parent52f9ce5528e3a82c4170be2f3d117966793e8efc (diff)
downloademacs-7464640d2ac6a0342c4134aad15ba8e96ba1a40c.tar.gz
emacs-7464640d2ac6a0342c4134aad15ba8e96ba1a40c.tar.bz2
emacs-7464640d2ac6a0342c4134aad15ba8e96ba1a40c.zip
Make a prefix go to the previous error
* lisp/textmodes/flyspell.el (flyspell-goto-next-error): Make a prefix find the previous error (bug#50443).
Diffstat (limited to 'lisp/textmodes')
-rw-r--r--lisp/textmodes/flyspell.el51
1 files changed, 30 insertions, 21 deletions
diff --git a/lisp/textmodes/flyspell.el b/lisp/textmodes/flyspell.el
index 1094ef3e934..a893bc7b9ce 100644
--- a/lisp/textmodes/flyspell.el
+++ b/lisp/textmodes/flyspell.el
@@ -1714,25 +1714,32 @@ of a misspelled word removed when you've corrected it."
;;*---------------------------------------------------------------------*/
;;* flyspell-goto-next-error ... */
;;*---------------------------------------------------------------------*/
-(defun flyspell-goto-next-error ()
- "Go to the next previously detected error.
+(defun flyspell-goto-next-error (&optional previous)
+ "Go to the next error.
+If PREVIOUS (interactively, the prefix), go to the previous error
+instead.
+
In general FLYSPELL-GOTO-NEXT-ERROR must be used after
FLYSPELL-BUFFER."
- (interactive)
+ (interactive "P")
(let ((pos (point))
- (max (point-max)))
- (if (and (eq (current-buffer) flyspell-old-buffer-error)
- (eq pos flyspell-old-pos-error))
- (progn
- (if (= flyspell-old-pos-error max)
- ;; goto beginning of buffer
+ (max (if previous (point-min) (point-max))))
+ (when (and (eq (current-buffer) flyspell-old-buffer-error)
+ (eq pos flyspell-old-pos-error))
+ (if previous
+ (if (= flyspell-old-pos-error max)
(progn
- (message "Restarting from beginning of buffer")
- (goto-char (point-min)))
- (forward-word 1))
- (setq pos (point))))
- ;; seek the next error
- (while (and (< pos max)
+ (message "Restarting from end of the buffer")
+ (goto-char (point-max)))
+ (forward-word -1))
+ (if (= flyspell-old-pos-error max)
+ (progn
+ (message "Restarting from beginning of buffer")
+ (goto-char (point-min)))
+ (forward-word 1)))
+ (setq pos (point)))
+ ;; Seek the next error.
+ (while (and (/= pos max)
(let ((ovs (overlays-at pos))
(r '()))
(while (and (not r) (consp ovs))
@@ -1740,13 +1747,15 @@ FLYSPELL-BUFFER."
(setq r t)
(setq ovs (cdr ovs))))
(not r)))
- (setq pos (1+ pos)))
- ;; save the current location for next invocation
- (setq flyspell-old-pos-error pos)
- (setq flyspell-old-buffer-error (current-buffer))
+ (setq pos (if previous (1- pos) (1+ pos))))
(goto-char pos)
- (if (= pos max)
- (message "No more miss-spelled word!"))))
+ (when previous
+ (forward-word -1))
+ ;; Save the current location for next invocation.
+ (setq flyspell-old-pos-error (point))
+ (setq flyspell-old-buffer-error (current-buffer))
+ (when (= (point) max)
+ (message "No more miss-spelled words"))))
;;*---------------------------------------------------------------------*/
;;* flyspell-overlay-p ... */