* textmodes/flyspell.el (message-signature-separator):
[emacs.git] / lisp / textmodes / flyspell.el
blob73e8ec490450a03bde04dcc971406891f544be81
1 ;;; flyspell.el --- on-the-fly spell checker
3 ;; Copyright (C) 1998, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007 Free Software Foundation, Inc.
6 ;; Author: Manuel Serrano <Manuel.Serrano@sophia.inria.fr>
7 ;; Maintainer: FSF
8 ;; Keywords: convenience
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 3, or (at your option)
15 ;; any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
27 ;;; Commentary:
29 ;; Flyspell is a minor Emacs mode performing on-the-fly spelling
30 ;; checking.
32 ;; To enable Flyspell minor mode, type M-x flyspell-mode.
33 ;; This applies only to the current buffer.
35 ;; To enable Flyspell in text representing computer programs, type
36 ;; M-x flyspell-prog-mode.
37 ;; In that mode only text inside comments is checked.
39 ;; Note: consider setting the variable ispell-parser to `tex' to
40 ;; avoid TeX command checking; use `(setq ispell-parser 'tex)'.
42 ;; Some user variables control the behavior of flyspell. They are
43 ;; those defined under the `User variables' comment.
45 ;;; Code:
47 (require 'ispell)
49 ;;*---------------------------------------------------------------------*/
50 ;;* Group ... */
51 ;;*---------------------------------------------------------------------*/
52 (defgroup flyspell nil
53 "Spell checking on the fly."
54 :tag "FlySpell"
55 :prefix "flyspell-"
56 :group 'ispell
57 :group 'processes)
59 ;;*---------------------------------------------------------------------*/
60 ;;* User configuration ... */
61 ;;*---------------------------------------------------------------------*/
62 (defcustom flyspell-highlight-flag t
63 "How Flyspell should indicate misspelled words.
64 Non-nil means use highlight, nil means use minibuffer messages."
65 :group 'flyspell
66 :type 'boolean)
68 (defcustom flyspell-mark-duplications-flag t
69 "Non-nil means Flyspell reports a repeated word as an error.
70 See `flyspell-mark-duplications-exceptions' to add exceptions to this rule.
71 Detection of repeated words is not implemented in
72 \"large\" regions; see `flyspell-large-region'."
73 :group 'flyspell
74 :type 'boolean)
76 (defcustom flyspell-mark-duplications-exceptions
77 '(("francais" . ("nous" "vous")))
78 "A list of exceptions for duplicated words.
79 It should be a list of (LANGUAGE . EXCEPTION-LIST). LANGUAGE is matched
80 against the current dictionary and EXCEPTION-LIST is a list of strings.
81 The duplicated word is downcased before it is compared with the exceptions."
82 :group 'flyspell
83 :type '(alist :key-type string :value-type (repeat string)))
85 (defcustom flyspell-sort-corrections nil
86 "Non-nil means, sort the corrections alphabetically before popping them."
87 :group 'flyspell
88 :version "21.1"
89 :type 'boolean)
91 (defcustom flyspell-duplicate-distance -1
92 "The maximum distance for finding duplicates of unrecognized words.
93 This applies to the feature that when a word is not found in the dictionary,
94 if the same spelling occurs elsewhere in the buffer,
95 Flyspell uses a different face (`flyspell-duplicate') to highlight it.
96 This variable specifies how far to search to find such a duplicate.
97 -1 means no limit (search the whole buffer).
98 0 means do not search for duplicate unrecognized spellings."
99 :group 'flyspell
100 :version "21.1"
101 :type 'number)
103 (defcustom flyspell-delay 3
104 "The number of seconds to wait before checking, after a \"delayed\" command."
105 :group 'flyspell
106 :type 'number)
108 (defcustom flyspell-persistent-highlight t
109 "Non-nil means misspelled words remain highlighted until corrected.
110 If this variable is nil, only the most recently detected misspelled word
111 is highlighted."
112 :group 'flyspell
113 :type 'boolean)
115 (defcustom flyspell-highlight-properties t
116 "Non-nil means highlight incorrect words even if a property exists for this word."
117 :group 'flyspell
118 :type 'boolean)
120 (defcustom flyspell-default-delayed-commands
121 '(self-insert-command
122 delete-backward-char
123 backward-or-forward-delete-char
124 delete-char
125 scrollbar-vertical-drag
126 backward-delete-char-untabify)
127 "The standard list of delayed commands for Flyspell.
128 See `flyspell-delayed-commands'."
129 :group 'flyspell
130 :version "21.1"
131 :type '(repeat (symbol)))
133 (defcustom flyspell-delayed-commands nil
134 "List of commands that are \"delayed\" for Flyspell mode.
135 After these commands, Flyspell checking is delayed for a short time,
136 whose length is specified by `flyspell-delay'."
137 :group 'flyspell
138 :type '(repeat (symbol)))
140 (defcustom flyspell-default-deplacement-commands
141 '(next-line
142 previous-line
143 scroll-up
144 scroll-down)
145 "The standard list of deplacement commands for Flyspell.
146 See `flyspell-deplacement-commands'."
147 :group 'flyspell
148 :version "21.1"
149 :type '(repeat (symbol)))
151 (defcustom flyspell-deplacement-commands nil
152 "List of commands that are \"deplacement\" for Flyspell mode.
153 After these commands, Flyspell checking is performed only if the previous
154 command was not the very same command."
155 :group 'flyspell
156 :version "21.1"
157 :type '(repeat (symbol)))
159 (defcustom flyspell-issue-welcome-flag t
160 "Non-nil means that Flyspell should display a welcome message when started."
161 :group 'flyspell
162 :type 'boolean)
164 (defcustom flyspell-issue-message-flag t
165 "Non-nil means that Flyspell emits messages when checking words."
166 :group 'flyspell
167 :type 'boolean)
169 (defcustom flyspell-incorrect-hook nil
170 "List of functions to be called when incorrect words are encountered.
171 Each function is given three arguments. The first two
172 arguments are the beginning and the end of the incorrect region.
173 The third is either the symbol `doublon' or the list
174 of possible corrections as returned by `ispell-parse-output'.
176 If any of the functions return non-nil, the word is not highlighted as
177 incorrect."
178 :group 'flyspell
179 :version "21.1"
180 :type 'hook)
182 (defcustom flyspell-default-dictionary nil
183 "A string that is the name of the default dictionary.
184 This is passed to the `ispell-change-dictionary' when flyspell is started.
185 If the variable `ispell-local-dictionary' or `ispell-dictionary' is non-nil
186 when flyspell is started, the value of that variable is used instead
187 of `flyspell-default-dictionary' to select the default dictionary.
188 Otherwise, if `flyspell-default-dictionary' is nil, it means to use
189 Ispell's ultimate default dictionary."
190 :group 'flyspell
191 :version "21.1"
192 :type '(choice string (const :tag "Default" nil)))
194 (defcustom flyspell-tex-command-regexp
195 "\\(\\(begin\\|end\\)[ \t]*{\\|\\(cite[a-z*]*\\|label\\|ref\\|eqref\\|usepackage\\|documentclass\\)[ \t]*\\(\\[[^]]*\\]\\)?{[^{}]*\\)"
196 "A string that is the regular expression that matches TeX commands."
197 :group 'flyspell
198 :version "21.1"
199 :type 'string)
201 (defcustom flyspell-check-tex-math-command nil
202 "Non-nil means check even inside TeX math environment.
203 TeX math environments are discovered by the TEXMATHP that implemented
204 inside the texmathp.el Emacs package. That package may be found at:
205 http://strw.leidenuniv.nl/~dominik/Tools"
206 :group 'flyspell
207 :type 'boolean)
209 (defcustom flyspell-dictionaries-that-consider-dash-as-word-delimiter
210 '("francais" "deutsch8" "norsk")
211 "List of dictionary names that consider `-' as word delimiter."
212 :group 'flyspell
213 :version "21.1"
214 :type '(repeat (string)))
216 (defcustom flyspell-abbrev-p
218 "If non-nil, add correction to abbreviation table."
219 :group 'flyspell
220 :version "21.1"
221 :type 'boolean)
223 (defcustom flyspell-use-global-abbrev-table-p
225 "If non-nil, prefer global abbrev table to local abbrev table."
226 :group 'flyspell
227 :version "21.1"
228 :type 'boolean)
230 (defcustom flyspell-mode-line-string " Fly"
231 "String displayed on the modeline when flyspell is active.
232 Set this to nil if you don't want a modeline indicator."
233 :group 'flyspell
234 :type '(choice string (const :tag "None" nil)))
236 (defcustom flyspell-large-region 1000
237 "The threshold that determines if a region is small.
238 If the region is smaller than this number of characters,
239 `flyspell-region' checks the words sequentially using regular
240 flyspell methods. Else, if the region is large, a new Ispell process is
241 spawned for speed.
243 Doubled words are not detected in a large region, because Ispell
244 does not check for them.
246 If `flyspell-large-region' is nil, all regions are treated as small."
247 :group 'flyspell
248 :version "21.1"
249 :type '(choice number (const :tag "All small" nil)))
251 (defcustom flyspell-insert-function (function insert)
252 "Function for inserting word by flyspell upon correction."
253 :group 'flyspell
254 :type 'function)
256 (defcustom flyspell-before-incorrect-word-string nil
257 "String used to indicate an incorrect word starting."
258 :group 'flyspell
259 :type '(choice string (const nil)))
261 (defcustom flyspell-after-incorrect-word-string nil
262 "String used to indicate an incorrect word ending."
263 :group 'flyspell
264 :type '(choice string (const nil)))
266 (defcustom flyspell-use-meta-tab t
267 "Non-nil means that flyspell uses M-TAB to correct word."
268 :group 'flyspell
269 :type 'boolean)
271 (defcustom flyspell-auto-correct-binding
272 [(control ?\;)]
273 "The key binding for flyspell auto correction."
274 :group 'flyspell)
276 ;;*---------------------------------------------------------------------*/
277 ;;* Mode specific options */
278 ;;* ------------------------------------------------------------- */
279 ;;* Mode specific options enable users to disable flyspell on */
280 ;;* certain word depending of the emacs mode. For instance, when */
281 ;;* using flyspell with mail-mode add the following expression */
282 ;;* in your .emacs file: */
283 ;;* (add-hook 'mail-mode */
284 ;;* '(lambda () (setq flyspell-generic-check-word-predicate */
285 ;;* 'mail-mode-flyspell-verify))) */
286 ;;*---------------------------------------------------------------------*/
287 (defvar flyspell-generic-check-word-predicate nil
288 "Function providing per-mode customization over which words are flyspelled.
289 Returns t to continue checking, nil otherwise.
290 Flyspell mode sets this variable to whatever is the `flyspell-mode-predicate'
291 property of the major mode name.")
292 (make-variable-buffer-local 'flyspell-generic-check-word-predicate)
293 (defvaralias 'flyspell-generic-check-word-p
294 'flyspell-generic-check-word-predicate)
296 ;;*--- mail mode -------------------------------------------------------*/
297 (put 'mail-mode 'flyspell-mode-predicate 'mail-mode-flyspell-verify)
298 (put 'message-mode 'flyspell-mode-predicate 'mail-mode-flyspell-verify)
299 (defvar message-signature-separator)
300 (defun mail-mode-flyspell-verify ()
301 "Function used for `flyspell-generic-check-word-predicate' in Mail mode."
302 (let ((header-end (save-excursion
303 (goto-char (point-min))
304 (re-search-forward
305 (concat "^"
306 (regexp-quote mail-header-separator)
307 "$")
308 nil t)
309 (point)))
310 (signature-begin (save-excursion
311 (goto-char (point-max))
312 (re-search-backward message-signature-separator
313 nil t)
314 (point))))
315 (cond ((< (point) header-end)
316 (and (save-excursion (beginning-of-line)
317 (looking-at "^Subject:"))
318 (> (point) (match-end 0))))
319 ((> (point) signature-begin)
320 nil)
322 (save-excursion
323 (beginning-of-line)
324 (not (looking-at "[>}|]\\|To:")))))))
326 ;;*--- texinfo mode ----------------------------------------------------*/
327 (put 'texinfo-mode 'flyspell-mode-predicate 'texinfo-mode-flyspell-verify)
328 (defun texinfo-mode-flyspell-verify ()
329 "Function used for `flyspell-generic-check-word-predicate' in Texinfo mode."
330 (save-excursion
331 (forward-word -1)
332 (not (looking-at "@"))))
334 ;;*--- tex mode --------------------------------------------------------*/
335 (put 'tex-mode 'flyspell-mode-predicate 'tex-mode-flyspell-verify)
336 (defun tex-mode-flyspell-verify ()
337 "Function used for `flyspell-generic-check-word-predicate' in LaTeX mode."
338 (and
339 (not (save-excursion
340 (re-search-backward "^[ \t]*%%%[ \t]+Local" nil t)))
341 (not (save-excursion
342 (let ((this (point-marker))
343 (e (progn (end-of-line) (point-marker))))
344 (beginning-of-line)
345 (if (re-search-forward "\\\\\\(cite\\|label\\|ref\\){[^}]*}" e t)
346 (and (>= this (match-beginning 0))
347 (<= this (match-end 0)) )))))))
349 ;;*--- sgml mode -------------------------------------------------------*/
350 (put 'sgml-mode 'flyspell-mode-predicate 'sgml-mode-flyspell-verify)
351 (put 'html-mode 'flyspell-mode-predicate 'sgml-mode-flyspell-verify)
353 (defun sgml-mode-flyspell-verify ()
354 "Function used for `flyspell-generic-check-word-predicate' in SGML mode."
355 (not (save-excursion
356 (let ((this (point-marker))
357 (s (progn (beginning-of-line) (point-marker)))
358 (e (progn (end-of-line) (point-marker))))
359 (or (progn
360 (goto-char this)
361 (and (re-search-forward "[^<]*>" e t)
362 (= (match-beginning 0) this)))
363 (progn
364 (goto-char this)
365 (and (re-search-backward "<[^>]*" s t)
366 (= (match-end 0) this)))
367 (and (progn
368 (goto-char this)
369 (and (re-search-forward "[^&]*;" e t)
370 (= (match-beginning 0) this)))
371 (progn
372 (goto-char this)
373 (and (re-search-backward "&[^;]*" s t)
374 (= (match-end 0) this)))))))))
376 ;;*---------------------------------------------------------------------*/
377 ;;* Programming mode */
378 ;;*---------------------------------------------------------------------*/
379 (defvar flyspell-prog-text-faces
380 '(font-lock-string-face font-lock-comment-face font-lock-doc-face)
381 "Faces corresponding to text in programming-mode buffers.")
383 (defun flyspell-generic-progmode-verify ()
384 "Used for `flyspell-generic-check-word-predicate' in programming modes."
385 (let ((f (get-text-property (point) 'face)))
386 (memq f flyspell-prog-text-faces)))
388 ;;;###autoload
389 (defun flyspell-prog-mode ()
390 "Turn on `flyspell-mode' for comments and strings."
391 (interactive)
392 (setq flyspell-generic-check-word-predicate
393 'flyspell-generic-progmode-verify)
394 (flyspell-mode 1)
395 (run-hooks 'flyspell-prog-mode-hook))
397 ;;*---------------------------------------------------------------------*/
398 ;;* Overlay compatibility */
399 ;;*---------------------------------------------------------------------*/
400 (autoload 'make-overlay "overlay" "Overlay compatibility kit." t)
401 (autoload 'overlayp "overlay" "Overlay compatibility kit." t)
402 (autoload 'overlays-in "overlay" "Overlay compatibility kit." t)
403 (autoload 'delete-overlay "overlay" "Overlay compatibility kit." t)
404 (autoload 'overlays-at "overlay" "Overlay compatibility kit." t)
405 (autoload 'overlay-put "overlay" "Overlay compatibility kit." t)
406 (autoload 'overlay-get "overlay" "Overlay compatibility kit." t)
407 (autoload 'previous-overlay-change "overlay" "Overlay compatibility kit." t)
409 ;;*---------------------------------------------------------------------*/
410 ;;* The minor mode declaration. */
411 ;;*---------------------------------------------------------------------*/
412 (defvar flyspell-mouse-map
413 (let ((map (make-sparse-keymap)))
414 (define-key map (if (featurep 'xemacs) [button2] [down-mouse-2])
415 #'flyspell-correct-word)
416 map)
417 "Keymap for Flyspell to put on erroneous words.")
419 (defvar flyspell-mode-map
420 (let ((map (make-sparse-keymap)))
421 (if flyspell-use-meta-tab
422 (define-key map "\M-\t" 'flyspell-auto-correct-word))
423 (define-key map flyspell-auto-correct-binding 'flyspell-auto-correct-previous-word)
424 (define-key map [(control ?\,)] 'flyspell-goto-next-error)
425 (define-key map [(control ?\.)] 'flyspell-auto-correct-word)
426 (define-key map [?\C-c ?$] 'flyspell-correct-word-before-point)
427 map)
428 "Minor mode keymap for Flyspell mode--for the whole buffer.")
430 ;; dash character machinery
431 (defvar flyspell-consider-dash-as-word-delimiter-flag nil
432 "*Non-nil means that the `-' char is considered as a word delimiter.")
433 (make-variable-buffer-local 'flyspell-consider-dash-as-word-delimiter-flag)
434 (defvar flyspell-dash-dictionary nil)
435 (make-variable-buffer-local 'flyspell-dash-dictionary)
436 (defvar flyspell-dash-local-dictionary nil)
437 (make-variable-buffer-local 'flyspell-dash-local-dictionary)
439 ;;*---------------------------------------------------------------------*/
440 ;;* Highlighting */
441 ;;*---------------------------------------------------------------------*/
442 (defface flyspell-incorrect
443 '((((class color)) (:foreground "OrangeRed" :bold t :underline t))
444 (t (:bold t)))
445 "Face used for marking a misspelled word in Flyspell."
446 :group 'flyspell)
447 ;; backward-compatibility alias
448 (put 'flyspell-incorrect-face 'face-alias 'flyspell-incorrect)
450 (defface flyspell-duplicate
451 '((((class color)) (:foreground "Gold3" :bold t :underline t))
452 (t (:bold t)))
453 "Face used for marking a misspelled word that appears twice in the buffer.
454 See also `flyspell-duplicate-distance'."
455 :group 'flyspell)
456 ;; backward-compatibility alias
457 (put 'flyspell-duplicate-face 'face-alias 'flyspell-duplicate)
459 (defvar flyspell-overlay nil)
461 ;;*---------------------------------------------------------------------*/
462 ;;* flyspell-mode ... */
463 ;;*---------------------------------------------------------------------*/
464 ;;;###autoload(defvar flyspell-mode nil)
465 ;;;###autoload
466 (define-minor-mode flyspell-mode
467 "Minor mode performing on-the-fly spelling checking.
468 This spawns a single Ispell process and checks each word.
469 The default flyspell behavior is to highlight incorrect words.
470 With no argument, this command toggles Flyspell mode.
471 With a prefix argument ARG, turn Flyspell minor mode on if ARG is positive,
472 otherwise turn it off.
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 is entered.
483 Remark:
484 `flyspell-mode' uses `ispell-mode'. Thus all Ispell options are
485 valid. For instance, a personal 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 .emacs 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 ()
500 (flyspell-mode-on)
501 (error (message "Enabling Flyspell mode gave an error")
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-maybe-find-aspell-dictionaries)
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 (interactive-p))
613 (let ((binding (where-is-internal 'flyspell-auto-correct-word
614 nil 'non-ascii)))
615 (message "%s"
616 (if binding
617 (format "Welcome to flyspell. Use %s or Mouse-2 to correct words."
618 (key-description binding))
619 "Welcome to flyspell. Use Mouse-2 to correct words."))))
620 ;; we end with the flyspell hooks
621 (run-hooks 'flyspell-mode-hook))
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 (mapcar '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 as 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 (mapcar '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 of a deplacement command
656 as been used the current word is checked only if the previous command was
657 not the very same deplacement command."
658 (interactive "SDeplacement Flyspell after Command: ")
659 (put command 'flyspell-deplacement t))
661 ;;*---------------------------------------------------------------------*/
662 ;;* flyspell-word-cache ... */
663 ;;*---------------------------------------------------------------------*/
664 (defvar flyspell-word-cache-start nil)
665 (defvar flyspell-word-cache-end nil)
666 (defvar flyspell-word-cache-word nil)
667 (defvar flyspell-word-cache-result '_)
668 (make-variable-buffer-local 'flyspell-word-cache-start)
669 (make-variable-buffer-local 'flyspell-word-cache-end)
670 (make-variable-buffer-local 'flyspell-word-cache-word)
671 (make-variable-buffer-local 'flyspell-word-cache-result)
673 ;;*---------------------------------------------------------------------*/
674 ;;* The flyspell pre-hook, store the current position. In the */
675 ;;* post command hook, we will check, if the word at this position */
676 ;;* has to be spell checked. */
677 ;;*---------------------------------------------------------------------*/
678 (defvar flyspell-pre-buffer nil)
679 (defvar flyspell-pre-point nil)
680 (defvar flyspell-pre-column nil)
681 (defvar flyspell-pre-pre-buffer nil)
682 (defvar flyspell-pre-pre-point nil)
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 hilightings
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 (cond
728 ((or (not (numberp flyspell-pre-point))
729 (not (bufferp flyspell-pre-buffer))
730 (not (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 (eq (char-syntax (char-after flyspell-pre-point)) ?w))
737 (= flyspell-pre-point (point))
738 (= flyspell-pre-point (+ (point) 1)))
739 nil)
740 ((and (symbolp this-command)
741 (not executing-kbd-macro)
742 (or (get this-command 'flyspell-delayed)
743 (and (get this-command 'flyspell-deplacement)
744 (eq flyspell-previous-command this-command)))
745 (or (= (current-column) 0)
746 (= (current-column) flyspell-pre-column)
747 (eq (char-syntax (char-after flyspell-pre-point)) ?w)))
748 nil)
749 ((not (eq (current-buffer) flyspell-pre-buffer))
751 ((not (and (numberp flyspell-word-cache-start)
752 (numberp flyspell-word-cache-end)))
755 (or (< flyspell-pre-point flyspell-word-cache-start)
756 (> flyspell-pre-point flyspell-word-cache-end)))))
758 ;;*---------------------------------------------------------------------*/
759 ;;* The flyspell after-change-hook, store the change position. In */
760 ;;* the post command hook, we will check, if the word at this */
761 ;;* position has to be spell checked. */
762 ;;*---------------------------------------------------------------------*/
763 (defvar flyspell-changes nil)
764 (make-variable-buffer-local 'flyspell-changes)
766 ;;*---------------------------------------------------------------------*/
767 ;;* flyspell-after-change-function ... */
768 ;;*---------------------------------------------------------------------*/
769 (defun flyspell-after-change-function (start stop len)
770 "Save the current buffer and point for Flyspell's post-command hook."
771 (push (cons start stop) flyspell-changes))
773 ;;*---------------------------------------------------------------------*/
774 ;;* flyspell-check-changed-word-p ... */
775 ;;*---------------------------------------------------------------------*/
776 (defun flyspell-check-changed-word-p (start stop)
777 "Return t when the changed word has to be checked.
778 The answer depends of several criteria.
779 Mostly we check word delimiters."
780 (cond
781 ((and (memq (char-after start) '(?\n ? )) (> stop start))
783 ((not (numberp flyspell-pre-point))
785 ((and (>= flyspell-pre-point start) (<= flyspell-pre-point stop))
786 nil)
787 ((let ((pos (point)))
788 (or (>= pos start) (<= pos stop) (= pos (1+ stop))))
789 nil)
791 t)))
793 ;;*---------------------------------------------------------------------*/
794 ;;* flyspell-check-word-p ... */
795 ;;*---------------------------------------------------------------------*/
796 (defun flyspell-check-word-p ()
797 "Return t when the word at `point' has to be checked.
798 The answer depends of several criteria.
799 Mostly we check word delimiters."
800 (cond
801 ((<= (- (point-max) 1) (point-min))
802 ;; the buffer is not filled enough
803 nil)
804 ((and (and (> (current-column) 0)
805 (not (eq (current-column) flyspell-pre-column)))
806 (save-excursion
807 (backward-char 1)
808 (and (looking-at (flyspell-get-not-casechars))
809 (or flyspell-consider-dash-as-word-delimiter-flag
810 (not (looking-at "-"))))))
811 ;; yes because we have reached or typed a word delimiter.
813 ((symbolp this-command)
814 (cond
815 ((get this-command 'flyspell-deplacement)
816 (not (eq flyspell-previous-command this-command)))
817 ((get this-command 'flyspell-delayed)
818 ;; the current command is not delayed, that
819 ;; is that we must check the word now
820 (and (not unread-command-events)
821 (sit-for flyspell-delay)))
822 (t t)))
823 (t t)))
825 ;;*---------------------------------------------------------------------*/
826 ;;* flyspell-debug-signal-no-check ... */
827 ;;*---------------------------------------------------------------------*/
828 (defun flyspell-debug-signal-no-check (msg obj)
829 (setq debug-on-error t)
830 (with-current-buffer (get-buffer-create "*flyspell-debug*")
831 (erase-buffer)
832 (insert "NO-CHECK:\n")
833 (insert (format " %S : %S\n" msg obj))))
835 ;;*---------------------------------------------------------------------*/
836 ;;* flyspell-debug-signal-pre-word-checked ... */
837 ;;*---------------------------------------------------------------------*/
838 (defun flyspell-debug-signal-pre-word-checked ()
839 (setq debug-on-error t)
840 (with-current-buffer (get-buffer-create "*flyspell-debug*")
841 (insert "PRE-WORD:\n")
842 (insert (format " pre-point : %S\n" flyspell-pre-point))
843 (insert (format " pre-buffer : %S\n" flyspell-pre-buffer))
844 (insert (format " cache-start: %S\n" flyspell-word-cache-start))
845 (insert (format " cache-end : %S\n" flyspell-word-cache-end))
846 (goto-char (point-max))))
848 ;;*---------------------------------------------------------------------*/
849 ;;* flyspell-debug-signal-word-checked ... */
850 ;;*---------------------------------------------------------------------*/
851 (defun flyspell-debug-signal-word-checked ()
852 (setq debug-on-error t)
853 (let ((oldbuf (current-buffer))
854 (point (point)))
855 (with-current-buffer (get-buffer-create "*flyspell-debug*")
856 (insert "WORD:\n")
857 (insert (format " this-cmd : %S\n" this-command))
858 (insert (format " delayed : %S\n" (and (symbolp this-command)
859 (get this-command 'flyspell-delayed))))
860 (insert (format " point : %S\n" point))
861 (insert (format " prev-char : [%c] %S\n"
862 (with-current-buffer oldbuf
863 (let ((c (if (> (point) (point-min))
864 (save-excursion
865 (backward-char 1)
866 (char-after (point)))
867 ? )))
869 (with-current-buffer oldbuf
870 (let ((c (if (> (point) (point-min))
871 (save-excursion
872 (backward-char 1)
873 (and (and (looking-at (flyspell-get-not-casechars)) 1)
874 (and (or flyspell-consider-dash-as-word-delimiter-flag
875 (not (looking-at "\\-"))) 2))))))
876 c))))
877 (insert (format " because : %S\n"
878 (cond
879 ((not (and (symbolp this-command)
880 (get this-command 'flyspell-delayed)))
881 ;; the current command is not delayed, that
882 ;; is that we must check the word now
883 'not-delayed)
884 ((with-current-buffer oldbuf
885 (let ((c (if (> (point) (point-min))
886 (save-excursion
887 (backward-char 1)
888 (and (looking-at (flyspell-get-not-casechars))
889 (or flyspell-consider-dash-as-word-delimiter-flag
890 (not (looking-at "\\-"))))))))
892 ;; yes because we have reached or typed a word delimiter.
893 'separator)
894 ((not (integerp flyspell-delay))
895 ;; yes because the user had set up a no-delay configuration.
896 'no-delay)
898 'sit-for))))
899 (goto-char (point-max)))))
901 ;;*---------------------------------------------------------------------*/
902 ;;* flyspell-debug-signal-changed-checked ... */
903 ;;*---------------------------------------------------------------------*/
904 (defun flyspell-debug-signal-changed-checked ()
905 (setq debug-on-error t)
906 (let ((point (point)))
907 (with-current-buffer (get-buffer-create "*flyspell-debug*")
908 (insert "CHANGED WORD:\n")
909 (insert (format " point : %S\n" point))
910 (goto-char (point-max)))))
912 ;;*---------------------------------------------------------------------*/
913 ;;* flyspell-post-command-hook ... */
914 ;;* ------------------------------------------------------------- */
915 ;;* It is possible that we check several words: */
916 ;;* 1- the current word is checked if the predicate */
917 ;;* FLYSPELL-CHECK-WORD-P is true */
918 ;;* 2- the word that used to be the current word before the */
919 ;;* THIS-COMMAND is checked if: */
920 ;;* a- the previous word is different from the current word */
921 ;;* b- the previous word as not just been checked by the */
922 ;;* previous FLYSPELL-POST-COMMAND-HOOK */
923 ;;* 3- the words changed by the THIS-COMMAND that are neither the */
924 ;;* previous word nor the current word */
925 ;;*---------------------------------------------------------------------*/
926 (defun flyspell-post-command-hook ()
927 "The `post-command-hook' used by flyspell to check a word in-the-fly."
928 (interactive)
929 (let ((command this-command)
930 ;; Prevent anything we do from affecting the mark.
931 deactivate-mark)
932 (if (flyspell-check-pre-word-p)
933 (with-current-buffer flyspell-pre-buffer
934 '(flyspell-debug-signal-pre-word-checked)
935 (save-excursion
936 (goto-char flyspell-pre-point)
937 (flyspell-word))))
938 (if (flyspell-check-word-p)
939 (progn
940 '(flyspell-debug-signal-word-checked)
941 (flyspell-word)
942 ;; we remember which word we have just checked.
943 ;; this will be used next time we will check a word
944 ;; to compare the next current word with the word
945 ;; that as been registered in the pre-command-hook
946 ;; that is these variables are used within the predicate
947 ;; FLYSPELL-CHECK-PRE-WORD-P
948 (setq flyspell-pre-pre-buffer (current-buffer))
949 (setq flyspell-pre-pre-point (point)))
950 (progn
951 (setq flyspell-pre-pre-buffer nil)
952 (setq flyspell-pre-pre-point nil)
953 ;; when a word is not checked because of a delayed command
954 ;; we do not disable the ispell cache.
955 (if (and (symbolp this-command) (get this-command 'flyspell-delayed))
956 (progn
957 (setq flyspell-word-cache-end -1)
958 (setq flyspell-word-cache-result '_)))))
959 (while (and (not (input-pending-p)) (consp flyspell-changes))
960 (let ((start (car (car flyspell-changes)))
961 (stop (cdr (car flyspell-changes))))
962 (if (flyspell-check-changed-word-p start stop)
963 (save-excursion
964 '(flyspell-debug-signal-changed-checked)
965 (goto-char start)
966 (flyspell-word)))
967 (setq flyspell-changes (cdr flyspell-changes))))
968 (setq flyspell-previous-command command)))
970 ;;*---------------------------------------------------------------------*/
971 ;;* flyspell-notify-misspell ... */
972 ;;*---------------------------------------------------------------------*/
973 (defun flyspell-notify-misspell (word poss)
974 (let ((replacements (if (stringp poss)
975 poss
976 (if flyspell-sort-corrections
977 (sort (car (cdr (cdr poss))) 'string<)
978 (car (cdr (cdr poss)))))))
979 (if flyspell-issue-message-flag
980 (message "misspelling `%s' %S" word replacements))))
982 ;;*---------------------------------------------------------------------*/
983 ;;* flyspell-word-search-backward ... */
984 ;;*---------------------------------------------------------------------*/
985 (defun flyspell-word-search-backward (word bound)
986 (save-excursion
987 (let ((r '())
988 (inhibit-point-motion-hooks t)
990 (while (and (not r) (setq p (search-backward word bound t)))
991 (let ((lw (flyspell-get-word '())))
992 (if (and (consp lw) (string-equal (car lw) word))
993 (setq r p)
994 (goto-char p))))
995 r)))
997 ;;*---------------------------------------------------------------------*/
998 ;;* flyspell-word-search-forward ... */
999 ;;*---------------------------------------------------------------------*/
1000 (defun flyspell-word-search-forward (word bound)
1001 (save-excursion
1002 (let ((r '())
1003 (inhibit-point-motion-hooks t)
1005 (while (and (not r) (setq p (search-forward word bound t)))
1006 (let ((lw (flyspell-get-word '())))
1007 (if (and (consp lw) (string-equal (car lw) word))
1008 (setq r p)
1009 (goto-char (1+ p)))))
1010 r)))
1012 ;;*---------------------------------------------------------------------*/
1013 ;;* flyspell-word ... */
1014 ;;*---------------------------------------------------------------------*/
1015 (defun flyspell-word (&optional following)
1016 "Spell check a word."
1017 (interactive (list ispell-following-word))
1018 (save-excursion
1019 ;; use the correct dictionary
1020 (flyspell-accept-buffer-local-defs)
1021 (let* ((cursor-location (point))
1022 (flyspell-word (flyspell-get-word following))
1023 start end poss word ispell-filter)
1024 (if (or (eq flyspell-word nil)
1025 (and (fboundp flyspell-generic-check-word-predicate)
1026 (not (funcall flyspell-generic-check-word-predicate))))
1028 (progn
1029 ;; destructure return flyspell-word info list.
1030 (setq start (car (cdr flyspell-word))
1031 end (car (cdr (cdr flyspell-word)))
1032 word (car flyspell-word))
1033 ;; before checking in the directory, we check for doublons.
1034 (cond
1035 ((and (or (not (eq ispell-parser 'tex))
1036 (and (> start (point-min))
1037 (not (memq (char-after (1- start)) '(?\} ?\\)))))
1038 flyspell-mark-duplications-flag
1039 (not (catch 'exception
1040 (dolist (except flyspell-mark-duplications-exceptions)
1041 (and (string= (or ispell-local-dictionary
1042 ispell-dictionary)
1043 (car except))
1044 (member (downcase word) (cdr except))
1045 (throw 'exception t)))))
1046 (save-excursion
1047 (goto-char start)
1048 (let* ((bound
1049 (- start
1050 (- end start)
1051 (- (skip-chars-backward " \t\n\f"))))
1052 (p (when (>= bound (point-min))
1053 (flyspell-word-search-backward word bound))))
1054 (and p (/= p start)))))
1055 ;; yes, this is a doublon
1056 (flyspell-highlight-incorrect-region start end 'doublon)
1057 nil)
1058 ((and (eq flyspell-word-cache-start start)
1059 (eq flyspell-word-cache-end end)
1060 (string-equal flyspell-word-cache-word word))
1061 ;; this word had been already checked, we skip
1062 flyspell-word-cache-result)
1063 ((and (eq ispell-parser 'tex)
1064 (flyspell-tex-command-p flyspell-word))
1065 ;; this is a correct word (because a tex command)
1066 (flyspell-unhighlight-at start)
1067 (if (> end start)
1068 (flyspell-unhighlight-at (- end 1)))
1071 ;; we setup the cache
1072 (setq flyspell-word-cache-start start)
1073 (setq flyspell-word-cache-end end)
1074 (setq flyspell-word-cache-word word)
1075 ;; now check spelling of word.
1076 (ispell-send-string "%\n")
1077 ;; put in verbose mode
1078 (ispell-send-string (concat "^" word "\n"))
1079 ;; we mark the ispell process so it can be killed
1080 ;; when emacs is exited without query
1081 (set-process-query-on-exit-flag ispell-process nil)
1082 ;; Wait until ispell has processed word. Since this code is often
1083 ;; executed from post-command-hook but the ispell process may not
1084 ;; be responsive, it's important to make sure we re-enable C-g.
1085 (with-local-quit
1086 (while (progn
1087 (accept-process-output ispell-process)
1088 (not (string= "" (car ispell-filter))))))
1089 ;; (ispell-send-string "!\n")
1090 ;; back to terse mode.
1091 ;; Remove leading empty element
1092 (setq ispell-filter (cdr ispell-filter))
1093 ;; ispell process should return something after word is sent.
1094 ;; Tag word as valid (i.e., skip) otherwise
1095 (or ispell-filter
1096 (setq ispell-filter '(*)))
1097 (if (consp ispell-filter)
1098 (setq poss (ispell-parse-output (car ispell-filter))))
1099 (let ((res (cond ((eq poss t)
1100 ;; correct
1101 (setq flyspell-word-cache-result t)
1102 (flyspell-unhighlight-at start)
1103 (if (> end start)
1104 (flyspell-unhighlight-at (- end 1)))
1106 ((and (stringp poss) flyspell-highlight-flag)
1107 ;; correct
1108 (setq flyspell-word-cache-result t)
1109 (flyspell-unhighlight-at start)
1110 (if (> end start)
1111 (flyspell-unhighlight-at (- end 1)))
1113 ((null poss)
1114 (setq flyspell-word-cache-result t)
1115 (flyspell-unhighlight-at start)
1116 (if (> end start)
1117 (flyspell-unhighlight-at (- end 1)))
1119 ((or (and (< flyspell-duplicate-distance 0)
1120 (or (save-excursion
1121 (goto-char start)
1122 (flyspell-word-search-backward
1123 word
1124 (point-min)))
1125 (save-excursion
1126 (goto-char end)
1127 (flyspell-word-search-forward
1128 word
1129 (point-max)))))
1130 (and (> flyspell-duplicate-distance 0)
1131 (or (save-excursion
1132 (goto-char start)
1133 (flyspell-word-search-backward
1134 word
1135 (- start
1136 flyspell-duplicate-distance)))
1137 (save-excursion
1138 (goto-char end)
1139 (flyspell-word-search-forward
1140 word
1141 (+ end
1142 flyspell-duplicate-distance))))))
1143 ;; This is a misspelled word which occurs
1144 ;; twice within flyspell-duplicate-distance.
1145 (setq flyspell-word-cache-result nil)
1146 (if flyspell-highlight-flag
1147 (flyspell-highlight-duplicate-region
1148 start end poss)
1149 (message "duplicate `%s'" word))
1150 nil)
1152 (setq flyspell-word-cache-result nil)
1153 ;; incorrect highlight the location
1154 (if flyspell-highlight-flag
1155 (flyspell-highlight-incorrect-region
1156 start end poss)
1157 (flyspell-notify-misspell word poss))
1158 nil))))
1159 ;; return to original location
1160 (goto-char cursor-location)
1161 (if ispell-quit (setq ispell-quit nil))
1162 res))))))))
1164 ;;*---------------------------------------------------------------------*/
1165 ;;* flyspell-tex-math-initialized ... */
1166 ;;*---------------------------------------------------------------------*/
1167 (defvar flyspell-tex-math-initialized nil)
1169 ;;*---------------------------------------------------------------------*/
1170 ;;* flyspell-math-tex-command-p ... */
1171 ;;* ------------------------------------------------------------- */
1172 ;;* This function uses the texmathp package to check if (point) */
1173 ;;* is within a tex command. In order to avoid using */
1174 ;;* condition-case each time we use the variable */
1175 ;;* flyspell-tex-math-initialized to make a special case the first */
1176 ;;* time that function is called. */
1177 ;;*---------------------------------------------------------------------*/
1178 (defun flyspell-math-tex-command-p ()
1179 (when (fboundp 'texmathp)
1180 (cond
1181 (flyspell-check-tex-math-command
1182 nil)
1183 ((eq flyspell-tex-math-initialized t)
1184 (texmathp))
1185 ((eq flyspell-tex-math-initialized 'error)
1186 nil)
1188 (setq flyspell-tex-math-initialized t)
1189 (condition-case nil
1190 (texmathp)
1191 (error (progn
1192 (setq flyspell-tex-math-initialized 'error)
1193 nil)))))))
1195 ;;*---------------------------------------------------------------------*/
1196 ;;* flyspell-tex-command-p ... */
1197 ;;*---------------------------------------------------------------------*/
1198 (defun flyspell-tex-command-p (word)
1199 "Return t if WORD is a TeX command."
1200 (or (save-excursion
1201 (let ((b (car (cdr word))))
1202 (and (re-search-backward "\\\\" (- (point) 100) t)
1203 (or (= (match-end 0) b)
1204 (and (goto-char (match-end 0))
1205 (looking-at flyspell-tex-command-regexp)
1206 (>= (match-end 0) b))))))
1207 (flyspell-math-tex-command-p)))
1209 ;;*---------------------------------------------------------------------*/
1210 ;;* flyspell-casechars-cache ... */
1211 ;;*---------------------------------------------------------------------*/
1212 (defvar flyspell-casechars-cache nil)
1213 (defvar flyspell-ispell-casechars-cache nil)
1214 (make-variable-buffer-local 'flyspell-casechars-cache)
1215 (make-variable-buffer-local 'flyspell-ispell-casechars-cache)
1217 ;;*---------------------------------------------------------------------*/
1218 ;;* flyspell-get-casechars ... */
1219 ;;*---------------------------------------------------------------------*/
1220 (defun flyspell-get-casechars ()
1221 "This function builds a string that is the regexp of word chars.
1222 In order to avoid one useless string construction,
1223 this function changes the last char of the `ispell-casechars' string."
1224 (let ((ispell-casechars (ispell-get-casechars)))
1225 (cond
1226 ((eq ispell-parser 'tex)
1227 (setq flyspell-ispell-casechars-cache ispell-casechars)
1228 (setq flyspell-casechars-cache
1229 (concat (substring ispell-casechars
1231 (- (length ispell-casechars) 1))
1232 "]"))
1233 flyspell-casechars-cache)
1235 (setq flyspell-ispell-casechars-cache ispell-casechars)
1236 (setq flyspell-casechars-cache ispell-casechars)
1237 flyspell-casechars-cache))))
1239 ;;*---------------------------------------------------------------------*/
1240 ;;* flyspell-get-not-casechars-cache ... */
1241 ;;*---------------------------------------------------------------------*/
1242 (defvar flyspell-not-casechars-cache nil)
1243 (defvar flyspell-ispell-not-casechars-cache nil)
1244 (make-variable-buffer-local 'flyspell-not-casechars-cache)
1245 (make-variable-buffer-local 'flyspell-ispell-not-casechars-cache)
1247 ;;*---------------------------------------------------------------------*/
1248 ;;* flyspell-get-not-casechars ... */
1249 ;;*---------------------------------------------------------------------*/
1250 (defun flyspell-get-not-casechars ()
1251 "This function builds a string that is the regexp of non-word chars."
1252 (let ((ispell-not-casechars (ispell-get-not-casechars)))
1253 (cond
1254 ((eq ispell-parser 'tex)
1255 (setq flyspell-ispell-not-casechars-cache ispell-not-casechars)
1256 (setq flyspell-not-casechars-cache
1257 (concat (substring ispell-not-casechars
1259 (- (length ispell-not-casechars) 1))
1260 "]"))
1261 flyspell-not-casechars-cache)
1263 (setq flyspell-ispell-not-casechars-cache ispell-not-casechars)
1264 (setq flyspell-not-casechars-cache ispell-not-casechars)
1265 flyspell-not-casechars-cache))))
1267 ;;*---------------------------------------------------------------------*/
1268 ;;* flyspell-get-word ... */
1269 ;;*---------------------------------------------------------------------*/
1270 (defun flyspell-get-word (following &optional extra-otherchars)
1271 "Return the word for spell-checking according to Ispell syntax.
1272 If optional argument FOLLOWING is non-nil or if `flyspell-following-word'
1273 is non-nil when called interactively, then the following word
1274 \(rather than preceding\) is checked when the cursor is not over a word.
1275 Optional second argument contains otherchars that can be included in word
1276 many times.
1278 Word syntax described by `flyspell-dictionary-alist' (which see)."
1279 (let* ((flyspell-casechars (flyspell-get-casechars))
1280 (flyspell-not-casechars (flyspell-get-not-casechars))
1281 (ispell-otherchars (ispell-get-otherchars))
1282 (ispell-many-otherchars-p (ispell-get-many-otherchars-p))
1283 (word-regexp (concat flyspell-casechars
1284 "+\\("
1285 (if (not (string= "" ispell-otherchars))
1286 (concat ispell-otherchars "?"))
1287 (if extra-otherchars
1288 (concat extra-otherchars "?"))
1289 flyspell-casechars
1290 "+\\)"
1291 (if (or ispell-many-otherchars-p
1292 extra-otherchars)
1293 "*" "?")))
1294 did-it-once prevpt
1295 start end word)
1296 ;; find the word
1297 (if (not (looking-at flyspell-casechars))
1298 (if following
1299 (re-search-forward flyspell-casechars nil t)
1300 (re-search-backward flyspell-casechars nil t)))
1301 ;; move to front of word
1302 (re-search-backward flyspell-not-casechars nil 'start)
1303 (while (and (or (and (not (string= "" ispell-otherchars))
1304 (looking-at ispell-otherchars))
1305 (and extra-otherchars (looking-at extra-otherchars)))
1306 (not (bobp))
1307 (or (not did-it-once)
1308 ispell-many-otherchars-p)
1309 (not (eq prevpt (point))))
1310 (if (and extra-otherchars (looking-at extra-otherchars))
1311 (progn
1312 (backward-char 1)
1313 (if (looking-at flyspell-casechars)
1314 (re-search-backward flyspell-not-casechars nil 'move)))
1315 (setq did-it-once t
1316 prevpt (point))
1317 (backward-char 1)
1318 (if (looking-at flyspell-casechars)
1319 (re-search-backward flyspell-not-casechars nil 'move)
1320 (backward-char -1))))
1321 ;; Now mark the word and save to string.
1322 (if (not (re-search-forward word-regexp nil t))
1324 (progn
1325 (setq start (match-beginning 0)
1326 end (point)
1327 word (buffer-substring-no-properties start end))
1328 (list word start end)))))
1330 ;;*---------------------------------------------------------------------*/
1331 ;;* flyspell-small-region ... */
1332 ;;*---------------------------------------------------------------------*/
1333 (defun flyspell-small-region (beg end)
1334 "Flyspell text between BEG and END."
1335 (save-excursion
1336 (if (> beg end)
1337 (let ((old beg))
1338 (setq beg end)
1339 (setq end old)))
1340 (goto-char beg)
1341 (let ((count 0))
1342 (while (< (point) end)
1343 (if (and flyspell-issue-message-flag (= count 100))
1344 (progn
1345 (message "Spell Checking...%d%%"
1346 (* 100 (/ (float (- (point) beg)) (- end beg))))
1347 (setq count 0))
1348 (setq count (+ 1 count)))
1349 (flyspell-word)
1350 (sit-for 0)
1351 (let ((cur (point)))
1352 (forward-word 1)
1353 (if (and (< (point) end) (> (point) (+ cur 1)))
1354 (backward-char 1)))))
1355 (backward-char 1)
1356 (if flyspell-issue-message-flag (message "Spell Checking completed."))
1357 (flyspell-word)))
1359 ;;*---------------------------------------------------------------------*/
1360 ;;* flyspell-external-ispell-process ... */
1361 ;;*---------------------------------------------------------------------*/
1362 (defvar flyspell-external-ispell-process '()
1363 "The external Flyspell Ispell process.")
1365 ;;*---------------------------------------------------------------------*/
1366 ;;* flyspell-external-ispell-buffer ... */
1367 ;;*---------------------------------------------------------------------*/
1368 (defvar flyspell-external-ispell-buffer '())
1369 (defvar flyspell-large-region-buffer '())
1370 (defvar flyspell-large-region-beg (point-min))
1371 (defvar flyspell-large-region-end (point-max))
1373 ;;*---------------------------------------------------------------------*/
1374 ;;* flyspell-external-point-words ... */
1375 ;;*---------------------------------------------------------------------*/
1376 (defun flyspell-external-point-words ()
1377 "Mark words from a buffer listing incorrect words in order of appearance.
1378 The list of incorrect words should be in `flyspell-external-ispell-buffer'.
1379 \(We finish by killing that buffer and setting the variable to nil.)
1380 The buffer to mark them in is `flyspell-large-region-buffer'."
1381 (let (words-not-found
1382 (ispell-otherchars (ispell-get-otherchars))
1383 (buffer-scan-pos flyspell-large-region-beg)
1384 case-fold-search)
1385 (with-current-buffer flyspell-external-ispell-buffer
1386 (goto-char (point-min))
1387 ;; Loop over incorrect words, in the order they were reported,
1388 ;; which is also the order they appear in the buffer being checked.
1389 (while (re-search-forward "\\([^\n]+\\)\n" nil t)
1390 ;; Bind WORD to the next one.
1391 (let ((word (match-string 1)) (wordpos (point)))
1392 ;; Here there used to be code to see if WORD is the same
1393 ;; as the previous iteration, and count the number of consecutive
1394 ;; identical words, and the loop below would search for that many.
1395 ;; That code seemed to be incorrect, and on principle, should
1396 ;; be unnecessary too. -- rms.
1397 (if flyspell-issue-message-flag
1398 (message "Spell Checking...%d%% [%s]"
1399 (* 100 (/ (float (point)) (point-max)))
1400 word))
1401 (with-current-buffer flyspell-large-region-buffer
1402 (goto-char buffer-scan-pos)
1403 (let ((keep t))
1404 ;; Iterate on string search until string is found as word,
1405 ;; not as substring
1406 (while keep
1407 (if (search-forward word
1408 flyspell-large-region-end t)
1409 (let* ((found-list
1410 (save-excursion
1411 ;; Move back into the match
1412 ;; so flyspell-get-word will find it.
1413 (forward-char -1)
1414 (flyspell-get-word nil)))
1415 (found (car found-list))
1416 (found-length (length found))
1417 (misspell-length (length word)))
1418 (when (or
1419 ;; Size matches, we really found it.
1420 (= found-length misspell-length)
1421 ;; Matches as part of a boundary-char separated word
1422 (member word
1423 (split-string found ispell-otherchars))
1424 ;; Misspelling has higher length than
1425 ;; what flyspell considers the
1426 ;; word. Caused by boundary-chars
1427 ;; mismatch. Validating seems safe.
1428 (< found-length misspell-length)
1429 ;; ispell treats beginning of some TeX
1430 ;; commands as nroff control sequences
1431 ;; and strips them in the list of
1432 ;; misspelled words thus giving a
1433 ;; non-existent word. Skip if ispell
1434 ;; is used, string is a TeX command
1435 ;; (char before beginning of word is
1436 ;; backslash) and none of the previous
1437 ;; contitions match
1438 (and (not ispell-really-aspell)
1439 (save-excursion
1440 (goto-char (- (nth 1 found-list) 1))
1441 (if (looking-at "[\\]" )
1443 nil))))
1444 (setq keep nil)
1445 (flyspell-word)
1446 ;; Search for next misspelled word will begin from
1447 ;; end of last validated match.
1448 (setq buffer-scan-pos (point))))
1449 ;; Record if misspelling is not found and try new one
1450 (add-to-list 'words-not-found
1451 (concat " -> " word " - "
1452 (int-to-string wordpos)))
1453 (setq keep nil)))))))
1454 ;; we are done
1455 (if flyspell-issue-message-flag (message "Spell Checking completed.")))
1456 ;; Warn about not found misspellings
1457 (dolist (word words-not-found)
1458 (message "%s: word not found" word))
1459 ;; Kill and forget the buffer with the list of incorrect words.
1460 (kill-buffer flyspell-external-ispell-buffer)
1461 (setq flyspell-external-ispell-buffer nil)))
1463 ;;*---------------------------------------------------------------------*/
1464 ;;* flyspell-process-localwords ... */
1465 ;;* ------------------------------------------------------------- */
1466 ;;* This function is used to prevent marking of words explicitly */
1467 ;;* declared correct. */
1468 ;;*---------------------------------------------------------------------*/
1469 (defun flyspell-process-localwords (misspellings-buffer)
1470 (let (localwords case-fold-search
1471 (ispell-casechars (ispell-get-casechars)))
1472 ;; Get localwords from the original buffer
1473 (save-excursion
1474 (goto-char (point-min))
1475 ;; Localwords parsing copied from ispell.el.
1476 (while (search-forward ispell-words-keyword nil t)
1477 (let ((end (save-excursion (end-of-line) (point)))
1478 string)
1479 ;; buffer-local words separated by a space, and can contain
1480 ;; any character other than a space. Not rigorous enough.
1481 (while (re-search-forward " *\\([^ ]+\\)" end t)
1482 (setq string (buffer-substring-no-properties (match-beginning 1)
1483 (match-end 1)))
1484 ;; This can fail when string contains a word with invalid chars.
1485 ;; Error handling needs to be added between Ispell and Emacs.
1486 (if (and (< 1 (length string))
1487 (equal 0 (string-match ispell-casechars string)))
1488 (push string localwords))))))
1489 ;; Remove localwords matches from misspellings-buffer.
1490 ;; The usual mechanism of communicating the local words to ispell
1491 ;; does not affect the special ispell process used by
1492 ;; flyspell-large-region.
1493 (with-current-buffer misspellings-buffer
1494 (save-excursion
1495 (dolist (word localwords)
1496 (goto-char (point-min))
1497 (let ((regexp (concat "^" word "\n")))
1498 (while (re-search-forward regexp nil t)
1499 (delete-region (match-beginning 0) (match-end 0)))))))))
1501 ;;* ---------------------------------------------------------------
1502 ;;* flyspell-check-region-doublons
1503 ;;* ---------------------------------------------------------------
1504 (defun flyspell-check-region-doublons (beg end)
1505 "Check for adjacent duplicated words (doublons) in the given region."
1506 (save-excursion
1507 (goto-char beg)
1508 (flyspell-word) ; Make sure current word is checked
1509 (backward-word 1)
1510 (while (and (< (point) end)
1511 (re-search-forward "\\<\\(\\w+\\)\\>[ \n\t\f]+\\1\\>"
1512 end 'move))
1513 (flyspell-word)
1514 (backward-word 1))
1515 (flyspell-word)))
1517 ;;*---------------------------------------------------------------------*/
1518 ;;* flyspell-large-region ... */
1519 ;;*---------------------------------------------------------------------*/
1520 (defun flyspell-large-region (beg end)
1521 (let* ((curbuf (current-buffer))
1522 (buffer (get-buffer-create "*flyspell-region*")))
1523 (setq flyspell-external-ispell-buffer buffer)
1524 (setq flyspell-large-region-buffer curbuf)
1525 (setq flyspell-large-region-beg beg)
1526 (setq flyspell-large-region-end end)
1527 (flyspell-accept-buffer-local-defs)
1528 (set-buffer buffer)
1529 (erase-buffer)
1530 ;; this is done, we can start checking...
1531 (if flyspell-issue-message-flag (message "Checking region..."))
1532 (set-buffer curbuf)
1533 (ispell-check-version)
1534 (let ((c (apply 'ispell-call-process-region beg
1536 ispell-program-name
1538 buffer
1540 (if ispell-really-aspell "list" "-l")
1541 (let (args)
1542 ;; Local dictionary becomes the global dictionary in use.
1543 (if ispell-local-dictionary
1544 (setq ispell-dictionary ispell-local-dictionary))
1545 (setq args (ispell-get-ispell-args))
1546 (if ispell-dictionary ; use specified dictionary
1547 (setq args
1548 (append (list "-d" ispell-dictionary) args)))
1549 (if ispell-personal-dictionary ; use specified pers dict
1550 (setq args
1551 (append args
1552 (list "-p"
1553 (expand-file-name
1554 ispell-personal-dictionary)))))
1555 (setq args (append args ispell-extra-args))
1556 args))))
1557 (if (eq c 0)
1558 (progn
1559 (flyspell-process-localwords buffer)
1560 (with-current-buffer curbuf
1561 (flyspell-delete-region-overlays beg end)
1562 (flyspell-check-region-doublons beg end))
1563 (flyspell-external-point-words))
1564 (error "Can't check region...")))))
1566 ;;*---------------------------------------------------------------------*/
1567 ;;* flyspell-region ... */
1568 ;;* ------------------------------------------------------------- */
1569 ;;* Because `ispell -a' is too slow, it is not possible to use */
1570 ;;* it on large region. Then, when ispell is invoked on a large */
1571 ;;* text region, a new `ispell -l' process is spawned. The */
1572 ;;* pointed out words are then searched in the region a checked with */
1573 ;;* regular flyspell means. */
1574 ;;*---------------------------------------------------------------------*/
1575 ;;;###autoload
1576 (defun flyspell-region (beg end)
1577 "Flyspell text between BEG and END."
1578 (interactive "r")
1579 (if (= beg end)
1581 (save-excursion
1582 (if (> beg end)
1583 (let ((old beg))
1584 (setq beg end)
1585 (setq end old)))
1586 (if (and flyspell-large-region (> (- end beg) flyspell-large-region))
1587 (flyspell-large-region beg end)
1588 (flyspell-small-region beg end)))))
1590 ;;*---------------------------------------------------------------------*/
1591 ;;* flyspell-buffer ... */
1592 ;;*---------------------------------------------------------------------*/
1593 ;;;###autoload
1594 (defun flyspell-buffer ()
1595 "Flyspell whole buffer."
1596 (interactive)
1597 (flyspell-region (point-min) (point-max)))
1599 ;;*---------------------------------------------------------------------*/
1600 ;;* old next error position ... */
1601 ;;*---------------------------------------------------------------------*/
1602 (defvar flyspell-old-buffer-error nil)
1603 (defvar flyspell-old-pos-error nil)
1605 ;;*---------------------------------------------------------------------*/
1606 ;;* flyspell-goto-next-error ... */
1607 ;;*---------------------------------------------------------------------*/
1608 (defun flyspell-goto-next-error ()
1609 "Go to the next previously detected error.
1610 In general FLYSPELL-GOTO-NEXT-ERROR must be used after
1611 FLYSPELL-BUFFER."
1612 (interactive)
1613 (let ((pos (point))
1614 (max (point-max)))
1615 (if (and (eq (current-buffer) flyspell-old-buffer-error)
1616 (eq pos flyspell-old-pos-error))
1617 (progn
1618 (if (= flyspell-old-pos-error max)
1619 ;; goto beginning of buffer
1620 (progn
1621 (message "Restarting from beginning of buffer")
1622 (goto-char (point-min)))
1623 (forward-word 1))
1624 (setq pos (point))))
1625 ;; seek the next error
1626 (while (and (< pos max)
1627 (let ((ovs (overlays-at pos))
1628 (r '()))
1629 (while (and (not r) (consp ovs))
1630 (if (flyspell-overlay-p (car ovs))
1631 (setq r t)
1632 (setq ovs (cdr ovs))))
1633 (not r)))
1634 (setq pos (1+ pos)))
1635 ;; save the current location for next invocation
1636 (setq flyspell-old-pos-error pos)
1637 (setq flyspell-old-buffer-error (current-buffer))
1638 (goto-char pos)
1639 (if (= pos max)
1640 (message "No more miss-spelled word!"))))
1642 ;;*---------------------------------------------------------------------*/
1643 ;;* flyspell-overlay-p ... */
1644 ;;*---------------------------------------------------------------------*/
1645 (defun flyspell-overlay-p (o)
1646 "Return true if O is an overlay used by flyspell."
1647 (and (overlayp o) (overlay-get o 'flyspell-overlay)))
1649 ;;*---------------------------------------------------------------------*/
1650 ;;* flyspell-delete-region-overlays, flyspell-delete-all-overlays */
1651 ;;* ------------------------------------------------------------- */
1652 ;;* Remove overlays introduced by flyspell. */
1653 ;;*---------------------------------------------------------------------*/
1654 (defun flyspell-delete-region-overlays (beg end)
1655 "Delete overlays used by flyspell in a given region."
1656 (remove-overlays beg end 'flyspell-overlay t))
1659 (defun flyspell-delete-all-overlays ()
1660 "Delete all the overlays used by flyspell."
1661 (remove-overlays (point-min) (point-max) 'flyspell-overlay t))
1663 ;;*---------------------------------------------------------------------*/
1664 ;;* flyspell-unhighlight-at ... */
1665 ;;*---------------------------------------------------------------------*/
1666 (defun flyspell-unhighlight-at (pos)
1667 "Remove the flyspell overlay that are located at POS."
1668 (if flyspell-persistent-highlight
1669 (let ((overlays (overlays-at pos)))
1670 (while (consp overlays)
1671 (if (flyspell-overlay-p (car overlays))
1672 (delete-overlay (car overlays)))
1673 (setq overlays (cdr overlays))))
1674 (if (flyspell-overlay-p flyspell-overlay)
1675 (delete-overlay flyspell-overlay))))
1677 ;;*---------------------------------------------------------------------*/
1678 ;;* flyspell-properties-at-p ... */
1679 ;;* ------------------------------------------------------------- */
1680 ;;* Is there an highlight properties at position pos? */
1681 ;;*---------------------------------------------------------------------*/
1682 (defun flyspell-properties-at-p (pos)
1683 "Return t if there is a text property at POS, not counting `local-map'.
1684 If variable `flyspell-highlight-properties' is set to nil,
1685 text with properties are not checked. This function is used to discover
1686 if the character at POS has any other property."
1687 (let ((prop (text-properties-at pos))
1688 (keep t))
1689 (while (and keep (consp prop))
1690 (if (and (eq (car prop) 'local-map) (consp (cdr prop)))
1691 (setq prop (cdr (cdr prop)))
1692 (setq keep nil)))
1693 (consp prop)))
1695 ;;*---------------------------------------------------------------------*/
1696 ;;* make-flyspell-overlay ... */
1697 ;;*---------------------------------------------------------------------*/
1698 (defun make-flyspell-overlay (beg end face mouse-face)
1699 "Allocate an overlay to highlight an incorrect word.
1700 BEG and END specify the range in the buffer of that word.
1701 FACE and MOUSE-FACE specify the `face' and `mouse-face' properties
1702 for the overlay."
1703 (let ((overlay (make-overlay beg end nil t nil)))
1704 (overlay-put overlay 'face face)
1705 (overlay-put overlay 'mouse-face mouse-face)
1706 (overlay-put overlay 'flyspell-overlay t)
1707 (overlay-put overlay 'evaporate t)
1708 (overlay-put overlay 'help-echo "mouse-2: correct word at point")
1709 (overlay-put overlay 'keymap flyspell-mouse-map)
1710 (when (eq face 'flyspell-incorrect)
1711 (and (stringp flyspell-before-incorrect-word-string)
1712 (overlay-put overlay 'before-string
1713 flyspell-before-incorrect-word-string))
1714 (and (stringp flyspell-after-incorrect-word-string)
1715 (overlay-put overlay 'after-string
1716 flyspell-after-incorrect-word-string)))
1717 overlay))
1719 ;;*---------------------------------------------------------------------*/
1720 ;;* flyspell-highlight-incorrect-region ... */
1721 ;;*---------------------------------------------------------------------*/
1722 (defun flyspell-highlight-incorrect-region (beg end poss)
1723 "Set up an overlay on a misspelled word, in the buffer from BEG to END.
1724 POSS is usually a list of possible spelling/correction lists,
1725 as returned by `ispell-parse-output'.
1726 It can also be the symbol `doublon', in the case where the word
1727 is itself incorrect, but suspiciously repeated."
1728 (let ((inhibit-read-only t))
1729 (unless (run-hook-with-args-until-success
1730 'flyspell-incorrect-hook beg end poss)
1731 (if (or flyspell-highlight-properties
1732 (not (flyspell-properties-at-p beg)))
1733 (progn
1734 ;; we cleanup all the overlay that are in the region, not
1735 ;; beginning at the word start position
1736 (if (< (1+ beg) end)
1737 (let ((os (overlays-in (1+ beg) end)))
1738 (while (consp os)
1739 (if (flyspell-overlay-p (car os))
1740 (delete-overlay (car os)))
1741 (setq os (cdr os)))))
1742 ;; we cleanup current overlay at the same position
1743 (flyspell-unhighlight-at beg)
1744 ;; now we can use a new overlay
1745 (setq flyspell-overlay
1746 (make-flyspell-overlay
1747 beg end
1748 (if (eq poss 'doublon) 'flyspell-duplicate 'flyspell-incorrect)
1749 'highlight)))))))
1751 ;;*---------------------------------------------------------------------*/
1752 ;;* flyspell-highlight-duplicate-region ... */
1753 ;;*---------------------------------------------------------------------*/
1754 (defun flyspell-highlight-duplicate-region (beg end poss)
1755 "Set up an overlay on a duplicate misspelled word, in the buffer from BEG to END.
1756 POSS is a list of possible spelling/correction lists,
1757 as returned by `ispell-parse-output'."
1758 (let ((inhibit-read-only t))
1759 (unless (run-hook-with-args-until-success
1760 'flyspell-incorrect-hook beg end poss)
1761 (if (or flyspell-highlight-properties
1762 (not (flyspell-properties-at-p beg)))
1763 (progn
1764 ;; we cleanup current overlay at the same position
1765 (flyspell-unhighlight-at beg)
1766 ;; now we can use a new overlay
1767 (setq flyspell-overlay
1768 (make-flyspell-overlay beg end
1769 'flyspell-duplicate
1770 'highlight)))))))
1772 ;;*---------------------------------------------------------------------*/
1773 ;;* flyspell-auto-correct-cache ... */
1774 ;;*---------------------------------------------------------------------*/
1775 (defvar flyspell-auto-correct-pos nil)
1776 (defvar flyspell-auto-correct-region nil)
1777 (defvar flyspell-auto-correct-ring nil)
1778 (defvar flyspell-auto-correct-word nil)
1779 (make-variable-buffer-local 'flyspell-auto-correct-pos)
1780 (make-variable-buffer-local 'flyspell-auto-correct-region)
1781 (make-variable-buffer-local 'flyspell-auto-correct-ring)
1782 (make-variable-buffer-local 'flyspell-auto-correct-word)
1784 ;;*---------------------------------------------------------------------*/
1785 ;;* flyspell-check-previous-highlighted-word ... */
1786 ;;*---------------------------------------------------------------------*/
1787 (defun flyspell-check-previous-highlighted-word (&optional arg)
1788 "Correct the closer misspelled word.
1789 This function scans a mis-spelled word before the cursor. If it finds one
1790 it proposes replacement for that word. With prefix arg, count that many
1791 misspelled words backwards."
1792 (interactive)
1793 (let ((pos1 (point))
1794 (pos (point))
1795 (arg (if (or (not (numberp arg)) (< arg 1)) 1 arg))
1796 ov ovs)
1797 (if (catch 'exit
1798 (while (and (setq pos (previous-overlay-change pos))
1799 (not (= pos pos1)))
1800 (setq pos1 pos)
1801 (if (> pos (point-min))
1802 (progn
1803 (setq ovs (overlays-at (1- pos)))
1804 (while (consp ovs)
1805 (setq ov (car ovs))
1806 (setq ovs (cdr ovs))
1807 (if (and (flyspell-overlay-p ov)
1808 (= 0 (setq arg (1- arg))))
1809 (throw 'exit t)))))))
1810 (save-excursion
1811 (goto-char pos)
1812 (ispell-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 nil)))
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 mispelled 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-marker)))
2051 (let ((cursor-location (point))
2052 (word (flyspell-get-word nil)))
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 (flyspell-unhighlight-at cursor-location)
2111 (if (null ispell-pdict-modified-p)
2112 (setq ispell-pdict-modified-p
2113 (list ispell-pdict-modified-p)))
2114 (goto-char save)
2115 (if (eq replace 'buffer)
2116 (ispell-add-per-file-word-list word)))
2117 (replace
2118 ;; This was added only to the Emacs side. I assume its absence on
2119 ;; the XEmacs side was an oversight. --Stef
2120 (flyspell-unhighlight-at cursor-location)
2121 (let ((old-max (point-max))
2122 (new-word (if (atom replace)
2123 replace
2124 (car replace)))
2125 (cursor-location (+ (- (length word) (- end start))
2126 cursor-location)))
2127 (unless (equal new-word (car poss))
2128 (delete-region start end)
2129 (goto-char start)
2130 (funcall flyspell-insert-function new-word)
2131 (if flyspell-abbrev-p
2132 (flyspell-define-abbrev word new-word)))
2133 ;; In the original Emacs code, this was only called in the body
2134 ;; of the if. I arbitrarily kept the XEmacs behavior instead.
2135 (flyspell-ajust-cursor-point save cursor-location old-max)))
2137 (goto-char save)
2138 nil)))
2140 ;;*---------------------------------------------------------------------*/
2141 ;;* flyspell-ajust-cursor-point ... */
2142 ;;*---------------------------------------------------------------------*/
2143 (defun flyspell-ajust-cursor-point (save cursor-location old-max)
2144 (if (>= save cursor-location)
2145 (let ((new-pos (+ save (- (point-max) old-max))))
2146 (goto-char (cond
2147 ((< new-pos (point-min))
2148 (point-min))
2149 ((> new-pos (point-max))
2150 (point-max))
2151 (t new-pos))))
2152 (goto-char save)))
2154 ;;*---------------------------------------------------------------------*/
2155 ;;* flyspell-emacs-popup ... */
2156 ;;*---------------------------------------------------------------------*/
2157 (defun flyspell-emacs-popup (event poss word)
2158 "The Emacs popup menu."
2159 (unless window-system
2160 (error "This command requires pop-up dialogs"))
2161 (if (not event)
2162 (let* ((mouse-pos (mouse-position))
2163 (mouse-pos (if (nth 1 mouse-pos)
2164 mouse-pos
2165 (set-mouse-position (car mouse-pos)
2166 (/ (frame-width) 2) 2)
2167 (mouse-position))))
2168 (setq event (list (list (car (cdr mouse-pos))
2169 (1+ (cdr (cdr mouse-pos))))
2170 (car mouse-pos)))))
2171 (let* ((corrects (if flyspell-sort-corrections
2172 (sort (car (cdr (cdr poss))) 'string<)
2173 (car (cdr (cdr poss)))))
2174 (cor-menu (if (consp corrects)
2175 (mapcar (lambda (correct)
2176 (list correct correct))
2177 corrects)
2178 '()))
2179 (affix (car (cdr (cdr (cdr poss)))))
2180 show-affix-info
2181 (base-menu (let ((save (if (and (consp affix) show-affix-info)
2182 (list
2183 (list (concat "Save affix: " (car affix))
2184 'save)
2185 '("Accept (session)" session)
2186 '("Accept (buffer)" buffer))
2187 '(("Save word" save)
2188 ("Accept (session)" session)
2189 ("Accept (buffer)" buffer)))))
2190 (if (consp cor-menu)
2191 (append cor-menu (cons "" save))
2192 save)))
2193 (menu (cons "flyspell correction menu" base-menu)))
2194 (car (x-popup-menu event
2195 (list (format "%s [%s]" word (or ispell-local-dictionary
2196 ispell-dictionary))
2197 menu)))))
2199 ;;*---------------------------------------------------------------------*/
2200 ;;* flyspell-xemacs-popup ... */
2201 ;;*---------------------------------------------------------------------*/
2202 (defun flyspell-xemacs-popup (poss word cursor-location start end save)
2203 "The XEmacs popup menu."
2204 (let* ((corrects (if flyspell-sort-corrections
2205 (sort (car (cdr (cdr poss))) 'string<)
2206 (car (cdr (cdr poss)))))
2207 (cor-menu (if (consp corrects)
2208 (mapcar (lambda (correct)
2209 (vector correct
2210 (list 'flyspell-do-correct
2211 correct
2212 (list 'quote poss)
2213 word
2214 cursor-location
2215 start
2217 save)
2219 corrects)
2220 '()))
2221 (affix (car (cdr (cdr (cdr poss)))))
2222 show-affix-info
2223 (menu (let ((save (if (and (consp affix) show-affix-info)
2224 (vector
2225 (concat "Save affix: " (car affix))
2226 (list 'flyspell-do-correct
2227 ''save
2228 (list 'quote poss)
2229 word
2230 cursor-location
2231 start
2233 save)
2235 (vector
2236 "Save word"
2237 (list 'flyspell-do-correct
2238 ''save
2239 (list 'quote poss)
2240 word
2241 cursor-location
2242 start
2244 save)
2245 t)))
2246 (session (vector "Accept (session)"
2247 (list 'flyspell-do-correct
2248 ''session
2249 (list 'quote poss)
2250 word
2251 cursor-location
2252 start
2254 save)
2256 (buffer (vector "Accept (buffer)"
2257 (list 'flyspell-do-correct
2258 ''buffer
2259 (list 'quote poss)
2260 word
2261 cursor-location
2262 start
2264 save)
2265 t)))
2266 (if (consp cor-menu)
2267 (append cor-menu (list "-" save session buffer))
2268 (list save session buffer)))))
2269 (popup-menu (cons (format "%s [%s]" word (or ispell-local-dictionary
2270 ispell-dictionary))
2271 menu))))
2273 ;;*---------------------------------------------------------------------*/
2274 ;;* Some example functions for real autocorrecting */
2275 ;;*---------------------------------------------------------------------*/
2276 (defun flyspell-maybe-correct-transposition (beg end poss)
2277 "Check replacements for transposed characters.
2279 If the text between BEG and END is equal to a correction suggested by
2280 Ispell, after transposing two adjacent characters, correct the text,
2281 and return t.
2283 The third arg POSS is either the symbol 'doublon' or a list of
2284 possible corrections as returned by `ispell-parse-output'.
2286 This function is meant to be added to `flyspell-incorrect-hook'."
2287 (when (consp poss)
2288 (catch 'done
2289 (let ((str (buffer-substring beg end))
2290 (i 0) (len (- end beg)) tmp)
2291 (while (< (1+ i) len)
2292 (setq tmp (aref str i))
2293 (aset str i (aref str (1+ i)))
2294 (aset str (1+ i) tmp)
2295 (when (member str (nth 2 poss))
2296 (save-excursion
2297 (goto-char (+ beg i 1))
2298 (transpose-chars 1))
2299 (throw 'done t))
2300 (setq tmp (aref str i))
2301 (aset str i (aref str (1+ i)))
2302 (aset str (1+ i) tmp)
2303 (setq i (1+ i))))
2304 nil)))
2306 (defun flyspell-maybe-correct-doubling (beg end poss)
2307 "Check replacements for doubled characters.
2309 If the text between BEG and END is equal to a correction suggested by
2310 Ispell, after removing a pair of doubled characters, correct the text,
2311 and return t.
2313 The third arg POSS is either the symbol 'doublon' or a list of
2314 possible corrections as returned by `ispell-parse-output'.
2316 This function is meant to be added to `flyspell-incorrect-hook'."
2317 (when (consp poss)
2318 (catch 'done
2319 (let ((str (buffer-substring beg end))
2320 (i 0) (len (- end beg)))
2321 (while (< (1+ i) len)
2322 (when (and (= (aref str i) (aref str (1+ i)))
2323 (member (concat (substring str 0 (1+ i))
2324 (substring str (+ i 2)))
2325 (nth 2 poss)))
2326 (goto-char (+ beg i))
2327 (delete-char 1)
2328 (throw 'done t))
2329 (setq i (1+ i))))
2330 nil)))
2332 ;;*---------------------------------------------------------------------*/
2333 ;;* flyspell-already-abbrevp ... */
2334 ;;*---------------------------------------------------------------------*/
2335 (defun flyspell-already-abbrevp (table word)
2336 (let ((sym (abbrev-symbol word table)))
2337 (and sym (symbolp sym))))
2339 ;;*---------------------------------------------------------------------*/
2340 ;;* flyspell-change-abbrev ... */
2341 ;;*---------------------------------------------------------------------*/
2342 (defun flyspell-change-abbrev (table old new)
2343 (set (abbrev-symbol old table) new))
2345 (provide 'flyspell)
2347 ;; arch-tag: 05d915b9-e9cf-44fb-9137-fc28f5eaab2a
2348 ;;; flyspell.el ends here