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