>From aca6b5bc1571018efa3f05e972882738ddb3a271 Mon Sep 17 00:00:00 2001 From: Damien Cassou Date: Sat, 7 Dec 2019 16:01:13 +0100 Subject: [PATCH 1/5] Add function `ispell-correct-p` * 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-correct-p): New function. Use `ispell--run-on-word`. --- lisp/textmodes/ispell.el | 46 +++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/lisp/textmodes/ispell.el b/lisp/textmodes/ispell.el index dd1eeb4530..7ec445211d 100644 --- a/lisp/textmodes/ispell.el +++ b/lisp/textmodes/ispell.el @@ -1951,18 +1951,7 @@ ispell-word (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)) (cond ((eq poss t) (or quietly (message "%s is correct" @@ -2024,6 +2013,39 @@ ispell-word (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-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)) + (poss (ispell--run-on-word (car word-and-boundaries)))) + (unless poss + (error "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"))) + (or (eq poss t) + (stringp poss))))) (defun ispell-get-word (following &optional extra-otherchars) "Return the word for spell-checking according to ispell syntax. -- 2.23.0