Mercurial > emacs
annotate lisp/textmodes/flyspell.el @ 22970:ea0e3bbd3703 gcc-2_8_1-980811
Detect HPPA 2.0 architecture.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sun, 09 Aug 1998 22:42:36 +0000 |
parents | 424ac751577a |
children | 72461ea3cfc8 |
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 | |
136 (defcustom flyspell-multi-language-p t | |
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: | |
276 flyspell-mode-hook is runner after flyspell is entered. | |
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") | |
292 ;; we set the mode on or off | |
293 (setq flyspell-mode (not (or (and (null arg) flyspell-mode) | |
294 (<= (prefix-numeric-value arg) 0)))) | |
295 (if flyspell-mode | |
296 (flyspell-mode-on) | |
297 (flyspell-mode-off)) | |
298 ;; we force the modeline re-printing | |
299 (set-buffer-modified-p (buffer-modified-p))) | |
300 | |
301 ;*---------------------------------------------------------------------*/ | |
302 ;* flyspell-mode-on ... */ | |
303 ;*---------------------------------------------------------------------*/ | |
304 (defun flyspell-mode-on () | |
22844
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
305 "Turn flyspell mode on. Do not use this; use `flyspell-mode' instead." |
22611 | 306 (setq ispell-highlight-face 'flyspell-incorrect-face) |
307 ;; ispell initialization | |
308 (if flyspell-multi-language-p | |
309 (progn | |
310 (make-variable-buffer-local 'ispell-dictionary) | |
311 (make-variable-buffer-local 'ispell-process) | |
312 (make-variable-buffer-local 'ispell-filter) | |
313 (make-variable-buffer-local 'ispell-filter-continue) | |
314 (make-variable-buffer-local 'ispell-process-directory) | |
315 (make-variable-buffer-local 'ispell-parser))) | |
22891
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
316 ;; We put the `flyspel-delayed' property on some commands. |
22611 | 317 (flyspell-delay-commands) |
318 ;; 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
|
319 (make-local-hook 'post-command-hook) |
f4509374e88e
(flyspell-command-hook): Option deleted.
Richard M. Stallman <rms@gnu.org>
parents:
22946
diff
changeset
|
320 (add-hook 'post-command-hook (function flyspell-post-command-hook) t t) |
22611 | 321 ;; 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
|
322 (make-local-hook 'pre-command-hook) |
f4509374e88e
(flyspell-command-hook): Option deleted.
Richard M. Stallman <rms@gnu.org>
parents:
22946
diff
changeset
|
323 (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
|
324 |
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
325 ;; 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
|
326 (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
|
327 (if mode-predicate |
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
328 (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
|
329 |
22611 | 330 ;; the welcome message |
331 (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
|
332 (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
|
333 nil 'non-ascii))) |
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
334 (message |
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
335 (if binding |
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
336 (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
|
337 (key-description binding)) |
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
338 "Welcome to flyspell. Use Mouse-2 to correct words.")))) |
22611 | 339 ;; we have to kill the flyspell process when the buffer is deleted. |
340 ;; (thanks to Jeff Miller and Roland Rosenfeld who sent me this | |
341 ;; improvement). | |
342 (add-hook 'kill-buffer-hook | |
343 '(lambda () | |
344 (if flyspell-mode | |
345 (flyspell-mode-off)))) | |
346 ;; we end with the flyspell hooks | |
347 (run-hooks 'flyspell-mode-hook)) | |
348 | |
349 ;*---------------------------------------------------------------------*/ | |
350 ;* flyspell-delay-commands ... */ | |
351 ;*---------------------------------------------------------------------*/ | |
352 (defun flyspell-delay-commands () | |
22844
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
353 "Install the standard set of delayed commands." |
22611 | 354 (mapcar 'flyspell-delay-command flyspell-default-delayed-commands) |
355 (mapcar 'flyspell-delay-command flyspell-delayed-commands)) | |
356 | |
357 ;*---------------------------------------------------------------------*/ | |
358 ;* flyspell-delay-command ... */ | |
359 ;*---------------------------------------------------------------------*/ | |
360 (defun flyspell-delay-command (command) | |
361 "Set COMMAND to be delayed. | |
362 When flyspell `post-command-hook' is invoked because a delayed command | |
363 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
|
364 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
|
365 (interactive "SDelay Flyspell after Command: ") |
22611 | 366 (put command 'flyspell-delayed t)) |
367 | |
368 ;*---------------------------------------------------------------------*/ | |
369 ;* flyspell-ignore-commands ... */ | |
370 ;*---------------------------------------------------------------------*/ | |
371 (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
|
372 "This is an obsolete function, use `flyspell-delay-commands' instead." |
22611 | 373 (flyspell-delay-commands)) |
374 | |
375 ;*---------------------------------------------------------------------*/ | |
376 ;* flyspell-ignore-command ... */ | |
377 ;*---------------------------------------------------------------------*/ | |
378 (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
|
379 "This is an obsolete function, use `flyspell-delay-command' instead. |
22611 | 380 COMMAND is the name of the command to be delayed." |
381 (flyspell-delay-command command)) | |
382 | |
383 (make-obsolete 'flyspell-ignore-commands 'flyspell-delay-commands) | |
384 (make-obsolete 'flyspell-ignore-command 'flyspell-delay-command) | |
385 | |
386 ;*---------------------------------------------------------------------*/ | |
387 ;* flyspell-word-cache ... */ | |
388 ;*---------------------------------------------------------------------*/ | |
389 (defvar flyspell-word-cache-start nil) | |
390 (defvar flyspell-word-cache-end nil) | |
391 (defvar flyspell-word-cache-word nil) | |
392 (make-variable-buffer-local 'flyspell-word-cache-start) | |
393 (make-variable-buffer-local 'flyspell-word-cache-end) | |
394 (make-variable-buffer-local 'flyspell-word-cache-word) | |
395 | |
396 ;*---------------------------------------------------------------------*/ | |
397 ;* The flyspell pre-hook, store the current position. In the */ | |
398 ;* post command hook, we will check, if the word at this position */ | |
399 ;* has to be spell checked. */ | |
400 ;*---------------------------------------------------------------------*/ | |
401 (defvar flyspell-pre-buffer nil) | |
402 (defvar flyspell-pre-point nil) | |
403 | |
404 ;*---------------------------------------------------------------------*/ | |
405 ;* flyspell-pre-command-hook ... */ | |
406 ;*---------------------------------------------------------------------*/ | |
407 (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
|
408 "Save the current buffer and point for Flyspell's post-command hook." |
22611 | 409 (interactive) |
410 (setq flyspell-pre-buffer (current-buffer)) | |
411 (setq flyspell-pre-point (point))) | |
412 | |
413 ;*---------------------------------------------------------------------*/ | |
414 ;* flyspell-mode-off ... */ | |
415 ;*---------------------------------------------------------------------*/ | |
416 (defun flyspell-mode-off () | |
22844
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
417 "Turn flyspell mode off. Do not use this--use `flyspell-mode' instead." |
22891
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
418 ;; 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
|
419 ;; 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
|
420 (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
|
421 (ispell-kill-ispell t)) |
22611 | 422 ;; we remove the hooks |
22962
f4509374e88e
(flyspell-command-hook): Option deleted.
Richard M. Stallman <rms@gnu.org>
parents:
22946
diff
changeset
|
423 (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
|
424 (remove-hook 'pre-command-hook (function flyspell-pre-command-hook) t) |
22611 | 425 ;; we remove all the flyspell hilightings |
426 (flyspell-delete-all-overlays) | |
427 ;; we have to erase pre cache variables | |
428 (setq flyspell-pre-buffer nil) | |
429 (setq flyspell-pre-point nil) | |
430 ;; we mark the mode as killed | |
431 (setq flyspell-mode nil)) | |
432 | |
433 ;*---------------------------------------------------------------------*/ | |
434 ;* flyspell-check-word-p ... */ | |
435 ;*---------------------------------------------------------------------*/ | |
436 (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
|
437 "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
|
438 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
|
439 Mostly we check word delimiters." |
22611 | 440 (cond |
441 ((<= (- (point-max) 1) (point-min)) | |
442 ;; the buffer is not filled enough | |
443 nil) | |
444 ((not (and (symbolp this-command) (get this-command 'flyspell-delayed))) | |
445 ;; the current command is not delayed, that | |
446 ;; is that we must check the word now | |
447 t) | |
448 ((and (> (point) (point-min)) | |
449 (save-excursion | |
450 (backward-char 1) | |
451 (and (looking-at (flyspell-get-not-casechars)) | |
452 (or flyspell-consider-dash-as-word-delimiter-flag | |
453 (not (looking-at "\\-")))))) | |
22962
f4509374e88e
(flyspell-command-hook): Option deleted.
Richard M. Stallman <rms@gnu.org>
parents:
22946
diff
changeset
|
454 ;; yes because we have reached or typed a word delimiter. |
22611 | 455 t) |
456 ((not (integerp flyspell-delay)) | |
22962
f4509374e88e
(flyspell-command-hook): Option deleted.
Richard M. Stallman <rms@gnu.org>
parents:
22946
diff
changeset
|
457 ;; yes because the user had set up a no-delay configuration. |
22611 | 458 t) |
459 (t | |
460 (if (fboundp 'about-xemacs) | |
461 (sit-for flyspell-delay nil) | |
462 (sit-for flyspell-delay 0 nil))))) | |
463 | |
464 ;*---------------------------------------------------------------------*/ | |
465 ;* flyspell-check-pre-word-p ... */ | |
466 ;*---------------------------------------------------------------------*/ | |
467 (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
|
468 "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
|
469 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
|
470 before the current command." |
22611 | 471 (cond |
472 ((or (not (numberp flyspell-pre-point)) | |
473 (not (bufferp flyspell-pre-buffer)) | |
474 (not (buffer-live-p flyspell-pre-buffer))) | |
475 nil) | |
22891
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
476 ((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
|
477 (eq (char-syntax (char-after flyspell-pre-point)) ?w)) |
22611 | 478 (= flyspell-pre-point (point)) |
479 (= flyspell-pre-point (+ (point) 1))) | |
480 nil) | |
481 ((not (eq (current-buffer) flyspell-pre-buffer)) | |
482 t) | |
483 ((not (and (numberp flyspell-word-cache-start) | |
484 (numberp flyspell-word-cache-end))) | |
485 t) | |
486 (t | |
487 (or (< flyspell-pre-point flyspell-word-cache-start) | |
488 (> flyspell-pre-point flyspell-word-cache-end))))) | |
489 | |
490 ;*---------------------------------------------------------------------*/ | |
491 ;* flyspell-post-command-hook ... */ | |
492 ;*---------------------------------------------------------------------*/ | |
493 (defun flyspell-post-command-hook () | |
494 "The `post-command-hook' used by flyspell to check a word in-the-fly." | |
495 (interactive) | |
496 (if (flyspell-check-word-p) | |
497 (flyspell-word)) | |
498 (if (flyspell-check-pre-word-p) | |
499 (save-excursion | |
500 (set-buffer flyspell-pre-buffer) | |
501 (save-excursion | |
502 (goto-char flyspell-pre-point) | |
503 (flyspell-word))))) | |
504 | |
505 ;*---------------------------------------------------------------------*/ | |
506 ;* flyspell-word ... */ | |
507 ;*---------------------------------------------------------------------*/ | |
508 (defun flyspell-word (&optional following) | |
509 "Spell check a word." | |
510 (interactive (list current-prefix-arg)) | |
511 (if (interactive-p) | |
512 (setq following ispell-following-word)) | |
513 (save-excursion | |
514 (ispell-accept-buffer-local-defs) ; use the correct dictionary | |
515 (let ((cursor-location (point)) ; retain cursor location | |
516 (word (flyspell-get-word following)) | |
517 start end poss) | |
518 (if (or (eq word nil) | |
519 (and (fboundp flyspell-generic-check-word-p) | |
520 (not (funcall flyspell-generic-check-word-p)))) | |
521 t | |
522 (progn | |
523 ;; destructure return word info list. | |
524 (setq start (car (cdr word)) | |
525 end (car (cdr (cdr word))) | |
526 word (car word)) | |
527 ;; before checking in the directory, we check for doublons. | |
528 (cond | |
22844
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
529 ((and flyspell-mark-duplications-flag |
22611 | 530 (save-excursion |
531 (goto-char start) | |
532 (word-search-backward word | |
533 (- start | |
534 (+ 1 (- end start))) | |
535 t))) | |
536 ;; yes, this is a doublon | |
537 (flyspell-highlight-incorrect-region start end)) | |
538 ((and (eq flyspell-word-cache-start start) | |
539 (eq flyspell-word-cache-end end) | |
540 (string-equal flyspell-word-cache-word word)) | |
541 ;; this word had been already checked, we skip | |
542 nil) | |
543 ((and (eq ispell-parser 'tex) | |
544 (flyspell-tex-command-p word)) | |
545 ;; this is a correct word (because a tex command) | |
546 (flyspell-unhighlight-at start) | |
547 (if (> end start) | |
548 (flyspell-unhighlight-at (- end 1))) | |
549 t) | |
550 (t | |
551 ;; we setup the cache | |
552 (setq flyspell-word-cache-start start) | |
553 (setq flyspell-word-cache-end end) | |
554 (setq flyspell-word-cache-word word) | |
555 ;; now check spelling of word. | |
556 (process-send-string ispell-process "%\n") | |
557 ;; put in verbose mode | |
558 (process-send-string ispell-process | |
559 (concat "^" word "\n")) | |
22891
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
560 ;; 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
|
561 ;; 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
|
562 (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
|
563 (process-kill-without-query ispell-process)) |
22611 | 564 ;; wait until ispell has processed word |
565 (while (progn | |
566 (accept-process-output ispell-process) | |
567 (not (string= "" (car ispell-filter))))) | |
568 ;; (process-send-string ispell-process "!\n") | |
569 ;; back to terse mode. | |
570 (setq ispell-filter (cdr ispell-filter)) | |
571 (if (listp ispell-filter) | |
572 (setq poss (ispell-parse-output (car ispell-filter)))) | |
573 (cond ((eq poss t) | |
574 ;; correct | |
575 (flyspell-unhighlight-at start) | |
576 (if (> end start) | |
577 (flyspell-unhighlight-at (- end 1))) | |
578 t) | |
579 ((and (stringp poss) flyspell-highlight-flag) | |
580 ;; correct | |
581 (flyspell-unhighlight-at start) | |
582 (if (> end start) | |
583 (flyspell-unhighlight-at (- end 1))) | |
584 t) | |
585 ((null poss) | |
586 (flyspell-unhighlight-at start) | |
587 (if (> end start) | |
588 (flyspell-unhighlight-at (- end 1))) | |
589 (message "Error in ispell process")) | |
590 ((or (and (< flyspell-duplicate-distance 0) | |
591 (or (save-excursion | |
592 (goto-char start) | |
593 (word-search-backward word | |
594 (point-min) | |
595 t)) | |
596 (save-excursion | |
597 (goto-char end) | |
598 (word-search-forward word | |
599 (point-max) | |
600 t)))) | |
601 (and (> flyspell-duplicate-distance 0) | |
602 (or (save-excursion | |
603 (goto-char start) | |
604 (word-search-backward | |
605 word | |
606 (- start | |
607 flyspell-duplicate-distance) | |
608 t)) | |
609 (save-excursion | |
610 (goto-char end) | |
611 (word-search-forward | |
612 word | |
613 (+ end | |
614 flyspell-duplicate-distance) | |
615 t))))) | |
616 (if flyspell-highlight-flag | |
617 (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
|
618 (message (format "duplicate `%s'" word)))) |
22611 | 619 (t |
620 ;; incorrect highlight the location | |
621 (if flyspell-highlight-flag | |
622 (flyspell-highlight-incorrect-region start end) | |
623 (message (format "mispelling `%s'" word))))) | |
624 (goto-char cursor-location) ; return to original location | |
625 (if ispell-quit (setq ispell-quit nil))))))))) | |
626 | |
627 ;*---------------------------------------------------------------------*/ | |
628 ;* flyspell-tex-command-p ... */ | |
629 ;*---------------------------------------------------------------------*/ | |
630 (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
|
631 "Return t if WORD is a TeX command." |
22611 | 632 (eq (aref word 0) ?\\)) |
633 | |
634 ;*---------------------------------------------------------------------*/ | |
635 ;* flyspell-casechars-cache ... */ | |
636 ;*---------------------------------------------------------------------*/ | |
637 (defvar flyspell-casechars-cache nil) | |
638 (defvar flyspell-ispell-casechars-cache nil) | |
639 (make-variable-buffer-local 'flyspell-casechars-cache) | |
640 (make-variable-buffer-local 'flyspell-ispell-casechars-cache) | |
641 | |
642 ;*---------------------------------------------------------------------*/ | |
643 ;* flyspell-get-casechars ... */ | |
644 ;*---------------------------------------------------------------------*/ | |
645 (defun flyspell-get-casechars () | |
646 "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
|
647 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
|
648 this function changes the last char of the `ispell-casechars' string." |
22611 | 649 (let ((ispell-casechars (ispell-get-casechars))) |
650 (cond | |
651 ((eq ispell-casechars flyspell-ispell-casechars-cache) | |
652 flyspell-casechars-cache) | |
653 ((not (eq ispell-parser 'tex)) | |
654 (setq flyspell-ispell-casechars-cache ispell-casechars) | |
655 (setq flyspell-casechars-cache | |
656 (concat (substring ispell-casechars | |
657 0 | |
658 (- (length ispell-casechars) 1)) | |
659 "{}]")) | |
660 flyspell-casechars-cache) | |
661 (t | |
662 (setq flyspell-ispell-casechars-cache ispell-casechars) | |
663 (setq flyspell-casechars-cache ispell-casechars) | |
664 flyspell-casechars-cache)))) | |
665 | |
666 ;*---------------------------------------------------------------------*/ | |
667 ;* flyspell-get-not-casechars-cache ... */ | |
668 ;*---------------------------------------------------------------------*/ | |
669 (defvar flyspell-not-casechars-cache nil) | |
670 (defvar flyspell-ispell-not-casechars-cache nil) | |
671 (make-variable-buffer-local 'flyspell-not-casechars-cache) | |
672 (make-variable-buffer-local 'flyspell-ispell-not-casechars-cache) | |
673 | |
674 ;*---------------------------------------------------------------------*/ | |
675 ;* flyspell-get-not-casechars ... */ | |
676 ;*---------------------------------------------------------------------*/ | |
677 (defun flyspell-get-not-casechars () | |
678 "This function builds a string that is the regexp of non-word chars." | |
679 (let ((ispell-not-casechars (ispell-get-not-casechars))) | |
680 (cond | |
681 ((eq ispell-not-casechars flyspell-ispell-not-casechars-cache) | |
682 flyspell-not-casechars-cache) | |
683 ((not (eq ispell-parser 'tex)) | |
684 (setq flyspell-ispell-not-casechars-cache ispell-not-casechars) | |
685 (setq flyspell-not-casechars-cache | |
686 (concat (substring ispell-not-casechars | |
687 0 | |
688 (- (length ispell-not-casechars) 1)) | |
689 "{}]")) | |
690 flyspell-not-casechars-cache) | |
691 (t | |
692 (setq flyspell-ispell-not-casechars-cache ispell-not-casechars) | |
693 (setq flyspell-not-casechars-cache ispell-not-casechars) | |
694 flyspell-not-casechars-cache)))) | |
695 | |
696 ;*---------------------------------------------------------------------*/ | |
697 ;* flyspell-get-word ... */ | |
698 ;*---------------------------------------------------------------------*/ | |
699 (defun flyspell-get-word (following) | |
700 "Return the word for spell-checking according to Ispell syntax. | |
701 If optional argument FOLLOWING is non-nil or if `ispell-following-word' | |
702 is non-nil when called interactively, then the following word | |
703 \(rather than preceding\) is checked when the cursor is not over a word. | |
704 Optional second argument contains otherchars that can be included in word | |
705 many times. | |
706 | |
707 Word syntax described by `ispell-dictionary-alist' (which see)." | |
708 (let* ((flyspell-casechars (flyspell-get-casechars)) | |
709 (flyspell-not-casechars (flyspell-get-not-casechars)) | |
710 (ispell-otherchars (ispell-get-otherchars)) | |
711 (ispell-many-otherchars-p (ispell-get-many-otherchars-p)) | |
712 (word-regexp (concat flyspell-casechars | |
713 "+\\(" | |
714 ispell-otherchars | |
715 "?" | |
716 flyspell-casechars | |
717 "+\\)" | |
718 (if ispell-many-otherchars-p | |
719 "*" "?"))) | |
720 (tex-prelude "[\\\\{]") | |
721 (tex-regexp (if (eq ispell-parser 'tex) | |
722 (concat tex-prelude "?" word-regexp "}?") | |
723 word-regexp)) | |
724 | |
725 did-it-once | |
726 start end word) | |
727 ;; find the word | |
728 (if (not (or (looking-at flyspell-casechars) | |
729 (and (eq ispell-parser 'tex) | |
730 (looking-at tex-prelude)))) | |
731 (if following | |
732 (re-search-forward flyspell-casechars (point-max) t) | |
733 (re-search-backward flyspell-casechars (point-min) t))) | |
734 ;; move to front of word | |
735 (re-search-backward flyspell-not-casechars (point-min) 'start) | |
736 (let ((pos nil)) | |
737 (while (and (looking-at ispell-otherchars) | |
738 (not (bobp)) | |
739 (or (not did-it-once) | |
740 ispell-many-otherchars-p) | |
741 (not (eq pos (point)))) | |
742 (setq pos (point)) | |
743 (setq did-it-once t) | |
744 (backward-char 1) | |
745 (if (looking-at flyspell-casechars) | |
746 (re-search-backward flyspell-not-casechars (point-min) 'move) | |
747 (backward-char -1)))) | |
748 ;; Now mark the word and save to string. | |
749 (if (eq (re-search-forward tex-regexp (point-max) t) nil) | |
750 nil | |
751 (progn | |
752 (setq start (match-beginning 0) | |
753 end (point) | |
754 word (buffer-substring start end)) | |
755 (list word start end))))) | |
756 | |
757 ;*---------------------------------------------------------------------*/ | |
758 ;* flyspell-region ... */ | |
759 ;*---------------------------------------------------------------------*/ | |
760 (defun flyspell-region (beg end) | |
761 "Flyspell text between BEG and END." | |
762 (interactive "r") | |
763 (save-excursion | |
22891
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
764 (if (> beg end) |
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
765 (let ((old beg)) |
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
766 (setq beg end) |
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
767 (setq end old))) |
22611 | 768 (goto-char beg) |
22612
6def3da74c7c
Delete defcustom definition.
Richard M. Stallman <rms@gnu.org>
parents:
22611
diff
changeset
|
769 (let ((count 0)) |
6def3da74c7c
Delete defcustom definition.
Richard M. Stallman <rms@gnu.org>
parents:
22611
diff
changeset
|
770 (while (< (point) end) |
6def3da74c7c
Delete defcustom definition.
Richard M. Stallman <rms@gnu.org>
parents:
22611
diff
changeset
|
771 (if (= count 100) |
6def3da74c7c
Delete defcustom definition.
Richard M. Stallman <rms@gnu.org>
parents:
22611
diff
changeset
|
772 (progn |
6def3da74c7c
Delete defcustom definition.
Richard M. Stallman <rms@gnu.org>
parents:
22611
diff
changeset
|
773 (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
|
774 (* 100 (/ (float (- (point) beg)) (- end beg)))) |
22612
6def3da74c7c
Delete defcustom definition.
Richard M. Stallman <rms@gnu.org>
parents:
22611
diff
changeset
|
775 (setq count 0)) |
6def3da74c7c
Delete defcustom definition.
Richard M. Stallman <rms@gnu.org>
parents:
22611
diff
changeset
|
776 (setq count (+ 1 count))) |
6def3da74c7c
Delete defcustom definition.
Richard M. Stallman <rms@gnu.org>
parents:
22611
diff
changeset
|
777 (flyspell-word) |
6def3da74c7c
Delete defcustom definition.
Richard M. Stallman <rms@gnu.org>
parents:
22611
diff
changeset
|
778 (let ((cur (point))) |
6def3da74c7c
Delete defcustom definition.
Richard M. Stallman <rms@gnu.org>
parents:
22611
diff
changeset
|
779 (forward-word 1) |
6def3da74c7c
Delete defcustom definition.
Richard M. Stallman <rms@gnu.org>
parents:
22611
diff
changeset
|
780 (if (and (< (point) end) (> (point) (+ cur 1))) |
6def3da74c7c
Delete defcustom definition.
Richard M. Stallman <rms@gnu.org>
parents:
22611
diff
changeset
|
781 (backward-char 1))))) |
22611 | 782 (backward-char 1) |
783 (message "Spell Checking...done") | |
784 (flyspell-word))) | |
785 | |
786 ;*---------------------------------------------------------------------*/ | |
787 ;* flyspell-buffer ... */ | |
788 ;*---------------------------------------------------------------------*/ | |
789 (defun flyspell-buffer () | |
790 "Flyspell whole buffer." | |
791 (interactive) | |
792 (flyspell-region (point-min) (point-max))) | |
793 | |
794 ;*---------------------------------------------------------------------*/ | |
795 ;* flyspell-overlay-p ... */ | |
796 ;*---------------------------------------------------------------------*/ | |
797 (defun flyspell-overlay-p (o) | |
798 "A predicate that return true iff O is an overlay used by flyspell." | |
799 (and (overlayp o) (overlay-get o 'flyspell-overlay))) | |
800 | |
801 ;*---------------------------------------------------------------------*/ | |
802 ;* flyspell-delete-all-overlays ... */ | |
803 ;* ------------------------------------------------------------- */ | |
804 ;* Remove all the overlays introduced by flyspell. */ | |
805 ;*---------------------------------------------------------------------*/ | |
806 (defun flyspell-delete-all-overlays () | |
807 "Delete all the overlays used by flyspell." | |
808 (let ((l (overlays-in (point-min) (point-max)))) | |
809 (while (consp l) | |
810 (progn | |
811 (if (flyspell-overlay-p (car l)) | |
812 (delete-overlay (car l))) | |
813 (setq l (cdr l)))))) | |
814 | |
815 ;*---------------------------------------------------------------------*/ | |
816 ;* flyspell-unhighlight-at ... */ | |
817 ;*---------------------------------------------------------------------*/ | |
818 (defun flyspell-unhighlight-at (pos) | |
819 "Remove the flyspell overlay that are located at POS." | |
820 (if flyspell-persistent-highlight | |
821 (let ((overlays (overlays-at pos))) | |
822 (while (consp overlays) | |
823 (if (flyspell-overlay-p (car overlays)) | |
824 (delete-overlay (car overlays))) | |
825 (setq overlays (cdr overlays)))) | |
826 (delete-overlay flyspell-overlay))) | |
827 | |
828 ;*---------------------------------------------------------------------*/ | |
829 ;* flyspell-properties-at-p ... */ | |
830 ;* ------------------------------------------------------------- */ | |
831 ;* Is there an highlight properties at position pos? */ | |
832 ;*---------------------------------------------------------------------*/ | |
22891
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
833 (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
|
834 "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
|
835 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
|
836 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
|
837 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
|
838 (let ((prop (text-properties-at pos)) |
22611 | 839 (keep t)) |
840 (while (and keep (consp prop)) | |
841 (if (and (eq (car prop) 'local-map) (consp (cdr prop))) | |
842 (setq prop (cdr (cdr prop))) | |
843 (setq keep nil))) | |
844 (consp prop))) | |
845 | |
846 ;*---------------------------------------------------------------------*/ | |
847 ;* make-flyspell-overlay ... */ | |
848 ;*---------------------------------------------------------------------*/ | |
849 (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
|
850 "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
|
851 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
|
852 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
|
853 for the overlay." |
22611 | 854 (let ((flyspell-overlay (make-overlay beg end))) |
855 (overlay-put flyspell-overlay 'face face) | |
856 (overlay-put flyspell-overlay 'mouse-face mouse-face) | |
857 (overlay-put flyspell-overlay 'flyspell-overlay t) | |
858 (if (eq flyspell-emacs 'xemacs) | |
859 (overlay-put flyspell-overlay | |
860 flyspell-overlay-keymap-property-name | |
861 flyspell-mouse-map)))) | |
862 | |
863 ;*---------------------------------------------------------------------*/ | |
864 ;* flyspell-highlight-incorrect-region ... */ | |
865 ;*---------------------------------------------------------------------*/ | |
866 (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
|
867 "Set up an overlay on a misspelled word, in the buffer from BEG to END." |
22611 | 868 (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
|
869 (if (or flyspell-highlight-properties (not (flyspell-properties-at-p beg))) |
22611 | 870 (progn |
871 ;; we cleanup current overlay at the same position | |
872 (if (and (not flyspell-persistent-highlight) | |
873 (overlayp flyspell-overlay)) | |
874 (delete-overlay flyspell-overlay) | |
875 (let ((overlays (overlays-at beg))) | |
876 (while (consp overlays) | |
877 (if (flyspell-overlay-p (car overlays)) | |
878 (delete-overlay (car overlays))) | |
879 (setq overlays (cdr overlays))))) | |
880 ;; now we can use a new overlay | |
881 (setq flyspell-overlay | |
882 (make-flyspell-overlay beg end | |
883 'flyspell-incorrect-face 'highlight))))) | |
884 | |
885 ;*---------------------------------------------------------------------*/ | |
886 ;* flyspell-highlight-duplicate-region ... */ | |
887 ;*---------------------------------------------------------------------*/ | |
888 (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
|
889 "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
|
890 (if (or flyspell-highlight-properties (not (flyspell-properties-at-p beg))) |
22611 | 891 (progn |
892 ;; we cleanup current overlay at the same position | |
893 (if (and (not flyspell-persistent-highlight) | |
894 (overlayp flyspell-overlay)) | |
895 (delete-overlay flyspell-overlay) | |
896 (let ((overlays (overlays-at beg))) | |
897 (while (consp overlays) | |
898 (if (flyspell-overlay-p (car overlays)) | |
899 (delete-overlay (car overlays))) | |
900 (setq overlays (cdr overlays))))) | |
901 ;; now we can use a new overlay | |
902 (setq flyspell-overlay | |
903 (make-flyspell-overlay beg end | |
904 'flyspell-duplicate-face 'highlight))))) | |
905 | |
906 ;*---------------------------------------------------------------------*/ | |
907 ;* flyspell-auto-correct-cache ... */ | |
908 ;*---------------------------------------------------------------------*/ | |
909 (defvar flyspell-auto-correct-pos nil) | |
910 (defvar flyspell-auto-correct-region nil) | |
911 (defvar flyspell-auto-correct-ring nil) | |
912 | |
913 ;*---------------------------------------------------------------------*/ | |
914 ;* flyspell-auto-correct-word ... */ | |
915 ;*---------------------------------------------------------------------*/ | |
916 (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
|
917 "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
|
918 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
|
919 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
|
920 to this command." |
22611 | 921 (interactive "d") |
922 ;; use the correct dictionary | |
923 (ispell-accept-buffer-local-defs) | |
924 (if (eq flyspell-auto-correct-pos pos) | |
925 ;; we have already been using the function at the same location | |
926 (progn | |
927 (save-excursion | |
928 (let ((start (car flyspell-auto-correct-region)) | |
929 (len (cdr flyspell-auto-correct-region))) | |
930 (delete-region start (+ start len)) | |
931 (setq flyspell-auto-correct-ring (cdr flyspell-auto-correct-ring)) | |
932 (let* ((word (car flyspell-auto-correct-ring)) | |
933 (len (length word))) | |
934 (rplacd flyspell-auto-correct-region len) | |
935 (goto-char start) | |
936 (insert word)))) | |
937 (setq flyspell-auto-correct-pos (point))) | |
938 ;; retain cursor location | |
939 (let ((cursor-location pos) | |
940 (word (flyspell-get-word nil)) | |
941 start end poss) | |
942 ;; destructure return word info list. | |
943 (setq start (car (cdr word)) | |
944 end (car (cdr (cdr word))) | |
945 word (car word)) | |
946 ;; now check spelling of word. | |
947 (process-send-string ispell-process "%\n") ;put in verbose mode | |
948 (process-send-string ispell-process (concat "^" word "\n")) | |
949 ;; wait until ispell has processed word | |
950 (while (progn | |
951 (accept-process-output ispell-process) | |
952 (not (string= "" (car ispell-filter))))) | |
953 (setq ispell-filter (cdr ispell-filter)) | |
954 (if (listp ispell-filter) | |
955 (setq poss (ispell-parse-output (car ispell-filter)))) | |
956 (cond ((or (eq poss t) (stringp poss)) | |
957 ;; don't correct word | |
958 t) | |
959 ((null poss) | |
960 ;; ispell error | |
961 (error "Ispell: error in Ispell process")) | |
962 (t | |
963 ;; the word is incorrect, we have to propose a replacement | |
964 (let ((replacements (if flyspell-sort-corrections | |
965 (sort (car (cdr (cdr poss))) 'string<) | |
966 (car (cdr (cdr poss)))))) | |
967 (if (consp replacements) | |
968 (progn | |
969 (let ((replace (car replacements))) | |
970 (setq word replace) | |
971 (setq cursor-location (+ (- (length word) (- end start)) | |
972 cursor-location)) | |
973 (if (not (equal word (car poss))) | |
974 (progn | |
975 ;; the save the current replacements | |
976 (setq flyspell-auto-correct-pos cursor-location) | |
977 (setq flyspell-auto-correct-region | |
978 (cons start (length word))) | |
979 (let ((l replacements)) | |
980 (while (consp (cdr l)) | |
981 (setq l (cdr l))) | |
982 (rplacd l (cons (car poss) replacements))) | |
983 (setq flyspell-auto-correct-ring | |
984 (cdr replacements)) | |
985 (delete-region start end) | |
986 (insert word))))))))) | |
987 ;; return to original location | |
988 (goto-char cursor-location) | |
989 (ispell-pdict-save t)))) | |
990 | |
991 ;*---------------------------------------------------------------------*/ | |
992 ;* flyspell-correct-word ... */ | |
993 ;*---------------------------------------------------------------------*/ | |
994 (defun flyspell-correct-word (event) | |
995 "Check spelling of word under or before the cursor. | |
996 If the word is not found in dictionary, display possible corrections | |
997 in a popup menu allowing you to choose one. | |
998 | |
999 Word syntax described by `ispell-dictionary-alist' (which see). | |
1000 | |
1001 This will check or reload the dictionary. Use \\[ispell-change-dictionary] | |
1002 or \\[ispell-region] to update the Ispell process." | |
1003 (interactive "e") | |
1004 (if (eq flyspell-emacs 'xemacs) | |
1005 (flyspell-correct-word/mouse-keymap event) | |
1006 (flyspell-correct-word/local-keymap event))) | |
1007 | |
1008 ;*---------------------------------------------------------------------*/ | |
1009 ;* flyspell-correct-word/local-keymap ... */ | |
1010 ;*---------------------------------------------------------------------*/ | |
1011 (defun flyspell-correct-word/local-keymap (event) | |
1012 "emacs 19.xx seems to be buggous. Overlay keymap does not seems | |
1013 to work correctly with local map. That is, if a key is not | |
1014 defined for the overlay keymap, the current local map, is not | |
1015 checked. The binding is resolved with the global map. The | |
1016 consequence is that we can not use overlay map with flyspell." | |
1017 (interactive "e") | |
1018 (save-window-excursion | |
1019 (let ((save (point))) | |
1020 (mouse-set-point event) | |
1021 ;; we look for a flyspell overlay here | |
1022 (let ((overlays (overlays-at (point))) | |
1023 (overlay nil)) | |
1024 (while (consp overlays) | |
1025 (if (flyspell-overlay-p (car overlays)) | |
1026 (progn | |
1027 (setq overlay (car overlays)) | |
1028 (setq overlays nil)) | |
1029 (setq overlays (cdr overlays)))) | |
1030 ;; we return to the correct location | |
1031 (goto-char save) | |
1032 ;; we check to see if button2 has been used overlay a | |
1033 ;; flyspell overlay | |
1034 (if overlay | |
1035 ;; yes, so we use the flyspell function | |
1036 (flyspell-correct-word/mouse-keymap event) | |
1037 ;; no so we have to use the non flyspell binding | |
1038 (let ((flyspell-mode nil)) | |
1039 (if (key-binding (this-command-keys)) | |
1040 (command-execute (key-binding (this-command-keys)))))))))) | |
1041 | |
1042 ;*---------------------------------------------------------------------*/ | |
1043 ;* flyspell-correct-word ... */ | |
1044 ;*---------------------------------------------------------------------*/ | |
1045 (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
|
1046 "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
|
1047 The word checked is the word at the mouse position." |
22611 | 1048 (interactive "e") |
1049 ;; use the correct dictionary | |
1050 (ispell-accept-buffer-local-defs) | |
1051 ;; retain cursor location (I don't know why but save-excursion here fails). | |
1052 (let ((save (point))) | |
1053 (mouse-set-point event) | |
1054 (let ((cursor-location (point)) | |
1055 (word (flyspell-get-word nil)) | |
1056 start end poss replace) | |
1057 ;; destructure return word info list. | |
1058 (setq start (car (cdr word)) | |
1059 end (car (cdr (cdr word))) | |
1060 word (car word)) | |
1061 ;; now check spelling of word. | |
1062 (process-send-string ispell-process "%\n") ;put in verbose mode | |
1063 (process-send-string ispell-process (concat "^" word "\n")) | |
1064 ;; wait until ispell has processed word | |
1065 (while (progn | |
1066 (accept-process-output ispell-process) | |
1067 (not (string= "" (car ispell-filter))))) | |
1068 (setq ispell-filter (cdr ispell-filter)) | |
1069 (if (listp ispell-filter) | |
1070 (setq poss (ispell-parse-output (car ispell-filter)))) | |
1071 (cond ((or (eq poss t) (stringp poss)) | |
1072 ;; don't correct word | |
1073 t) | |
1074 ((null poss) | |
1075 ;; ispell error | |
1076 (error "Ispell: error in Ispell process")) | |
1077 ((string-match "GNU" (emacs-version)) | |
1078 ;; 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
|
1079 (setq replace (flyspell-emacs-popup event poss word)) |
22611 | 1080 (cond ((eq replace 'ignore) |
1081 nil) | |
1082 ((eq replace 'save) | |
1083 (process-send-string ispell-process (concat "*" word "\n")) | |
1084 (flyspell-unhighlight-at cursor-location) | |
1085 (setq ispell-pdict-modified-p '(t))) | |
1086 ((or (eq replace 'buffer) (eq replace 'session)) | |
1087 (process-send-string ispell-process (concat "@" word "\n")) | |
1088 (if (null ispell-pdict-modified-p) | |
1089 (setq ispell-pdict-modified-p | |
1090 (list ispell-pdict-modified-p))) | |
1091 (flyspell-unhighlight-at cursor-location) | |
1092 (if (eq replace 'buffer) | |
1093 (ispell-add-per-file-word-list word))) | |
1094 (replace | |
1095 (setq word (if (atom replace) replace (car replace)) | |
1096 cursor-location (+ (- (length word) (- end start)) | |
1097 cursor-location)) | |
1098 (if (not (equal word (car poss))) | |
1099 (progn | |
1100 (delete-region start end) | |
1101 (insert word)))))) | |
1102 ((string-match "XEmacs" (emacs-version)) | |
1103 (flyspell-xemacs-popup | |
1104 event poss word cursor-location start end))) | |
1105 (ispell-pdict-save t)) | |
1106 (if (< save (point-max)) | |
1107 (goto-char save) | |
1108 (goto-char (point-max))))) | |
1109 | |
1110 ;*---------------------------------------------------------------------*/ | |
1111 ;* flyspell-xemacs-correct ... */ | |
1112 ;*---------------------------------------------------------------------*/ | |
1113 (defun flyspell-xemacs-correct (replace poss word cursor-location start end) | |
1114 "The xemacs popup menu callback." | |
1115 (cond ((eq replace 'ignore) | |
1116 nil) | |
1117 ((eq replace 'save) | |
1118 (process-send-string ispell-process (concat "*" word "\n")) | |
1119 (flyspell-unhighlight-at cursor-location) | |
1120 (setq ispell-pdict-modified-p '(t))) | |
1121 ((or (eq replace 'buffer) (eq replace 'session)) | |
1122 (process-send-string ispell-process (concat "@" word "\n")) | |
1123 (flyspell-unhighlight-at cursor-location) | |
1124 (if (null ispell-pdict-modified-p) | |
1125 (setq ispell-pdict-modified-p | |
1126 (list ispell-pdict-modified-p))) | |
1127 (if (eq replace 'buffer) | |
1128 (ispell-add-per-file-word-list word))) | |
1129 (replace | |
1130 (setq word (if (atom replace) replace (car replace)) | |
1131 cursor-location (+ (- (length word) (- end start)) | |
1132 cursor-location)) | |
1133 (if (not (equal word (car poss))) | |
1134 (save-excursion | |
1135 (delete-region start end) | |
1136 (goto-char start) | |
1137 (insert word)))))) | |
1138 | |
1139 ;*---------------------------------------------------------------------*/ | |
22891
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
1140 ;* flyspell-emacs-popup ... */ |
22611 | 1141 ;*---------------------------------------------------------------------*/ |
22844
1104a715c324
(flyspell-emacs-popup): Renamed from flyspell-gnuemacs-popup. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
22648
diff
changeset
|
1142 (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
|
1143 "The Emacs popup menu." |
22611 | 1144 (if (not event) |
1145 (let* ((mouse-pos (mouse-position)) | |
1146 (mouse-pos (if (nth 1 mouse-pos) | |
1147 mouse-pos | |
1148 (set-mouse-position (car mouse-pos) | |
1149 (/ (frame-width) 2) 2) | |
1150 (unfocus-frame) | |
1151 (mouse-position)))) | |
1152 (setq event (list (list (car (cdr mouse-pos)) | |
1153 (1+ (cdr (cdr mouse-pos)))) | |
1154 (car mouse-pos))))) | |
1155 (let* ((corrects (if flyspell-sort-corrections | |
1156 (sort (car (cdr (cdr poss))) 'string<) | |
1157 (car (cdr (cdr poss))))) | |
1158 (cor-menu (if (consp corrects) | |
1159 (mapcar (lambda (correct) | |
1160 (list correct correct)) | |
1161 corrects) | |
1162 '())) | |
1163 (affix (car (cdr (cdr (cdr poss))))) | |
1164 (base-menu (let ((save (if (consp affix) | |
1165 (list | |
1166 (list (concat "Save affix: " (car affix)) | |
1167 'save) | |
1168 '("Accept (session)" accept) | |
1169 '("Accept (buffer)" buffer)) | |
1170 '(("Save word" save) | |
1171 ("Accept (session)" session) | |
1172 ("Accept (buffer)" buffer))))) | |
1173 (if (consp cor-menu) | |
1174 (append cor-menu (cons "" save)) | |
1175 save))) | |
1176 (menu (cons "flyspell correction menu" base-menu))) | |
1177 (car (x-popup-menu event | |
1178 (list (format "%s [%s]" word (or ispell-local-dictionary | |
1179 ispell-dictionary)) | |
1180 menu))))) | |
1181 | |
1182 ;*---------------------------------------------------------------------*/ | |
22891
780c3ef895d7
(flyspell-duplicate-distance): Doc fix; change default to 10000.
Richard M. Stallman <rms@gnu.org>
parents:
22844
diff
changeset
|
1183 ;* flyspell-xemacs-popup ... */ |
22611 | 1184 ;*---------------------------------------------------------------------*/ |
1185 (defun flyspell-xemacs-popup (event poss word cursor-location start end) | |
1186 "The xemacs popup menu." | |
1187 (let* ((corrects (if flyspell-sort-corrections | |
1188 (sort (car (cdr (cdr poss))) 'string<) | |
1189 (car (cdr (cdr poss))))) | |
1190 (cor-menu (if (consp corrects) | |
1191 (mapcar (lambda (correct) | |
1192 (vector correct | |
1193 (list 'flyspell-xemacs-correct | |
1194 correct | |
1195 (list 'quote poss) | |
1196 word | |
1197 cursor-location | |
1198 start | |
1199 end) | |
1200 t)) | |
1201 corrects) | |
1202 '())) | |
1203 (affix (car (cdr (cdr (cdr poss))))) | |
1204 (menu (let ((save (if (consp affix) | |
1205 (vector | |
1206 (concat "Save affix: " (car affix)) | |
1207 (list 'flyspell-xemacs-correct | |
1208 ''save | |
1209 (list 'quote poss) | |
1210 word | |
1211 cursor-location | |
1212 start | |
1213 end) | |
1214 t) | |
1215 (vector | |
1216 "Save word" | |
1217 (list 'flyspell-xemacs-correct | |
1218 ''save | |
1219 (list 'quote poss) | |
1220 word | |
1221 cursor-location | |
1222 start | |
1223 end) | |
1224 t))) | |
1225 (session (vector "Accept (session)" | |
1226 (list 'flyspell-xemacs-correct | |
1227 ''session | |
1228 (list 'quote poss) | |
1229 word | |
1230 cursor-location | |
1231 start | |
1232 end) | |
1233 t)) | |
1234 (buffer (vector "Accept (buffer)" | |
1235 (list 'flyspell-xemacs-correct | |
1236 ''buffer | |
1237 (list 'quote poss) | |
1238 word | |
1239 cursor-location | |
1240 start | |
1241 end) | |
1242 t))) | |
1243 (if (consp cor-menu) | |
1244 (append cor-menu (list "-" save session buffer)) | |
1245 (list save session buffer))))) | |
1246 (popup-menu (cons (format "%s [%s]" word (or ispell-local-dictionary | |
1247 ispell-dictionary)) | |
1248 menu)))) | |
1249 | |
1250 (provide 'flyspell) | |
1251 | |
1252 ;;; flyspell.el ends here |