1 ;;; flyspell.el --- on-the-fly spell checker
3 ;; Copyright (C) 1998, 2000, 2001, 2002, 2004 Free Software Foundation, Inc.
5 ;; Author: Manuel Serrano <Manuel.Serrano@sophia.inria.fr>
7 ;; Keywords: convenience
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
28 ;; Flyspell is a minor Emacs mode performing on-the-fly spelling
31 ;; To enable Flyspell minor mode, type M-x flyspell-mode.
32 ;; This applies only to the current buffer.
34 ;; To enable Flyspell in text representing computer programs, type
35 ;; M-x flyspell-prog-mode.
36 ;; In that mode only text inside comments is checked.
38 ;; Note: consider setting the variable ispell-parser to `tex' to
39 ;; avoid TeX command checking; use `(setq ispell-parser 'tex)'.
41 ;; Some user variables control the behavior of flyspell. They are
42 ;; those defined under the `User variables' comment.
48 ;*---------------------------------------------------------------------*/
50 ;*---------------------------------------------------------------------*/
51 (defgroup flyspell nil
52 "Spell checking on the fly."
58 ;*---------------------------------------------------------------------*/
59 ;* User configuration ... */
60 ;*---------------------------------------------------------------------*/
61 (defcustom flyspell-highlight-flag t
62 "*How Flyspell should indicate misspelled words.
63 Non-nil means use highlight, nil means use minibuffer messages."
67 (defcustom flyspell-mark-duplications-flag t
68 "*Non-nil means Flyspell reports a repeated word as an error."
72 (defcustom flyspell-sort-corrections nil
73 "*Non-nil means, sort the corrections alphabetically before popping them."
78 (defcustom flyspell-duplicate-distance -
1
79 "*The maximum distance for finding duplicates of unrecognized words.
80 This applies to the feature that when a word is not found in the dictionary,
81 if the same spelling occurs elsewhere in the buffer,
82 Flyspell uses a different face (`flyspell-duplicate-face') to highlight it.
83 This variable specifies how far to search to find such a duplicate.
84 -1 means no limit (search the whole buffer).
85 0 means do not search for duplicate unrecognized spellings."
90 (defcustom flyspell-delay
3
91 "*The number of seconds to wait before checking, after a \"delayed\" command."
95 (defcustom flyspell-persistent-highlight t
96 "*Non-nil means misspelled words remain highlighted until corrected.
97 If this variable is nil, only the most recently detected misspelled word
102 (defcustom flyspell-highlight-properties t
103 "*Non-nil means highlight incorrect words even if a property exists for this word."
107 (defcustom flyspell-default-delayed-commands
108 '(self-insert-command
110 backward-or-forward-delete-char
112 scrollbar-vertical-drag
)
113 "The standard list of delayed commands for Flyspell.
114 See `flyspell-delayed-commands'."
117 :type
'(repeat (symbol)))
119 (defcustom flyspell-delayed-commands nil
120 "List of commands that are \"delayed\" for Flyspell mode.
121 After these commands, Flyspell checking is delayed for a short time,
122 whose length is specified by `flyspell-delay'."
124 :type
'(repeat (symbol)))
126 (defcustom flyspell-default-deplacement-commands
131 "The standard list of deplacement commands for Flyspell.
132 See `flyspell-deplacement-commands'."
135 :type
'(repeat (symbol)))
137 (defcustom flyspell-deplacement-commands nil
138 "List of commands that are \"deplacement\" for Flyspell mode.
139 After these commands, Flyspell checking is performed only if the previous
140 command was not the very same command."
143 :type
'(repeat (symbol)))
145 (defcustom flyspell-issue-welcome-flag t
146 "*Non-nil means that Flyspell should display a welcome message when started."
150 (defcustom flyspell-issue-message-flag t
151 "*Non-nil means that Flyspell emits messages when checking words."
155 (defcustom flyspell-incorrect-hook nil
156 "*List of functions to be called when incorrect words are encountered.
157 Each function is given three arguments: the beginning and the end
158 of the incorrect region. The third is either the symbol 'doublon' or the list
159 of possible corrections as returned by 'ispell-parse-output'.
161 If any of the functions return non-Nil, the word is not highlighted as
167 (defcustom flyspell-default-dictionary nil
168 "A string that is the name of the default dictionary.
169 This is passed to the `ispell-change-dictionary' when flyspell is started.
170 If the variable `ispell-local-dictionary' or `ispell-dictionary' is non-nil
171 when flyspell is started, the value of that variable is used instead
172 of `flyspell-default-dictionary' to select the default dictionary.
173 Otherwise, if `flyspell-default-dictionary' is nil, it means to use
174 Ispell's ultimate default dictionary."
177 :type
'(choice string
(const :tag
"Default" nil
)))
179 (defcustom flyspell-tex-command-regexp
180 "\\(\\(begin\\|end\\)[ \t]*{\\|\\(cite[a-z*]*\\|label\\|ref\\|eqref\\|usepackage\\|documentclass\\)[ \t]*\\(\\[[^]]*\\]\\)?{[^{}]*\\)"
181 "A string that is the regular expression that matches TeX commands."
186 (defcustom flyspell-check-tex-math-command nil
187 "*Non nil means check even inside TeX math environment.
188 TeX math environments are discovered by the TEXMATHP that implemented
189 inside the texmathp.el Emacs package. That package may be found at:
190 http://strw.leidenuniv.nl/~dominik/Tools"
194 (defcustom flyspell-dictionaries-that-consider-dash-as-word-delimiter
195 '("francais" "deutsch8" "norsk")
196 "List of dictionary names that consider `-' as word delimiter."
199 :type
'(repeat (string)))
201 (defcustom flyspell-abbrev-p
203 "*If true, add correction to abbreviation table."
208 (defcustom flyspell-use-global-abbrev-table-p
210 "*If true, prefer global abbrev table to local abbrev table."
216 (defcustom flyspell-mode-line-string
" Fly"
217 "*String displayed on the modeline when flyspell is active.
218 Set this to nil if you don't want a modeline indicator."
220 :type
'(choice string
(const :tag
"None" nil
)))
222 (defcustom flyspell-large-region
1000
223 "*The threshold that determines if a region is small.
224 The `flyspell-region' function is invoked if the region is small, the
225 word are checked one after the other using regular flyspell check
226 means. If the region is large, a new Ispell process is spawned to get
232 (defcustom flyspell-insert-function
(function insert
)
233 "*Function for inserting word by flyspell upon correction."
237 (defcustom flyspell-before-incorrect-word-string nil
238 "String used to indicate an incorrect word starting."
240 :type
'(choice string
(const nil
)))
242 (defcustom flyspell-after-incorrect-word-string nil
243 "String used to indicate an incorrect word ending."
245 :type
'(choice string
(const nil
)))
247 ;*---------------------------------------------------------------------*/
248 ;* Mode specific options */
249 ;* ------------------------------------------------------------- */
250 ;* Mode specific options enable users to disable flyspell on */
251 ;* certain word depending of the emacs mode. For instance, when */
252 ;* using flyspell with mail-mode add the following expression */
253 ;* in your .emacs file: */
254 ;* (add-hook 'mail-mode */
255 ;* '(lambda () (setq flyspell-generic-check-word-p */
256 ;* 'mail-mode-flyspell-verify))) */
257 ;*---------------------------------------------------------------------*/
258 (defvar flyspell-generic-check-word-p nil
259 "Function providing per-mode customization over which words are flyspelled.
260 Returns t to continue checking, nil otherwise.
261 Flyspell mode sets this variable to whatever is the `flyspell-mode-predicate'
262 property of the major mode name.")
263 (make-variable-buffer-local 'flyspell-generic-check-word-p
)
265 ;*--- mail mode -------------------------------------------------------*/
266 (put 'mail-mode
'flyspell-mode-predicate
'mail-mode-flyspell-verify
)
267 (put 'message-mode
'flyspell-mode-predicate
'mail-mode-flyspell-verify
)
268 (defun mail-mode-flyspell-verify ()
269 "This function is used for `flyspell-generic-check-word-p' in Mail mode."
270 (let ((in-headers (save-excursion
271 ;; When mail-header-separator is "",
272 ;; it is likely to be found in both directions.
273 (not (re-search-backward (concat "^" (regexp-quote mail-header-separator
) "$") nil t
))))
274 (in-signature (save-excursion
275 (re-search-backward message-signature-separator nil t
))))
277 (and (save-excursion (beginning-of-line)
278 (looking-at "^Subject:"))
279 (> (point) (match-end 0))))
285 (not (looking-at "[>}|]\\To:")))))))
287 ;*--- texinfo mode ----------------------------------------------------*/
288 (put 'texinfo-mode
'flyspell-mode-predicate
'texinfo-mode-flyspell-verify
)
289 (defun texinfo-mode-flyspell-verify ()
290 "This function is used for `flyspell-generic-check-word-p' in Texinfo mode."
293 (not (looking-at "@"))))
295 ;*--- tex mode --------------------------------------------------------*/
296 (put 'tex-mode
'flyspell-mode-predicate
'tex-mode-flyspell-verify
)
297 (defun tex-mode-flyspell-verify ()
298 "This function is used for `flyspell-generic-check-word-p' in LaTeX mode."
301 (re-search-backward "^[ \t]*%%%[ \t]+Local" (point-min) t
)))
303 (let ((this (point-marker))
304 (e (progn (end-of-line) (point-marker))))
306 (if (re-search-forward "\\\\\\(cite\\|label\\|ref\\){[^}]*}" e t
)
307 (and (>= this
(match-beginning 0))
308 (<= this
(match-end 0)) )))))))
310 ;*--- sgml mode -------------------------------------------------------*/
311 (put 'sgml-mode
'flyspell-mode-predicate
'sgml-mode-flyspell-verify
)
312 (put 'html-mode
'flyspell-mode-predicate
'sgml-mode-flyspell-verify
)
314 (defun sgml-mode-flyspell-verify ()
315 "This function is used for `flyspell-generic-check-word-p' in SGML mode."
317 (let ((this (point-marker))
318 (s (progn (beginning-of-line) (point-marker)))
319 (e (progn (end-of-line) (point-marker))))
322 (and (re-search-forward "[^<]*>" e t
)
323 (= (match-beginning 0) this
)))
326 (and (re-search-backward "<[^>]*" s t
)
327 (= (match-end 0) this
)))
330 (and (re-search-forward "[^&]*;" e t
)
331 (= (match-beginning 0) this
)))
334 (and (re-search-backward "&[^;]*" s t
)
335 (= (match-end 0) this
)))))))))
337 ;*---------------------------------------------------------------------*/
338 ;* Programming mode */
339 ;*---------------------------------------------------------------------*/
340 (defvar flyspell-prog-text-faces
341 '(font-lock-string-face font-lock-comment-face font-lock-doc-face
)
342 "Faces corresponding to text in programming-mode buffers.")
344 (defun flyspell-generic-progmode-verify ()
345 "Used for `flyspell-generic-check-word-p' in programming modes."
346 (let ((f (get-text-property (point) 'face
)))
347 (memq f flyspell-prog-text-faces
)))
350 (defun flyspell-prog-mode ()
351 "Turn on `flyspell-mode' for comments and strings."
353 (setq flyspell-generic-check-word-p
'flyspell-generic-progmode-verify
)
356 ;*---------------------------------------------------------------------*/
357 ;* Overlay compatibility */
358 ;*---------------------------------------------------------------------*/
359 (autoload 'make-overlay
"overlay" "Overlay compatibility kit." t
)
360 (autoload 'overlayp
"overlay" "Overlay compatibility kit." t
)
361 (autoload 'overlays-in
"overlay" "Overlay compatibility kit." t
)
362 (autoload 'delete-overlay
"overlay" "Overlay compatibility kit." t
)
363 (autoload 'overlays-at
"overlay" "Overlay compatibility kit." t
)
364 (autoload 'overlay-put
"overlay" "Overlay compatibility kit." t
)
365 (autoload 'overlay-get
"overlay" "Overlay compatibility kit." t
)
366 (autoload 'previous-overlay-change
"overlay" "Overlay compatibility kit." t
)
368 ;*---------------------------------------------------------------------*/
369 ;* Which emacs are we currently running */
370 ;*---------------------------------------------------------------------*/
371 (defvar flyspell-emacs
373 ((string-match "XEmacs" emacs-version
)
377 "The type of Emacs we are currently running.")
379 (defvar flyspell-use-local-map
380 (or (eq flyspell-emacs
'xemacs
)
381 (not (string< emacs-version
"20"))))
383 ;*---------------------------------------------------------------------*/
384 ;* The minor mode declaration. */
385 ;*---------------------------------------------------------------------*/
386 (eval-when-compile (defvar flyspell-local-mouse-map
))
389 (defvar flyspell-mode nil
)
390 (make-variable-buffer-local 'flyspell-mode
)
392 (defvar flyspell-mouse-map
393 (let ((map (make-sparse-keymap)))
394 (define-key map
(if (featurep 'xemacs
) [button2] [down-mouse-2])
395 #'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 This spawns a single Ispell process and checks each word.
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 `flyspell-delayed' property on some commands
553 (flyspell-delay-commands)
554 ;; we put the `flyspell-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 ispell-following-word))
957 ;; use the correct dictionary
958 (flyspell-accept-buffer-local-defs)
959 (let* ((cursor-location (point))
960 (flyspell-word (flyspell-get-word following))
962 (if (or (eq flyspell-word nil)
963 (and (fboundp flyspell-generic-check-word-p)
964 (not (funcall flyspell-generic-check-word-p))))
967 ;; destructure return flyspell-word info list.
968 (setq start (car (cdr flyspell-word))
969 end (car (cdr (cdr flyspell-word)))
970 word (car flyspell-word))
971 ;; before checking in the directory, we check for doublons.
973 ((and (or (not (eq ispell-parser 'tex))
974 (not (eq (char-after start) ?\\)))
975 flyspell-mark-duplications-flag
978 (word-search-backward word
982 ;; yes, this is a doublon
983 (flyspell-highlight-incorrect-region start end 'doublon))
984 ((and (eq flyspell-word-cache-start start)
985 (eq flyspell-word-cache-end end)
986 (string-equal flyspell-word-cache-word word))
987 ;; this word had been already checked, we skip
989 ((and (eq ispell-parser 'tex)
990 (flyspell-tex-command-p flyspell-word))
991 ;; this is a correct word (because a tex command)
992 (flyspell-unhighlight-at start)
994 (flyspell-unhighlight-at (- end 1)))
997 ;; we setup the cache
998 (setq flyspell-word-cache-start start)
999 (setq flyspell-word-cache-end end)
1000 (setq flyspell-word-cache-word word)
1001 ;; now check spelling of word.
1002 (process-send-string ispell-process "%\n")
1003 ;; put in verbose mode
1004 (process-send-string ispell-process
1005 (concat "^" word "\n"))
1006 ;; we mark the ispell process so it can be killed
1007 ;; when emacs is exited without query
1008 (set-process-query-on-exit-flag ispell-process nil)
1009 ;; wait until ispell has processed word
1011 (accept-process-output ispell-process)
1012 (not (string= "" (car ispell-filter)))))
1013 ;; (process-send-string ispell-process "!\n")
1014 ;; back to terse mode.
1015 (setq ispell-filter (cdr ispell-filter))
1016 (if (consp ispell-filter)
1017 (setq poss (ispell-parse-output (car ispell-filter))))
1020 (flyspell-unhighlight-at start)
1022 (flyspell-unhighlight-at (- end 1)))
1024 ((and (stringp poss) flyspell-highlight-flag)
1026 (flyspell-unhighlight-at start)
1028 (flyspell-unhighlight-at (- end 1)))
1031 (flyspell-unhighlight-at start)
1033 (flyspell-unhighlight-at (- end 1))))
1034 ((or (and (< flyspell-duplicate-distance 0)
1037 (word-search-backward word
1042 (word-search-forward word
1045 (and (> flyspell-duplicate-distance 0)
1048 (word-search-backward
1051 flyspell-duplicate-distance)
1055 (word-search-forward
1058 flyspell-duplicate-distance)
1060 (if flyspell-highlight-flag
1061 (flyspell-highlight-duplicate-region start end poss)
1062 (message (format "duplicate `%s'" word))))
1064 ;; incorrect highlight the location
1065 (if flyspell-highlight-flag
1066 (flyspell-highlight-incorrect-region start end poss)
1067 (flyspell-notify-misspell start end word poss))))
1068 ;; return to original location
1069 (goto-char cursor-location)
1070 (if ispell-quit (setq ispell-quit nil)))))))))
1072 ;*---------------------------------------------------------------------*/
1073 ;* flyspell-tex-math-initialized ... */
1074 ;*---------------------------------------------------------------------*/
1075 (defvar flyspell-tex-math-initialized nil)
1077 ;*---------------------------------------------------------------------*/
1078 ;* flyspell-math-tex-command-p ... */
1079 ;* ------------------------------------------------------------- */
1080 ;* This function uses the texmathp package to check if (point) */
1081 ;* is within a tex command. In order to avoid using */
1082 ;* condition-case each time we use the variable */
1083 ;* flyspell-tex-math-initialized to make a special case the first */
1084 ;* time that function is called. */
1085 ;*---------------------------------------------------------------------*/
1086 (defun flyspell-math-tex-command-p ()
1088 (flyspell-check-tex-math-command
1090 ((eq flyspell-tex-math-initialized t)
1092 ((eq flyspell-tex-math-initialized 'error)
1095 (setq flyspell-tex-math-initialized t)
1099 (setq flyspell-tex-math-initialized 'error)
1102 ;*---------------------------------------------------------------------*/
1103 ;* flyspell-tex-command-p ... */
1104 ;*---------------------------------------------------------------------*/
1105 (defun flyspell-tex-command-p (word)
1106 "Return t if WORD is a TeX command."
1108 (let ((b (car (cdr word))))
1109 (and (re-search-backward "\\\\" (- (point) 100) t)
1110 (or (= (match-end 0) b)
1111 (and (goto-char (match-end 0))
1112 (looking-at flyspell-tex-command-regexp)
1113 (>= (match-end 0) b))))))
1114 (flyspell-math-tex-command-p)))
1116 ;*---------------------------------------------------------------------*/
1117 ;* flyspell-casechars-cache ... */
1118 ;*---------------------------------------------------------------------*/
1119 (defvar flyspell-casechars-cache nil)
1120 (defvar flyspell-ispell-casechars-cache nil)
1121 (make-variable-buffer-local 'flyspell-casechars-cache)
1122 (make-variable-buffer-local 'flyspell-ispell-casechars-cache)
1124 ;*---------------------------------------------------------------------*/
1125 ;* flyspell-get-casechars ... */
1126 ;*---------------------------------------------------------------------*/
1127 (defun flyspell-get-casechars ()
1128 "This function builds a string that is the regexp of word chars.
1129 In order to avoid one useless string construction,
1130 this function changes the last char of the `ispell-casechars' string."
1131 (let ((ispell-casechars (ispell-get-casechars)))
1133 ((eq ispell-parser 'tex)
1134 (setq flyspell-ispell-casechars-cache ispell-casechars)
1135 (setq flyspell-casechars-cache
1136 (concat (substring ispell-casechars
1138 (- (length ispell-casechars) 1))
1140 flyspell-casechars-cache)
1142 (setq flyspell-ispell-casechars-cache ispell-casechars)
1143 (setq flyspell-casechars-cache ispell-casechars)
1144 flyspell-casechars-cache))))
1146 ;*---------------------------------------------------------------------*/
1147 ;* flyspell-get-not-casechars-cache ... */
1148 ;*---------------------------------------------------------------------*/
1149 (defvar flyspell-not-casechars-cache nil)
1150 (defvar flyspell-ispell-not-casechars-cache nil)
1151 (make-variable-buffer-local 'flyspell-not-casechars-cache)
1152 (make-variable-buffer-local 'flyspell-ispell-not-casechars-cache)
1154 ;*---------------------------------------------------------------------*/
1155 ;* flyspell-get-not-casechars ... */
1156 ;*---------------------------------------------------------------------*/
1157 (defun flyspell-get-not-casechars ()
1158 "This function builds a string that is the regexp of non-word chars."
1159 (let ((ispell-not-casechars (ispell-get-not-casechars)))
1161 ((eq ispell-parser 'tex)
1162 (setq flyspell-ispell-not-casechars-cache ispell-not-casechars)
1163 (setq flyspell-not-casechars-cache
1164 (concat (substring ispell-not-casechars
1166 (- (length ispell-not-casechars) 1))
1168 flyspell-not-casechars-cache)
1170 (setq flyspell-ispell-not-casechars-cache ispell-not-casechars)
1171 (setq flyspell-not-casechars-cache ispell-not-casechars)
1172 flyspell-not-casechars-cache))))
1174 ;*---------------------------------------------------------------------*/
1175 ;* flyspell-get-word ... */
1176 ;*---------------------------------------------------------------------*/
1177 (defun flyspell-get-word (following)
1178 "Return the word for spell-checking according to Ispell syntax.
1179 If argument FOLLOWING is non-nil or if `ispell-following-word'
1180 is non-nil when called interactively, then the following word
1181 \(rather than preceding\) is checked when the cursor is not over a word.
1182 Optional second argument contains other chars that can be included in word
1185 Word syntax described by `ispell-dictionary-alist' (which see)."
1186 (let* ((flyspell-casechars (flyspell-get-casechars))
1187 (flyspell-not-casechars (flyspell-get-not-casechars))
1188 (ispell-otherchars (ispell-get-otherchars))
1189 (ispell-many-otherchars-p (ispell-get-many-otherchars-p))
1190 (word-regexp (if (string< "" ispell-otherchars)
1191 (concat flyspell-casechars
1197 (if ispell-many-otherchars-p
1199 (concat flyspell-casechars "+")))
1203 (if (not (looking-at flyspell-casechars))
1205 (re-search-forward flyspell-casechars (point-max) t)
1206 (re-search-backward flyspell-casechars (point-min) t)))
1207 ;; move to front of word
1208 (re-search-backward flyspell-not-casechars (point-min) 'start)
1210 (if (string< "" ispell-otherchars)
1211 (while (and (looking-at ispell-otherchars)
1213 (or (not did-it-once)
1214 ispell-many-otherchars-p)
1215 (not (eq pos (point))))
1217 (setq did-it-once t)
1219 (if (looking-at flyspell-casechars)
1220 (re-search-backward flyspell-not-casechars (point-min) 'move)
1221 (backward-char -1)))))
1222 ;; Now mark the word and save to string.
1223 (if (eq (re-search-forward word-regexp (point-max) t) nil)
1226 (setq start (match-beginning 0)
1228 word (buffer-substring-no-properties start end))
1229 (list word start end)))))
1231 ;*---------------------------------------------------------------------*/
1232 ;* flyspell-small-region ... */
1233 ;*---------------------------------------------------------------------*/
1234 (defun flyspell-small-region (beg end)
1235 "Flyspell text between BEG and END."
1243 (while (< (point) end)
1244 (if (and flyspell-issue-message-flag (= count 100))
1246 (message "Spell Checking...%d%%"
1247 (* 100 (/ (float (- (point) beg)) (- end beg))))
1249 (setq count (+ 1 count)))
1252 (let ((cur (point)))
1254 (if (and (< (point) end) (> (point) (+ cur 1)))
1255 (backward-char 1)))))
1257 (if flyspell-issue-message-flag (message "Spell Checking completed."))
1260 ;*---------------------------------------------------------------------*/
1261 ;* flyspell-external-ispell-process ... */
1262 ;*---------------------------------------------------------------------*/
1263 (defvar flyspell-external-ispell-process '()
1264 "The external Flyspell Ispell process.")
1266 ;*---------------------------------------------------------------------*/
1267 ;* flyspell-external-ispell-buffer ... */
1268 ;*---------------------------------------------------------------------*/
1269 (defvar flyspell-external-ispell-buffer '())
1270 (defvar flyspell-large-region-buffer '())
1271 (defvar flyspell-large-region-beg (point-min))
1272 (defvar flyspell-large-region-end (point-max))
1274 ;*---------------------------------------------------------------------*/
1275 ;* flyspell-external-point-words ... */
1276 ;*---------------------------------------------------------------------*/
1277 (defun flyspell-external-point-words ()
1278 (let ((buffer flyspell-external-ispell-buffer))
1280 (goto-char (point-min))
1281 (let ((size (- flyspell-large-region-end flyspell-large-region-beg))
1282 (start flyspell-large-region-beg))
1283 ;; now we are done with ispell, we have to find the word in
1284 ;; the initial buffer
1285 (while (< (point) (- (point-max) 1))
1286 ;; we have to fetch the incorrect word
1287 (if (re-search-forward "\\([^\n]+\\)\n" (point-max) t)
1288 (let ((word (match-string 1)))
1289 (goto-char (match-end 0))
1290 (set-buffer flyspell-large-region-buffer)
1291 (goto-char flyspell-large-region-beg)
1292 (if flyspell-issue-message-flag
1293 (message "Spell Checking...%d%% [%s]"
1294 (* 100 (/ (float (- (point) start)) size))
1296 (if (search-forward word flyspell-large-region-end t)
1298 (setq flyspell-large-region-beg (point))
1299 (goto-char (- (point) 1))
1301 (set-buffer buffer))
1302 (goto-char (point-max)))))
1304 (if flyspell-issue-message-flag (message "Spell Checking completed."))
1305 ;; ok, we are done with pointing out incorrect words, we just
1306 ;; have to kill the temporary buffer
1307 (kill-buffer flyspell-external-ispell-buffer)
1308 (setq flyspell-external-ispell-buffer nil)))
1310 ;*---------------------------------------------------------------------*/
1311 ;* flyspell-large-region ... */
1312 ;*---------------------------------------------------------------------*/
1313 (defun flyspell-large-region (beg end)
1314 (let* ((curbuf (current-buffer))
1315 (buffer (get-buffer-create "*flyspell-region*")))
1316 (setq flyspell-external-ispell-buffer buffer)
1317 (setq flyspell-large-region-buffer curbuf)
1318 (setq flyspell-large-region-beg beg)
1319 (setq flyspell-large-region-end end)
1322 ;; this is done, we can start checking...
1323 (if flyspell-issue-message-flag (message "Checking region..."))
1325 (let ((c (apply 'call-process-region beg
1333 ;; Local dictionary becomes the global dictionary in use.
1334 (if ispell-local-dictionary
1335 (setq ispell-dictionary ispell-local-dictionary))
1336 (setq args (ispell-get-ispell-args))
1337 (if ispell-dictionary ; use specified dictionary
1339 (append (list "-d" ispell-dictionary) args)))
1340 (if ispell-personal-dictionary ; use specified pers dict
1345 ispell-personal-dictionary)))))
1346 (setq args (append args ispell-extra-args))
1349 (flyspell-external-point-words)
1350 (error "Can't check region...")))))
1352 ;*---------------------------------------------------------------------*/
1353 ;* flyspell-region ... */
1354 ;* ------------------------------------------------------------- */
1355 ;* Because `ispell -a' is too slow, it is not possible to use */
1356 ;* it on large region. Then, when ispell is invoked on a large */
1357 ;* text region, a new `ispell -l' process is spawned. The */
1358 ;* pointed out words are then searched in the region a checked with */
1359 ;* regular flyspell means. */
1360 ;*---------------------------------------------------------------------*/
1362 (defun flyspell-region (beg end)
1363 "Flyspell text between BEG and END."
1372 (if (> (- end beg) flyspell-large-region)
1373 (flyspell-large-region beg end)
1374 (flyspell-small-region beg end)))))
1376 ;*---------------------------------------------------------------------*/
1377 ;* flyspell-buffer ... */
1378 ;*---------------------------------------------------------------------*/
1380 (defun flyspell-buffer ()
1381 "Flyspell whole buffer."
1383 (flyspell-region (point-min) (point-max)))
1385 ;*---------------------------------------------------------------------*/
1386 ;* old next error position ... */
1387 ;*---------------------------------------------------------------------*/
1388 (defvar flyspell-old-buffer-error nil)
1389 (defvar flyspell-old-pos-error nil)
1391 ;*---------------------------------------------------------------------*/
1392 ;* flyspell-goto-next-error ... */
1393 ;*---------------------------------------------------------------------*/
1394 (defun flyspell-goto-next-error ()
1395 "Go to the next previously detected error.
1396 In general FLYSPELL-GOTO-NEXT-ERROR must be used after
1401 (if (and (eq (current-buffer) flyspell-old-buffer-error)
1402 (eq pos flyspell-old-pos-error))
1404 (if (= flyspell-old-pos-error max)
1405 ;; goto beginning of buffer
1407 (message "Restarting from beginning of buffer")
1408 (goto-char (point-min)))
1410 (setq pos (point))))
1411 ;; seek the next error
1412 (while (and (< pos max)
1413 (let ((ovs (overlays-at pos))
1415 (while (and (not r) (consp ovs))
1416 (if (flyspell-overlay-p (car ovs))
1418 (setq ovs (cdr ovs))))
1420 (setq pos (1+ pos)))
1421 ;; save the current location for next invocation
1422 (setq flyspell-old-pos-error pos)
1423 (setq flyspell-old-buffer-error (current-buffer))
1426 (message "No more miss-spelled word!"))))
1428 ;*---------------------------------------------------------------------*/
1429 ;* flyspell-overlay-p ... */
1430 ;*---------------------------------------------------------------------*/
1431 (defun flyspell-overlay-p (o)
1432 "A predicate that return true iff O is an overlay used by flyspell."
1433 (and (overlayp o) (overlay-get o 'flyspell-overlay)))
1435 ;*---------------------------------------------------------------------*/
1436 ;* flyspell-delete-all-overlays ... */
1437 ;* ------------------------------------------------------------- */
1438 ;* Remove all the overlays introduced by flyspell. */
1439 ;*---------------------------------------------------------------------*/
1440 (defun flyspell-delete-all-overlays ()
1441 "Delete all the overlays used by flyspell."
1442 (let ((l (overlays-in (point-min) (point-max))))
1445 (if (flyspell-overlay-p (car l))
1446 (delete-overlay (car l)))
1447 (setq l (cdr l))))))
1449 ;*---------------------------------------------------------------------*/
1450 ;* flyspell-unhighlight-at ... */
1451 ;*---------------------------------------------------------------------*/
1452 (defun flyspell-unhighlight-at (pos)
1453 "Remove the flyspell overlay that are located at POS."
1454 (if flyspell-persistent-highlight
1455 (let ((overlays (overlays-at pos)))
1456 (while (consp overlays)
1457 (if (flyspell-overlay-p (car overlays))
1458 (delete-overlay (car overlays)))
1459 (setq overlays (cdr overlays))))
1460 (if (flyspell-overlay-p flyspell-overlay)
1461 (delete-overlay flyspell-overlay))))
1463 ;*---------------------------------------------------------------------*/
1464 ;* flyspell-properties-at-p ... */
1465 ;* ------------------------------------------------------------- */
1466 ;* Is there an highlight properties at position pos? */
1467 ;*---------------------------------------------------------------------*/
1468 (defun flyspell-properties-at-p (pos)
1469 "Return t if there is a text property at POS, not counting `local-map'.
1470 If variable `flyspell-highlight-properties' is set to nil,
1471 text with properties are not checked. This function is used to discover
1472 if the character at POS has any other property."
1473 (let ((prop (text-properties-at pos))
1475 (while (and keep (consp prop))
1476 (if (and (eq (car prop) 'local-map) (consp (cdr prop)))
1477 (setq prop (cdr (cdr prop)))
1481 ;*---------------------------------------------------------------------*/
1482 ;* make-flyspell-overlay ... */
1483 ;*---------------------------------------------------------------------*/
1484 (defun make-flyspell-overlay (beg end face mouse-face)
1485 "Allocate an overlay to highlight an incorrect word.
1486 BEG and END specify the range in the buffer of that word.
1487 FACE and MOUSE-FACE specify the `face' and `mouse-face' properties
1489 (let ((flyspell-overlay (make-overlay beg end nil t nil)))
1490 (overlay-put flyspell-overlay 'face face)
1491 (overlay-put flyspell-overlay 'mouse-face mouse-face)
1492 (overlay-put flyspell-overlay 'flyspell-overlay t)
1493 (overlay-put flyspell-overlay 'evaporate t)
1494 (overlay-put flyspell-overlay 'help-echo "mouse-2: correct word at point")
1495 (if flyspell-use-local-map
1496 (overlay-put flyspell-overlay
1497 flyspell-overlay-keymap-property-name
1498 flyspell-mouse-map))
1499 (when (eq face 'flyspell-incorrect-face)
1500 (and (stringp flyspell-before-incorrect-word-string)
1501 (overlay-put flyspell-overlay 'before-string
1502 flyspell-before-incorrect-word-string))
1503 (and (stringp flyspell-after-incorrect-word-string)
1504 (overlay-put flyspell-overlay 'after-string
1505 flyspell-after-incorrect-word-string)))
1508 ;*---------------------------------------------------------------------*/
1509 ;* flyspell-highlight-incorrect-region ... */
1510 ;*---------------------------------------------------------------------*/
1511 (defun flyspell-highlight-incorrect-region (beg end poss)
1512 "Set up an overlay on a misspelled word, in the buffer from BEG to END."
1513 (let ((inhibit-read-only t))
1514 (unless (run-hook-with-args-until-success
1515 'flyspell-incorrect-hook beg end poss)
1516 (if (or flyspell-highlight-properties
1517 (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
1531 beg end 'flyspell-incorrect-face 'highlight)))))))
1533 ;*---------------------------------------------------------------------*/
1534 ;* flyspell-highlight-duplicate-region ... */
1535 ;*---------------------------------------------------------------------*/
1536 (defun flyspell-highlight-duplicate-region (beg end poss)
1537 "Set up an overlay on a duplicated word, in the buffer from BEG to END.
1538 ??? What does POSS mean?"
1539 (let ((inhibit-read-only t))
1540 (unless (run-hook-with-args-until-success
1541 'flyspell-incorrect-hook beg end poss)
1542 (if (or flyspell-highlight-properties
1543 (not (flyspell-properties-at-p beg)))
1545 ;; we cleanup current overlay at the same position
1546 (if (and (not flyspell-persistent-highlight)
1547 (overlayp flyspell-overlay))
1548 (delete-overlay flyspell-overlay)
1549 (let ((overlays (overlays-at beg)))
1550 (while (consp overlays)
1551 (if (flyspell-overlay-p (car overlays))
1552 (delete-overlay (car overlays)))
1553 (setq overlays (cdr overlays)))))
1554 ;; now we can use a new overlay
1555 (setq flyspell-overlay
1556 (make-flyspell-overlay beg end
1557 'flyspell-duplicate-face
1560 ;*---------------------------------------------------------------------*/
1561 ;* flyspell-auto-correct-cache ... */
1562 ;*---------------------------------------------------------------------*/
1563 (defvar flyspell-auto-correct-pos nil)
1564 (defvar flyspell-auto-correct-region nil)
1565 (defvar flyspell-auto-correct-ring nil)
1566 (defvar flyspell-auto-correct-word nil)
1567 (make-variable-buffer-local 'flyspell-auto-correct-pos)
1568 (make-variable-buffer-local 'flyspell-auto-correct-region)
1569 (make-variable-buffer-local 'flyspell-auto-correct-ring)
1570 (make-variable-buffer-local 'flyspell-auto-correct-word)
1572 ;*---------------------------------------------------------------------*/
1573 ;* flyspell-check-previous-highlighted-word ... */
1574 ;*---------------------------------------------------------------------*/
1575 (defun flyspell-check-previous-highlighted-word (&optional arg)
1576 "Correct the closer misspelled word.
1577 This function scans a mis-spelled word before the cursor. If it finds one
1578 it proposes replacement for that word. With prefix arg, count that many
1579 misspelled words backwards."
1581 (let ((pos1 (point))
1583 (arg (if (or (not (numberp arg)) (< arg 1)) 1 arg))
1586 (while (and (setq pos (previous-overlay-change pos))
1589 (if (> pos (point-min))
1591 (setq ovs (overlays-at (1- pos)))
1594 (setq ovs (cdr ovs))
1595 (if (and (overlay-get ov 'flyspell-overlay)
1596 (= 0 (setq arg (1- arg))))
1597 (throw 'exit t)))))))
1601 (error "No word to correct before point"))))
1603 ;*---------------------------------------------------------------------*/
1604 ;* flyspell-display-next-corrections ... */
1605 ;*---------------------------------------------------------------------*/
1606 (defun flyspell-display-next-corrections (corrections)
1607 (let ((string "Corrections:")
1610 (while (< (length string) 80)
1611 (if (equal (car l) flyspell-auto-correct-word)
1612 (setq pos (cons (+ 1 (length string)) pos)))
1613 (setq string (concat string " " (car l)))
1616 (let ((num (car pos)))
1617 (put-text-property num
1618 (+ num (length flyspell-auto-correct-word))
1620 'flyspell-incorrect-face
1622 (setq pos (cdr pos)))
1623 (if (fboundp 'display-message)
1624 (display-message 'no-log string)
1627 ;*---------------------------------------------------------------------*/
1628 ;* flyspell-abbrev-table ... */
1629 ;*---------------------------------------------------------------------*/
1630 (defun flyspell-abbrev-table ()
1631 (if flyspell-use-global-abbrev-table-p
1633 (or local-abbrev-table global-abbrev-table)))
1635 ;*---------------------------------------------------------------------*/
1636 ;* flyspell-define-abbrev ... */
1637 ;*---------------------------------------------------------------------*/
1638 (defun flyspell-define-abbrev (name expansion)
1639 (let ((table (flyspell-abbrev-table)))
1641 (define-abbrev table name expansion))))
1643 ;*---------------------------------------------------------------------*/
1644 ;* flyspell-auto-correct-word ... */
1645 ;*---------------------------------------------------------------------*/
1646 (defun flyspell-auto-correct-word ()
1647 "Correct the current word.
1648 This command proposes various successive corrections for the current word."
1651 (old-max (point-max)))
1652 ;; use the correct dictionary
1653 (flyspell-accept-buffer-local-defs)
1654 (if (and (eq flyspell-auto-correct-pos pos)
1655 (consp flyspell-auto-correct-region))
1656 ;; we have already been using the function at the same location
1657 (let* ((start (car flyspell-auto-correct-region))
1658 (len (cdr flyspell-auto-correct-region)))
1659 (flyspell-unhighlight-at start)
1660 (delete-region start (+ start len))
1661 (setq flyspell-auto-correct-ring (cdr flyspell-auto-correct-ring))
1662 (let* ((word (car flyspell-auto-correct-ring))
1663 (len (length word)))
1664 (rplacd flyspell-auto-correct-region len)
1666 (if flyspell-abbrev-p
1667 (if (flyspell-already-abbrevp (flyspell-abbrev-table)
1668 flyspell-auto-correct-word)
1669 (flyspell-change-abbrev (flyspell-abbrev-table)
1670 flyspell-auto-correct-word
1672 (flyspell-define-abbrev flyspell-auto-correct-word word)))
1673 (funcall flyspell-insert-function word)
1675 (flyspell-display-next-corrections flyspell-auto-correct-ring))
1676 (flyspell-ajust-cursor-point pos (point) old-max)
1677 (setq flyspell-auto-correct-pos (point)))
1678 ;; fetch the word to be checked
1679 (let ((word (flyspell-get-word nil))
1681 ;; destructure return word info list.
1682 (setq start (car (cdr word))
1683 end (car (cdr (cdr word)))
1685 (setq flyspell-auto-correct-word word)
1686 ;; now check spelling of word.
1687 (process-send-string ispell-process "%\n") ;put in verbose mode
1688 (process-send-string ispell-process (concat "^" word "\n"))
1689 ;; wait until ispell has processed word
1691 (accept-process-output ispell-process)
1692 (not (string= "" (car ispell-filter)))))
1693 (setq ispell-filter (cdr ispell-filter))
1694 (if (consp ispell-filter)
1695 (setq poss (ispell-parse-output (car ispell-filter))))
1696 (cond ((or (eq poss t) (stringp poss))
1697 ;; don't correct word
1701 (error "Ispell: error in Ispell process"))
1703 ;; the word is incorrect, we have to propose a replacement
1704 (let ((replacements (if flyspell-sort-corrections
1705 (sort (car (cdr (cdr poss))) 'string<)
1706 (car (cdr (cdr poss))))))
1707 (setq flyspell-auto-correct-region nil)
1708 (if (consp replacements)
1710 (let ((replace (car replacements)))
1711 (let ((new-word replace))
1712 (if (not (equal new-word (car poss)))
1714 ;; the save the current replacements
1715 (setq flyspell-auto-correct-region
1716 (cons start (length new-word)))
1717 (let ((l replacements))
1718 (while (consp (cdr l))
1720 (rplacd l (cons (car poss) replacements)))
1721 (setq flyspell-auto-correct-ring
1723 (flyspell-unhighlight-at start)
1724 (delete-region start end)
1725 (funcall flyspell-insert-function new-word)
1726 (if flyspell-abbrev-p
1727 (if (flyspell-already-abbrevp
1728 (flyspell-abbrev-table) word)
1729 (flyspell-change-abbrev
1730 (flyspell-abbrev-table)
1733 (flyspell-define-abbrev word new-word)))
1735 (flyspell-display-next-corrections
1736 (cons new-word flyspell-auto-correct-ring))
1737 (flyspell-ajust-cursor-point pos
1740 (setq flyspell-auto-correct-pos (point))
1741 (ispell-pdict-save t)))))
1743 ;*---------------------------------------------------------------------*/
1744 ;* flyspell-auto-correct-previous-pos ... */
1745 ;*---------------------------------------------------------------------*/
1746 (defvar flyspell-auto-correct-previous-pos nil
1747 "Holds the start of the first incorrect word before point.")
1749 ;*---------------------------------------------------------------------*/
1750 ;* flyspell-auto-correct-previous-hook ... */
1751 ;*---------------------------------------------------------------------*/
1752 (defun flyspell-auto-correct-previous-hook ()
1753 "Hook to track successive calls to `flyspell-auto-correct-previous-word'.
1754 Sets flyspell-auto-correct-previous-pos to nil"
1756 (remove-hook 'pre-command-hook (function flyspell-auto-correct-previous-hook) t)
1757 (unless (eq this-command (function flyspell-auto-correct-previous-word))
1758 (setq flyspell-auto-correct-previous-pos nil)))
1760 ;*---------------------------------------------------------------------*/
1761 ;* flyspell-auto-correct-previous-word ... */
1762 ;*---------------------------------------------------------------------*/
1763 (defun flyspell-auto-correct-previous-word (position)
1764 "*Auto correct the first mispelled word that occurs before point."
1767 (add-hook 'pre-command-hook
1768 (function flyspell-auto-correct-previous-hook) t t)
1771 (unless flyspell-auto-correct-previous-pos
1772 ;; only reset if a new overlay exists
1773 (setq flyspell-auto-correct-previous-pos nil)
1775 (let ((overlay-list (overlays-in (point-min) position))
1776 (new-overlay 'dummy-value))
1778 ;; search for previous (new) flyspell overlay
1779 (while (and new-overlay
1780 (or (not (flyspell-overlay-p new-overlay))
1781 ;; check if its face has changed
1782 (not (eq (get-char-property
1783 (overlay-start new-overlay) 'face)
1784 'flyspell-incorrect-face))))
1785 (setq new-overlay (car-safe overlay-list))
1786 (setq overlay-list (cdr-safe overlay-list)))
1788 ;; if nothing new exits new-overlay should be nil
1789 (if new-overlay;; the length of the word may change so go to the start
1790 (setq flyspell-auto-correct-previous-pos
1791 (overlay-start new-overlay)))))
1793 (when flyspell-auto-correct-previous-pos
1795 (goto-char flyspell-auto-correct-previous-pos)
1796 (let ((ispell-following-word t));; point is at start
1797 (if (numberp flyspell-auto-correct-previous-pos)
1798 (goto-char flyspell-auto-correct-previous-pos))
1799 (flyspell-auto-correct-word))
1800 ;; the point may have moved so reset this
1801 (setq flyspell-auto-correct-previous-pos (point))))))
1803 ;*---------------------------------------------------------------------*/
1804 ;* flyspell-correct-word ... */
1805 ;*---------------------------------------------------------------------*/
1806 (defun flyspell-correct-word (event)
1807 "Pop up a menu of possible corrections for a misspelled word.
1808 The word checked is the word at the mouse position."
1810 ;; use the correct dictionary
1811 (flyspell-accept-buffer-local-defs)
1812 ;; retain cursor location (I don't know why but save-excursion here fails).
1813 (let ((save (point)))
1814 (mouse-set-point event)
1815 (let ((cursor-location (point))
1816 (word (flyspell-get-word nil))
1817 start end poss replace)
1818 ;; destructure return word info list.
1819 (setq start (car (cdr word))
1820 end (car (cdr (cdr word)))
1822 ;; now check spelling of word.
1823 (process-send-string ispell-process "%\n") ;put in verbose mode
1824 (process-send-string ispell-process (concat "^" word "\n"))
1825 ;; wait until ispell has processed word
1827 (accept-process-output ispell-process)
1828 (not (string= "" (car ispell-filter)))))
1829 (setq ispell-filter (cdr ispell-filter))
1830 (if (consp ispell-filter)
1831 (setq poss (ispell-parse-output (car ispell-filter))))
1832 (cond ((or (eq poss t) (stringp poss))
1833 ;; don't correct word
1837 (error "Ispell: error in Ispell process"))
1838 ((string-match "GNU" (emacs-version))
1839 ;; the word is incorrect, we have to propose a replacement
1840 (setq replace (flyspell-emacs-popup event poss word))
1841 (cond ((eq replace 'ignore)
1846 (process-send-string ispell-process (concat "*" word "\n"))
1847 (flyspell-unhighlight-at cursor-location)
1848 (setq ispell-pdict-modified-p '(t)))
1849 ((or (eq replace 'buffer) (eq replace 'session))
1850 (process-send-string ispell-process (concat "@" word "\n"))
1851 (if (null ispell-pdict-modified-p)
1852 (setq ispell-pdict-modified-p
1853 (list ispell-pdict-modified-p)))
1854 (flyspell-unhighlight-at cursor-location)
1856 (if (eq replace 'buffer)
1857 (ispell-add-per-file-word-list word)))
1859 (flyspell-unhighlight-at cursor-location)
1860 (let ((new-word (if (atom replace)
1863 (cursor-location (+ (- (length word) (- end start))
1865 (if (not (equal new-word (car poss)))
1866 (let ((old-max (point-max)))
1867 (delete-region start end)
1868 (funcall flyspell-insert-function new-word)
1869 (if flyspell-abbrev-p
1870 (flyspell-define-abbrev word new-word))
1871 (flyspell-ajust-cursor-point save
1877 ((eq flyspell-emacs 'xemacs)
1878 (flyspell-xemacs-popup
1879 event poss word cursor-location start end save)
1881 (ispell-pdict-save t))))
1883 ;*---------------------------------------------------------------------*/
1884 ;* flyspell-xemacs-correct ... */
1885 ;*---------------------------------------------------------------------*/
1886 (defun flyspell-xemacs-correct (replace poss word cursor-location start end save)
1887 "The xemacs popup menu callback."
1888 (cond ((eq replace 'ignore)
1891 (process-send-string ispell-process (concat "*" word "\n"))
1892 (process-send-string ispell-process "#\n")
1893 (flyspell-unhighlight-at cursor-location)
1894 (setq ispell-pdict-modified-p '(t)))
1895 ((or (eq replace 'buffer) (eq replace 'session))
1896 (process-send-string ispell-process (concat "@" word "\n"))
1897 (flyspell-unhighlight-at cursor-location)
1898 (if (null ispell-pdict-modified-p)
1899 (setq ispell-pdict-modified-p
1900 (list ispell-pdict-modified-p)))
1901 (if (eq replace 'buffer)
1902 (ispell-add-per-file-word-list word)))
1904 (let ((old-max (point-max))
1905 (new-word (if (atom replace)
1908 (cursor-location (+ (- (length word) (- end start))
1910 (if (not (equal new-word (car poss)))
1912 (delete-region start end)
1914 (funcall flyspell-insert-function new-word)
1915 (if flyspell-abbrev-p
1916 (flyspell-define-abbrev word new-word))))
1917 (flyspell-ajust-cursor-point save cursor-location old-max)))))
1919 ;*---------------------------------------------------------------------*/
1920 ;* flyspell-ajust-cursor-point ... */
1921 ;*---------------------------------------------------------------------*/
1922 (defun flyspell-ajust-cursor-point (save cursor-location old-max)
1923 (if (>= save cursor-location)
1924 (let ((new-pos (+ save (- (point-max) old-max))))
1926 ((< new-pos (point-min))
1928 ((> new-pos (point-max))
1933 ;*---------------------------------------------------------------------*/
1934 ;* flyspell-emacs-popup ... */
1935 ;*---------------------------------------------------------------------*/
1936 (defun flyspell-emacs-popup (event poss word)
1937 "The Emacs popup menu."
1939 (let* ((mouse-pos (mouse-position))
1940 (mouse-pos (if (nth 1 mouse-pos)
1942 (set-mouse-position (car mouse-pos)
1943 (/ (frame-width) 2) 2)
1945 (setq event (list (list (car (cdr mouse-pos))
1946 (1+ (cdr (cdr mouse-pos))))
1948 (let* ((corrects (if flyspell-sort-corrections
1949 (sort (car (cdr (cdr poss))) 'string<)
1950 (car (cdr (cdr poss)))))
1951 (cor-menu (if (consp corrects)
1952 (mapcar (lambda (correct)
1953 (list correct correct))
1956 (affix (car (cdr (cdr (cdr poss)))))
1957 (base-menu (let ((save (if (consp affix)
1959 (list (concat "Save affix: " (car affix))
1961 '("Accept (session)" session)
1962 '("Accept (buffer)" buffer))
1963 '(("Save word" save)
1964 ("Accept (session)" session)
1965 ("Accept (buffer)" buffer)))))
1966 (if (consp cor-menu)
1967 (append cor-menu (cons "" save))
1969 (menu (cons "flyspell correction menu" base-menu)))
1970 (car (x-popup-menu event
1971 (list (format "%s [%s]" word (or ispell-local-dictionary
1975 ;*---------------------------------------------------------------------*/
1976 ;* flyspell-xemacs-popup ... */
1977 ;*---------------------------------------------------------------------*/
1978 (defun flyspell-xemacs-popup (event poss word cursor-location start end save)
1979 "The XEmacs popup menu."
1980 (let* ((corrects (if flyspell-sort-corrections
1981 (sort (car (cdr (cdr poss))) 'string<)
1982 (car (cdr (cdr poss)))))
1983 (cor-menu (if (consp corrects)
1984 (mapcar (lambda (correct)
1986 (list 'flyspell-xemacs-correct
1997 (affix (car (cdr (cdr (cdr poss)))))
1998 (menu (let ((save (if (consp affix)
2000 (concat "Save affix: " (car affix))
2001 (list 'flyspell-xemacs-correct
2012 (list 'flyspell-xemacs-correct
2021 (session (vector "Accept (session)"
2022 (list 'flyspell-xemacs-correct
2031 (buffer (vector "Accept (buffer)"
2032 (list 'flyspell-xemacs-correct
2041 (if (consp cor-menu)
2042 (append cor-menu (list "-" save session buffer))
2043 (list save session buffer)))))
2044 (popup-menu (cons (format "%s [%s]" word (or ispell-local-dictionary
2048 ;*---------------------------------------------------------------------*/
2049 ;* Some example functions for real autocorrecting */
2050 ;*---------------------------------------------------------------------*/
2051 (defun flyspell-maybe-correct-transposition (beg end poss)
2052 "Check replacements for transposed characters.
2054 If the text between BEG and END is equal to a correction suggested by
2055 Ispell, after transposing two adjacent characters, correct the text,
2058 The third arg POSS is either the symbol 'doublon' or a list of
2059 possible corrections as returned by 'ispell-parse-output'.
2061 This function is meant to be added to 'flyspell-incorrect-hook'."
2064 (let ((str (buffer-substring beg end))
2065 (i 0) (len (- end beg)) tmp)
2066 (while (< (1+ i) len)
2067 (setq tmp (aref str i))
2068 (aset str i (aref str (1+ i)))
2069 (aset str (1+ i) tmp)
2070 (when (member str (nth 2 poss))
2072 (goto-char (+ beg i 1))
2073 (transpose-chars 1))
2075 (setq tmp (aref str i))
2076 (aset str i (aref str (1+ i)))
2077 (aset str (1+ i) tmp)
2081 (defun flyspell-maybe-correct-doubling (beg end poss)
2082 "Check replacements for doubled characters.
2084 If the text between BEG and END is equal to a correction suggested by
2085 Ispell, after removing a pair of doubled characters, correct the text,
2088 The third arg POSS is either the symbol 'doublon' or a list of
2089 possible corrections as returned by 'ispell-parse-output'.
2091 This function is meant to be added to 'flyspell-incorrect-hook'."
2094 (let ((str (buffer-substring beg end))
2095 (i 0) (len (- end beg)))
2096 (while (< (1+ i) len)
2097 (when (and (= (aref str i) (aref str (1+ i)))
2098 (member (concat (substring str 0 (1+ i))
2099 (substring str (+ i 2)))
2101 (goto-char (+ beg i))
2107 ;*---------------------------------------------------------------------*/
2108 ;* flyspell-already-abbrevp ... */
2109 ;*---------------------------------------------------------------------*/
2110 (defun flyspell-already-abbrevp (table word)
2111 (let ((sym (abbrev-symbol word table)))
2112 (and sym (symbolp sym))))
2114 ;*---------------------------------------------------------------------*/
2115 ;* flyspell-change-abbrev ... */
2116 ;*---------------------------------------------------------------------*/
2117 (defun flyspell-change-abbrev (table old new)
2118 (set (abbrev-symbol old table) new))
2122 ;; arch-tag: 05d915b9-e9cf-44fb-9137-fc28f5eaab2a
2123 ;;; flyspell.el ends here