[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 2aefd55 1/2: ispell: Commands to check comments or strings at poi
From: |
Št?pán N?mec |
Subject: |
master 2aefd55 1/2: ispell: Commands to check comments or strings at point or in region |
Date: |
Wed, 26 Aug 2020 07:20:06 -0400 (EDT) |
branch: master
commit 2aefd5590431bc84a70f2740f6949c2f771c2b55
Author: Štěpán Němec <stepnem@gmail.com>
Commit: Štěpán Němec <stepnem@gmail.com>
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 | 9 +++++++++
lisp/textmodes/ispell.el | 31 ++++++++++++++++++++++++-------
2 files changed, 33 insertions(+), 7 deletions(-)
diff --git a/etc/NEWS b/etc/NEWS
index 2f8e5eb..05105a1 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -381,6 +381,15 @@ take the actual screenshot, and defaults to "ImageMagick
import".
The menu-bar Help menu now has a "Show Recent Inputs" item under the
"Describe" sub-menu.
+** 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 8252da6..6eaa058 100644
--- a/lisp/textmodes/ispell.el
+++ b/lisp/textmodes/ispell.el
@@ -44,6 +44,7 @@
;; ispell-buffer
;; ispell-message
;; ispell-comments-and-strings
+;; ispell-comment-or-string-at-point
;; ispell-continue
;; ispell-complete-word
;; ispell-complete-word-interior-frag
@@ -3580,24 +3581,40 @@ Returns the sum SHIFT due to changes in word
replacements."
;;;###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 ()