• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /macosx-10.9.5/emacs-92/emacs/lisp/textmodes/

Lines Matching +defs:flyspell +defs:prog +defs:mode

0 ;;; flyspell.el --- on-the-fly spell checker
29 ;; Flyspell is a minor Emacs mode performing on-the-fly spelling
32 ;; To enable Flyspell minor mode, type M-x flyspell-mode.
36 ;; M-x flyspell-prog-mode.
37 ;; In that mode only text inside comments is checked.
42 ;; Some user variables control the behavior of flyspell. They are
52 (defgroup flyspell nil
55 :prefix "flyspell-"
62 (defcustom flyspell-highlight-flag t
65 :group 'flyspell
68 (defcustom flyspell-mark-duplications-flag t
71 \"large\" regions; see `flyspell-large-region'."
72 :group 'flyspell
75 (defcustom flyspell-sort-corrections nil
77 :group 'flyspell
81 (defcustom flyspell-duplicate-distance -1
85 Flyspell uses a different face (`flyspell-duplicate') to highlight it.
89 :group 'flyspell
93 (defcustom flyspell-delay 3
95 :group 'flyspell
98 (defcustom flyspell-persistent-highlight t
102 :group 'flyspell
105 (defcustom flyspell-highlight-properties t
107 :group 'flyspell
110 (defcustom flyspell-default-delayed-commands
118 See `flyspell-delayed-commands'."
119 :group 'flyspell
123 (defcustom flyspell-delayed-commands nil
124 "List of commands that are \"delayed\" for Flyspell mode.
126 whose length is specified by `flyspell-delay'."
127 :group 'flyspell
130 (defcustom flyspell-default-deplacement-commands
136 See `flyspell-deplacement-commands'."
137 :group 'flyspell
141 (defcustom flyspell-deplacement-commands nil
142 "List of commands that are \"deplacement\" for Flyspell mode.
145 :group 'flyspell
149 (defcustom flyspell-issue-welcome-flag t
151 :group 'flyspell
154 (defcustom flyspell-issue-message-flag t
156 :group 'flyspell
159 (defcustom flyspell-incorrect-hook nil
168 :group 'flyspell
172 (defcustom flyspell-default-dictionary nil
174 This is passed to the `ispell-change-dictionary' when flyspell is started.
176 when flyspell is started, the value of that variable is used instead
177 of `flyspell-default-dictionary' to select the default dictionary.
178 Otherwise, if `flyspell-default-dictionary' is nil, it means to use
180 :group 'flyspell
184 (defcustom flyspell-tex-command-regexp
187 :group 'flyspell
191 (defcustom flyspell-check-tex-math-command nil
196 :group 'flyspell
199 (defcustom flyspell-dictionaries-that-consider-dash-as-word-delimiter
202 :group 'flyspell
206 (defcustom flyspell-abbrev-p
209 :group 'flyspell
213 (defcustom flyspell-use-global-abbrev-table-p
216 :group 'flyspell
220 (defcustom flyspell-mode-line-string " Fly"
221 "String displayed on the modeline when flyspell is active.
223 :group 'flyspell
226 (defcustom flyspell-large-region 1000
229 `flyspell-region' checks the words sequentially using regular
230 flyspell methods. Else, if the region is large, a new Ispell process is
236 If `flyspell-large-region' is nil, all regions are treated as small."
237 :group 'flyspell
241 (defcustom flyspell-insert-function (function insert)
242 "Function for inserting word by flyspell upon correction."
243 :group 'flyspell
246 (defcustom flyspell-before-incorrect-word-string nil
248 :group 'flyspell
251 (defcustom flyspell-after-incorrect-word-string nil
253 :group 'flyspell
256 (defcustom flyspell-use-meta-tab t
257 "Non-nil means that flyspell uses M-TAB to correct word."
258 :group 'flyspell
261 (defcustom flyspell-auto-correct-binding
263 "The key binding for flyspell auto correction."
264 :group 'flyspell)
269 ;;* Mode specific options enable users to disable flyspell on */
270 ;;* certain word depending of the emacs mode. For instance, when */
271 ;;* using flyspell with mail-mode add the following expression */
273 ;;* (add-hook 'mail-mode */
274 ;;* '(lambda () (setq flyspell-generic-check-word-predicate */
275 ;;* 'mail-mode-flyspell-verify))) */
277 (defvar flyspell-generic-check-word-predicate nil
278 "Function providing per-mode customization over which words are flyspelled.
280 Flyspell mode sets this variable to whatever is the `flyspell-mode-predicate'
281 property of the major mode name.")
282 (make-variable-buffer-local 'flyspell-generic-check-word-predicate)
283 (defvaralias 'flyspell-generic-check-word-p
284 'flyspell-generic-check-word-predicate)
286 ;;*--- mail mode -------------------------------------------------------*/
287 (put 'mail-mode 'flyspell-mode-predicate 'mail-mode-flyspell-verify)
288 (put 'message-mode 'flyspell-mode-predicate 'mail-mode-flyspell-verify)
289 (defun mail-mode-flyspell-verify ()
290 "Function used for `flyspell-generic-check-word-predicate' in Mail mode."
315 ;;*--- texinfo mode ----------------------------------------------------*/
316 (put 'texinfo-mode 'flyspell-mode-predicate 'texinfo-mode-flyspell-verify)
317 (defun texinfo-mode-flyspell-verify ()
318 "Function used for `flyspell-generic-check-word-predicate' in Texinfo mode."
323 ;;*--- tex mode --------------------------------------------------------*/
324 (put 'tex-mode 'flyspell-mode-predicate 'tex-mode-flyspell-verify)
325 (defun tex-mode-flyspell-verify ()
326 "Function used for `flyspell-generic-check-word-predicate' in LaTeX mode."
338 ;;*--- sgml mode -------------------------------------------------------*/
339 (put 'sgml-mode 'flyspell-mode-predicate 'sgml-mode-flyspell-verify)
340 (put 'html-mode 'flyspell-mode-predicate 'sgml-mode-flyspell-verify)
342 (defun sgml-mode-flyspell-verify ()
343 "Function used for `flyspell-generic-check-word-predicate' in SGML mode."
366 ;;* Programming mode */
368 (defvar flyspell-prog-text-faces
370 "Faces corresponding to text in programming-mode buffers.")
372 (defun flyspell-generic-progmode-verify ()
373 "Used for `flyspell-generic-check-word-predicate' in programming modes."
375 (memq f flyspell-prog-text-faces)))
378 (defun flyspell-prog-mode ()
379 "Turn on `flyspell-mode' for comments and strings."
381 (setq flyspell-generic-check-word-predicate
382 'flyspell-generic-progmode-verify)
383 (flyspell-mode 1)
384 (run-hooks 'flyspell-prog-mode-hook))
399 ;;* The minor mode declaration. */
401 (defvar flyspell-mouse-map
404 #'flyspell-correct-word)
408 (defvar flyspell-mode-map
410 (if flyspell-use-meta-tab
411 (define-key map "\M-\t" 'flyspell-auto-correct-word))
412 (define-key map flyspell-auto-correct-binding 'flyspell-auto-correct-previous-word)
413 (define-key map [(control ?\,)] 'flyspell-goto-next-error)
414 (define-key map [(control ?\.)] 'flyspell-auto-correct-word)
415 (define-key map [?\C-c ?$] 'flyspell-correct-word-before-point)
417 "Minor mode keymap for Flyspell mode--for the whole buffer.")
420 (defvar flyspell-consider-dash-as-word-delimiter-flag nil
422 (make-variable-buffer-local 'flyspell-consider-dash-as-word-delimiter-flag)
423 (defvar flyspell-dash-dictionary nil)
424 (make-variable-buffer-local 'flyspell-dash-dictionary)
425 (defvar flyspell-dash-local-dictionary nil)
426 (make-variable-buffer-local 'flyspell-dash-local-dictionary)
431 (defface flyspell-incorrect
435 :group 'flyspell)
437 (put 'flyspell-incorrect-face 'face-alias 'flyspell-incorrect)
439 (defface flyspell-duplicate
443 See also `flyspell-duplicate-distance'."
444 :group 'flyspell)
446 (put 'flyspell-duplicate-face 'face-alias 'flyspell-duplicate)
448 (defvar flyspell-overlay nil)
451 ;;* flyspell-mode ... */
453 ;;;###autoload(defvar flyspell-mode nil)
455 (define-minor-mode flyspell-mode
456 "Minor mode performing on-the-fly spelling checking.
458 The default flyspell behavior is to highlight incorrect words.
459 With no argument, this command toggles Flyspell mode.
460 With a prefix argument ARG, turn Flyspell minor mode on iff ARG is positive.
464 \\[flyspell-auto-correct-word]: automatically correct word.
465 \\[flyspell-auto-correct-previous-word]: automatically correct the last misspelled word.
466 \\[flyspell-correct-word] (or down-mouse-2): popup correct words.
469 This runs `flyspell-mode-hook' after flyspell is entered.
472 `flyspell-mode' uses `ispell-mode'. Thus all Ispell options are
478 \(add-hook 'tex-mode-hook (function (lambda () (setq ispell-parser 'tex))))
481 \\[flyspell-region] checks all words inside a region.
482 \\[flyspell-buffer] checks the whole buffer."
483 :lighter flyspell-mode-line-string
484 :keymap flyspell-mode-map
485 :group 'flyspell
486 (if flyspell-mode
487 (flyspell-mode-on)
488 (flyspell-mode-off)))
491 (defun turn-on-flyspell ()
492 "Unconditionally turn on Flyspell mode."
493 (flyspell-mode 1))
496 (defun turn-off-flyspell ()
497 "Unconditionally turn off Flyspell mode."
498 (flyspell-mode -1))
500 (custom-add-option 'text-mode-hook 'turn-on-flyspell)
503 ;;* flyspell-buffers ... */
505 ;;* For remembering buffers running flyspell */
507 (defvar flyspell-buffers nil)
510 ;;* flyspell-minibuffer-p ... */
512 (defun flyspell-minibuffer-p (buffer)
518 ;;* flyspell-accept-buffer-local-defs ... */
520 (defvar flyspell-last-buffer nil
521 "The buffer in which the last flyspell operation took place.")
523 (defun flyspell-accept-buffer-local-defs (&optional force)
524 ;; When flyspell-word is used inside a loop (e.g. when processing
525 ;; flyspell-changes), the calls to `ispell-accept-buffer-local-defs' end
527 (when (or force (not (eq flyspell-last-buffer (current-buffer))))
528 (setq flyspell-last-buffer (current-buffer))
535 (unless (and (eq flyspell-dash-dictionary ispell-dictionary)
536 (eq flyspell-dash-local-dictionary ispell-local-dictionary))
538 (setq flyspell-dash-dictionary ispell-dictionary)
539 (setq flyspell-dash-local-dictionary ispell-local-dictionary)
540 (setq flyspell-consider-dash-as-word-delimiter-flag
542 flyspell-dictionaries-that-consider-dash-as-word-delimiter)))))
544 (defun flyspell-hack-local-variables-hook ()
547 (flyspell-accept-buffer-local-defs 'force))
549 (defun flyspell-kill-ispell-hook ()
550 (setq flyspell-last-buffer nil)
553 (kill-local-variable 'flyspell-word-cache-word))))
556 ;; flyspell-mode-on, since flyspell-region may be used without ever turning
557 ;; on flyspell-mode.
558 (add-hook 'ispell-kill-ispell-hook 'flyspell-kill-ispell-hook)
561 ;;* flyspell-mode-on ... */
563 (defun flyspell-mode-on ()
564 "Turn Flyspell mode on. Do not use this; use `flyspell-mode' instead."
566 (setq ispell-highlight-face 'flyspell-incorrect)
569 (if flyspell-default-dictionary
570 (ispell-change-dictionary flyspell-default-dictionary)))
574 ;; Pass the `force' argument for the case where flyspell was active already
576 (flyspell-accept-buffer-local-defs 'force)
577 ;; we put the `flyspell-delayed' property on some commands
578 (flyspell-delay-commands)
579 ;; we put the `flyspell-deplacement' property on some commands
580 (flyspell-deplacement-commands)
581 ;; we bound flyspell action to post-command hook
582 (add-hook 'post-command-hook (function flyspell-post-command-hook) t t)
583 ;; we bound flyspell action to pre-command hook
584 (add-hook 'pre-command-hook (function flyspell-pre-command-hook) t t)
585 ;; we bound flyspell action to after-change hook
586 (add-hook 'after-change-functions 'flyspell-after-change-function nil t)
587 ;; we bound flyspell action to hack-local-variables-hook
589 (function flyspell-hack-local-variables-hook) t t)
590 ;; set flyspell-generic-check-word-predicate based on the major mode
591 (let ((mode-predicate (get major-mode 'flyspell-mode-predicate)))
592 (if mode-predicate
593 (setq flyspell-generic-check-word-predicate mode-predicate)))
595 (if (and flyspell-issue-message-flag
596 flyspell-issue-welcome-flag
598 (let ((binding (where-is-internal 'flyspell-auto-correct-word
602 (format "Welcome to flyspell. Use %s or Mouse-2 to correct words."
604 "Welcome to flyspell. Use Mouse-2 to correct words."))))
605 ;; we end with the flyspell hooks
606 (run-hooks 'flyspell-mode-hook))
609 ;;* flyspell-delay-commands ... */
611 (defun flyspell-delay-commands ()
613 (mapcar 'flyspell-delay-command flyspell-default-delayed-commands)
614 (mapcar 'flyspell-delay-command flyspell-delayed-commands))
617 ;;* flyspell-delay-command ... */
619 (defun flyspell-delay-command (command)
621 When flyspell `post-command-hook' is invoked because a delayed command
623 It will be checked only after `flyspell-delay' seconds."
625 (put command 'flyspell-delayed t))
628 ;;* flyspell-deplacement-commands ... */
630 (defun flyspell-deplacement-commands ()
632 (mapcar 'flyspell-deplacement-command flyspell-default-deplacement-commands)
633 (mapcar 'flyspell-deplacement-command flyspell-deplacement-commands))
636 ;;* flyspell-deplacement-command ... */
638 (defun flyspell-deplacement-command (command)
640 When flyspell `post-command-hook' is invoked because of a deplacement command
644 (put command 'flyspell-deplacement t))
647 ;;* flyspell-word-cache ... */
649 (defvar flyspell-word-cache-start nil)
650 (defvar flyspell-word-cache-end nil)
651 (defvar flyspell-word-cache-word nil)
652 (defvar flyspell-word-cache-result '_)
653 (make-variable-buffer-local 'flyspell-word-cache-start)
654 (make-variable-buffer-local 'flyspell-word-cache-end)
655 (make-variable-buffer-local 'flyspell-word-cache-word)
656 (make-variable-buffer-local 'flyspell-word-cache-result)
659 ;;* The flyspell pre-hook, store the current position. In the */
663 (defvar flyspell-pre-buffer nil)
664 (defvar flyspell-pre-point nil)
665 (defvar flyspell-pre-column nil)
666 (defvar flyspell-pre-pre-buffer nil)
667 (defvar flyspell-pre-pre-point nil)
670 ;;* flyspell-previous-command ... */
672 (defvar flyspell-previous-command nil
676 ;;* flyspell-pre-command-hook ... */
678 (defun flyspell-pre-command-hook ()
681 (setq flyspell-pre-buffer (current-buffer))
682 (setq flyspell-pre-point (point))
683 (setq flyspell-pre-column (current-column)))
686 ;;* flyspell-mode-off ... */
689 (defun flyspell-mode-off ()
690 "Turn Flyspell mode off."
692 (remove-hook 'post-command-hook (function flyspell-post-command-hook) t)
693 (remove-hook 'pre-command-hook (function flyspell-pre-command-hook) t)
694 (remove-hook 'after-change-functions 'flyspell-after-change-function t)
696 (function flyspell-hack-local-variables-hook) t)
697 ;; we remove all the flyspell hilightings
698 (flyspell-delete-all-overlays)
700 (setq flyspell-pre-buffer nil)
701 (setq flyspell-pre-point nil)
702 ;; we mark the mode as killed
703 (setq flyspell-mode nil))
706 ;;* flyspell-check-pre-word-p ... */
708 (defun flyspell-check-pre-word-p ()
713 ((or (not (numberp flyspell-pre-point))
714 (not (bufferp flyspell-pre-buffer))
715 (not (buffer-live-p flyspell-pre-buffer)))
717 ((and (eq flyspell-pre-pre-point flyspell-pre-point)
718 (eq flyspell-pre-pre-buffer flyspell-pre-buffer))
720 ((or (and (= flyspell-pre-point (- (point) 1))
721 (eq (char-syntax (char-after flyspell-pre-point)) ?w))
722 (= flyspell-pre-point (point))
723 (= flyspell-pre-point (+ (point) 1)))
727 (or (get this-command 'flyspell-delayed)
728 (and (get this-command 'flyspell-deplacement)
729 (eq flyspell-previous-command this-command)))
731 (= (current-column) flyspell-pre-column)
732 (eq (char-syntax (char-after flyspell-pre-point)) ?w)))
734 ((not (eq (current-buffer) flyspell-pre-buffer))
736 ((not (and (numberp flyspell-word-cache-start)
737 (numberp flyspell-word-cache-end)))
740 (or (< flyspell-pre-point flyspell-word-cache-start)
741 (> flyspell-pre-point flyspell-word-cache-end)))))
744 ;;* The flyspell after-change-hook, store the change position. In */
748 (defvar flyspell-changes nil)
749 (make-variable-buffer-local 'flyspell-changes)
752 ;;* flyspell-after-change-function ... */
754 (defun flyspell-after-change-function (start stop len)
756 (push (cons start stop) flyspell-changes))
759 ;;* flyspell-check-changed-word-p ... */
761 (defun flyspell-check-changed-word-p (start stop)
768 ((not (numberp flyspell-pre-point))
770 ((and (>= flyspell-pre-point start) (<= flyspell-pre-point stop))
779 ;;* flyspell-check-word-p ... */
781 (defun flyspell-check-word-p ()
790 (not (eq (current-column) flyspell-pre-column)))
793 (and (looking-at (flyspell-get-not-casechars))
794 (or flyspell-consider-dash-as-word-delimiter-flag
800 ((get this-command 'flyspell-deplacement)
801 (not (eq flyspell-previous-command this-command)))
802 ((get this-command 'flyspell-delayed)
806 (sit-for flyspell-delay)))
811 ;;* flyspell-debug-signal-no-check ... */
813 (defun flyspell-debug-signal-no-check (msg obj)
815 (with-current-buffer (get-buffer-create "*flyspell-debug*")
821 ;;* flyspell-debug-signal-pre-word-checked ... */
823 (defun flyspell-debug-signal-pre-word-checked ()
825 (with-current-buffer (get-buffer-create "*flyspell-debug*")
827 (insert (format " pre-point : %S\n" flyspell-pre-point))
828 (insert (format " pre-buffer : %S\n" flyspell-pre-buffer))
829 (insert (format " cache-start: %S\n" flyspell-word-cache-start))
830 (insert (format " cache-end : %S\n" flyspell-word-cache-end))
834 ;;* flyspell-debug-signal-word-checked ... */
836 (defun flyspell-debug-signal-word-checked ()
840 (with-current-buffer (get-buffer-create "*flyspell-debug*")
844 (get this-command 'flyspell-delayed))))
858 (and (and (looking-at (flyspell-get-not-casechars)) 1)
859 (and (or flyspell-consider-dash-as-word-delimiter-flag
865 (get this-command 'flyspell-delayed)))
873 (and (looking-at (flyspell-get-not-casechars))
874 (or flyspell-consider-dash-as-word-delimiter-flag
879 ((not (integerp flyspell-delay))
887 ;;* flyspell-debug-signal-changed-checked ... */
889 (defun flyspell-debug-signal-changed-checked ()
892 (with-current-buffer (get-buffer-create "*flyspell-debug*")
898 ;;* flyspell-post-command-hook ... */
911 (defun flyspell-post-command-hook ()
912 "The `post-command-hook' used by flyspell to check a word in-the-fly."
917 (if (flyspell-check-pre-word-p)
918 (with-current-buffer flyspell-pre-buffer
919 '(flyspell-debug-signal-pre-word-checked)
921 (goto-char flyspell-pre-point)
922 (flyspell-word))))
923 (if (flyspell-check-word-p)
925 '(flyspell-debug-signal-word-checked)
926 (flyspell-word)
933 (setq flyspell-pre-pre-buffer (current-buffer))
934 (setq flyspell-pre-pre-point (point)))
936 (setq flyspell-pre-pre-buffer nil)
937 (setq flyspell-pre-pre-point nil)
940 (if (and (symbolp this-command) (get this-command 'flyspell-delayed))
942 (setq flyspell-word-cache-end -1)
943 (setq flyspell-word-cache-result '_)))))
944 (while (and (not (input-pending-p)) (consp flyspell-changes))
945 (let ((start (car (car flyspell-changes)))
946 (stop (cdr (car flyspell-changes))))
947 (if (flyspell-check-changed-word-p start stop)
949 '(flyspell-debug-signal-changed-checked)
951 (flyspell-word)))
952 (setq flyspell-changes (cdr flyspell-changes))))
953 (setq flyspell-previous-command command)))
956 ;;* flyspell-notify-misspell ... */
958 (defun flyspell-notify-misspell (word poss)
961 (if flyspell-sort-corrections
964 (if flyspell-issue-message-flag
968 ;;* flyspell-word-search-backward ... */
970 (defun flyspell-word-search-backward (word bound)
976 (let ((lw (flyspell-get-word '())))
983 ;;* flyspell-word-search-forward ... */
985 (defun flyspell-word-search-forward (word bound)
991 (let ((lw (flyspell-get-word '())))
998 ;;* flyspell-word ... */
1000 (defun flyspell-word (&optional following)
1005 (flyspell-accept-buffer-local-defs)
1007 (flyspell-word (flyspell-get-word following))
1009 (if (or (eq flyspell-word nil)
1010 (and (fboundp flyspell-generic-check-word-predicate)
1011 (not (funcall flyspell-generic-check-word-predicate))))
1014 ;; destructure return flyspell-word info list.
1015 (setq start (car (cdr flyspell-word))
1016 end (car (cdr (cdr flyspell-word)))
1017 word (car flyspell-word))
1023 flyspell-mark-duplications-flag
1031 (flyspell-word-search-backward word bound))))
1034 (flyspell-highlight-incorrect-region start end 'doublon)
1036 ((and (eq flyspell-word-cache-start start)
1037 (eq flyspell-word-cache-end end)
1038 (string-equal flyspell-word-cache-word word))
1040 flyspell-word-cache-result)
1042 (flyspell-tex-command-p flyspell-word))
1044 (flyspell-unhighlight-at start)
1046 (flyspell-unhighlight-at (- end 1)))
1050 (setq flyspell-word-cache-start start)
1051 (setq flyspell-word-cache-end end)
1052 (setq flyspell-word-cache-word word)
1055 ;; put in verbose mode
1068 ;; back to terse mode.
1079 (setq flyspell-word-cache-result t)
1080 (flyspell-unhighlight-at start)
1082 (flyspell-unhighlight-at (- end 1)))
1084 ((and (stringp poss) flyspell-highlight-flag)
1086 (setq flyspell-word-cache-result t)
1087 (flyspell-unhighlight-at start)
1089 (flyspell-unhighlight-at (- end 1)))
1092 (setq flyspell-word-cache-result t)
1093 (flyspell-unhighlight-at start)
1095 (flyspell-unhighlight-at (- end 1)))
1097 ((or (and (< flyspell-duplicate-distance 0)
1100 (flyspell-word-search-backward
1105 (flyspell-word-search-forward
1108 (and (> flyspell-duplicate-distance 0)
1111 (flyspell-word-search-backward
1114 flyspell-duplicate-distance)))
1117 (flyspell-word-search-forward
1120 flyspell-duplicate-distance))))))
1122 ;; twice within flyspell-duplicate-distance.
1123 (setq flyspell-word-cache-result nil)
1124 (if flyspell-highlight-flag
1125 (flyspell-highlight-duplicate-region
1130 (setq flyspell-word-cache-result nil)
1132 (if flyspell-highlight-flag
1133 (flyspell-highlight-incorrect-region
1135 (flyspell-notify-misspell word poss))
1143 ;;* flyspell-tex-math-initialized ... */
1145 (defvar flyspell-tex-math-initialized nil)
1148 ;;* flyspell-math-tex-command-p ... */
1153 ;;* flyspell-tex-math-initialized to make a special case the first */
1156 (defun flyspell-math-tex-command-p ()
1159 (flyspell-check-tex-math-command
1161 ((eq flyspell-tex-math-initialized t)
1163 ((eq flyspell-tex-math-initialized 'error)
1166 (setq flyspell-tex-math-initialized t)
1170 (setq flyspell-tex-math-initialized 'error)
1174 ;;* flyspell-tex-command-p ... */
1176 (defun flyspell-tex-command-p (word)
1183 (looking-at flyspell-tex-command-regexp)
1185 (flyspell-math-tex-command-p)))
1188 ;;* flyspell-casechars-cache ... */
1190 (defvar flyspell-casechars-cache nil)
1191 (defvar flyspell-ispell-casechars-cache nil)
1192 (make-variable-buffer-local 'flyspell-casechars-cache)
1193 (make-variable-buffer-local 'flyspell-ispell-casechars-cache)
1196 ;;* flyspell-get-casechars ... */
1198 (defun flyspell-get-casechars ()
1205 (setq flyspell-ispell-casechars-cache ispell-casechars)
1206 (setq flyspell-casechars-cache
1211 flyspell-casechars-cache)
1213 (setq flyspell-ispell-casechars-cache ispell-casechars)
1214 (setq flyspell-casechars-cache ispell-casechars)
1215 flyspell-casechars-cache))))
1218 ;;* flyspell-get-not-casechars-cache ... */
1220 (defvar flyspell-not-casechars-cache nil)
1221 (defvar flyspell-ispell-not-casechars-cache nil)
1222 (make-variable-buffer-local 'flyspell-not-casechars-cache)
1223 (make-variable-buffer-local 'flyspell-ispell-not-casechars-cache)
1226 ;;* flyspell-get-not-casechars ... */
1228 (defun flyspell-get-not-casechars ()
1233 (setq flyspell-ispell-not-casechars-cache ispell-not-casechars)
1234 (setq flyspell-not-casechars-cache
1239 flyspell-not-casechars-cache)
1241 (setq flyspell-ispell-not-casechars-cache ispell-not-casechars)
1242 (setq flyspell-not-casechars-cache ispell-not-casechars)
1243 flyspell-not-casechars-cache))))
1246 ;;* flyspell-get-word ... */
1248 (defun flyspell-get-word (following &optional extra-otherchars)
1250 If optional argument FOLLOWING is non-nil or if `flyspell-following-word'
1256 Word syntax described by `flyspell-dictionary-alist' (which see)."
1257 (let* ((flyspell-casechars (flyspell-get-casechars))
1258 (flyspell-not-casechars (flyspell-get-not-casechars))
1261 (word-regexp (concat flyspell-casechars
1267 flyspell-casechars
1275 (if (not (looking-at flyspell-casechars))
1277 (re-search-forward flyspell-casechars nil t)
1278 (re-search-backward flyspell-casechars nil t)))
1280 (re-search-backward flyspell-not-casechars nil 'start)
1291 (if (looking-at flyspell-casechars)
1292 (re-search-backward flyspell-not-casechars nil 'move)))
1296 (if (looking-at flyspell-casechars)
1297 (re-search-backward flyspell-not-casechars nil 'move)
1309 ;;* flyspell-small-region ... */
1311 (defun flyspell-small-region (beg end)
1321 (if (and flyspell-issue-message-flag (= count 100))
1327 (flyspell-word)
1334 (if flyspell-issue-message-flag (message "Spell Checking completed."))
1335 (flyspell-word)))
1338 ;;* flyspell-external-ispell-process ... */
1340 (defvar flyspell-external-ispell-process '()
1344 ;;* flyspell-external-ispell-buffer ... */
1346 (defvar flyspell-external-ispell-buffer '())
1347 (defvar flyspell-large-region-buffer '())
1348 (defvar flyspell-large-region-beg (point-min))
1349 (defvar flyspell-large-region-end (point-max))
1352 ;;* flyspell-external-point-words ... */
1354 (defun flyspell-external-point-words ()
1356 The list of incorrect words should be in `flyspell-external-ispell-buffer'.
1358 The buffer to mark them in is `flyspell-large-region-buffer'."
1361 (buffer-scan-pos flyspell-large-region-beg)
1363 (with-current-buffer flyspell-external-ispell-buffer
1375 (if flyspell-issue-message-flag
1379 (with-current-buffer flyspell-large-region-buffer
1386 flyspell-large-region-end t)
1390 ;; so flyspell-get-word will find it.
1392 (flyspell-get-word nil)))
1403 ;; what flyspell considers the
1423 (flyspell-word)
1433 (if flyspell-issue-message-flag (message "Spell Checking completed.")))
1438 (kill-buffer flyspell-external-ispell-buffer)
1439 (setq flyspell-external-ispell-buffer nil)))
1442 ;;* flyspell-process-localwords ... */
1447 (defun flyspell-process-localwords (misspellings-buffer)
1470 ;; flyspell-large-region.
1480 ;;* flyspell-check-region-doublons
1482 (defun flyspell-check-region-doublons (beg end)
1486 (flyspell-word) ; Make sure current word is checked
1491 (flyspell-word)
1493 (flyspell-word)))
1496 ;;* flyspell-large-region ... */
1498 (defun flyspell-large-region (beg end)
1500 (buffer (get-buffer-create "*flyspell-region*")))
1501 (setq flyspell-external-ispell-buffer buffer)
1502 (setq flyspell-large-region-buffer curbuf)
1503 (setq flyspell-large-region-beg beg)
1504 (setq flyspell-large-region-end end)
1505 (flyspell-accept-buffer-local-defs)
1509 (if flyspell-issue-message-flag (message "Checking region..."))
1537 (flyspell-process-localwords buffer)
1539 (flyspell-delete-region-overlays beg end)
1540 (flyspell-check-region-doublons beg end))
1541 (flyspell-external-point-words))
1545 ;;* flyspell-region ... */
1551 ;;* regular flyspell means. */
1554 (defun flyspell-region (beg end)
1564 (if (and flyspell-large-region (> (- end beg) flyspell-large-region))
1565 (flyspell-large-region beg end)
1566 (flyspell-small-region beg end)))))
1569 ;;* flyspell-buffer ... */
1572 (defun flyspell-buffer ()
1575 (flyspell-region (point-min) (point-max)))
1580 (defvar flyspell-old-buffer-error nil)
1581 (defvar flyspell-old-pos-error nil)
1584 ;;* flyspell-goto-next-error ... */
1586 (defun flyspell-goto-next-error ()
1593 (if (and (eq (current-buffer) flyspell-old-buffer-error)
1594 (eq pos flyspell-old-pos-error))
1596 (if (= flyspell-old-pos-error max)
1608 (if (flyspell-overlay-p (car ovs))
1614 (setq flyspell-old-pos-error pos)
1615 (setq flyspell-old-buffer-error (current-buffer))
1621 ;;* flyspell-overlay-p ... */
1623 (defun flyspell-overlay-p (o)
1624 "A predicate that return true iff O is an overlay used by flyspell."
1625 (and (overlayp o) (overlay-get o 'flyspell-overlay)))
1628 ;;* flyspell-delete-region-overlays, flyspell-delete-all-overlays */
1630 ;;* Remove overlays introduced by flyspell. */
1632 (defun flyspell-delete-region-overlays (beg end)
1633 "Delete overlays used by flyspell in a given region."
1634 (remove-overlays beg end 'flyspell-overlay t))
1637 (defun flyspell-delete-all-overlays ()
1638 "Delete all the overlays used by flyspell."
1639 (remove-overlays (point-min) (point-max) 'flyspell-overlay t))
1642 ;;* flyspell-unhighlight-at ... */
1644 (defun flyspell-unhighlight-at (pos)
1645 "Remove the flyspell overlay that are located at POS."
1646 (if flyspell-persistent-highlight
1649 (if (flyspell-overlay-p (car overlays))
1652 (if (flyspell-overlay-p flyspell-overlay)
1653 (delete-overlay flyspell-overlay))))
1656 ;;* flyspell-properties-at-p ... */
1660 (defun flyspell-properties-at-p (pos)
1662 If variable `flyspell-highlight-properties' is set to nil,
1674 ;;* make-flyspell-overlay ... */
1676 (defun make-flyspell-overlay (beg end face mouse-face)
1684 (overlay-put overlay 'flyspell-overlay t)
1687 (overlay-put overlay 'keymap flyspell-mouse-map)
1688 (when (eq face 'flyspell-incorrect)
1689 (and (stringp flyspell-before-incorrect-word-string)
1691 flyspell-before-incorrect-word-string))
1692 (and (stringp flyspell-after-incorrect-word-string)
1694 flyspell-after-incorrect-word-string)))
1698 ;;* flyspell-highlight-incorrect-region ... */
1700 (defun flyspell-highlight-incorrect-region (beg end poss)
1708 'flyspell-incorrect-hook beg end poss)
1709 (if (or flyspell-highlight-properties
1710 (not (flyspell-properties-at-p beg)))
1717 (if (flyspell-overlay-p (car os))
1721 (flyspell-unhighlight-at beg)
1723 (setq flyspell-overlay
1724 (make-flyspell-overlay
1726 (if (eq poss 'doublon) 'flyspell-duplicate 'flyspell-incorrect)
1730 ;;* flyspell-highlight-duplicate-region ... */
1732 (defun flyspell-highlight-duplicate-region (beg end poss)
1738 'flyspell-incorrect-hook beg end poss)
1739 (if (or flyspell-highlight-properties
1740 (not (flyspell-properties-at-p beg)))
1743 (flyspell-unhighlight-at beg)
1745 (setq flyspell-overlay
1746 (make-flyspell-overlay beg end
1747 'flyspell-duplicate
1751 ;;* flyspell-auto-correct-cache ... */
1753 (defvar flyspell-auto-correct-pos nil)
1754 (defvar flyspell-auto-correct-region nil)
1755 (defvar flyspell-auto-correct-ring nil)
1756 (defvar flyspell-auto-correct-word nil)
1757 (make-variable-buffer-local 'flyspell-auto-correct-pos)
1758 (make-variable-buffer-local 'flyspell-auto-correct-region)
1759 (make-variable-buffer-local 'flyspell-auto-correct-ring)
1760 (make-variable-buffer-local 'flyspell-auto-correct-word)
1763 ;;* flyspell-check-previous-highlighted-word ... */
1765 (defun flyspell-check-previous-highlighted-word (&optional arg)
1785 (if (and (flyspell-overlay-p ov)
1794 ;;* flyspell-display-next-corrections ... */
1796 (defun flyspell-display-next-corrections (corrections)
1801 (if (equal (car l) flyspell-auto-correct-word)
1808 (+ num (length flyspell-auto-correct-word))
1809 'face 'flyspell-incorrect
1817 ;;* flyspell-abbrev-table ... */
1819 (defun flyspell-abbrev-table ()
1820 (if flyspell-use-global-abbrev-table-p
1825 ;;* flyspell-define-abbrev ... */
1827 (defun flyspell-define-abbrev (name expansion)
1828 (let ((table (flyspell-abbrev-table)))
1833 ;;* flyspell-auto-correct-word ... */
1835 (defun flyspell-auto-correct-word ()
1842 (flyspell-accept-buffer-local-defs)
1843 (if (and (eq flyspell-auto-correct-pos pos)
1844 (consp flyspell-auto-correct-region))
1846 (let* ((start (car flyspell-auto-correct-region))
1847 (len (cdr flyspell-auto-correct-region)))
1848 (flyspell-unhighlight-at start)
1850 (setq flyspell-auto-correct-ring (cdr flyspell-auto-correct-ring))
1851 (let* ((word (car flyspell-auto-correct-ring))
1853 (rplacd flyspell-auto-correct-region len)
1855 (if flyspell-abbrev-p
1856 (if (flyspell-already-abbrevp (flyspell-abbrev-table)
1857 flyspell-auto-correct-word)
1858 (flyspell-change-abbrev (flyspell-abbrev-table)
1859 flyspell-auto-correct-word
1861 (flyspell-define-abbrev flyspell-auto-correct-word word)))
1862 (funcall flyspell-insert-function word)
1863 (flyspell-word)
1864 (flyspell-display-next-corrections flyspell-auto-correct-ring))
1865 (flyspell-ajust-cursor-point pos (point) old-max)
1866 (setq flyspell-auto-correct-pos (point)))
1868 (let ((word (flyspell-get-word nil)))
1874 (setq flyspell-auto-correct-word word)
1876 (ispell-send-string "%\n") ;put in verbose mode
1899 (let ((replacements (if flyspell-sort-corrections
1902 (setq flyspell-auto-correct-region nil)
1910 (setq flyspell-auto-correct-region
1916 (setq flyspell-auto-correct-ring
1918 (flyspell-unhighlight-at start)
1920 (funcall flyspell-insert-function new-word)
1921 (if flyspell-abbrev-p
1922 (if (flyspell-already-abbrevp
1923 (flyspell-abbrev-table) word)
1924 (flyspell-change-abbrev
1925 (flyspell-abbrev-table)
1928 (flyspell-define-abbrev word
1930 (flyspell-word)
1931 (flyspell-display-next-corrections
1932 (cons new-word flyspell-auto-correct-ring))
1933 (flyspell-ajust-cursor-point pos
1936 (setq flyspell-auto-correct-pos (point))
1940 ;;* flyspell-auto-correct-previous-pos ... */
1942 (defvar flyspell-auto-correct-previous-pos nil
1946 ;;* flyspell-auto-correct-previous-hook ... */
1948 (defun flyspell-auto-correct-previous-hook ()
1949 "Hook to track successive calls to `flyspell-auto-correct-previous-word'.
1950 Sets `flyspell-auto-correct-previous-pos' to nil"
1952 (remove-hook 'pre-command-hook (function flyspell-auto-correct-previous-hook) t)
1953 (unless (eq this-command (function flyspell-auto-correct-previous-word))
1954 (setq flyspell-auto-correct-previous-pos nil)))
1957 ;;* flyspell-auto-correct-previous-word ... */
1959 (defun flyspell-auto-correct-previous-word (position)
1972 (function flyspell-auto-correct-previous-hook) t t)
1974 (unless flyspell-auto-correct-previous-pos
1976 (setq flyspell-auto-correct-previous-pos nil)
1981 ;; search for previous (new) flyspell overlay
1983 (or (not (flyspell-overlay-p new-overlay))
1987 'flyspell-incorrect))))
1993 (setq flyspell-auto-correct-previous-pos
1996 (when flyspell-auto-correct-previous-pos
1998 (goto-char flyspell-auto-correct-previous-pos)
2000 (if (numberp flyspell-auto-correct-previous-pos)
2001 (goto-char flyspell-auto-correct-previous-pos))
2002 (flyspell-auto-correct-word))
2004 (setq flyspell-auto-correct-previous-pos (point))))))))
2007 ;;* flyspell-correct-word ... */
2010 (defun flyspell-correct-word (event)
2016 (flyspell-correct-word-before-point event save)))
2018 (defun flyspell-correct-word-before-point (&optional event opoint)
2027 (flyspell-accept-buffer-local-defs)
2030 (word (flyspell-get-word nil)))
2037 (ispell-send-string "%\n") ;put in verbose mode
2059 (flyspell-xemacs-popup
2063 (flyspell-do-correct (flyspell-emacs-popup event poss word)
2068 ;;* flyspell-do-correct ... */
2070 (defun flyspell-do-correct (replace poss word cursor-location start end save)
2081 ;; flyspell. I assume its absence on the Emacs side was an
2084 (flyspell-unhighlight-at cursor-location)
2088 (flyspell-unhighlight-at cursor-location)
2098 (flyspell-unhighlight-at cursor-location)
2108 (funcall flyspell-insert-function new-word)
2109 (if flyspell-abbrev-p
2110 (flyspell-define-abbrev word new-word)))
2113 (flyspell-ajust-cursor-point save cursor-location old-max)))
2119 ;;* flyspell-ajust-cursor-point ... */
2121 (defun flyspell-ajust-cursor-point (save cursor-location old-max)
2133 ;;* flyspell-emacs-popup ... */
2135 (defun flyspell-emacs-popup (event poss word)
2149 (let* ((corrects (if flyspell-sort-corrections
2171 (menu (cons "flyspell correction menu" base-menu)))
2178 ;;* flyspell-xemacs-popup ... */
2180 (defun flyspell-xemacs-popup (poss word cursor-location start end save)
2182 (let* ((corrects (if flyspell-sort-corrections
2188 (list 'flyspell-do-correct
2204 (list 'flyspell-do-correct
2215 (list 'flyspell-do-correct
2225 (list 'flyspell-do-correct
2235 (list 'flyspell-do-correct
2254 (defun flyspell-maybe-correct-transposition (beg end poss)
2264 This function is meant to be added to `flyspell-incorrect-hook'."
2284 (defun flyspell-maybe-correct-doubling (beg end poss)
2294 This function is meant to be added to `flyspell-incorrect-hook'."
2311 ;;* flyspell-already-abbrevp ... */
2313 (defun flyspell-already-abbrevp (table word)
2318 ;;* flyspell-change-abbrev ... */
2320 (defun flyspell-change-abbrev (table old new)
2323 (provide 'flyspell)
2326 ;;; flyspell.el ends here