summaryrefslogtreecommitdiff
path: root/lisp/textmodes/ispell.el
diff options
context:
space:
mode:
authorDamien Cassou <damien@cassou.me>2019-12-27 15:35:52 +0100
committerEli Zaretskii <eliz@gnu.org>2020-01-17 11:29:06 +0200
commit6338f69102551cb8bfba36000fb73935aefa5b7b (patch)
tree7bf8a4733ed2b2a2efe687dbc6385107acba9360 /lisp/textmodes/ispell.el
parent4453acbdc987130e9967ef7afe90359ad7a48987 (diff)
downloademacs-6338f69102551cb8bfba36000fb73935aefa5b7b.tar.gz
emacs-6338f69102551cb8bfba36000fb73935aefa5b7b.tar.bz2
emacs-6338f69102551cb8bfba36000fb73935aefa5b7b.zip
Add unattended spell-checking to checkdoc
This commit makes checkdoc capable of spell-checking even when the user isn't using it interactively. When TAKE-NOTES is non-nil, checkdoc will run spell-checking (with ispell) and report spelling mistakes. Fixes: (bug#38583). * lisp/textmodes/ispell.el (ispell-word): Extract part of it to `ispell--run-on-word`. (ispell--run-on-word): New function, extracted from `ispell-word`. (ispell-error-checking-word): New function. (ispell-correct-p): New function. Use `ispell--run-on-word` and `ispell-error-checking-word`. * lisp/emacs-lisp/checkdoc.el (checkdoc-current-buffer): Pass TAKE-NOTES to `checkdoc-start`. (checkdoc-continue): Pass TAKE-NOTES to `checkdoc-this-string-valid`. (checkdoc-this-string-valid): Add optional argument TAKE-NOTES and pass it to `checkdoc-this-string-valid-engine`. (checkdoc-this-string-valid-engine): Add optional argument TAKE-NOTES and pass it to `checkdoc-ispell-docstring-engine`. (checkdoc-ispell-init): Call `ispell-set-spellchecker-params` and `ispell-accept-buffer-local-defs`. These calls are required to properly use ispell. The problem went unnoticed until now because checkdoc was only using ispell through the high-level command `ispell-word` which takes care of all the initialization for the user. (checkdoc-ispell-docstring-engine): Add optional argument TAKE-NOTES to force reporting of spell-checking errors. Throw error when (checkdoc-ispell-init) fails configuring ispell. Replace a few (if cond nil body) with (unless cond body). Replace (let ((var nil))) with (let (var)). Replace (if (not (eq checkdoc-autofix-flag 'never)) body) with just body because `checkdoc-autofix-flag` is checked at the beginning of the function. (cherry picked from commit 25adbc4a5ecc3e16625c0171607e3153bbdf7ab1)
Diffstat (limited to 'lisp/textmodes/ispell.el')
-rw-r--r--lisp/textmodes/ispell.el50
1 files changed, 38 insertions, 12 deletions
diff --git a/lisp/textmodes/ispell.el b/lisp/textmodes/ispell.el
index 53a45433085..c06f3915faa 100644
--- a/lisp/textmodes/ispell.el
+++ b/lisp/textmodes/ispell.el
@@ -1951,18 +1951,7 @@ quit spell session exited."
(or quietly
(message "Checking spelling of %s..."
(funcall ispell-format-word-function word)))
- (ispell-send-string "%\n") ; put in verbose mode
- (ispell-send-string (concat "^" word "\n"))
- ;; wait until ispell has processed word
- (while (progn
- (ispell-accept-output)
- (not (string= "" (car ispell-filter)))))
- ;;(ispell-send-string "!\n") ;back to terse mode.
- (setq ispell-filter (cdr ispell-filter)) ; remove extra \n
- (if (and ispell-filter (listp ispell-filter))
- (if (> (length ispell-filter) 1)
- (error "Ispell and its process have different character maps")
- (setq poss (ispell-parse-output (car ispell-filter)))))
+ (setq poss (ispell--run-on-word word))
(cond ((eq poss t)
(or quietly
(message "%s is correct"
@@ -2024,6 +2013,43 @@ quit spell session exited."
(goto-char cursor-location) ; return to original location
replace))))
+(defun ispell--run-on-word (word)
+ "Run ispell on WORD."
+ (ispell-send-string "%\n") ; put in verbose mode
+ (ispell-send-string (concat "^" word "\n"))
+ ;; wait until ispell has processed word
+ (while (progn
+ (ispell-accept-output)
+ (not (string= "" (car ispell-filter)))))
+ (setq ispell-filter (cdr ispell-filter))
+ (when (and ispell-filter (listp ispell-filter))
+ (if (> (length ispell-filter) 1)
+ (error "Ispell and its processs have different character maps: %s" ispell-filter)
+ (ispell-parse-output (car ispell-filter)))))
+
+(defun ispell-error-checking-word (word)
+ "Return a string describing that checking for WORD failed."
+ (format "Error checking word %s using %s with %s dictionary"
+ (funcall ispell-format-word-function word)
+ (file-name-nondirectory ispell-program-name)
+ (or ispell-current-dictionary "default")))
+
+(defun ispell-correct-p (&optional following)
+ "Return t if the word at point is correct. Nil otherwise.
+
+If optional argument FOLLOWING is non-nil then the following
+word (rather than preceding) is checked when the cursor is not
+over a word."
+ (save-excursion
+ ;; reset ispell-filter so it only contains the result of
+ ;; spell-checking the current-word:
+ (setq ispell-filter nil)
+ (let* ((word-and-boundaries (ispell-get-word following))
+ (word (car word-and-boundaries))
+ (poss (ispell--run-on-word word)))
+ (unless poss (error (ispell-error-checking-word word)))
+ (or (eq poss t)
+ (stringp poss)))))
(defun ispell-get-word (following &optional extra-otherchars)
"Return the word for spell-checking according to ispell syntax.