* Flyspell error traversal additions
[not found] <87sg6lchgc.fsf@kallio.app>
@ 2021-01-28 13:57 ` Roni Kallio
[not found] ` <CADwFkm==pCKz+0eirFtmcZr-fKx5m7cOKZYPRt1KGCTX5Bc8BA@mail.gmail.com>
0 siblings, 1 reply; 2+ messages in thread
From: Roni Kallio @ 2021-01-28 13:57 UTC (permalink / raw)
To: emacs-devel
[-- 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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: bug#50443: Fwd: Flyspell error traversal additions
[not found] ` <CADwFkm==pCKz+0eirFtmcZr-fKx5m7cOKZYPRt1KGCTX5Bc8BA@mail.gmail.com>
@ 2021-09-08 3:27 ` Richard Stallman
0 siblings, 0 replies; 2+ messages in thread
From: Richard Stallman @ 2021-09-08 3:27 UTC (permalink / raw)
To: Stefan Kangas; +Cc: emacs-devel
[[[ To any NSA and FBI agents reading my email: please consider ]]]
[[[ whether defending the US Constitution against all enemies, ]]]
[[[ foreign or domestic, requires you to follow Snowden's example. ]]]
> This was sent to emacs-devel, but never followed up. I'm forwarding
> to the bug tracker so that we don't lose track of it.
Thank you. That's an example of good housekeeping.
--
Dr Richard Stallman (https://stallman.org)
Chief GNUisance of the GNU Project (https://gnu.org)
Founder, Free Software Foundation (https://fsf.org)
Internet Hall-of-Famer (https://internethalloffame.org)
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-09-08 3:27 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <87sg6lchgc.fsf@kallio.app>
2021-01-28 13:57 ` Flyspell error traversal additions Roni Kallio
[not found] ` <CADwFkm==pCKz+0eirFtmcZr-fKx5m7cOKZYPRt1KGCTX5Bc8BA@mail.gmail.com>
2021-09-08 3:27 ` bug#50443: Fwd: " Richard Stallman
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).