Update docstrings and comments to use "init file" terminology.
[emacs.git] / lisp / textmodes / flyspell.el
blob42f0418b69083281017b82a05824de927e3524db
1 ;;; flyspell.el --- on-the-fly spell checker
3 ;; Copyright (C) 1998, 2000-2012 Free Software Foundation, Inc.
5 ;; Author: Manuel Serrano <Manuel.Serrano@sophia.inria.fr>
6 ;; Maintainer: FSF
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 3 of the License, or
14 ;; (at your option) any later version.
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. If not, see <http://www.gnu.org/licenses/>.
24 ;;; Commentary:
26 ;; Flyspell is a minor Emacs mode performing on-the-fly spelling
27 ;; checking.
29 ;; To enable Flyspell minor mode, type M-x flyspell-mode.
30 ;; This applies only to the current buffer.
32 ;; To enable Flyspell in text representing computer programs, type
33 ;; M-x flyspell-prog-mode.
34 ;; In that mode only text inside comments is checked.
36 ;; Some user variables control the behavior of flyspell. They are
37 ;; those defined under the `User variables' comment.
39 ;;; Code:
41 (require 'ispell)
43 ;;*---------------------------------------------------------------------*/
44 ;;* Group ... */
45 ;;*---------------------------------------------------------------------*/
46 (defgroup flyspell nil
47 "Spell checking on the fly."
48 :tag "FlySpell"
49 :prefix "flyspell-"
50 :group 'ispell
51 :group 'processes)
53 ;;*---------------------------------------------------------------------*/
54 ;;* User configuration ... */
55 ;;*---------------------------------------------------------------------*/
56 (defcustom flyspell-highlight-flag t
57 "How Flyspell should indicate misspelled words.
58 Non-nil means use highlight, nil means use minibuffer messages."
59 :group 'flyspell
60 :type 'boolean)
62 (defcustom flyspell-mark-duplications-flag t
63 "Non-nil means Flyspell reports a repeated word as an error.
64 See `flyspell-mark-duplications-exceptions' to add exceptions to this rule.
65 Detection of repeated words is not implemented in
66 \"large\" regions; see `flyspell-large-region'."
67 :group 'flyspell
68 :type 'boolean)
70 (defcustom flyspell-mark-duplications-exceptions
71 '((nil . ("that" "had")) ; Common defaults for English.
72 ("\\`francais" . ("nous" "vous")))
73 "A list of exceptions for duplicated words.
74 It should be a list of (LANGUAGE . EXCEPTION-LIST).
76 LANGUAGE is nil, which means the exceptions apply regardless of
77 the current dictionary, or a regular expression matching the
78 dictionary name (`ispell-local-dictionary' or
79 `ispell-dictionary') for which the exceptions should apply.
81 EXCEPTION-LIST is a list of strings. The checked word is
82 downcased before comparing with these exceptions."
83 :group 'flyspell
84 :type '(alist :key-type (choice (const :tag "All dictionaries" nil)
85 string)
86 :value-type (repeat string))
87 :version "24.1")
89 (defcustom flyspell-sort-corrections nil
90 "Non-nil means, sort the corrections alphabetically before popping them."
91 :group 'flyspell
92 :version "21.1"
93 :type 'boolean)
95 (defcustom flyspell-duplicate-distance -1
96 "The maximum distance for finding duplicates of unrecognized words.
97 This applies to the feature that when a word is not found in the dictionary,
98 if the same spelling occurs elsewhere in the buffer,
99 Flyspell uses a different face (`flyspell-duplicate') to highlight it.
100 This variable specifies how far to search to find such a duplicate.
101 -1 means no limit (search the whole buffer).
102 0 means do not search for duplicate unrecognized spellings."
103 :group 'flyspell
104 :version "21.1"
105 :type '(choice (const :tag "no limit" -1)
106 number))
108 (defcustom flyspell-delay 3
109 "The number of seconds to wait before checking, after a \"delayed\" command."
110 :group 'flyspell
111 :type 'number)
113 (defcustom flyspell-persistent-highlight t
114 "Non-nil means misspelled words remain highlighted until corrected.
115 If this variable is nil, only the most recently detected misspelled word
116 is highlighted."
117 :group 'flyspell
118 :type 'boolean)
120 (defcustom flyspell-highlight-properties t
121 "Non-nil means highlight incorrect words even if a property exists for this word."
122 :group 'flyspell
123 :type 'boolean)
125 (defcustom flyspell-default-delayed-commands
126 '(self-insert-command
127 delete-backward-char
128 backward-or-forward-delete-char
129 delete-char
130 scrollbar-vertical-drag
131 backward-delete-char-untabify)
132 "The standard list of delayed commands for Flyspell.
133 See `flyspell-delayed-commands'."
134 :group 'flyspell
135 :version "21.1"
136 :type '(repeat (symbol)))
138 (defcustom flyspell-delayed-commands nil
139 "List of commands that are \"delayed\" for Flyspell mode.
140 After these commands, Flyspell checking is delayed for a short time,
141 whose length is specified by `flyspell-delay'."
142 :group 'flyspell
143 :type '(repeat (symbol)))
145 (defcustom flyspell-default-deplacement-commands
146 '(next-line previous-line
147 handle-switch-frame handle-select-window
148 scroll-up scroll-down)
149 "The standard list of deplacement commands for Flyspell.
150 See `flyspell-deplacement-commands'."
151 :group 'flyspell
152 :version "21.1"
153 :type '(repeat (symbol)))
155 (defcustom flyspell-deplacement-commands nil
156 "List of commands that are \"deplacement\" for Flyspell mode.
157 After these commands, Flyspell checking is performed only if the previous
158 command was not the very same command."
159 :group 'flyspell
160 :version "21.1"
161 :type '(repeat (symbol)))
163 (defcustom flyspell-issue-welcome-flag t
164 "Non-nil means that Flyspell should display a welcome message when started."
165 :group 'flyspell
166 :type 'boolean)
168 (defcustom flyspell-issue-message-flag t
169 "Non-nil means that Flyspell emits messages when checking words."
170 :group 'flyspell
171 :type 'boolean)
173 (defcustom flyspell-incorrect-hook nil
174 "List of functions to be called when incorrect words are encountered.
175 Each function is given three arguments. The first two
176 arguments are the beginning and the end of the incorrect region.
177 The third is either the symbol `doublon' or the list
178 of possible corrections as returned by `ispell-parse-output'.
180 If any of the functions return non-nil, the word is not highlighted as
181 incorrect."
182 :group 'flyspell
183 :version "21.1"
184 :type 'hook)
186 (defcustom flyspell-default-dictionary nil
187 "A string that is the name of the default dictionary.
188 This is passed to the `ispell-change-dictionary' when flyspell is started.
189 If the variable `ispell-local-dictionary' or `ispell-dictionary' is non-nil
190 when flyspell is started, the value of that variable is used instead
191 of `flyspell-default-dictionary' to select the default dictionary.
192 Otherwise, if `flyspell-default-dictionary' is nil, it means to use
193 Ispell's ultimate default dictionary."
194 :group 'flyspell
195 :version "21.1"
196 :type '(choice string (const :tag "Default" nil)))
198 (defcustom flyspell-tex-command-regexp
199 "\\(\\(begin\\|end\\)[ \t]*{\\|\\(cite[a-z*]*\\|label\\|ref\\|eqref\\|usepackage\\|documentclass\\)[ \t]*\\(\\[[^]]*\\]\\)?{[^{}]*\\)"
200 "A string that is the regular expression that matches TeX commands."
201 :group 'flyspell
202 :version "21.1"
203 :type 'string)
205 (defcustom flyspell-check-tex-math-command nil
206 "Non-nil means check even inside TeX math environment.
207 TeX math environments are discovered by `texmathp', implemented
208 inside AUCTeX package. That package may be found at
209 URL `http://www.gnu.org/software/auctex/'"
210 :group 'flyspell
211 :type 'boolean)
213 (defcustom flyspell-dictionaries-that-consider-dash-as-word-delimiter
214 '("francais" "deutsch8" "norsk")
215 "List of dictionary names that consider `-' as word delimiter."
216 :group 'flyspell
217 :version "21.1"
218 :type '(repeat (string)))
220 (defcustom flyspell-abbrev-p
222 "If non-nil, add correction to abbreviation table."
223 :group 'flyspell
224 :version "21.1"
225 :type 'boolean)
227 (defcustom flyspell-use-global-abbrev-table-p
229 "If non-nil, prefer global abbrev table to local abbrev table."
230 :group 'flyspell
231 :version "21.1"
232 :type 'boolean)
234 (defcustom flyspell-mode-line-string " Fly"
235 "String displayed on the mode line when flyspell is active.
236 Set this to nil if you don't want a mode line indicator."
237 :group 'flyspell
238 :type '(choice string (const :tag "None" nil)))
240 (defcustom flyspell-large-region 1000
241 "The threshold that determines if a region is small.
242 If the region is smaller than this number of characters,
243 `flyspell-region' checks the words sequentially using regular
244 flyspell methods. Else, if the region is large, a new Ispell process is
245 spawned for speed.
247 Doubled words are not detected in a large region, because Ispell
248 does not check for them.
250 If this variable is nil, all regions are treated as small."
251 :group 'flyspell
252 :version "21.1"
253 :type '(choice number (const :tag "All small" nil)))
255 (defcustom flyspell-insert-function (function insert)
256 "Function for inserting word by flyspell upon correction."
257 :group 'flyspell
258 :type 'function)
260 (defcustom flyspell-before-incorrect-word-string nil
261 "String used to indicate an incorrect word starting."
262 :group 'flyspell
263 :type '(choice string (const nil)))
265 (defcustom flyspell-after-incorrect-word-string nil
266 "String used to indicate an incorrect word ending."
267 :group 'flyspell
268 :type '(choice string (const nil)))
270 (defvar flyspell-mode-map)
272 (defcustom flyspell-use-meta-tab t
273 "Non-nil means that flyspell uses M-TAB to correct word."
274 :group 'flyspell
275 :type 'boolean
276 :initialize 'custom-initialize-default
277 :set (lambda (sym val)
278 (define-key flyspell-mode-map "\M-\t"
279 (if (set sym val)
280 'flyspell-auto-correct-word))))
282 (defcustom flyspell-auto-correct-binding
283 [(control ?\;)]
284 "The key binding for flyspell auto correction."
285 :group 'flyspell)
287 ;;*---------------------------------------------------------------------*/
288 ;;* Mode specific options */
289 ;;* ------------------------------------------------------------- */
290 ;;* Mode specific options enable users to disable flyspell on */
291 ;;* certain word depending of the emacs mode. For instance, when */
292 ;;* using flyspell with mail-mode add the following expression */
293 ;;* in your init file: */
294 ;;* (add-hook 'mail-mode */
295 ;;* (lambda () (setq flyspell-generic-check-word-predicate */
296 ;;* 'mail-mode-flyspell-verify))) */
297 ;;*---------------------------------------------------------------------*/
298 (defvar flyspell-generic-check-word-predicate nil
299 "Function providing per-mode customization over which words are flyspelled.
300 Returns t to continue checking, nil otherwise.
301 Flyspell mode sets this variable to whatever is the `flyspell-mode-predicate'
302 property of the major mode name.")
303 (make-variable-buffer-local 'flyspell-generic-check-word-predicate)
304 (defvaralias 'flyspell-generic-check-word-p
305 'flyspell-generic-check-word-predicate)
307 ;;*--- mail mode -------------------------------------------------------*/
308 (put 'mail-mode 'flyspell-mode-predicate 'mail-mode-flyspell-verify)
309 (put 'message-mode 'flyspell-mode-predicate 'mail-mode-flyspell-verify)
310 (defvar message-signature-separator)
311 (defun mail-mode-flyspell-verify ()
312 "Function used for `flyspell-generic-check-word-predicate' in Mail mode."
313 (let ((header-end (save-excursion
314 (goto-char (point-min))
315 (re-search-forward
316 (concat "^"
317 (regexp-quote mail-header-separator)
318 "$")
319 nil t)
320 (point)))
321 (signature-begin
322 (if (not (boundp 'message-signature-separator))
323 (point-max)
324 (save-excursion
325 (goto-char (point-max))
326 (re-search-backward message-signature-separator nil t)
327 (point)))))
328 (cond ((< (point) header-end)
329 (and (save-excursion (beginning-of-line)
330 (looking-at "^Subject:"))
331 (> (point) (match-end 0))))
332 ((> (point) signature-begin)
333 nil)
335 (save-excursion
336 (beginning-of-line)
337 (not (looking-at "[>}|]\\|To:")))))))
339 ;;*--- texinfo mode ----------------------------------------------------*/
340 (put 'texinfo-mode 'flyspell-mode-predicate 'texinfo-mode-flyspell-verify)
341 (defun texinfo-mode-flyspell-verify ()
342 "Function used for `flyspell-generic-check-word-predicate' in Texinfo mode."
343 (save-excursion
344 (forward-word -1)
345 (not (looking-at "@"))))
347 ;;*--- tex mode --------------------------------------------------------*/
348 (put 'tex-mode 'flyspell-mode-predicate 'tex-mode-flyspell-verify)
349 (defun tex-mode-flyspell-verify ()
350 "Function used for `flyspell-generic-check-word-predicate' in LaTeX mode."
351 (and
352 (not (save-excursion
353 (re-search-backward "^[ \t]*%%%[ \t]+Local" nil t)))
354 (not (save-excursion
355 (let ((this (point)))
356 (beginning-of-line)
357 (and (re-search-forward "\\\\\\(cite\\|label\\|ref\\){[^}]*}"
358 (line-end-position) t)
359 (>= this (match-beginning 0))
360 (<= this (match-end 0))))))))
362 ;;*--- sgml mode -------------------------------------------------------*/
363 (put 'sgml-mode 'flyspell-mode-predicate 'sgml-mode-flyspell-verify)
364 (put 'html-mode 'flyspell-mode-predicate 'sgml-mode-flyspell-verify)
365 (put 'nxml-mode 'flyspell-mode-predicate 'sgml-mode-flyspell-verify)
367 (autoload 'sgml-lexical-context "sgml-mode")
369 (defun sgml-mode-flyspell-verify ()
370 "Function used for `flyspell-generic-check-word-predicate' in SGML mode.
371 Tag and attribute names are not spell checked, everything else is.
373 String values of attributes are checked because they can be text
374 like <img alt=\"Some thing.\">."
376 (not (memq (car (sgml-lexical-context))
377 '(tag pi))))
379 ;;*---------------------------------------------------------------------*/
380 ;;* Programming mode */
381 ;;*---------------------------------------------------------------------*/
382 (defvar flyspell-prog-text-faces
383 '(font-lock-string-face font-lock-comment-face font-lock-doc-face)
384 "Faces corresponding to text in programming-mode buffers.")
386 (defun flyspell-generic-progmode-verify ()
387 "Used for `flyspell-generic-check-word-predicate' in programming modes."
388 ;; (point) is next char after the word. Must check one char before.
389 (let ((f (get-text-property (- (point) 1) 'face)))
390 (memq f flyspell-prog-text-faces)))
392 ;;;###autoload
393 (defun flyspell-prog-mode ()
394 "Turn on `flyspell-mode' for comments and strings."
395 (interactive)
396 (setq flyspell-generic-check-word-predicate
397 'flyspell-generic-progmode-verify)
398 (flyspell-mode 1)
399 (run-hooks 'flyspell-prog-mode-hook))
401 ;;*---------------------------------------------------------------------*/
402 ;;* Overlay compatibility */
403 ;;*---------------------------------------------------------------------*/
404 (autoload 'make-overlay "overlay" "Overlay compatibility kit." t)
405 (autoload 'overlayp "overlay" "Overlay compatibility kit." t)
406 (autoload 'overlays-in "overlay" "Overlay compatibility kit." t)
407 (autoload 'delete-overlay "overlay" "Overlay compatibility kit." t)
408 (autoload 'overlays-at "overlay" "Overlay compatibility kit." t)
409 (autoload 'overlay-put "overlay" "Overlay compatibility kit." t)
410 (autoload 'overlay-get "overlay" "Overlay compatibility kit." t)
411 (autoload 'previous-overlay-change "overlay" "Overlay compatibility kit." t)
413 ;;*---------------------------------------------------------------------*/
414 ;;* The minor mode declaration. */
415 ;;*---------------------------------------------------------------------*/
416 (defvar flyspell-mouse-map
417 (let ((map (make-sparse-keymap)))
418 (if (featurep 'xemacs)
419 (define-key map [button2] #'flyspell-correct-word)
420 (define-key map [down-mouse-2] #'flyspell-correct-word)
421 (define-key map [mouse-2] 'undefined))
422 map)
423 "Keymap for Flyspell to put on erroneous words.")
425 (defvar flyspell-mode-map
426 (let ((map (make-sparse-keymap)))
427 (if flyspell-use-meta-tab
428 (define-key map "\M-\t" 'flyspell-auto-correct-word))
429 (define-key map flyspell-auto-correct-binding 'flyspell-auto-correct-previous-word)
430 (define-key map [(control ?\,)] 'flyspell-goto-next-error)
431 (define-key map [(control ?\.)] 'flyspell-auto-correct-word)
432 (define-key map [?\C-c ?$] 'flyspell-correct-word-before-point)
433 map)
434 "Minor mode keymap for Flyspell mode--for the whole buffer.")
436 ;; dash character machinery
437 (defvar flyspell-consider-dash-as-word-delimiter-flag nil
438 "Non-nil means that the `-' char is considered as a word delimiter.")
439 (make-variable-buffer-local 'flyspell-consider-dash-as-word-delimiter-flag)
440 (defvar flyspell-dash-dictionary nil)
441 (make-variable-buffer-local 'flyspell-dash-dictionary)
442 (defvar flyspell-dash-local-dictionary nil)
443 (make-variable-buffer-local 'flyspell-dash-local-dictionary)
445 ;;*---------------------------------------------------------------------*/
446 ;;* Highlighting */
447 ;;*---------------------------------------------------------------------*/
448 (defface flyspell-incorrect '((t :underline t :inherit error))
449 "Flyspell face for misspelled words."
450 :group 'flyspell)
452 (defface flyspell-duplicate '((t :underline t :inherit warning))
453 "Flyspell face for words that appear twice in a row.
454 See also `flyspell-duplicate-distance'."
455 :group 'flyspell)
457 (defvar flyspell-overlay nil)
459 ;;*---------------------------------------------------------------------*/
460 ;;* flyspell-mode ... */
461 ;;*---------------------------------------------------------------------*/
462 ;;;###autoload(defvar flyspell-mode nil "Non-nil if Flyspell mode is enabled.")
463 ;;;###autoload
464 (define-minor-mode flyspell-mode
465 "Toggle on-the-fly spell checking (Flyspell mode).
466 With a prefix argument ARG, enable Flyspell mode if ARG is
467 positive, and disable it otherwise. If called from Lisp, enable
468 the mode if ARG is omitted or nil.
470 Flyspell mode is a buffer-local minor mode. When enabled, it
471 spawns a single Ispell process and checks each word. The default
472 flyspell behavior is to highlight incorrect words.
474 Bindings:
475 \\[ispell-word]: correct words (using Ispell).
476 \\[flyspell-auto-correct-word]: automatically correct word.
477 \\[flyspell-auto-correct-previous-word]: automatically correct the last misspelled word.
478 \\[flyspell-correct-word] (or down-mouse-2): popup correct words.
480 Hooks:
481 This runs `flyspell-mode-hook' after flyspell mode is entered or exit.
483 Remark:
484 `flyspell-mode' uses `ispell-mode'. Thus all Ispell options are
485 valid. For instance, a different dictionary can be used by
486 invoking `ispell-change-dictionary'.
488 Consider using the `ispell-parser' to check your text. For instance
489 consider adding:
490 \(add-hook 'tex-mode-hook (function (lambda () (setq ispell-parser 'tex))))
491 in your init file.
493 \\[flyspell-region] checks all words inside a region.
494 \\[flyspell-buffer] checks the whole buffer."
495 :lighter flyspell-mode-line-string
496 :keymap flyspell-mode-map
497 :group 'flyspell
498 (if flyspell-mode
499 (condition-case err
500 (flyspell-mode-on)
501 (error (message "Error enabling Flyspell mode:\n%s" (cdr err))
502 (flyspell-mode -1)))
503 (flyspell-mode-off)))
505 ;;;###autoload
506 (defun turn-on-flyspell ()
507 "Unconditionally turn on Flyspell mode."
508 (flyspell-mode 1))
510 ;;;###autoload
511 (defun turn-off-flyspell ()
512 "Unconditionally turn off Flyspell mode."
513 (flyspell-mode -1))
515 (custom-add-option 'text-mode-hook 'turn-on-flyspell)
517 ;;*---------------------------------------------------------------------*/
518 ;;* flyspell-buffers ... */
519 ;;* ------------------------------------------------------------- */
520 ;;* For remembering buffers running flyspell */
521 ;;*---------------------------------------------------------------------*/
522 (defvar flyspell-buffers nil)
524 ;;*---------------------------------------------------------------------*/
525 ;;* flyspell-minibuffer-p ... */
526 ;;*---------------------------------------------------------------------*/
527 (defun flyspell-minibuffer-p (buffer)
528 "Is BUFFER a minibuffer?"
529 (let ((ws (get-buffer-window-list buffer t)))
530 (and (consp ws) (window-minibuffer-p (car ws)))))
532 ;;*---------------------------------------------------------------------*/
533 ;;* flyspell-accept-buffer-local-defs ... */
534 ;;*---------------------------------------------------------------------*/
535 (defvar flyspell-last-buffer nil
536 "The buffer in which the last flyspell operation took place.")
538 (defun flyspell-accept-buffer-local-defs (&optional force)
539 ;; When flyspell-word is used inside a loop (e.g. when processing
540 ;; flyspell-changes), the calls to `ispell-accept-buffer-local-defs' end
541 ;; up dwarfing everything else, so only do it when the buffer has changed.
542 (when (or force (not (eq flyspell-last-buffer (current-buffer))))
543 (setq flyspell-last-buffer (current-buffer))
544 ;; Strange problem: If buffer in current window has font-lock turned on,
545 ;; but SET-BUFFER was called to point to an invisible buffer, this ispell
546 ;; call will reset the buffer to the buffer in the current window.
547 ;; However, it only happens at startup (fix by Albert L. Ting).
548 (save-current-buffer
549 (ispell-accept-buffer-local-defs))
550 (unless (and (eq flyspell-dash-dictionary ispell-dictionary)
551 (eq flyspell-dash-local-dictionary ispell-local-dictionary))
552 ;; The dictionary has changed
553 (setq flyspell-dash-dictionary ispell-dictionary)
554 (setq flyspell-dash-local-dictionary ispell-local-dictionary)
555 (setq flyspell-consider-dash-as-word-delimiter-flag
556 (member (or ispell-local-dictionary ispell-dictionary)
557 flyspell-dictionaries-that-consider-dash-as-word-delimiter)))))
559 (defun flyspell-hack-local-variables-hook ()
560 ;; When local variables are loaded, see if the dictionary context
561 ;; has changed.
562 (flyspell-accept-buffer-local-defs 'force))
564 (defun flyspell-kill-ispell-hook ()
565 (setq flyspell-last-buffer nil)
566 (dolist (buf (buffer-list))
567 (with-current-buffer buf
568 (kill-local-variable 'flyspell-word-cache-word))))
570 ;; Make sure we flush our caches when needed. Do it here rather than in
571 ;; flyspell-mode-on, since flyspell-region may be used without ever turning
572 ;; on flyspell-mode.
573 (add-hook 'ispell-kill-ispell-hook 'flyspell-kill-ispell-hook)
575 ;;*---------------------------------------------------------------------*/
576 ;;* flyspell-mode-on ... */
577 ;;*---------------------------------------------------------------------*/
578 (defun flyspell-mode-on ()
579 "Turn Flyspell mode on. Do not use this; use `flyspell-mode' instead."
580 (ispell-set-spellchecker-params) ; Initialize variables and dicts alists
581 (setq ispell-highlight-face 'flyspell-incorrect)
582 ;; local dictionaries setup
583 (or ispell-local-dictionary ispell-dictionary
584 (if flyspell-default-dictionary
585 (ispell-change-dictionary flyspell-default-dictionary)))
586 ;; we have to force ispell to accept the local definition or
587 ;; otherwise it could be too late, the local dictionary may
588 ;; be forgotten!
589 ;; Pass the `force' argument for the case where flyspell was active already
590 ;; but the buffer's local-defs have been edited.
591 (flyspell-accept-buffer-local-defs 'force)
592 ;; we put the `flyspell-delayed' property on some commands
593 (flyspell-delay-commands)
594 ;; we put the `flyspell-deplacement' property on some commands
595 (flyspell-deplacement-commands)
596 ;; we bound flyspell action to post-command hook
597 (add-hook 'post-command-hook (function flyspell-post-command-hook) t t)
598 ;; we bound flyspell action to pre-command hook
599 (add-hook 'pre-command-hook (function flyspell-pre-command-hook) t t)
600 ;; we bound flyspell action to after-change hook
601 (add-hook 'after-change-functions 'flyspell-after-change-function nil t)
602 ;; we bound flyspell action to hack-local-variables-hook
603 (add-hook 'hack-local-variables-hook
604 (function flyspell-hack-local-variables-hook) t t)
605 ;; set flyspell-generic-check-word-predicate based on the major mode
606 (let ((mode-predicate (get major-mode 'flyspell-mode-predicate)))
607 (if mode-predicate
608 (setq flyspell-generic-check-word-predicate mode-predicate)))
609 ;; the welcome message
610 (if (and flyspell-issue-message-flag
611 flyspell-issue-welcome-flag
612 (if (featurep 'xemacs)
613 (interactive-p) ;; XEmacs does not have (called-interactively-p)
614 (called-interactively-p 'interactive)))
615 (let ((binding (where-is-internal 'flyspell-auto-correct-word
616 nil 'non-ascii)))
617 (message "%s"
618 (if binding
619 (format "Welcome to flyspell. Use %s or Mouse-2 to correct words."
620 (key-description binding))
621 "Welcome to flyspell. Use Mouse-2 to correct words.")))))
623 ;;*---------------------------------------------------------------------*/
624 ;;* flyspell-delay-commands ... */
625 ;;*---------------------------------------------------------------------*/
626 (defun flyspell-delay-commands ()
627 "Install the standard set of Flyspell delayed commands."
628 (mapc 'flyspell-delay-command flyspell-default-delayed-commands)
629 (mapc 'flyspell-delay-command flyspell-delayed-commands))
631 ;;*---------------------------------------------------------------------*/
632 ;;* flyspell-delay-command ... */
633 ;;*---------------------------------------------------------------------*/
634 (defun flyspell-delay-command (command)
635 "Set COMMAND to be delayed, for Flyspell.
636 When flyspell `post-command-hook' is invoked because a delayed command
637 has been used, the current word is not immediately checked.
638 It will be checked only after `flyspell-delay' seconds."
639 (interactive "SDelay Flyspell after Command: ")
640 (put command 'flyspell-delayed t))
642 ;;*---------------------------------------------------------------------*/
643 ;;* flyspell-deplacement-commands ... */
644 ;;*---------------------------------------------------------------------*/
645 (defun flyspell-deplacement-commands ()
646 "Install the standard set of Flyspell deplacement commands."
647 (mapc 'flyspell-deplacement-command flyspell-default-deplacement-commands)
648 (mapc 'flyspell-deplacement-command flyspell-deplacement-commands))
650 ;;*---------------------------------------------------------------------*/
651 ;;* flyspell-deplacement-command ... */
652 ;;*---------------------------------------------------------------------*/
653 (defun flyspell-deplacement-command (command)
654 "Set COMMAND that implement cursor movements, for Flyspell.
655 When flyspell `post-command-hook' is invoked because a deplacement command
656 has been used, the current word is not checked."
657 (interactive "SDeplacement Flyspell after Command: ")
658 (put command 'flyspell-deplacement t))
660 ;;*---------------------------------------------------------------------*/
661 ;;* flyspell-word-cache ... */
662 ;;*---------------------------------------------------------------------*/
663 (defvar flyspell-word-cache-start nil)
664 (defvar flyspell-word-cache-end nil)
665 (defvar flyspell-word-cache-word nil)
666 (defvar flyspell-word-cache-result '_)
667 (make-variable-buffer-local 'flyspell-word-cache-start)
668 (make-variable-buffer-local 'flyspell-word-cache-end)
669 (make-variable-buffer-local 'flyspell-word-cache-word)
670 (make-variable-buffer-local 'flyspell-word-cache-result)
672 ;;*---------------------------------------------------------------------*/
673 ;;* The flyspell pre-hook, store the current position. In the */
674 ;;* post command hook, we will check, if the word at this position */
675 ;;* has to be spell checked. */
676 ;;*---------------------------------------------------------------------*/
677 (defvar flyspell-pre-buffer nil "Buffer current before `this-command'.")
678 (defvar flyspell-pre-point nil "Point before running `this-command'")
679 (defvar flyspell-pre-column nil "Column before running `this-command'")
680 (defvar flyspell-pre-pre-buffer nil)
681 (defvar flyspell-pre-pre-point nil)
682 (make-variable-buffer-local 'flyspell-pre-point) ;Why?? --Stef
684 ;;*---------------------------------------------------------------------*/
685 ;;* flyspell-previous-command ... */
686 ;;*---------------------------------------------------------------------*/
687 (defvar flyspell-previous-command nil
688 "The last interactive command checked by Flyspell.")
690 ;;*---------------------------------------------------------------------*/
691 ;;* flyspell-pre-command-hook ... */
692 ;;*---------------------------------------------------------------------*/
693 (defun flyspell-pre-command-hook ()
694 "Save the current buffer and point for Flyspell's post-command hook."
695 (interactive)
696 (setq flyspell-pre-buffer (current-buffer))
697 (setq flyspell-pre-point (point))
698 (setq flyspell-pre-column (current-column)))
700 ;;*---------------------------------------------------------------------*/
701 ;;* flyspell-mode-off ... */
702 ;;*---------------------------------------------------------------------*/
703 ;;;###autoload
704 (defun flyspell-mode-off ()
705 "Turn Flyspell mode off."
706 ;; We remove the hooks.
707 (remove-hook 'post-command-hook (function flyspell-post-command-hook) t)
708 (remove-hook 'pre-command-hook (function flyspell-pre-command-hook) t)
709 (remove-hook 'after-change-functions 'flyspell-after-change-function t)
710 (remove-hook 'hack-local-variables-hook
711 (function flyspell-hack-local-variables-hook) t)
712 ;; We remove all the flyspell highlightings.
713 (flyspell-delete-all-overlays)
714 ;; We have to erase pre cache variables.
715 (setq flyspell-pre-buffer nil)
716 (setq flyspell-pre-point nil)
717 ;; We mark the mode as killed.
718 (setq flyspell-mode nil))
720 ;;*---------------------------------------------------------------------*/
721 ;;* flyspell-check-pre-word-p ... */
722 ;;*---------------------------------------------------------------------*/
723 (defun flyspell-check-pre-word-p ()
724 "Return non-nil if we should check the word before point.
725 More precisely, it applies to the word that was before point
726 before the current command."
727 (let ((ispell-otherchars (ispell-get-otherchars)))
728 (cond
729 ((not (and (numberp flyspell-pre-point)
730 (buffer-live-p flyspell-pre-buffer)))
731 nil)
732 ((and (eq flyspell-pre-pre-point flyspell-pre-point)
733 (eq flyspell-pre-pre-buffer flyspell-pre-buffer))
734 nil)
735 ((or (and (= flyspell-pre-point (- (point) 1))
736 (or (eq (char-syntax (char-after flyspell-pre-point)) ?w)
737 (and (not (string= "" ispell-otherchars))
738 (string-match
739 ispell-otherchars
740 (buffer-substring-no-properties
741 flyspell-pre-point (1+ flyspell-pre-point))))))
742 (= flyspell-pre-point (point))
743 (= flyspell-pre-point (+ (point) 1)))
744 nil)
745 ((and (symbolp this-command)
746 (not executing-kbd-macro)
747 (or (get this-command 'flyspell-delayed)
748 (and (get this-command 'flyspell-deplacement)
749 (eq flyspell-previous-command this-command)))
750 (or (= (current-column) 0)
751 (= (current-column) flyspell-pre-column)
752 ;; If other post-command-hooks change the buffer,
753 ;; flyspell-pre-point can lie past eob (bug#468).
754 (null (char-after flyspell-pre-point))
755 (or (eq (char-syntax (char-after flyspell-pre-point)) ?w)
756 (and (not (string= "" ispell-otherchars))
757 (string-match
758 ispell-otherchars
759 (buffer-substring-no-properties
760 flyspell-pre-point (1+ flyspell-pre-point)))))))
761 nil)
762 ((not (eq (current-buffer) flyspell-pre-buffer))
764 ((not (and (numberp flyspell-word-cache-start)
765 (numberp flyspell-word-cache-end)))
768 (or (< flyspell-pre-point flyspell-word-cache-start)
769 (> flyspell-pre-point flyspell-word-cache-end))))))
771 ;;*---------------------------------------------------------------------*/
772 ;;* The flyspell after-change-hook, store the change position. In */
773 ;;* the post command hook, we will check, if the word at this */
774 ;;* position has to be spell checked. */
775 ;;*---------------------------------------------------------------------*/
776 (defvar flyspell-changes nil)
777 (make-variable-buffer-local 'flyspell-changes)
779 ;;*---------------------------------------------------------------------*/
780 ;;* flyspell-after-change-function ... */
781 ;;*---------------------------------------------------------------------*/
782 (defun flyspell-after-change-function (start stop len)
783 "Save the current buffer and point for Flyspell's post-command hook."
784 (push (cons start stop) flyspell-changes))
786 ;;*---------------------------------------------------------------------*/
787 ;;* flyspell-check-changed-word-p ... */
788 ;;*---------------------------------------------------------------------*/
789 (defun flyspell-check-changed-word-p (start stop)
790 "Return non-nil when the changed word has to be checked.
791 The answer depends of several criteria.
792 Mostly we check word delimiters."
793 (not (and (not (and (memq (char-after start) '(?\n ? )) (> stop start)))
794 (numberp flyspell-pre-point)
796 (and (>= flyspell-pre-point start) (<= flyspell-pre-point stop))
797 (let ((pos (point)))
798 (or (>= pos start) (<= pos stop) (= pos (1+ stop))))))))
800 ;;*---------------------------------------------------------------------*/
801 ;;* flyspell-check-word-p ... */
802 ;;*---------------------------------------------------------------------*/
803 (defun flyspell-check-word-p ()
804 "Return t when the word at `point' has to be checked.
805 The answer depends of several criteria.
806 Mostly we check word delimiters."
807 (let ((ispell-otherchars (ispell-get-otherchars)))
808 (cond
809 ((<= (- (point-max) 1) (point-min))
810 ;; The buffer is not filled enough.
811 nil)
812 ((and (and (> (current-column) 0)
813 (not (eq (current-column) flyspell-pre-column)))
814 (save-excursion
815 (backward-char 1)
816 (and (looking-at (flyspell-get-not-casechars))
817 (or (string= "" ispell-otherchars)
818 (not (looking-at ispell-otherchars)))
819 (or flyspell-consider-dash-as-word-delimiter-flag
820 (not (looking-at "-"))))))
821 ;; Yes because we have reached or typed a word delimiter.
823 ((symbolp this-command)
824 (cond
825 ((get this-command 'flyspell-deplacement)
826 (not (eq flyspell-previous-command this-command)))
827 ((get this-command 'flyspell-delayed)
828 ;; The current command is not delayed, that
829 ;; is that we must check the word now.
830 (and (not unread-command-events)
831 (sit-for flyspell-delay)))
832 (t t)))
833 (t t))))
835 ;;*---------------------------------------------------------------------*/
836 ;;* flyspell-debug-signal-no-check ... */
837 ;;*---------------------------------------------------------------------*/
838 (defun flyspell-debug-signal-no-check (msg obj)
839 (setq debug-on-error t)
840 (with-current-buffer (get-buffer-create "*flyspell-debug*")
841 (erase-buffer)
842 (insert "NO-CHECK:\n")
843 (insert (format " %S : %S\n" msg obj))))
845 ;;*---------------------------------------------------------------------*/
846 ;;* flyspell-debug-signal-pre-word-checked ... */
847 ;;*---------------------------------------------------------------------*/
848 (defun flyspell-debug-signal-pre-word-checked ()
849 (setq debug-on-error t)
850 (with-current-buffer (get-buffer-create "*flyspell-debug*")
851 (insert "PRE-WORD:\n")
852 (insert (format " pre-point : %S\n" flyspell-pre-point))
853 (insert (format " pre-buffer : %S\n" flyspell-pre-buffer))
854 (insert (format " cache-start: %S\n" flyspell-word-cache-start))
855 (insert (format " cache-end : %S\n" flyspell-word-cache-end))
856 (goto-char (point-max))))
858 ;;*---------------------------------------------------------------------*/
859 ;;* flyspell-debug-signal-word-checked ... */
860 ;;*---------------------------------------------------------------------*/
861 (defun flyspell-debug-signal-word-checked ()
862 (setq debug-on-error t)
863 (let ((ispell-otherchars (ispell-get-otherchars))
864 (oldbuf (current-buffer))
865 (point (point)))
866 (with-current-buffer (get-buffer-create "*flyspell-debug*")
867 (insert
868 "WORD:\n"
869 (format " this-cmd : %S\n" this-command)
870 (format " delayed : %S\n" (and (symbolp this-command)
871 (get this-command
872 'flyspell-delayed)))
873 (format " point : %S\n" point)
874 (format " prev-char : [%c] %S\n"
875 (with-current-buffer oldbuf
876 (if (bobp) ?\ (char-before)))
877 (with-current-buffer oldbuf
878 (if (bobp)
880 (save-excursion
881 (backward-char 1)
882 (and (looking-at (flyspell-get-not-casechars))
883 (or (string= "" ispell-otherchars)
884 (not (looking-at ispell-otherchars)))
885 (or flyspell-consider-dash-as-word-delimiter-flag
886 (not (looking-at "\\-")))
887 2)))))
888 (format " because : %S\n"
889 (cond
890 ((not (and (symbolp this-command)
891 (get this-command 'flyspell-delayed)))
892 ;; The current command is not delayed, that
893 ;; is that we must check the word now.
894 'not-delayed)
895 ((with-current-buffer oldbuf
896 (if (bobp)
898 (save-excursion
899 (backward-char 1)
900 (and (looking-at (flyspell-get-not-casechars))
901 (or (string= "" ispell-otherchars)
902 (not (looking-at ispell-otherchars)))
903 (or flyspell-consider-dash-as-word-delimiter-flag
904 (not (looking-at "\\-")))))))
905 ;; Yes because we have reached or typed a word delimiter.
906 'separator)
907 ((not (integerp flyspell-delay))
908 ;; Yes because the user set up a no-delay configuration.
909 'no-delay)
911 'sit-for))))
912 (goto-char (point-max)))))
914 ;;*---------------------------------------------------------------------*/
915 ;;* flyspell-debug-signal-changed-checked ... */
916 ;;*---------------------------------------------------------------------*/
917 (defun flyspell-debug-signal-changed-checked ()
918 (setq debug-on-error t)
919 (let ((point (point)))
920 (with-current-buffer (get-buffer-create "*flyspell-debug*")
921 (insert "CHANGED WORD:\n")
922 (insert (format " point : %S\n" point))
923 (goto-char (point-max)))))
925 ;;*---------------------------------------------------------------------*/
926 ;;* flyspell-post-command-hook ... */
927 ;;* ------------------------------------------------------------- */
928 ;;* It is possible that we check several words: */
929 ;;* 1- the current word is checked if the predicate */
930 ;;* FLYSPELL-CHECK-WORD-P is true */
931 ;;* 2- the word that used to be the current word before the */
932 ;;* THIS-COMMAND is checked if: */
933 ;;* a- the previous word is different from the current word */
934 ;;* b- the previous word has not just been checked by the */
935 ;;* previous FLYSPELL-POST-COMMAND-HOOK */
936 ;;* 3- the words changed by the THIS-COMMAND that are neither the */
937 ;;* previous word nor the current word */
938 ;;*---------------------------------------------------------------------*/
939 (defun flyspell-post-command-hook ()
940 "The `post-command-hook' used by flyspell to check a word on-the-fly."
941 (interactive)
942 (when flyspell-mode
943 (with-local-quit
944 (let ((command this-command)
945 ;; Prevent anything we do from affecting the mark.
946 deactivate-mark)
947 (if (flyspell-check-pre-word-p)
948 (with-current-buffer flyspell-pre-buffer
949 '(flyspell-debug-signal-pre-word-checked)
950 (save-excursion
951 (goto-char flyspell-pre-point)
952 (flyspell-word))))
953 (if (flyspell-check-word-p)
954 (progn
955 '(flyspell-debug-signal-word-checked)
956 ;; FIXME: This should be asynchronous!
957 (flyspell-word)
958 ;; we remember which word we have just checked.
959 ;; this will be used next time we will check a word
960 ;; to compare the next current word with the word
961 ;; that has been registered in the pre-command-hook
962 ;; that is these variables are used within the predicate
963 ;; FLYSPELL-CHECK-PRE-WORD-P
964 (setq flyspell-pre-pre-buffer (current-buffer))
965 (setq flyspell-pre-pre-point (point)))
966 (progn
967 (setq flyspell-pre-pre-buffer nil)
968 (setq flyspell-pre-pre-point nil)
969 ;; when a word is not checked because of a delayed command
970 ;; we do not disable the ispell cache.
971 (if (and (symbolp this-command)
972 (get this-command 'flyspell-delayed))
973 (progn
974 (setq flyspell-word-cache-end -1)
975 (setq flyspell-word-cache-result '_)))))
976 (while (and (not (input-pending-p)) (consp flyspell-changes))
977 (let ((start (car (car flyspell-changes)))
978 (stop (cdr (car flyspell-changes))))
979 (if (flyspell-check-changed-word-p start stop)
980 (save-excursion
981 '(flyspell-debug-signal-changed-checked)
982 (goto-char start)
983 (flyspell-word)))
984 (setq flyspell-changes (cdr flyspell-changes))))
985 (setq flyspell-previous-command command)))))
987 ;;*---------------------------------------------------------------------*/
988 ;;* flyspell-notify-misspell ... */
989 ;;*---------------------------------------------------------------------*/
990 (defun flyspell-notify-misspell (word poss)
991 (let ((replacements (if (stringp poss)
992 poss
993 (if flyspell-sort-corrections
994 (sort (car (cdr (cdr poss))) 'string<)
995 (car (cdr (cdr poss)))))))
996 (if flyspell-issue-message-flag
997 (message "misspelling `%s' %S" word replacements))))
999 ;;*---------------------------------------------------------------------*/
1000 ;;* flyspell-word-search-backward ... */
1001 ;;*---------------------------------------------------------------------*/
1002 (defun flyspell-word-search-backward (word bound &optional ignore-case)
1003 (save-excursion
1004 (let ((r '())
1005 (inhibit-point-motion-hooks t)
1007 (while (and (not r) (setq p (search-backward word bound t)))
1008 (let ((lw (flyspell-get-word)))
1009 (if (and (consp lw)
1010 (if ignore-case
1011 (string-equal (downcase (car lw)) (downcase word))
1012 (string-equal (car lw) word)))
1013 (setq r p)
1014 (goto-char p))))
1015 r)))
1017 ;;*---------------------------------------------------------------------*/
1018 ;;* flyspell-word-search-forward ... */
1019 ;;*---------------------------------------------------------------------*/
1020 (defun flyspell-word-search-forward (word bound)
1021 (save-excursion
1022 (let ((r '())
1023 (inhibit-point-motion-hooks t)
1025 (while (and (not r) (setq p (search-forward word bound t)))
1026 (let ((lw (flyspell-get-word)))
1027 (if (and (consp lw) (string-equal (car lw) word))
1028 (setq r p)
1029 (goto-char (1+ p)))))
1030 r)))
1032 ;;*---------------------------------------------------------------------*/
1033 ;;* flyspell-word ... */
1034 ;;*---------------------------------------------------------------------*/
1035 (defun flyspell-word (&optional following known-misspelling)
1036 "Spell check a word.
1037 If the optional argument FOLLOWING, or, when called interactively
1038 `ispell-following-word', is non-nil, checks the following (rather
1039 than preceding) word when the cursor is not over a word. If
1040 optional argument KNOWN-MISSPELLING is non nil considers word a
1041 misspelling and skips redundant spell-checking step."
1042 (interactive (list ispell-following-word))
1043 (ispell-set-spellchecker-params) ; Initialize variables and dicts alists
1044 (save-excursion
1045 ;; use the correct dictionary
1046 (flyspell-accept-buffer-local-defs)
1047 (let* ((cursor-location (point))
1048 (flyspell-word (flyspell-get-word following))
1049 start end poss word ispell-filter)
1050 (if (or (eq flyspell-word nil)
1051 (and (fboundp flyspell-generic-check-word-predicate)
1052 (not (funcall flyspell-generic-check-word-predicate))))
1054 (progn
1055 ;; destructure return flyspell-word info list.
1056 (setq start (car (cdr flyspell-word))
1057 end (car (cdr (cdr flyspell-word)))
1058 word (car flyspell-word))
1059 ;; before checking in the directory, we check for doublons.
1060 (cond
1061 ((and (or (not (eq ispell-parser 'tex))
1062 (and (> start (point-min))
1063 (not (memq (char-after (1- start)) '(?\} ?\\)))))
1064 flyspell-mark-duplications-flag
1065 (not (catch 'exception
1066 (let ((dict (or ispell-local-dictionary
1067 ispell-dictionary)))
1068 (dolist (except flyspell-mark-duplications-exceptions)
1069 (and (or (null (car except))
1070 (and (stringp dict)
1071 (string-match (car except) dict)))
1072 (member (downcase word) (cdr except))
1073 (throw 'exception t))))))
1074 (save-excursion
1075 (goto-char start)
1076 (let* ((bound
1077 (- start
1078 (- end start)
1079 (- (skip-chars-backward " \t\n\f"))))
1080 (p (when (>= bound (point-min))
1081 (flyspell-word-search-backward word bound t))))
1082 (and p (/= p start)))))
1083 ;; yes, this is a doublon
1084 (flyspell-highlight-incorrect-region start end 'doublon)
1085 nil)
1086 ((and (eq flyspell-word-cache-start start)
1087 (eq flyspell-word-cache-end end)
1088 (string-equal flyspell-word-cache-word word))
1089 ;; this word had been already checked, we skip
1090 flyspell-word-cache-result)
1091 ((and (eq ispell-parser 'tex)
1092 (flyspell-tex-command-p flyspell-word))
1093 ;; this is a correct word (because a tex command)
1094 (flyspell-unhighlight-at start)
1095 (if (> end start)
1096 (flyspell-unhighlight-at (- end 1)))
1099 ;; we setup the cache
1100 (setq flyspell-word-cache-start start)
1101 (setq flyspell-word-cache-end end)
1102 (setq flyspell-word-cache-word word)
1103 ;; now check spelling of word.
1104 (if (not known-misspelling)
1105 (progn
1106 (ispell-send-string "%\n")
1107 ;; put in verbose mode
1108 (ispell-send-string (concat "^" word "\n"))
1109 ;; we mark the ispell process so it can be killed
1110 ;; when emacs is exited without query
1111 (if (featurep 'xemacs)
1112 (process-kill-without-query ispell-process)
1113 (set-process-query-on-exit-flag ispell-process nil))
1114 ;; Wait until ispell has processed word.
1115 (while (progn
1116 (accept-process-output ispell-process)
1117 (not (string= "" (car ispell-filter)))))
1118 ;; (ispell-send-string "!\n")
1119 ;; back to terse mode.
1120 ;; Remove leading empty element
1121 (setq ispell-filter (cdr ispell-filter))
1122 ;; ispell process should return something after word is sent.
1123 ;; Tag word as valid (i.e., skip) otherwise
1124 (or ispell-filter
1125 (setq ispell-filter '(*)))
1126 (if (consp ispell-filter)
1127 (setq poss (ispell-parse-output (car ispell-filter)))))
1128 ;; Else, this was a known misspelling to begin with, and
1129 ;; we should forge an ispell return value.
1130 (setq poss (list word 1 nil nil)))
1131 (let ((res (cond ((eq poss t)
1132 ;; correct
1133 (setq flyspell-word-cache-result t)
1134 (flyspell-unhighlight-at start)
1135 (if (> end start)
1136 (flyspell-unhighlight-at (- end 1)))
1138 ((and (stringp poss) flyspell-highlight-flag)
1139 ;; correct
1140 (setq flyspell-word-cache-result t)
1141 (flyspell-unhighlight-at start)
1142 (if (> end start)
1143 (flyspell-unhighlight-at (- end 1)))
1145 ((null poss)
1146 (setq flyspell-word-cache-result t)
1147 (flyspell-unhighlight-at start)
1148 (if (> end start)
1149 (flyspell-unhighlight-at (- end 1)))
1151 ((or (and (< flyspell-duplicate-distance 0)
1152 (or (save-excursion
1153 (goto-char start)
1154 (flyspell-word-search-backward
1155 word
1156 (point-min)))
1157 (save-excursion
1158 (goto-char end)
1159 (flyspell-word-search-forward
1160 word
1161 (point-max)))))
1162 (and (> flyspell-duplicate-distance 0)
1163 (or (save-excursion
1164 (goto-char start)
1165 (flyspell-word-search-backward
1166 word
1167 (- start
1168 flyspell-duplicate-distance)))
1169 (save-excursion
1170 (goto-char end)
1171 (flyspell-word-search-forward
1172 word
1173 (+ end
1174 flyspell-duplicate-distance))))))
1175 ;; This is a misspelled word which occurs
1176 ;; twice within flyspell-duplicate-distance.
1177 (setq flyspell-word-cache-result nil)
1178 (if flyspell-highlight-flag
1179 (flyspell-highlight-duplicate-region
1180 start end poss)
1181 (message "duplicate `%s'" word))
1182 nil)
1184 (setq flyspell-word-cache-result nil)
1185 ;; Highlight the location as incorrect,
1186 ;; including offset specified in POSS.
1187 (if flyspell-highlight-flag
1188 (flyspell-highlight-incorrect-region
1189 (if (and (consp poss)
1190 (integerp (nth 1 poss)))
1191 (+ start (nth 1 poss) -1)
1192 start)
1193 end poss)
1194 (flyspell-notify-misspell word poss))
1195 nil))))
1196 ;; return to original location
1197 (goto-char cursor-location)
1198 (if ispell-quit (setq ispell-quit nil))
1199 res))))))))
1201 ;;*---------------------------------------------------------------------*/
1202 ;;* flyspell-math-tex-command-p ... */
1203 ;;* ------------------------------------------------------------- */
1204 ;;* This function uses the texmathp package to check if point */
1205 ;;* is within a TeX math environment. `texmathp' can yield errors */
1206 ;;* if the document is currently not valid TeX syntax. */
1207 ;;*---------------------------------------------------------------------*/
1208 (defun flyspell-math-tex-command-p ()
1209 (when (fboundp 'texmathp)
1210 (if flyspell-check-tex-math-command
1212 (condition-case nil
1213 (texmathp)
1214 (error nil)))))
1216 ;;*---------------------------------------------------------------------*/
1217 ;;* flyspell-tex-command-p ... */
1218 ;;*---------------------------------------------------------------------*/
1219 (defun flyspell-tex-command-p (word)
1220 "Return t if WORD is a TeX command."
1221 (or (save-excursion
1222 (let ((b (car (cdr word))))
1223 (and (re-search-backward "\\\\" (- (point) 100) t)
1224 (or (= (match-end 0) b)
1225 (and (goto-char (match-end 0))
1226 (looking-at flyspell-tex-command-regexp)
1227 (>= (match-end 0) b))))))
1228 (flyspell-math-tex-command-p)))
1230 (defalias 'flyspell-get-casechars 'ispell-get-casechars)
1231 (defalias 'flyspell-get-not-casechars 'ispell-get-not-casechars)
1233 ;;*---------------------------------------------------------------------*/
1234 ;;* flyspell-get-word ... */
1235 ;;*---------------------------------------------------------------------*/
1236 (defun flyspell-get-word (&optional following extra-otherchars)
1237 "Return the word for spell-checking according to Ispell syntax.
1238 Optional argument FOLLOWING non-nil means to get the following
1239 \(rather than preceding) word when the cursor is not over a word.
1240 Optional second argument EXTRA-OTHERCHARS is a regexp of characters
1241 that may be included as part of a word (see `ispell-dictionary-alist')."
1242 (let* ((flyspell-casechars (flyspell-get-casechars))
1243 (flyspell-not-casechars (flyspell-get-not-casechars))
1244 (ispell-otherchars (ispell-get-otherchars))
1245 (ispell-many-otherchars-p (ispell-get-many-otherchars-p))
1246 (word-regexp (concat flyspell-casechars
1247 "+\\("
1248 (if (not (string= "" ispell-otherchars))
1249 (concat ispell-otherchars "?"))
1250 (if extra-otherchars
1251 (concat extra-otherchars "?"))
1252 flyspell-casechars
1253 "+\\)"
1254 (if (or ispell-many-otherchars-p
1255 extra-otherchars)
1256 "*" "?")))
1257 did-it-once prevpt
1258 start end word)
1259 ;; find the word
1260 (if (not (looking-at flyspell-casechars))
1261 (if following
1262 (re-search-forward flyspell-casechars nil t)
1263 (re-search-backward flyspell-casechars nil t)))
1264 ;; move to front of word
1265 (re-search-backward flyspell-not-casechars nil 'start)
1266 (while (and (or (and (not (string= "" ispell-otherchars))
1267 (looking-at ispell-otherchars))
1268 (and extra-otherchars (looking-at extra-otherchars)))
1269 (not (bobp))
1270 (or (not did-it-once)
1271 ispell-many-otherchars-p)
1272 (not (eq prevpt (point))))
1273 (if (and extra-otherchars (looking-at extra-otherchars))
1274 (progn
1275 (backward-char 1)
1276 (if (looking-at flyspell-casechars)
1277 (re-search-backward flyspell-not-casechars nil 'move)))
1278 (setq did-it-once t
1279 prevpt (point))
1280 (backward-char 1)
1281 (if (looking-at flyspell-casechars)
1282 (re-search-backward flyspell-not-casechars nil 'move)
1283 (backward-char -1))))
1284 ;; Now mark the word and save to string.
1285 (if (not (re-search-forward word-regexp nil t))
1287 (progn
1288 (setq start (match-beginning 0)
1289 end (point)
1290 word (buffer-substring-no-properties start end))
1291 (list word start end)))))
1293 ;;*---------------------------------------------------------------------*/
1294 ;;* flyspell-small-region ... */
1295 ;;*---------------------------------------------------------------------*/
1296 (defun flyspell-small-region (beg end)
1297 "Flyspell text between BEG and END."
1298 (save-excursion
1299 (if (> beg end)
1300 (let ((old beg))
1301 (setq beg end)
1302 (setq end old)))
1303 (goto-char beg)
1304 (let ((count 0))
1305 (while (< (point) end)
1306 (if (and flyspell-issue-message-flag (= count 100))
1307 (progn
1308 (message "Spell Checking...%d%%"
1309 (* 100 (/ (float (- (point) beg)) (- end beg))))
1310 (setq count 0))
1311 (setq count (+ 1 count)))
1312 (flyspell-word)
1313 (sit-for 0)
1314 (let ((cur (point)))
1315 (forward-word 1)
1316 (if (and (< (point) end) (> (point) (+ cur 1)))
1317 (backward-char 1)))))
1318 (backward-char 1)
1319 (if flyspell-issue-message-flag (message "Spell Checking completed."))
1320 (flyspell-word)))
1322 ;;*---------------------------------------------------------------------*/
1323 ;;* flyspell-external-ispell-process ... */
1324 ;;*---------------------------------------------------------------------*/
1325 (defvar flyspell-external-ispell-process '()
1326 "The external Flyspell Ispell process.")
1328 ;;*---------------------------------------------------------------------*/
1329 ;;* flyspell-external-ispell-buffer ... */
1330 ;;*---------------------------------------------------------------------*/
1331 (defvar flyspell-external-ispell-buffer '())
1332 (defvar flyspell-large-region-buffer '())
1333 (defvar flyspell-large-region-beg (point-min))
1334 (defvar flyspell-large-region-end (point-max))
1336 ;;*---------------------------------------------------------------------*/
1337 ;;* flyspell-external-point-words ... */
1338 ;;*---------------------------------------------------------------------*/
1339 (defun flyspell-external-point-words ()
1340 "Mark words from a buffer listing incorrect words in order of appearance.
1341 The list of incorrect words should be in `flyspell-external-ispell-buffer'.
1342 \(We finish by killing that buffer and setting the variable to nil.)
1343 The buffer to mark them in is `flyspell-large-region-buffer'."
1344 (let (words-not-found
1345 (ispell-otherchars (ispell-get-otherchars))
1346 (buffer-scan-pos flyspell-large-region-beg)
1347 case-fold-search)
1348 (with-current-buffer flyspell-external-ispell-buffer
1349 (goto-char (point-min))
1350 ;; Loop over incorrect words, in the order they were reported,
1351 ;; which is also the order they appear in the buffer being checked.
1352 (while (re-search-forward "\\([^\n]+\\)\n" nil t)
1353 ;; Bind WORD to the next one.
1354 (let ((word (match-string 1)) (wordpos (point)))
1355 ;; Here there used to be code to see if WORD is the same
1356 ;; as the previous iteration, and count the number of consecutive
1357 ;; identical words, and the loop below would search for that many.
1358 ;; That code seemed to be incorrect, and on principle, should
1359 ;; be unnecessary too. -- rms.
1360 (if flyspell-issue-message-flag
1361 (message "Spell Checking...%d%% [%s]"
1362 (* 100 (/ (float (point)) (point-max)))
1363 word))
1364 (with-current-buffer flyspell-large-region-buffer
1365 (goto-char buffer-scan-pos)
1366 (let ((keep t))
1367 ;; Iterate on string search until string is found as word,
1368 ;; not as substring.
1369 (while keep
1370 (if (search-forward word
1371 flyspell-large-region-end t)
1372 (let* ((found-list
1373 (save-excursion
1374 ;; Move back into the match
1375 ;; so flyspell-get-word will find it.
1376 (forward-char -1)
1377 (flyspell-get-word)))
1378 (found (car found-list))
1379 (found-length (length found))
1380 (misspell-length (length word)))
1381 (when (or
1382 ;; Size matches, we really found it.
1383 (= found-length misspell-length)
1384 ;; Matches as part of a boundary-char separated
1385 ;; word.
1386 (member word
1387 (split-string found ispell-otherchars))
1388 ;; Misspelling has higher length than
1389 ;; what flyspell considers the word.
1390 ;; Caused by boundary-chars mismatch.
1391 ;; Validating seems safe.
1392 (< found-length misspell-length)
1393 ;; ispell treats beginning of some TeX
1394 ;; commands as nroff control sequences
1395 ;; and strips them in the list of
1396 ;; misspelled words thus giving a
1397 ;; non-existent word. Skip if ispell
1398 ;; is used, string is a TeX command
1399 ;; (char before beginning of word is
1400 ;; backslash) and none of the previous
1401 ;; conditions match.
1402 (and (not ispell-really-aspell)
1403 (save-excursion
1404 (goto-char (- (nth 1 found-list) 1))
1405 (if (looking-at "[\\]" )
1407 nil))))
1408 (setq keep nil)
1409 (flyspell-word nil t)
1410 ;; Search for next misspelled word will begin from
1411 ;; end of last validated match.
1412 (setq buffer-scan-pos (point))))
1413 ;; Record if misspelling is not found and try new one
1414 (add-to-list 'words-not-found
1415 (concat " -> " word " - "
1416 (int-to-string wordpos)))
1417 (setq keep nil)))))))
1418 ;; we are done
1419 (if flyspell-issue-message-flag (message "Spell Checking completed.")))
1420 ;; Warn about not found misspellings
1421 (dolist (word words-not-found)
1422 (message "%s: word not found" word))
1423 ;; Kill and forget the buffer with the list of incorrect words.
1424 (kill-buffer flyspell-external-ispell-buffer)
1425 (setq flyspell-external-ispell-buffer nil)))
1427 ;;*---------------------------------------------------------------------*/
1428 ;;* flyspell-process-localwords ... */
1429 ;;* ------------------------------------------------------------- */
1430 ;;* This function is used to prevent marking of words explicitly */
1431 ;;* declared correct. */
1432 ;;*---------------------------------------------------------------------*/
1433 (defun flyspell-process-localwords (misspellings-buffer)
1434 (let ((localwords ispell-buffer-session-localwords)
1435 case-fold-search
1436 (ispell-casechars (ispell-get-casechars)))
1437 ;; Get localwords from the original buffer
1438 (save-excursion
1439 (goto-char (point-min))
1440 ;; Localwords parsing copied from ispell.el.
1441 (while (search-forward ispell-words-keyword nil t)
1442 (let ((end (point-at-eol))
1443 string)
1444 ;; buffer-local words separated by a space, and can contain
1445 ;; any character other than a space. Not rigorous enough.
1446 (while (re-search-forward " *\\([^ ]+\\)" end t)
1447 (setq string (buffer-substring-no-properties (match-beginning 1)
1448 (match-end 1)))
1449 ;; This can fail when string contains a word with invalid chars.
1450 ;; Error handling needs to be added between Ispell and Emacs.
1451 (if (and (< 1 (length string))
1452 (equal 0 (string-match ispell-casechars string)))
1453 (push string localwords))))))
1454 ;; Remove localwords matches from misspellings-buffer.
1455 ;; The usual mechanism of communicating the local words to ispell
1456 ;; does not affect the special ispell process used by
1457 ;; flyspell-large-region.
1458 (with-current-buffer misspellings-buffer
1459 (save-excursion
1460 (dolist (word localwords)
1461 (goto-char (point-min))
1462 (let ((regexp (concat "^" word "\n")))
1463 (while (re-search-forward regexp nil t)
1464 (delete-region (match-beginning 0) (match-end 0)))))))))
1466 ;;* ---------------------------------------------------------------
1467 ;;* flyspell-check-region-doublons
1468 ;;* ---------------------------------------------------------------
1469 (defun flyspell-check-region-doublons (beg end)
1470 "Check for adjacent duplicated words (doublons) in the given region."
1471 (save-excursion
1472 (goto-char beg)
1473 (flyspell-word) ; Make sure current word is checked
1474 (backward-word 1)
1475 (while (and (< (point) end)
1476 (re-search-forward "\\<\\(\\w+\\)\\>[ \n\t\f]+\\1\\>"
1477 end 'move))
1478 (flyspell-word)
1479 (backward-word 1))
1480 (flyspell-word)))
1482 ;;*---------------------------------------------------------------------*/
1483 ;;* flyspell-large-region ... */
1484 ;;*---------------------------------------------------------------------*/
1485 (defun flyspell-large-region (beg end)
1486 (let* ((curbuf (current-buffer))
1487 (buffer (get-buffer-create "*flyspell-region*")))
1488 (setq flyspell-external-ispell-buffer buffer)
1489 (setq flyspell-large-region-buffer curbuf)
1490 (setq flyspell-large-region-beg beg)
1491 (setq flyspell-large-region-end end)
1492 (flyspell-accept-buffer-local-defs)
1493 (set-buffer buffer)
1494 (erase-buffer)
1495 ;; this is done, we can start checking...
1496 (if flyspell-issue-message-flag (message "Checking region..."))
1497 (set-buffer curbuf)
1498 (ispell-set-spellchecker-params) ; Initialize variables and dicts alists
1499 ;; Local dictionary becomes the global dictionary in use.
1500 (setq ispell-current-dictionary
1501 (or ispell-local-dictionary ispell-dictionary))
1502 (setq ispell-current-personal-dictionary
1503 (or ispell-local-pdict ispell-personal-dictionary))
1504 (let ((args (ispell-get-ispell-args))
1505 (encoding (ispell-get-coding-system))
1507 (if (and ispell-current-dictionary ; use specified dictionary
1508 (not (member "-d" args))) ; only define if not overridden
1509 (setq args
1510 (append (list "-d" ispell-current-dictionary) args)))
1511 (if ispell-current-personal-dictionary ; use specified pers dict
1512 (setq args
1513 (append args
1514 (list "-p"
1515 (expand-file-name
1516 ispell-current-personal-dictionary)))))
1518 ;; Check for extended character mode
1519 (let ((extended-char-mode (ispell-get-extended-character-mode)))
1520 (and extended-char-mode ; ~ extended character mode
1521 (string-match "[^~]+$" extended-char-mode)
1522 (add-to-list 'args (concat "-T" (match-string 0 extended-char-mode)))))
1524 ;; Add ispell-extra-args
1525 (setq args (append args ispell-extra-args))
1527 ;; If we are using recent aspell or hunspell, make sure we use the right encoding
1528 ;; for communication. ispell or older aspell/hunspell does not support this
1529 (if ispell-encoding8-command
1530 (setq args
1531 (append args
1532 (if ispell-really-hunspell
1533 (list ispell-encoding8-command
1534 (upcase (symbol-name encoding)))
1535 (list (concat ispell-encoding8-command
1536 (symbol-name encoding)))))))
1538 (let ((process-coding-system-alist (list (cons "\\.*" encoding))))
1539 (setq c (apply 'ispell-call-process-region beg
1541 ispell-program-name
1543 buffer
1545 (if ispell-really-aspell "list" "-l")
1546 args)))
1547 (if (eq c 0)
1548 (progn
1549 (flyspell-process-localwords buffer)
1550 (with-current-buffer curbuf
1551 (flyspell-delete-region-overlays beg end)
1552 (flyspell-check-region-doublons beg end))
1553 (flyspell-external-point-words))
1554 (error "Can't check region")))))
1556 ;;*---------------------------------------------------------------------*/
1557 ;;* flyspell-region ... */
1558 ;;* ------------------------------------------------------------- */
1559 ;;* Because `ispell -a' is too slow, it is not possible to use */
1560 ;;* it on large region. Then, when ispell is invoked on a large */
1561 ;;* text region, a new `ispell -l' process is spawned. The */
1562 ;;* pointed out words are then searched in the region a checked with */
1563 ;;* regular flyspell means. */
1564 ;;*---------------------------------------------------------------------*/
1565 ;;;###autoload
1566 (defun flyspell-region (beg end)
1567 "Flyspell text between BEG and END."
1568 (interactive "r")
1569 (ispell-set-spellchecker-params) ; Initialize variables and dicts alists
1570 (if (= beg end)
1572 (save-excursion
1573 (if (> beg end)
1574 (let ((old beg))
1575 (setq beg end)
1576 (setq end old)))
1577 (if (and flyspell-large-region (> (- end beg) flyspell-large-region))
1578 (flyspell-large-region beg end)
1579 (flyspell-small-region beg end)))))
1581 ;;*---------------------------------------------------------------------*/
1582 ;;* flyspell-buffer ... */
1583 ;;*---------------------------------------------------------------------*/
1584 ;;;###autoload
1585 (defun flyspell-buffer ()
1586 "Flyspell whole buffer."
1587 (interactive)
1588 (flyspell-region (point-min) (point-max)))
1590 ;;*---------------------------------------------------------------------*/
1591 ;;* old next error position ... */
1592 ;;*---------------------------------------------------------------------*/
1593 (defvar flyspell-old-buffer-error nil)
1594 (defvar flyspell-old-pos-error nil)
1596 ;;*---------------------------------------------------------------------*/
1597 ;;* flyspell-goto-next-error ... */
1598 ;;*---------------------------------------------------------------------*/
1599 (defun flyspell-goto-next-error ()
1600 "Go to the next previously detected error.
1601 In general FLYSPELL-GOTO-NEXT-ERROR must be used after
1602 FLYSPELL-BUFFER."
1603 (interactive)
1604 (let ((pos (point))
1605 (max (point-max)))
1606 (if (and (eq (current-buffer) flyspell-old-buffer-error)
1607 (eq pos flyspell-old-pos-error))
1608 (progn
1609 (if (= flyspell-old-pos-error max)
1610 ;; goto beginning of buffer
1611 (progn
1612 (message "Restarting from beginning of buffer")
1613 (goto-char (point-min)))
1614 (forward-word 1))
1615 (setq pos (point))))
1616 ;; seek the next error
1617 (while (and (< pos max)
1618 (let ((ovs (overlays-at pos))
1619 (r '()))
1620 (while (and (not r) (consp ovs))
1621 (if (flyspell-overlay-p (car ovs))
1622 (setq r t)
1623 (setq ovs (cdr ovs))))
1624 (not r)))
1625 (setq pos (1+ pos)))
1626 ;; save the current location for next invocation
1627 (setq flyspell-old-pos-error pos)
1628 (setq flyspell-old-buffer-error (current-buffer))
1629 (goto-char pos)
1630 (if (= pos max)
1631 (message "No more miss-spelled word!"))))
1633 ;;*---------------------------------------------------------------------*/
1634 ;;* flyspell-overlay-p ... */
1635 ;;*---------------------------------------------------------------------*/
1636 (defun flyspell-overlay-p (o)
1637 "Return true if O is an overlay used by flyspell."
1638 (and (overlayp o) (overlay-get o 'flyspell-overlay)))
1640 ;;*---------------------------------------------------------------------*/
1641 ;;* flyspell-delete-region-overlays, flyspell-delete-all-overlays */
1642 ;;* ------------------------------------------------------------- */
1643 ;;* Remove overlays introduced by flyspell. */
1644 ;;*---------------------------------------------------------------------*/
1645 (defun flyspell-delete-region-overlays (beg end)
1646 "Delete overlays used by flyspell in a given region."
1647 (if (featurep 'emacs)
1648 (remove-overlays beg end 'flyspell-overlay t)
1649 ;; XEmacs does not have `remove-overlays'
1650 (let ((l (overlays-in beg end)))
1651 (while (consp l)
1652 (progn
1653 (if (flyspell-overlay-p (car l))
1654 (delete-overlay (car l)))
1655 (setq l (cdr l)))))))
1657 (defun flyspell-delete-all-overlays ()
1658 "Delete all the overlays used by flyspell."
1659 (flyspell-delete-region-overlays (point-min) (point-max)))
1661 ;;*---------------------------------------------------------------------*/
1662 ;;* flyspell-unhighlight-at ... */
1663 ;;*---------------------------------------------------------------------*/
1664 (defun flyspell-unhighlight-at (pos)
1665 "Remove the flyspell overlay that are located at POS."
1666 (if flyspell-persistent-highlight
1667 (let ((overlays (overlays-at pos)))
1668 (while (consp overlays)
1669 (if (flyspell-overlay-p (car overlays))
1670 (delete-overlay (car overlays)))
1671 (setq overlays (cdr overlays))))
1672 (if (flyspell-overlay-p flyspell-overlay)
1673 (delete-overlay flyspell-overlay))))
1675 ;;*---------------------------------------------------------------------*/
1676 ;;* flyspell-properties-at-p ... */
1677 ;;* ------------------------------------------------------------- */
1678 ;;* Is there an highlight properties at position pos? */
1679 ;;*---------------------------------------------------------------------*/
1680 (defun flyspell-properties-at-p (pos)
1681 "Return t if there is a text property at POS, not counting `local-map'.
1682 If variable `flyspell-highlight-properties' is set to nil,
1683 text with properties are not checked. This function is used to discover
1684 if the character at POS has any other property."
1685 (let ((prop (text-properties-at pos))
1686 (keep t))
1687 (while (and keep (consp prop))
1688 (if (and (eq (car prop) 'local-map) (consp (cdr prop)))
1689 (setq prop (cdr (cdr prop)))
1690 (setq keep nil)))
1691 (consp prop)))
1693 ;;*---------------------------------------------------------------------*/
1694 ;;* make-flyspell-overlay ... */
1695 ;;*---------------------------------------------------------------------*/
1696 (defun make-flyspell-overlay (beg end face mouse-face)
1697 "Allocate an overlay to highlight an incorrect word.
1698 BEG and END specify the range in the buffer of that word.
1699 FACE and MOUSE-FACE specify the `face' and `mouse-face' properties
1700 for the overlay."
1701 (let ((overlay (make-overlay beg end nil t nil)))
1702 (overlay-put overlay 'face face)
1703 (overlay-put overlay 'mouse-face mouse-face)
1704 (overlay-put overlay 'flyspell-overlay t)
1705 (overlay-put overlay 'evaporate t)
1706 (overlay-put overlay 'help-echo "mouse-2: correct word at point")
1707 (overlay-put overlay 'keymap flyspell-mouse-map)
1708 (when (eq face 'flyspell-incorrect)
1709 (and (stringp flyspell-before-incorrect-word-string)
1710 (overlay-put overlay 'before-string
1711 flyspell-before-incorrect-word-string))
1712 (and (stringp flyspell-after-incorrect-word-string)
1713 (overlay-put overlay 'after-string
1714 flyspell-after-incorrect-word-string)))
1715 overlay))
1717 ;;*---------------------------------------------------------------------*/
1718 ;;* flyspell-highlight-incorrect-region ... */
1719 ;;*---------------------------------------------------------------------*/
1720 (defun flyspell-highlight-incorrect-region (beg end poss)
1721 "Set up an overlay on a misspelled word, in the buffer from BEG to END.
1722 POSS is usually a list of possible spelling/correction lists,
1723 as returned by `ispell-parse-output'.
1724 It can also be the symbol `doublon', in the case where the word
1725 is itself incorrect, but suspiciously repeated."
1726 (let ((inhibit-read-only t))
1727 (unless (run-hook-with-args-until-success
1728 'flyspell-incorrect-hook beg end poss)
1729 (if (or flyspell-highlight-properties
1730 (not (flyspell-properties-at-p beg)))
1731 (progn
1732 ;; we cleanup all the overlay that are in the region, not
1733 ;; beginning at the word start position
1734 (if (< (1+ beg) end)
1735 (let ((os (overlays-in (1+ beg) end)))
1736 (while (consp os)
1737 (if (flyspell-overlay-p (car os))
1738 (delete-overlay (car os)))
1739 (setq os (cdr os)))))
1740 ;; we cleanup current overlay at the same position
1741 (flyspell-unhighlight-at beg)
1742 ;; now we can use a new overlay
1743 (setq flyspell-overlay
1744 (make-flyspell-overlay
1745 beg end
1746 (if (eq poss 'doublon) 'flyspell-duplicate 'flyspell-incorrect)
1747 'highlight)))))))
1749 ;;*---------------------------------------------------------------------*/
1750 ;;* flyspell-highlight-duplicate-region ... */
1751 ;;*---------------------------------------------------------------------*/
1752 (defun flyspell-highlight-duplicate-region (beg end poss)
1753 "Set up an overlay on a duplicate misspelled word, in the buffer from BEG to END.
1754 POSS is a list of possible spelling/correction lists,
1755 as returned by `ispell-parse-output'."
1756 (let ((inhibit-read-only t))
1757 (unless (run-hook-with-args-until-success
1758 'flyspell-incorrect-hook beg end poss)
1759 (if (or flyspell-highlight-properties
1760 (not (flyspell-properties-at-p beg)))
1761 (progn
1762 ;; we cleanup current overlay at the same position
1763 (flyspell-unhighlight-at beg)
1764 ;; now we can use a new overlay
1765 (setq flyspell-overlay
1766 (make-flyspell-overlay beg end
1767 'flyspell-duplicate
1768 'highlight)))))))
1770 ;;*---------------------------------------------------------------------*/
1771 ;;* flyspell-auto-correct-cache ... */
1772 ;;*---------------------------------------------------------------------*/
1773 (defvar flyspell-auto-correct-pos nil)
1774 (defvar flyspell-auto-correct-region nil)
1775 (defvar flyspell-auto-correct-ring nil)
1776 (defvar flyspell-auto-correct-word nil)
1777 (make-variable-buffer-local 'flyspell-auto-correct-pos)
1778 (make-variable-buffer-local 'flyspell-auto-correct-region)
1779 (make-variable-buffer-local 'flyspell-auto-correct-ring)
1780 (make-variable-buffer-local 'flyspell-auto-correct-word)
1782 ;;*---------------------------------------------------------------------*/
1783 ;;* flyspell-check-previous-highlighted-word ... */
1784 ;;*---------------------------------------------------------------------*/
1785 (defun flyspell-check-previous-highlighted-word (&optional arg)
1786 "Correct the closer misspelled word.
1787 This function scans a mis-spelled word before the cursor. If it finds one
1788 it proposes replacement for that word. With prefix arg, count that many
1789 misspelled words backwards."
1790 (interactive)
1791 (let ((pos1 (point))
1792 (pos (point))
1793 (arg (if (or (not (numberp arg)) (< arg 1)) 1 arg))
1794 ov ovs)
1795 (if (catch 'exit
1796 (while (and (setq pos (previous-overlay-change pos))
1797 (not (= pos pos1)))
1798 (setq pos1 pos)
1799 (if (> pos (point-min))
1800 (progn
1801 (setq ovs (overlays-at (1- pos)))
1802 (while (consp ovs)
1803 (setq ov (car ovs))
1804 (setq ovs (cdr ovs))
1805 (if (and (flyspell-overlay-p ov)
1806 (= 0 (setq arg (1- arg))))
1807 (throw 'exit t)))))))
1808 (save-excursion
1809 (goto-char pos)
1810 (ispell-word)
1811 (setq flyspell-word-cache-word nil) ;; Force flyspell-word re-check
1812 (flyspell-word))
1813 (error "No word to correct before point"))))
1815 ;;*---------------------------------------------------------------------*/
1816 ;;* flyspell-display-next-corrections ... */
1817 ;;*---------------------------------------------------------------------*/
1818 (defun flyspell-display-next-corrections (corrections)
1819 (let ((string "Corrections:")
1820 (l corrections)
1821 (pos '()))
1822 (while (< (length string) 80)
1823 (if (equal (car l) flyspell-auto-correct-word)
1824 (setq pos (cons (+ 1 (length string)) pos)))
1825 (setq string (concat string " " (car l)))
1826 (setq l (cdr l)))
1827 (while (consp pos)
1828 (let ((num (car pos)))
1829 (put-text-property num
1830 (+ num (length flyspell-auto-correct-word))
1831 'face 'flyspell-incorrect
1832 string))
1833 (setq pos (cdr pos)))
1834 (if (fboundp 'display-message)
1835 (display-message 'no-log string)
1836 (message "%s" string))))
1838 ;;*---------------------------------------------------------------------*/
1839 ;;* flyspell-abbrev-table ... */
1840 ;;*---------------------------------------------------------------------*/
1841 (defun flyspell-abbrev-table ()
1842 (if flyspell-use-global-abbrev-table-p
1843 global-abbrev-table
1844 (or local-abbrev-table global-abbrev-table)))
1846 ;;*---------------------------------------------------------------------*/
1847 ;;* flyspell-define-abbrev ... */
1848 ;;*---------------------------------------------------------------------*/
1849 (defun flyspell-define-abbrev (name expansion)
1850 (let ((table (flyspell-abbrev-table)))
1851 (when table
1852 (define-abbrev table (downcase name) expansion))))
1854 ;;*---------------------------------------------------------------------*/
1855 ;;* flyspell-auto-correct-word ... */
1856 ;;*---------------------------------------------------------------------*/
1857 (defun flyspell-auto-correct-word ()
1858 "Correct the current word.
1859 This command proposes various successive corrections for the current word."
1860 (interactive)
1861 (let ((pos (point))
1862 (old-max (point-max)))
1863 ;; Use the correct dictionary.
1864 (flyspell-accept-buffer-local-defs)
1865 (if (and (eq flyspell-auto-correct-pos pos)
1866 (consp flyspell-auto-correct-region))
1867 ;; We have already been using the function at the same location.
1868 (let* ((start (car flyspell-auto-correct-region))
1869 (len (cdr flyspell-auto-correct-region)))
1870 (flyspell-unhighlight-at start)
1871 (delete-region start (+ start len))
1872 (setq flyspell-auto-correct-ring (cdr flyspell-auto-correct-ring))
1873 (let* ((word (car flyspell-auto-correct-ring))
1874 (len (length word)))
1875 (rplacd flyspell-auto-correct-region len)
1876 (goto-char start)
1877 (if flyspell-abbrev-p
1878 (if (flyspell-already-abbrevp (flyspell-abbrev-table)
1879 flyspell-auto-correct-word)
1880 (flyspell-change-abbrev (flyspell-abbrev-table)
1881 flyspell-auto-correct-word
1882 word)
1883 (flyspell-define-abbrev flyspell-auto-correct-word word)))
1884 (funcall flyspell-insert-function word)
1885 (flyspell-word)
1886 (flyspell-display-next-corrections flyspell-auto-correct-ring))
1887 (flyspell-ajust-cursor-point pos (point) old-max)
1888 (setq flyspell-auto-correct-pos (point)))
1889 ;; Fetch the word to be checked.
1890 (let ((word (flyspell-get-word)))
1891 (if (consp word)
1892 (let ((start (car (cdr word)))
1893 (end (car (cdr (cdr word))))
1894 (word (car word))
1895 poss ispell-filter)
1896 (setq flyspell-auto-correct-word word)
1897 ;; Now check spelling of word..
1898 (ispell-send-string "%\n") ;Put in verbose mode.
1899 (ispell-send-string (concat "^" word "\n"))
1900 ;; Wait until ispell has processed word.
1901 (while (progn
1902 (accept-process-output ispell-process)
1903 (not (string= "" (car ispell-filter)))))
1904 ;; Remove leading empty element.
1905 (setq ispell-filter (cdr ispell-filter))
1906 ;; Ispell process should return something after word is sent.
1907 ;; Tag word as valid (i.e., skip) otherwise.
1908 (or ispell-filter
1909 (setq ispell-filter '(*)))
1910 (if (consp ispell-filter)
1911 (setq poss (ispell-parse-output (car ispell-filter))))
1912 (cond
1913 ((or (eq poss t) (stringp poss))
1914 ;; Don't correct word.
1916 ((null poss)
1917 ;; Ispell error.
1918 (error "Ispell: error in Ispell process"))
1920 ;; The word is incorrect, we have to propose a replacement.
1921 (let ((replacements (if flyspell-sort-corrections
1922 (sort (car (cdr (cdr poss))) 'string<)
1923 (car (cdr (cdr poss))))))
1924 (setq flyspell-auto-correct-region nil)
1925 (if (consp replacements)
1926 (progn
1927 (let ((replace (car replacements)))
1928 (let ((new-word replace))
1929 (if (not (equal new-word (car poss)))
1930 (progn
1931 ;; the save the current replacements
1932 (setq flyspell-auto-correct-region
1933 (cons start (length new-word)))
1934 (let ((l replacements))
1935 (while (consp (cdr l))
1936 (setq l (cdr l)))
1937 (rplacd l (cons (car poss) replacements)))
1938 (setq flyspell-auto-correct-ring
1939 replacements)
1940 (flyspell-unhighlight-at start)
1941 (delete-region start end)
1942 (funcall flyspell-insert-function new-word)
1943 (if flyspell-abbrev-p
1944 (if (flyspell-already-abbrevp
1945 (flyspell-abbrev-table) word)
1946 (flyspell-change-abbrev
1947 (flyspell-abbrev-table)
1948 word
1949 new-word)
1950 (flyspell-define-abbrev word
1951 new-word)))
1952 (flyspell-word)
1953 (flyspell-display-next-corrections
1954 (cons new-word flyspell-auto-correct-ring))
1955 (flyspell-ajust-cursor-point pos
1956 (point)
1957 old-max))))))))))
1958 (setq flyspell-auto-correct-pos (point))
1959 (ispell-pdict-save t)))))))
1961 ;;*---------------------------------------------------------------------*/
1962 ;;* flyspell-auto-correct-previous-pos ... */
1963 ;;*---------------------------------------------------------------------*/
1964 (defvar flyspell-auto-correct-previous-pos nil
1965 "Holds the start of the first incorrect word before point.")
1967 ;;*---------------------------------------------------------------------*/
1968 ;;* flyspell-auto-correct-previous-hook ... */
1969 ;;*---------------------------------------------------------------------*/
1970 (defun flyspell-auto-correct-previous-hook ()
1971 "Hook to track successive calls to `flyspell-auto-correct-previous-word'.
1972 Sets `flyspell-auto-correct-previous-pos' to nil"
1973 (interactive)
1974 (remove-hook 'pre-command-hook (function flyspell-auto-correct-previous-hook) t)
1975 (unless (eq this-command (function flyspell-auto-correct-previous-word))
1976 (setq flyspell-auto-correct-previous-pos nil)))
1978 ;;*---------------------------------------------------------------------*/
1979 ;;* flyspell-auto-correct-previous-word ... */
1980 ;;*---------------------------------------------------------------------*/
1981 (defun flyspell-auto-correct-previous-word (position)
1982 "Auto correct the first misspelled word that occurs before point.
1983 But don't look beyond what's visible on the screen."
1984 (interactive "d")
1986 (let ((top (window-start))
1987 (bot (window-end)))
1988 (save-excursion
1989 (save-restriction
1990 (narrow-to-region top bot)
1991 (overlay-recenter (point))
1993 (add-hook 'pre-command-hook
1994 (function flyspell-auto-correct-previous-hook) t t)
1996 (unless flyspell-auto-correct-previous-pos
1997 ;; only reset if a new overlay exists
1998 (setq flyspell-auto-correct-previous-pos nil)
2000 (let ((overlay-list (overlays-in (point-min) position))
2001 (new-overlay 'dummy-value))
2003 ;; search for previous (new) flyspell overlay
2004 (while (and new-overlay
2005 (or (not (flyspell-overlay-p new-overlay))
2006 ;; check if its face has changed
2007 (not (eq (get-char-property
2008 (overlay-start new-overlay) 'face)
2009 'flyspell-incorrect))))
2010 (setq new-overlay (car-safe overlay-list))
2011 (setq overlay-list (cdr-safe overlay-list)))
2013 ;; if nothing new exits new-overlay should be nil
2014 (if new-overlay ;; the length of the word may change so go to the start
2015 (setq flyspell-auto-correct-previous-pos
2016 (overlay-start new-overlay)))))
2018 (when flyspell-auto-correct-previous-pos
2019 (save-excursion
2020 (goto-char flyspell-auto-correct-previous-pos)
2021 (let ((ispell-following-word t)) ;; point is at start
2022 (if (numberp flyspell-auto-correct-previous-pos)
2023 (goto-char flyspell-auto-correct-previous-pos))
2024 (flyspell-auto-correct-word))
2025 ;; the point may have moved so reset this
2026 (setq flyspell-auto-correct-previous-pos (point))))))))
2028 ;;*---------------------------------------------------------------------*/
2029 ;;* flyspell-correct-word ... */
2030 ;;*---------------------------------------------------------------------*/
2032 (defun flyspell-correct-word (event)
2033 "Pop up a menu of possible corrections for a misspelled word.
2034 The word checked is the word at the mouse position."
2035 (interactive "e")
2036 (let ((save (point)))
2037 (mouse-set-point event)
2038 (flyspell-correct-word-before-point event save)))
2040 (defun flyspell-correct-word-before-point (&optional event opoint)
2041 "Pop up a menu of possible corrections for misspelled word before point.
2042 If EVENT is non-nil, it is the mouse event that invoked this operation;
2043 that controls where to put the menu.
2044 If OPOINT is non-nil, restore point there after adjusting it for replacement."
2045 (interactive)
2046 (unless (mouse-position)
2047 (error "Pop-up menus do not work on this terminal"))
2048 ;; use the correct dictionary
2049 (flyspell-accept-buffer-local-defs)
2050 (or opoint (setq opoint (point)))
2051 (let ((cursor-location (point))
2052 (word (flyspell-get-word)))
2053 (if (consp word)
2054 (let ((start (car (cdr word)))
2055 (end (car (cdr (cdr word))))
2056 (word (car word))
2057 poss ispell-filter)
2058 ;; now check spelling of word.
2059 (ispell-send-string "%\n") ;put in verbose mode
2060 (ispell-send-string (concat "^" word "\n"))
2061 ;; wait until ispell has processed word
2062 (while (progn
2063 (accept-process-output ispell-process)
2064 (not (string= "" (car ispell-filter)))))
2065 ;; Remove leading empty element
2066 (setq ispell-filter (cdr ispell-filter))
2067 ;; ispell process should return something after word is sent.
2068 ;; Tag word as valid (i.e., skip) otherwise
2069 (or ispell-filter
2070 (setq ispell-filter '(*)))
2071 (if (consp ispell-filter)
2072 (setq poss (ispell-parse-output (car ispell-filter))))
2073 (cond
2074 ((or (eq poss t) (stringp poss))
2075 ;; don't correct word
2077 ((null poss)
2078 ;; ispell error
2079 (error "Ispell: error in Ispell process"))
2080 ((featurep 'xemacs)
2081 (flyspell-xemacs-popup
2082 poss word cursor-location start end opoint))
2084 ;; The word is incorrect, we have to propose a replacement.
2085 (flyspell-do-correct (flyspell-emacs-popup event poss word)
2086 poss word cursor-location start end opoint)))
2087 (ispell-pdict-save t)))))
2089 ;;*---------------------------------------------------------------------*/
2090 ;;* flyspell-do-correct ... */
2091 ;;*---------------------------------------------------------------------*/
2092 (defun flyspell-do-correct (replace poss word cursor-location start end save)
2093 "The popup menu callback."
2094 ;; Originally, the XEmacs code didn't do the (goto-char save) here and did
2095 ;; it instead right after calling the function.
2096 (cond ((eq replace 'ignore)
2097 (goto-char save)
2098 nil)
2099 ((eq replace 'save)
2100 (goto-char save)
2101 (ispell-send-string (concat "*" word "\n"))
2102 ;; This was added only to the XEmacs side in revision 1.18 of
2103 ;; flyspell. I assume its absence on the Emacs side was an
2104 ;; oversight. --Stef
2105 (ispell-send-string "#\n")
2106 (flyspell-unhighlight-at cursor-location)
2107 (setq ispell-pdict-modified-p '(t)))
2108 ((or (eq replace 'buffer) (eq replace 'session))
2109 (ispell-send-string (concat "@" word "\n"))
2110 (add-to-list 'ispell-buffer-session-localwords word)
2111 (or ispell-buffer-local-name ; session localwords might conflict
2112 (setq ispell-buffer-local-name (buffer-name)))
2113 (flyspell-unhighlight-at cursor-location)
2114 (if (null ispell-pdict-modified-p)
2115 (setq ispell-pdict-modified-p
2116 (list ispell-pdict-modified-p)))
2117 (goto-char save)
2118 (if (eq replace 'buffer)
2119 (ispell-add-per-file-word-list word)))
2120 (replace
2121 ;; This was added only to the Emacs side. I assume its absence on
2122 ;; the XEmacs side was an oversight. --Stef
2123 (flyspell-unhighlight-at cursor-location)
2124 (let ((old-max (point-max))
2125 (new-word (if (atom replace)
2126 replace
2127 (car replace)))
2128 (cursor-location (+ (- (length word) (- end start))
2129 cursor-location)))
2130 (unless (equal new-word (car poss))
2131 (delete-region start end)
2132 (goto-char start)
2133 (funcall flyspell-insert-function new-word)
2134 (if flyspell-abbrev-p
2135 (flyspell-define-abbrev word new-word)))
2136 ;; In the original Emacs code, this was only called in the body
2137 ;; of the if. I arbitrarily kept the XEmacs behavior instead.
2138 (flyspell-ajust-cursor-point save cursor-location old-max)))
2140 (goto-char save)
2141 nil)))
2143 ;;*---------------------------------------------------------------------*/
2144 ;;* flyspell-ajust-cursor-point ... */
2145 ;;*---------------------------------------------------------------------*/
2146 (defun flyspell-ajust-cursor-point (save cursor-location old-max)
2147 (if (>= save cursor-location)
2148 (let ((new-pos (+ save (- (point-max) old-max))))
2149 (goto-char (cond
2150 ((< new-pos (point-min))
2151 (point-min))
2152 ((> new-pos (point-max))
2153 (point-max))
2154 (t new-pos))))
2155 (goto-char save)))
2157 ;;*---------------------------------------------------------------------*/
2158 ;;* flyspell-emacs-popup ... */
2159 ;;*---------------------------------------------------------------------*/
2160 (defun flyspell-emacs-popup (event poss word)
2161 "The Emacs popup menu."
2162 (unless window-system
2163 (error "This command requires pop-up dialogs"))
2164 (if (not event)
2165 (let* ((mouse-pos (mouse-position))
2166 (mouse-pos (if (nth 1 mouse-pos)
2167 mouse-pos
2168 (set-mouse-position (car mouse-pos)
2169 (/ (frame-width) 2) 2)
2170 (mouse-position))))
2171 (setq event (list (list (car (cdr mouse-pos))
2172 (1+ (cdr (cdr mouse-pos))))
2173 (car mouse-pos)))))
2174 (let* ((corrects (if flyspell-sort-corrections
2175 (sort (car (cdr (cdr poss))) 'string<)
2176 (car (cdr (cdr poss)))))
2177 (cor-menu (if (consp corrects)
2178 (mapcar (lambda (correct)
2179 (list correct correct))
2180 corrects)
2181 '()))
2182 (affix (car (cdr (cdr (cdr poss)))))
2183 show-affix-info
2184 (base-menu (let ((save (if (and (consp affix) show-affix-info)
2185 (list
2186 (list (concat "Save affix: " (car affix))
2187 'save)
2188 '("Accept (session)" session)
2189 '("Accept (buffer)" buffer))
2190 '(("Save word" save)
2191 ("Accept (session)" session)
2192 ("Accept (buffer)" buffer)))))
2193 (if (consp cor-menu)
2194 (append cor-menu (cons "" save))
2195 save)))
2196 (menu (cons "flyspell correction menu" base-menu)))
2197 (car (x-popup-menu event
2198 (list (format "%s [%s]" word (or ispell-local-dictionary
2199 ispell-dictionary))
2200 menu)))))
2202 ;;*---------------------------------------------------------------------*/
2203 ;;* flyspell-xemacs-popup ... */
2204 ;;*---------------------------------------------------------------------*/
2205 (defun flyspell-xemacs-popup (poss word cursor-location start end save)
2206 "The XEmacs popup menu."
2207 (let* ((corrects (if flyspell-sort-corrections
2208 (sort (car (cdr (cdr poss))) 'string<)
2209 (car (cdr (cdr poss)))))
2210 (cor-menu (if (consp corrects)
2211 (mapcar (lambda (correct)
2212 (vector correct
2213 (list 'flyspell-do-correct
2214 correct
2215 (list 'quote poss)
2216 word
2217 cursor-location
2218 start
2220 save)
2222 corrects)
2223 '()))
2224 (affix (car (cdr (cdr (cdr poss)))))
2225 show-affix-info
2226 (menu (let ((save (if (and (consp affix) show-affix-info)
2227 (vector
2228 (concat "Save affix: " (car affix))
2229 (list 'flyspell-do-correct
2230 ''save
2231 (list 'quote poss)
2232 word
2233 cursor-location
2234 start
2236 save)
2238 (vector
2239 "Save word"
2240 (list 'flyspell-do-correct
2241 ''save
2242 (list 'quote poss)
2243 word
2244 cursor-location
2245 start
2247 save)
2248 t)))
2249 (session (vector "Accept (session)"
2250 (list 'flyspell-do-correct
2251 ''session
2252 (list 'quote poss)
2253 word
2254 cursor-location
2255 start
2257 save)
2259 (buffer (vector "Accept (buffer)"
2260 (list 'flyspell-do-correct
2261 ''buffer
2262 (list 'quote poss)
2263 word
2264 cursor-location
2265 start
2267 save)
2268 t)))
2269 (if (consp cor-menu)
2270 (append cor-menu (list "-" save session buffer))
2271 (list save session buffer)))))
2272 (popup-menu (cons (format "%s [%s]" word (or ispell-local-dictionary
2273 ispell-dictionary))
2274 menu))))
2276 ;;*---------------------------------------------------------------------*/
2277 ;;* Some example functions for real autocorrecting */
2278 ;;*---------------------------------------------------------------------*/
2279 (defun flyspell-maybe-correct-transposition (beg end poss)
2280 "Check replacements for transposed characters.
2282 If the text between BEG and END is equal to a correction suggested by
2283 Ispell, after transposing two adjacent characters, correct the text,
2284 and return t.
2286 The third arg POSS is either the symbol 'doublon' or a list of
2287 possible corrections as returned by `ispell-parse-output'.
2289 This function is meant to be added to `flyspell-incorrect-hook'."
2290 (when (consp poss)
2291 (catch 'done
2292 (let ((str (buffer-substring beg end))
2293 (i 0) (len (- end beg)) tmp)
2294 (while (< (1+ i) len)
2295 (setq tmp (aref str i))
2296 (aset str i (aref str (1+ i)))
2297 (aset str (1+ i) tmp)
2298 (when (member str (nth 2 poss))
2299 (save-excursion
2300 (goto-char (+ beg i 1))
2301 (transpose-chars 1))
2302 (throw 'done t))
2303 (setq tmp (aref str i))
2304 (aset str i (aref str (1+ i)))
2305 (aset str (1+ i) tmp)
2306 (setq i (1+ i))))
2307 nil)))
2309 (defun flyspell-maybe-correct-doubling (beg end poss)
2310 "Check replacements for doubled characters.
2312 If the text between BEG and END is equal to a correction suggested by
2313 Ispell, after removing a pair of doubled characters, correct the text,
2314 and return t.
2316 The third arg POSS is either the symbol 'doublon' or a list of
2317 possible corrections as returned by `ispell-parse-output'.
2319 This function is meant to be added to `flyspell-incorrect-hook'."
2320 (when (consp poss)
2321 (catch 'done
2322 (let ((str (buffer-substring beg end))
2323 (i 0) (len (- end beg)))
2324 (while (< (1+ i) len)
2325 (when (and (= (aref str i) (aref str (1+ i)))
2326 (member (concat (substring str 0 (1+ i))
2327 (substring str (+ i 2)))
2328 (nth 2 poss)))
2329 (goto-char (+ beg i))
2330 (delete-char 1)
2331 (throw 'done t))
2332 (setq i (1+ i))))
2333 nil)))
2335 ;;*---------------------------------------------------------------------*/
2336 ;;* flyspell-already-abbrevp ... */
2337 ;;*---------------------------------------------------------------------*/
2338 (defun flyspell-already-abbrevp (table word)
2339 (let ((sym (abbrev-symbol word table)))
2340 (and sym (symbolp sym))))
2342 ;;*---------------------------------------------------------------------*/
2343 ;;* flyspell-change-abbrev ... */
2344 ;;*---------------------------------------------------------------------*/
2345 (defun flyspell-change-abbrev (table old new)
2346 (set (abbrev-symbol old table) new))
2348 (provide 'flyspell)
2350 ;;; flyspell.el ends here