Function: flyspell-auto-correct-word
flyspell-auto-correct-word is an interactive and byte-compiled
function defined in flyspell.el.gz.
Signature
(flyspell-auto-correct-word)
Documentation
Correct the current word.
This command proposes various successive corrections for the current word. If invoked repeatedly on the same position, it cycles through the possible corrections of the current word.
See flyspell-get-word for details of how this finds the word to
spell-check.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/textmodes/flyspell.el.gz
;;*---------------------------------------------------------------------*/
;;* flyspell-auto-correct-word ... */
;;*---------------------------------------------------------------------*/
(defun flyspell-auto-correct-word ()
"Correct the current word.
This command proposes various successive corrections for the
current word. If invoked repeatedly on the same position, it
cycles through the possible corrections of the current word.
See `flyspell-get-word' for details of how this finds the word to
spell-check."
(interactive)
;; If we are not in the construct where flyspell should be active,
;; invoke the original binding of M-TAB, if that was recorded.
(let ((pos (point))
(old-max (point-max))
(next-cmd (and (functionp flyspell-generic-check-word-predicate)
(not (funcall flyspell-generic-check-word-predicate))
(let ((flyspell-mode nil))
(key-binding (this-command-keys))))))
(if next-cmd
(command-execute next-cmd)
;; Flush a possibly stale cache from previous invocations of
;; flyspell-auto-correct-word/flyspell-auto-correct-previous-word.
(if (not (memq last-command '(flyspell-auto-correct-word
flyspell-auto-correct-previous-word)))
(setq flyspell-auto-correct-region nil))
;; Use the correct dictionary.
(flyspell-accept-buffer-local-defs)
(if (and (eq flyspell-auto-correct-pos pos)
(consp flyspell-auto-correct-region))
;; We have already been using the function at the same location.
(let* ((start (car flyspell-auto-correct-region))
(len (cdr flyspell-auto-correct-region)))
(flyspell-unhighlight-at start)
(delete-region start (+ start len))
(setq flyspell-auto-correct-ring (cdr flyspell-auto-correct-ring))
(let* ((word (car flyspell-auto-correct-ring))
(len (length word)))
(rplacd flyspell-auto-correct-region len)
(goto-char start)
(if flyspell-abbrev-p
(if (flyspell-already-abbrevp (flyspell-abbrev-table)
flyspell-auto-correct-word)
(flyspell-change-abbrev (flyspell-abbrev-table)
flyspell-auto-correct-word
word)
(flyspell-define-abbrev flyspell-auto-correct-word word)))
(funcall flyspell-insert-function word)
(flyspell-word)
(flyspell-display-next-corrections flyspell-auto-correct-ring))
(flyspell-adjust-cursor-point pos (point) old-max)
(setq flyspell-auto-correct-pos (point)))
;; Fetch the word to be checked.
(let ((word (flyspell-get-word)))
(if (consp word)
(let ((start (car (cdr word)))
(end (car (cdr (cdr word))))
(word (car word))
poss ispell-filter)
(setq flyspell-auto-correct-word word)
;; Now check spelling of word..
(ispell-send-string "%\n") ;Put in verbose mode.
(ispell-send-string (concat "^" word "\n"))
;; Wait until ispell has processed word.
(while (progn
(accept-process-output ispell-process)
(not (string= "" (car ispell-filter)))))
;; Remove leading empty element.
(setq ispell-filter (cdr ispell-filter))
;; Ispell process should return something after word is sent.
;; Tag word as valid (i.e., skip) otherwise.
(or ispell-filter
(setq ispell-filter '(*)))
(if (consp ispell-filter)
(setq poss (ispell-parse-output (car ispell-filter))))
(cond
((or (eq poss t) (stringp poss))
;; Don't correct word.
t)
((null poss)
;; Ispell error.
(error "Ispell: error in Ispell process"))
(t
;; The word is incorrect, we have to propose a replacement.
(let ((replacements (flyspell-sort (car (cdr (cdr poss)))
word)))
(setq flyspell-auto-correct-region nil)
(if (consp replacements)
(progn
(let ((replace (car replacements)))
(let ((new-word replace))
(if (not (equal new-word (car poss)))
(progn
;; then save the current replacements
(setq flyspell-auto-correct-region
(cons start (length new-word)))
(let ((l replacements))
(while (consp (cdr l))
(setq l (cdr l)))
(rplacd l (cons (car poss) replacements)))
(setq flyspell-auto-correct-ring
replacements)
(flyspell-unhighlight-at start)
(delete-region start end)
(funcall flyspell-insert-function new-word)
(if flyspell-abbrev-p
(if (flyspell-already-abbrevp
(flyspell-abbrev-table) word)
(flyspell-change-abbrev
(flyspell-abbrev-table)
word
new-word)
(flyspell-define-abbrev word
new-word)))
(flyspell-word)
(flyspell-display-next-corrections
(cons new-word flyspell-auto-correct-ring))
(flyspell-adjust-cursor-point pos
(point)
old-max))))))))))
(setq flyspell-auto-correct-pos (point))
(ispell-pdict-save t))))))))