From: Roni Kallio <roni@kallio.app>
To: emacs-devel@gnu.org
Subject: Flyspell error traversal additions
Date: Thu, 28 Jan 2021 15:57:30 +0200 [thread overview]
Message-ID: <87r1m5ch9n.fsf@kallio.app> (raw)
In-Reply-To: 87sg6lchgc.fsf@kallio.app
[-- Attachment #1: Type: text/plain, Size: 1314 bytes --]
While consolidating my spell/syntax checking setup, I noticed that
flyspell lacks a command to jump to the nearest error that is before the
point in a buffer. There exists `flyspell-goto-next-error', which of
course loops back to beginning when the end of the buffer is reached,
but no equivalent command for going backwards.
I have attached a patch that implements backwards traversal, making sure
it acts analogous to `flyspell-goto-next-error'. I'd like to open a
discussion on whether it would be feasible to have a key binding in
`flyspell-mode-map' for this command. For reference, the bindings
currently are:
C-; -- flyspell-auto-correct-previous-word
C-, -- flyspell-goto-next-error
C-. -- flyspell-auto-correct-word
C-c $ -- flyspell-correct-word-before-point
IMO the best course of action would be to modify
`flyspell-goto-next-error' to accept a prefix argument. The prefix
would control the direction and number of jumps performed; negative
arguments would jump backwards -ARG errors (by calling
flyspell-goto-previous-error), while positive arguments would jump
forwards ARG errors. This would be similar to how commands like
`forward-word' handle prefix arguments. This would allow us to leave
the mode-map unchanged, but still distribute the improvement to all
users.
--
Roni Kallio
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-flyspell-goto-previous-error.patch --]
[-- Type: text/x-patch, Size: 2227 bytes --]
From 4c69d32c61bf94804e4e7efad25dce279dcb8369 Mon Sep 17 00:00:00 2001
From: Roni Kallio <roni@kallio.app>
Date: Thu, 28 Jan 2021 13:22:08 +0200
Subject: [PATCH] Add flyspell-goto-previous-error
Now possible to go backwards detected flyspell errors.
Usage: M-x flyspell-goto-previous-error RET.
In the future this will allow us to implement jumping backward and
forward, and jumping over multiple errors using prefix-argument in
both flyspell-goto-next-error and flyspell-goto-previous-error.
---
lisp/textmodes/flyspell.el | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/lisp/textmodes/flyspell.el b/lisp/textmodes/flyspell.el
index d850316884..12f9b7a203 100644
--- a/lisp/textmodes/flyspell.el
+++ b/lisp/textmodes/flyspell.el
@@ -1757,6 +1757,34 @@ flyspell-goto-next-error
(if (= pos max)
(message "No more miss-spelled word!"))))
+(defun flyspell-goto-previous-error ()
+ "Go to the previous detected error.
+In general `flyspell-goto-previous-error' must be used after
+`flyspell-buffer'."
+ (interactive)
+ (let ((min (point-min)))
+ (when (and (eq (current-buffer) flyspell-old-buffer-error)
+ (eq (point) flyspell-old-pos-error))
+ (when (= (point) min)
+ (message "Restarting from end of buffer")
+ (goto-char (point-max)))
+ (backward-word 1))
+ (while (and (> (point) min)
+ (let ((ovs (overlays-at (point)))
+ (r nil))
+ ;; look for a flyspell overlay
+ (while (and (not r) (consp ovs))
+ (if (flyspell-overlay-p (car ovs))
+ (setq r t)
+ (setq ovs (cdr ovs))))
+ (not r)))
+ ;; go to previous word if no overlay was found
+ (backward-word 1))
+ (setq flyspell-old-pos-error (point))
+ (setq flyspell-old-buffer-error (current-buffer))
+ (when (= (point) min)
+ (message "No more miss-spelled word!"))))
+
;;*---------------------------------------------------------------------*/
;;* flyspell-overlay-p ... */
;;*---------------------------------------------------------------------*/
--
2.29.2
next parent reply other threads:[~2021-01-28 13:57 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <87sg6lchgc.fsf@kallio.app>
2021-01-28 13:57 ` Roni Kallio [this message]
2021-09-07 0:22 ` bug#50443: Fwd: Flyspell error traversal additions Stefan Kangas
2021-09-07 5:57 ` Eli Zaretskii
2021-09-09 20:58 ` Roni Kallio
2021-09-19 16:05 ` Stefan Kangas
2021-12-27 3:12 ` Stefan Kangas
2022-03-24 9:06 ` Lars Ingebrigtsen
2022-08-25 14:20 ` Lars Ingebrigtsen
2021-09-08 3:27 ` Richard Stallman
2021-09-09 17:24 ` Juri Linkov
2021-09-10 6:39 ` Juri Linkov
2021-09-10 6:49 ` Stefan Kangas
2021-09-10 16:12 ` Juri Linkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87r1m5ch9n.fsf@kallio.app \
--to=roni@kallio.app \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.