Function: ispell-parse-output
ispell-parse-output is a byte-compiled function defined in
ispell.el.gz.
Signature
(ispell-parse-output OUTPUT &optional ACCEPT-LIST SHIFT)
Documentation
Parse the OUTPUT string from Ispell process and return:
1: t for an exact match.
2: A string containing the root word matched via suffix removal.
3: A list of possible correct spellings of the format:
("ORIGINAL-WORD" OFFSET MISS-LIST GUESS-LIST)
ORIGINAL-WORD is a string of the possibly misspelled word.
OFFSET is an integer giving the line offset of the word.
MISS-LIST and GUESS-LIST are possibly null lists of guesses and misses.
4: nil when an error has occurred.
Optional second arg ACCEPT-LIST is list of words already accepted. Optional third arg SHIFT is an offset to apply based on previous corrections.
Source Code
;; Defined in /usr/src/emacs/lisp/textmodes/ispell.el.gz
;; Should we add a compound word match return value?
(defun ispell-parse-output (output &optional accept-list shift)
"Parse the OUTPUT string from Ispell process and return:
1: t for an exact match.
2: A string containing the root word matched via suffix removal.
3: A list of possible correct spellings of the format:
(\"ORIGINAL-WORD\" OFFSET MISS-LIST GUESS-LIST)
ORIGINAL-WORD is a string of the possibly misspelled word.
OFFSET is an integer giving the line offset of the word.
MISS-LIST and GUESS-LIST are possibly null lists of guesses and misses.
4: nil when an error has occurred.
Optional second arg ACCEPT-LIST is list of words already accepted.
Optional third arg SHIFT is an offset to apply based on previous corrections."
(cond
((string= output "") t) ; for startup with pipes...
((string= output "*") t) ; exact match
((string= output "-") t) ; compound word match
((eq (aref output 0) ?+) ; found because of root word
(substring output 2)) ; return root word
((equal 0 (string-match "[\ra-zA-Z]" output))
(ding) ; error message from ispell!
(message "Ispell error: %s" output)
(sit-for 5)
nil)
(t ; need to process &, ?, and #'s
(let ((type (aref output 0)) ; &, ?, or #
(original-word (substring output 2 (string-match " " output 2)))
(cur-count 0) ; contains number of misses + guesses
count miss-list guess-list offset)
(setq output (substring output (match-end 0))) ; skip over misspelling
(if (eq type ?#)
(setq count 0) ; no misses for type #
(setq count (string-to-number output) ; get number of misses.
output (substring output (1+ (string-search " " output 1)))))
(setq offset (string-to-number output))
(setq output (if (eq type ?#) ; No miss or guess list.
nil
(substring output (1+ (string-search " " output 1)))))
(while output
(let ((end (string-match ", \\|\\($\\)" output))) ; end of miss/guess.
(setq cur-count (1+ cur-count))
(if (> cur-count count)
(push (substring output 0 end) guess-list)
(push (substring output 0 end) miss-list))
(setq output (if (match-end 1) ; True only when at end of line.
nil ; No more misses or guesses.
(substring output (+ end 2))))))
;; return results. Accept word if it was already accepted.
;; adjust offset.
(if (member original-word accept-list)
t
(list original-word
(if (numberp shift) (+ shift offset) offset)
(nreverse miss-list) (nreverse guess-list)))))))