Mercurial > emacs
annotate lisp/textmodes/flyspell.el @ 23422:a209636732e9
(Fw32_set_clipboard_data): Call find_charset_in_str with CMPCHARP arg 0.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Mon, 12 Oct 1998 12:00:44 +0000 |
parents | b0e173658e2e |
children | 764497f1c6a0 |
rev | line source |
---|---|
22611 | 1 ;;; flyspell.el --- On-the-fly spell checker |
2 | |
3 ;; Copyright (C) 1998 Free Software Foundation, Inc. | |
4 | |
5 ;; Author: Manuel Serrano <Manuel.Serrano@unice.fr> | |
22612
6def3da74c7c
Delete defcustom definition.
Richard M. Stallman <rms@gnu.org>
parents:
22611
diff
changeset
|
6 ;; Keywords: convenience |
22611 | 7 |
8 ;;; This file is part of GNU Emacs. | |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
12 ;; the Free Software Foundation; either version 2, or (at your option) | |
13 ;; any later version. | |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 ;; Boston, MA 02111-1307, USA. | |
24 | |
25 ;;; commentary: | |
26 ;; | |
27 ;; Flyspell is a minor Emacs mode performing on-the-fly spelling | |
22612
6def3da74c7c
Delete defcustom definition.
Richard M. Stallman <rms@gnu.org>
parents:
22611
diff
changeset
|
28 ;; checking. |
22611 | 29 ;; |
22891
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
30 ;; To enable Flyspell minor mode, type Meta-x flyspell-mode. |
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
31 ;; This applies only to the current buffer. |
22611 | 32 ;; |
22844
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
33 ;; Note: consider setting the variable ispell-parser to `tex' to |
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
34 ;; avoid TeX command checking; use `(setq ispell-parser 'tex)' |
22611 | 35 ;; _before_ entering flyspell. |
36 ;; | |
37 ;; Some user variables control the behavior of flyspell. They are | |
38 ;; those defined under the `User variables' comment. | |
39 ;; | |
22612
6def3da74c7c
Delete defcustom definition.
Richard M. Stallman <rms@gnu.org>
parents:
22611
diff
changeset
|
40 ;; Note: as suggested by Yaron M. Minsky, if you use flyspell when |
22611 | 41 ;; sending mails, you should add the following: |
42 ;; (add-hook 'mail-send-hook 'flyspell-mode-off) | |
43 | |
44 ;;; Code: | |
45 (require 'ispell) | |
46 | |
22891
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
47 ;*---------------------------------------------------------------------*/ |
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
48 ;* Group ... */ |
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
49 ;*---------------------------------------------------------------------*/ |
22611 | 50 (defgroup flyspell nil |
51 "Spellchecking on the fly." | |
52 :tag "FlySpell" | |
53 :prefix "flyspell-" | |
22648
3b7f1e026beb
*** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents:
22612
diff
changeset
|
54 :group 'processes |
3b7f1e026beb
*** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents:
22612
diff
changeset
|
55 :version "20.3") |
22611 | 56 |
57 ;*---------------------------------------------------------------------*/ | |
58 ;* User variables ... */ | |
59 ;*---------------------------------------------------------------------*/ | |
60 (defcustom flyspell-highlight-flag t | |
22844
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
61 "*How Flyspell should indicate misspelled words. |
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
62 Non-nil means use highlight, nil means use minibuffer messages." |
22611 | 63 :group 'flyspell |
64 :type 'boolean) | |
65 | |
22844
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
66 (defcustom flyspell-mark-duplications-flag t |
22962
f4509374e88e
(flyspell-command-hook): Option deleted.
Richard M. Stallman <rms@gnu.org>
parents:
22946
diff
changeset
|
67 "*Non-nil means Flyspell reports a repeated word as an error." |
22611 | 68 :group 'flyspell |
69 :type 'boolean) | |
70 | |
71 (defcustom flyspell-sort-corrections t | |
72 "*Non-nil means, sort the corrections alphabetically before popping them." | |
73 :group 'flyspell | |
74 :type 'boolean) | |
75 | |
22891
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
76 (defcustom flyspell-duplicate-distance 10000 |
22962
f4509374e88e
(flyspell-command-hook): Option deleted.
Richard M. Stallman <rms@gnu.org>
parents:
22946
diff
changeset
|
77 "*The maximum distance for finding duplicates of unrecognized words. |
f4509374e88e
(flyspell-command-hook): Option deleted.
Richard M. Stallman <rms@gnu.org>
parents:
22946
diff
changeset
|
78 This applies to the feature that when a word is not found in the dictionary, |
f4509374e88e
(flyspell-command-hook): Option deleted.
Richard M. Stallman <rms@gnu.org>
parents:
22946
diff
changeset
|
79 if the same spelling occurs elsewhere in the buffer, |
f4509374e88e
(flyspell-command-hook): Option deleted.
Richard M. Stallman <rms@gnu.org>
parents:
22946
diff
changeset
|
80 Flyspell uses a different face (`flyspell-duplicate-face') to highlight it. |
f4509374e88e
(flyspell-command-hook): Option deleted.
Richard M. Stallman <rms@gnu.org>
parents:
22946
diff
changeset
|
81 This variable specifies how far to search to find such a duplicate. |
22891
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
82 -1 means no limit (search the whole buffer). |
22962
f4509374e88e
(flyspell-command-hook): Option deleted.
Richard M. Stallman <rms@gnu.org>
parents:
22946
diff
changeset
|
83 0 means do not search for duplicate unrecognized spellings." |
22611 | 84 :group 'flyspell |
85 :type 'number) | |
86 | |
87 (defcustom flyspell-delay 3 | |
22891
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
88 "*The number of seconds to wait before checking, after a \"delayed\" command." |
22611 | 89 :group 'flyspell |
90 :type 'number) | |
91 | |
92 (defcustom flyspell-persistent-highlight t | |
22946
cfde96067373
(flyspell-persistent-highlight): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
22891
diff
changeset
|
93 "*Non-nil means misspelled words remain highlighted until corrected. |
cfde96067373
(flyspell-persistent-highlight): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
22891
diff
changeset
|
94 If this variable is nil, only the most recently detected misspelled word |
cfde96067373
(flyspell-persistent-highlight): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
22891
diff
changeset
|
95 is highlighted." |
22611 | 96 :group 'flyspell |
97 :type 'boolean) | |
98 | |
99 (defcustom flyspell-highlight-properties t | |
22844
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
100 "*Non-nil means highlight incorrect words even if a property exists for this word." |
22611 | 101 :group 'flyspell |
102 :type 'boolean) | |
103 | |
104 (defcustom flyspell-default-delayed-commands | |
105 '(self-insert-command | |
106 delete-backward-char | |
107 delete-char) | |
22844
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
108 "The standard list of delayed commands for Flyspell. |
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
109 See `flyspell-delayed-commands'." |
22611 | 110 :group 'flyspell |
111 :type '(repeat (symbol))) | |
112 | |
22844
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
113 (defcustom flyspell-delayed-commands nil |
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
114 "List of commands that are \"delayed\" for Flyspell mode. |
22891
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
115 After these commands, Flyspell checking is delayed for a short time, |
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
116 whose length is specified by `flyspell-delay'." |
22611 | 117 :group 'flyspell |
118 :type '(repeat (symbol))) | |
119 | |
120 (defcustom flyspell-issue-welcome-flag t | |
22891
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
121 "*Non-nil means that Flyspell should display a welcome message when started." |
22611 | 122 :group 'flyspell |
123 :type 'boolean) | |
124 | |
125 (defcustom flyspell-consider-dash-as-word-delimiter-flag nil | |
126 "*Non-nil means that the `-' char is considered as a word delimiter." | |
127 :group 'flyspell | |
128 :type 'boolean) | |
129 | |
130 (defcustom flyspell-incorrect-hook nil | |
22844
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
131 "*List of functions to be called when incorrect words are encountered. |
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
132 Each function is given two arguments: the beginning and the end |
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
133 of the incorrect region." |
22611 | 134 :group 'flyspell) |
135 | |
23179
72461ea3cfc8
(flyspell-mode): Do nothing if mode
Karl Heuer <kwzh@gnu.org>
parents:
22963
diff
changeset
|
136 (defcustom flyspell-multi-language-p nil |
22844
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
137 "*Non-nil means that Flyspell can be used with multiple languages. |
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
138 This mode works by starting a separate Ispell process for each buffer, |
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
139 so that each buffer can use its own language." |
22611 | 140 :group 'flyspell |
141 :type 'boolean) | |
142 | |
143 ;*---------------------------------------------------------------------*/ | |
144 ;* Mode specific options */ | |
145 ;* ------------------------------------------------------------- */ | |
146 ;* Mode specific options enable users to disable flyspell on */ | |
147 ;* certain word depending of the emacs mode. For instance, when */ | |
148 ;* using flyspell with mail-mode add the following expression */ | |
149 ;* in your .emacs file: */ | |
150 ;* (add-hook 'mail-mode */ | |
151 ;* '(lambda () (setq flyspell-generic-check-word-p */ | |
152 ;* 'mail-mode-flyspell-verify))) */ | |
153 ;*---------------------------------------------------------------------*/ | |
154 (defvar flyspell-generic-check-word-p nil | |
155 "Function providing per-mode customization over which words are flyspelled. | |
22844
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
156 Returns t to continue checking, nil otherwise. |
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
157 Flyspell mode sets this variable to whatever is the `flyspell-mode-predicate' |
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
158 property of the major mode name.") |
22611 | 159 (make-variable-buffer-local 'flyspell-generic-check-word-p) |
160 | |
22844
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
161 (put 'mail-mode 'flyspell-mode-predicate 'mail-mode-flyspell-verify) |
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
162 (put 'message-mode 'flyspell-mode-predicate 'mail-mode-flyspell-verify) |
22611 | 163 (defun mail-mode-flyspell-verify () |
22844
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
164 "This function is used for `flyspell-generic-check-word-p' in Mail mode." |
22611 | 165 (save-excursion |
22612
6def3da74c7c
Delete defcustom definition.
Richard M. Stallman <rms@gnu.org>
parents:
22611
diff
changeset
|
166 (or (progn |
6def3da74c7c
Delete defcustom definition.
Richard M. Stallman <rms@gnu.org>
parents:
22611
diff
changeset
|
167 (beginning-of-line) |
6def3da74c7c
Delete defcustom definition.
Richard M. Stallman <rms@gnu.org>
parents:
22611
diff
changeset
|
168 (looking-at "Subject:")) |
6def3da74c7c
Delete defcustom definition.
Richard M. Stallman <rms@gnu.org>
parents:
22611
diff
changeset
|
169 (not (or (re-search-forward mail-header-separator nil t) |
6def3da74c7c
Delete defcustom definition.
Richard M. Stallman <rms@gnu.org>
parents:
22611
diff
changeset
|
170 (re-search-backward message-signature-separator nil t) |
6def3da74c7c
Delete defcustom definition.
Richard M. Stallman <rms@gnu.org>
parents:
22611
diff
changeset
|
171 (progn |
6def3da74c7c
Delete defcustom definition.
Richard M. Stallman <rms@gnu.org>
parents:
22611
diff
changeset
|
172 (beginning-of-line) |
6def3da74c7c
Delete defcustom definition.
Richard M. Stallman <rms@gnu.org>
parents:
22611
diff
changeset
|
173 (looking-at "[>}|]"))))))) |
22611 | 174 |
22844
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
175 (put 'texinfo-mode 'flyspell-mode-predicate 'texinfo-mode-flyspell-verify) |
22611 | 176 (defun texinfo-mode-flyspell-verify () |
22844
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
177 "This function is used for `flyspell-generic-check-word-p' in Texinfo mode." |
22611 | 178 (save-excursion |
179 (forward-word -1) | |
180 (not (looking-at "@")))) | |
181 | |
182 ;*---------------------------------------------------------------------*/ | |
183 ;* Overlay compatibility */ | |
184 ;*---------------------------------------------------------------------*/ | |
185 (autoload 'make-overlay "overlay" "" t) | |
186 (autoload 'move-overlay "overlay" "" t) | |
187 (autoload 'overlayp "overlay" "" t) | |
188 (autoload 'overlay-properties "overlay" "" t) | |
189 (autoload 'overlays-in "overlay" "" t) | |
190 (autoload 'delete-overlay "overlay" "" t) | |
191 (autoload 'overlays-at "overlay" "" t) | |
192 (autoload 'overlay-put "overlay" "" t) | |
193 (autoload 'overlay-get "overlay" "" t) | |
194 | |
195 ;*---------------------------------------------------------------------*/ | |
196 ;* Which emacs are we currently running */ | |
197 ;*---------------------------------------------------------------------*/ | |
198 (defvar flyspell-emacs | |
199 (cond | |
200 ((string-match "XEmacs" emacs-version) | |
201 'xemacs) | |
202 (t | |
203 'emacs)) | |
22891
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
204 "The type of Emacs we are currently running.") |
22611 | 205 |
206 ;*---------------------------------------------------------------------*/ | |
207 ;* The minor mode declaration. */ | |
208 ;*---------------------------------------------------------------------*/ | |
209 (defvar flyspell-mode nil) | |
210 (make-variable-buffer-local 'flyspell-mode) | |
211 | |
212 (defvar flyspell-mode-map (make-sparse-keymap)) | |
213 (defvar flyspell-mouse-map (make-sparse-keymap)) | |
214 | |
215 (or (assoc 'flyspell-mode minor-mode-alist) | |
22844
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
216 (setq minor-mode-alist |
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
217 (cons '(flyspell-mode " Fly") minor-mode-alist))) |
22611 | 218 |
219 (or (assoc 'flyspell-mode minor-mode-map-alist) | |
22844
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
220 (setq minor-mode-map-alist |
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
221 (cons (cons 'flyspell-mode flyspell-mode-map) |
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
222 minor-mode-map-alist))) |
22611 | 223 |
22891
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
224 (define-key flyspell-mode-map "\M-\t" 'flyspell-auto-correct-word) |
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
225 |
22611 | 226 ;; mouse bindings |
22612
6def3da74c7c
Delete defcustom definition.
Richard M. Stallman <rms@gnu.org>
parents:
22611
diff
changeset
|
227 (cond |
6def3da74c7c
Delete defcustom definition.
Richard M. Stallman <rms@gnu.org>
parents:
22611
diff
changeset
|
228 ((eq flyspell-emacs 'xemacs) |
6def3da74c7c
Delete defcustom definition.
Richard M. Stallman <rms@gnu.org>
parents:
22611
diff
changeset
|
229 (define-key flyspell-mouse-map [(button2)] |
6def3da74c7c
Delete defcustom definition.
Richard M. Stallman <rms@gnu.org>
parents:
22611
diff
changeset
|
230 (function flyspell-correct-word/mouse-keymap))) |
6def3da74c7c
Delete defcustom definition.
Richard M. Stallman <rms@gnu.org>
parents:
22611
diff
changeset
|
231 (t |
22611 | 232 (define-key flyspell-mode-map [(mouse-2)] |
22612
6def3da74c7c
Delete defcustom definition.
Richard M. Stallman <rms@gnu.org>
parents:
22611
diff
changeset
|
233 (function flyspell-correct-word/local-keymap)))) |
22611 | 234 |
235 ;; the name of the overlay property that defines the keymap | |
236 (defvar flyspell-overlay-keymap-property-name | |
237 (if (string-match "19.*XEmacs" emacs-version) | |
238 'keymap | |
239 'local-map)) | |
22891
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
240 |
22611 | 241 ;*---------------------------------------------------------------------*/ |
242 ;* Highlighting */ | |
243 ;*---------------------------------------------------------------------*/ | |
22844
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
244 (defface flyspell-incorrect-face |
22891
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
245 '((((class color)) (:foreground "OrangeRed" :bold t :underline t)) |
22844
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
246 (t (:bold t))) |
22962
f4509374e88e
(flyspell-command-hook): Option deleted.
Richard M. Stallman <rms@gnu.org>
parents:
22946
diff
changeset
|
247 "Face used for marking a misspelled word in Flyspell." |
22844
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
248 :group 'flyspell) |
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
249 |
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
250 (defface flyspell-duplicate-face |
22891
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
251 '((((class color)) (:foreground "Gold3" :bold t :underline t)) |
22844
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
252 (t (:bold t))) |
22962
f4509374e88e
(flyspell-command-hook): Option deleted.
Richard M. Stallman <rms@gnu.org>
parents:
22946
diff
changeset
|
253 "Face used for marking a misspelled word that appears twice in the buffer. |
f4509374e88e
(flyspell-command-hook): Option deleted.
Richard M. Stallman <rms@gnu.org>
parents:
22946
diff
changeset
|
254 See also `flyspell-duplicate-distance'." |
22844
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
255 :group 'flyspell) |
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
256 |
22611 | 257 (defvar flyspell-overlay nil) |
258 | |
259 ;*---------------------------------------------------------------------*/ | |
260 ;* flyspell-mode ... */ | |
261 ;*---------------------------------------------------------------------*/ | |
262 ;;;###autoload | |
263 (defun flyspell-mode (&optional arg) | |
264 "Minor mode performing on-the-fly spelling checking. | |
265 Ispell is automatically spawned on background for each entered words. | |
22844
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
266 The default flyspell behavior is to highlight incorrect words. |
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
267 With no argument, this command toggles Flyspell mode. |
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
268 With a prefix argument ARG, turn Flyspell minor mode on iff ARG is positive. |
22611 | 269 |
270 Bindings: | |
271 \\[ispell-word]: correct words (using Ispell). | |
272 \\[flyspell-auto-correct-word]: automatically correct word. | |
273 \\[flyspell-correct-word] (or mouse-2): popup correct words. | |
274 | |
275 Hooks: | |
23234 | 276 flyspell-mode-hook is run after flyspell is entered. |
22611 | 277 |
278 Remark: | |
279 `flyspell-mode' uses `ispell-mode'. Thus all Ispell options are | |
280 valid. For instance, a personal dictionary can be used by | |
281 invoking `ispell-change-dictionary'. | |
282 | |
283 Consider using the `ispell-parser' to check your text. For instance | |
284 consider adding: | |
22844
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
285 \(add-hook 'tex-mode-hook (function (lambda () (setq ispell-parser 'tex)))) |
22611 | 286 in your .emacs file. |
287 | |
288 flyspell-region checks all words inside a region. | |
289 | |
290 flyspell-buffer checks the whole buffer." | |
291 (interactive "P") | |
23179
72461ea3cfc8
(flyspell-mode): Do nothing if mode
Karl Heuer <kwzh@gnu.org>
parents:
22963
diff
changeset
|
292 (let ((old-flyspell-mode flyspell-mode)) |
72461ea3cfc8
(flyspell-mode): Do nothing if mode
Karl Heuer <kwzh@gnu.org>
parents:
22963
diff
changeset
|
293 ;; Mark the mode as on or off. |
72461ea3cfc8
(flyspell-mode): Do nothing if mode
Karl Heuer <kwzh@gnu.org>
parents:
22963
diff
changeset
|
294 (setq flyspell-mode (not (or (and (null arg) flyspell-mode) |
72461ea3cfc8
(flyspell-mode): Do nothing if mode
Karl Heuer <kwzh@gnu.org>
parents:
22963
diff
changeset
|
295 (<= (prefix-numeric-value arg) 0)))) |
72461ea3cfc8
(flyspell-mode): Do nothing if mode
Karl Heuer <kwzh@gnu.org>
parents:
22963
diff
changeset
|
296 ;; Do the real work. |
72461ea3cfc8
(flyspell-mode): Do nothing if mode
Karl Heuer <kwzh@gnu.org>
parents:
22963
diff
changeset
|
297 (unless (eq flyspell-mode old-flyspell-mode) |
72461ea3cfc8
(flyspell-mode): Do nothing if mode
Karl Heuer <kwzh@gnu.org>
parents:
22963
diff
changeset
|
298 (if flyspell-mode |
72461ea3cfc8
(flyspell-mode): Do nothing if mode
Karl Heuer <kwzh@gnu.org>
parents:
22963
diff
changeset
|
299 (flyspell-mode-on) |
72461ea3cfc8
(flyspell-mode): Do nothing if mode
Karl Heuer <kwzh@gnu.org>
parents:
22963
diff
changeset
|
300 (flyspell-mode-off)) |
72461ea3cfc8
(flyspell-mode): Do nothing if mode
Karl Heuer <kwzh@gnu.org>
parents:
22963
diff
changeset
|
301 ;; Force modeline redisplay. |
72461ea3cfc8
(flyspell-mode): Do nothing if mode
Karl Heuer <kwzh@gnu.org>
parents:
22963
diff
changeset
|
302 (set-buffer-modified-p (buffer-modified-p))))) |
22611 | 303 |
304 ;*---------------------------------------------------------------------*/ | |
305 ;* flyspell-mode-on ... */ | |
306 ;*---------------------------------------------------------------------*/ | |
307 (defun flyspell-mode-on () | |
23234 | 308 "Turn Flyspell mode on. Do not use this; use `flyspell-mode' instead." |
22611 | 309 (setq ispell-highlight-face 'flyspell-incorrect-face) |
310 ;; ispell initialization | |
311 (if flyspell-multi-language-p | |
312 (progn | |
313 (make-variable-buffer-local 'ispell-dictionary) | |
314 (make-variable-buffer-local 'ispell-process) | |
315 (make-variable-buffer-local 'ispell-filter) | |
316 (make-variable-buffer-local 'ispell-filter-continue) | |
317 (make-variable-buffer-local 'ispell-process-directory) | |
23234 | 318 (make-variable-buffer-local 'ispell-parser) |
319 (put 'ispell-dictionary 'permanent-local t) | |
320 (put 'ispell-process 'permanent-local t) | |
321 (put 'ispell-filter 'permanent-local t) | |
322 (put 'ispell-filter-continue 'permanent-local t) | |
323 (put 'ispell-process-directory 'permanent-local t) | |
324 (put 'ispell-parser 'permanent-local t))) | |
22891
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
325 ;; We put the `flyspel-delayed' property on some commands. |
22611 | 326 (flyspell-delay-commands) |
327 ;; we bound flyspell action to post-command hook | |
22962
f4509374e88e
(flyspell-command-hook): Option deleted.
Richard M. Stallman <rms@gnu.org>
parents:
22946
diff
changeset
|
328 (make-local-hook 'post-command-hook) |
f4509374e88e
(flyspell-command-hook): Option deleted.
Richard M. Stallman <rms@gnu.org>
parents:
22946
diff
changeset
|
329 (add-hook 'post-command-hook (function flyspell-post-command-hook) t t) |
22611 | 330 ;; we bound flyspell action to pre-command hook |
22962
f4509374e88e
(flyspell-command-hook): Option deleted.
Richard M. Stallman <rms@gnu.org>
parents:
22946
diff
changeset
|
331 (make-local-hook 'pre-command-hook) |
f4509374e88e
(flyspell-command-hook): Option deleted.
Richard M. Stallman <rms@gnu.org>
parents:
22946
diff
changeset
|
332 (add-hook 'pre-command-hook (function flyspell-pre-command-hook) t t) |
22891
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
333 |
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
334 ;; Set flyspell-generic-check-word-p based on the major mode. |
22844
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
335 (let ((mode-predicate (get major-mode 'flyspell-mode-predicate))) |
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
336 (if mode-predicate |
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
337 (setq flyspell-generic-check-word-p mode-predicate))) |
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
338 |
22611 | 339 ;; the welcome message |
340 (if flyspell-issue-welcome-flag | |
22891
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
341 (let ((binding (where-is-internal 'flyspell-auto-correct-word |
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
342 nil 'non-ascii))) |
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
343 (message |
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
344 (if binding |
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
345 (format "Welcome to flyspell. Use %s or Mouse-2 to correct words." |
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
346 (key-description binding)) |
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
347 "Welcome to flyspell. Use Mouse-2 to correct words.")))) |
22611 | 348 ;; we have to kill the flyspell process when the buffer is deleted. |
349 ;; (thanks to Jeff Miller and Roland Rosenfeld who sent me this | |
350 ;; improvement). | |
351 (add-hook 'kill-buffer-hook | |
352 '(lambda () | |
23233
b31869394e03
(flyspell-mode-on): fix kill-buffer-hook
Karl Heuer <kwzh@gnu.org>
parents:
23179
diff
changeset
|
353 (if (and flyspell-multi-language-p ispell-process) |
b31869394e03
(flyspell-mode-on): fix kill-buffer-hook
Karl Heuer <kwzh@gnu.org>
parents:
23179
diff
changeset
|
354 (ispell-kill-ispell t)))) |
22611 | 355 ;; we end with the flyspell hooks |
356 (run-hooks 'flyspell-mode-hook)) | |
357 | |
358 ;*---------------------------------------------------------------------*/ | |
359 ;* flyspell-delay-commands ... */ | |
360 ;*---------------------------------------------------------------------*/ | |
361 (defun flyspell-delay-commands () | |
23234 | 362 "Install the standard set of Flyspell delayed commands." |
22611 | 363 (mapcar 'flyspell-delay-command flyspell-default-delayed-commands) |
364 (mapcar 'flyspell-delay-command flyspell-delayed-commands)) | |
365 | |
366 ;*---------------------------------------------------------------------*/ | |
367 ;* flyspell-delay-command ... */ | |
368 ;*---------------------------------------------------------------------*/ | |
369 (defun flyspell-delay-command (command) | |
23234 | 370 "Set COMMAND to be delayed, for Flyspell. |
22611 | 371 When flyspell `post-command-hook' is invoked because a delayed command |
372 as been used the current word is not immediatly checked. | |
22844
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
373 It will be checked only after `flyspell-delay' seconds." |
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
374 (interactive "SDelay Flyspell after Command: ") |
22611 | 375 (put command 'flyspell-delayed t)) |
376 | |
377 ;*---------------------------------------------------------------------*/ | |
378 ;* flyspell-ignore-commands ... */ | |
379 ;*---------------------------------------------------------------------*/ | |
380 (defun flyspell-ignore-commands () | |
22844
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
381 "This is an obsolete function, use `flyspell-delay-commands' instead." |
22611 | 382 (flyspell-delay-commands)) |
383 | |
384 ;*---------------------------------------------------------------------*/ | |
385 ;* flyspell-ignore-command ... */ | |
386 ;*---------------------------------------------------------------------*/ | |
387 (defun flyspell-ignore-command (command) | |
22844
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
388 "This is an obsolete function, use `flyspell-delay-command' instead. |
22611 | 389 COMMAND is the name of the command to be delayed." |
390 (flyspell-delay-command command)) | |
391 | |
392 (make-obsolete 'flyspell-ignore-commands 'flyspell-delay-commands) | |
393 (make-obsolete 'flyspell-ignore-command 'flyspell-delay-command) | |
394 | |
395 ;*---------------------------------------------------------------------*/ | |
396 ;* flyspell-word-cache ... */ | |
397 ;*---------------------------------------------------------------------*/ | |
398 (defvar flyspell-word-cache-start nil) | |
399 (defvar flyspell-word-cache-end nil) | |
400 (defvar flyspell-word-cache-word nil) | |
401 (make-variable-buffer-local 'flyspell-word-cache-start) | |
402 (make-variable-buffer-local 'flyspell-word-cache-end) | |
403 (make-variable-buffer-local 'flyspell-word-cache-word) | |
404 | |
405 ;*---------------------------------------------------------------------*/ | |
406 ;* The flyspell pre-hook, store the current position. In the */ | |
407 ;* post command hook, we will check, if the word at this position */ | |
408 ;* has to be spell checked. */ | |
409 ;*---------------------------------------------------------------------*/ | |
410 (defvar flyspell-pre-buffer nil) | |
411 (defvar flyspell-pre-point nil) | |
412 | |
413 ;*---------------------------------------------------------------------*/ | |
414 ;* flyspell-pre-command-hook ... */ | |
415 ;*---------------------------------------------------------------------*/ | |
416 (defun flyspell-pre-command-hook () | |
22844
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
417 "Save the current buffer and point for Flyspell's post-command hook." |
22611 | 418 (interactive) |
419 (setq flyspell-pre-buffer (current-buffer)) | |
420 (setq flyspell-pre-point (point))) | |
421 | |
422 ;*---------------------------------------------------------------------*/ | |
423 ;* flyspell-mode-off ... */ | |
424 ;*---------------------------------------------------------------------*/ | |
23234 | 425 ;;;###autoload |
22611 | 426 (defun flyspell-mode-off () |
23234 | 427 "Turn Flyspell mode off." |
22891
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
428 ;; If we have an Ispell process for each buffer, |
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
429 ;; kill the one for this buffer. |
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
430 (if flyspell-multi-language-p |
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
431 (ispell-kill-ispell t)) |
22611 | 432 ;; we remove the hooks |
22962
f4509374e88e
(flyspell-command-hook): Option deleted.
Richard M. Stallman <rms@gnu.org>
parents:
22946
diff
changeset
|
433 (remove-hook 'post-command-hook (function flyspell-post-command-hook) t) |
f4509374e88e
(flyspell-command-hook): Option deleted.
Richard M. Stallman <rms@gnu.org>
parents:
22946
diff
changeset
|
434 (remove-hook 'pre-command-hook (function flyspell-pre-command-hook) t) |
22611 | 435 ;; we remove all the flyspell hilightings |
436 (flyspell-delete-all-overlays) | |
437 ;; we have to erase pre cache variables | |
438 (setq flyspell-pre-buffer nil) | |
439 (setq flyspell-pre-point nil) | |
440 ;; we mark the mode as killed | |
441 (setq flyspell-mode nil)) | |
442 | |
443 ;*---------------------------------------------------------------------*/ | |
444 ;* flyspell-check-word-p ... */ | |
445 ;*---------------------------------------------------------------------*/ | |
446 (defun flyspell-check-word-p () | |
22844
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
447 "Return t when the word at `point' has to be checked. |
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
448 The answer depends of several criteria. |
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
449 Mostly we check word delimiters." |
22611 | 450 (cond |
451 ((<= (- (point-max) 1) (point-min)) | |
452 ;; the buffer is not filled enough | |
453 nil) | |
454 ((not (and (symbolp this-command) (get this-command 'flyspell-delayed))) | |
455 ;; the current command is not delayed, that | |
456 ;; is that we must check the word now | |
457 t) | |
458 ((and (> (point) (point-min)) | |
459 (save-excursion | |
460 (backward-char 1) | |
461 (and (looking-at (flyspell-get-not-casechars)) | |
462 (or flyspell-consider-dash-as-word-delimiter-flag | |
463 (not (looking-at "\\-")))))) | |
22962
f4509374e88e
(flyspell-command-hook): Option deleted.
Richard M. Stallman <rms@gnu.org>
parents:
22946
diff
changeset
|
464 ;; yes because we have reached or typed a word delimiter. |
22611 | 465 t) |
466 ((not (integerp flyspell-delay)) | |
22962
f4509374e88e
(flyspell-command-hook): Option deleted.
Richard M. Stallman <rms@gnu.org>
parents:
22946
diff
changeset
|
467 ;; yes because the user had set up a no-delay configuration. |
22611 | 468 t) |
469 (t | |
470 (if (fboundp 'about-xemacs) | |
471 (sit-for flyspell-delay nil) | |
472 (sit-for flyspell-delay 0 nil))))) | |
473 | |
474 ;*---------------------------------------------------------------------*/ | |
475 ;* flyspell-check-pre-word-p ... */ | |
476 ;*---------------------------------------------------------------------*/ | |
477 (defun flyspell-check-pre-word-p () | |
22844
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
478 "Return non-nil if we should to check the word before point. |
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
479 More precisely, it applies to the word that was before point |
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
480 before the current command." |
22611 | 481 (cond |
482 ((or (not (numberp flyspell-pre-point)) | |
483 (not (bufferp flyspell-pre-buffer)) | |
484 (not (buffer-live-p flyspell-pre-buffer))) | |
485 nil) | |
22891
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
486 ((or (and (= flyspell-pre-point (- (point) 1)) |
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
487 (eq (char-syntax (char-after flyspell-pre-point)) ?w)) |
22611 | 488 (= flyspell-pre-point (point)) |
489 (= flyspell-pre-point (+ (point) 1))) | |
490 nil) | |
491 ((not (eq (current-buffer) flyspell-pre-buffer)) | |
492 t) | |
493 ((not (and (numberp flyspell-word-cache-start) | |
494 (numberp flyspell-word-cache-end))) | |
495 t) | |
496 (t | |
497 (or (< flyspell-pre-point flyspell-word-cache-start) | |
498 (> flyspell-pre-point flyspell-word-cache-end))))) | |
499 | |
500 ;*---------------------------------------------------------------------*/ | |
501 ;* flyspell-post-command-hook ... */ | |
502 ;*---------------------------------------------------------------------*/ | |
503 (defun flyspell-post-command-hook () | |
504 "The `post-command-hook' used by flyspell to check a word in-the-fly." | |
505 (interactive) | |
506 (if (flyspell-check-word-p) | |
507 (flyspell-word)) | |
508 (if (flyspell-check-pre-word-p) | |
509 (save-excursion | |
510 (set-buffer flyspell-pre-buffer) | |
511 (save-excursion | |
512 (goto-char flyspell-pre-point) | |
513 (flyspell-word))))) | |
514 | |
515 ;*---------------------------------------------------------------------*/ | |
516 ;* flyspell-word ... */ | |
517 ;*---------------------------------------------------------------------*/ | |
518 (defun flyspell-word (&optional following) | |
519 "Spell check a word." | |
520 (interactive (list current-prefix-arg)) | |
521 (if (interactive-p) | |
522 (setq following ispell-following-word)) | |
523 (save-excursion | |
524 (ispell-accept-buffer-local-defs) ; use the correct dictionary | |
525 (let ((cursor-location (point)) ; retain cursor location | |
526 (word (flyspell-get-word following)) | |
527 start end poss) | |
528 (if (or (eq word nil) | |
529 (and (fboundp flyspell-generic-check-word-p) | |
530 (not (funcall flyspell-generic-check-word-p)))) | |
531 t | |
532 (progn | |
533 ;; destructure return word info list. | |
534 (setq start (car (cdr word)) | |
535 end (car (cdr (cdr word))) | |
536 word (car word)) | |
537 ;; before checking in the directory, we check for doublons. | |
538 (cond | |
22844
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
539 ((and flyspell-mark-duplications-flag |
22611 | 540 (save-excursion |
541 (goto-char start) | |
542 (word-search-backward word | |
543 (- start | |
544 (+ 1 (- end start))) | |
545 t))) | |
546 ;; yes, this is a doublon | |
547 (flyspell-highlight-incorrect-region start end)) | |
548 ((and (eq flyspell-word-cache-start start) | |
549 (eq flyspell-word-cache-end end) | |
550 (string-equal flyspell-word-cache-word word)) | |
551 ;; this word had been already checked, we skip | |
552 nil) | |
553 ((and (eq ispell-parser 'tex) | |
554 (flyspell-tex-command-p word)) | |
555 ;; this is a correct word (because a tex command) | |
556 (flyspell-unhighlight-at start) | |
557 (if (> end start) | |
558 (flyspell-unhighlight-at (- end 1))) | |
559 t) | |
560 (t | |
561 ;; we setup the cache | |
562 (setq flyspell-word-cache-start start) | |
563 (setq flyspell-word-cache-end end) | |
564 (setq flyspell-word-cache-word word) | |
565 ;; now check spelling of word. | |
566 (process-send-string ispell-process "%\n") | |
567 ;; put in verbose mode | |
568 (process-send-string ispell-process | |
569 (concat "^" word "\n")) | |
22891
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
570 ;; we mark the ispell process so it can be killed |
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
571 ;; when emacs is exited without query |
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
572 (if (fboundp 'process-kill-without-query) |
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
573 (process-kill-without-query ispell-process)) |
22611 | 574 ;; wait until ispell has processed word |
575 (while (progn | |
576 (accept-process-output ispell-process) | |
577 (not (string= "" (car ispell-filter))))) | |
578 ;; (process-send-string ispell-process "!\n") | |
579 ;; back to terse mode. | |
580 (setq ispell-filter (cdr ispell-filter)) | |
581 (if (listp ispell-filter) | |
582 (setq poss (ispell-parse-output (car ispell-filter)))) | |
583 (cond ((eq poss t) | |
584 ;; correct | |
585 (flyspell-unhighlight-at start) | |
586 (if (> end start) | |
587 (flyspell-unhighlight-at (- end 1))) | |
588 t) | |
589 ((and (stringp poss) flyspell-highlight-flag) | |
590 ;; correct | |
591 (flyspell-unhighlight-at start) | |
592 (if (> end start) | |
593 (flyspell-unhighlight-at (- end 1))) | |
594 t) | |
595 ((null poss) | |
596 (flyspell-unhighlight-at start) | |
597 (if (> end start) | |
598 (flyspell-unhighlight-at (- end 1))) | |
599 (message "Error in ispell process")) | |
600 ((or (and (< flyspell-duplicate-distance 0) | |
601 (or (save-excursion | |
602 (goto-char start) | |
603 (word-search-backward word | |
604 (point-min) | |
605 t)) | |
606 (save-excursion | |
607 (goto-char end) | |
608 (word-search-forward word | |
609 (point-max) | |
610 t)))) | |
611 (and (> flyspell-duplicate-distance 0) | |
612 (or (save-excursion | |
613 (goto-char start) | |
614 (word-search-backward | |
615 word | |
616 (- start | |
617 flyspell-duplicate-distance) | |
618 t)) | |
619 (save-excursion | |
620 (goto-char end) | |
621 (word-search-forward | |
622 word | |
623 (+ end | |
624 flyspell-duplicate-distance) | |
625 t))))) | |
626 (if flyspell-highlight-flag | |
627 (flyspell-highlight-duplicate-region start end) | |
22891
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
628 (message (format "duplicate `%s'" word)))) |
22611 | 629 (t |
630 ;; incorrect highlight the location | |
631 (if flyspell-highlight-flag | |
632 (flyspell-highlight-incorrect-region start end) | |
633 (message (format "mispelling `%s'" word))))) | |
634 (goto-char cursor-location) ; return to original location | |
635 (if ispell-quit (setq ispell-quit nil))))))))) | |
636 | |
637 ;*---------------------------------------------------------------------*/ | |
638 ;* flyspell-tex-command-p ... */ | |
639 ;*---------------------------------------------------------------------*/ | |
640 (defun flyspell-tex-command-p (word) | |
22844
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
641 "Return t if WORD is a TeX command." |
22611 | 642 (eq (aref word 0) ?\\)) |
643 | |
644 ;*---------------------------------------------------------------------*/ | |
645 ;* flyspell-casechars-cache ... */ | |
646 ;*---------------------------------------------------------------------*/ | |
647 (defvar flyspell-casechars-cache nil) | |
648 (defvar flyspell-ispell-casechars-cache nil) | |
649 (make-variable-buffer-local 'flyspell-casechars-cache) | |
650 (make-variable-buffer-local 'flyspell-ispell-casechars-cache) | |
651 | |
652 ;*---------------------------------------------------------------------*/ | |
653 ;* flyspell-get-casechars ... */ | |
654 ;*---------------------------------------------------------------------*/ | |
655 (defun flyspell-get-casechars () | |
656 "This function builds a string that is the regexp of word chars. | |
22844
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
657 In order to avoid one useless string construction, |
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
658 this function changes the last char of the `ispell-casechars' string." |
22611 | 659 (let ((ispell-casechars (ispell-get-casechars))) |
660 (cond | |
661 ((eq ispell-casechars flyspell-ispell-casechars-cache) | |
662 flyspell-casechars-cache) | |
663 ((not (eq ispell-parser 'tex)) | |
664 (setq flyspell-ispell-casechars-cache ispell-casechars) | |
665 (setq flyspell-casechars-cache | |
666 (concat (substring ispell-casechars | |
667 0 | |
668 (- (length ispell-casechars) 1)) | |
669 "{}]")) | |
670 flyspell-casechars-cache) | |
671 (t | |
672 (setq flyspell-ispell-casechars-cache ispell-casechars) | |
673 (setq flyspell-casechars-cache ispell-casechars) | |
674 flyspell-casechars-cache)))) | |
675 | |
676 ;*---------------------------------------------------------------------*/ | |
677 ;* flyspell-get-not-casechars-cache ... */ | |
678 ;*---------------------------------------------------------------------*/ | |
679 (defvar flyspell-not-casechars-cache nil) | |
680 (defvar flyspell-ispell-not-casechars-cache nil) | |
681 (make-variable-buffer-local 'flyspell-not-casechars-cache) | |
682 (make-variable-buffer-local 'flyspell-ispell-not-casechars-cache) | |
683 | |
684 ;*---------------------------------------------------------------------*/ | |
685 ;* flyspell-get-not-casechars ... */ | |
686 ;*---------------------------------------------------------------------*/ | |
687 (defun flyspell-get-not-casechars () | |
688 "This function builds a string that is the regexp of non-word chars." | |
689 (let ((ispell-not-casechars (ispell-get-not-casechars))) | |
690 (cond | |
691 ((eq ispell-not-casechars flyspell-ispell-not-casechars-cache) | |
692 flyspell-not-casechars-cache) | |
693 ((not (eq ispell-parser 'tex)) | |
694 (setq flyspell-ispell-not-casechars-cache ispell-not-casechars) | |
695 (setq flyspell-not-casechars-cache | |
696 (concat (substring ispell-not-casechars | |
697 0 | |
698 (- (length ispell-not-casechars) 1)) | |
699 "{}]")) | |
700 flyspell-not-casechars-cache) | |
701 (t | |
702 (setq flyspell-ispell-not-casechars-cache ispell-not-casechars) | |
703 (setq flyspell-not-casechars-cache ispell-not-casechars) | |
704 flyspell-not-casechars-cache)))) | |
705 | |
706 ;*---------------------------------------------------------------------*/ | |
707 ;* flyspell-get-word ... */ | |
708 ;*---------------------------------------------------------------------*/ | |
709 (defun flyspell-get-word (following) | |
710 "Return the word for spell-checking according to Ispell syntax. | |
711 If optional argument FOLLOWING is non-nil or if `ispell-following-word' | |
712 is non-nil when called interactively, then the following word | |
713 \(rather than preceding\) is checked when the cursor is not over a word. | |
714 Optional second argument contains otherchars that can be included in word | |
715 many times. | |
716 | |
717 Word syntax described by `ispell-dictionary-alist' (which see)." | |
718 (let* ((flyspell-casechars (flyspell-get-casechars)) | |
719 (flyspell-not-casechars (flyspell-get-not-casechars)) | |
720 (ispell-otherchars (ispell-get-otherchars)) | |
721 (ispell-many-otherchars-p (ispell-get-many-otherchars-p)) | |
722 (word-regexp (concat flyspell-casechars | |
723 "+\\(" | |
724 ispell-otherchars | |
725 "?" | |
726 flyspell-casechars | |
727 "+\\)" | |
728 (if ispell-many-otherchars-p | |
729 "*" "?"))) | |
730 (tex-prelude "[\\\\{]") | |
731 (tex-regexp (if (eq ispell-parser 'tex) | |
732 (concat tex-prelude "?" word-regexp "}?") | |
733 word-regexp)) | |
734 | |
735 did-it-once | |
736 start end word) | |
737 ;; find the word | |
738 (if (not (or (looking-at flyspell-casechars) | |
739 (and (eq ispell-parser 'tex) | |
740 (looking-at tex-prelude)))) | |
741 (if following | |
742 (re-search-forward flyspell-casechars (point-max) t) | |
743 (re-search-backward flyspell-casechars (point-min) t))) | |
744 ;; move to front of word | |
745 (re-search-backward flyspell-not-casechars (point-min) 'start) | |
746 (let ((pos nil)) | |
747 (while (and (looking-at ispell-otherchars) | |
748 (not (bobp)) | |
749 (or (not did-it-once) | |
750 ispell-many-otherchars-p) | |
751 (not (eq pos (point)))) | |
752 (setq pos (point)) | |
753 (setq did-it-once t) | |
754 (backward-char 1) | |
755 (if (looking-at flyspell-casechars) | |
756 (re-search-backward flyspell-not-casechars (point-min) 'move) | |
757 (backward-char -1)))) | |
758 ;; Now mark the word and save to string. | |
759 (if (eq (re-search-forward tex-regexp (point-max) t) nil) | |
760 nil | |
761 (progn | |
762 (setq start (match-beginning 0) | |
763 end (point) | |
764 word (buffer-substring start end)) | |
765 (list word start end))))) | |
766 | |
767 ;*---------------------------------------------------------------------*/ | |
768 ;* flyspell-region ... */ | |
769 ;*---------------------------------------------------------------------*/ | |
770 (defun flyspell-region (beg end) | |
771 "Flyspell text between BEG and END." | |
772 (interactive "r") | |
773 (save-excursion | |
22891
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
774 (if (> beg end) |
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
775 (let ((old beg)) |
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
776 (setq beg end) |
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
777 (setq end old))) |
22611 | 778 (goto-char beg) |
22612
6def3da74c7c
Delete defcustom definition.
Richard M. Stallman <rms@gnu.org>
parents:
22611
diff
changeset
|
779 (let ((count 0)) |
6def3da74c7c
Delete defcustom definition.
Richard M. Stallman <rms@gnu.org>
parents:
22611
diff
changeset
|
780 (while (< (point) end) |
6def3da74c7c
Delete defcustom definition.
Richard M. Stallman <rms@gnu.org>
parents:
22611
diff
changeset
|
781 (if (= count 100) |
6def3da74c7c
Delete defcustom definition.
Richard M. Stallman <rms@gnu.org>
parents:
22611
diff
changeset
|
782 (progn |
6def3da74c7c
Delete defcustom definition.
Richard M. Stallman <rms@gnu.org>
parents:
22611
diff
changeset
|
783 (message "Spell Checking...%d%%" |
22891
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
784 (* 100 (/ (float (- (point) beg)) (- end beg)))) |
22612
6def3da74c7c
Delete defcustom definition.
Richard M. Stallman <rms@gnu.org>
parents:
22611
diff
changeset
|
785 (setq count 0)) |
6def3da74c7c
Delete defcustom definition.
Richard M. Stallman <rms@gnu.org>
parents:
22611
diff
changeset
|
786 (setq count (+ 1 count))) |
6def3da74c7c
Delete defcustom definition.
Richard M. Stallman <rms@gnu.org>
parents:
22611
diff
changeset
|
787 (flyspell-word) |
6def3da74c7c
Delete defcustom definition.
Richard M. Stallman <rms@gnu.org>
parents:
22611
diff
changeset
|
788 (let ((cur (point))) |
6def3da74c7c
Delete defcustom definition.
Richard M. Stallman <rms@gnu.org>
parents:
22611
diff
changeset
|
789 (forward-word 1) |
6def3da74c7c
Delete defcustom definition.
Richard M. Stallman <rms@gnu.org>
parents:
22611
diff
changeset
|
790 (if (and (< (point) end) (> (point) (+ cur 1))) |
6def3da74c7c
Delete defcustom definition.
Richard M. Stallman <rms@gnu.org>
parents:
22611
diff
changeset
|
791 (backward-char 1))))) |
22611 | 792 (backward-char 1) |
793 (message "Spell Checking...done") | |
794 (flyspell-word))) | |
795 | |
796 ;*---------------------------------------------------------------------*/ | |
797 ;* flyspell-buffer ... */ | |
798 ;*---------------------------------------------------------------------*/ | |
799 (defun flyspell-buffer () | |
800 "Flyspell whole buffer." | |
801 (interactive) | |
802 (flyspell-region (point-min) (point-max))) | |
803 | |
804 ;*---------------------------------------------------------------------*/ | |
805 ;* flyspell-overlay-p ... */ | |
806 ;*---------------------------------------------------------------------*/ | |
807 (defun flyspell-overlay-p (o) | |
808 "A predicate that return true iff O is an overlay used by flyspell." | |
809 (and (overlayp o) (overlay-get o 'flyspell-overlay))) | |
810 | |
811 ;*---------------------------------------------------------------------*/ | |
812 ;* flyspell-delete-all-overlays ... */ | |
813 ;* ------------------------------------------------------------- */ | |
814 ;* Remove all the overlays introduced by flyspell. */ | |
815 ;*---------------------------------------------------------------------*/ | |
816 (defun flyspell-delete-all-overlays () | |
817 "Delete all the overlays used by flyspell." | |
818 (let ((l (overlays-in (point-min) (point-max)))) | |
819 (while (consp l) | |
820 (progn | |
821 (if (flyspell-overlay-p (car l)) | |
822 (delete-overlay (car l))) | |
823 (setq l (cdr l)))))) | |
824 | |
825 ;*---------------------------------------------------------------------*/ | |
826 ;* flyspell-unhighlight-at ... */ | |
827 ;*---------------------------------------------------------------------*/ | |
828 (defun flyspell-unhighlight-at (pos) | |
829 "Remove the flyspell overlay that are located at POS." | |
830 (if flyspell-persistent-highlight | |
831 (let ((overlays (overlays-at pos))) | |
832 (while (consp overlays) | |
833 (if (flyspell-overlay-p (car overlays)) | |
834 (delete-overlay (car overlays))) | |
835 (setq overlays (cdr overlays)))) | |
836 (delete-overlay flyspell-overlay))) | |
837 | |
838 ;*---------------------------------------------------------------------*/ | |
839 ;* flyspell-properties-at-p ... */ | |
840 ;* ------------------------------------------------------------- */ | |
841 ;* Is there an highlight properties at position pos? */ | |
842 ;*---------------------------------------------------------------------*/ | |
22891
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
843 (defun flyspell-properties-at-p (pos) |
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
844 "Return t if there is a text property at POS, not counting `local-map'. |
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
845 If variable `flyspell-highlight-properties' is set to nil, |
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
846 text with properties are not checked. This function is used to discover |
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
847 if the character at POS has any other property." |
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
848 (let ((prop (text-properties-at pos)) |
22611 | 849 (keep t)) |
850 (while (and keep (consp prop)) | |
851 (if (and (eq (car prop) 'local-map) (consp (cdr prop))) | |
852 (setq prop (cdr (cdr prop))) | |
853 (setq keep nil))) | |
854 (consp prop))) | |
855 | |
856 ;*---------------------------------------------------------------------*/ | |
857 ;* make-flyspell-overlay ... */ | |
858 ;*---------------------------------------------------------------------*/ | |
859 (defun make-flyspell-overlay (beg end face mouse-face) | |
22844
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
860 "Allocate an overlay to highlight an incorrect word. |
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
861 BEG and END specify the range in the buffer of that word. |
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
862 FACE and MOUSE-FACE specify the `face' and `mouse-face' properties |
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
863 for the overlay." |
22611 | 864 (let ((flyspell-overlay (make-overlay beg end))) |
865 (overlay-put flyspell-overlay 'face face) | |
866 (overlay-put flyspell-overlay 'mouse-face mouse-face) | |
867 (overlay-put flyspell-overlay 'flyspell-overlay t) | |
868 (if (eq flyspell-emacs 'xemacs) | |
869 (overlay-put flyspell-overlay | |
870 flyspell-overlay-keymap-property-name | |
871 flyspell-mouse-map)))) | |
872 | |
873 ;*---------------------------------------------------------------------*/ | |
874 ;* flyspell-highlight-incorrect-region ... */ | |
875 ;*---------------------------------------------------------------------*/ | |
876 (defun flyspell-highlight-incorrect-region (beg end) | |
22844
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
877 "Set up an overlay on a misspelled word, in the buffer from BEG to END." |
22611 | 878 (run-hook-with-args 'flyspell-incorrect-hook beg end) |
22891
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
879 (if (or flyspell-highlight-properties (not (flyspell-properties-at-p beg))) |
22611 | 880 (progn |
881 ;; we cleanup current overlay at the same position | |
882 (if (and (not flyspell-persistent-highlight) | |
883 (overlayp flyspell-overlay)) | |
884 (delete-overlay flyspell-overlay) | |
885 (let ((overlays (overlays-at beg))) | |
886 (while (consp overlays) | |
887 (if (flyspell-overlay-p (car overlays)) | |
888 (delete-overlay (car overlays))) | |
889 (setq overlays (cdr overlays))))) | |
890 ;; now we can use a new overlay | |
891 (setq flyspell-overlay | |
892 (make-flyspell-overlay beg end | |
893 'flyspell-incorrect-face 'highlight))))) | |
894 | |
895 ;*---------------------------------------------------------------------*/ | |
896 ;* flyspell-highlight-duplicate-region ... */ | |
897 ;*---------------------------------------------------------------------*/ | |
898 (defun flyspell-highlight-duplicate-region (beg end) | |
22844
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
899 "Set up an overlay on a duplicated word, in the buffer from BEG to END." |
22891
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
900 (if (or flyspell-highlight-properties (not (flyspell-properties-at-p beg))) |
22611 | 901 (progn |
902 ;; we cleanup current overlay at the same position | |
903 (if (and (not flyspell-persistent-highlight) | |
904 (overlayp flyspell-overlay)) | |
905 (delete-overlay flyspell-overlay) | |
906 (let ((overlays (overlays-at beg))) | |
907 (while (consp overlays) | |
908 (if (flyspell-overlay-p (car overlays)) | |
909 (delete-overlay (car overlays))) | |
910 (setq overlays (cdr overlays))))) | |
911 ;; now we can use a new overlay | |
912 (setq flyspell-overlay | |
913 (make-flyspell-overlay beg end | |
914 'flyspell-duplicate-face 'highlight))))) | |
915 | |
916 ;*---------------------------------------------------------------------*/ | |
917 ;* flyspell-auto-correct-cache ... */ | |
918 ;*---------------------------------------------------------------------*/ | |
919 (defvar flyspell-auto-correct-pos nil) | |
920 (defvar flyspell-auto-correct-region nil) | |
921 (defvar flyspell-auto-correct-ring nil) | |
922 | |
923 ;*---------------------------------------------------------------------*/ | |
924 ;* flyspell-auto-correct-word ... */ | |
925 ;*---------------------------------------------------------------------*/ | |
926 (defun flyspell-auto-correct-word (pos) | |
22891
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
927 "Correct the word at POS. |
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
928 This command proposes various successive corrections for the word at POS. |
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
929 The variable `flyspell-auto-correct-binding' specifies the key to bind |
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
930 to this command." |
22611 | 931 (interactive "d") |
932 ;; use the correct dictionary | |
933 (ispell-accept-buffer-local-defs) | |
934 (if (eq flyspell-auto-correct-pos pos) | |
935 ;; we have already been using the function at the same location | |
936 (progn | |
937 (save-excursion | |
938 (let ((start (car flyspell-auto-correct-region)) | |
939 (len (cdr flyspell-auto-correct-region))) | |
940 (delete-region start (+ start len)) | |
941 (setq flyspell-auto-correct-ring (cdr flyspell-auto-correct-ring)) | |
942 (let* ((word (car flyspell-auto-correct-ring)) | |
943 (len (length word))) | |
944 (rplacd flyspell-auto-correct-region len) | |
945 (goto-char start) | |
946 (insert word)))) | |
947 (setq flyspell-auto-correct-pos (point))) | |
948 ;; retain cursor location | |
949 (let ((cursor-location pos) | |
950 (word (flyspell-get-word nil)) | |
951 start end poss) | |
952 ;; destructure return word info list. | |
953 (setq start (car (cdr word)) | |
954 end (car (cdr (cdr word))) | |
955 word (car word)) | |
956 ;; now check spelling of word. | |
957 (process-send-string ispell-process "%\n") ;put in verbose mode | |
958 (process-send-string ispell-process (concat "^" word "\n")) | |
959 ;; wait until ispell has processed word | |
960 (while (progn | |
961 (accept-process-output ispell-process) | |
962 (not (string= "" (car ispell-filter))))) | |
963 (setq ispell-filter (cdr ispell-filter)) | |
964 (if (listp ispell-filter) | |
965 (setq poss (ispell-parse-output (car ispell-filter)))) | |
966 (cond ((or (eq poss t) (stringp poss)) | |
967 ;; don't correct word | |
968 t) | |
969 ((null poss) | |
970 ;; ispell error | |
971 (error "Ispell: error in Ispell process")) | |
972 (t | |
973 ;; the word is incorrect, we have to propose a replacement | |
974 (let ((replacements (if flyspell-sort-corrections | |
975 (sort (car (cdr (cdr poss))) 'string<) | |
976 (car (cdr (cdr poss)))))) | |
977 (if (consp replacements) | |
978 (progn | |
979 (let ((replace (car replacements))) | |
980 (setq word replace) | |
981 (setq cursor-location (+ (- (length word) (- end start)) | |
982 cursor-location)) | |
983 (if (not (equal word (car poss))) | |
984 (progn | |
985 ;; the save the current replacements | |
986 (setq flyspell-auto-correct-pos cursor-location) | |
987 (setq flyspell-auto-correct-region | |
988 (cons start (length word))) | |
989 (let ((l replacements)) | |
990 (while (consp (cdr l)) | |
991 (setq l (cdr l))) | |
992 (rplacd l (cons (car poss) replacements))) | |
993 (setq flyspell-auto-correct-ring | |
994 (cdr replacements)) | |
995 (delete-region start end) | |
996 (insert word))))))))) | |
997 ;; return to original location | |
998 (goto-char cursor-location) | |
999 (ispell-pdict-save t)))) | |
1000 | |
1001 ;*---------------------------------------------------------------------*/ | |
1002 ;* flyspell-correct-word ... */ | |
1003 ;*---------------------------------------------------------------------*/ | |
1004 (defun flyspell-correct-word (event) | |
1005 "Check spelling of word under or before the cursor. | |
1006 If the word is not found in dictionary, display possible corrections | |
1007 in a popup menu allowing you to choose one. | |
1008 | |
1009 Word syntax described by `ispell-dictionary-alist' (which see). | |
1010 | |
1011 This will check or reload the dictionary. Use \\[ispell-change-dictionary] | |
1012 or \\[ispell-region] to update the Ispell process." | |
1013 (interactive "e") | |
1014 (if (eq flyspell-emacs 'xemacs) | |
1015 (flyspell-correct-word/mouse-keymap event) | |
1016 (flyspell-correct-word/local-keymap event))) | |
1017 | |
1018 ;*---------------------------------------------------------------------*/ | |
1019 ;* flyspell-correct-word/local-keymap ... */ | |
1020 ;*---------------------------------------------------------------------*/ | |
1021 (defun flyspell-correct-word/local-keymap (event) | |
1022 "emacs 19.xx seems to be buggous. Overlay keymap does not seems | |
1023 to work correctly with local map. That is, if a key is not | |
1024 defined for the overlay keymap, the current local map, is not | |
1025 checked. The binding is resolved with the global map. The | |
1026 consequence is that we can not use overlay map with flyspell." | |
1027 (interactive "e") | |
1028 (save-window-excursion | |
1029 (let ((save (point))) | |
1030 (mouse-set-point event) | |
1031 ;; we look for a flyspell overlay here | |
1032 (let ((overlays (overlays-at (point))) | |
1033 (overlay nil)) | |
1034 (while (consp overlays) | |
1035 (if (flyspell-overlay-p (car overlays)) | |
1036 (progn | |
1037 (setq overlay (car overlays)) | |
1038 (setq overlays nil)) | |
1039 (setq overlays (cdr overlays)))) | |
1040 ;; we return to the correct location | |
1041 (goto-char save) | |
1042 ;; we check to see if button2 has been used overlay a | |
1043 ;; flyspell overlay | |
1044 (if overlay | |
1045 ;; yes, so we use the flyspell function | |
1046 (flyspell-correct-word/mouse-keymap event) | |
1047 ;; no so we have to use the non flyspell binding | |
1048 (let ((flyspell-mode nil)) | |
1049 (if (key-binding (this-command-keys)) | |
1050 (command-execute (key-binding (this-command-keys)))))))))) | |
1051 | |
1052 ;*---------------------------------------------------------------------*/ | |
1053 ;* flyspell-correct-word ... */ | |
1054 ;*---------------------------------------------------------------------*/ | |
1055 (defun flyspell-correct-word/mouse-keymap (event) | |
22844
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
1056 "Pop up a menu of possible corrections for a misspelled word. |
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
1057 The word checked is the word at the mouse position." |
22611 | 1058 (interactive "e") |
1059 ;; use the correct dictionary | |
1060 (ispell-accept-buffer-local-defs) | |
1061 ;; retain cursor location (I don't know why but save-excursion here fails). | |
1062 (let ((save (point))) | |
1063 (mouse-set-point event) | |
1064 (let ((cursor-location (point)) | |
1065 (word (flyspell-get-word nil)) | |
1066 start end poss replace) | |
1067 ;; destructure return word info list. | |
1068 (setq start (car (cdr word)) | |
1069 end (car (cdr (cdr word))) | |
1070 word (car word)) | |
1071 ;; now check spelling of word. | |
1072 (process-send-string ispell-process "%\n") ;put in verbose mode | |
1073 (process-send-string ispell-process (concat "^" word "\n")) | |
1074 ;; wait until ispell has processed word | |
1075 (while (progn | |
1076 (accept-process-output ispell-process) | |
1077 (not (string= "" (car ispell-filter))))) | |
1078 (setq ispell-filter (cdr ispell-filter)) | |
1079 (if (listp ispell-filter) | |
1080 (setq poss (ispell-parse-output (car ispell-filter)))) | |
1081 (cond ((or (eq poss t) (stringp poss)) | |
1082 ;; don't correct word | |
1083 t) | |
1084 ((null poss) | |
1085 ;; ispell error | |
1086 (error "Ispell: error in Ispell process")) | |
1087 ((string-match "GNU" (emacs-version)) | |
1088 ;; the word is incorrect, we have to propose a replacement | |
22844
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
1089 (setq replace (flyspell-emacs-popup event poss word)) |
22611 | 1090 (cond ((eq replace 'ignore) |
1091 nil) | |
1092 ((eq replace 'save) | |
1093 (process-send-string ispell-process (concat "*" word "\n")) | |
1094 (flyspell-unhighlight-at cursor-location) | |
1095 (setq ispell-pdict-modified-p '(t))) | |
1096 ((or (eq replace 'buffer) (eq replace 'session)) | |
1097 (process-send-string ispell-process (concat "@" word "\n")) | |
1098 (if (null ispell-pdict-modified-p) | |
1099 (setq ispell-pdict-modified-p | |
1100 (list ispell-pdict-modified-p))) | |
1101 (flyspell-unhighlight-at cursor-location) | |
1102 (if (eq replace 'buffer) | |
1103 (ispell-add-per-file-word-list word))) | |
1104 (replace | |
1105 (setq word (if (atom replace) replace (car replace)) | |
1106 cursor-location (+ (- (length word) (- end start)) | |
1107 cursor-location)) | |
1108 (if (not (equal word (car poss))) | |
1109 (progn | |
1110 (delete-region start end) | |
1111 (insert word)))))) | |
1112 ((string-match "XEmacs" (emacs-version)) | |
1113 (flyspell-xemacs-popup | |
1114 event poss word cursor-location start end))) | |
1115 (ispell-pdict-save t)) | |
1116 (if (< save (point-max)) | |
1117 (goto-char save) | |
1118 (goto-char (point-max))))) | |
1119 | |
1120 ;*---------------------------------------------------------------------*/ | |
1121 ;* flyspell-xemacs-correct ... */ | |
1122 ;*---------------------------------------------------------------------*/ | |
1123 (defun flyspell-xemacs-correct (replace poss word cursor-location start end) | |
1124 "The xemacs popup menu callback." | |
1125 (cond ((eq replace 'ignore) | |
1126 nil) | |
1127 ((eq replace 'save) | |
1128 (process-send-string ispell-process (concat "*" word "\n")) | |
1129 (flyspell-unhighlight-at cursor-location) | |
1130 (setq ispell-pdict-modified-p '(t))) | |
1131 ((or (eq replace 'buffer) (eq replace 'session)) | |
1132 (process-send-string ispell-process (concat "@" word "\n")) | |
1133 (flyspell-unhighlight-at cursor-location) | |
1134 (if (null ispell-pdict-modified-p) | |
1135 (setq ispell-pdict-modified-p | |
1136 (list ispell-pdict-modified-p))) | |
1137 (if (eq replace 'buffer) | |
1138 (ispell-add-per-file-word-list word))) | |
1139 (replace | |
1140 (setq word (if (atom replace) replace (car replace)) | |
1141 cursor-location (+ (- (length word) (- end start)) | |
1142 cursor-location)) | |
1143 (if (not (equal word (car poss))) | |
1144 (save-excursion | |
1145 (delete-region start end) | |
1146 (goto-char start) | |
1147 (insert word)))))) | |
1148 | |
1149 ;*---------------------------------------------------------------------*/ | |
22891
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
1150 ;* flyspell-emacs-popup ... */ |
22611 | 1151 ;*---------------------------------------------------------------------*/ |
22844
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
1152 (defun flyspell-emacs-popup (event poss word) |
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
1153 "The Emacs popup menu." |
22611 | 1154 (if (not event) |
1155 (let* ((mouse-pos (mouse-position)) | |
1156 (mouse-pos (if (nth 1 mouse-pos) | |
1157 mouse-pos | |
1158 (set-mouse-position (car mouse-pos) | |
1159 (/ (frame-width) 2) 2) | |
1160 (unfocus-frame) | |
1161 (mouse-position)))) | |
1162 (setq event (list (list (car (cdr mouse-pos)) | |
1163 (1+ (cdr (cdr mouse-pos)))) | |
1164 (car mouse-pos))))) | |
1165 (let* ((corrects (if flyspell-sort-corrections | |
1166 (sort (car (cdr (cdr poss))) 'string<) | |
1167 (car (cdr (cdr poss))))) | |
1168 (cor-menu (if (consp corrects) | |
1169 (mapcar (lambda (correct) | |
1170 (list correct correct)) | |
1171 corrects) | |
1172 '())) | |
1173 (affix (car (cdr (cdr (cdr poss))))) | |
1174 (base-menu (let ((save (if (consp affix) | |
1175 (list | |
1176 (list (concat "Save affix: " (car affix)) | |
1177 'save) | |
1178 '("Accept (session)" accept) | |
1179 '("Accept (buffer)" buffer)) | |
1180 '(("Save word" save) | |
1181 ("Accept (session)" session) | |
1182 ("Accept (buffer)" buffer))))) | |
1183 (if (consp cor-menu) | |
1184 (append cor-menu (cons "" save)) | |
1185 save))) | |
1186 (menu (cons "flyspell correction menu" base-menu))) | |
1187 (car (x-popup-menu event | |
1188 (list (format "%s [%s]" word (or ispell-local-dictionary | |
1189 ispell-dictionary)) | |
1190 menu))))) | |
1191 | |
1192 ;*---------------------------------------------------------------------*/ | |
22891
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
1193 ;* flyspell-xemacs-popup ... */ |
22611 | 1194 ;*---------------------------------------------------------------------*/ |
1195 (defun flyspell-xemacs-popup (event poss word cursor-location start end) | |
1196 "The xemacs popup menu." | |
1197 (let* ((corrects (if flyspell-sort-corrections | |
1198 (sort (car (cdr (cdr poss))) 'string<) | |
1199 (car (cdr (cdr poss))))) | |
1200 (cor-menu (if (consp corrects) | |
1201 (mapcar (lambda (correct) | |
1202 (vector correct | |
1203 (list 'flyspell-xemacs-correct | |
1204 correct | |
1205 (list 'quote poss) | |
1206 word | |
1207 cursor-location | |
1208 start | |
1209 end) | |
1210 t)) | |
1211 corrects) | |
1212 '())) | |
1213 (affix (car (cdr (cdr (cdr poss))))) | |
1214 (menu (let ((save (if (consp affix) | |
1215 (vector | |
1216 (concat "Save affix: " (car affix)) | |
1217 (list 'flyspell-xemacs-correct | |
1218 ''save | |
1219 (list 'quote poss) | |
1220 word | |
1221 cursor-location | |
1222 start | |
1223 end) | |
1224 t) | |
1225 (vector | |
1226 "Save word" | |
1227 (list 'flyspell-xemacs-correct | |
1228 ''save | |
1229 (list 'quote poss) | |
1230 word | |
1231 cursor-location | |
1232 start | |
1233 end) | |
1234 t))) | |
1235 (session (vector "Accept (session)" | |
1236 (list 'flyspell-xemacs-correct | |
1237 ''session | |
1238 (list 'quote poss) | |
1239 word | |
1240 cursor-location | |
1241 start | |
1242 end) | |
1243 t)) | |
1244 (buffer (vector "Accept (buffer)" | |
1245 (list 'flyspell-xemacs-correct | |
1246 ''buffer | |
1247 (list 'quote poss) | |
1248 word | |
1249 cursor-location | |
1250 start | |
1251 end) | |
1252 t))) | |
1253 (if (consp cor-menu) | |
1254 (append cor-menu (list "-" save session buffer)) | |
1255 (list save session buffer))))) | |
1256 (popup-menu (cons (format "%s [%s]" word (or ispell-local-dictionary | |
1257 ispell-dictionary)) | |
1258 menu)))) | |
1259 | |
1260 (provide 'flyspell) | |
1261 | |
1262 ;;; flyspell.el ends here |