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 "*The function to be used when a word has to be inserted by flyspell
236 (defcustom flyspell-before-incorrect-word-string nil
237 "String used to indicate an incorrect word starting."
239 :type '(choice string (const nil)))
241 (defcustom flyspell-after-incorrect-word-string nil
242 "String used to indicate an incorrect word ending."
244 :type '(choice string (const nil)))
246 ;*---------------------------------------------------------------------*/
247 ;* Mode specific options */
248 ;* ------------------------------------------------------------- */
249 ;* Mode specific options enable users to disable flyspell on */
250 ;* certain word depending of the emacs mode. For instance, when */
251 ;* using flyspell with mail-mode add the following expression */
252 ;* in your .emacs file: */
253 ;* (add-hook 'mail-mode */
254 ;* '(lambda () (setq flyspell-generic-check-word-p */
255 ;* 'mail-mode-flyspell-verify))) */
256 ;*---------------------------------------------------------------------*/
257 (defvar flyspell-generic-check-word-p nil
258 "Function providing per-mode customization over which words are flyspelled.
259 Returns t to continue checking, nil otherwise.
260 Flyspell mode sets this variable to whatever is the `flyspell-mode-predicate'
261 property of the major mode name.")
262 (make-variable-buffer-local 'flyspell-generic-check-word-p)
264 ;*--- mail mode -------------------------------------------------------*/
265 (put 'mail-mode 'flyspell-mode-predicate 'mail-mode-flyspell-verify)
266 (put 'message-mode 'flyspell-mode-predicate 'mail-mode-flyspell-verify)
267 (defun mail-mode-flyspell-verify ()
268 "This function is used for `flyspell-generic-check-word-p' in Mail mode."
269 (let ((in-headers (save-excursion
270 (re-search-forward mail-header-separator nil t)))
271 (in-signature (save-excursion
272 (re-search-backward message-signature-separator nil t))))
274 (and (save-excursion (beginning-of-line)
275 (looking-at "^Subject:"))
276 (> (point) (match-end 0))))
282 (not (looking-at "[>}|]\\To:")))))))
284 ;*--- texinfo mode ----------------------------------------------------*/
285 (put 'texinfo-mode 'flyspell-mode-predicate 'texinfo-mode-flyspell-verify)
286 (defun texinfo-mode-flyspell-verify ()
287 "This function is used for `flyspell-generic-check-word-p' in Texinfo mode."
290 (not (looking-at "@"))))
292 ;*--- tex mode --------------------------------------------------------*/
293 (put 'tex-mode 'flyspell-mode-predicate 'tex-mode-flyspell-verify)
294 (defun tex-mode-flyspell-verify ()
295 "This function is used for `flyspell-generic-check-word-p' in LaTeX mode."
298 (re-search-backward "^[ \t]*%%%[ \t]+Local" (point-min) t)))
300 (let ((this (point-marker))
301 (e (progn (end-of-line) (point-marker))))
303 (if (re-search-forward "\\\\\\(cite\\|label\\|ref\\){[^}]*}" e t)
304 (and (>= this (match-beginning 0))
305 (<= this (match-end 0)) )))))))
307 ;*--- sgml mode -------------------------------------------------------*/
308 (put 'sgml-mode 'flyspell-mode-predicate 'sgml-mode-flyspell-verify)
309 (put 'html-mode 'flyspell-mode-predicate 'sgml-mode-flyspell-verify)
311 (defun sgml-mode-flyspell-verify ()
312 "This function is used for `flyspell-generic-check-word-p' in SGML mode."
314 (let ((this (point-marker))
315 (s (progn (beginning-of-line) (point-marker)))
316 (e (progn (end-of-line) (point-marker))))
319 (and (re-search-forward "[^<]*>" e t)
320 (= (match-beginning 0) this)))
323 (and (re-search-backward "<[^>]*" s t)
324 (= (match-end 0) this)))
327 (and (re-search-forward "[^&]*;" e t)
328 (= (match-beginning 0) this)))
331 (and (re-search-backward "&[^;]*" s t)
332 (= (match-end 0) this)))))))))
334 ;*---------------------------------------------------------------------*/
335 ;* Programming mode */
336 ;*---------------------------------------------------------------------*/
337 (defvar flyspell-prog-text-faces
338 '(font-lock-string-face font-lock-comment-face font-lock-doc-face)
339 "Faces corresponding to text in programming-mode buffers.")
341 (defun flyspell-generic-progmode-verify ()
342 "Used for `flyspell-generic-check-word-p' in programming modes."
343 (let ((f (get-text-property (point) 'face)))
344 (memq f flyspell-prog-text-faces)))
347 (defun flyspell-prog-mode ()
348 "Turn on `flyspell-mode' for comments and strings."
350 (setq flyspell-generic-check-word-p 'flyspell-generic-progmode-verify)
353 ;*---------------------------------------------------------------------*/
354 ;* Overlay compatibility */
355 ;*---------------------------------------------------------------------*/
356 (autoload 'make-overlay "overlay" "Overlay compatibility kit." t)
357 (autoload 'overlayp "overlay" "Overlay compatibility kit." t)
358 (autoload 'overlays-in "overlay" "Overlay compatibility kit." t)
359 (autoload 'delete-overlay "overlay" "Overlay compatibility kit." t)
360 (autoload 'overlays-at "overlay" "Overlay compatibility kit." t)
361 (autoload 'overlay-put "overlay" "Overlay compatibility kit." t)
362 (autoload 'overlay-get "overlay" "Overlay compatibility kit." t)
363 (autoload 'previous-overlay-change "overlay" "Overlay compatibility kit." t)
365 ;*---------------------------------------------------------------------*/
366 ;* Which emacs are we currently running */
367 ;*---------------------------------------------------------------------*/
368 (defvar flyspell-emacs
370 ((string-match "XEmacs" emacs-version)
374 "The type of Emacs we are currently running.")
376 (defvar flyspell-use-local-map
377 (or (eq flyspell-emacs 'xemacs)
378 (not (string< emacs-version "20"))))
380 ;*---------------------------------------------------------------------*/
381 ;* The minor mode declaration. */
382 ;*---------------------------------------------------------------------*/
383 (eval-when-compile (defvar flyspell-local-mouse-map))
385 (defvar flyspell-mode nil)
386 (make-variable-buffer-local 'flyspell-mode)
388 (defvar flyspell-mouse-map
389 (let ((map (make-sparse-keymap)))
391 ((eq flyspell-emacs 'xemacs)
392 (define-key map [(button2)] #'flyspell-correct-word)
393 (define-key map "\M-\t" #'flyspell-auto-correct-word))
394 (flyspell-use-local-map
395 (define-key map [(mouse-2)] #'flyspell-correct-word)
396 (define-key map "\M-\t" #'flyspell-auto-correct-word)))
400 (defvar flyspell-mode-map (make-sparse-keymap))
402 ;; mouse, keyboard bindings and misc definition
403 (when (or (assoc 'flyspell-mode minor-mode-map-alist)
404 (setq minor-mode-map-alist
405 (cons (cons 'flyspell-mode flyspell-mode-map)
406 minor-mode-map-alist)))
407 (define-key flyspell-mode-map "\M-\t" 'flyspell-auto-correct-word))
409 ;; the name of the overlay property that defines the keymap
410 (defvar flyspell-overlay-keymap-property-name 'keymap)
412 ;; dash character machinery
413 (defvar flyspell-consider-dash-as-word-delimiter-flag nil
414 "*Non-nil means that the `-' char is considered as a word delimiter.")
415 (make-variable-buffer-local 'flyspell-consider-dash-as-word-delimiter-flag)
416 (defvar flyspell-dash-dictionary nil)
417 (make-variable-buffer-local 'flyspell-dash-dictionary)
418 (defvar flyspell-dash-local-dictionary nil)
419 (make-variable-buffer-local 'flyspell-dash-local-dictionary)
421 ;*---------------------------------------------------------------------*/
423 ;*---------------------------------------------------------------------*/
424 (defface flyspell-incorrect-face
425 (if (eq flyspell-emacs 'xemacs)
426 '((((class color)) (:foreground "OrangeRed" :bold t :underline t))
428 '((((class color)) (:foreground "OrangeRed" :weight bold :underline t))
430 "Face used for marking a misspelled word in Flyspell."
433 (defface flyspell-duplicate-face
434 (if (eq flyspell-emacs 'xemacs)
435 '((((class color)) (:foreground "Gold3" :bold t :underline t))
437 '((((class color)) (:foreground "Gold3" :weight bold :underline t))
439 "Face used for marking a misspelled word that appears twice in the buffer.
440 See also `flyspell-duplicate-distance'."
443 (defvar flyspell-overlay nil)
445 ;*---------------------------------------------------------------------*/
446 ;* flyspell-mode ... */
447 ;*---------------------------------------------------------------------*/
449 (defun flyspell-mode (&optional arg)
450 "Minor mode performing on-the-fly spelling checking.
451 Ispell is automatically spawned on background for each entered words.
452 The default flyspell behavior is to highlight incorrect words.
453 With no argument, this command toggles Flyspell mode.
454 With a prefix argument ARG, turn Flyspell minor mode on iff ARG is positive.
457 \\[ispell-word]: correct words (using Ispell).
458 \\[flyspell-auto-correct-word]: automatically correct word.
459 \\[flyspell-correct-word] (or mouse-2): popup correct words.
462 This runs `flyspell-mode-hook' after flyspell is entered.
465 `flyspell-mode' uses `ispell-mode'. Thus all Ispell options are
466 valid. For instance, a personal dictionary can be used by
467 invoking `ispell-change-dictionary'.
469 Consider using the `ispell-parser' to check your text. For instance
471 \(add-hook 'tex-mode-hook (function (lambda () (setq ispell-parser 'tex))))
474 \\[flyspell-region] checks all words inside a region.
475 \\[flyspell-buffer] checks the whole buffer."
477 (let ((old-flyspell-mode flyspell-mode))
478 ;; Mark the mode as on or off.
479 (setq flyspell-mode (not (or (and (null arg) flyspell-mode)
480 (<= (prefix-numeric-value arg) 0))))
482 (unless (eq flyspell-mode old-flyspell-mode)
486 ;; Force modeline redisplay.
487 (set-buffer-modified-p (buffer-modified-p)))))
489 ;*---------------------------------------------------------------------*/
491 ;*---------------------------------------------------------------------*/
493 (add-minor-mode 'flyspell-mode
494 'flyspell-mode-line-string
499 ;*---------------------------------------------------------------------*/
500 ;* flyspell-buffers ... */
501 ;* ------------------------------------------------------------- */
502 ;* For remembering buffers running flyspell */
503 ;*---------------------------------------------------------------------*/
504 (defvar flyspell-buffers nil)
506 ;*---------------------------------------------------------------------*/
507 ;* flyspell-minibuffer-p ... */
508 ;*---------------------------------------------------------------------*/
509 (defun flyspell-minibuffer-p (buffer)
510 "Is BUFFER a minibuffer?"
511 (let ((ws (get-buffer-window-list buffer t)))
512 (and (consp ws) (window-minibuffer-p (car ws)))))
514 ;*---------------------------------------------------------------------*/
515 ;* flyspell-version ... */
516 ;*---------------------------------------------------------------------*/
518 (defun flyspell-version ()
519 "The flyspell version"
523 ;*---------------------------------------------------------------------*/
524 ;* flyspell-accept-buffer-local-defs ... */
525 ;*---------------------------------------------------------------------*/
526 (defun flyspell-accept-buffer-local-defs ()
527 (ispell-accept-buffer-local-defs)
528 (if (not (and (eq flyspell-dash-dictionary ispell-dictionary)
529 (eq flyspell-dash-local-dictionary ispell-local-dictionary)))
530 ;; the dictionary has changed
532 (setq flyspell-dash-dictionary ispell-dictionary)
533 (setq flyspell-dash-local-dictionary ispell-local-dictionary)
534 (if (member (or ispell-local-dictionary ispell-dictionary)
535 flyspell-dictionaries-that-consider-dash-as-word-delimiter)
536 (setq flyspell-consider-dash-as-word-delimiter-flag t)
537 (setq flyspell-consider-dash-as-word-delimiter-flag nil)))))
539 ;*---------------------------------------------------------------------*/
540 ;* flyspell-mode-on ... */
541 ;*---------------------------------------------------------------------*/
542 (defun flyspell-mode-on ()
543 "Turn Flyspell mode on. Do not use this; use `flyspell-mode' instead."
544 (setq ispell-highlight-face 'flyspell-incorrect-face)
545 ;; local dictionaries setup
546 (ispell-change-dictionary
547 (or ispell-local-dictionary ispell-dictionary flyspell-default-dictionary))
548 ;; we have to force ispell to accept the local definition or
549 ;; otherwise it could be too late, the local dictionary may
551 (flyspell-accept-buffer-local-defs)
552 ;; we put the `flyspel-delayed' property on some commands
553 (flyspell-delay-commands)
554 ;; we put the `flyspel-deplacement' property on some commands
555 (flyspell-deplacement-commands)
556 ;; we bound flyspell action to post-command hook
557 (add-hook 'post-command-hook (function flyspell-post-command-hook) t t)
558 ;; we bound flyspell action to pre-command hook
559 (add-hook 'pre-command-hook (function flyspell-pre-command-hook) t t)
560 ;; we bound flyspell action to after-change hook
561 (make-local-variable 'after-change-functions)
562 (setq after-change-functions
563 (cons 'flyspell-after-change-function after-change-functions))
564 ;; set flyspell-generic-check-word-p based on the major mode
565 (let ((mode-predicate (get major-mode 'flyspell-mode-predicate)))
567 (setq flyspell-generic-check-word-p mode-predicate)))
568 ;; the welcome message
569 (if (and flyspell-issue-message-flag
570 flyspell-issue-welcome-flag
572 (let ((binding (where-is-internal 'flyspell-auto-correct-word
576 (format "Welcome to flyspell. Use %s or Mouse-2 to correct words."
577 (key-description binding))
578 "Welcome to flyspell. Use Mouse-2 to correct words."))))
579 ;; we end with the flyspell hooks
580 (run-hooks 'flyspell-mode-hook))
582 ;*---------------------------------------------------------------------*/
583 ;* flyspell-delay-commands ... */
584 ;*---------------------------------------------------------------------*/
585 (defun flyspell-delay-commands ()
586 "Install the standard set of Flyspell delayed commands."
587 (mapcar 'flyspell-delay-command flyspell-default-delayed-commands)
588 (mapcar 'flyspell-delay-command flyspell-delayed-commands))
590 ;*---------------------------------------------------------------------*/
591 ;* flyspell-delay-command ... */
592 ;*---------------------------------------------------------------------*/
593 (defun flyspell-delay-command (command)
594 "Set COMMAND to be delayed, for Flyspell.
595 When flyspell `post-command-hook' is invoked because a delayed command
596 as been used the current word is not immediately checked.
597 It will be checked only after `flyspell-delay' seconds."
598 (interactive "SDelay Flyspell after Command: ")
599 (put command 'flyspell-delayed t))
601 ;*---------------------------------------------------------------------*/
602 ;* flyspell-deplacement-commands ... */
603 ;*---------------------------------------------------------------------*/
604 (defun flyspell-deplacement-commands ()
605 "Install the standard set of Flyspell deplacement commands."
606 (mapcar 'flyspell-deplacement-command flyspell-default-deplacement-commands)
607 (mapcar 'flyspell-deplacement-command flyspell-deplacement-commands))
609 ;*---------------------------------------------------------------------*/
610 ;* flyspell-deplacement-command ... */
611 ;*---------------------------------------------------------------------*/
612 (defun flyspell-deplacement-command (command)
613 "Set COMMAND that implement cursor movements, for Flyspell.
614 When flyspell `post-command-hook' is invoked because of a deplacement command
615 as been used the current word is checked only if the previous command was
616 not the very same deplacement command."
617 (interactive "SDeplacement Flyspell after Command: ")
618 (put command 'flyspell-deplacement t))
620 ;*---------------------------------------------------------------------*/
621 ;* flyspell-word-cache ... */
622 ;*---------------------------------------------------------------------*/
623 (defvar flyspell-word-cache-start nil)
624 (defvar flyspell-word-cache-end nil)
625 (defvar flyspell-word-cache-word nil)
626 (make-variable-buffer-local 'flyspell-word-cache-start)
627 (make-variable-buffer-local 'flyspell-word-cache-end)
628 (make-variable-buffer-local 'flyspell-word-cache-word)
630 ;*---------------------------------------------------------------------*/
631 ;* The flyspell pre-hook, store the current position. In the */
632 ;* post command hook, we will check, if the word at this position */
633 ;* has to be spell checked. */
634 ;*---------------------------------------------------------------------*/
635 (defvar flyspell-pre-buffer nil)
636 (defvar flyspell-pre-point nil)
637 (defvar flyspell-pre-column nil)
638 (defvar flyspell-pre-pre-buffer nil)
639 (defvar flyspell-pre-pre-point nil)
641 ;*---------------------------------------------------------------------*/
642 ;* flyspell-previous-command ... */
643 ;*---------------------------------------------------------------------*/
644 (defvar flyspell-previous-command nil
645 "The last interactive command checked by Flyspell.")
647 ;*---------------------------------------------------------------------*/
648 ;* flyspell-pre-command-hook ... */
649 ;*---------------------------------------------------------------------*/
650 (defun flyspell-pre-command-hook ()
651 "Save the current buffer and point for Flyspell's post-command hook."
653 (setq flyspell-pre-buffer (current-buffer))
654 (setq flyspell-pre-point (point))
655 (setq flyspell-pre-column (current-column)))
657 ;*---------------------------------------------------------------------*/
658 ;* flyspell-mode-off ... */
659 ;*---------------------------------------------------------------------*/
661 (defun flyspell-mode-off ()
662 "Turn Flyspell mode off."
663 ;; we remove the hooks
664 (remove-hook 'post-command-hook (function flyspell-post-command-hook) t)
665 (remove-hook 'pre-command-hook (function flyspell-pre-command-hook) t)
666 (setq after-change-functions (delq 'flyspell-after-change-function
667 after-change-functions))
668 ;; we remove all the flyspell hilightings
669 (flyspell-delete-all-overlays)
670 ;; we have to erase pre cache variables
671 (setq flyspell-pre-buffer nil)
672 (setq flyspell-pre-point nil)
673 ;; we mark the mode as killed
674 (setq flyspell-mode nil))
676 ;*---------------------------------------------------------------------*/
677 ;* flyspell-check-pre-word-p ... */
678 ;*---------------------------------------------------------------------*/
679 (defun flyspell-check-pre-word-p ()
680 "Return non-nil if we should to check the word before point.
681 More precisely, it applies to the word that was before point
682 before the current command."
684 ((or (not (numberp flyspell-pre-point))
685 (not (bufferp flyspell-pre-buffer))
686 (not (buffer-live-p flyspell-pre-buffer)))
688 ((and (eq flyspell-pre-pre-point flyspell-pre-point)
689 (eq flyspell-pre-pre-buffer flyspell-pre-buffer))
691 ((or (and (= flyspell-pre-point (- (point) 1))
692 (eq (char-syntax (char-after flyspell-pre-point)) ?w))
693 (= flyspell-pre-point (point))
694 (= flyspell-pre-point (+ (point) 1)))
696 ((and (symbolp this-command)
697 (not executing-kbd-macro)
698 (or (get this-command 'flyspell-delayed)
699 (and (get this-command 'flyspell-deplacement)
700 (eq flyspell-previous-command this-command)))
701 (or (= (current-column) 0)
702 (= (current-column) flyspell-pre-column)
703 (eq (char-syntax (char-after flyspell-pre-point)) ?w)))
705 ((not (eq (current-buffer) flyspell-pre-buffer))
707 ((not (and (numberp flyspell-word-cache-start)
708 (numberp flyspell-word-cache-end)))
711 (or (< flyspell-pre-point flyspell-word-cache-start)
712 (> flyspell-pre-point flyspell-word-cache-end)))))
714 ;*---------------------------------------------------------------------*/
715 ;* The flyspell after-change-hook, store the change position. In */
716 ;* the post command hook, we will check, if the word at this */
717 ;* position has to be spell checked. */
718 ;*---------------------------------------------------------------------*/
719 (defvar flyspell-changes nil)
721 ;*---------------------------------------------------------------------*/
722 ;* flyspell-after-change-function ... */
723 ;*---------------------------------------------------------------------*/
724 (defun flyspell-after-change-function (start stop len)
725 "Save the current buffer and point for Flyspell's post-command hook."
727 (setq flyspell-changes (cons (cons start stop) flyspell-changes)))
729 ;*---------------------------------------------------------------------*/
730 ;* flyspell-check-changed-word-p ... */
731 ;*---------------------------------------------------------------------*/
732 (defun flyspell-check-changed-word-p (start stop)
733 "Return t when the changed word has to be checked.
734 The answer depends of several criteria.
735 Mostly we check word delimiters."
737 ((and (eq (char-after start) ?\n) (> stop start))
739 ((not (numberp flyspell-pre-point))
741 ((and (>= flyspell-pre-point start) (<= flyspell-pre-point stop))
743 ((let ((pos (point)))
744 (or (>= pos start) (<= pos stop) (= pos (1+ stop))))
749 ;*---------------------------------------------------------------------*/
750 ;* flyspell-check-word-p ... */
751 ;*---------------------------------------------------------------------*/
752 (defun flyspell-check-word-p ()
753 "Return t when the word at `point' has to be checked.
754 The answer depends of several criteria.
755 Mostly we check word delimiters."
757 ((<= (- (point-max) 1) (point-min))
758 ;; the buffer is not filled enough
760 ((and (and (> (current-column) 0)
761 (not (eq (current-column) flyspell-pre-column)))
764 (and (looking-at (flyspell-get-not-casechars))
765 (or flyspell-consider-dash-as-word-delimiter-flag
766 (not (looking-at "\\-"))))))
767 ;; yes because we have reached or typed a word delimiter.
769 ((symbolp this-command)
771 ((get this-command 'flyspell-deplacement)
772 (not (eq flyspell-previous-command this-command)))
773 ((get this-command 'flyspell-delayed)
774 ;; the current command is not delayed, that
775 ;; is that we must check the word now
776 (if (fboundp 'about-xemacs)
777 (sit-for flyspell-delay nil)
778 (sit-for flyspell-delay 0 nil)))
782 ;*---------------------------------------------------------------------*/
783 ;* flyspell-debug-signal-no-check ... */
784 ;*---------------------------------------------------------------------*/
785 (defun flyspell-debug-signal-no-check (msg obj)
786 (setq debug-on-error t)
788 (let ((buffer (get-buffer-create "*flyspell-debug*")))
791 (insert "NO-CHECK:\n")
792 (insert (format " %S : %S\n" msg obj)))))
794 ;*---------------------------------------------------------------------*/
795 ;* flyspell-debug-signal-pre-word-checked ... */
796 ;*---------------------------------------------------------------------*/
797 (defun flyspell-debug-signal-pre-word-checked ()
798 (setq debug-on-error t)
800 (let ((buffer (get-buffer-create "*flyspell-debug*")))
802 (insert "PRE-WORD:\n")
803 (insert (format " pre-point : %S\n" flyspell-pre-point))
804 (insert (format " pre-buffer : %S\n" flyspell-pre-buffer))
805 (insert (format " cache-start: %S\n" flyspell-word-cache-start))
806 (insert (format " cache-end : %S\n" flyspell-word-cache-end))
807 (goto-char (point-max)))))
809 ;*---------------------------------------------------------------------*/
810 ;* flyspell-debug-signal-word-checked ... */
811 ;*---------------------------------------------------------------------*/
812 (defun flyspell-debug-signal-word-checked ()
813 (setq debug-on-error t)
815 (let ((oldbuf (current-buffer))
816 (buffer (get-buffer-create "*flyspell-debug*"))
820 (insert (format " this-cmd : %S\n" this-command))
821 (insert (format " delayed : %S\n" (and (symbolp this-command)
822 (get this-command 'flyspell-delayed))))
823 (insert (format " point : %S\n" point))
824 (insert (format " prev-char : [%c] %S\n"
827 (let ((c (if (> (point) (point-min))
830 (char-after (point)))
836 (let ((c (if (> (point) (point-min))
839 (and (and (looking-at (flyspell-get-not-casechars)) 1)
840 (and (or flyspell-consider-dash-as-word-delimiter-flag
841 (not (looking-at "\\-"))) 2))))))
844 (insert (format " because : %S\n"
846 ((not (and (symbolp this-command)
847 (get this-command 'flyspell-delayed)))
848 ;; the current command is not delayed, that
849 ;; is that we must check the word now
853 (let ((c (if (> (point) (point-min))
856 (and (looking-at (flyspell-get-not-casechars))
857 (or flyspell-consider-dash-as-word-delimiter-flag
858 (not (looking-at "\\-"))))))))
861 ;; yes because we have reached or typed a word delimiter.
863 ((not (integerp flyspell-delay))
864 ;; yes because the user had set up a no-delay configuration.
868 (goto-char (point-max)))))
870 ;*---------------------------------------------------------------------*/
871 ;* flyspell-debug-signal-changed-checked ... */
872 ;*---------------------------------------------------------------------*/
873 (defun flyspell-debug-signal-changed-checked ()
874 (setq debug-on-error t)
876 (let ((buffer (get-buffer-create "*flyspell-debug*"))
879 (insert "CHANGED WORD:\n")
880 (insert (format " point : %S\n" point))
881 (goto-char (point-max)))))
883 ;*---------------------------------------------------------------------*/
884 ;* flyspell-post-command-hook ... */
885 ;* ------------------------------------------------------------- */
886 ;* It is possible that we check several words: */
887 ;* 1- the current word is checked if the predicate */
888 ;* FLYSPELL-CHECK-WORD-P is true */
889 ;* 2- the word that used to be the current word before the */
890 ;* THIS-COMMAND is checked if: */
891 ;* a- the previous word is different from the current word */
892 ;* b- the previous word as not just been checked by the */
893 ;* previous FLYSPELL-POST-COMMAND-HOOK */
894 ;* 3- the words changed by the THIS-COMMAND that are neither the */
895 ;* previous word nor the current word */
896 ;*---------------------------------------------------------------------*/
897 (defun flyspell-post-command-hook ()
898 "The `post-command-hook' used by flyspell to check a word in-the-fly."
900 (let ((command this-command))
901 (if (flyspell-check-pre-word-p)
903 '(flyspell-debug-signal-pre-word-checked)
904 (set-buffer flyspell-pre-buffer)
906 (goto-char flyspell-pre-point)
908 (if (flyspell-check-word-p)
910 '(flyspell-debug-signal-word-checked)
912 ;; we remember which word we have just checked.
913 ;; this will be used next time we will check a word
914 ;; to compare the next current word with the word
915 ;; that as been registered in the pre-command-hook
916 ;; that is these variables are used within the predicate
917 ;; FLYSPELL-CHECK-PRE-WORD-P
918 (setq flyspell-pre-pre-buffer (current-buffer))
919 (setq flyspell-pre-pre-point (point)))
921 (setq flyspell-pre-pre-buffer nil)
922 (setq flyspell-pre-pre-point nil)
923 ;; when a word is not checked because of a delayed command
924 ;; we do not disable the ispell cache.
925 (if (and (symbolp this-command) (get this-command 'flyspell-delayed))
926 (setq flyspell-word-cache-end -1))))
927 (while (consp flyspell-changes)
928 (let ((start (car (car flyspell-changes)))
929 (stop (cdr (car flyspell-changes))))
930 (if (flyspell-check-changed-word-p start stop)
932 '(flyspell-debug-signal-changed-checked)
935 (setq flyspell-changes (cdr flyspell-changes))))
936 (setq flyspell-previous-command command)))
938 ;*---------------------------------------------------------------------*/
939 ;* flyspell-notify-misspell ... */
940 ;*---------------------------------------------------------------------*/
941 (defun flyspell-notify-misspell (start end word poss)
942 (let ((replacements (if (stringp poss)
944 (if flyspell-sort-corrections
945 (sort (car (cdr (cdr poss))) 'string<)
946 (car (cdr (cdr poss)))))))
947 (if flyspell-issue-message-flag
948 (message (format "mispelling `%s' %S" word replacements)))))
950 ;*---------------------------------------------------------------------*/
951 ;* flyspell-word ... */
952 ;*---------------------------------------------------------------------*/
953 (defun flyspell-word (&optional following)
954 "Spell check a word."
955 (interactive (list current-prefix-arg))
957 (setq following ispell-following-word))
959 ;; use the correct dictionary
960 (flyspell-accept-buffer-local-defs)
961 (let* ((cursor-location (point))
962 (flyspell-word (flyspell-get-word following))
964 (if (or (eq flyspell-word nil)
965 (and (fboundp flyspell-generic-check-word-p)
966 (not (funcall flyspell-generic-check-word-p))))
969 ;; destructure return flyspell-word info list.
970 (setq start (car (cdr flyspell-word))
971 end (car (cdr (cdr flyspell-word)))
972 word (car flyspell-word))
973 ;; before checking in the directory, we check for doublons.
975 ((and (or (not (eq ispell-parser 'tex))
976 (not (eq (char-after start) ?\\)))
977 flyspell-mark-duplications-flag
980 (word-search-backward word
984 ;; yes, this is a doublon
985 (flyspell-highlight-incorrect-region start end 'doublon))
986 ((and (eq flyspell-word-cache-start start)
987 (eq flyspell-word-cache-end end)
988 (string-equal flyspell-word-cache-word word))
989 ;; this word had been already checked, we skip
991 ((and (eq ispell-parser 'tex)
992 (flyspell-tex-command-p flyspell-word))
993 ;; this is a correct word (because a tex command)
994 (flyspell-unhighlight-at start)
996 (flyspell-unhighlight-at (- end 1)))
999 ;; we setup the cache
1000 (setq flyspell-word-cache-start start)
1001 (setq flyspell-word-cache-end end)
1002 (setq flyspell-word-cache-word word)
1003 ;; now check spelling of word.
1004 (process-send-string ispell-process "%\n")
1005 ;; put in verbose mode
1006 (process-send-string ispell-process
1007 (concat "^" word "\n"))
1008 ;; we mark the ispell process so it can be killed
1009 ;; when emacs is exited without query
1010 (if (fboundp 'process-kill-without-query)
1011 (process-kill-without-query ispell-process))
1012 ;; wait until ispell has processed word
1014 (accept-process-output ispell-process)
1015 (not (string= "" (car ispell-filter)))))
1016 ;; (process-send-string ispell-process "!\n")
1017 ;; back to terse mode.
1018 (setq ispell-filter (cdr ispell-filter))
1019 (if (consp ispell-filter)
1020 (setq poss (ispell-parse-output (car ispell-filter))))
1023 (flyspell-unhighlight-at start)
1025 (flyspell-unhighlight-at (- end 1)))
1027 ((and (stringp poss) flyspell-highlight-flag)
1029 (flyspell-unhighlight-at start)
1031 (flyspell-unhighlight-at (- end 1)))
1034 (flyspell-unhighlight-at start)
1036 (flyspell-unhighlight-at (- end 1))))
1037 ((or (and (< flyspell-duplicate-distance 0)
1040 (word-search-backward word
1045 (word-search-forward word
1048 (and (> flyspell-duplicate-distance 0)
1051 (word-search-backward
1054 flyspell-duplicate-distance)
1058 (word-search-forward
1061 flyspell-duplicate-distance)
1063 (if flyspell-highlight-flag
1064 (flyspell-highlight-duplicate-region start end)
1065 (message (format "duplicate `%s'" word))))
1067 ;; incorrect highlight the location
1068 (if flyspell-highlight-flag
1069 (flyspell-highlight-incorrect-region start end poss)
1070 (flyspell-notify-misspell start end word poss))))
1071 ;; return to original location
1072 (goto-char cursor-location)
1073 (if ispell-quit (setq ispell-quit nil)))))))))
1075 ;*---------------------------------------------------------------------*/
1076 ;* flyspell-tex-math-initialized ... */
1077 ;*---------------------------------------------------------------------*/
1078 (defvar flyspell-tex-math-initialized nil)
1080 ;*---------------------------------------------------------------------*/
1081 ;* flyspell-math-tex-command-p ... */
1082 ;* ------------------------------------------------------------- */
1083 ;* This function uses the texmathp package to check if (point) */
1084 ;* is within a tex command. In order to avoid using */
1085 ;* condition-case each time we use the variable */
1086 ;* flyspell-tex-math-initialized to make a special case the first */
1087 ;* time that function is called. */
1088 ;*---------------------------------------------------------------------*/
1089 (defun flyspell-math-tex-command-p ()
1091 (flyspell-check-tex-math-command
1093 ((eq flyspell-tex-math-initialized t)
1095 ((eq flyspell-tex-math-initialized 'error)
1098 (setq flyspell-tex-math-initialized t)
1102 (setq flyspell-tex-math-initialized 'error)
1105 ;*---------------------------------------------------------------------*/
1106 ;* flyspell-tex-command-p ... */
1107 ;*---------------------------------------------------------------------*/
1108 (defun flyspell-tex-command-p (word)
1109 "Return t if WORD is a TeX command."
1111 (let ((b (car (cdr word))))
1112 (and (re-search-backward "\\\\" (- (point) 100) t)
1113 (or (= (match-end 0) b)
1114 (and (goto-char (match-end 0))
1115 (looking-at flyspell-tex-command-regexp)
1116 (>= (match-end 0) b))))))
1117 (flyspell-math-tex-command-p)))
1119 ;*---------------------------------------------------------------------*/
1120 ;* flyspell-casechars-cache ... */
1121 ;*---------------------------------------------------------------------*/
1122 (defvar flyspell-casechars-cache nil)
1123 (defvar flyspell-ispell-casechars-cache nil)
1124 (make-variable-buffer-local 'flyspell-casechars-cache)
1125 (make-variable-buffer-local 'flyspell-ispell-casechars-cache)
1127 ;*---------------------------------------------------------------------*/
1128 ;* flyspell-get-casechars ... */
1129 ;*---------------------------------------------------------------------*/
1130 (defun flyspell-get-casechars ()
1131 "This function builds a string that is the regexp of word chars.
1132 In order to avoid one useless string construction,
1133 this function changes the last char of the `ispell-casechars' string."
1134 (let ((ispell-casechars (ispell-get-casechars)))
1136 ((eq ispell-parser 'tex)
1137 (setq flyspell-ispell-casechars-cache ispell-casechars)
1138 (setq flyspell-casechars-cache
1139 (concat (substring ispell-casechars
1141 (- (length ispell-casechars) 1))
1143 flyspell-casechars-cache)
1145 (setq flyspell-ispell-casechars-cache ispell-casechars)
1146 (setq flyspell-casechars-cache ispell-casechars)
1147 flyspell-casechars-cache))))
1149 ;*---------------------------------------------------------------------*/
1150 ;* flyspell-get-not-casechars-cache ... */
1151 ;*---------------------------------------------------------------------*/
1152 (defvar flyspell-not-casechars-cache nil)
1153 (defvar flyspell-ispell-not-casechars-cache nil)
1154 (make-variable-buffer-local 'flyspell-not-casechars-cache)
1155 (make-variable-buffer-local 'flyspell-ispell-not-casechars-cache)
1157 ;*---------------------------------------------------------------------*/
1158 ;* flyspell-get-not-casechars ... */
1159 ;*---------------------------------------------------------------------*/
1160 (defun flyspell-get-not-casechars ()
1161 "This function builds a string that is the regexp of non-word chars."
1162 (let ((ispell-not-casechars (ispell-get-not-casechars)))
1164 ((eq ispell-parser 'tex)
1165 (setq flyspell-ispell-not-casechars-cache ispell-not-casechars)
1166 (setq flyspell-not-casechars-cache
1167 (concat (substring ispell-not-casechars
1169 (- (length ispell-not-casechars) 1))
1171 flyspell-not-casechars-cache)
1173 (setq flyspell-ispell-not-casechars-cache ispell-not-casechars)
1174 (setq flyspell-not-casechars-cache ispell-not-casechars)
1175 flyspell-not-casechars-cache))))
1177 ;*---------------------------------------------------------------------*/
1178 ;* flyspell-get-word ... */
1179 ;*---------------------------------------------------------------------*/
1180 (defun flyspell-get-word (following)
1181 "Return the word for spell-checking according to Ispell syntax.
1182 If argument FOLLOWING is non-nil or if `ispell-following-word'
1183 is non-nil when called interactively, then the following word
1184 \(rather than preceding\) is checked when the cursor is not over a word.
1185 Optional second argument contains other chars that can be included in word
1188 Word syntax described by `ispell-dictionary-alist' (which see)."
1189 (let* ((flyspell-casechars (flyspell-get-casechars))
1190 (flyspell-not-casechars (flyspell-get-not-casechars))
1191 (ispell-otherchars (ispell-get-otherchars))
1192 (ispell-many-otherchars-p (ispell-get-many-otherchars-p))
1193 (word-regexp (if (string< "" ispell-otherchars)
1194 (concat flyspell-casechars
1200 (if ispell-many-otherchars-p
1202 (concat flyspell-casechars "+")))
1206 (if (not (looking-at flyspell-casechars))
1208 (re-search-forward flyspell-casechars (point-max) t)
1209 (re-search-backward flyspell-casechars (point-min) t)))
1210 ;; move to front of word
1211 (re-search-backward flyspell-not-casechars (point-min) 'start)
1213 (if (string< "" ispell-otherchars)
1214 (while (and (looking-at ispell-otherchars)
1216 (or (not did-it-once)
1217 ispell-many-otherchars-p)
1218 (not (eq pos (point))))
1220 (setq did-it-once t)
1222 (if (looking-at flyspell-casechars)
1223 (re-search-backward flyspell-not-casechars (point-min) 'move)
1224 (backward-char -1)))))
1225 ;; Now mark the word and save to string.
1226 (if (eq (re-search-forward word-regexp (point-max) t) nil)
1229 (setq start (match-beginning 0)
1231 word (buffer-substring-no-properties start end))
1232 (list word start end)))))
1234 ;*---------------------------------------------------------------------*/
1235 ;* flyspell-small-region ... */
1236 ;*---------------------------------------------------------------------*/
1237 (defun flyspell-small-region (beg end)
1238 "Flyspell text between BEG and END."
1246 (while (< (point) end)
1247 (if (and flyspell-issue-message-flag (= count 100))
1249 (message "Spell Checking...%d%%"
1250 (* 100 (/ (float (- (point) beg)) (- end beg))))
1252 (setq count (+ 1 count)))
1255 (let ((cur (point)))
1257 (if (and (< (point) end) (> (point) (+ cur 1)))
1258 (backward-char 1)))))
1260 (if flyspell-issue-message-flag (message "Spell Checking completed."))
1263 ;*---------------------------------------------------------------------*/
1264 ;* flyspell-external-ispell-process ... */
1265 ;*---------------------------------------------------------------------*/
1266 (defvar flyspell-external-ispell-process '()
1267 "The external Flyspell Ispell process.")
1269 ;*---------------------------------------------------------------------*/
1270 ;* flyspell-external-ispell-buffer ... */
1271 ;*---------------------------------------------------------------------*/
1272 (defvar flyspell-external-ispell-buffer '())
1273 (defvar flyspell-large-region-buffer '())
1274 (defvar flyspell-large-region-beg (point-min))
1275 (defvar flyspell-large-region-end (point-max))
1277 ;*---------------------------------------------------------------------*/
1278 ;* flyspell-external-point-words ... */
1279 ;*---------------------------------------------------------------------*/
1280 (defun flyspell-external-point-words ()
1281 (let ((buffer flyspell-external-ispell-buffer))
1283 (beginning-of-buffer)
1284 (let ((size (- flyspell-large-region-end flyspell-large-region-beg))
1285 (start flyspell-large-region-beg))
1286 ;; now we are done with ispell, we have to find the word in
1287 ;; the initial buffer
1288 (while (< (point) (- (point-max) 1))
1289 ;; we have to fetch the incorrect word
1290 (if (re-search-forward "\\([^\n]+\\)\n" (point-max) t)
1291 (let ((word (match-string 1)))
1292 (goto-char (match-end 0))
1293 (set-buffer flyspell-large-region-buffer)
1294 (goto-char flyspell-large-region-beg)
1295 (if flyspell-issue-message-flag
1296 (message "Spell Checking...%d%% [%s]"
1297 (* 100 (/ (float (- (point) start)) size))
1299 (if (search-forward word flyspell-large-region-end t)
1301 (setq flyspell-large-region-beg (point))
1302 (goto-char (- (point) 1))
1304 (set-buffer buffer))
1305 (goto-char (point-max)))))
1307 (if flyspell-issue-message-flag (message "Spell Checking completed."))
1308 ;; ok, we are done with pointing out incorrect words, we just
1309 ;; have to kill the temporary buffer
1310 (kill-buffer flyspell-external-ispell-buffer)
1311 (setq flyspell-external-ispell-buffer nil)))
1313 ;*---------------------------------------------------------------------*/
1314 ;* flyspell-large-region ... */
1315 ;*---------------------------------------------------------------------*/
1316 (defun flyspell-large-region (beg end)
1317 (let* ((curbuf (current-buffer))
1318 (buffer (get-buffer-create "*flyspell-region*")))
1319 (setq flyspell-external-ispell-buffer buffer)
1320 (setq flyspell-large-region-buffer curbuf)
1321 (setq flyspell-large-region-beg beg)
1322 (setq flyspell-large-region-end end)
1325 ;; this is done, we can start checking...
1326 (if flyspell-issue-message-flag (message "Checking region..."))
1328 (let ((c (apply 'call-process-region beg
1336 ;; Local dictionary becomes the global dictionary in use.
1337 (if ispell-local-dictionary
1338 (setq ispell-dictionary ispell-local-dictionary))
1339 (setq args (ispell-get-ispell-args))
1340 (if ispell-dictionary ; use specified dictionary
1342 (append (list "-d" ispell-dictionary) args)))
1343 (if ispell-personal-dictionary ; use specified pers dict
1348 ispell-personal-dictionary)))))
1349 (setq args (append args ispell-extra-args))
1352 (flyspell-external-point-words)
1353 (error "Can't check region...")))))
1355 ;*---------------------------------------------------------------------*/
1356 ;* flyspell-region ... */
1357 ;* ------------------------------------------------------------- */
1358 ;* Because `ispell -a' is too slow, it is not possible to use */
1359 ;* it on large region. Then, when ispell is invoked on a large */
1360 ;* text region, a new `ispell -l' process is spawned. The */
1361 ;* pointed out words are then searched in the region a checked with */
1362 ;* regular flyspell means. */
1363 ;*---------------------------------------------------------------------*/
1365 (defun flyspell-region (beg end)
1366 "Flyspell text between BEG and END."
1375 (if (> (- end beg) flyspell-large-region)
1376 (flyspell-large-region beg end)
1377 (flyspell-small-region beg end)))))
1379 ;*---------------------------------------------------------------------*/
1380 ;* flyspell-buffer ... */
1381 ;*---------------------------------------------------------------------*/
1383 (defun flyspell-buffer ()
1384 "Flyspell whole buffer."
1386 (flyspell-region (point-min) (point-max)))
1388 ;*---------------------------------------------------------------------*/
1389 ;* old next error position ... */
1390 ;*---------------------------------------------------------------------*/
1391 (defvar flyspell-old-buffer-error nil)
1392 (defvar flyspell-old-pos-error nil)
1394 ;*---------------------------------------------------------------------*/
1395 ;* flyspell-goto-next-error ... */
1396 ;*---------------------------------------------------------------------*/
1397 (defun flyspell-goto-next-error ()
1398 "Go to the next previously detected error.
1399 In general FLYSPELL-GOTO-NEXT-ERROR must be used after
1404 (if (and (eq (current-buffer) flyspell-old-buffer-error)
1405 (eq pos flyspell-old-pos-error))
1407 (if (= flyspell-old-pos-error max)
1408 ;; goto beginning of buffer
1410 (message "Restarting from beginning of buffer")
1411 (goto-char (point-min)))
1413 (setq pos (point))))
1414 ;; seek the next error
1415 (while (and (< pos max)
1416 (let ((ovs (overlays-at pos))
1418 (while (and (not r) (consp ovs))
1419 (if (flyspell-overlay-p (car ovs))
1421 (setq ovs (cdr ovs))))
1423 (setq pos (1+ pos)))
1424 ;; save the current location for next invocation
1425 (setq flyspell-old-pos-error pos)
1426 (setq flyspell-old-buffer-error (current-buffer))
1429 (message "No more miss-spelled word!"))))
1431 ;*---------------------------------------------------------------------*/
1432 ;* flyspell-overlay-p ... */
1433 ;*---------------------------------------------------------------------*/
1434 (defun flyspell-overlay-p (o)
1435 "A predicate that return true iff O is an overlay used by flyspell."
1436 (and (overlayp o) (overlay-get o 'flyspell-overlay)))
1438 ;*---------------------------------------------------------------------*/
1439 ;* flyspell-delete-all-overlays ... */
1440 ;* ------------------------------------------------------------- */
1441 ;* Remove all the overlays introduced by flyspell. */
1442 ;*---------------------------------------------------------------------*/
1443 (defun flyspell-delete-all-overlays ()
1444 "Delete all the overlays used by flyspell."
1445 (let ((l (overlays-in (point-min) (point-max))))
1448 (if (flyspell-overlay-p (car l))
1449 (delete-overlay (car l)))
1450 (setq l (cdr l))))))
1452 ;*---------------------------------------------------------------------*/
1453 ;* flyspell-unhighlight-at ... */
1454 ;*---------------------------------------------------------------------*/
1455 (defun flyspell-unhighlight-at (pos)
1456 "Remove the flyspell overlay that are located at POS."
1457 (if flyspell-persistent-highlight
1458 (let ((overlays (overlays-at pos)))
1459 (while (consp overlays)
1460 (if (flyspell-overlay-p (car overlays))
1461 (delete-overlay (car overlays)))
1462 (setq overlays (cdr overlays))))
1463 (if (flyspell-overlay-p flyspell-overlay)
1464 (delete-overlay flyspell-overlay))))
1466 ;*---------------------------------------------------------------------*/
1467 ;* flyspell-properties-at-p ... */
1468 ;* ------------------------------------------------------------- */
1469 ;* Is there an highlight properties at position pos? */
1470 ;*---------------------------------------------------------------------*/
1471 (defun flyspell-properties-at-p (pos)
1472 "Return t if there is a text property at POS, not counting `local-map'.
1473 If variable `flyspell-highlight-properties' is set to nil,
1474 text with properties are not checked. This function is used to discover
1475 if the character at POS has any other property."
1476 (let ((prop (text-properties-at pos))
1478 (while (and keep (consp prop))
1479 (if (and (eq (car prop) 'local-map) (consp (cdr prop)))
1480 (setq prop (cdr (cdr prop)))
1484 ;*---------------------------------------------------------------------*/
1485 ;* make-flyspell-overlay ... */
1486 ;*---------------------------------------------------------------------*/
1487 (defun make-flyspell-overlay (beg end face mouse-face)
1488 "Allocate an overlay to highlight an incorrect word.
1489 BEG and END specify the range in the buffer of that word.
1490 FACE and MOUSE-FACE specify the `face' and `mouse-face' properties
1492 (let ((flyspell-overlay (make-overlay beg end nil t nil)))
1493 (overlay-put flyspell-overlay 'face face)
1494 (overlay-put flyspell-overlay 'mouse-face mouse-face)
1495 (overlay-put flyspell-overlay 'flyspell-overlay t)
1496 (overlay-put flyspell-overlay 'evaporate t)
1497 (if flyspell-use-local-map
1498 (overlay-put flyspell-overlay
1499 flyspell-overlay-keymap-property-name
1500 flyspell-mouse-map))
1501 (when (eq face 'flyspell-incorrect-face)
1502 (and (stringp flyspell-before-incorrect-word-string)
1503 (overlay-put flyspell-overlay 'before-string
1504 flyspell-before-incorrect-word-string))
1505 (and (stringp flyspell-after-incorrect-word-string)
1506 (overlay-put flyspell-overlay 'after-string
1507 flyspell-after-incorrect-word-string)))
1510 ;*---------------------------------------------------------------------*/
1511 ;* flyspell-highlight-incorrect-region ... */
1512 ;*---------------------------------------------------------------------*/
1513 (defun flyspell-highlight-incorrect-region (beg end poss)
1514 "Set up an overlay on a misspelled word, in the buffer from BEG to END."
1515 (unless (run-hook-with-args-until-success
1516 'flyspell-incorrect-hook beg end poss)
1517 (if (or flyspell-highlight-properties (not (flyspell-properties-at-p beg)))
1519 ;; we cleanup current overlay at the same position
1520 (if (and (not flyspell-persistent-highlight)
1521 (overlayp flyspell-overlay))
1522 (delete-overlay flyspell-overlay)
1523 (let ((overlays (overlays-at beg)))
1524 (while (consp overlays)
1525 (if (flyspell-overlay-p (car overlays))
1526 (delete-overlay (car overlays)))
1527 (setq overlays (cdr overlays)))))
1528 ;; now we can use a new overlay
1529 (setq flyspell-overlay
1530 (make-flyspell-overlay beg end
1531 'flyspell-incorrect-face
1534 ;*---------------------------------------------------------------------*/
1535 ;* flyspell-highlight-duplicate-region ... */
1536 ;*---------------------------------------------------------------------*/
1537 (defun flyspell-highlight-duplicate-region (beg end)
1538 "Set up an overlay on a duplicated word, in the buffer from BEG to END."
1539 (if (or flyspell-highlight-properties (not (flyspell-properties-at-p beg)))
1541 ;; we cleanup current overlay at the same position
1542 (if (and (not flyspell-persistent-highlight)
1543 (overlayp flyspell-overlay))
1544 (delete-overlay flyspell-overlay)
1545 (let ((overlays (overlays-at beg)))
1546 (while (consp overlays)
1547 (if (flyspell-overlay-p (car overlays))
1548 (delete-overlay (car overlays)))
1549 (setq overlays (cdr overlays)))))
1550 ;; now we can use a new overlay
1551 (setq flyspell-overlay
1552 (make-flyspell-overlay beg end
1553 'flyspell-duplicate-face
1556 ;*---------------------------------------------------------------------*/
1557 ;* flyspell-auto-correct-cache ... */
1558 ;*---------------------------------------------------------------------*/
1559 (defvar flyspell-auto-correct-pos nil)
1560 (defvar flyspell-auto-correct-region nil)
1561 (defvar flyspell-auto-correct-ring nil)
1562 (defvar flyspell-auto-correct-word nil)
1563 (make-variable-buffer-local 'flyspell-auto-correct-pos)
1564 (make-variable-buffer-local 'flyspell-auto-correct-region)
1565 (make-variable-buffer-local 'flyspell-auto-correct-ring)
1566 (make-variable-buffer-local 'flyspell-auto-correct-word)
1568 ;*---------------------------------------------------------------------*/
1569 ;* flyspell-check-previous-highlighted-word ... */
1570 ;*---------------------------------------------------------------------*/
1571 (defun flyspell-check-previous-highlighted-word (&optional arg)
1572 "Correct the closer misspelled word.
1573 This function scans a mis-spelled word before the cursor. If it finds one
1574 it proposes replacement for that word. With prefix arg, count that many
1575 misspelled words backwards."
1577 (let ((pos1 (point))
1579 (arg (if (or (not (numberp arg)) (< arg 1)) 1 arg))
1582 (while (and (setq pos (previous-overlay-change pos))
1585 (if (> pos (point-min))
1587 (setq ovs (overlays-at (1- pos)))
1590 (setq ovs (cdr ovs))
1591 (if (and (overlay-get ov 'flyspell-overlay)
1592 (= 0 (setq arg (1- arg))))
1593 (throw 'exit t)))))))
1597 (error "No word to correct before point"))))
1599 ;*---------------------------------------------------------------------*/
1600 ;* flyspell-display-next-corrections ... */
1601 ;*---------------------------------------------------------------------*/
1602 (defun flyspell-display-next-corrections (corrections)
1603 (let ((string "Corrections:")
1606 (while (< (length string) 80)
1607 (if (equal (car l) flyspell-auto-correct-word)
1608 (setq pos (cons (+ 1 (length string)) pos)))
1609 (setq string (concat string " " (car l)))
1612 (let ((num (car pos)))
1613 (put-text-property num
1614 (+ num (length flyspell-auto-correct-word))
1616 'flyspell-incorrect-face
1618 (setq pos (cdr pos)))
1619 (if (fboundp 'display-message)
1620 (display-message 'no-log string)
1623 ;*---------------------------------------------------------------------*/
1624 ;* flyspell-abbrev-table ... */
1625 ;*---------------------------------------------------------------------*/
1626 (defun flyspell-abbrev-table ()
1627 (if flyspell-use-global-abbrev-table-p
1629 local-abbrev-table))
1631 ;*---------------------------------------------------------------------*/
1632 ;* flyspell-define-abbrev ... */
1633 ;*---------------------------------------------------------------------*/
1634 (defun flyspell-define-abbrev (name expansion)
1635 (let ((table (flyspell-abbrev-table)))
1637 (define-abbrev table name expansion))))
1639 ;*---------------------------------------------------------------------*/
1640 ;* flyspell-auto-correct-word ... */
1641 ;*---------------------------------------------------------------------*/
1642 (defun flyspell-auto-correct-word ()
1643 "Correct the current word.
1644 This command proposes various successive corrections for the current word."
1647 (old-max (point-max)))
1648 ;; use the correct dictionary
1649 (flyspell-accept-buffer-local-defs)
1650 (if (and (eq flyspell-auto-correct-pos pos)
1651 (consp flyspell-auto-correct-region))
1652 ;; we have already been using the function at the same location
1653 (let* ((start (car flyspell-auto-correct-region))
1654 (len (cdr flyspell-auto-correct-region)))
1655 (flyspell-unhighlight-at start)
1656 (delete-region start (+ start len))
1657 (setq flyspell-auto-correct-ring (cdr flyspell-auto-correct-ring))
1658 (let* ((word (car flyspell-auto-correct-ring))
1659 (len (length word)))
1660 (rplacd flyspell-auto-correct-region len)
1662 (if flyspell-abbrev-p
1663 (if (flyspell-already-abbrevp (flyspell-abbrev-table)
1664 flyspell-auto-correct-word)
1665 (flyspell-change-abbrev (flyspell-abbrev-table)
1666 flyspell-auto-correct-word
1668 (flyspell-define-abbrev flyspell-auto-correct-word word)))
1669 (funcall flyspell-insert-function word)
1671 (flyspell-display-next-corrections flyspell-auto-correct-ring))
1672 (flyspell-ajust-cursor-point pos (point) old-max)
1673 (setq flyspell-auto-correct-pos (point)))
1674 ;; fetch the word to be checked
1675 (let ((word (flyspell-get-word nil))
1677 ;; destructure return word info list.
1678 (setq start (car (cdr word))
1679 end (car (cdr (cdr word)))
1681 (setq flyspell-auto-correct-word word)
1682 ;; now check spelling of word.
1683 (process-send-string ispell-process "%\n") ;put in verbose mode
1684 (process-send-string ispell-process (concat "^" word "\n"))
1685 ;; wait until ispell has processed word
1687 (accept-process-output ispell-process)
1688 (not (string= "" (car ispell-filter)))))
1689 (setq ispell-filter (cdr ispell-filter))
1690 (if (consp ispell-filter)
1691 (setq poss (ispell-parse-output (car ispell-filter))))
1692 (cond ((or (eq poss t) (stringp poss))
1693 ;; don't correct word
1697 (error "Ispell: error in Ispell process"))
1699 ;; the word is incorrect, we have to propose a replacement
1700 (let ((replacements (if flyspell-sort-corrections
1701 (sort (car (cdr (cdr poss))) 'string<)
1702 (car (cdr (cdr poss))))))
1703 (setq flyspell-auto-correct-region nil)
1704 (if (consp replacements)
1706 (let ((replace (car replacements)))
1707 (let ((new-word replace))
1708 (if (not (equal new-word (car poss)))
1710 ;; the save the current replacements
1711 (setq flyspell-auto-correct-region
1712 (cons start (length new-word)))
1713 (let ((l replacements))
1714 (while (consp (cdr l))
1716 (rplacd l (cons (car poss) replacements)))
1717 (setq flyspell-auto-correct-ring
1719 (flyspell-unhighlight-at start)
1720 (delete-region start end)
1721 (funcall flyspell-insert-function new-word)
1722 (if flyspell-abbrev-p
1723 (if (flyspell-already-abbrevp
1724 (flyspell-abbrev-table) word)
1725 (flyspell-change-abbrev
1726 (flyspell-abbrev-table)
1729 (flyspell-define-abbrev word new-word)))
1731 (flyspell-display-next-corrections
1732 (cons new-word flyspell-auto-correct-ring))
1733 (flyspell-ajust-cursor-point pos
1736 (setq flyspell-auto-correct-pos (point))
1737 (ispell-pdict-save t)))))
1739 ;*---------------------------------------------------------------------*/
1740 ;* flyspell-auto-correct-previous-pos ... */
1741 ;*---------------------------------------------------------------------*/
1742 (defvar flyspell-auto-correct-previous-pos nil
1743 "Holds the start of the first incorrect word before point.")
1745 ;*---------------------------------------------------------------------*/
1746 ;* flyspell-auto-correct-previous-hook ... */
1747 ;*---------------------------------------------------------------------*/
1748 (defun flyspell-auto-correct-previous-hook ()
1749 "Hook to track successive calls to `flyspell-auto-correct-previous-word'.
1750 Sets flyspell-auto-correct-previous-pos to nil"
1752 (remove-hook 'pre-command-hook (function flyspell-auto-correct-previous-hook) t)
1753 (unless (eq this-command (function flyspell-auto-correct-previous-word))
1754 (setq flyspell-auto-correct-previous-pos nil)))
1756 ;*---------------------------------------------------------------------*/
1757 ;* flyspell-auto-correct-previous-word ... */
1758 ;*---------------------------------------------------------------------*/
1759 (defun flyspell-auto-correct-previous-word (position)
1760 "*Auto correct the first mispelled word that occurs before point."
1763 (add-hook 'pre-command-hook
1764 (function flyspell-auto-correct-previous-hook) t t)
1767 (unless flyspell-auto-correct-previous-pos
1768 ;; only reset if a new overlay exists
1769 (setq flyspell-auto-correct-previous-pos nil)
1771 (let ((overlay-list (overlays-in (point-min) position))
1772 (new-overlay 'dummy-value))
1774 ;; search for previous (new) flyspell overlay
1775 (while (and new-overlay
1776 (or (not (flyspell-overlay-p new-overlay))
1777 ;; check if its face has changed
1778 (not (eq (get-char-property
1779 (overlay-start new-overlay) 'face)
1780 'flyspell-incorrect-face))))
1781 (setq new-overlay (car-safe overlay-list))
1782 (setq overlay-list (cdr-safe overlay-list)))
1784 ;; if nothing new exits new-overlay should be nil
1785 (if new-overlay;; the length of the word may change so go to the start
1786 (setq flyspell-auto-correct-previous-pos
1787 (overlay-start new-overlay)))))
1789 (when flyspell-auto-correct-previous-pos
1791 (goto-char flyspell-auto-correct-previous-pos)
1792 (let ((ispell-following-word t));; point is at start
1793 (if (numberp flyspell-auto-correct-previous-pos)
1794 (goto-char flyspell-auto-correct-previous-pos))
1795 (flyspell-auto-correct-word))
1796 ;; the point may have moved so reset this
1797 (setq flyspell-auto-correct-previous-pos (point))))))
1799 ;*---------------------------------------------------------------------*/
1800 ;* flyspell-correct-word ... */
1801 ;*---------------------------------------------------------------------*/
1802 (defun flyspell-correct-word (event)
1803 "Pop up a menu of possible corrections for a misspelled word.
1804 The word checked is the word at the mouse position."
1806 ;; use the correct dictionary
1807 (flyspell-accept-buffer-local-defs)
1808 ;; retain cursor location (I don't know why but save-excursion here fails).
1809 (let ((save (point)))
1810 (mouse-set-point event)
1811 (let ((cursor-location (point))
1812 (word (flyspell-get-word nil))
1813 start end poss replace)
1814 ;; destructure return word info list.
1815 (setq start (car (cdr word))
1816 end (car (cdr (cdr word)))
1818 ;; now check spelling of word.
1819 (process-send-string ispell-process "%\n") ;put in verbose mode
1820 (process-send-string ispell-process (concat "^" word "\n"))
1821 ;; wait until ispell has processed word
1823 (accept-process-output ispell-process)
1824 (not (string= "" (car ispell-filter)))))
1825 (setq ispell-filter (cdr ispell-filter))
1826 (if (consp ispell-filter)
1827 (setq poss (ispell-parse-output (car ispell-filter))))
1828 (cond ((or (eq poss t) (stringp poss))
1829 ;; don't correct word
1833 (error "Ispell: error in Ispell process"))
1834 ((string-match "GNU" (emacs-version))
1835 ;; the word is incorrect, we have to propose a replacement
1836 (setq replace (flyspell-emacs-popup event poss word))
1837 (cond ((eq replace 'ignore)
1842 (process-send-string ispell-process (concat "*" word "\n"))
1843 (flyspell-unhighlight-at cursor-location)
1844 (setq ispell-pdict-modified-p '(t)))
1845 ((or (eq replace 'buffer) (eq replace 'session))
1846 (process-send-string ispell-process (concat "@" word "\n"))
1847 (if (null ispell-pdict-modified-p)
1848 (setq ispell-pdict-modified-p
1849 (list ispell-pdict-modified-p)))
1850 (flyspell-unhighlight-at cursor-location)
1852 (if (eq replace 'buffer)
1853 (ispell-add-per-file-word-list word)))
1855 (flyspell-unhighlight-at cursor-location)
1856 (let ((new-word (if (atom replace)
1859 (cursor-location (+ (- (length word) (- end start))
1861 (if (not (equal new-word (car poss)))
1862 (let ((old-max (point-max)))
1863 (delete-region start end)
1864 (funcall flyspell-insert-function new-word)
1865 (if flyspell-abbrev-p
1866 (flyspell-define-abbrev word new-word))
1867 (flyspell-ajust-cursor-point save
1873 ((eq flyspell-emacs 'xemacs)
1874 (flyspell-xemacs-popup
1875 event poss word cursor-location start end save)
1877 (ispell-pdict-save t))))
1879 ;*---------------------------------------------------------------------*/
1880 ;* flyspell-xemacs-correct ... */
1881 ;*---------------------------------------------------------------------*/
1882 (defun flyspell-xemacs-correct (replace poss word cursor-location start end save)
1883 "The xemacs popup menu callback."
1884 (cond ((eq replace 'ignore)
1887 (process-send-string ispell-process (concat "*" word "\n"))
1888 (process-send-string ispell-process "#\n")
1889 (flyspell-unhighlight-at cursor-location)
1890 (setq ispell-pdict-modified-p '(t)))
1891 ((or (eq replace 'buffer) (eq replace 'session))
1892 (process-send-string ispell-process (concat "@" word "\n"))
1893 (flyspell-unhighlight-at cursor-location)
1894 (if (null ispell-pdict-modified-p)
1895 (setq ispell-pdict-modified-p
1896 (list ispell-pdict-modified-p)))
1897 (if (eq replace 'buffer)
1898 (ispell-add-per-file-word-list word)))
1900 (let ((old-max (point-max))
1901 (new-word (if (atom replace)
1904 (cursor-location (+ (- (length word) (- end start))
1906 (if (not (equal new-word (car poss)))
1908 (delete-region start end)
1910 (funcall flyspell-insert-function new-word)
1911 (if flyspell-abbrev-p
1912 (flyspell-define-abbrev word new-word))))
1913 (flyspell-ajust-cursor-point save cursor-location old-max)))))
1915 ;*---------------------------------------------------------------------*/
1916 ;* flyspell-ajust-cursor-point ... */
1917 ;*---------------------------------------------------------------------*/
1918 (defun flyspell-ajust-cursor-point (save cursor-location old-max)
1919 (if (>= save cursor-location)
1920 (let ((new-pos (+ save (- (point-max) old-max))))
1922 ((< new-pos (point-min))
1924 ((> new-pos (point-max))
1929 ;*---------------------------------------------------------------------*/
1930 ;* flyspell-emacs-popup ... */
1931 ;*---------------------------------------------------------------------*/
1932 (defun flyspell-emacs-popup (event poss word)
1933 "The Emacs popup menu."
1935 (let* ((mouse-pos (mouse-position))
1936 (mouse-pos (if (nth 1 mouse-pos)
1938 (set-mouse-position (car mouse-pos)
1939 (/ (frame-width) 2) 2)
1942 (setq event (list (list (car (cdr mouse-pos))
1943 (1+ (cdr (cdr mouse-pos))))
1945 (let* ((corrects (if flyspell-sort-corrections
1946 (sort (car (cdr (cdr poss))) 'string<)
1947 (car (cdr (cdr poss)))))
1948 (cor-menu (if (consp corrects)
1949 (mapcar (lambda (correct)
1950 (list correct correct))
1953 (affix (car (cdr (cdr (cdr poss)))))
1954 (base-menu (let ((save (if (consp affix)
1956 (list (concat "Save affix: " (car affix))
1958 '("Accept (session)" session)
1959 '("Accept (buffer)" buffer))
1960 '(("Save word" save)
1961 ("Accept (session)" session)
1962 ("Accept (buffer)" buffer)))))
1963 (if (consp cor-menu)
1964 (append cor-menu (cons "" save))
1966 (menu (cons "flyspell correction menu" base-menu)))
1967 (car (x-popup-menu event
1968 (list (format "%s [%s]" word (or ispell-local-dictionary
1972 ;*---------------------------------------------------------------------*/
1973 ;* flyspell-xemacs-popup ... */
1974 ;*---------------------------------------------------------------------*/
1975 (defun flyspell-xemacs-popup (event poss word cursor-location start end save)
1976 "The XEmacs popup menu."
1977 (let* ((corrects (if flyspell-sort-corrections
1978 (sort (car (cdr (cdr poss))) 'string<)
1979 (car (cdr (cdr poss)))))
1980 (cor-menu (if (consp corrects)
1981 (mapcar (lambda (correct)
1983 (list 'flyspell-xemacs-correct
1994 (affix (car (cdr (cdr (cdr poss)))))
1995 (menu (let ((save (if (consp affix)
1997 (concat "Save affix: " (car affix))
1998 (list 'flyspell-xemacs-correct
2009 (list 'flyspell-xemacs-correct
2018 (session (vector "Accept (session)"
2019 (list 'flyspell-xemacs-correct
2028 (buffer (vector "Accept (buffer)"
2029 (list 'flyspell-xemacs-correct
2038 (if (consp cor-menu)
2039 (append cor-menu (list "-" save session buffer))
2040 (list save session buffer)))))
2041 (popup-menu (cons (format "%s [%s]" word (or ispell-local-dictionary
2045 ;*---------------------------------------------------------------------*/
2046 ;* Some example functions for real autocorrecting */
2047 ;*---------------------------------------------------------------------*/
2048 (defun flyspell-maybe-correct-transposition (beg end poss)
2049 "Check replacements for transposed characters.
2051 If the text between BEG and END is equal to a correction suggested by
2052 Ispell, after transposing two adjacent characters, correct the text,
2055 The third arg POSS is either the symbol 'doublon' or a list of
2056 possible corrections as returned by 'ispell-parse-output'.
2058 This function is meant to be added to 'flyspell-incorrect-hook'."
2060 (let ((temp-buffer (get-buffer-create " *flyspell-temp*"))
2063 (copy-to-buffer temp-buffer beg end)
2064 (set-buffer temp-buffer)
2065 (goto-char (1+ (point-min)))
2066 (while (and (not (eobp)) (not found))
2068 (if (member (buffer-string) (nth 2 poss))
2069 (setq found (point))
2070 (transpose-chars -1)
2074 (goto-char (+ beg found -1))
2075 (transpose-chars -1)
2078 (defun flyspell-maybe-correct-doubling (beg end poss)
2079 "Check replacements for doubled characters.
2081 If the text between BEG and END is equal to a correction suggested by
2082 Ispell, after removing a pair of doubled characters, correct the text,
2085 The third arg POSS is either the symbol 'doublon' or a list of
2086 possible corrections as returned by 'ispell-parse-output'.
2088 This function is meant to be added to 'flyspell-incorrect-hook'."
2090 (let ((temp-buffer (get-buffer-create " *flyspell-temp*"))
2093 (copy-to-buffer temp-buffer beg end)
2094 (set-buffer temp-buffer)
2095 (goto-char (1+ (point-min)))
2096 (while (and (not (eobp)) (not found))
2097 (when (char-equal (char-after) (char-before))
2099 (if (member (buffer-string) (nth 2 poss))
2100 (setq found (point))
2101 (insert-char (char-before) 1)))
2105 (goto-char (+ beg found -1))
2109 ;*---------------------------------------------------------------------*/
2110 ;* flyspell-already-abbrevp ... */
2111 ;*---------------------------------------------------------------------*/
2112 (defun flyspell-already-abbrevp (table word)
2113 (let ((sym (abbrev-symbol word table)))
2114 (and sym (symbolp sym))))
2116 ;*---------------------------------------------------------------------*/
2117 ;* flyspell-change-abbrev ... */
2118 ;*---------------------------------------------------------------------*/
2119 (defun flyspell-change-abbrev (table old new)
2120 (set (abbrev-symbol old table) new))
2124 ;;; flyspell.el ends here