Function: flyspell-maybe-correct-transposition

flyspell-maybe-correct-transposition is a byte-compiled function defined in flyspell.el.gz.

Signature

(flyspell-maybe-correct-transposition BEG END POSS)

Documentation

Check replacements for transposed characters.

If the text between BEG and END is equal to a correction suggested by Ispell, after transposing two adjacent characters, correct the text, and return t.

The third arg POSS is either the symbol doublon or a list of possible corrections as returned by ispell-parse-output.

This function is meant to be added to flyspell-incorrect-hook.

Source Code

;; Defined in /usr/src/emacs/lisp/textmodes/flyspell.el.gz
;;*---------------------------------------------------------------------*/
;;*    Some example functions for real autocorrecting                   */
;;*---------------------------------------------------------------------*/
(defun flyspell-maybe-correct-transposition (beg end poss)
  "Check replacements for transposed characters.

If the text between BEG and END is equal to a correction suggested by
Ispell, after transposing two adjacent characters, correct the text,
and return t.

The third arg POSS is either the symbol `doublon' or a list of
possible corrections as returned by `ispell-parse-output'.

This function is meant to be added to `flyspell-incorrect-hook'."
  (when (consp poss)
    (catch 'done
      (let ((str (buffer-substring beg end))
	    (i 0) (len (- end beg)) tmp)
	(while (< (1+ i) len)
	  (setq tmp (aref str i))
	  (aset str i (aref str (1+ i)))
	  (aset str (1+ i) tmp)
          (when (member str (nth 2 poss))
	    (save-excursion
	      (goto-char (+ beg i 1))
	      (transpose-chars 1))
	    (throw 'done t))
	  (setq tmp (aref str i))
	  (aset str i (aref str (1+ i)))
	  (aset str (1+ i) tmp)
	  (setq i (1+ i))))
      nil)))