diff options
| author | Damien Cassou | 2019-12-27 15:35:52 +0100 |
|---|---|---|
| committer | Eli Zaretskii | 2020-01-17 11:29:06 +0200 |
| commit | 6338f69102551cb8bfba36000fb73935aefa5b7b (patch) | |
| tree | 7bf8a4733ed2b2a2efe687dbc6385107acba9360 /lisp/textmodes | |
| parent | 4453acbdc987130e9967ef7afe90359ad7a48987 (diff) | |
| download | emacs-6338f69102551cb8bfba36000fb73935aefa5b7b.tar.gz 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')
| -rw-r--r-- | lisp/textmodes/ispell.el | 50 |
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." | |||
| 1951 | (or quietly | 1951 | (or quietly |
| 1952 | (message "Checking spelling of %s..." | 1952 | (message "Checking spelling of %s..." |
| 1953 | (funcall ispell-format-word-function word))) | 1953 | (funcall ispell-format-word-function word))) |
| 1954 | (ispell-send-string "%\n") ; put in verbose mode | 1954 | (setq poss (ispell--run-on-word word)) |
| 1955 | (ispell-send-string (concat "^" word "\n")) | ||
| 1956 | ;; wait until ispell has processed word | ||
| 1957 | (while (progn | ||
| 1958 | (ispell-accept-output) | ||
| 1959 | (not (string= "" (car ispell-filter))))) | ||
| 1960 | ;;(ispell-send-string "!\n") ;back to terse mode. | ||
| 1961 | (setq ispell-filter (cdr ispell-filter)) ; remove extra \n | ||
| 1962 | (if (and ispell-filter (listp ispell-filter)) | ||
| 1963 | (if (> (length ispell-filter) 1) | ||
| 1964 | (error "Ispell and its process have different character maps") | ||
| 1965 | (setq poss (ispell-parse-output (car ispell-filter))))) | ||
| 1966 | (cond ((eq poss t) | 1955 | (cond ((eq poss t) |
| 1967 | (or quietly | 1956 | (or quietly |
| 1968 | (message "%s is correct" | 1957 | (message "%s is correct" |
| @@ -2024,6 +2013,43 @@ quit spell session exited." | |||
| 2024 | (goto-char cursor-location) ; return to original location | 2013 | (goto-char cursor-location) ; return to original location |
| 2025 | replace)))) | 2014 | replace)))) |
| 2026 | 2015 | ||
| 2016 | (defun ispell--run-on-word (word) | ||
| 2017 | "Run ispell on WORD." | ||
| 2018 | (ispell-send-string "%\n") ; put in verbose mode | ||
| 2019 | (ispell-send-string (concat "^" word "\n")) | ||
| 2020 | ;; wait until ispell has processed word | ||
| 2021 | (while (progn | ||
| 2022 | (ispell-accept-output) | ||
| 2023 | (not (string= "" (car ispell-filter))))) | ||
| 2024 | (setq ispell-filter (cdr ispell-filter)) | ||
| 2025 | (when (and ispell-filter (listp ispell-filter)) | ||
| 2026 | (if (> (length ispell-filter) 1) | ||
| 2027 | (error "Ispell and its processs have different character maps: %s" ispell-filter) | ||
| 2028 | (ispell-parse-output (car ispell-filter))))) | ||
| 2029 | |||
| 2030 | (defun ispell-error-checking-word (word) | ||
| 2031 | "Return a string describing that checking for WORD failed." | ||
| 2032 | (format "Error checking word %s using %s with %s dictionary" | ||
| 2033 | (funcall ispell-format-word-function word) | ||
| 2034 | (file-name-nondirectory ispell-program-name) | ||
| 2035 | (or ispell-current-dictionary "default"))) | ||
| 2036 | |||
| 2037 | (defun ispell-correct-p (&optional following) | ||
| 2038 | "Return t if the word at point is correct. Nil otherwise. | ||
| 2039 | |||
| 2040 | If optional argument FOLLOWING is non-nil then the following | ||
| 2041 | word (rather than preceding) is checked when the cursor is not | ||
| 2042 | over a word." | ||
| 2043 | (save-excursion | ||
| 2044 | ;; reset ispell-filter so it only contains the result of | ||
| 2045 | ;; spell-checking the current-word: | ||
| 2046 | (setq ispell-filter nil) | ||
| 2047 | (let* ((word-and-boundaries (ispell-get-word following)) | ||
| 2048 | (word (car word-and-boundaries)) | ||
| 2049 | (poss (ispell--run-on-word word))) | ||
| 2050 | (unless poss (error (ispell-error-checking-word word))) | ||
| 2051 | (or (eq poss t) | ||
| 2052 | (stringp poss))))) | ||
| 2027 | 2053 | ||
| 2028 | (defun ispell-get-word (following &optional extra-otherchars) | 2054 | (defun ispell-get-word (following &optional extra-otherchars) |
| 2029 | "Return the word for spell-checking according to ispell syntax. | 2055 | "Return the word for spell-checking according to ispell syntax. |