1 ;;; flyspell.el --- on-the-fly spell checker
3 ;; Copyright (C) 1998, 2000, 2001, 2002 Free Software Foundation, Inc.
5 ;; Author: Manuel Serrano <Manuel.Serrano@unice.fr>
6 ;; Keywords: convenience
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
27 ;; Flyspell is a minor Emacs mode performing on-the-fly spelling
30 ;; To enable Flyspell minor mode, type M-x flyspell-mode.
31 ;; This applies only to the current buffer.
33 ;; To enable Flyspell in text representing computer programs, type
34 ;; M-x flyspell-prog-mode.
35 ;; In that mode only text inside comments is checked.
37 ;; Note: consider setting the variable ispell-parser to `tex' to
38 ;; avoid TeX command checking; use `(setq ispell-parser 'tex)'.
40 ;; Some user variables control the behavior of flyspell. They are
41 ;; those defined under the `User variables' comment.
47 ;*---------------------------------------------------------------------*/
49 ;*---------------------------------------------------------------------*/
50 (defgroup flyspell nil
51 "Spell checking on the fly."
56 ;*---------------------------------------------------------------------*/
57 ;* User configuration ... */
58 ;*---------------------------------------------------------------------*/
59 (defcustom flyspell-highlight-flag t
60 "*How Flyspell should indicate misspelled words.
61 Non-nil means use highlight, nil means use minibuffer messages."
65 (defcustom flyspell-mark-duplications-flag t
66 "*Non-nil means Flyspell reports a repeated word as an error."
70 (defcustom flyspell-sort-corrections nil
71 "*Non-nil means, sort the corrections alphabetically before popping them."
76 (defcustom flyspell-duplicate-distance -1
77 "*The maximum distance for finding duplicates of unrecognized words.
78 This applies to the feature that when a word is not found in the dictionary,
79 if the same spelling occurs elsewhere in the buffer,
80 Flyspell uses a different face (`flyspell-duplicate-face') to highlight it.
81 This variable specifies how far to search to find such a duplicate.
82 -1 means no limit (search the whole buffer).
83 0 means do not search for duplicate unrecognized spellings."
88 (defcustom flyspell-delay 3
89 "*The number of seconds to wait before checking, after a \"delayed\" command."
93 (defcustom flyspell-persistent-highlight t
94 "*Non-nil means misspelled words remain highlighted until corrected.
95 If this variable is nil, only the most recently detected misspelled word
100 (defcustom flyspell-highlight-properties t
101 "*Non-nil means highlight incorrect words even if a property exists for this word."
105 (defcustom flyspell-default-delayed-commands
106 '(self-insert-command
108 backward-or-forward-delete-char
110 scrollbar-vertical-drag)
111 "The standard list of delayed commands for Flyspell.
112 See `flyspell-delayed-commands'."
115 :type '(repeat (symbol)))
117 (defcustom flyspell-delayed-commands nil
118 "List of commands that are \"delayed\" for Flyspell mode.
119 After these commands, Flyspell checking is delayed for a short time,
120 whose length is specified by `flyspell-delay'."
122 :type '(repeat (symbol)))
124 (defcustom flyspell-default-deplacement-commands
129 "The standard list of deplacement commands for Flyspell.
130 See `flyspell-deplacement-commands'."
133 :type '(repeat (symbol)))
135 (defcustom flyspell-deplacement-commands nil
136 "List of commands that are \"deplacement\" for Flyspell mode.
137 After these commands, Flyspell checking is performed only if the previous
138 command was not the very same command."
141 :type '(repeat (symbol)))
143 (defcustom flyspell-issue-welcome-flag t
144 "*Non-nil means that Flyspell should display a welcome message when started."
148 (defcustom flyspell-issue-message-flag t
149 "*Non-nil means that Flyspell emits messages when checking words."
153 (defcustom flyspell-incorrect-hook nil
154 "*List of functions to be called when incorrect words are encountered.
155 Each function is given three arguments: the beginning and the end
156 of the incorrect region. The third is either the symbol 'doublon' or the list
157 of possible corrections as returned by 'ispell-parse-output'.
159 If any of the functions return non-Nil, the word is not highlighted as
165 (defcustom flyspell-default-dictionary nil
166 "A string that is the name of the default dictionary.
167 This is passed to the `ispell-change-dictionary' when flyspell is started.
168 If the variable `ispell-local-dictionary' or `ispell-dictionary' is non-nil
169 when flyspell is started, the value of that variable is used instead
170 of `flyspell-default-dictionary' to select the default dictionary.
171 Otherwise, if `flyspell-default-dictionary' is nil, it means to use
172 Ispell's ultimate default dictionary."
175 :type '(choice string (const :tag "Default" nil)))
177 (defcustom flyspell-tex-command-regexp
178 "\\(\\(begin\\|end\\)[ \t]*{\\|\\(cite[a-z*]*\\|label\\|ref\\|eqref\\|usepackage\\|documentclass\\)[ \t]*\\(\\[[^]]*\\]\\)?{[^{}]*\\)"
179 "A string that is the regular expression that matches TeX commands."
184 (defcustom flyspell-check-tex-math-command nil
185 "*Non nil means check even inside TeX math environment.
186 TeX math environments are discovered by the TEXMATHP that implemented
187 inside the texmathp.el Emacs package. That package may be found at:
188 http://strw.leidenuniv.nl/~dominik/Tools"
192 (defcustom flyspell-dictionaries-that-consider-dash-as-word-delimiter
193 '("francais" "deutsch8" "norsk")
194 "List of dictionary names that consider `-' as word delimiter."
197 :type '(repeat (string)))
199 (defcustom flyspell-abbrev-p
201 "*If true, add correction to abbreviation table."
206 (defcustom flyspell-use-global-abbrev-table-p
208 "*If true, prefer global abbrev table to local abbrev table."
214 (defcustom flyspell-mode-line-string " Fly"
215 "*String displayed on the modeline when flyspell is active.
216 Set this to nil if you don't want a modeline indicator."
218 :type '(choice string (const :tag "None" nil)))
220 (defcustom flyspell-large-region 1000
221 "*The threshold that determines if a region is small.
222 The `flyspell-region' function is invoked if the region is small, the
223 word are checked one after the other using regular flyspell check
224 means. If the region is large, a new Ispell process is spawned to get
230 (defcustom flyspell-insert-function (function insert)
231 "*Function for inserting word by flyspell upon correction."
235 (defcustom flyspell-before-incorrect-word-string nil
236 "String used to indicate an incorrect word starting."
238 :type '(choice string (const nil)))
240 (defcustom flyspell-after-incorrect-word-string nil
241 "String used to indicate an incorrect word ending."
243 :type '(choice string (const nil)))
245 ;*---------------------------------------------------------------------*/
246 ;* Mode specific options */
247 ;* ------------------------------------------------------------- */
248 ;* Mode specific options enable users to disable flyspell on */
249 ;* certain word depending of the emacs mode. For instance, when */
250 ;* using flyspell with mail-mode add the following expression */
251 ;* in your .emacs file: */
252 ;* (add-hook 'mail-mode */
253 ;* '(lambda () (setq flyspell-generic-check-word-p */
254 ;* 'mail-mode-flyspell-verify))) */
255 ;*---------------------------------------------------------------------*/
256 (defvar flyspell-generic-check-word-p nil
257 "Function providing per-mode customization over which words are flyspelled.
258 Returns t to continue checking, nil otherwise.
259 Flyspell mode sets this variable to whatever is the `flyspell-mode-predicate'
260 property of the major mode name.")
261 (make-variable-buffer-local 'flyspell-generic-check-word-p)
263 ;*--- mail mode -------------------------------------------------------*/
264 (put 'mail-mode 'flyspell-mode-predicate 'mail-mode-flyspell-verify)
265 (put 'message-mode 'flyspell-mode-predicate 'mail-mode-flyspell-verify)
266 (defun mail-mode-flyspell-verify ()
267 "This function is used for `flyspell-generic-check-word-p' in Mail mode."
268 (let ((in-headers (save-excursion
269 (re-search-forward mail-header-separator nil t)))
270 (in-signature (save-excursion
271 (re-search-backward message-signature-separator nil t))))
273 (and (save-excursion (beginning-of-line)
274 (looking-at "^Subject:"))
275 (> (point) (match-end 0))))
281 (not (looking-at "[>}|]\\To:")))))))
283 ;*--- texinfo mode ----------------------------------------------------*/
284 (put 'texinfo-mode 'flyspell-mode-predicate 'texinfo-mode-flyspell-verify)
285 (defun texinfo-mode-flyspell-verify ()
286 "This function is used for `flyspell-generic-check-word-p' in Texinfo mode."
289 (not (looking-at "@"))))
291 ;*--- tex mode --------------------------------------------------------*/
292 (put 'tex-mode 'flyspell-mode-predicate 'tex-mode-flyspell-verify)
293 (defun tex-mode-flyspell-verify ()
294 "This function is used for `flyspell-generic-check-word-p' in LaTeX mode."
297 (re-search-backward "^[ \t]*%%%[ \t]+Local" (point-min) t)))
299 (let ((this (point-marker))
300 (e (progn (end-of-line) (point-marker))))
302 (if (re-search-forward "\\\\\\(cite\\|label\\|ref\\){[^}]*}" e t)
303 (and (>= this (match-beginning 0))
304 (<= this (match-end 0)) )))))))
306 ;*--- sgml mode -------------------------------------------------------*/
307 (put 'sgml-mode 'flyspell-mode-predicate 'sgml-mode-flyspell-verify)
308 (put 'html-mode 'flyspell-mode-predicate 'sgml-mode-flyspell-verify)
310 (defun sgml-mode-flyspell-verify ()
311 "This function is used for `flyspell-generic-check-word-p' in SGML mode."
313 (let ((this (point-marker))
314 (s (progn (beginning-of-line) (point-marker)))
315 (e (progn (end-of-line) (point-marker))))
318 (and (re-search-forward "[^<]*>" e t)
319 (= (match-beginning 0) this)))
322 (and (re-search-backward "<[^>]*" s t)
323 (= (match-end 0) this)))
326 (and (re-search-forward "[^&]*;" e t)
327 (= (match-beginning 0) this)))
330 (and (re-search-backward "&[^;]*" s t)
331 (= (match-end 0) this)))))))))
333 ;*---------------------------------------------------------------------*/
334 ;* Programming mode */
335 ;*---------------------------------------------------------------------*/
336 (defvar flyspell-prog-text-faces
337 '(font-lock-string-face font-lock-comment-face font-lock-doc-face)
338 "Faces corresponding to text in programming-mode buffers.")
340 (defun flyspell-generic-progmode-verify ()
341 "Used for `flyspell-generic-check-word-p' in programming modes."
342 (let ((f (get-text-property (point) 'face)))
343 (memq f flyspell-prog-text-faces)))
346 (defun flyspell-prog-mode ()
347 "Turn on `flyspell-mode' for comments and strings."
349 (setq flyspell-generic-check-word-p 'flyspell-generic-progmode-verify)
352 ;*---------------------------------------------------------------------*/
353 ;* Overlay compatibility */
354 ;*---------------------------------------------------------------------*/
355 (autoload 'make-overlay "overlay" "Overlay compatibility kit." t)
356 (autoload 'overlayp "overlay" "Overlay compatibility kit." t)
357 (autoload 'overlays-in "overlay" "Overlay compatibility kit." t)
358 (autoload 'delete-overlay "overlay" "Overlay compatibility kit." t)
359 (autoload 'overlays-at "overlay" "Overlay compatibility kit." t)
360 (autoload 'overlay-put "overlay" "Overlay compatibility kit." t)
361 (autoload 'overlay-get "overlay" "Overlay compatibility kit." t)
362 (autoload 'previous-overlay-change "overlay" "Overlay compatibility kit." t)
364 ;*---------------------------------------------------------------------*/
365 ;* Which emacs are we currently running */
366 ;*---------------------------------------------------------------------*/
367 (defvar flyspell-emacs
369 ((string-match "XEmacs" emacs-version)
373 "The type of Emacs we are currently running.")
375 (defvar flyspell-use-local-map
376 (or (eq flyspell-emacs 'xemacs)
377 (not (string< emacs-version "20"))))
379 ;*---------------------------------------------------------------------*/
380 ;* The minor mode declaration. */
381 ;*---------------------------------------------------------------------*/
382 (eval-when-compile (defvar flyspell-local-mouse-map))
384 (defvar flyspell-mode nil)
385 (make-variable-buffer-local 'flyspell-mode)
387 (defvar flyspell-mouse-map
388 (let ((map (make-sparse-keymap)))
390 ((eq flyspell-emacs 'xemacs)
391 (define-key map [(button2)] #'flyspell-correct-word)
392 (define-key map "\M-\t" #'flyspell-auto-correct-word))
393 (flyspell-use-local-map
394 (define-key map [(mouse-2)] #'flyspell-correct-word)
395 (define-key map "\M-\t" #'flyspell-auto-correct-word)))
399 (defvar flyspell-mode-map (make-sparse-keymap))
401 ;; mouse, keyboard bindings and misc definition
402 (when (or (assoc 'flyspell-mode minor-mode-map-alist)
403 (setq minor-mode-map-alist
404 (cons (cons 'flyspell-mode flyspell-mode-map)
405 minor-mode-map-alist)))
406 (define-key flyspell-mode-map "\M-\t" 'flyspell-auto-correct-word))
408 ;; the name of the overlay property that defines the keymap
409 (defvar flyspell-overlay-keymap-property-name 'keymap)
411 ;; dash character machinery
412 (defvar flyspell-consider-dash-as-word-delimiter-flag nil
413 "*Non-nil means that the `-' char is considered as a word delimiter.")
414 (make-variable-buffer-local 'flyspell-consider-dash-as-word-delimiter-flag)
415 (defvar flyspell-dash-dictionary nil)
416 (make-variable-buffer-local 'flyspell-dash-dictionary)
417 (defvar flyspell-dash-local-dictionary nil)
418 (make-variable-buffer-local 'flyspell-dash-local-dictionary)
420 ;*---------------------------------------------------------------------*/
422 ;*---------------------------------------------------------------------*/
423 (defface flyspell-incorrect-face
424 (if (eq flyspell-emacs 'xemacs)
425 '((((class color)) (:foreground "OrangeRed" :bold t :underline t))
427 '((((class color)) (:foreground "OrangeRed" :weight bold :underline t))
429 "Face used for marking a misspelled word in Flyspell."
432 (defface flyspell-duplicate-face
433 (if (eq flyspell-emacs 'xemacs)
434 '((((class color)) (:foreground "Gold3" :bold t :underline t))
436 '((((class color)) (:foreground "Gold3" :weight bold :underline t))
438 "Face used for marking a misspelled word that appears twice in the buffer.
439 See also `flyspell-duplicate-distance'."
442 (defvar flyspell-overlay nil)
444 ;*---------------------------------------------------------------------*/
445 ;* flyspell-mode ... */
446 ;*---------------------------------------------------------------------*/
448 (defun flyspell-mode (&optional arg)
449 "Minor mode performing on-the-fly spelling checking.
450 Ispell is automatically spawned on background for each entered words.
451 The default flyspell behavior is to highlight incorrect words.
452 With no argument, this command toggles Flyspell mode.
453 With a prefix argument ARG, turn Flyspell minor mode on iff ARG is positive.
456 \\[ispell-word]: correct words (using Ispell).
457 \\[flyspell-auto-correct-word]: automatically correct word.
458 \\[flyspell-correct-word] (or mouse-2): popup correct words.
461 This runs `flyspell-mode-hook' after flyspell is entered.
464 `flyspell-mode' uses `ispell-mode'. Thus all Ispell options are
465 valid. For instance, a personal dictionary can be used by
466 invoking `ispell-change-dictionary'.
468 Consider using the `ispell-parser' to check your text. For instance
470 \(add-hook 'tex-mode-hook (function (lambda () (setq ispell-parser 'tex))))
473 \\[flyspell-region] checks all words inside a region.
474 \\[flyspell-buffer] checks the whole buffer."
476 (let ((old-flyspell-mode flyspell-mode))
477 ;; Mark the mode as on or off.
478 (setq flyspell-mode (not (or (and (null arg) flyspell-mode)
479 (<= (prefix-numeric-value arg) 0))))
481 (unless (eq flyspell-mode old-flyspell-mode)
485 ;; Force modeline redisplay.
486 (set-buffer-modified-p (buffer-modified-p)))))
488 ;*---------------------------------------------------------------------*/
490 ;*---------------------------------------------------------------------*/
492 (add-minor-mode 'flyspell-mode
493 'flyspell-mode-line-string
498 ;*---------------------------------------------------------------------*/
499 ;* flyspell-buffers ... */
500 ;* ------------------------------------------------------------- */
501 ;* For remembering buffers running flyspell */
502 ;*---------------------------------------------------------------------*/
503 (defvar flyspell-buffers nil)
505 ;*---------------------------------------------------------------------*/
506 ;* flyspell-minibuffer-p ... */
507 ;*---------------------------------------------------------------------*/
508 (defun flyspell-minibuffer-p (buffer)
509 "Is BUFFER a minibuffer?"
510 (let ((ws (get-buffer-window-list buffer t)))
511 (and (consp ws) (window-minibuffer-p (car ws)))))
513 ;*---------------------------------------------------------------------*/
514 ;* flyspell-version ... */
515 ;*---------------------------------------------------------------------*/
517 (defun flyspell-version ()
518 "The flyspell version"
522 ;*---------------------------------------------------------------------*/
523 ;* flyspell-accept-buffer-local-defs ... */
524 ;*---------------------------------------------------------------------*/
525 (defun flyspell-accept-buffer-local-defs ()
526 (ispell-accept-buffer-local-defs)
527 (if (not (and (eq flyspell-dash-dictionary ispell-dictionary)
528 (eq flyspell-dash-local-dictionary ispell-local-dictionary)))
529 ;; the dictionary has changed
531 (setq flyspell-dash-dictionary ispell-dictionary)
532 (setq flyspell-dash-local-dictionary ispell-local-dictionary)
533 (if (member (or ispell-local-dictionary ispell-dictionary)
534 flyspell-dictionaries-that-consider-dash-as-word-delimiter)
535 (setq flyspell-consider-dash-as-word-delimiter-flag t)
536 (setq flyspell-consider-dash-as-word-delimiter-flag nil)))))
538 ;*---------------------------------------------------------------------*/
539 ;* flyspell-mode-on ... */
540 ;*---------------------------------------------------------------------*/
541 (defun flyspell-mode-on ()
542 "Turn Flyspell mode on. Do not use this; use `flyspell-mode' instead."
543 (setq ispell-highlight-face 'flyspell-incorrect-face)
544 ;; local dictionaries setup
545 (ispell-change-dictionary
546 (or ispell-local-dictionary ispell-dictionary flyspell-default-dictionary))
547 ;; we have to force ispell to accept the local definition or
548 ;; otherwise it could be too late, the local dictionary may
550 (flyspell-accept-buffer-local-defs)
551 ;; we put the `flyspel-delayed' property on some commands
552 (flyspell-delay-commands)
553 ;; we put the `flyspel-deplacement' property on some commands
554 (flyspell-deplacement-commands)
555 ;; we bound flyspell action to post-command hook
556 (add-hook 'post-command-hook (function flyspell-post-command-hook) t t)
557 ;; we bound flyspell action to pre-command hook
558 (add-hook 'pre-command-hook (function flyspell-pre-command-hook) t t)
559 ;; we bound flyspell action to after-change hook
560 (make-local-variable 'after-change-functions)
561 (setq after-change-functions
562 (cons 'flyspell-after-change-function after-change-functions))
563 ;; set flyspell-generic-check-word-p based on the major mode
564 (let ((mode-predicate (get major-mode 'flyspell-mode-predicate)))
566 (setq flyspell-generic-check-word-p mode-predicate)))
567 ;; the welcome message
568 (if (and flyspell-issue-message-flag
569 flyspell-issue-welcome-flag
571 (let ((binding (where-is-internal 'flyspell-auto-correct-word
575 (format "Welcome to flyspell. Use %s or Mouse-2 to correct words."
576 (key-description binding))
577 "Welcome to flyspell. Use Mouse-2 to correct words."))))
578 ;; we end with the flyspell hooks
579 (run-hooks 'flyspell-mode-hook))
581 ;*---------------------------------------------------------------------*/
582 ;* flyspell-delay-commands ... */
583 ;*---------------------------------------------------------------------*/
584 (defun flyspell-delay-commands ()
585 "Install the standard set of Flyspell delayed commands."
586 (mapcar 'flyspell-delay-command flyspell-default-delayed-commands)
587 (mapcar 'flyspell-delay-command flyspell-delayed-commands))
589 ;*---------------------------------------------------------------------*/
590 ;* flyspell-delay-command ... */
591 ;*---------------------------------------------------------------------*/
592 (defun flyspell-delay-command (command)
593 "Set COMMAND to be delayed, for Flyspell.
594 When flyspell `post-command-hook' is invoked because a delayed command
595 as been used the current word is not immediately checked.
596 It will be checked only after `flyspell-delay' seconds."
597 (interactive "SDelay Flyspell after Command: ")
598 (put command 'flyspell-delayed t))
600 ;*---------------------------------------------------------------------*/
601 ;* flyspell-deplacement-commands ... */
602 ;*---------------------------------------------------------------------*/
603 (defun flyspell-deplacement-commands ()
604 "Install the standard set of Flyspell deplacement commands."
605 (mapcar 'flyspell-deplacement-command flyspell-default-deplacement-commands)
606 (mapcar 'flyspell-deplacement-command flyspell-deplacement-commands))
608 ;*---------------------------------------------------------------------*/
609 ;* flyspell-deplacement-command ... */
610 ;*---------------------------------------------------------------------*/
611 (defun flyspell-deplacement-command (command)
612 "Set COMMAND that implement cursor movements, for Flyspell.
613 When flyspell `post-command-hook' is invoked because of a deplacement command
614 as been used the current word is checked only if the previous command was
615 not the very same deplacement command."
616 (interactive "SDeplacement Flyspell after Command: ")
617 (put command 'flyspell-deplacement t))
619 ;*---------------------------------------------------------------------*/
620 ;* flyspell-word-cache ... */
621 ;*---------------------------------------------------------------------*/
622 (defvar flyspell-word-cache-start nil)
623 (defvar flyspell-word-cache-end nil)
624 (defvar flyspell-word-cache-word nil)
625 (make-variable-buffer-local 'flyspell-word-cache-start)
626 (make-variable-buffer-local 'flyspell-word-cache-end)
627 (make-variable-buffer-local 'flyspell-word-cache-word)
629 ;*---------------------------------------------------------------------*/
630 ;* The flyspell pre-hook, store the current position. In the */
631 ;* post command hook, we will check, if the word at this position */
632 ;* has to be spell checked. */
633 ;*---------------------------------------------------------------------*/
634 (defvar flyspell-pre-buffer nil)
635 (defvar flyspell-pre-point nil)
636 (defvar flyspell-pre-column nil)
637 (defvar flyspell-pre-pre-buffer nil)
638 (defvar flyspell-pre-pre-point nil)
640 ;*---------------------------------------------------------------------*/
641 ;* flyspell-previous-command ... */
642 ;*---------------------------------------------------------------------*/
643 (defvar flyspell-previous-command nil
644 "The last interactive command checked by Flyspell.")
646 ;*---------------------------------------------------------------------*/
647 ;* flyspell-pre-command-hook ... */
648 ;*---------------------------------------------------------------------*/
649 (defun flyspell-pre-command-hook ()
650 "Save the current buffer and point for Flyspell's post-command hook."
652 (setq flyspell-pre-buffer (current-buffer))
653 (setq flyspell-pre-point (point))
654 (setq flyspell-pre-column (current-column)))
656 ;*---------------------------------------------------------------------*/
657 ;* flyspell-mode-off ... */
658 ;*---------------------------------------------------------------------*/
660 (defun flyspell-mode-off ()
661 "Turn Flyspell mode off."
662 ;; we remove the hooks
663 (remove-hook 'post-command-hook (function flyspell-post-command-hook) t)
664 (remove-hook 'pre-command-hook (function flyspell-pre-command-hook) t)
665 (setq after-change-functions (delq 'flyspell-after-change-function
666 after-change-functions))
667 ;; we remove all the flyspell hilightings
668 (flyspell-delete-all-overlays)
669 ;; we have to erase pre cache variables
670 (setq flyspell-pre-buffer nil)
671 (setq flyspell-pre-point nil)
672 ;; we mark the mode as killed
673 (setq flyspell-mode nil))
675 ;*---------------------------------------------------------------------*/
676 ;* flyspell-check-pre-word-p ... */
677 ;*---------------------------------------------------------------------*/
678 (defun flyspell-check-pre-word-p ()
679 "Return non-nil if we should to check the word before point.
680 More precisely, it applies to the word that was before point
681 before the current command."
683 ((or (not (numberp flyspell-pre-point))
684 (not (bufferp flyspell-pre-buffer))
685 (not (buffer-live-p flyspell-pre-buffer)))
687 ((and (eq flyspell-pre-pre-point flyspell-pre-point)
688 (eq flyspell-pre-pre-buffer flyspell-pre-buffer))
690 ((or (and (= flyspell-pre-point (- (point) 1))
691 (eq (char-syntax (char-after flyspell-pre-point)) ?w))
692 (= flyspell-pre-point (point))
693 (= flyspell-pre-point (+ (point) 1)))
695 ((and (symbolp this-command)
696 (not executing-kbd-macro)
697 (or (get this-command 'flyspell-delayed)
698 (and (get this-command 'flyspell-deplacement)
699 (eq flyspell-previous-command this-command)))
700 (or (= (current-column) 0)
701 (= (current-column) flyspell-pre-column)
702 (eq (char-syntax (char-after flyspell-pre-point)) ?w)))
704 ((not (eq (current-buffer) flyspell-pre-buffer))
706 ((not (and (numberp flyspell-word-cache-start)
707 (numberp flyspell-word-cache-end)))
710 (or (< flyspell-pre-point flyspell-word-cache-start)
711 (> flyspell-pre-point flyspell-word-cache-end)))))
713 ;*---------------------------------------------------------------------*/
714 ;* The flyspell after-change-hook, store the change position. In */
715 ;* the post command hook, we will check, if the word at this */
716 ;* position has to be spell checked. */
717 ;*---------------------------------------------------------------------*/
718 (defvar flyspell-changes nil)
720 ;*---------------------------------------------------------------------*/
721 ;* flyspell-after-change-function ... */
722 ;*---------------------------------------------------------------------*/
723 (defun flyspell-after-change-function (start stop len)
724 "Save the current buffer and point for Flyspell's post-command hook."
726 (setq flyspell-changes (cons (cons start stop) flyspell-changes)))
728 ;*---------------------------------------------------------------------*/
729 ;* flyspell-check-changed-word-p ... */
730 ;*---------------------------------------------------------------------*/
731 (defun flyspell-check-changed-word-p (start stop)
732 "Return t when the changed word has to be checked.
733 The answer depends of several criteria.
734 Mostly we check word delimiters."
736 ((and (eq (char-after start) ?\n) (> stop start))
738 ((not (numberp flyspell-pre-point))
740 ((and (>= flyspell-pre-point start) (<= flyspell-pre-point stop))
742 ((let ((pos (point)))
743 (or (>= pos start) (<= pos stop) (= pos (1+ stop))))
748 ;*---------------------------------------------------------------------*/
749 ;* flyspell-check-word-p ... */
750 ;*---------------------------------------------------------------------*/
751 (defun flyspell-check-word-p ()
752 "Return t when the word at `point' has to be checked.
753 The answer depends of several criteria.
754 Mostly we check word delimiters."
756 ((<= (- (point-max) 1) (point-min))
757 ;; the buffer is not filled enough
759 ((and (and (> (current-column) 0)
760 (not (eq (current-column) flyspell-pre-column)))
763 (and (looking-at (flyspell-get-not-casechars))
764 (or flyspell-consider-dash-as-word-delimiter-flag
765 (not (looking-at "\\-"))))))
766 ;; yes because we have reached or typed a word delimiter.
768 ((symbolp this-command)
770 ((get this-command 'flyspell-deplacement)
771 (not (eq flyspell-previous-command this-command)))
772 ((get this-command 'flyspell-delayed)
773 ;; the current command is not delayed, that
774 ;; is that we must check the word now
775 (if (fboundp 'about-xemacs)
776 (sit-for flyspell-delay nil)
777 (sit-for flyspell-delay 0 nil)))
781 ;*---------------------------------------------------------------------*/
782 ;* flyspell-debug-signal-no-check ... */
783 ;*---------------------------------------------------------------------*/
784 (defun flyspell-debug-signal-no-check (msg obj)
785 (setq debug-on-error t)
787 (let ((buffer (get-buffer-create "*flyspell-debug*")))
790 (insert "NO-CHECK:\n")
791 (insert (format " %S : %S\n" msg obj)))))
793 ;*---------------------------------------------------------------------*/
794 ;* flyspell-debug-signal-pre-word-checked ... */
795 ;*---------------------------------------------------------------------*/
796 (defun flyspell-debug-signal-pre-word-checked ()
797 (setq debug-on-error t)
799 (let ((buffer (get-buffer-create "*flyspell-debug*")))
801 (insert "PRE-WORD:\n")
802 (insert (format " pre-point : %S\n" flyspell-pre-point))
803 (insert (format " pre-buffer : %S\n" flyspell-pre-buffer))
804 (insert (format " cache-start: %S\n" flyspell-word-cache-start))
805 (insert (format " cache-end : %S\n" flyspell-word-cache-end))
806 (goto-char (point-max)))))
808 ;*---------------------------------------------------------------------*/
809 ;* flyspell-debug-signal-word-checked ... */
810 ;*---------------------------------------------------------------------*/
811 (defun flyspell-debug-signal-word-checked ()
812 (setq debug-on-error t)
814 (let ((oldbuf (current-buffer))
815 (buffer (get-buffer-create "*flyspell-debug*"))
819 (insert (format " this-cmd : %S\n" this-command))
820 (insert (format " delayed : %S\n" (and (symbolp this-command)
821 (get this-command 'flyspell-delayed))))
822 (insert (format " point : %S\n" point))
823 (insert (format " prev-char : [%c] %S\n"
826 (let ((c (if (> (point) (point-min))
829 (char-after (point)))
835 (let ((c (if (> (point) (point-min))
838 (and (and (looking-at (flyspell-get-not-casechars)) 1)
839 (and (or flyspell-consider-dash-as-word-delimiter-flag
840 (not (looking-at "\\-"))) 2))))))
843 (insert (format " because : %S\n"
845 ((not (and (symbolp this-command)
846 (get this-command 'flyspell-delayed)))
847 ;; the current command is not delayed, that
848 ;; is that we must check the word now
852 (let ((c (if (> (point) (point-min))
855 (and (looking-at (flyspell-get-not-casechars))
856 (or flyspell-consider-dash-as-word-delimiter-flag
857 (not (looking-at "\\-"))))))))
860 ;; yes because we have reached or typed a word delimiter.
862 ((not (integerp flyspell-delay))
863 ;; yes because the user had set up a no-delay configuration.
867 (goto-char (point-max)))))
869 ;*---------------------------------------------------------------------*/
870 ;* flyspell-debug-signal-changed-checked ... */
871 ;*---------------------------------------------------------------------*/
872 (defun flyspell-debug-signal-changed-checked ()
873 (setq debug-on-error t)
875 (let ((buffer (get-buffer-create "*flyspell-debug*"))
878 (insert "CHANGED WORD:\n")
879 (insert (format " point : %S\n" point))
880 (goto-char (point-max)))))
882 ;*---------------------------------------------------------------------*/
883 ;* flyspell-post-command-hook ... */
884 ;* ------------------------------------------------------------- */
885 ;* It is possible that we check several words: */
886 ;* 1- the current word is checked if the predicate */
887 ;* FLYSPELL-CHECK-WORD-P is true */
888 ;* 2- the word that used to be the current word before the */
889 ;* THIS-COMMAND is checked if: */
890 ;* a- the previous word is different from the current word */
891 ;* b- the previous word as not just been checked by the */
892 ;* previous FLYSPELL-POST-COMMAND-HOOK */
893 ;* 3- the words changed by the THIS-COMMAND that are neither the */
894 ;* previous word nor the current word */
895 ;*---------------------------------------------------------------------*/
896 (defun flyspell-post-command-hook ()
897 "The `post-command-hook' used by flyspell to check a word in-the-fly."
899 (let ((command this-command))
900 (if (flyspell-check-pre-word-p)
902 '(flyspell-debug-signal-pre-word-checked)
903 (set-buffer flyspell-pre-buffer)
905 (goto-char flyspell-pre-point)
907 (if (flyspell-check-word-p)
909 '(flyspell-debug-signal-word-checked)
911 ;; we remember which word we have just checked.
912 ;; this will be used next time we will check a word
913 ;; to compare the next current word with the word
914 ;; that as been registered in the pre-command-hook
915 ;; that is these variables are used within the predicate
916 ;; FLYSPELL-CHECK-PRE-WORD-P
917 (setq flyspell-pre-pre-buffer (current-buffer))
918 (setq flyspell-pre-pre-point (point)))
920 (setq flyspell-pre-pre-buffer nil)
921 (setq flyspell-pre-pre-point nil)
922 ;; when a word is not checked because of a delayed command
923 ;; we do not disable the ispell cache.
924 (if (and (symbolp this-command) (get this-command 'flyspell-delayed))
925 (setq flyspell-word-cache-end -1))))
926 (while (consp flyspell-changes)
927 (let ((start (car (car flyspell-changes)))
928 (stop (cdr (car flyspell-changes))))
929 (if (flyspell-check-changed-word-p start stop)
931 '(flyspell-debug-signal-changed-checked)
934 (setq flyspell-changes (cdr flyspell-changes))))
935 (setq flyspell-previous-command command)))
937 ;*---------------------------------------------------------------------*/
938 ;* flyspell-notify-misspell ... */
939 ;*---------------------------------------------------------------------*/
940 (defun flyspell-notify-misspell (start end word poss)
941 (let ((replacements (if (stringp poss)
943 (if flyspell-sort-corrections
944 (sort (car (cdr (cdr poss))) 'string<)
945 (car (cdr (cdr poss)))))))
946 (if flyspell-issue-message-flag
947 (message (format "mispelling `%s' %S" word replacements)))))
949 ;*---------------------------------------------------------------------*/
950 ;* flyspell-word ... */
951 ;*---------------------------------------------------------------------*/
952 (defun flyspell-word (&optional following)
953 "Spell check a word."
954 (interactive (list current-prefix-arg))
956 (setq following ispell-following-word))
958 ;; use the correct dictionary
959 (flyspell-accept-buffer-local-defs)
960 (let* ((cursor-location (point))
961 (flyspell-word (flyspell-get-word following))
963 (if (or (eq flyspell-word nil)
964 (and (fboundp flyspell-generic-check-word-p)
965 (not (funcall flyspell-generic-check-word-p))))
968 ;; destructure return flyspell-word info list.
969 (setq start (car (cdr flyspell-word))
970 end (car (cdr (cdr flyspell-word)))
971 word (car flyspell-word))
972 ;; before checking in the directory, we check for doublons.
974 ((and (or (not (eq ispell-parser 'tex))
975 (not (eq (char-after start) ?\\)))
976 flyspell-mark-duplications-flag
979 (word-search-backward word
983 ;; yes, this is a doublon
984 (flyspell-highlight-incorrect-region start end 'doublon))
985 ((and (eq flyspell-word-cache-start start)
986 (eq flyspell-word-cache-end end)
987 (string-equal flyspell-word-cache-word word))
988 ;; this word had been already checked, we skip
990 ((and (eq ispell-parser 'tex)
991 (flyspell-tex-command-p flyspell-word))
992 ;; this is a correct word (because a tex command)
993 (flyspell-unhighlight-at start)
995 (flyspell-unhighlight-at (- end 1)))
998 ;; we setup the cache
999 (setq flyspell-word-cache-start start)
1000 (setq flyspell-word-cache-end end)
1001 (setq flyspell-word-cache-word word)
1002 ;; now check spelling of word.
1003 (process-send-string ispell-process "%\n")
1004 ;; put in verbose mode
1005 (process-send-string ispell-process
1006 (concat "^" word "\n"))
1007 ;; we mark the ispell process so it can be killed
1008 ;; when emacs is exited without query
1009 (if (fboundp 'process-kill-without-query)
1010 (process-kill-without-query ispell-process))
1011 ;; wait until ispell has processed word
1013 (accept-process-output ispell-process)
1014 (not (string= "" (car ispell-filter)))))
1015 ;; (process-send-string ispell-process "!\n")
1016 ;; back to terse mode.
1017 (setq ispell-filter (cdr ispell-filter))
1018 (if (consp ispell-filter)
1019 (setq poss (ispell-parse-output (car ispell-filter))))
1022 (flyspell-unhighlight-at start)
1024 (flyspell-unhighlight-at (- end 1)))
1026 ((and (stringp poss) flyspell-highlight-flag)
1028 (flyspell-unhighlight-at start)
1030 (flyspell-unhighlight-at (- end 1)))
1033 (flyspell-unhighlight-at start)
1035 (flyspell-unhighlight-at (- end 1))))
1036 ((or (and (< flyspell-duplicate-distance 0)
1039 (word-search-backward word
1044 (word-search-forward word
1047 (and (> flyspell-duplicate-distance 0)
1050 (word-search-backward
1053 flyspell-duplicate-distance)
1057 (word-search-forward
1060 flyspell-duplicate-distance)
1062 (if flyspell-highlight-flag
1063 (flyspell-highlight-duplicate-region start end)
1064 (message (format "duplicate `%s'" word))))
1066 ;; incorrect highlight the location
1067 (if flyspell-highlight-flag
1068 (flyspell-highlight-incorrect-region start end poss)
1069 (flyspell-notify-misspell start end word poss))))
1070 ;; return to original location
1071 (goto-char cursor-location)
1072 (if ispell-quit (setq ispell-quit nil)))))))))
1074 ;*---------------------------------------------------------------------*/
1075 ;* flyspell-tex-math-initialized ... */
1076 ;*---------------------------------------------------------------------*/
1077 (defvar flyspell-tex-math-initialized nil)
1079 ;*---------------------------------------------------------------------*/
1080 ;* flyspell-math-tex-command-p ... */
1081 ;* ------------------------------------------------------------- */
1082 ;* This function uses the texmathp package to check if (point) */
1083 ;* is within a tex command. In order to avoid using */
1084 ;* condition-case each time we use the variable */
1085 ;* flyspell-tex-math-initialized to make a special case the first */
1086 ;* time that function is called. */
1087 ;*---------------------------------------------------------------------*/
1088 (defun flyspell-math-tex-command-p ()
1090 (flyspell-check-tex-math-command
1092 ((eq flyspell-tex-math-initialized t)
1094 ((eq flyspell-tex-math-initialized 'error)
1097 (setq flyspell-tex-math-initialized t)
1101 (setq flyspell-tex-math-initialized 'error)
1104 ;*---------------------------------------------------------------------*/
1105 ;* flyspell-tex-command-p ... */
1106 ;*---------------------------------------------------------------------*/
1107 (defun flyspell-tex-command-p (word)
1108 "Return t if WORD is a TeX command."
1110 (let ((b (car (cdr word))))
1111 (and (re-search-backward "\\\\" (- (point) 100) t)
1112 (or (= (match-end 0) b)
1113 (and (goto-char (match-end 0))
1114 (looking-at flyspell-tex-command-regexp)
1115 (>= (match-end 0) b))))))
1116 (flyspell-math-tex-command-p)))
1118 ;*---------------------------------------------------------------------*/
1119 ;* flyspell-casechars-cache ... */
1120 ;*---------------------------------------------------------------------*/
1121 (defvar flyspell-casechars-cache nil)
1122 (defvar flyspell-ispell-casechars-cache nil)
1123 (make-variable-buffer-local 'flyspell-casechars-cache)
1124 (make-variable-buffer-local 'flyspell-ispell-casechars-cache)
1126 ;*---------------------------------------------------------------------*/
1127 ;* flyspell-get-casechars ... */
1128 ;*---------------------------------------------------------------------*/
1129 (defun flyspell-get-casechars ()
1130 "This function builds a string that is the regexp of word chars.
1131 In order to avoid one useless string construction,
1132 this function changes the last char of the `ispell-casechars' string."
1133 (let ((ispell-casechars (ispell-get-casechars)))
1135 ((eq ispell-parser 'tex)
1136 (setq flyspell-ispell-casechars-cache ispell-casechars)
1137 (setq flyspell-casechars-cache
1138 (concat (substring ispell-casechars
1140 (- (length ispell-casechars) 1))
1142 flyspell-casechars-cache)
1144 (setq flyspell-ispell-casechars-cache ispell-casechars)
1145 (setq flyspell-casechars-cache ispell-casechars)
1146 flyspell-casechars-cache))))
1148 ;*---------------------------------------------------------------------*/
1149 ;* flyspell-get-not-casechars-cache ... */
1150 ;*---------------------------------------------------------------------*/
1151 (defvar flyspell-not-casechars-cache nil)
1152 (defvar flyspell-ispell-not-casechars-cache nil)
1153 (make-variable-buffer-local 'flyspell-not-casechars-cache)
1154 (make-variable-buffer-local 'flyspell-ispell-not-casechars-cache)
1156 ;*---------------------------------------------------------------------*/
1157 ;* flyspell-get-not-casechars ... */
1158 ;*---------------------------------------------------------------------*/
1159 (defun flyspell-get-not-casechars ()
1160 "This function builds a string that is the regexp of non-word chars."
1161 (let ((ispell-not-casechars (ispell-get-not-casechars)))
1163 ((eq ispell-parser 'tex)
1164 (setq flyspell-ispell-not-casechars-cache ispell-not-casechars)
1165 (setq flyspell-not-casechars-cache
1166 (concat (substring ispell-not-casechars
1168 (- (length ispell-not-casechars) 1))
1170 flyspell-not-casechars-cache)
1172 (setq flyspell-ispell-not-casechars-cache ispell-not-casechars)
1173 (setq flyspell-not-casechars-cache ispell-not-casechars)
1174 flyspell-not-casechars-cache))))
1176 ;*---------------------------------------------------------------------*/
1177 ;* flyspell-get-word ... */
1178 ;*---------------------------------------------------------------------*/
1179 (defun flyspell-get-word (following)
1180 "Return the word for spell-checking according to Ispell syntax.
1181 If argument FOLLOWING is non-nil or if `ispell-following-word'
1182 is non-nil when called interactively, then the following word
1183 \(rather than preceding\) is checked when the cursor is not over a word.
1184 Optional second argument contains other chars that can be included in word
1187 Word syntax described by `ispell-dictionary-alist' (which see)."
1188 (let* ((flyspell-casechars (flyspell-get-casechars))
1189 (flyspell-not-casechars (flyspell-get-not-casechars))
1190 (ispell-otherchars (ispell-get-otherchars))
1191 (ispell-many-otherchars-p (ispell-get-many-otherchars-p))
1192 (word-regexp (if (string< "" ispell-otherchars)
1193 (concat flyspell-casechars
1199 (if ispell-many-otherchars-p
1201 (concat flyspell-casechars "+")))
1205 (if (not (looking-at flyspell-casechars))
1207 (re-search-forward flyspell-casechars (point-max) t)
1208 (re-search-backward flyspell-casechars (point-min) t)))
1209 ;; move to front of word
1210 (re-search-backward flyspell-not-casechars (point-min) 'start)
1212 (if (string< "" ispell-otherchars)
1213 (while (and (looking-at ispell-otherchars)
1215 (or (not did-it-once)
1216 ispell-many-otherchars-p)
1217 (not (eq pos (point))))
1219 (setq did-it-once t)
1221 (if (looking-at flyspell-casechars)
1222 (re-search-backward flyspell-not-casechars (point-min) 'move)
1223 (backward-char -1)))))
1224 ;; Now mark the word and save to string.
1225 (if (eq (re-search-forward word-regexp (point-max) t) nil)
1228 (setq start (match-beginning 0)
1230 word (buffer-substring-no-properties start end))
1231 (list word start end)))))
1233 ;*---------------------------------------------------------------------*/
1234 ;* flyspell-small-region ... */
1235 ;*---------------------------------------------------------------------*/
1236 (defun flyspell-small-region (beg end)
1237 "Flyspell text between BEG and END."
1245 (while (< (point) end)
1246 (if (and flyspell-issue-message-flag (= count 100))
1248 (message "Spell Checking...%d%%"
1249 (* 100 (/ (float (- (point) beg)) (- end beg))))
1251 (setq count (+ 1 count)))
1254 (let ((cur (point)))
1256 (if (and (< (point) end) (> (point) (+ cur 1)))
1257 (backward-char 1)))))
1259 (if flyspell-issue-message-flag (message "Spell Checking completed."))
1262 ;*---------------------------------------------------------------------*/
1263 ;* flyspell-external-ispell-process ... */
1264 ;*---------------------------------------------------------------------*/
1265 (defvar flyspell-external-ispell-process '()
1266 "The external Flyspell Ispell process.")
1268 ;*---------------------------------------------------------------------*/
1269 ;* flyspell-external-ispell-buffer ... */
1270 ;*---------------------------------------------------------------------*/
1271 (defvar flyspell-external-ispell-buffer '())
1272 (defvar flyspell-large-region-buffer '())
1273 (defvar flyspell-large-region-beg (point-min))
1274 (defvar flyspell-large-region-end (point-max))
1276 ;*---------------------------------------------------------------------*/
1277 ;* flyspell-external-point-words ... */
1278 ;*---------------------------------------------------------------------*/
1279 (defun flyspell-external-point-words ()
1280 (let ((buffer flyspell-external-ispell-buffer))
1282 (beginning-of-buffer)
1283 (let ((size (- flyspell-large-region-end flyspell-large-region-beg))
1284 (start flyspell-large-region-beg))
1285 ;; now we are done with ispell, we have to find the word in
1286 ;; the initial buffer
1287 (while (< (point) (- (point-max) 1))
1288 ;; we have to fetch the incorrect word
1289 (if (re-search-forward "\\([^\n]+\\)\n" (point-max) t)
1290 (let ((word (match-string 1)))
1291 (goto-char (match-end 0))
1292 (set-buffer flyspell-large-region-buffer)
1293 (goto-char flyspell-large-region-beg)
1294 (if flyspell-issue-message-flag
1295 (message "Spell Checking...%d%% [%s]"
1296 (* 100 (/ (float (- (point) start)) size))
1298 (if (search-forward word flyspell-large-region-end t)
1300 (setq flyspell-large-region-beg (point))
1301 (goto-char (- (point) 1))
1303 (set-buffer buffer))
1304 (goto-char (point-max)))))
1306 (if flyspell-issue-message-flag (message "Spell Checking completed."))
1307 ;; ok, we are done with pointing out incorrect words, we just
1308 ;; have to kill the temporary buffer
1309 (kill-buffer flyspell-external-ispell-buffer)
1310 (setq flyspell-external-ispell-buffer nil)))
1312 ;*---------------------------------------------------------------------*/
1313 ;* flyspell-large-region ... */
1314 ;*---------------------------------------------------------------------*/
1315 (defun flyspell-large-region (beg end)
1316 (let* ((curbuf (current-buffer))
1317 (buffer (get-buffer-create "*flyspell-region*")))
1318 (setq flyspell-external-ispell-buffer buffer)
1319 (setq flyspell-large-region-buffer curbuf)
1320 (setq flyspell-large-region-beg beg)
1321 (setq flyspell-large-region-end end)
1324 ;; this is done, we can start checking...
1325 (if flyspell-issue-message-flag (message "Checking region..."))
1327 (let ((c (apply 'call-process-region beg
1335 ;; Local dictionary becomes the global dictionary in use.
1336 (if ispell-local-dictionary
1337 (setq ispell-dictionary ispell-local-dictionary))
1338 (setq args (ispell-get-ispell-args))
1339 (if ispell-dictionary ; use specified dictionary
1341 (append (list "-d" ispell-dictionary) args)))
1342 (if ispell-personal-dictionary ; use specified pers dict
1347 ispell-personal-dictionary)))))
1348 (setq args (append args ispell-extra-args))
1351 (flyspell-external-point-words)
1352 (error "Can't check region...")))))
1354 ;*---------------------------------------------------------------------*/
1355 ;* flyspell-region ... */
1356 ;* ------------------------------------------------------------- */
1357 ;* Because `ispell -a' is too slow, it is not possible to use */
1358 ;* it on large region. Then, when ispell is invoked on a large */
1359 ;* text region, a new `ispell -l' process is spawned. The */
1360 ;* pointed out words are then searched in the region a checked with */
1361 ;* regular flyspell means. */
1362 ;*---------------------------------------------------------------------*/
1364 (defun flyspell-region (beg end)
1365 "Flyspell text between BEG and END."
1374 (if (> (- end beg) flyspell-large-region)
1375 (flyspell-large-region beg end)
1376 (flyspell-small-region beg end)))))
1378 ;*---------------------------------------------------------------------*/
1379 ;* flyspell-buffer ... */
1380 ;*---------------------------------------------------------------------*/
1382 (defun flyspell-buffer ()
1383 "Flyspell whole buffer."
1385 (flyspell-region (point-min) (point-max)))
1387 ;*---------------------------------------------------------------------*/
1388 ;* old next error position ... */
1389 ;*---------------------------------------------------------------------*/
1390 (defvar flyspell-old-buffer-error nil)
1391 (defvar flyspell-old-pos-error nil)
1393 ;*---------------------------------------------------------------------*/
1394 ;* flyspell-goto-next-error ... */
1395 ;*---------------------------------------------------------------------*/
1396 (defun flyspell-goto-next-error ()
1397 "Go to the next previously detected error.
1398 In general FLYSPELL-GOTO-NEXT-ERROR must be used after
1403 (if (and (eq (current-buffer) flyspell-old-buffer-error)
1404 (eq pos flyspell-old-pos-error))
1406 (if (= flyspell-old-pos-error max)
1407 ;; goto beginning of buffer
1409 (message "Restarting from beginning of buffer")
1410 (goto-char (point-min)))
1412 (setq pos (point))))
1413 ;; seek the next error
1414 (while (and (< pos max)
1415 (let ((ovs (overlays-at pos))
1417 (while (and (not r) (consp ovs))
1418 (if (flyspell-overlay-p (car ovs))
1420 (setq ovs (cdr ovs))))
1422 (setq pos (1+ pos)))
1423 ;; save the current location for next invocation
1424 (setq flyspell-old-pos-error pos)
1425 (setq flyspell-old-buffer-error (current-buffer))
1428 (message "No more miss-spelled word!"))))
1430 ;*---------------------------------------------------------------------*/
1431 ;* flyspell-overlay-p ... */
1432 ;*---------------------------------------------------------------------*/
1433 (defun flyspell-overlay-p (o)
1434 "A predicate that return true iff O is an overlay used by flyspell."
1435 (and (overlayp o) (overlay-get o 'flyspell-overlay)))
1437 ;*---------------------------------------------------------------------*/
1438 ;* flyspell-delete-all-overlays ... */
1439 ;* ------------------------------------------------------------- */
1440 ;* Remove all the overlays introduced by flyspell. */
1441 ;*---------------------------------------------------------------------*/
1442 (defun flyspell-delete-all-overlays ()
1443 "Delete all the overlays used by flyspell."
1444 (let ((l (overlays-in (point-min) (point-max))))
1447 (if (flyspell-overlay-p (car l))
1448 (delete-overlay (car l)))
1449 (setq l (cdr l))))))
1451 ;*---------------------------------------------------------------------*/
1452 ;* flyspell-unhighlight-at ... */
1453 ;*---------------------------------------------------------------------*/
1454 (defun flyspell-unhighlight-at (pos)
1455 "Remove the flyspell overlay that are located at POS."
1456 (if flyspell-persistent-highlight
1457 (let ((overlays (overlays-at pos)))
1458 (while (consp overlays)
1459 (if (flyspell-overlay-p (car overlays))
1460 (delete-overlay (car overlays)))
1461 (setq overlays (cdr overlays))))
1462 (if (flyspell-overlay-p flyspell-overlay)
1463 (delete-overlay flyspell-overlay))))
1465 ;*---------------------------------------------------------------------*/
1466 ;* flyspell-properties-at-p ... */
1467 ;* ------------------------------------------------------------- */
1468 ;* Is there an highlight properties at position pos? */
1469 ;*---------------------------------------------------------------------*/
1470 (defun flyspell-properties-at-p (pos)
1471 "Return t if there is a text property at POS, not counting `local-map'.
1472 If variable `flyspell-highlight-properties' is set to nil,
1473 text with properties are not checked. This function is used to discover
1474 if the character at POS has any other property."
1475 (let ((prop (text-properties-at pos))
1477 (while (and keep (consp prop))
1478 (if (and (eq (car prop) 'local-map) (consp (cdr prop)))
1479 (setq prop (cdr (cdr prop)))
1483 ;*---------------------------------------------------------------------*/
1484 ;* make-flyspell-overlay ... */
1485 ;*---------------------------------------------------------------------*/
1486 (defun make-flyspell-overlay (beg end face mouse-face)
1487 "Allocate an overlay to highlight an incorrect word.
1488 BEG and END specify the range in the buffer of that word.
1489 FACE and MOUSE-FACE specify the `face' and `mouse-face' properties
1491 (let ((flyspell-overlay (make-overlay beg end nil t nil)))
1492 (overlay-put flyspell-overlay 'face face)
1493 (overlay-put flyspell-overlay 'mouse-face mouse-face)
1494 (overlay-put flyspell-overlay 'flyspell-overlay t)
1495 (overlay-put flyspell-overlay 'evaporate t)
1496 (if flyspell-use-local-map
1497 (overlay-put flyspell-overlay
1498 flyspell-overlay-keymap-property-name
1499 flyspell-mouse-map))
1500 (when (eq face 'flyspell-incorrect-face)
1501 (and (stringp flyspell-before-incorrect-word-string)
1502 (overlay-put flyspell-overlay 'before-string
1503 flyspell-before-incorrect-word-string))
1504 (and (stringp flyspell-after-incorrect-word-string)
1505 (overlay-put flyspell-overlay 'after-string
1506 flyspell-after-incorrect-word-string)))
1509 ;*---------------------------------------------------------------------*/
1510 ;* flyspell-highlight-incorrect-region ... */
1511 ;*---------------------------------------------------------------------*/
1512 (defun flyspell-highlight-incorrect-region (beg end poss)
1513 "Set up an overlay on a misspelled word, in the buffer from BEG to END."
1514 (unless (run-hook-with-args-until-success
1515 'flyspell-incorrect-hook beg end poss)
1516 (if (or flyspell-highlight-properties (not (flyspell-properties-at-p beg)))
1518 ;; we cleanup current overlay at the same position
1519 (if (and (not flyspell-persistent-highlight)
1520 (overlayp flyspell-overlay))
1521 (delete-overlay flyspell-overlay)
1522 (let ((overlays (overlays-at beg)))
1523 (while (consp overlays)
1524 (if (flyspell-overlay-p (car overlays))
1525 (delete-overlay (car overlays)))
1526 (setq overlays (cdr overlays)))))
1527 ;; now we can use a new overlay
1528 (setq flyspell-overlay
1529 (make-flyspell-overlay beg end
1530 'flyspell-incorrect-face
1533 ;*---------------------------------------------------------------------*/
1534 ;* flyspell-highlight-duplicate-region ... */
1535 ;*---------------------------------------------------------------------*/
1536 (defun flyspell-highlight-duplicate-region (beg end)
1537 "Set up an overlay on a duplicated word, in the buffer from BEG to END."
1538 (if (or flyspell-highlight-properties (not (flyspell-properties-at-p beg)))
1540 ;; we cleanup current overlay at the same position
1541 (if (and (not flyspell-persistent-highlight)
1542 (overlayp flyspell-overlay))
1543 (delete-overlay flyspell-overlay)
1544 (let ((overlays (overlays-at beg)))
1545 (while (consp overlays)
1546 (if (flyspell-overlay-p (car overlays))
1547 (delete-overlay (car overlays)))
1548 (setq overlays (cdr overlays)))))
1549 ;; now we can use a new overlay
1550 (setq flyspell-overlay
1551 (make-flyspell-overlay beg end
1552 'flyspell-duplicate-face
1555 ;*---------------------------------------------------------------------*/
1556 ;* flyspell-auto-correct-cache ... */
1557 ;*---------------------------------------------------------------------*/
1558 (defvar flyspell-auto-correct-pos nil)
1559 (defvar flyspell-auto-correct-region nil)
1560 (defvar flyspell-auto-correct-ring nil)
1561 (defvar flyspell-auto-correct-word nil)
1562 (make-variable-buffer-local 'flyspell-auto-correct-pos)
1563 (make-variable-buffer-local 'flyspell-auto-correct-region)
1564 (make-variable-buffer-local 'flyspell-auto-correct-ring)
1565 (make-variable-buffer-local 'flyspell-auto-correct-word)
1567 ;*---------------------------------------------------------------------*/
1568 ;* flyspell-check-previous-highlighted-word ... */
1569 ;*---------------------------------------------------------------------*/
1570 (defun flyspell-check-previous-highlighted-word (&optional arg)
1571 "Correct the closer misspelled word.
1572 This function scans a mis-spelled word before the cursor. If it finds one
1573 it proposes replacement for that word. With prefix arg, count that many
1574 misspelled words backwards."
1576 (let ((pos1 (point))
1578 (arg (if (or (not (numberp arg)) (< arg 1)) 1 arg))
1581 (while (and (setq pos (previous-overlay-change pos))
1584 (if (> pos (point-min))
1586 (setq ovs (overlays-at (1- pos)))
1589 (setq ovs (cdr ovs))
1590 (if (and (overlay-get ov 'flyspell-overlay)
1591 (= 0 (setq arg (1- arg))))
1592 (throw 'exit t)))))))
1596 (error "No word to correct before point"))))
1598 ;*---------------------------------------------------------------------*/
1599 ;* flyspell-display-next-corrections ... */
1600 ;*---------------------------------------------------------------------*/
1601 (defun flyspell-display-next-corrections (corrections)
1602 (let ((string "Corrections:")
1605 (while (< (length string) 80)
1606 (if (equal (car l) flyspell-auto-correct-word)
1607 (setq pos (cons (+ 1 (length string)) pos)))
1608 (setq string (concat string " " (car l)))
1611 (let ((num (car pos)))
1612 (put-text-property num
1613 (+ num (length flyspell-auto-correct-word))
1615 'flyspell-incorrect-face
1617 (setq pos (cdr pos)))
1618 (if (fboundp 'display-message)
1619 (display-message 'no-log string)
1622 ;*---------------------------------------------------------------------*/
1623 ;* flyspell-abbrev-table ... */
1624 ;*---------------------------------------------------------------------*/
1625 (defun flyspell-abbrev-table ()
1626 (if flyspell-use-global-abbrev-table-p
1628 local-abbrev-table))
1630 ;*---------------------------------------------------------------------*/
1631 ;* flyspell-define-abbrev ... */
1632 ;*---------------------------------------------------------------------*/
1633 (defun flyspell-define-abbrev (name expansion)
1634 (let ((table (flyspell-abbrev-table)))
1636 (define-abbrev table name expansion))))
1638 ;*---------------------------------------------------------------------*/
1639 ;* flyspell-auto-correct-word ... */
1640 ;*---------------------------------------------------------------------*/
1641 (defun flyspell-auto-correct-word ()
1642 "Correct the current word.
1643 This command proposes various successive corrections for the current word."
1646 (old-max (point-max)))
1647 ;; use the correct dictionary
1648 (flyspell-accept-buffer-local-defs)
1649 (if (and (eq flyspell-auto-correct-pos pos)
1650 (consp flyspell-auto-correct-region))
1651 ;; we have already been using the function at the same location
1652 (let* ((start (car flyspell-auto-correct-region))
1653 (len (cdr flyspell-auto-correct-region)))
1654 (flyspell-unhighlight-at start)
1655 (delete-region start (+ start len))
1656 (setq flyspell-auto-correct-ring (cdr flyspell-auto-correct-ring))
1657 (let* ((word (car flyspell-auto-correct-ring))
1658 (len (length word)))
1659 (rplacd flyspell-auto-correct-region len)
1661 (if flyspell-abbrev-p
1662 (if (flyspell-already-abbrevp (flyspell-abbrev-table)
1663 flyspell-auto-correct-word)
1664 (flyspell-change-abbrev (flyspell-abbrev-table)
1665 flyspell-auto-correct-word
1667 (flyspell-define-abbrev flyspell-auto-correct-word word)))
1668 (funcall flyspell-insert-function word)
1670 (flyspell-display-next-corrections flyspell-auto-correct-ring))
1671 (flyspell-ajust-cursor-point pos (point) old-max)
1672 (setq flyspell-auto-correct-pos (point)))
1673 ;; fetch the word to be checked
1674 (let ((word (flyspell-get-word nil))
1676 ;; destructure return word info list.
1677 (setq start (car (cdr word))
1678 end (car (cdr (cdr word)))
1680 (setq flyspell-auto-correct-word word)
1681 ;; now check spelling of word.
1682 (process-send-string ispell-process "%\n") ;put in verbose mode
1683 (process-send-string ispell-process (concat "^" word "\n"))
1684 ;; wait until ispell has processed word
1686 (accept-process-output ispell-process)
1687 (not (string= "" (car ispell-filter)))))
1688 (setq ispell-filter (cdr ispell-filter))
1689 (if (consp ispell-filter)
1690 (setq poss (ispell-parse-output (car ispell-filter))))
1691 (cond ((or (eq poss t) (stringp poss))
1692 ;; don't correct word
1696 (error "Ispell: error in Ispell process"))
1698 ;; the word is incorrect, we have to propose a replacement
1699 (let ((replacements (if flyspell-sort-corrections
1700 (sort (car (cdr (cdr poss))) 'string<)
1701 (car (cdr (cdr poss))))))
1702 (setq flyspell-auto-correct-region nil)
1703 (if (consp replacements)
1705 (let ((replace (car replacements)))
1706 (let ((new-word replace))
1707 (if (not (equal new-word (car poss)))
1709 ;; the save the current replacements
1710 (setq flyspell-auto-correct-region
1711 (cons start (length new-word)))
1712 (let ((l replacements))
1713 (while (consp (cdr l))
1715 (rplacd l (cons (car poss) replacements)))
1716 (setq flyspell-auto-correct-ring
1718 (flyspell-unhighlight-at start)
1719 (delete-region start end)
1720 (funcall flyspell-insert-function new-word)
1721 (if flyspell-abbrev-p
1722 (if (flyspell-already-abbrevp
1723 (flyspell-abbrev-table) word)
1724 (flyspell-change-abbrev
1725 (flyspell-abbrev-table)
1728 (flyspell-define-abbrev word new-word)))
1730 (flyspell-display-next-corrections
1731 (cons new-word flyspell-auto-correct-ring))
1732 (flyspell-ajust-cursor-point pos
1735 (setq flyspell-auto-correct-pos (point))
1736 (ispell-pdict-save t)))))
1738 ;*---------------------------------------------------------------------*/
1739 ;* flyspell-auto-correct-previous-pos ... */
1740 ;*---------------------------------------------------------------------*/
1741 (defvar flyspell-auto-correct-previous-pos nil
1742 "Holds the start of the first incorrect word before point.")
1744 ;*---------------------------------------------------------------------*/
1745 ;* flyspell-auto-correct-previous-hook ... */
1746 ;*---------------------------------------------------------------------*/
1747 (defun flyspell-auto-correct-previous-hook ()
1748 "Hook to track successive calls to `flyspell-auto-correct-previous-word'.
1749 Sets flyspell-auto-correct-previous-pos to nil"
1751 (remove-hook 'pre-command-hook (function flyspell-auto-correct-previous-hook) t)
1752 (unless (eq this-command (function flyspell-auto-correct-previous-word))
1753 (setq flyspell-auto-correct-previous-pos nil)))
1755 ;*---------------------------------------------------------------------*/
1756 ;* flyspell-auto-correct-previous-word ... */
1757 ;*---------------------------------------------------------------------*/
1758 (defun flyspell-auto-correct-previous-word (position)
1759 "*Auto correct the first mispelled word that occurs before point."
1762 (add-hook 'pre-command-hook
1763 (function flyspell-auto-correct-previous-hook) t t)
1766 (unless flyspell-auto-correct-previous-pos
1767 ;; only reset if a new overlay exists
1768 (setq flyspell-auto-correct-previous-pos nil)
1770 (let ((overlay-list (overlays-in (point-min) position))
1771 (new-overlay 'dummy-value))
1773 ;; search for previous (new) flyspell overlay
1774 (while (and new-overlay
1775 (or (not (flyspell-overlay-p new-overlay))
1776 ;; check if its face has changed
1777 (not (eq (get-char-property
1778 (overlay-start new-overlay) 'face)
1779 'flyspell-incorrect-face))))
1780 (setq new-overlay (car-safe overlay-list))
1781 (setq overlay-list (cdr-safe overlay-list)))
1783 ;; if nothing new exits new-overlay should be nil
1784 (if new-overlay;; the length of the word may change so go to the start
1785 (setq flyspell-auto-correct-previous-pos
1786 (overlay-start new-overlay)))))
1788 (when flyspell-auto-correct-previous-pos
1790 (goto-char flyspell-auto-correct-previous-pos)
1791 (let ((ispell-following-word t));; point is at start
1792 (if (numberp flyspell-auto-correct-previous-pos)
1793 (goto-char flyspell-auto-correct-previous-pos))
1794 (flyspell-auto-correct-word))
1795 ;; the point may have moved so reset this
1796 (setq flyspell-auto-correct-previous-pos (point))))))
1798 ;*---------------------------------------------------------------------*/
1799 ;* flyspell-correct-word ... */
1800 ;*---------------------------------------------------------------------*/
1801 (defun flyspell-correct-word (event)
1802 "Pop up a menu of possible corrections for a misspelled word.
1803 The word checked is the word at the mouse position."
1805 ;; use the correct dictionary
1806 (flyspell-accept-buffer-local-defs)
1807 ;; retain cursor location (I don't know why but save-excursion here fails).
1808 (let ((save (point)))
1809 (mouse-set-point event)
1810 (let ((cursor-location (point))
1811 (word (flyspell-get-word nil))
1812 start end poss replace)
1813 ;; destructure return word info list.
1814 (setq start (car (cdr word))
1815 end (car (cdr (cdr word)))
1817 ;; now check spelling of word.
1818 (process-send-string ispell-process "%\n") ;put in verbose mode
1819 (process-send-string ispell-process (concat "^" word "\n"))
1820 ;; wait until ispell has processed word
1822 (accept-process-output ispell-process)
1823 (not (string= "" (car ispell-filter)))))
1824 (setq ispell-filter (cdr ispell-filter))
1825 (if (consp ispell-filter)
1826 (setq poss (ispell-parse-output (car ispell-filter))))
1827 (cond ((or (eq poss t) (stringp poss))
1828 ;; don't correct word
1832 (error "Ispell: error in Ispell process"))
1833 ((string-match "GNU" (emacs-version))
1834 ;; the word is incorrect, we have to propose a replacement
1835 (setq replace (flyspell-emacs-popup event poss word))
1836 (cond ((eq replace 'ignore)
1841 (process-send-string ispell-process (concat "*" word "\n"))
1842 (flyspell-unhighlight-at cursor-location)
1843 (setq ispell-pdict-modified-p '(t)))
1844 ((or (eq replace 'buffer) (eq replace 'session))
1845 (process-send-string ispell-process (concat "@" word "\n"))
1846 (if (null ispell-pdict-modified-p)
1847 (setq ispell-pdict-modified-p
1848 (list ispell-pdict-modified-p)))
1849 (flyspell-unhighlight-at cursor-location)
1851 (if (eq replace 'buffer)
1852 (ispell-add-per-file-word-list word)))
1854 (flyspell-unhighlight-at cursor-location)
1855 (let ((new-word (if (atom replace)
1858 (cursor-location (+ (- (length word) (- end start))
1860 (if (not (equal new-word (car poss)))
1861 (let ((old-max (point-max)))
1862 (delete-region start end)
1863 (funcall flyspell-insert-function new-word)
1864 (if flyspell-abbrev-p
1865 (flyspell-define-abbrev word new-word))
1866 (flyspell-ajust-cursor-point save
1872 ((eq flyspell-emacs 'xemacs)
1873 (flyspell-xemacs-popup
1874 event poss word cursor-location start end save)
1876 (ispell-pdict-save t))))
1878 ;*---------------------------------------------------------------------*/
1879 ;* flyspell-xemacs-correct ... */
1880 ;*---------------------------------------------------------------------*/
1881 (defun flyspell-xemacs-correct (replace poss word cursor-location start end save)
1882 "The xemacs popup menu callback."
1883 (cond ((eq replace 'ignore)
1886 (process-send-string ispell-process (concat "*" word "\n"))
1887 (process-send-string ispell-process "#\n")
1888 (flyspell-unhighlight-at cursor-location)
1889 (setq ispell-pdict-modified-p '(t)))
1890 ((or (eq replace 'buffer) (eq replace 'session))
1891 (process-send-string ispell-process (concat "@" word "\n"))
1892 (flyspell-unhighlight-at cursor-location)
1893 (if (null ispell-pdict-modified-p)
1894 (setq ispell-pdict-modified-p
1895 (list ispell-pdict-modified-p)))
1896 (if (eq replace 'buffer)
1897 (ispell-add-per-file-word-list word)))
1899 (let ((old-max (point-max))
1900 (new-word (if (atom replace)
1903 (cursor-location (+ (- (length word) (- end start))
1905 (if (not (equal new-word (car poss)))
1907 (delete-region start end)
1909 (funcall flyspell-insert-function new-word)
1910 (if flyspell-abbrev-p
1911 (flyspell-define-abbrev word new-word))))
1912 (flyspell-ajust-cursor-point save cursor-location old-max)))))
1914 ;*---------------------------------------------------------------------*/
1915 ;* flyspell-ajust-cursor-point ... */
1916 ;*---------------------------------------------------------------------*/
1917 (defun flyspell-ajust-cursor-point (save cursor-location old-max)
1918 (if (>= save cursor-location)
1919 (let ((new-pos (+ save (- (point-max) old-max))))
1921 ((< new-pos (point-min))
1923 ((> new-pos (point-max))
1928 ;*---------------------------------------------------------------------*/
1929 ;* flyspell-emacs-popup ... */
1930 ;*---------------------------------------------------------------------*/
1931 (defun flyspell-emacs-popup (event poss word)
1932 "The Emacs popup menu."
1934 (let* ((mouse-pos (mouse-position))
1935 (mouse-pos (if (nth 1 mouse-pos)
1937 (set-mouse-position (car mouse-pos)
1938 (/ (frame-width) 2) 2)
1941 (setq event (list (list (car (cdr mouse-pos))
1942 (1+ (cdr (cdr mouse-pos))))
1944 (let* ((corrects (if flyspell-sort-corrections
1945 (sort (car (cdr (cdr poss))) 'string<)
1946 (car (cdr (cdr poss)))))
1947 (cor-menu (if (consp corrects)
1948 (mapcar (lambda (correct)
1949 (list correct correct))
1952 (affix (car (cdr (cdr (cdr poss)))))
1953 (base-menu (let ((save (if (consp affix)
1955 (list (concat "Save affix: " (car affix))
1957 '("Accept (session)" session)
1958 '("Accept (buffer)" buffer))
1959 '(("Save word" save)
1960 ("Accept (session)" session)
1961 ("Accept (buffer)" buffer)))))
1962 (if (consp cor-menu)
1963 (append cor-menu (cons "" save))
1965 (menu (cons "flyspell correction menu" base-menu)))
1966 (car (x-popup-menu event
1967 (list (format "%s [%s]" word (or ispell-local-dictionary
1971 ;*---------------------------------------------------------------------*/
1972 ;* flyspell-xemacs-popup ... */
1973 ;*---------------------------------------------------------------------*/
1974 (defun flyspell-xemacs-popup (event poss word cursor-location start end save)
1975 "The XEmacs popup menu."
1976 (let* ((corrects (if flyspell-sort-corrections
1977 (sort (car (cdr (cdr poss))) 'string<)
1978 (car (cdr (cdr poss)))))
1979 (cor-menu (if (consp corrects)
1980 (mapcar (lambda (correct)
1982 (list 'flyspell-xemacs-correct
1993 (affix (car (cdr (cdr (cdr poss)))))
1994 (menu (let ((save (if (consp affix)
1996 (concat "Save affix: " (car affix))
1997 (list 'flyspell-xemacs-correct
2008 (list 'flyspell-xemacs-correct
2017 (session (vector "Accept (session)"
2018 (list 'flyspell-xemacs-correct
2027 (buffer (vector "Accept (buffer)"
2028 (list 'flyspell-xemacs-correct
2037 (if (consp cor-menu)
2038 (append cor-menu (list "-" save session buffer))
2039 (list save session buffer)))))
2040 (popup-menu (cons (format "%s [%s]" word (or ispell-local-dictionary
2044 ;*---------------------------------------------------------------------*/
2045 ;* Some example functions for real autocorrecting */
2046 ;*---------------------------------------------------------------------*/
2047 (defun flyspell-maybe-correct-transposition (beg end poss)
2048 "Check replacements for transposed characters.
2050 If the text between BEG and END is equal to a correction suggested by
2051 Ispell, after transposing two adjacent characters, correct the text,
2054 The third arg POSS is either the symbol 'doublon' or a list of
2055 possible corrections as returned by 'ispell-parse-output'.
2057 This function is meant to be added to 'flyspell-incorrect-hook'."
2059 (let ((temp-buffer (get-buffer-create " *flyspell-temp*"))
2062 (copy-to-buffer temp-buffer beg end)
2063 (set-buffer temp-buffer)
2064 (goto-char (1+ (point-min)))
2065 (while (and (not (eobp)) (not found))
2067 (if (member (buffer-string) (nth 2 poss))
2068 (setq found (point))
2069 (transpose-chars -1)
2073 (goto-char (+ beg found -1))
2074 (transpose-chars -1)
2077 (defun flyspell-maybe-correct-doubling (beg end poss)
2078 "Check replacements for doubled characters.
2080 If the text between BEG and END is equal to a correction suggested by
2081 Ispell, after removing a pair of doubled characters, correct the text,
2084 The third arg POSS is either the symbol 'doublon' or a list of
2085 possible corrections as returned by 'ispell-parse-output'.
2087 This function is meant to be added to 'flyspell-incorrect-hook'."
2089 (let ((temp-buffer (get-buffer-create " *flyspell-temp*"))
2092 (copy-to-buffer temp-buffer beg end)
2093 (set-buffer temp-buffer)
2094 (goto-char (1+ (point-min)))
2095 (while (and (not (eobp)) (not found))
2096 (when (char-equal (char-after) (char-before))
2098 (if (member (buffer-string) (nth 2 poss))
2099 (setq found (point))
2100 (insert-char (char-before) 1)))
2104 (goto-char (+ beg found -1))
2108 ;*---------------------------------------------------------------------*/
2109 ;* flyspell-already-abbrevp ... */
2110 ;*---------------------------------------------------------------------*/
2111 (defun flyspell-already-abbrevp (table word)
2112 (let ((sym (abbrev-symbol word table)))
2113 (and sym (symbolp sym))))
2115 ;*---------------------------------------------------------------------*/
2116 ;* flyspell-change-abbrev ... */
2117 ;*---------------------------------------------------------------------*/
2118 (defun flyspell-change-abbrev (table old new)
2119 (set (abbrev-symbol old table) new))
2123 ;;; flyspell.el ends here