From: "Štěpán Němec" <stepnem@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: Stefan Kangas <stefan@marxist.se>,
lennart.borgman@gmail.com, 6411@debbugs.gnu.org
Subject: bug#6411: Ispell string or comment, bug#6411: Ispell string or comment
Date: Wed, 08 Apr 2020 21:23:20 +0200 [thread overview]
Message-ID: <87k12pkcif.fsf@gmail.com> (raw)
In-Reply-To: <83r25ejvjm.fsf@gnu.org> (Eli Zaretskii's message of "Wed, 21 Aug 2019 20:08:29 +0300, Wed, 21 Aug 2019 22:57:21 +0200")
[-- Attachment #1: Type: text/plain, Size: 1898 bytes --]
tags 6411 + patch
thanks
On Wed, 21 Aug 2019 20:08:29 +0300
Eli Zaretskii wrote:
> Sorry, but I happen to think the proposed implementation is somewhat
> inelegant:
>
> . what's with the "(interactive (list nil))" part?
> . why not just make ispell-comments-and-strings accept a prefix
> argument to modify its behavior?
> . alternatively, why not make ispell-comments-and-strings be
> sensitive to the active region?
> . as yet another alternative, make the new ispell-comment-or-string
> narrow to the comment/string at point and then call
> ispell-comments-and-strings with no code changes whatsoever; then
> make the new command be sensitive to active region, and fall back
> on the string/comment at point if no active region
On Wed, 21 Aug 2019 22:57:21 +0200
Stefan Kangas wrote:
> Let's hope someone picks up the ball and provides us with a revised or
> new patch. If Lennart Borgman doesn't feel up to it after all these
> years, maybe someone else?
Here's my take on it.
I didn't go the narrowing route, as I think it is useful to have full
context during spelling corrections (recursive edit etc.).
I also didn't see an obvious way to reuse one function/command from the
other, as in order to get bounds of a comment/string, we have to parse
the (part of the) buffer, by which point we can just pass the bounds
straight to `ispell-region'.
I did update `ispell-comments-and-strings' to honour active region and
take optional bounds, anyway, as it seems useful in itself.
One other possibility I see would be to merge the two commands and
condition the "at-point" functionality on a prefix argument, but then
the name ('ispell-comments-and-strings') would probably have to be
changed, anyway (and to what?), and perhaps the command would already
become too much of a kitchen sink.
--
Štěpán
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ispell-Commands-to-check-comments-or-strings-at-poin.patch --]
[-- Type: text/x-patch, Size: 3221 bytes --]
From 9ea826c09e848f18b9c09e23c00d525da26d280b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C5=A0t=C4=9Bp=C3=A1n=20N=C4=9Bmec?= <stepnem@gmail.com>
Date: Wed, 8 Apr 2020 20:32:51 +0200
Subject: [PATCH] ispell: Commands to check comments or strings at point or in
region
* lisp/textmodes/ispell.el (ispell-comments-and-strings): Accept START
and END arguments, defaulting to active region in interactive calls.
(ispell-comment-or-string-at-point): New command. (bug#6411)
---
etc/NEWS | 7 +++++++
lisp/textmodes/ispell.el | 30 +++++++++++++++++++++++-------
2 files changed, 30 insertions(+), 7 deletions(-)
diff --git a/etc/NEWS b/etc/NEWS
index fa5478679f..f7f18d12b9 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -144,6 +144,13 @@ this user option.
+++
*** New command 'describe-keymap' describes keybindings in a keymap.
+** Ispell
+---
+*** 'ispell-comments-and-strings' now accepts START and END arguments,
+defaulting to active region when used interactively.
+---
+*** New command 'ispell-comment-or-string-at-point' is provided.
+
---
** The old non-SMIE indentation of 'sh-mode' has been removed.
diff --git a/lisp/textmodes/ispell.el b/lisp/textmodes/ispell.el
index a9fbd2f04c..e1642a8d87 100644
--- a/lisp/textmodes/ispell.el
+++ b/lisp/textmodes/ispell.el
@@ -3591,24 +3591,40 @@ ispell-process-line
;;;###autoload
-(defun ispell-comments-and-strings ()
- "Check comments and strings in the current buffer for spelling errors."
- (interactive)
- (goto-char (point-min))
+(defun ispell-comments-and-strings (&optional start end)
+ "Check comments and strings in the current buffer for spelling errors.
+If called interactively with an active region, check only comments and
+strings in the region.
+When called from Lisp, START and END buffer positions can be provided
+to limit the check."
+ (interactive (when (use-region-p) (list (region-beginning) (region-end))))
+ (unless end (setq end (point-max)))
+ (goto-char (or start (point-min)))
(let (state done)
(while (not done)
(setq done t)
- (setq state (parse-partial-sexp (point) (point-max)
- nil nil state 'syntax-table))
+ (setq state (parse-partial-sexp (point) end nil nil state 'syntax-table))
(if (or (nth 3 state) (nth 4 state))
(let ((start (point)))
- (setq state (parse-partial-sexp start (point-max)
+ (setq state (parse-partial-sexp start end
nil nil state 'syntax-table))
(if (or (nth 3 state) (nth 4 state))
(error "Unterminated string or comment"))
(save-excursion
(setq done (not (ispell-region start (point))))))))))
+;;;###autoload
+(defun ispell-comment-or-string-at-point ()
+ "Check the comment or string containing point for spelling errors."
+ (interactive)
+ (save-excursion
+ (let ((state (syntax-ppss)))
+ (if (or (nth 3 state) (nth 4 state))
+ (ispell-region (nth 8 state)
+ (progn (parse-partial-sexp (point) (point-max)
+ nil nil state 'syntax-table)
+ (point)))
+ (user-error "Not inside a string or comment")))))
;;;###autoload
(defun ispell-buffer ()
--
2.26.0
next prev parent reply other threads:[~2020-04-08 19:23 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-06-12 17:57 bug#6411: Ispell string or comment Lennart Borgman
2010-06-22 15:00 ` Agustin Martin
2019-08-21 14:07 ` Stefan Kangas
2019-08-21 17:08 ` Eli Zaretskii
2019-08-21 20:57 ` Stefan Kangas
2020-04-08 19:23 ` Štěpán Němec [this message]
2020-04-09 6:21 ` bug#6411: Ispell string or comment, " Eli Zaretskii
2020-04-09 14:48 ` Štěpán Němec
2020-04-09 17:06 ` Eli Zaretskii
2020-04-09 17:11 ` Eli Zaretskii
2020-04-09 18:44 ` Štěpán Němec
2020-04-09 19:01 ` Eli Zaretskii
2020-04-09 19:56 ` Štěpán Němec
2020-04-10 6:22 ` Eli Zaretskii
2020-08-26 11:27 ` Štěpán Němec
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=87k12pkcif.fsf@gmail.com \
--to=stepnem@gmail.com \
--cc=6411@debbugs.gnu.org \
--cc=eliz@gnu.org \
--cc=lennart.borgman@gmail.com \
--cc=stefan@marxist.se \
/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.