Function: flyspell-post-command-hook

flyspell-post-command-hook is an interactive and byte-compiled function defined in flyspell.el.gz.

Signature

(flyspell-post-command-hook)

Documentation

The post-command-hook used by flyspell to check a word on-the-fly.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/textmodes/flyspell.el.gz
;;*---------------------------------------------------------------------*/
;;*    flyspell-post-command-hook ...                                   */
;;*    -------------------------------------------------------------    */
;;*    It is possible that we check several words:                      */
;;*    1- the current word is checked if the predicate                  */
;;*       FLYSPELL-CHECK-WORD-P is true                                 */
;;*    2- the word that used to be the current word before the          */
;;*       THIS-COMMAND is checked if:                                   */
;;*        a- the previous word is different from the current word      */
;;*        b- the previous word has not just been checked by the        */
;;*           previous FLYSPELL-POST-COMMAND-HOOK                       */
;;*    3- the words changed by the THIS-COMMAND that are neither the    */
;;*       previous word nor the current word                            */
;;*---------------------------------------------------------------------*/
(defun flyspell-post-command-hook ()
  "The `post-command-hook' used by flyspell to check a word on-the-fly."
  (interactive)
  (when flyspell-mode
    (with-local-quit
      (let ((command this-command)
            ;; Prevent anything we do from affecting the mark.
            deactivate-mark)
        (if (and (eq command 'transpose-chars)
                 flyspell-pre-point)
            (save-excursion
              (goto-char (- flyspell-pre-point 1))
              (flyspell-word)))
        (if (flyspell-check-pre-word-p)
            (save-excursion
              '(flyspell-debug-signal-pre-word-checked)
              (goto-char flyspell-pre-point)
              (flyspell-word)))
        (if (flyspell-check-word-p)
            (progn
              '(flyspell-debug-signal-word-checked)
              ;; FIXME: This should be asynchronous!
              (flyspell-word)
              ;; we remember which word we have just checked.
              ;; this will be used next time we will check a word
              ;; to compare the next current word with the word
              ;; that has been registered in the pre-command-hook
              ;; that is these variables are used within the predicate
              ;; FLYSPELL-CHECK-PRE-WORD-P
              (setq flyspell-pre-pre-buffer (current-buffer))
              (setq flyspell-pre-pre-point  (point)))
          (setq flyspell-pre-pre-buffer nil)
          (setq flyspell-pre-pre-point  nil)
          ;; when a word is not checked because of a delayed command
          ;; we do not disable the ispell cache.
          (when (and (symbolp this-command)
                     (get this-command 'flyspell-delayed))
            (setq flyspell-word-cache-end -1)
            (setq flyspell-word-cache-result '_)))
        (while (and (not (input-pending-p)) (consp flyspell-changes))
          (let ((start (car (car flyspell-changes)))
                (stop  (cdr (car flyspell-changes))))
            (if (flyspell-check-changed-word-p start stop)
                (save-excursion
                  '(flyspell-debug-signal-changed-checked)
                  (goto-char start)
                  (flyspell-word)))
            (setq flyspell-changes (cdr flyspell-changes))))
        (setq flyspell-previous-command command)))))