Commit | Line | Data |
---|---|---|
be010748 RS |
1 | ;;; ispell.el --- spell checking using Ispell |
2 | ||
b578f267 | 3 | ;; Copyright (C) 1994, 1995 Free Software Foundation, Inc. |
be010748 | 4 | |
b578f267 EN |
5 | ;; Authors : Ken Stevens <k.stevens@ieee.org> |
6 | ;; Last Modified On: Tue Jun 13 12:05:28 EDT 1995 | |
7 | ;; Update Revision : 2.37 | |
8 | ;; Syntax : emacs-lisp | |
9 | ;; Status : Release with 3.1.12+ ispell. | |
10 | ;; Version : International Ispell Version 3.1 by Geoff Kuenning. | |
11 | ;; Bug Reports : ispell-el-bugs@itcorp.com | |
be010748 | 12 | |
b578f267 EN |
13 | ;; This file is part of GNU Emacs. |
14 | ||
15 | ;; GNU Emacs is free software; you can redistribute it and/or modify | |
16 | ;; it under the terms of the GNU General Public License as published by | |
17 | ;; the Free Software Foundation; either version 2, or (at your option) | |
18 | ;; any later version. | |
19 | ||
20 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
21 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
22 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
23 | ;; GNU General Public License for more details. | |
24 | ||
25 | ;; You should have received a copy of the GNU General Public License | |
26 | ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
27 | ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
28 | ;; Boston, MA 02111-1307, USA. | |
29 | ||
30 | ;; Note: version numbers and time stamp are not updated | |
31 | ;; when this file is edited for release with GNU Emacs. | |
be010748 | 32 | |
007852e0 | 33 | ;;; Commentary: |
007852e0 | 34 | |
b578f267 EN |
35 | ;; INSTRUCTIONS |
36 | ;; | |
37 | ;; This code contains a section of user-settable variables that you should | |
38 | ;; inspect prior to installation. Look past the end of the history list. | |
39 | ;; Set them up for your locale and the preferences of the majority of the | |
40 | ;; users. Otherwise the users may need to set a number of variables | |
41 | ;; themselves. | |
42 | ;; You particularly may want to change the default dictionary for your | |
43 | ;; country and language. | |
44 | ;; | |
45 | ;; | |
46 | ;; To fully install this, add this file to your Emacs Lisp directory and | |
47 | ;; compile it with M-X byte-compile-file. Then add the following to the | |
48 | ;; appropriate init file: | |
49 | ;; | |
50 | ;; (autoload 'ispell-word "ispell" | |
51 | ;; "Check the spelling of word in buffer." t) | |
52 | ;; (global-set-key "\e$" 'ispell-word) | |
53 | ;; (autoload 'ispell-region "ispell" | |
54 | ;; "Check the spelling of region." t) | |
55 | ;; (autoload 'ispell-buffer "ispell" | |
56 | ;; "Check the spelling of buffer." t) | |
57 | ;; (autoload 'ispell-complete-word "ispell" | |
58 | ;; "Look up current word in dictionary and try to complete it." t) | |
59 | ;; (autoload 'ispell-change-dictionary "ispell" | |
60 | ;; "Change ispell dictionary." t) | |
61 | ;; (autoload 'ispell-message "ispell" | |
62 | ;; "Check spelling of mail message or news post.") | |
63 | ;; | |
64 | ;; Depending on the mail system you use, you may want to include these: | |
65 | ;; | |
66 | ;; (add-hook 'news-inews-hook 'ispell-message) | |
67 | ;; (add-hook 'mail-send-hook 'ispell-message) | |
68 | ;; (add-hook 'mh-before-send-letter-hook 'ispell-message) | |
69 | ;; | |
70 | ;; | |
71 | ;; Ispell has a TeX parser and a nroff parser (the default). | |
72 | ;; The parsing is controlled by the variable ispell-parser. Currently | |
73 | ;; it is just a "toggle" between TeX and nroff, but if more parsers are | |
74 | ;; added it will be updated. See the variable description for more info. | |
75 | ;; | |
76 | ;; | |
77 | ;; TABLE OF CONTENTS | |
78 | ;; | |
79 | ;; ispell-word | |
80 | ;; ispell-region | |
81 | ;; ispell-buffer | |
82 | ;; ispell-message | |
83 | ;; ispell-continue | |
84 | ;; ispell-complete-word | |
85 | ;; ispell-complete-word-interior-frag | |
86 | ;; ispell-change-dictionary | |
87 | ;; ispell-kill-ispell | |
88 | ;; ispell-pdict-save | |
89 | ;; | |
90 | ;; | |
91 | ;; Commands in ispell-region: | |
92 | ;; Character replacement: Replace word with choice. May query-replace. | |
93 | ;; ' ': Accept word this time. | |
94 | ;; 'i': Accept word and insert into private dictionary. | |
95 | ;; 'a': Accept word for this session. | |
96 | ;; 'A': Accept word and place in buffer-local dictionary. | |
97 | ;; 'r': Replace word with typed-in value. Rechecked. | |
98 | ;; 'R': Replace word with typed-in value. Query-replaced in buffer. Rechecked. | |
99 | ;; '?': Show these commands | |
100 | ;; 'x': Exit spelling buffer. Move cursor to original point. | |
101 | ;; 'X': Exit spelling buffer. Leave cursor at the current point. | |
102 | ;; 'q': Quit spelling session (Kills ispell process). | |
103 | ;; 'l': Look up typed-in replacement in alternate dictionary. Wildcards okay. | |
104 | ;; 'u': Like 'i', but the word is lower-cased first. | |
105 | ;; 'm': Like 'i', but allows one to include dictionary completion info. | |
106 | ;; 'C-l': redraws screen | |
107 | ;; 'C-r': recursive edit | |
108 | ;; 'C-z': suspend emacs or iconify frame | |
109 | ;; | |
110 | ;; Buffer-Local features: | |
111 | ;; There are a number of buffer-local features that can be used to customize | |
112 | ;; ispell for the current buffer. This includes language dictionaries, | |
113 | ;; personal dictionaries, parsing, and local word spellings. Each of these | |
114 | ;; local customizations are done either through local variables, or by | |
115 | ;; including the keyword and argument(s) at the end of the buffer (usually | |
116 | ;; prefixed by the comment characters). See the end of this file for | |
117 | ;; examples. The local keywords and variables are: | |
118 | ;; | |
119 | ;; ispell-dictionary-keyword language-dictionary | |
120 | ;; uses local variable ispell-local-dictionary | |
121 | ;; ispell-pdict-keyword personal-dictionary | |
122 | ;; uses local variable ispell-local-pdict | |
123 | ;; ispell-parsing-keyword mode-arg extended-char-arg | |
124 | ;; ispell-words-keyword any number of local word spellings | |
125 | ;; | |
126 | ;; | |
127 | ;; BUGS: | |
128 | ;; Highlighting in version 19 still doesn't work on tty's. | |
129 | ;; On some versions of emacs, growing the minibuffer fails. | |
130 | ;; | |
131 | ;; HISTORY | |
132 | ;; | |
133 | ;; Revision 2.37 1995/6/13 12:05:28 stevens | |
134 | ;; Removed autoload from ispell-dictionary-alist. *choices* mode-line shows | |
135 | ;; misspelled word. Block skip for pgp & forwarded messages added. | |
136 | ;; RMS: the autoload changes had problems and I removed them. | |
137 | ;; | |
138 | ;; Revision 2.36 1995/2/6 17:39:38 stevens | |
139 | ;; Properly adjust screen with different ispell-choices-win-default-height | |
140 | ;; settings. Skips SGML entity references. | |
141 | ;; | |
142 | ;; Revision 2.35 1995/1/13 14:16:46 stevens | |
143 | ;; Skips SGML tags, ispell-change-dictionary fix for add-hook, assure personal | |
144 | ;; dictionary is saved when called from the menu | |
145 | ;; | |
146 | ;; Revision 2.34 1994/12/08 13:17:41 stevens | |
147 | ;; Interaction corrected to function with all 3.1 ispell versions. | |
148 | ;; | |
149 | ;; Revision 2.33 1994/11/24 02:31:20 stevens | |
150 | ;; Repaired bug introduced in 2.32 that corrupts buffers when correcting. | |
151 | ;; Improved buffer scrolling. Nondestructive buffer selections allowed. | |
152 | ;; | |
153 | ;; Revision 2.32 1994/10/31 21:10:08 geoff | |
154 | ;; Many revisions accepted from RMS/FSF. I think (though I don't know) that | |
155 | ;; this represents an 'official' version. | |
156 | ;; | |
157 | ;; Revision 2.31 1994/5/31 10:18:17 stevens | |
158 | ;; Repaired comments. buffer-local commands executed in `ispell-word' now. | |
159 | ;; German dictionary described for extended character mode. Dict messages. | |
160 | ;; | |
161 | ;; Revision 2.30 1994/5/20 22:18:36 stevens | |
162 | ;; Continue ispell from ispell-word, C-z functionality fixed. | |
163 | ;; | |
164 | ;; Revision 2.29 1994/5/12 09:44:33 stevens | |
165 | ;; Restored ispell-use-ptys-p, ispell-message aborts sends with interrupt. | |
166 | ;; defined fn ispell | |
167 | ;; | |
168 | ;; Revision 2.28 1994/4/28 16:24:40 stevens | |
169 | ;; Window checking when ispell-message put on gnus-inews-article-hook jwz. | |
170 | ;; prefixed ispell- to highlight functions and horiz-scroll fn. | |
171 | ;; Try and respect case of word in ispell-complete-word. | |
172 | ;; Ignore non-char events. Ispell-use-ptys-p commented out. Lucid menu. | |
173 | ;; Better interrupt handling. ispell-message improvements from Ethan. | |
174 | ;; | |
175 | ;; Revision 2.27 | |
176 | ;; version 18 explicit C-g handling disabled as it didn't work. Added | |
177 | ;; ispell-extra-args for ispell customization (jwz) | |
178 | ;; | |
179 | ;; Revision 2.26 1994/2/15 16:11:14 stevens | |
180 | ;; name changes for copyright assignment. Added word-frags in complete-word. | |
181 | ;; Horizontal scroll (John Conover). Query-replace matches words now. bugs. | |
182 | ;; | |
183 | ;; Revision 2.25 | |
184 | ;; minor mods, upgraded ispell-message | |
185 | ;; | |
186 | ;; Revision 2.24 | |
187 | ;; query-replace more robust, messages, defaults, ispell-change-dict. | |
188 | ;; | |
189 | ;; Revision 2.23 1993/11/22 23:47:03 stevens | |
190 | ;; ispell-message, Fixed highlighting, added menu-bar, fixed ispell-help, ... | |
191 | ;; | |
192 | ;; Revision 2.22 | |
193 | ;; Added 'u' command. Fixed default in ispell-local-dictionary. | |
194 | ;; fixed affix rules display. Tib skipping more robust. Contributions by | |
195 | ;; Per Abraham (parser selection), Denis Howe, and Eberhard Mattes. | |
196 | ;; | |
197 | ;; Revision 2.21 1993/06/30 14:09:04 stevens | |
198 | ;; minor bugs. (nroff word skipping fixed) | |
199 | ;; | |
200 | ;; Revision 2.20 1993/06/30 14:09:04 stevens | |
201 | ;; | |
202 | ;; Debugging and contributions by: Boris Aronov, Rik Faith, Chris Moore, | |
203 | ;; Kevin Rodgers, Malcolm Davis. | |
204 | ;; Particular thanks to Michael Lipp, Jamie Zawinski, Phil Queinnec | |
205 | ;; and John Heidemann for suggestions and code. | |
206 | ;; Major update including many tweaks. | |
207 | ;; Many changes were integrations of suggestions. | |
208 | ;; lookup-words rehacked to use call-process (Jamie). | |
209 | ;; ispell-complete-word rehacked to be compatible with the rest of the | |
210 | ;; system for word searching and to include multiple wildcards, | |
211 | ;; and it's own dictionary. | |
212 | ;; query-replace capability added. New options 'X', 'R', and 'A'. | |
213 | ;; buffer-local modes for dictionary, word-spelling, and formatter-parsing. | |
214 | ;; Many random bugs, like commented comments being skipped, fix to | |
215 | ;; keep-choices-win, fix for math mode, added pipe mode choice, | |
216 | ;; fixed 'q' command, ispell-word checks previous word and leave cursor | |
217 | ;; in same location. Fixed tib code which could drop spelling regions. | |
218 | ;; Cleaned up setq calls for efficiency. Gave more context on window overlays. | |
219 | ;; Assure context on ispell-command-loop. Window lossage in look cmd fixed. | |
220 | ;; Due to pervasive opinion, common-lisp package syntax removed. Display | |
221 | ;; problem when not highlighting. | |
222 | ;; | |
223 | ;; Revision 2.19 1992/01/10 10:54:08 geoff | |
224 | ;; Make another attempt at fixing the "Bogus, dude" problem. This one is | |
225 | ;; less elegant, but has the advantage of working. | |
226 | ;; | |
227 | ;; Revision 2.18 1992/01/07 10:04:52 geoff | |
228 | ;; Fix the "Bogus, Dude" problem in ispell-word. | |
229 | ;; | |
230 | ;; Revision 2.17 1991/09/12 00:01:42 geoff | |
231 | ;; Add some changes to make ispell-complete-word work better, though | |
232 | ;; still not perfectly. | |
233 | ;; | |
234 | ;; Revision 2.16 91/09/04 18:00:52 geoff | |
235 | ;; More updates from Sebastian, to make the multiple-dictionary support | |
236 | ;; more flexible. | |
237 | ;; | |
238 | ;; Revision 2.15 91/09/04 17:30:02 geoff | |
239 | ;; Sebastian Kremer's tib support | |
240 | ;; | |
241 | ;; Revision 2.14 91/09/04 16:19:37 geoff | |
242 | ;; Don't do set-window-start if the move-to-window-line moved us | |
243 | ;; downward, rather than upward. This prevents getting the buffer all | |
244 | ;; confused. Also, don't use the "not-modified" function to clear the | |
245 | ;; modification flag; instead use set-buffer-modified-p. This prevents | |
246 | ;; extra messages from flashing. | |
247 | ;; | |
248 | ;; Revision 2.13 91/09/04 14:35:41 geoff | |
249 | ;; Fix a spelling error in a comment. Add code to handshake with the | |
250 | ;; ispell process before sending anything to it. | |
251 | ;; | |
252 | ;; Revision 2.12 91/09/03 20:14:21 geoff | |
253 | ;; Add Sebastian Kremer's multiple-language support. | |
254 | ;; | |
255 | ;; | |
256 | ;; Walt Buehring | |
257 | ;; Texas Instruments - Computer Science Center | |
258 | ;; ARPA: Buehring%TI-CSL@CSNet-Relay | |
259 | ;; UUCP: {smu, texsun, im4u, rice} ! ti-csl ! buehring | |
260 | ;; | |
261 | ;; ispell-region and associated routines added by | |
262 | ;; Perry Smith | |
263 | ;; pedz@bobkat | |
264 | ;; Tue Jan 13 20:18:02 CST 1987 | |
265 | ;; | |
266 | ;; extensively modified by Mark Davies and Andrew Vignaux | |
267 | ;; {mark,andrew}@vuwcomp | |
268 | ;; Sun May 10 11:45:04 NZST 1987 | |
269 | ;; | |
270 | ;; Ken Stevens ARPA: k.stevens@ieee.org | |
271 | ;; Tue Jan 3 16:59:07 PST 1989 | |
272 | ;; This file has overgone a major overhaul to be compatible with ispell | |
273 | ;; version 2.1. Most of the functions have been totally rewritten, and | |
274 | ;; many user-accessible variables have been added. The syntax table has | |
275 | ;; been removed since it didn't work properly anyway, and a filter is | |
276 | ;; used rather than a buffer. Regular expressions are used based on | |
277 | ;; ispell's internal definition of characters (see ispell(4)). | |
278 | ;; Some new updates: | |
279 | ;; - Updated to version 3.0 to include terse processing. | |
280 | ;; - Added a variable for the look command. | |
281 | ;; - Fixed a bug in ispell-word when cursor is far away from the word | |
282 | ;; that is to be checked. | |
283 | ;; - Ispell places the incorrect word or guess in the minibuffer now. | |
284 | ;; - fixed a bug with 'l' option when multiple windows are on the screen. | |
285 | ;; - lookup-words just didn't work with the process filter. Fixed. | |
286 | ;; - Rewrote the process filter to make it cleaner and more robust | |
287 | ;; in the event of a continued line not being completed. | |
288 | ;; - Made ispell-init-process more robust in handling errors. | |
289 | ;; - Fixed bug in continuation location after a region has been modified by | |
290 | ;; correcting a misspelling. | |
291 | ;; Mon 17 Sept 1990 | |
292 | ;; | |
293 | ;; Sebastian Kremer <sk@thp.uni-koeln.de> | |
294 | ;; Wed Aug 7 14:02:17 MET DST 1991 | |
295 | ;; - Ported ispell-complete-word from Ispell 2 to Ispell 3. | |
296 | ;; - Added ispell-kill-ispell command. | |
297 | ;; - Added ispell-dictionary and ispell-dictionary-alist variables to | |
298 | ;; support other than default language. See their docstrings and | |
299 | ;; command ispell-change-dictionary. | |
300 | ;; - (ispelled it :-) | |
301 | ;; - Added ispell-skip-tib variable to support the tib bibliography | |
302 | ;; program. | |
007852e0 RS |
303 | |
304 | ||
b578f267 EN |
305 | ;; ********************************************************************** |
306 | ;; The following variables should be set according to personal preference | |
307 | ;; and location of binaries: | |
308 | ;; ********************************************************************** | |
007852e0 | 309 | |
b578f267 | 310 | ;; ******* THIS FILE IS WRITTEN FOR ISPELL VERSION 3.1 |
007852e0 | 311 | |
007852e0 RS |
312 | ;;; Code: |
313 | ||
314 | (defvar ispell-highlight-p t | |
4b03da72 | 315 | "*Highlight spelling errors when non-nil.") |
007852e0 RS |
316 | |
317 | (defvar ispell-highlight-face 'highlight | |
a9210a53 RS |
318 | "*The face used for Ispell highlighting. For Emacses with overlays. |
319 | Possible values are `highlight', `modeline', `secondary-selection', | |
320 | `region', and `underline'. | |
007852e0 RS |
321 | This variable can be set by the user to whatever face they desire. |
322 | It's most convenient if the cursor color and highlight color are | |
4b03da72 | 323 | slightly different.") |
007852e0 RS |
324 | |
325 | (defvar ispell-check-comments nil | |
4b03da72 | 326 | "*Spelling of comments checked when non-nil.") |
007852e0 RS |
327 | |
328 | (defvar ispell-query-replace-choices nil | |
4b03da72 | 329 | "*Corrections made throughout region when non-nil. |
a9210a53 | 330 | Uses `query-replace' (\\[query-replace]) for corrections.") |
007852e0 RS |
331 | |
332 | (defvar ispell-skip-tib nil | |
a9210a53 | 333 | "*Does not spell check `tib' bibliography references when non-nil. |
4b03da72 | 334 | Skips any text between strings matching regular expressions |
a9210a53 | 335 | `ispell-tib-ref-beginning' and `ispell-tib-ref-end'. |
007852e0 RS |
336 | |
337 | TeX users beware: Any field starting with [. will skip until a .] -- even | |
a9210a53 | 338 | your whole buffer -- unless you set `ispell-skip-tib' to nil. That includes |
007852e0 RS |
339 | a [.5mm] type of number....") |
340 | ||
341 | (defvar ispell-tib-ref-beginning "[[<]\\." | |
342 | "Regexp matching the beginning of a Tib reference.") | |
343 | ||
344 | (defvar ispell-tib-ref-end "\\.[]>]" | |
345 | "Regexp matching the end of a Tib reference.") | |
346 | ||
347 | (defvar ispell-keep-choices-win t | |
a9210a53 | 348 | "*When not nil, the `*Choices*' window remains for spelling session. |
007852e0 RS |
349 | This minimizes redisplay thrashing.") |
350 | ||
351 | (defvar ispell-choices-win-default-height 2 | |
a9210a53 | 352 | "*The default size of the `*Choices*' window, including status line. |
4b03da72 | 353 | Must be greater than 1.") |
007852e0 RS |
354 | |
355 | (defvar ispell-program-name "ispell" | |
356 | "Program invoked by \\[ispell-word] and \\[ispell-region] commands.") | |
357 | ||
358 | (defvar ispell-alternate-dictionary | |
359 | (cond ((file-exists-p "/usr/dict/web2") "/usr/dict/web2") | |
e29702dd | 360 | ((file-exists-p "/usr/share/dict/web2") "/usr/share/dict/web2") |
007852e0 RS |
361 | ((file-exists-p "/usr/dict/words") "/usr/dict/words") |
362 | ((file-exists-p "/usr/lib/dict/words") "/usr/lib/dict/words") | |
e29702dd | 363 | ((file-exists-p "/usr/share/dict/words") "/usr/share/dict/words") |
007852e0 RS |
364 | ((file-exists-p "/sys/dict") "/sys/dict") |
365 | (t "/usr/dict/words")) | |
366 | "*Alternate dictionary for spelling help.") | |
367 | ||
368 | (defvar ispell-complete-word-dict ispell-alternate-dictionary | |
369 | "*Dictionary used for word completion.") | |
370 | ||
e8649704 | 371 | (defvar ispell-grep-command "egrep" |
007852e0 RS |
372 | "Name of the grep command for search processes.") |
373 | ||
374 | (defvar ispell-grep-options "-i" | |
a9210a53 | 375 | "String of options to use when running the program in `ispell-grep-command'. |
007852e0 RS |
376 | Should probably be \"-i\" or \"-e\". |
377 | Some machines (like the NeXT) don't support \"-i\"") | |
378 | ||
e8649704 | 379 | (defvar ispell-look-command "look" |
007852e0 | 380 | "Name of the look command for search processes. |
a9210a53 | 381 | This must be an absolute file name.") |
007852e0 RS |
382 | |
383 | (defvar ispell-look-p (file-exists-p ispell-look-command) | |
e29702dd | 384 | "*Non-nil means use `look' rather than `grep'. |
a9210a53 | 385 | Default is based on whether `look' seems to be available.") |
007852e0 RS |
386 | |
387 | (defvar ispell-have-new-look nil | |
a9210a53 | 388 | "*Non-nil means use the `-r' option (regexp) when running `look'.") |
007852e0 RS |
389 | |
390 | (defvar ispell-look-options (if ispell-have-new-look "-dfr" "-df") | |
a9210a53 | 391 | "String of command options for `ispell-look-command'.") |
007852e0 RS |
392 | |
393 | (defvar ispell-use-ptys-p nil | |
a9210a53 RS |
394 | "When non-nil, Emacs uses ptys to communicate with Ispell. |
395 | When nil, Emacs uses pipes.") | |
007852e0 RS |
396 | |
397 | (defvar ispell-following-word nil | |
a9210a53 RS |
398 | "*Non-nil means `ispell-word' checks the word around or after point. |
399 | Otherwise `ispell-word' checks the preceding word.") | |
007852e0 | 400 | |
4b03da72 | 401 | (defvar ispell-help-in-bufferp nil |
a9210a53 RS |
402 | "*Non-nil means display interactive keymap help in a buffer. |
403 | Otherwise use the minibuffer.") | |
007852e0 RS |
404 | |
405 | (defvar ispell-quietly nil | |
a9210a53 | 406 | "*Non-nil means suppress messages in `ispell-word'.") |
007852e0 RS |
407 | |
408 | (defvar ispell-format-word (function upcase) | |
4b03da72 RS |
409 | "*Formatting function for displaying word being spell checked. |
410 | The function must take one string argument and return a string.") | |
007852e0 | 411 | |
d38e5dbe | 412 | ;;;###autoload |
007852e0 | 413 | (defvar ispell-personal-dictionary nil |
e29702dd KH |
414 | "*File name of your personal spelling dictionary, or nil. |
415 | If nil, the default personal dictionary, \"~/.ispell_DICTNAME\" is used, | |
416 | where DICTNAME is the name of your default dictionary.") | |
007852e0 RS |
417 | |
418 | (defvar ispell-silently-savep nil | |
a9210a53 | 419 | "*When non-nil, save the personal dictionary without confirmation.") |
007852e0 RS |
420 | |
421 | ;;; This variable contains the current dictionary being used if the ispell | |
422 | ;;; process is running. Otherwise it contains the global default. | |
423 | (defvar ispell-dictionary nil | |
424 | "If non-nil, a dictionary to use instead of the default one. | |
a9210a53 RS |
425 | This is passed to the ispell process using the `-d' switch and is |
426 | used as key in `ispell-dictionary-alist' (which see). | |
007852e0 | 427 | |
a9210a53 | 428 | You should set this variable before your first use of Emacs spell-checking |
e29702dd KH |
429 | commands in the Emacs session, or else use the \\[ispell-change-dictionary] |
430 | command to change it. Otherwise, this variable only takes effect in a newly | |
a9210a53 | 431 | started Ispell process.") |
007852e0 | 432 | |
4b03da72 | 433 | (defvar ispell-extra-args nil |
a9210a53 | 434 | "*If non-nil, a list of extra switches to pass to the Ispell program. |
4b03da72 RS |
435 | For example, '(\"-W\" \"3\") to cause it to accept all 1-3 character |
436 | words as correct. See also `ispell-dictionary-alist', which may be used | |
437 | for language-specific arguments.") | |
438 | ||
d38e5dbe RS |
439 | ;;; The preparation of the menu bar menu must be autoloaded |
440 | ;;; because otherwise this file gets autoloaded every time Emacs starts | |
441 | ;;; so that it can set up the menus and determine keyboard equivalents. | |
8ce8687e | 442 | |
d38e5dbe RS |
443 | ;;;###autoload |
444 | (defvar ispell-dictionary-alist-1 ; sk 9-Aug-1991 18:28 | |
007852e0 | 445 | '((nil ; default (english.aff) |
99b11016 | 446 | "[A-Za-z]" "[^A-Za-z]" "[']" nil ("-B") nil) |
007852e0 | 447 | ("english" ; make english explicitly selectable |
99b11016 | 448 | "[A-Za-z]" "[^A-Za-z]" "[']" nil ("-B") nil) |
e29702dd KH |
449 | ("british" ; british version |
450 | "[A-Za-z]" "[^A-Za-z]" "[']" nil ("-B" "-d" "british") nil) | |
007852e0 | 451 | ("deutsch" ; deutsch.aff |
e29702dd | 452 | "[a-zA-Z\"]" "[^a-zA-Z\"]" "[']" t ("-C") "~tex") |
007852e0 RS |
453 | ("deutsch8" |
454 | "[a-zA-Z\304\326\334\344\366\337\374]" | |
455 | "[^a-zA-Z\304\326\334\344\366\337\374]" | |
e29702dd KH |
456 | "[']" t ("-C" "-d" "deutsch") "~latin1") |
457 | ("nederlands" ; nederlands.aff | |
458 | "[A-Za-z\300-\305\307\310-\317\322-\326\331-\334\340-\345\347\350-\357\361\362-\366\371-\374]" | |
459 | "[^A-Za-z\300-\305\307\310-\317\322-\326\331-\334\340-\345\347\350-\357\361\362-\366\371-\374]" | |
460 | "[']" t ("-C") nil) | |
007852e0 RS |
461 | ("nederlands8" ; dutch8.aff |
462 | "[A-Za-z\300-\305\307\310-\317\322-\326\331-\334\340-\345\347\350-\357\361\362-\366\371-\374]" | |
463 | "[^A-Za-z\300-\305\307\310-\317\322-\326\331-\334\340-\345\347\350-\357\361\362-\366\371-\374]" | |
d38e5dbe RS |
464 | "[']" t ("-C") nil))) |
465 | ||
466 | ;;;###autoload | |
467 | (defvar ispell-dictionary-alist-2 | |
468 | '(("svenska" ;7 bit swedish mode | |
007852e0 | 469 | "[A-Za-z}{|\\133\\135\\\\]" "[^A-Za-z}{|\\133\\135\\\\]" |
e29702dd | 470 | "[']" nil ("-C") nil) |
007852e0 RS |
471 | ("svenska8" ;8 bit swedish mode |
472 | "[A-Za-z\345\344\366\305\304\366]" "[^A-Za-z\345\344\366\305\304\366]" | |
e29702dd KH |
473 | "[']" nil ("-C" "-d" "svenska") "~list") ; Add `"-T" "list"' instead? |
474 | ("francais7" | |
475 | "[A-Za-z]" "[^A-Za-z]" "[`'^---]" t nil nil) | |
476 | ("francais" ; francais.aff | |
477 | "[A-Za-z\300\302\306\307\310\311\312\313\316\317\324\331\333\334\340\342\347\350\351\352\353\356\357\364\371\373\374]" | |
478 | "[^A-Za-z\300\302\306\307\310\311\312\313\316\317\324\331\333\334\340\342\347\350\351\352\353\356\357\364\371\373\374]" | |
479 | "[---']" t nil "~list") | |
480 | ("francais-tex" ; francais.aff | |
481 | "[A-Za-z\300\302\306\307\310\311\312\313\316\317\324\331\333\334\340\342\347\350\351\352\353\356\357\364\371\373\374\\]" | |
482 | "[^A-Za-z\300\302\306\307\310\311\312\313\316\317\324\331\333\334\340\342\347\350\351\352\353\356\357\364\371\373\374\\]" | |
483 | "[---'^`\"]" t nil "~tex") | |
4b03da72 | 484 | ("dansk" ; dansk.aff |
007852e0 | 485 | "[A-Z\306\330\305a-z\346\370\345]" "[^A-Z\306\330\305a-z\346\370\345]" |
e29702dd | 486 | "" nil ("-C") nil) |
d38e5dbe RS |
487 | )) |
488 | ||
12e53d2e | 489 | |
d38e5dbe RS |
490 | ;;; ispell-dictionary-alist is set up from two subvariables above |
491 | ;;; to avoid having very long lines in loaddefs.el. | |
492 | ;;;###autoload | |
493 | (defvar ispell-dictionary-alist | |
494 | (append ispell-dictionary-alist-1 ispell-dictionary-alist-2) | |
007852e0 RS |
495 | "An alist of dictionaries and their associated parameters. |
496 | ||
497 | Each element of this list is also a list: | |
498 | ||
4b03da72 | 499 | \(DICTIONARY-NAME CASECHARS NOT-CASECHARS OTHERCHARS MANY-OTHERCHARS-P |
007852e0 RS |
500 | ISPELL-ARGS EXTENDED-CHARACTER-MODE\) |
501 | ||
a9210a53 | 502 | DICTIONARY-NAME is a possible value of variable `ispell-dictionary', nil |
007852e0 RS |
503 | means the default dictionary. |
504 | ||
505 | CASECHARS is a regular expression of valid characters that comprise a | |
506 | word. | |
507 | ||
508 | NOT-CASECHARS is the opposite regexp of CASECHARS. | |
509 | ||
510 | OTHERCHARS is a regular expression of other characters that are valid | |
511 | in word constructs. Otherchars cannot be adjacent to each other in a | |
512 | word, nor can they begin or end a word. This implies we can't check | |
513 | \"Stevens'\" as a correct possessive and other correct formations. | |
514 | ||
515 | Hint: regexp syntax requires the hyphen to be declared first here. | |
516 | ||
517 | MANY-OTHERCHARS-P is non-nil if many otherchars are to be allowed in a | |
518 | word instead of only one. | |
519 | ||
520 | ISPELL-ARGS is a list of additional arguments passed to the ispell | |
521 | subprocess. | |
522 | ||
523 | EXTENDED-CHARACTER-MODE should be used when dictionaries are used which | |
e29702dd | 524 | have been configured in an Ispell affix file. (For example, umlauts |
007852e0 | 525 | can be encoded as \\\"a, a\\\", \"a, ...) Defaults are ~tex and ~nroff |
a9210a53 RS |
526 | in English. This has the same effect as the command-line `-T' option. |
527 | The buffer Major Mode controls Ispell's parsing in tex or nroff mode, | |
007852e0 RS |
528 | but the dictionary can control the extended character mode. |
529 | Both defaults can be overruled in a buffer-local fashion. See | |
a9210a53 | 530 | `ispell-parsing-keyword' for details on this. |
007852e0 RS |
531 | |
532 | Note that the CASECHARS and OTHERCHARS slots of the alist should | |
533 | contain the same character set as casechars and otherchars in the | |
534 | language.aff file \(e.g., english.aff\).") | |
535 | ||
d38e5dbe | 536 | ;;;###autoload |
e29702dd | 537 | (defvar ispell-menu-map nil "Key map for ispell menu") |
007852e0 | 538 | |
d38e5dbe | 539 | ;;;###autoload |
e29702dd KH |
540 | (defvar ispell-menu-lucid nil "Spelling menu for Lucid Emacs.") |
541 | ||
542 | ;;; Break out lucid menu and split into several calls to avoid having | |
543 | ;;; long lines in loaddefs.el. Detect need off following constant. | |
12e53d2e | 544 | |
d38e5dbe | 545 | ;;;###autoload |
e29702dd KH |
546 | (defconst ispell-menu-map-needed ; make sure this is not Lucid Emacs |
547 | (and (not ispell-menu-map) | |
d38e5dbe RS |
548 | ;;; This is commented out because it fails in Emacs. |
549 | ;;; due to the fact that menu-bar is loaded much later than loaddefs. | |
550 | ;;; ;; make sure this isn't Lucid Emacs | |
551 | ;;; (featurep 'menu-bar) | |
8ce8687e | 552 | (not (string-match "Lucid" emacs-version)))) |
e29702dd | 553 | |
d38e5dbe RS |
554 | ;;; Set up dictionary |
555 | ;;;###autoload | |
12e53d2e RS |
556 | (if ispell-menu-map-needed |
557 | (let ((dicts (reverse (cons (cons "default" nil) ispell-dictionary-alist))) | |
558 | name) | |
12e53d2e | 559 | (setq ispell-menu-map (make-sparse-keymap "Spell")) |
e29702dd | 560 | ;; add the dictionaries to the bottom of the list. |
12e53d2e RS |
561 | (while dicts |
562 | (setq name (car (car dicts)) | |
563 | dicts (cdr dicts)) | |
564 | (if (stringp name) | |
565 | (define-key ispell-menu-map (vector (intern name)) | |
566 | (cons (concat "Select " (capitalize name)) | |
567 | (list 'lambda () '(interactive) | |
568 | (list 'ispell-change-dictionary name)))))))) | |
569 | ||
e29702dd | 570 | ;;; define commands in menu in opposite order you want them to appear. |
d38e5dbe | 571 | ;;;###autoload |
12e53d2e RS |
572 | (if ispell-menu-map-needed |
573 | (progn | |
12e53d2e RS |
574 | (define-key ispell-menu-map [ispell-change-dictionary] |
575 | '("Change Dictionary" . ispell-change-dictionary)) | |
576 | (define-key ispell-menu-map [ispell-kill-ispell] | |
577 | '("Kill Process" . ispell-kill-ispell)) | |
578 | (define-key ispell-menu-map [ispell-pdict-save] | |
1335d078 | 579 | '("Save Dictionary" . (lambda () (interactive) (ispell-pdict-save t t)))) |
12e53d2e RS |
580 | (define-key ispell-menu-map [ispell-complete-word] |
581 | '("Complete Word" . ispell-complete-word)) | |
582 | (define-key ispell-menu-map [ispell-complete-word-interior-frag] | |
583 | '("Complete Word Frag" . ispell-complete-word-interior-frag)))) | |
584 | ||
d38e5dbe | 585 | ;;;###autoload |
12e53d2e RS |
586 | (if ispell-menu-map-needed |
587 | (progn | |
588 | (define-key ispell-menu-map [ispell-continue] | |
589 | '("Continue Check" . ispell-continue)) | |
12e53d2e RS |
590 | (define-key ispell-menu-map [ispell-word] |
591 | '("Check Word" . ispell-word)) | |
81b328e5 KH |
592 | (define-key ispell-menu-map [ispell-region] |
593 | '("Check Region" . ispell-region)) | |
12e53d2e | 594 | (define-key ispell-menu-map [ispell-buffer] |
60d48874 RS |
595 | '("Check Buffer" . ispell-buffer)))) |
596 | ||
d38e5dbe | 597 | ;;;###autoload |
60d48874 RS |
598 | (if ispell-menu-map-needed |
599 | (progn | |
12e53d2e RS |
600 | (define-key ispell-menu-map [ispell-message] |
601 | '("Check Message" . ispell-message)) | |
602 | (define-key ispell-menu-map [ispell-help] | |
e29702dd | 603 | ;; use (x-popup-menu last-nonmenu-event(list "" ispell-help-list)) ? |
12e53d2e | 604 | '("Help" . (lambda () (interactive) (describe-function 'ispell-help)))) |
e29702dd KH |
605 | (put 'ispell-region 'menu-enable 'mark-active) |
606 | (fset 'ispell-menu-map (symbol-value 'ispell-menu-map)))) | |
607 | ||
608 | ;;; Xemacs version 19 | |
609 | (if (and (string-lessp "19" emacs-version) | |
610 | (string-match "Lucid" emacs-version)) | |
611 | (let ((dicts (cons (cons "default" nil) ispell-dictionary-alist)) | |
612 | (current-menubar (or current-menubar default-menubar)) | |
613 | (menu | |
614 | '(["Help" (describe-function 'ispell-help) t] | |
615 | ;;["Help" (popup-menu ispell-help-list) t] | |
616 | ["Check Message" ispell-message t] | |
617 | ["Check Buffer" ispell-buffer t] | |
618 | ["Check Word" ispell-word t] | |
619 | ["Check Region" ispell-region (or (not zmacs-regions) (mark))] | |
620 | ["Continue Check" ispell-continue t] | |
621 | ["Complete Word Frag"ispell-complete-word-interior-frag t] | |
622 | ["Complete Word" ispell-complete-word t] | |
623 | ["Kill Process" ispell-kill-ispell t] | |
624 | "-" | |
1335d078 | 625 | ["Save Dictionary" (ispell-pdict-save t t) t] |
e29702dd KH |
626 | ["Change Dictionary" ispell-change-dictionary t])) |
627 | name) | |
628 | (while dicts | |
629 | (setq name (car (car dicts)) | |
630 | dicts (cdr dicts)) | |
631 | (if (stringp name) | |
632 | (setq menu (append menu | |
633 | (list | |
634 | (vector (concat "Select " (capitalize name)) | |
635 | (list 'ispell-change-dictionary name) | |
636 | t)))))) | |
637 | (setq ispell-menu-lucid menu) | |
638 | (if current-menubar | |
639 | (progn | |
640 | (delete-menu-item '("Edit" "Spell")) ; in case already defined | |
641 | (add-menu '("Edit") "Spell" ispell-menu-lucid))))) | |
007852e0 RS |
642 | |
643 | ||
644 | ;;; ********************************************************************** | |
645 | ;;; The following are used by ispell, and should not be changed. | |
646 | ;;; ********************************************************************** | |
647 | ||
648 | ||
e29702dd | 649 | ;;; The version must be 3.1 or greater for this version of ispell.el |
8ce8687e | 650 | ;;; There is an incompatibility between version 3.1.12 and lower versions. |
e29702dd | 651 | (defconst ispell-required-version '("3.1." 12) |
007852e0 | 652 | "Ispell versions with which this version of ispell.el is known to work.") |
e29702dd KH |
653 | (defvar ispell-offset 1 |
654 | "Offset that maps protocol differences between ispell 3.1 versions.") | |
007852e0 RS |
655 | |
656 | (defun ispell-get-casechars () | |
657 | (nth 1 (assoc ispell-dictionary ispell-dictionary-alist))) | |
658 | (defun ispell-get-not-casechars () | |
659 | (nth 2 (assoc ispell-dictionary ispell-dictionary-alist))) | |
660 | (defun ispell-get-otherchars () | |
661 | (nth 3 (assoc ispell-dictionary ispell-dictionary-alist))) | |
662 | (defun ispell-get-many-otherchars-p () | |
663 | (nth 4 (assoc ispell-dictionary ispell-dictionary-alist))) | |
664 | (defun ispell-get-ispell-args () | |
665 | (nth 5 (assoc ispell-dictionary ispell-dictionary-alist))) | |
666 | (defun ispell-get-extended-character-mode () | |
667 | (nth 6 (assoc ispell-dictionary ispell-dictionary-alist))) | |
668 | ||
669 | (defvar ispell-process nil | |
a9210a53 | 670 | "The process object for Ispell.") |
007852e0 RS |
671 | |
672 | (defvar ispell-pdict-modified-p nil | |
a9210a53 | 673 | "Non-nil means personal dictionary has modifications to be saved.") |
007852e0 RS |
674 | |
675 | ;;; If you want to save the dictionary when quitting, must do so explicitly. | |
e29702dd KH |
676 | ;;; When non-nil, the spell session is terminated. |
677 | ;;; When numeric, contains cursor location in buffer, and cursor remains there. | |
a9210a53 | 678 | (defvar ispell-quit nil) |
007852e0 RS |
679 | |
680 | (defvar ispell-filter nil | |
a9210a53 | 681 | "Output filter from piped calls to Ispell.") |
007852e0 RS |
682 | |
683 | (defvar ispell-filter-continue nil | |
a9210a53 | 684 | "Control variable for Ispell filter function.") |
007852e0 RS |
685 | |
686 | (defvar ispell-process-directory nil | |
a9210a53 | 687 | "The directory where `ispell-process' was started.") |
007852e0 RS |
688 | |
689 | (defvar ispell-query-replace-marker (make-marker) | |
a9210a53 | 690 | "Marker for `query-replace' processing.") |
007852e0 RS |
691 | |
692 | (defvar ispell-checking-message nil | |
693 | "Non-nil when we're checking a mail message") | |
694 | ||
695 | (defconst ispell-choices-buffer "*Choices*") | |
696 | ||
a9210a53 | 697 | (defvar ispell-overlay nil "Overlay variable for Ispell highlighting.") |
007852e0 RS |
698 | |
699 | ;;; *** Buffer Local Definitions *** | |
700 | ||
701 | ;;; This is the local dictionary to use. When nil the default dictionary will | |
702 | ;;; be used. Do not redefine default value or it will override the global! | |
703 | (defvar ispell-local-dictionary nil | |
a9210a53 | 704 | "If non-nil, a dictionary to use for Ispell commands in this buffer. |
e29702dd | 705 | The value must be a string dictionary name in `ispell-dictionary-alist'. |
a9210a53 RS |
706 | This variable becomes buffer-local when set in any fashion. |
707 | ||
708 | Setting ispell-local-dictionary to a value has the same effect as | |
709 | calling \\[ispell-change-dictionary] with that value. This variable | |
710 | is automatically set when defined in the file with either | |
711 | `ispell-dictionary-keyword' or the Local Variable syntax.") | |
007852e0 RS |
712 | |
713 | (make-variable-buffer-local 'ispell-local-dictionary) | |
714 | ||
715 | ;; Use default directory, unless locally set. | |
716 | (set-default 'ispell-local-dictionary nil) | |
717 | ||
718 | (defconst ispell-words-keyword "LocalWords: " | |
719 | "The keyword for local oddly-spelled words to accept. | |
720 | The keyword will be followed by any number of local word spellings. | |
721 | There can be multiple of these keywords in the file.") | |
722 | ||
723 | (defconst ispell-dictionary-keyword "Local IspellDict: " | |
724 | "The keyword for local dictionary definitions. | |
725 | There should be only one dictionary keyword definition per file, and it | |
a9210a53 | 726 | should be followed by a correct dictionary name in `ispell-dictionary-alist'.") |
007852e0 RS |
727 | |
728 | (defconst ispell-parsing-keyword "Local IspellParsing: " | |
a9210a53 | 729 | "The keyword for overriding default Ispell parsing. |
4b03da72 RS |
730 | Determined by the buffer's major mode and extended-character mode as well as |
731 | the default dictionary. | |
007852e0 RS |
732 | |
733 | The above keyword string should be followed by `latex-mode' or | |
734 | `nroff-mode' to put the current buffer into the desired parsing mode. | |
735 | ||
736 | Extended character mode can be changed for this buffer by placing | |
737 | a `~' followed by an extended-character mode -- such as `~.tex'.") | |
738 | ||
1335d078 RS |
739 | (defvar ispell-skip-sgml nil |
740 | "Skips spell checking of SGML tags and entity references when non-nil. | |
8ce8687e | 741 | This variable is set when major-mode is sgml-mode or html-mode.") |
1335d078 | 742 | |
007852e0 | 743 | (defvar ispell-local-pdict ispell-personal-dictionary |
4b03da72 | 744 | "A buffer local variable containing the current personal dictionary. |
a9210a53 | 745 | If non-nil, the value must be a string, which is a file name. |
4b03da72 | 746 | |
a9210a53 RS |
747 | If you specify a personal dictionary for the current buffer which is |
748 | different from the current personal dictionary, the effect is similar | |
749 | to calling \\[ispell-change-dictionary]. This variable is automatically | |
750 | set when defined in the file with either `ispell-pdict-keyword' or the | |
751 | local variable syntax.") | |
007852e0 RS |
752 | |
753 | (make-variable-buffer-local 'ispell-local-pdict) | |
754 | ||
755 | (defconst ispell-pdict-keyword "Local IspellPersDict: " | |
756 | "The keyword for defining buffer local dictionaries.") | |
757 | ||
758 | (defvar ispell-buffer-local-name nil | |
759 | "Contains the buffer name if local word definitions were used. | |
760 | Ispell is then restarted because the local words could conflict.") | |
761 | ||
762 | (defvar ispell-parser 'use-mode-name | |
763 | "*Indicates whether ispell should parse the current buffer as TeX Code. | |
a9210a53 | 764 | Special value `use-mode-name' tries to guess using the name of major-mode. |
007852e0 RS |
765 | Default parser is 'nroff. |
766 | Currently the only other valid parser is 'tex. | |
767 | ||
768 | You can set this variable in hooks in your init file -- eg: | |
769 | ||
e29702dd | 770 | (add-hook 'tex-mode-hook (function (lambda () (setq ispell-parser 'tex))))") |
007852e0 RS |
771 | |
772 | (defvar ispell-region-end (make-marker) | |
773 | "Marker that allows spelling continuations.") | |
774 | ||
0349bab6 RS |
775 | (defvar ispell-check-only nil |
776 | "If non-nil, `ispell-word' does not try to correct the word.") | |
007852e0 | 777 | |
e29702dd | 778 | |
007852e0 RS |
779 | ;;; ********************************************************************** |
780 | ;;; ********************************************************************** | |
781 | ||
782 | ||
1335d078 RS |
783 | (and (string-lessp "19" emacs-version) |
784 | (not (boundp 'epoch::version)) | |
785 | (defalias 'ispell 'ispell-buffer)) | |
4b03da72 | 786 | |
8ce8687e RS |
787 | ;;;###autoload |
788 | (define-key global-map "\M-$" 'ispell-word) | |
a870f917 | 789 | |
007852e0 | 790 | ;;;###autoload |
9e7ad89a | 791 | (defun ispell-word (&optional following quietly continue) |
007852e0 | 792 | "Check spelling of word under or before the cursor. |
a9210a53 | 793 | If the word is not found in dictionary, display possible corrections |
e29702dd | 794 | in a window allowing you to choose one. |
a9210a53 | 795 | |
4b03da72 | 796 | With a prefix argument (or if CONTINUE is non-nil), |
9e7ad89a | 797 | resume interrupted spell-checking of a buffer or region. |
a9210a53 | 798 | |
4b03da72 | 799 | If optional argument FOLLOWING is non-nil or if `ispell-following-word' |
007852e0 | 800 | is non-nil when called interactively, then the following word |
3ee3ac77 | 801 | \(rather than preceding\) is checked when the cursor is not over a word. |
4b03da72 | 802 | When the optional argument QUIETLY is non-nil or `ispell-quietly' is non-nil |
007852e0 RS |
803 | when called interactively, non-corrective messages are suppressed. |
804 | ||
4b03da72 | 805 | Word syntax described by `ispell-dictionary-alist' (which see). |
007852e0 RS |
806 | |
807 | This will check or reload the dictionary. Use \\[ispell-change-dictionary] | |
3ee3ac77 | 808 | or \\[ispell-region] to update the Ispell process." |
9e7ad89a RS |
809 | (interactive (list nil nil current-prefix-arg)) |
810 | (if continue | |
811 | (ispell-continue) | |
812 | (if (interactive-p) | |
813 | (setq following ispell-following-word | |
814 | quietly ispell-quietly)) | |
e29702dd | 815 | (ispell-accept-buffer-local-defs) ; use the correct dictionary |
9e7ad89a | 816 | (let ((cursor-location (point)) ; retain cursor location |
9e7ad89a RS |
817 | (word (ispell-get-word following)) |
818 | start end poss replace) | |
819 | ;; destructure return word info list. | |
820 | (setq start (car (cdr word)) | |
821 | end (car (cdr (cdr word))) | |
822 | word (car word)) | |
823 | ||
824 | ;; now check spelling of word. | |
825 | (or quietly | |
826 | (message "Checking spelling of %s..." | |
827 | (funcall ispell-format-word word))) | |
9e7ad89a RS |
828 | (process-send-string ispell-process "%\n") ;put in verbose mode |
829 | (process-send-string ispell-process (concat "^" word "\n")) | |
830 | ;; wait until ispell has processed word | |
831 | (while (progn | |
832 | (accept-process-output ispell-process) | |
833 | (not (string= "" (car ispell-filter))))) | |
834 | ;;(process-send-string ispell-process "!\n") ;back to terse mode. | |
835 | (setq ispell-filter (cdr ispell-filter)) | |
836 | (if (listp ispell-filter) | |
837 | (setq poss (ispell-parse-output (car ispell-filter)))) | |
838 | (cond ((eq poss t) | |
839 | (or quietly | |
3ee3ac77 | 840 | (message "%s is correct" (funcall ispell-format-word word)))) |
9e7ad89a RS |
841 | ((stringp poss) |
842 | (or quietly | |
843 | (message "%s is correct because of root %s" | |
844 | (funcall ispell-format-word word) | |
845 | (funcall ispell-format-word poss)))) | |
846 | ((null poss) (message "Error in ispell process")) | |
0349bab6 RS |
847 | (ispell-check-only ; called from ispell minor mode. |
848 | (beep)) | |
9e7ad89a | 849 | (t ; prompt for correct word. |
29aec366 RS |
850 | (save-window-excursion |
851 | (setq replace (ispell-command-loop | |
852 | (car (cdr (cdr poss))) | |
853 | (car (cdr (cdr (cdr poss)))) | |
e29702dd | 854 | (car poss) start end))) |
9e7ad89a RS |
855 | (cond ((equal 0 replace) |
856 | (ispell-add-per-file-word-list (car poss))) | |
857 | (replace | |
9e7ad89a RS |
858 | (setq word (if (atom replace) replace (car replace)) |
859 | cursor-location (+ (- (length word) (- end start)) | |
860 | cursor-location)) | |
e29702dd KH |
861 | (if (not (equal word (car poss))) |
862 | (progn | |
863 | (delete-region start end) | |
864 | (insert word))) | |
9e7ad89a RS |
865 | (if (not (atom replace)) ; recheck spelling of replacement |
866 | (progn | |
867 | (goto-char cursor-location) | |
868 | (ispell-word following quietly))))) | |
869 | (if (get-buffer ispell-choices-buffer) | |
870 | (kill-buffer ispell-choices-buffer)))) | |
871 | (goto-char cursor-location) ; return to original location | |
872 | (ispell-pdict-save ispell-silently-savep) | |
873 | (if ispell-quit (setq ispell-quit nil))))) | |
007852e0 RS |
874 | |
875 | ||
876 | (defun ispell-get-word (following &optional extra-otherchars) | |
877 | "Return the word for spell-checking according to ispell syntax. | |
3ee3ac77 | 878 | If optional argument FOLLOWING is non-nil or if `ispell-following-word' |
007852e0 | 879 | is non-nil when called interactively, then the following word |
e29702dd | 880 | \(rather than preceding\) is checked when the cursor is not over a word. |
4b03da72 | 881 | Optional second argument contains otherchars that can be included in word |
007852e0 RS |
882 | many times. |
883 | ||
4b03da72 | 884 | Word syntax described by `ispell-dictionary-alist' (which see)." |
007852e0 RS |
885 | (let* ((ispell-casechars (ispell-get-casechars)) |
886 | (ispell-not-casechars (ispell-get-not-casechars)) | |
887 | (ispell-otherchars (ispell-get-otherchars)) | |
888 | (ispell-many-otherchars-p (ispell-get-many-otherchars-p)) | |
889 | (word-regexp (concat ispell-casechars | |
890 | "+\\(" | |
891 | ispell-otherchars | |
892 | "?" | |
893 | (if extra-otherchars | |
894 | (concat extra-otherchars "?")) | |
895 | ispell-casechars | |
896 | "+\\)" | |
897 | (if (or ispell-many-otherchars-p | |
898 | extra-otherchars) | |
899 | "*" "?"))) | |
900 | did-it-once | |
901 | start end word) | |
902 | ;; find the word | |
903 | (if (not (looking-at ispell-casechars)) | |
904 | (if following | |
905 | (re-search-forward ispell-casechars (point-max) t) | |
906 | (re-search-backward ispell-casechars (point-min) t))) | |
907 | ;; move to front of word | |
908 | (re-search-backward ispell-not-casechars (point-min) 'start) | |
909 | (while (and (or (looking-at ispell-otherchars) | |
910 | (and extra-otherchars (looking-at extra-otherchars))) | |
911 | (not (bobp)) | |
912 | (or (not did-it-once) | |
913 | ispell-many-otherchars-p)) | |
914 | (if (and extra-otherchars (looking-at extra-otherchars)) | |
915 | (progn | |
916 | (backward-char 1) | |
917 | (if (looking-at ispell-casechars) | |
918 | (re-search-backward ispell-not-casechars (point-min) 'move))) | |
919 | (setq did-it-once t) | |
920 | (backward-char 1) | |
921 | (if (looking-at ispell-casechars) | |
922 | (re-search-backward ispell-not-casechars (point-min) 'move) | |
923 | (backward-char -1)))) | |
924 | ;; Now mark the word and save to string. | |
925 | (or (re-search-forward word-regexp (point-max) t) | |
926 | (error "No word found to check!")) | |
927 | (setq start (match-beginning 0) | |
928 | end (point) | |
929 | word (buffer-substring start end)) | |
930 | (list word start end))) | |
931 | ||
932 | ||
933 | ;;; Global ispell-pdict-modified-p is set by ispell-command-loop and | |
934 | ;;; tracks changes in the dictionary. The global may either be | |
935 | ;;; a value or a list, whose value is the state of whether the | |
936 | ;;; dictionary needs to be saved. | |
937 | ||
938 | (defun ispell-pdict-save (&optional no-query force-save) | |
939 | "Check to see if the personal dictionary has been modified. | |
3ee3ac77 | 940 | If so, ask if it needs to be saved." |
007852e0 RS |
941 | (interactive (list ispell-silently-savep t)) |
942 | (if (and ispell-pdict-modified-p (listp ispell-pdict-modified-p)) | |
943 | (setq ispell-pdict-modified-p (car ispell-pdict-modified-p))) | |
944 | (if (or ispell-pdict-modified-p force-save) | |
945 | (if (or no-query (y-or-n-p "Personal dictionary modified. Save? ")) | |
1335d078 RS |
946 | (progn |
947 | (process-send-string ispell-process "#\n") | |
948 | (message "Personal dictionary saved.")))) | |
007852e0 RS |
949 | ;; unassert variable, even if not saved to avoid questioning. |
950 | (setq ispell-pdict-modified-p nil)) | |
951 | ||
952 | ||
29aec366 | 953 | (defun ispell-command-loop (miss guess word start end) |
007852e0 RS |
954 | "Display possible corrections from list MISS. |
955 | GUESS lists possibly valid affix construction of WORD. | |
956 | Returns nil to keep word. | |
4b03da72 RS |
957 | Returns 0 to insert locally into buffer-local dictionary. |
958 | Returns string for new chosen word. | |
959 | Returns list for new replacement word (will be rechecked). | |
29aec366 | 960 | Highlights the word, which is assumed to run from START to END. |
3ee3ac77 RS |
961 | Global `ispell-pdict-modified-p' becomes a list where the only value |
962 | indicates whether the dictionary has been modified when option `a' or `i' is | |
007852e0 | 963 | used." |
e29702dd KH |
964 | (let ((textbuf (current-buffer)) |
965 | (count ?0) | |
966 | (line 2) | |
967 | (max-lines (- (window-height) 4)) ; assure 4 context lines. | |
968 | (choices miss) | |
969 | (window-min-height (min window-min-height | |
970 | ispell-choices-win-default-height)) | |
971 | (command-characters '( ? ?i ?a ?A ?r ?R ?? ?x ?X ?q ?l ?u ?m )) | |
972 | (skipped 0) | |
973 | char num result textwin highlighted) | |
974 | ||
975 | ;; setup the *Choices* buffer with valid data. | |
976 | (save-excursion | |
977 | (set-buffer (get-buffer-create ispell-choices-buffer)) | |
8ce8687e | 978 | (setq mode-line-format (concat "-- %b -- word: " word)) |
e29702dd KH |
979 | (erase-buffer) |
980 | (if guess | |
981 | (progn | |
982 | (insert "Affix rules generate and capitalize " | |
983 | "this word as shown below:\n\t") | |
984 | (while guess | |
985 | (if (> (+ 4 (current-column) (length (car guess))) | |
986 | (window-width)) | |
987 | (progn | |
988 | (insert "\n\t") | |
989 | (setq line (1+ line)))) | |
990 | (insert (car guess) " ") | |
991 | (setq guess (cdr guess))) | |
992 | (insert "\nUse option `i' if this is a correct composition" | |
993 | " from the derivative root.\n") | |
994 | (setq line (+ line (if choices 3 2))))) | |
995 | (while (and choices | |
996 | (< (if (> (+ 7 (current-column) (length (car choices)) | |
997 | (if (> count ?~) 3 0)) | |
998 | (window-width)) | |
999 | (progn | |
1000 | (insert "\n") | |
1001 | (setq line (1+ line))) | |
1002 | line) | |
1003 | max-lines)) | |
1004 | ;; not so good if there are over 20 or 30 options, but then, if | |
1005 | ;; there are that many you don't want to scan them all anyway... | |
1006 | (while (memq count command-characters) ; skip command characters. | |
1007 | (setq count (1+ count) | |
1008 | skipped (1+ skipped))) | |
1009 | (insert "(" count ") " (car choices) " ") | |
1010 | (setq choices (cdr choices) | |
1011 | count (1+ count))) | |
1012 | (setq count (- count ?0 skipped))) | |
1013 | ||
1014 | ;; Assure word is visible | |
1015 | (if (not (pos-visible-in-window-p end)) | |
1016 | (sit-for 0)) | |
1017 | ;; Display choices for misspelled word. | |
1018 | (let ((choices-window (get-buffer-window ispell-choices-buffer))) | |
1019 | (if choices-window | |
1335d078 RS |
1020 | (if (= line (window-height choices-window)) |
1021 | (select-window choices-window) | |
1022 | ;; *Choices* window changed size. Adjust the choices window | |
1023 | ;; without scrolling the spelled window when possible | |
1024 | (let ((window-line (- line (window-height choices-window))) | |
1025 | (visible (progn (forward-line -1) (point)))) | |
1026 | (if (< line ispell-choices-win-default-height) | |
1027 | (setq window-line (+ window-line | |
1028 | (- ispell-choices-win-default-height | |
1029 | line)))) | |
1030 | (move-to-window-line 0) | |
1031 | (forward-line window-line) | |
1032 | (set-window-start (selected-window) | |
1033 | (if (> (point) visible) visible (point))) | |
1034 | (goto-char end) | |
1035 | (select-window (previous-window)) ; *Choices* window | |
1036 | (enlarge-window window-line))) | |
e29702dd KH |
1037 | ;; Overlay *Choices* window when it isn't showing |
1038 | (ispell-overlay-window (max line ispell-choices-win-default-height))) | |
1039 | (switch-to-buffer ispell-choices-buffer) | |
1040 | (goto-char (point-min))) | |
1041 | ||
1042 | (select-window (setq textwin (next-window))) | |
1043 | ||
1044 | ;; highlight word, protecting current buffer status | |
29aec366 | 1045 | (unwind-protect |
e29702dd | 1046 | (progn |
29aec366 | 1047 | (if ispell-highlight-p |
e29702dd KH |
1048 | (ispell-highlight-spelling-error start end t)) |
1049 | ;; Loop until a valid choice is made. | |
29aec366 RS |
1050 | (while |
1051 | (eq | |
1052 | t | |
1053 | (setq | |
1054 | result | |
1055 | (progn | |
1056 | (undo-boundary) | |
1057 | (message (concat "C-h or ? for more options; SPC to leave " | |
1058 | "unchanged, Character to replace word")) | |
1059 | (let ((inhibit-quit t)) | |
1060 | (setq char (if (fboundp 'read-char-exclusive) | |
1061 | (read-char-exclusive) | |
1062 | (read-char)) | |
1063 | skipped 0) | |
1064 | (if (or quit-flag (= char ?\C-g)) ; C-g is like typing X | |
1065 | (setq char ?X | |
1066 | quit-flag nil))) | |
1067 | ;; Adjust num to array offset skipping command characters. | |
1068 | (let ((com-chars command-characters)) | |
1069 | (while com-chars | |
1070 | (if (and (> (car com-chars) ?0) (< (car com-chars) char)) | |
1071 | (setq skipped (1+ skipped))) | |
1072 | (setq com-chars (cdr com-chars))) | |
1073 | (setq num (- char ?0 skipped))) | |
1074 | ||
1075 | (cond | |
e29702dd | 1076 | ((= char ? ) nil) ; accept word this time only |
29aec366 RS |
1077 | ((= char ?i) ; accept and insert word into pers dict |
1078 | (process-send-string ispell-process (concat "*" word "\n")) | |
1079 | (setq ispell-pdict-modified-p '(t)) ; dictionary modified! | |
1080 | nil) | |
1081 | ((or (= char ?a) (= char ?A)) ; accept word without insert | |
1082 | (process-send-string ispell-process (concat "@" word "\n")) | |
1083 | (if (null ispell-pdict-modified-p) | |
1084 | (setq ispell-pdict-modified-p | |
1085 | (list ispell-pdict-modified-p))) | |
1086 | (if (= char ?A) 0)) ; return 0 for ispell-add buffer-local | |
1087 | ((or (= char ?r) (= char ?R)) ; type in replacement | |
1088 | (if (or (= char ?R) ispell-query-replace-choices) | |
1089 | (list (read-string "Query-replacement for: " word) t) | |
1090 | (cons (read-string "Replacement for: " word) nil))) | |
1091 | ((or (= char ??) (= char help-char) (= char ?\C-h)) | |
1092 | (ispell-help) | |
1093 | t) | |
1094 | ;; Quit and move point back. | |
1095 | ((= char ?x) | |
1096 | (ispell-pdict-save ispell-silently-savep) | |
1097 | (message "Exited spell-checking") | |
1098 | (setq ispell-quit t) | |
1099 | nil) | |
1100 | ;; Quit and preserve point. | |
1101 | ((= char ?X) | |
1102 | (ispell-pdict-save ispell-silently-savep) | |
1103 | (message | |
1104 | (substitute-command-keys | |
1105 | (concat "Spell-checking suspended;" | |
1106 | " use C-u \\[ispell-word] to resume"))) | |
1107 | (setq ispell-quit (max (point-min) | |
1108 | (- (point) (length word)))) | |
1109 | nil) | |
1110 | ((= char ?q) | |
1111 | (if (y-or-n-p "Really kill Ispell process? ") | |
1112 | (progn | |
1113 | (ispell-kill-ispell t) ; terminate process. | |
1114 | (setq ispell-quit (or (not ispell-checking-message) | |
1115 | (point)) | |
1116 | ispell-pdict-modified-p nil)) | |
e29702dd | 1117 | t)) ; continue if they don't quit. |
29aec366 RS |
1118 | ((= char ?l) |
1119 | (let ((new-word (read-string | |
1120 | "Lookup string (`*' is wildcard): " | |
1121 | word)) | |
1122 | (new-line 2)) | |
1123 | (if new-word | |
007852e0 | 1124 | (progn |
29aec366 RS |
1125 | (save-excursion |
1126 | (set-buffer (get-buffer-create | |
1127 | ispell-choices-buffer)) | |
1128 | (erase-buffer) | |
1129 | (setq count ?0 | |
1130 | skipped 0 | |
8ce8687e RS |
1131 | mode-line-format (concat |
1132 | "-- %b -- word: " | |
1133 | new-word) | |
29aec366 RS |
1134 | miss (lookup-words new-word) |
1135 | choices miss) | |
1136 | (while (and choices ; adjust choices window. | |
1137 | (< (if (> (+ 7 (current-column) | |
1138 | (length (car choices)) | |
1139 | (if (> count ?~) 3 0)) | |
1140 | (window-width)) | |
1141 | (progn | |
1142 | (insert "\n") | |
1143 | (setq new-line | |
1144 | (1+ new-line))) | |
1145 | new-line) | |
1146 | max-lines)) | |
1147 | (while (memq count command-characters) | |
1148 | (setq count (1+ count) | |
1149 | skipped (1+ skipped))) | |
1150 | (insert "(" count ") " (car choices) " ") | |
1151 | (setq choices (cdr choices) | |
1152 | count (1+ count))) | |
1153 | (setq count (- count ?0 skipped))) | |
1154 | (select-window (previous-window)) | |
1335d078 RS |
1155 | (if (and (/= new-line line) |
1156 | (> (max line new-line) | |
1157 | ispell-choices-win-default-height)) | |
1158 | (let* ((minh ispell-choices-win-default-height) | |
1159 | (gr-bl (if (< line minh) ; blanks | |
1160 | (- minh line) | |
1161 | 0)) | |
1162 | (shr-bl (if (< new-line minh) ; blanks | |
1163 | (- minh new-line) | |
1164 | 0))) | |
29aec366 | 1165 | (if (> new-line line) |
1335d078 RS |
1166 | (enlarge-window (- new-line line gr-bl)) |
1167 | (shrink-window (- line new-line shr-bl))) | |
29aec366 RS |
1168 | (setq line new-line))) |
1169 | (select-window (next-window))))) | |
1170 | t) ; reselect from new choices | |
1171 | ((= char ?u) | |
1172 | (process-send-string ispell-process | |
1173 | (concat "*" (downcase word) "\n")) | |
1174 | (setq ispell-pdict-modified-p '(t)) ; dictionary modified! | |
1175 | nil) | |
1176 | ((= char ?m) ; type in what to insert | |
1177 | (process-send-string | |
1178 | ispell-process (concat "*" (read-string "Insert: " word) | |
1179 | "\n")) | |
1180 | (setq ispell-pdict-modified-p '(t)) | |
1181 | (cons word nil)) | |
1182 | ((and (>= num 0) (< num count)) | |
1183 | (if ispell-query-replace-choices ; Query replace flag | |
1184 | (list (nth num miss) 'query-replace) | |
1185 | (nth num miss))) | |
1186 | ((= char ?\C-l) | |
1187 | (redraw-display) t) | |
1188 | ((= char ?\C-r) | |
1189 | (save-window-excursion (recursive-edit)) t) | |
1190 | ((= char ?\C-z) | |
1191 | (funcall (key-binding "\C-z")) | |
1192 | t) | |
1193 | (t (ding) t)))))) | |
1194 | result) | |
e29702dd KH |
1195 | ;; protected |
1196 | (if ispell-highlight-p ; unhighlight | |
1197 | (save-window-excursion | |
1198 | (select-window textwin) | |
1199 | (ispell-highlight-spelling-error start end)))))) | |
007852e0 RS |
1200 | |
1201 | ||
829b9e73 | 1202 | ;;;###autoload |
007852e0 | 1203 | (defun ispell-help () |
3ee3ac77 | 1204 | "Display a list of the options available when a misspelling is encountered. |
007852e0 RS |
1205 | |
1206 | Selections are: | |
1207 | ||
1208 | DIGIT: Replace the word with a digit offered in the *Choices* buffer. | |
a9210a53 RS |
1209 | SPC: Accept word this time. |
1210 | `i': Accept word and insert into private dictionary. | |
1211 | `a': Accept word for this session. | |
1212 | `A': Accept word and place in `buffer-local dictionary'. | |
1213 | `r': Replace word with typed-in value. Rechecked. | |
1214 | `R': Replace word with typed-in value. Query-replaced in buffer. Rechecked. | |
1215 | `?': Show these commands. | |
1216 | `x': Exit spelling buffer. Move cursor to original point. | |
1217 | `X': Exit spelling buffer. Leaves cursor at the current point, and permits | |
007852e0 | 1218 | the aborted check to be completed later. |
a9210a53 RS |
1219 | `q': Quit spelling session (Kills ispell process). |
1220 | `l': Look up typed-in replacement in alternate dictionary. Wildcards okay. | |
1221 | `u': Like `i', but the word is lower-cased first. | |
1222 | `m': Like `i', but allows one to include dictionary completion information. | |
1223 | `C-l': redraws screen | |
1224 | `C-r': recursive edit | |
1225 | `C-z': suspend emacs or iconify frame" | |
007852e0 | 1226 | |
4b03da72 RS |
1227 | (let ((help-1 (concat "[r/R]eplace word; [a/A]ccept for this session; " |
1228 | "[i]nsert into private dictionary")) | |
1229 | (help-2 (concat "[l]ook a word up in alternate dictionary; " | |
1230 | "e[x/X]it; [q]uit session")) | |
1231 | (help-3 (concat "[u]ncapitalized insert into dictionary. " | |
1232 | "Type 'C-h d ispell-help' for more help"))) | |
007852e0 RS |
1233 | (save-window-excursion |
1234 | (if ispell-help-in-bufferp | |
1235 | (progn | |
1236 | (ispell-overlay-window 4) | |
1237 | (switch-to-buffer (get-buffer-create "*Ispell Help*")) | |
1238 | (insert (concat help-1 "\n" help-2 "\n" help-3)) | |
1239 | (sit-for 5) | |
1240 | (kill-buffer "*Ispell Help*")) | |
1241 | (select-window (minibuffer-window)) | |
4b03da72 | 1242 | ;;(enlarge-window 2) |
007852e0 RS |
1243 | (erase-buffer) |
1244 | (cond ((string-match "Lucid" emacs-version) | |
1245 | (message help-3) | |
1246 | (enlarge-window 1) | |
1247 | (message help-2) | |
1248 | (enlarge-window 1) | |
4b03da72 RS |
1249 | (message help-1) |
1250 | (goto-char (point-min))) | |
007852e0 | 1251 | (t |
4b03da72 | 1252 | (if (string-lessp "19" emacs-version) |
007852e0 RS |
1253 | (message nil)) |
1254 | (enlarge-window 2) | |
1255 | (insert (concat help-1 "\n" help-2 "\n" help-3)))) | |
1256 | (sit-for 5) | |
1257 | (erase-buffer))))) | |
1258 | ||
1259 | ||
1260 | (defun lookup-words (word &optional lookup-dict) | |
1261 | "Look up word in word-list dictionary. | |
4b03da72 RS |
1262 | A `*' serves as a wild card. If no wild cards, `look' is used if it exists. |
1263 | Otherwise the variable `ispell-grep-command' contains the command used to | |
1264 | search for the words (usually egrep). | |
1265 | ||
3ee3ac77 | 1266 | Optional second argument contains the dictionary to use; the default is |
4b03da72 | 1267 | `ispell-alternate-dictionary'." |
007852e0 RS |
1268 | ;; We don't use the filter for this function, rather the result is written |
1269 | ;; into a buffer. Hence there is no need to save the filter values. | |
1270 | (if (null lookup-dict) | |
1271 | (setq lookup-dict ispell-alternate-dictionary)) | |
1272 | ||
1273 | (let* ((process-connection-type ispell-use-ptys-p) | |
1274 | (wild-p (string-match "\\*" word)) | |
1275 | (look-p (and ispell-look-p ; Only use look for an exact match. | |
1276 | (or ispell-have-new-look (not wild-p)))) | |
1277 | (ispell-grep-buffer (get-buffer-create "*Ispell-Temp*")) ; result buf | |
1278 | (prog (if look-p ispell-look-command ispell-grep-command)) | |
1279 | (args (if look-p ispell-look-options ispell-grep-options)) | |
1280 | status results loc) | |
1281 | (unwind-protect | |
1282 | (save-window-excursion | |
1283 | (message "Starting \"%s\" process..." (file-name-nondirectory prog)) | |
1284 | (set-buffer ispell-grep-buffer) | |
1285 | (if look-p | |
1286 | nil | |
1287 | ;; convert * to .* | |
1288 | (insert "^" word "$") | |
1289 | (while (search-backward "*" nil t) (insert ".")) | |
1290 | (setq word (buffer-string)) | |
1291 | (erase-buffer)) | |
1292 | (setq status (call-process prog nil t nil args word lookup-dict)) | |
1293 | ;; grep returns status 1 and no output when word not found, which | |
1294 | ;; is a perfectly normal thing. | |
1295 | (if (stringp status) | |
1296 | (setq results (cons (format "error: %s exited with signal %s" | |
1297 | (file-name-nondirectory prog) status) | |
1298 | results)) | |
1299 | ;; else collect words into `results' in FIFO order | |
1300 | (goto-char (point-max)) | |
1301 | ;; assure we've ended with \n | |
1302 | (or (bobp) (= (preceding-char) ?\n) (insert ?\n)) | |
1303 | (while (not (bobp)) | |
1304 | (setq loc (point)) | |
1305 | (forward-line -1) | |
1306 | (setq results (cons (buffer-substring (point) (1- loc)) | |
1307 | results))))) | |
1308 | ;; protected | |
1309 | (kill-buffer ispell-grep-buffer) | |
1310 | (if (and results (string-match ".+: " (car results))) | |
1311 | (error "%s error: %s" ispell-grep-command (car results)))) | |
1312 | results)) | |
1313 | ||
1314 | ||
1315 | ;;; "ispell-filter" is a list of output lines from the generating function. | |
1316 | ;;; Each full line (ending with \n) is a separate item on the list. | |
1317 | ;;; "output" can contain multiple lines, part of a line, or both. | |
1318 | ;;; "start" and "end" are used to keep bounds on lines when "output" contains | |
1319 | ;;; multiple lines. | |
1320 | ;;; "ispell-filter-continue" is true when we have received only part of a | |
1321 | ;;; line as output from a generating function ("output" did not end with \n) | |
a7acbbe4 | 1322 | ;;; THIS FUNCTION WILL FAIL IF THE PROCESS OUTPUT DOESN'T END WITH \n! |
007852e0 RS |
1323 | ;;; This is the case when a process dies or fails. The default behavior |
1324 | ;;; in this case treats the next input received as fresh input. | |
1325 | ||
1326 | (defun ispell-filter (process output) | |
1327 | "Output filter function for ispell, grep, and look." | |
1328 | (let ((start 0) | |
1329 | (continue t) | |
1330 | end) | |
1331 | (while continue | |
1332 | (setq end (string-match "\n" output start)) ; get text up to the newline. | |
1333 | ;; If we get out of sync and ispell-filter-continue is asserted when we | |
1334 | ;; are not continuing, treat the next item as a separate list. When | |
1335 | ;; ispell-filter-continue is asserted, ispell-filter *should* always be a | |
1336 | ;; list! | |
1337 | ||
1338 | ;; Continue with same line (item)? | |
1339 | (if (and ispell-filter-continue ispell-filter (listp ispell-filter)) | |
1340 | ;; Yes. Add it to the prev item | |
1341 | (setcar ispell-filter | |
1342 | (concat (car ispell-filter) (substring output start end))) | |
1343 | ;; No. This is a new line and item. | |
1344 | (setq ispell-filter | |
1345 | (cons (substring output start end) ispell-filter))) | |
1346 | (if (null end) | |
1347 | ;; We've completed reading the output, but didn't finish the line. | |
1348 | (setq ispell-filter-continue t continue nil) | |
1349 | ;; skip over newline, this line complete. | |
1350 | (setq ispell-filter-continue nil end (1+ end)) | |
1351 | (if (= end (length output)) ; No more lines in output | |
1352 | (setq continue nil) ; so we can exit the filter. | |
1353 | (setq start end)))))) ; else move start to next line of input | |
1354 | ||
1355 | ||
1356 | ;;; This function destroys the mark location if it is in the word being | |
1357 | ;;; highlighted. | |
4b03da72 | 1358 | (defun ispell-highlight-spelling-error-generic (start end &optional highlight) |
3ee3ac77 RS |
1359 | "Highlight the word from START to END with a kludge using `inverse-video'. |
1360 | When the optional third arg HIGHLIGHT is set, the word is highlighted; | |
1361 | otherwise it is displayed normally." | |
007852e0 RS |
1362 | (let ((modified (buffer-modified-p)) ; don't allow this fn to modify buffer |
1363 | (buffer-read-only nil) ; Allow highlighting read-only buffers. | |
1364 | (text (buffer-substring start end)) ; Save highlight region | |
1365 | (inhibit-quit t) ; inhibit interrupt processing here. | |
29aec366 | 1366 | (buffer-undo-list t)) ; don't clutter the undo list. |
007852e0 | 1367 | (delete-region start end) |
a7acbbe4 | 1368 | (insert-char ? (- end start)) ; minimize amount of redisplay |
007852e0 RS |
1369 | (sit-for 0) ; update display |
1370 | (if highlight (setq inverse-video (not inverse-video))) ; toggle video | |
1371 | (delete-region start end) ; delete whitespace | |
1372 | (insert text) ; insert text in inverse video. | |
1373 | (sit-for 0) ; update display showing inverse video. | |
1374 | (if highlight (setq inverse-video (not inverse-video))) ; toggle video | |
1375 | (set-buffer-modified-p modified))) ; don't modify if flag not set. | |
1376 | ||
1377 | ||
4b03da72 | 1378 | (defun ispell-highlight-spelling-error-lucid (start end &optional highlight) |
3ee3ac77 | 1379 | "Highlight the word from START to END using `isearch-highlight'. |
e29702dd | 1380 | When the optional third arg HIGHLIGHT is set, the word is highlighted, |
007852e0 RS |
1381 | otherwise it is displayed normally." |
1382 | (if highlight | |
1383 | (isearch-highlight start end) | |
1384 | (isearch-dehighlight t)) | |
1385 | ;;(sit-for 0) | |
1386 | ) | |
1387 | ||
1388 | ||
4b03da72 | 1389 | (defun ispell-highlight-spelling-error-overlay (start end &optional highlight) |
3ee3ac77 RS |
1390 | "Highlight the word from START to END using overlays. |
1391 | When the optional third arg HIGHLIGHT is set, the word is highlighted | |
1392 | otherwise it is displayed normally. | |
4b03da72 | 1393 | |
a9210a53 | 1394 | The variable `ispell-highlight-face' selects the face to use for highlighting." |
007852e0 RS |
1395 | (if highlight |
1396 | (progn | |
1397 | (setq ispell-overlay (make-overlay start end)) | |
1398 | (overlay-put ispell-overlay 'face ispell-highlight-face)) | |
1399 | (delete-overlay ispell-overlay))) | |
1400 | ||
1401 | ||
e29702dd | 1402 | (defun ispell-highlight-spelling-error (start end &optional highlight) |
29aec366 RS |
1403 | (cond |
1404 | ((string-match "Lucid" emacs-version) | |
1405 | (ispell-highlight-spelling-error-lucid start end highlight)) | |
e29702dd KH |
1406 | ((and (string-lessp "19" emacs-version) |
1407 | (featurep 'faces) window-system) | |
29aec366 RS |
1408 | (ispell-highlight-spelling-error-overlay start end highlight)) |
1409 | (t (ispell-highlight-spelling-error-generic start end highlight)))) | |
007852e0 | 1410 | |
e29702dd | 1411 | |
007852e0 | 1412 | (defun ispell-overlay-window (height) |
3ee3ac77 RS |
1413 | "Create a window covering the top HEIGHT lines of the current window. |
1414 | Ensure that the line above point is still visible but otherwise avoid | |
045dbcbc | 1415 | scrolling the current window. Leave the new window selected." |
007852e0 RS |
1416 | (save-excursion |
1417 | (let ((oldot (save-excursion (forward-line -1) (point))) | |
1418 | (top (save-excursion (move-to-window-line height) (point)))) | |
1419 | ;; If line above old point (line starting at olddot) would be | |
1420 | ;; hidden by new window, scroll it to just below new win | |
1421 | ;; otherwise set top line of other win so it doesn't scroll. | |
1422 | (if (< oldot top) (setq top oldot)) | |
4b03da72 RS |
1423 | ;; NB: Lemacs 19.9 bug: If a window of size N (N includes the mode |
1424 | ;; line) is demanded, the last line is not visible. | |
1425 | ;; At least this happens on AIX 3.2, lemacs w/ Motif, font 9x15. | |
1426 | ;; So we increment the height for this case. | |
1427 | (if (string-match "19\.9.*Lucid" (emacs-version)) | |
1428 | (setq height (1+ height))) | |
007852e0 RS |
1429 | (split-window nil height) |
1430 | (set-window-start (next-window) top)))) | |
1431 | ||
1432 | ||
1433 | ;;; Should we add a compound word match return value? | |
1434 | (defun ispell-parse-output (output) | |
a9210a53 RS |
1435 | "Parse the OUTPUT string from Ispell and return: |
1436 | 1: t for an exact match. | |
007852e0 RS |
1437 | 2: A string containing the root word for a match via suffix removal. |
1438 | 3: A list of possible correct spellings of the format: | |
3ee3ac77 RS |
1439 | '(\"ORIGINAL-WORD\" OFFSET MISS-LIST GUESS-LIST) |
1440 | ORIGINAL-WORD is a string of the possibly misspelled word. | |
1441 | OFFSET is an integer giving the line offset of the word. | |
1442 | MISS-LIST and GUESS-LIST are possibly null lists of guesses and misses." | |
007852e0 RS |
1443 | (cond |
1444 | ((string= output "") t) ; for startup with pipes... | |
1445 | ((string= output "*") t) ; exact match | |
1446 | ((string= output "-") t) ; compound word match | |
1447 | ((string= (substring output 0 1) "+") ; found cuz of root word | |
1448 | (substring output 2)) ; return root word | |
1449 | (t ; need to process &, ?, and #'s | |
1450 | (let ((type (substring output 0 1)) ; &, ?, or # | |
1451 | (original-word (substring output 2 (string-match " " output 2))) | |
1452 | (cur-count 0) ; contains number of misses + guesses | |
1453 | count miss-list guess-list offset) | |
1454 | (setq output (substring output (match-end 0))) ; skip over misspelling | |
1455 | (if (string= type "#") | |
1456 | (setq count 0) ; no misses for type # | |
1457 | (setq count (string-to-int output) ; get number of misses. | |
1458 | output (substring output (1+ (string-match " " output 1))))) | |
1459 | (setq offset (string-to-int output)) | |
1460 | (if (string= type "#") ; No miss or guess list. | |
1461 | (setq output nil) | |
1462 | (setq output (substring output (1+ (string-match " " output 1))))) | |
1463 | (while output | |
1464 | (let ((end (string-match ", \\|\\($\\)" output))) ; end of miss/guess. | |
1465 | (setq cur-count (1+ cur-count)) | |
1466 | (if (> cur-count count) | |
1467 | (setq guess-list (cons (substring output 0 end) guess-list)) | |
1468 | (setq miss-list (cons (substring output 0 end) miss-list))) | |
1469 | (if (match-end 1) ; True only when at end of line. | |
1470 | (setq output nil) ; no more misses or guesses | |
1471 | (setq output (substring output (+ end 2)))))) | |
1472 | (list original-word offset miss-list guess-list))))) | |
1473 | ||
1474 | ||
1475 | (defun check-ispell-version () | |
1476 | ;; This is a little wasteful as we actually launch ispell twice: once | |
1477 | ;; to make sure it's the right version, and once for real. But people | |
1478 | ;; get confused by version mismatches *all* the time (and I've got the | |
1479 | ;; email to prove it) so I think this is worthwhile. And the -v[ersion] | |
1480 | ;; option is the only way I can think of to do this that works with | |
1481 | ;; all versions, since versions earlier than 3.0.09 didn't identify | |
1482 | ;; themselves on startup. | |
007852e0 | 1483 | (save-excursion |
1335d078 RS |
1484 | (let ((case-fold-search t) |
1485 | ;; avoid bugs when syntax of `.' changes in various default modes | |
1486 | (default-major-mode 'fundamental-mode) | |
1487 | status) | |
1488 | (set-buffer (get-buffer-create " *ispell-tmp*")) | |
1489 | (erase-buffer) | |
1490 | (setq status (call-process ispell-program-name nil t nil "-v")) | |
007852e0 | 1491 | (goto-char (point-min)) |
e29702dd KH |
1492 | (if (not (memq status '(0 nil))) |
1493 | (error "%s exited with %s %s" ispell-program-name | |
1494 | (if (stringp status) "signal" "code") status)) | |
1495 | (if (not (re-search-forward | |
1496 | (concat "\\b\\(" | |
1497 | (regexp-quote (car ispell-required-version)) | |
1498 | "\\)\\([0-9]*\\)\\b") | |
1499 | nil t)) | |
1500 | (error | |
1501 | "%s version %s* is required: try renaming ispell4.el to ispell.el" | |
1502 | ispell-program-name (car ispell-required-version)) | |
1503 | ;; check that it is the correct version. | |
1504 | (if (< (car (read-from-string (buffer-substring | |
1505 | (match-beginning 2) (match-end 2)))) | |
1506 | (car (cdr ispell-required-version))) | |
1507 | (setq ispell-offset 0))) | |
007852e0 RS |
1508 | (kill-buffer (current-buffer))))) |
1509 | ||
1510 | ||
1511 | (defun ispell-init-process () | |
3ee3ac77 | 1512 | "Check status of Ispell process and start if necessary." |
007852e0 RS |
1513 | (if (and ispell-process |
1514 | (eq (process-status ispell-process) 'run) | |
1515 | ;; If we're using a personal dictionary, assure | |
1516 | ;; we're in the same default directory! | |
1517 | (or (not ispell-personal-dictionary) | |
1518 | (equal ispell-process-directory default-directory))) | |
1519 | (setq ispell-filter nil ispell-filter-continue nil) | |
1520 | ;; may need to restart to select new personal dictionary. | |
1521 | (ispell-kill-ispell t) | |
3ee3ac77 | 1522 | (message "Starting new Ispell process...") |
007852e0 RS |
1523 | (sit-for 0) |
1524 | (check-ispell-version) | |
1525 | (setq ispell-process | |
1526 | (let ((process-connection-type ispell-use-ptys-p)) | |
1527 | (apply 'start-process | |
1528 | "ispell" nil ispell-program-name | |
1529 | "-a" ; accept single input lines | |
1530 | "-m" ; make root/affix combos not in dict | |
1531 | (let (args) | |
1532 | ;; Local dictionary becomes the global dictionary in use. | |
1533 | (if ispell-local-dictionary | |
1534 | (setq ispell-dictionary ispell-local-dictionary)) | |
1535 | (setq args (ispell-get-ispell-args)) | |
1536 | (if ispell-dictionary ; use specified dictionary | |
1537 | (setq args | |
1538 | (append (list "-d" ispell-dictionary) args))) | |
1539 | (if ispell-personal-dictionary ; use specified pers dict | |
1540 | (setq args | |
1541 | (append args | |
1542 | (list "-p" | |
1543 | (expand-file-name | |
1544 | ispell-personal-dictionary))))) | |
4b03da72 | 1545 | (setq args (append args ispell-extra-args)) |
007852e0 RS |
1546 | args))) |
1547 | ispell-filter nil | |
1548 | ispell-filter-continue nil | |
1549 | ispell-process-directory default-directory) | |
1550 | (set-process-filter ispell-process 'ispell-filter) | |
1551 | (accept-process-output ispell-process) ; Get version ID line | |
1552 | (cond ((null ispell-filter) | |
a8928dd2 | 1553 | (error "%s did not output version line" ispell-program-name)) |
01ea0e3b RS |
1554 | ((and |
1555 | (stringp (car ispell-filter)) | |
1556 | (if (string-match "warning: " (car ispell-filter)) | |
1557 | (progn | |
1558 | (accept-process-output ispell-process 5) ; 1st was warn msg. | |
1559 | (stringp (car ispell-filter))) | |
1560 | (null (cdr ispell-filter))) | |
1561 | (string-match "^@(#) " (car ispell-filter))) | |
007852e0 RS |
1562 | ;; got the version line as expected (we already know it's the right |
1563 | ;; version, so don't bother checking again.) | |
1564 | nil) | |
1565 | (t | |
1566 | ;; Otherwise, it must be an error message. Show the user. | |
1567 | ;; But first wait to see if some more output is going to arrive. | |
1568 | ;; Otherwise we get cool errors like "Can't open ". | |
1569 | (sleep-for 1) | |
1570 | (accept-process-output) | |
1571 | (error "%s" (mapconcat 'identity ispell-filter "\n")))) | |
1572 | (setq ispell-filter nil) ; Discard version ID line | |
1573 | (let ((extended-char-mode (ispell-get-extended-character-mode))) | |
1574 | (if extended-char-mode | |
1575 | (process-send-string ispell-process | |
1576 | (concat extended-char-mode "\n")))) | |
1577 | (process-kill-without-query ispell-process))) | |
1578 | ||
829b9e73 | 1579 | ;;;###autoload |
007852e0 | 1580 | (defun ispell-kill-ispell (&optional no-error) |
a9210a53 RS |
1581 | "Kill current Ispell process (so that you may start a fresh one). |
1582 | With NO-ERROR, just return non-nil if there was no Ispell running." | |
007852e0 RS |
1583 | (interactive) |
1584 | (if (not (and ispell-process | |
1585 | (eq (process-status ispell-process) 'run))) | |
1586 | (or no-error | |
1587 | (error "There is no ispell process running!")) | |
1588 | (kill-process ispell-process) | |
1589 | (setq ispell-process nil) | |
3ee3ac77 | 1590 | (message "Ispell process killed") |
007852e0 RS |
1591 | nil)) |
1592 | ||
1593 | ||
8ce8687e | 1594 | ;;; ispell-change-dictionary is set in some people's hooks. Maybe this should |
1335d078 RS |
1595 | ;;; call ispell-init-process rather than wait for a spell checking command? |
1596 | ||
007852e0 RS |
1597 | ;;;###autoload |
1598 | (defun ispell-change-dictionary (dict &optional arg) | |
a9210a53 | 1599 | "Change `ispell-dictionary' (q.v.) and kill old Ispell process. |
007852e0 RS |
1600 | A new one will be started as soon as necessary. |
1601 | ||
1602 | By just answering RET you can find out what the current dictionary is. | |
1603 | ||
1604 | With prefix argument, set the default directory." | |
1605 | (interactive | |
1606 | (list (completing-read | |
1607 | "Use new dictionary (RET for current, SPC to complete): " | |
1608 | (cons (cons "default" nil) ispell-dictionary-alist) nil t) | |
1609 | current-prefix-arg)) | |
1610 | (if (equal dict "default") (setq dict nil)) | |
1611 | ;; This relies on completing-read's bug of returning "" for no match | |
1612 | (cond ((equal dict "") | |
1613 | (message "Using %s dictionary" | |
1614 | (or ispell-local-dictionary ispell-dictionary "default"))) | |
1615 | ((and (equal dict ispell-dictionary) | |
1335d078 RS |
1616 | (or (null ispell-local-dictionary) |
1617 | (equal dict ispell-local-dictionary))) | |
007852e0 | 1618 | ;; Specified dictionary is the default already. No-op |
1335d078 RS |
1619 | (and (interactive-p) |
1620 | (message "No change, using %s dictionary" (or dict "default")))) | |
007852e0 RS |
1621 | (t ; reset dictionary! |
1622 | (if (assoc dict ispell-dictionary-alist) | |
1623 | (progn | |
1624 | (if (or arg (null dict)) ; set default dictionary | |
1625 | (setq ispell-dictionary dict)) | |
1626 | (if (null arg) ; set local dictionary | |
1627 | (setq ispell-local-dictionary dict))) | |
1628 | (error "Illegal dictionary: %s" dict)) | |
1629 | (ispell-kill-ispell t) | |
3ee3ac77 | 1630 | (message "(Next %sIspell command will use %s dictionary)" |
007852e0 RS |
1631 | (cond ((equal ispell-local-dictionary ispell-dictionary) |
1632 | "") | |
1633 | (arg "global ") | |
1634 | (t "local ")) | |
1635 | (or (if (or (equal ispell-local-dictionary ispell-dictionary) | |
1636 | (null arg)) | |
1637 | ispell-local-dictionary | |
1638 | ispell-dictionary) | |
1639 | "default"))))) | |
1640 | ||
1641 | ||
1642 | ;;; Spelling of comments are checked when ispell-check-comments is non-nil. | |
1643 | ||
1644 | ;;;###autoload | |
1645 | (defun ispell-region (reg-start reg-end) | |
1646 | "Interactively check a region for spelling errors." | |
1647 | (interactive "r") ; Don't flag errors on read-only bufs. | |
1648 | (ispell-accept-buffer-local-defs) ; set up dictionary, local words, etc. | |
1649 | (unwind-protect | |
4b03da72 | 1650 | (save-excursion |
e29702dd | 1651 | (message "Spell checking %s using %s dictionary..." |
4b03da72 | 1652 | (if (and (= reg-start (point-min)) (= reg-end (point-max))) |
e29702dd KH |
1653 | (buffer-name) "region") |
1654 | (or ispell-dictionary "default")) | |
1655 | ;; Returns cursor to original location. | |
4b03da72 | 1656 | (save-window-excursion |
4b03da72 | 1657 | (goto-char reg-start) |
1335d078 RS |
1658 | (let ((transient-mark-mode nil) |
1659 | ref-type) | |
4b03da72 RS |
1660 | (while (and (not ispell-quit) (< (point) reg-end)) |
1661 | (let ((start (point)) | |
1662 | (offset-change 0) | |
1663 | (end (save-excursion (end-of-line) (min (point) reg-end))) | |
1664 | (ispell-casechars (ispell-get-casechars)) | |
1665 | string) | |
1666 | (cond ; LOOK AT THIS LINE AND SKIP OR PROCESS | |
1667 | ((eolp) ; END OF LINE, just go to next line. | |
1668 | (forward-char 1)) | |
e29702dd | 1669 | ((and (null ispell-check-comments) ; SKIPPING COMMENTS |
4b03da72 RS |
1670 | comment-start ; skip comments that start on the line. |
1671 | (search-forward comment-start end t)) ; or found here. | |
1672 | (if (= (- (point) start) (length comment-start)) | |
1673 | ;; comment starts the line. Skip entire line or region | |
1674 | (if (string= "" comment-end) ; skip to next line | |
1675 | (beginning-of-line 2) ; or jump to comment end. | |
1676 | (search-forward comment-end reg-end 'limit)) | |
1677 | ;; Comment later in line. Check spelling before comment. | |
1678 | (let ((limit (- (point) (length comment-start)))) | |
1679 | (goto-char (1- limit)) | |
1680 | (if (looking-at "\\\\") ; "quoted" comment, don't skip | |
1681 | ;; quoted comment. Skip over comment-start | |
1682 | (if (= start (1- limit)) | |
1683 | (setq limit (+ limit (length comment-start))) | |
1684 | (setq limit (1- limit)))) | |
1685 | (goto-char start) | |
1686 | ;; Only check when "casechars" or math before comment | |
1687 | (if (or (re-search-forward ispell-casechars limit t) | |
1688 | (re-search-forward "[][()$]" limit t)) | |
1689 | (setq string | |
1690 | (concat "^" (buffer-substring start limit) | |
e29702dd KH |
1691 | "\n") |
1692 | offset-change (- offset-change ispell-offset))) | |
4b03da72 | 1693 | (goto-char limit)))) |
1335d078 RS |
1694 | ((looking-at "[---#@*+!%~^]") ; SKIP SPECIAL ISPELL CHARACTERS |
1695 | (forward-char 1)) | |
1696 | ((or (and ispell-skip-tib ; SKIP TIB REFERENCES OR SGML MARKUP | |
1697 | (re-search-forward ispell-tib-ref-beginning end t) | |
1698 | (setq ref-type 'tib)) | |
1699 | (and ispell-skip-sgml | |
1700 | (search-forward "[<&]" end t) | |
1701 | (setq ref-type 'sgml))) | |
1702 | (if (or (and (eq 'tib ref-type) ; tib tag is 2 chars. | |
1703 | (= (- (point) 2) start)) | |
1704 | (and (eq 'sgml ref-type) ; sgml skips 1 char. | |
1705 | (= (- (point) 1) start))) | |
1706 | ;; Skip to end of reference, not necessarily on this line | |
1707 | ;; Return an error if tib/sgml reference not found | |
1708 | (if (or | |
1709 | (and | |
1710 | (eq 'tib ref-type) | |
1711 | (not | |
1712 | (re-search-forward ispell-tib-ref-end reg-end t))) | |
1713 | (and (eq 'sgml ref-type) | |
1714 | (not (search-forward "[>;]" reg-end t)))) | |
4b03da72 RS |
1715 | (progn |
1716 | (ispell-pdict-save ispell-silently-savep) | |
1717 | (ding) | |
1718 | (message | |
1719 | (concat | |
1335d078 RS |
1720 | "Open tib or SGML command. Fix buffer or set " |
1721 | (if (eq 'tib ref-type) | |
1722 | "ispell-skip-tib" | |
1723 | "ispell-skip-sgml") | |
1724 | " to nil")) | |
4b03da72 RS |
1725 | ;; keep cursor at error location |
1726 | (setq ispell-quit (- (point) 2)))) | |
1335d078 RS |
1727 | ;; Check spelling between reference and start of the line. |
1728 | (let ((limit (- (point) (if (eq 'tib ref-type) 2 1)))) | |
4b03da72 RS |
1729 | (goto-char start) |
1730 | (if (or (re-search-forward ispell-casechars limit t) | |
1731 | (re-search-forward "[][()$]" limit t)) | |
1732 | (setq string | |
1733 | (concat "^" (buffer-substring start limit) | |
e29702dd KH |
1734 | "\n") |
1735 | offset-change (- offset-change ispell-offset))) | |
4b03da72 | 1736 | (goto-char limit)))) |
4b03da72 RS |
1737 | ((or (re-search-forward ispell-casechars end t) ; TEXT EXISTS |
1738 | (re-search-forward "[][()$]" end t)) ; or MATH COMMANDS | |
e29702dd KH |
1739 | (setq string (concat "^" (buffer-substring start end) "\n") |
1740 | offset-change (- offset-change ispell-offset)) | |
4b03da72 RS |
1741 | (goto-char end)) |
1742 | (t (beginning-of-line 2))) ; EMPTY LINE, skip it. | |
1743 | ||
1744 | (setq end (point)) ; "end" tracks end of region to check. | |
1745 | ||
1746 | (if string ; there is something to spell! | |
1747 | (let (poss) | |
1748 | ;; send string to spell process and get input. | |
1749 | (process-send-string ispell-process string) | |
1750 | (while (progn | |
1751 | (accept-process-output ispell-process) | |
1752 | ;; Last item of output contains a blank line. | |
1753 | (not (string= "" (car ispell-filter))))) | |
1754 | ;; parse all inputs from the stream one word at a time. | |
1755 | ;; Place in FIFO order and remove the blank item. | |
1756 | (setq ispell-filter (nreverse (cdr ispell-filter))) | |
1757 | (while (and (not ispell-quit) ispell-filter) | |
1758 | (setq poss (ispell-parse-output (car ispell-filter))) | |
1759 | (if (listp poss) ; spelling error occurred. | |
1760 | (let* ((word-start (+ start offset-change | |
1761 | (car (cdr poss)))) | |
1762 | (word-end (+ word-start | |
1763 | (length (car poss)))) | |
1764 | replace) | |
1765 | (goto-char word-start) | |
1766 | ;; Adjust the horizontal scroll & point | |
1767 | (ispell-horiz-scroll) | |
1768 | (goto-char word-end) | |
1769 | (ispell-horiz-scroll) | |
1770 | (goto-char word-start) | |
1771 | (ispell-horiz-scroll) | |
1772 | (if (/= word-end | |
1773 | (progn | |
1774 | (search-forward (car poss) word-end t) | |
1775 | (point))) | |
1776 | ;; This occurs due to filter pipe problems | |
1777 | (error | |
1778 | (concat "Ispell misalignment: word " | |
1779 | "`%s' point %d; please retry") | |
1780 | (car poss) word-start)) | |
a594e0e1 RS |
1781 | (if (not (pos-visible-in-window-p)) |
1782 | (sit-for 0)) | |
29aec366 RS |
1783 | (if ispell-keep-choices-win |
1784 | (setq replace | |
1785 | (ispell-command-loop | |
1786 | (car (cdr (cdr poss))) | |
1787 | (car (cdr (cdr (cdr poss)))) | |
e29702dd | 1788 | (car poss) word-start word-end)) |
29aec366 RS |
1789 | (save-window-excursion |
1790 | (setq replace | |
1791 | (ispell-command-loop | |
1792 | (car (cdr (cdr poss))) | |
1793 | (car (cdr (cdr (cdr poss)))) | |
e29702dd | 1794 | (car poss) word-start word-end)))) |
4b03da72 RS |
1795 | (cond |
1796 | ((and replace (listp replace)) | |
1797 | ;; REPLACEMENT WORD entered. Recheck line | |
1798 | ;; starting with the replacement word. | |
1799 | (setq ispell-filter nil | |
1800 | string (buffer-substring word-start | |
1801 | word-end)) | |
1802 | (let ((change (- (length (car replace)) | |
1803 | (length (car poss))))) | |
1804 | ;; adjust regions | |
1805 | (setq reg-end (+ reg-end change) | |
1806 | offset-change (+ offset-change | |
1807 | change))) | |
e29702dd KH |
1808 | (if (not (equal (car replace) (car poss))) |
1809 | (progn | |
1810 | (delete-region word-start word-end) | |
1811 | (insert (car replace)))) | |
4b03da72 RS |
1812 | ;; I only need to recheck typed-in replacements |
1813 | (if (not (eq 'query-replace | |
1814 | (car (cdr replace)))) | |
1815 | (backward-char (length (car replace)))) | |
1816 | (setq end (point)) ; reposition for recheck | |
1817 | ;; when second arg exists, query-replace, saving regions | |
1818 | (if (car (cdr replace)) | |
1819 | (unwind-protect | |
1820 | (save-window-excursion | |
1821 | (set-marker | |
1822 | ispell-query-replace-marker reg-end) | |
1823 | ;; Assume case-replace & | |
1824 | ;; case-fold-search correct? | |
1825 | (query-replace string (car replace) | |
1826 | t)) | |
1827 | (setq reg-end | |
1828 | (marker-position | |
1829 | ispell-query-replace-marker)) | |
1830 | (set-marker ispell-query-replace-marker | |
1831 | nil)))) | |
1832 | ((or (null replace) | |
1833 | (equal 0 replace)) ; ACCEPT/INSERT | |
1834 | (if (equal 0 replace) ; BUFFER-LOCAL DICT ADD | |
1835 | (setq reg-end | |
1836 | (ispell-add-per-file-word-list | |
1837 | (car poss) reg-end))) | |
1838 | ;; This avoids pointing out the word that was | |
1839 | ;; just accepted (via 'i' or 'a') if it follows | |
1840 | ;; on the same line. | |
1841 | ;; Redo check following the accepted word. | |
1842 | (if (and ispell-pdict-modified-p | |
1843 | (listp ispell-pdict-modified-p)) | |
1844 | ;; Word accepted. Recheck line. | |
1845 | (setq ispell-pdict-modified-p ; update flag | |
1846 | (car ispell-pdict-modified-p) | |
1847 | ispell-filter nil ; discontinue check | |
1848 | end word-start))) ; reposition loc. | |
1849 | (replace ; STRING REPLACEMENT for this word. | |
1850 | (delete-region word-start word-end) | |
1851 | (insert replace) | |
1852 | (let ((change (- (length replace) | |
1853 | (length (car poss))))) | |
1854 | (setq reg-end (+ reg-end change) | |
1855 | offset-change (+ offset-change change) | |
1856 | end (+ end change))))) | |
1857 | (if (not ispell-quit) | |
e29702dd KH |
1858 | (message |
1859 | (concat "Continuing spelling check using " | |
1860 | (or ispell-dictionary "default") | |
1861 | " dictionary..."))) | |
4b03da72 RS |
1862 | (sit-for 0))) |
1863 | ;; finished with line! | |
1864 | (setq ispell-filter (cdr ispell-filter))))) | |
1865 | (goto-char end))))) | |
1866 | (not ispell-quit)) | |
1867 | ;; protected | |
1868 | (if (get-buffer ispell-choices-buffer) | |
1869 | (kill-buffer ispell-choices-buffer)) | |
1870 | (if ispell-quit | |
1871 | (progn | |
1872 | ;; preserve or clear the region for ispell-continue. | |
1873 | (if (not (numberp ispell-quit)) | |
1874 | (set-marker ispell-region-end nil) | |
1875 | ;; Enable ispell-continue. | |
1876 | (set-marker ispell-region-end reg-end) | |
1877 | (goto-char ispell-quit)) | |
1878 | ;; Check for aborting | |
1879 | (if (and ispell-checking-message (numberp ispell-quit)) | |
1880 | (progn | |
1881 | (setq ispell-quit nil) | |
1882 | (error "Message send aborted."))) | |
1883 | (setq ispell-quit nil)) | |
1884 | (set-marker ispell-region-end nil) | |
1885 | ;; Only save if successful exit. | |
1886 | (ispell-pdict-save ispell-silently-savep) | |
1887 | (message "Spell-checking done")))) | |
007852e0 RS |
1888 | |
1889 | ||
1890 | ||
1891 | ;;;###autoload | |
4b03da72 | 1892 | (defun ispell-buffer () |
007852e0 RS |
1893 | "Check the current buffer for spelling errors interactively." |
1894 | (interactive) | |
1895 | (ispell-region (point-min) (point-max))) | |
1896 | ||
4b03da72 | 1897 | |
829b9e73 | 1898 | ;;;###autoload |
007852e0 RS |
1899 | (defun ispell-continue () |
1900 | (interactive) | |
1901 | "Continue a spelling session after making some changes." | |
1902 | (if (not (marker-position ispell-region-end)) | |
1903 | (message "No session to continue. Use 'X' command when checking!") | |
1904 | (if (not (equal (marker-buffer ispell-region-end) (current-buffer))) | |
1905 | (message "Must continue ispell from buffer %s" | |
1906 | (buffer-name (marker-buffer ispell-region-end))) | |
1907 | (ispell-region (point) (marker-position ispell-region-end))))) | |
1908 | ||
1909 | ||
1910 | ;;; Horizontal scrolling | |
4b03da72 RS |
1911 | (defun ispell-horiz-scroll () |
1912 | "Places point within the horizontal visibility of its window area." | |
007852e0 RS |
1913 | (if truncate-lines ; display truncating lines? |
1914 | ;; See if display needs to be scrolled. | |
1915 | (let ((column (- (current-column) (max (window-hscroll) 1)))) | |
1916 | (if (and (< column 0) (> (window-hscroll) 0)) | |
1917 | (scroll-right (max (- column) 10)) | |
1918 | (if (>= column (- (window-width) 2)) | |
1919 | (scroll-left (max (- column (window-width) -3) 10))))))) | |
1920 | ||
1921 | ||
1922 | ;;; Interactive word completion. | |
1923 | ;;; Forces "previous-word" processing. Do we want to make this selectable? | |
1924 | ||
1925 | ;;;###autoload | |
1926 | (defun ispell-complete-word (&optional interior-frag) | |
1927 | "Look up word before or under point in dictionary (see lookup-words command) | |
1928 | and try to complete it. If optional INTERIOR-FRAG is non-nil then the word | |
1929 | may be a character sequence inside of a word. | |
1930 | ||
1931 | Standard ispell choices are then available." | |
1932 | (interactive "P") | |
1933 | (let ((cursor-location (point)) | |
4b03da72 | 1934 | case-fold-search |
007852e0 RS |
1935 | (word (ispell-get-word nil "\\*")) ; force "previous-word" processing. |
1936 | start end possibilities replacement) | |
1937 | (setq start (car (cdr word)) | |
1938 | end (car (cdr (cdr word))) | |
1939 | word (car word) | |
1940 | possibilities | |
1941 | (or (string= word "") ; Will give you every word | |
1942 | (lookup-words (concat (if interior-frag "*") word "*") | |
1943 | ispell-complete-word-dict))) | |
1944 | (cond ((eq possibilities t) | |
1945 | (message "No word to complete")) | |
1946 | ((null possibilities) | |
1947 | (message "No match for \"%s\"" word)) | |
1948 | (t ; There is a modification... | |
4b03da72 RS |
1949 | (cond ; Try and respect case of word. |
1950 | ((string-match "^[^A-Z]+$" word) | |
1951 | (setq possibilities (mapcar 'downcase possibilities))) | |
1952 | ((string-match "^[^a-z]+$" word) | |
1953 | (setq possibilities (mapcar 'upcase possibilities))) | |
1954 | ((string-match "^[A-Z]" word) | |
1955 | (setq possibilities (mapcar 'capitalize possibilities)))) | |
29aec366 RS |
1956 | (save-window-excursion |
1957 | (setq replacement | |
1958 | (ispell-command-loop possibilities nil word start end))) | |
007852e0 RS |
1959 | (cond |
1960 | ((equal 0 replacement) ; BUFFER-LOCAL ADDITION | |
1961 | (ispell-add-per-file-word-list word)) | |
1962 | (replacement ; REPLACEMENT WORD | |
1963 | (delete-region start end) | |
1964 | (setq word (if (atom replacement) replacement (car replacement)) | |
1965 | cursor-location (+ (- (length word) (- end start)) | |
1966 | cursor-location)) | |
1967 | (insert word) | |
1968 | (if (not (atom replacement)) ; recheck spelling of replacement. | |
1969 | (progn | |
1970 | (goto-char cursor-location) | |
1971 | (ispell-word nil t))))) | |
1972 | (if (get-buffer ispell-choices-buffer) | |
1973 | (kill-buffer ispell-choices-buffer)))) | |
1974 | (ispell-pdict-save ispell-silently-savep) | |
1975 | (goto-char cursor-location))) | |
1976 | ||
1977 | ||
1978 | ;;;###autoload | |
1979 | (defun ispell-complete-word-interior-frag () | |
4b03da72 | 1980 | "Completes word matching character sequence inside a word." |
007852e0 RS |
1981 | (interactive) |
1982 | (ispell-complete-word t)) | |
1983 | ||
e29702dd | 1984 | |
0349bab6 RS |
1985 | ;;; ********************************************************************** |
1986 | ;;; Ispell Minor Mode | |
1987 | ;;; ********************************************************************** | |
1988 | ||
1989 | (defvar ispell-minor-mode nil | |
1990 | "Non-nil if Ispell minor mode is enabled.") | |
1991 | ;; Variable indicating that ispell minor mode is active. | |
1992 | (make-variable-buffer-local 'ispell-minor-mode) | |
1993 | ||
1994 | (or (assq 'ispell-minor-mode minor-mode-alist) | |
1995 | (setq minor-mode-alist | |
1996 | (cons '(ispell-minor-mode " Spell") minor-mode-alist))) | |
1997 | ||
1998 | (defvar ispell-minor-keymap | |
1999 | (let ((map (make-sparse-keymap))) | |
2000 | (define-key map " " 'ispell-minor-check) | |
2001 | (define-key map "\r" 'ispell-minor-check) | |
2002 | map) | |
2003 | "Keymap used for Ispell minor mode.") | |
2004 | ||
2005 | (or (not (boundp 'minor-mode-map-alist)) | |
2006 | (assoc 'ispell-minor-mode minor-mode-map-alist) | |
2007 | (setq minor-mode-map-alist | |
2008 | (cons (cons 'ispell-minor-mode ispell-minor-keymap) | |
2009 | minor-mode-map-alist))) | |
2010 | ||
2011 | ;;;###autoload | |
2012 | (defun ispell-minor-mode (&optional arg) | |
2013 | "Toggle Ispell minor mode. | |
2014 | With prefix arg, turn Ispell minor mode on iff arg is positive. | |
2015 | ||
2016 | In Ispell minor mode, pressing SPC or RET | |
2017 | warns you if the previous word is incorrectly spelled." | |
2018 | (interactive "P") | |
2019 | (setq ispell-minor-mode | |
2020 | (not (or (and (null arg) ispell-minor-mode) | |
2021 | (<= (prefix-numeric-value arg) 0)))) | |
2bcf8edb | 2022 | (force-mode-line-update)) |
0349bab6 RS |
2023 | |
2024 | (defun ispell-minor-check () | |
2025 | ;; Check previous word then continue with the normal binding of this key. | |
2026 | (interactive "*") | |
2027 | (let ((ispell-minor-mode nil) | |
2028 | (ispell-check-only t)) | |
2029 | (save-restriction | |
2030 | (narrow-to-region (point-min) (point)) | |
2031 | (ispell-word nil t)) | |
2032 | (call-interactively (key-binding (this-command-keys))))) | |
007852e0 | 2033 | |
e29702dd | 2034 | |
007852e0 RS |
2035 | ;;; ********************************************************************** |
2036 | ;;; Ispell Message | |
2037 | ;;; ********************************************************************** | |
7492978d RS |
2038 | ;;; Original from D. Quinlan, E. Bradford, A. Albert, and M. Ernst |
2039 | ||
2040 | ||
2041 | (defvar ispell-message-text-end | |
2042 | (mapconcat (function identity) | |
2043 | '( | |
2044 | ;; Matches postscript files. | |
8ce8687e | 2045 | "^%!PS-Adobe-[123].0" |
7492978d RS |
2046 | ;; Matches uuencoded text |
2047 | "^begin [0-9][0-9][0-9] .*\nM.*\nM.*\nM" | |
2048 | ;; Matches shell files (esp. auto-decoding) | |
e29702dd | 2049 | "^#! /bin/[ck]?sh" |
8581f180 RS |
2050 | ;; Matches context difference listing |
2051 | "\\(diff -c .*\\)?\n\\*\\*\\* .*\n--- .*\n\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*" | |
f1f9f8d5 RS |
2052 | ;; Matches reporter.el bug report |
2053 | "^current state:\n==============\n" | |
7492978d | 2054 | ;; Matches "----------------- cut here" |
5e228a39 KH |
2055 | ;; and "------- Start of forwarded message" |
2056 | "^[-=_]+\\s ?\\(cut here\\|Start of forwarded message\\)") | |
7492978d RS |
2057 | "\\|") |
2058 | "*End of text which will be checked in ispell-message. | |
e29702dd | 2059 | If it is a string, limit at first occurrence of that regular expression. |
7492978d | 2060 | Otherwise, it must be a function which is called to get the limit.") |
007852e0 | 2061 | |
4b03da72 | 2062 | |
8ce8687e RS |
2063 | (defvar ispell-message-start-skip |
2064 | (mapconcat (function identity) | |
2065 | '( | |
2066 | ;; Matches forwarded messages | |
2067 | "^---* Forwarded Message" | |
2068 | ;; Matches PGP Public Key block | |
2069 | "^---*BEGIN PGP [A-Z ]*--*" | |
2070 | ) | |
2071 | "\\|") | |
2072 | "Spelling is skipped inside these start/end groups by ispell-message. | |
2073 | Assumed that blocks are not mutually inclusive.") | |
2074 | ||
2075 | ||
2076 | (defvar ispell-message-end-skip | |
2077 | (mapconcat (function identity) | |
2078 | '( | |
2079 | ;; Matches forwarded messages | |
2080 | "^--- End of Forwarded Message" | |
2081 | ;; Matches PGP Public Key block | |
2082 | "^---*END PGP [A-Z ]*--*" | |
2083 | ) | |
2084 | "\\|") | |
2085 | "Spelling is skipped inside these start/end groups by ispell-message. | |
2086 | Assumed that blocks are not mutually inclusive.") | |
2087 | ||
2088 | ||
007852e0 RS |
2089 | ;;;###autoload |
2090 | (defun ispell-message () | |
2091 | "Check the spelling of a mail message or news post. | |
2092 | Don't check spelling of message headers except the Subject field. | |
2093 | Don't check included messages. | |
2094 | ||
2095 | To abort spell checking of a message REGION and send the message anyway, | |
a9210a53 RS |
2096 | use the `x' or `q' command. (Any subsequent regions will be checked.) |
2097 | The `X' command aborts the message send so that you can edit the buffer. | |
007852e0 RS |
2098 | |
2099 | To spell-check whenever a message is sent, include the appropriate lines | |
2100 | in your .emacs file: | |
2101 | (add-hook 'news-inews-hook 'ispell-message) | |
2102 | (add-hook 'mail-send-hook 'ispell-message) | |
2103 | (add-hook 'mh-before-send-letter-hook 'ispell-message) | |
2104 | ||
e29702dd | 2105 | You can bind this to the key C-c i in GNUS or mail by adding to |
a9210a53 | 2106 | `news-reply-mode-hook' or `mail-mode-hook' the following lambda expression: |
007852e0 RS |
2107 | (function (lambda () (local-set-key \"\\C-ci\" 'ispell-message)))" |
2108 | (interactive) | |
7492978d | 2109 | (save-excursion |
4b03da72 RS |
2110 | (goto-char (point-min)) |
2111 | (let* ((internal-messagep (save-excursion | |
2112 | (re-search-forward | |
2113 | (concat "^" | |
2114 | (regexp-quote mail-header-separator) | |
2115 | "$") | |
2116 | nil t))) | |
ae9fdfe5 | 2117 | (limit (copy-marker |
4b03da72 RS |
2118 | (cond |
2119 | ((not ispell-message-text-end) (point-max)) | |
2120 | ((char-or-string-p ispell-message-text-end) | |
2121 | (if (re-search-forward ispell-message-text-end nil t) | |
2122 | (match-beginning 0) | |
2123 | (point-max))) | |
2124 | (t (min (point-max) (funcall ispell-message-text-end)))))) | |
7492978d RS |
2125 | (cite-regexp ;Prefix of inserted text |
2126 | (cond | |
2127 | ((featurep 'supercite) ; sc 3.0 | |
2128 | (concat "\\(" (sc-cite-regexp) "\\)" "\\|" | |
2129 | (ispell-non-empty-string sc-reference-tag-string))) | |
2130 | ((featurep 'sc) ; sc 2.3 | |
2131 | (concat "\\(" sc-cite-regexp "\\)" "\\|" | |
2132 | (ispell-non-empty-string sc-reference-tag-string))) | |
a9210a53 | 2133 | ((equal major-mode 'news-reply-mode) ;GNUS |
7492978d RS |
2134 | (concat "In article <" "\\|" |
2135 | (if mail-yank-prefix | |
2136 | (ispell-non-empty-string mail-yank-prefix) | |
2137 | "^ \\|^\t"))) | |
2138 | ((equal major-mode 'mh-letter-mode) ; mh mail message | |
2139 | (ispell-non-empty-string mh-ins-buf-prefix)) | |
4b03da72 | 2140 | ((not internal-messagep) ; Assume n sent us this message. |
7492978d RS |
2141 | (concat "In [a-zA-Z.]+ you write:" "\\|" |
2142 | "In <[^,;&+=]+> [^,;&+=]+ writes:" "\\|" | |
2143 | " *> *")) | |
2144 | ((boundp 'vm-included-text-prefix) ; VM mail message | |
2145 | (concat "[^,;&+=]+ writes:" "\\|" | |
2146 | (ispell-non-empty-string vm-included-text-prefix))) | |
2147 | (mail-yank-prefix ; vanilla mail message. | |
2148 | (ispell-non-empty-string mail-yank-prefix)) | |
2149 | (t "^ \\|^\t"))) | |
4b03da72 RS |
2150 | (cite-regexp-start (concat "^[ \t]*$\\|" cite-regexp)) |
2151 | (cite-regexp-end (concat "^\\(" cite-regexp "\\)")) | |
2152 | (old-case-fold-search case-fold-search) | |
2153 | (case-fold-search t) | |
2154 | (ispell-checking-message t)) | |
2155 | (goto-char (point-min)) | |
007852e0 RS |
2156 | ;; Skip header fields except Subject: without Re:'s |
2157 | ;;(search-forward mail-header-separator nil t) | |
2158 | (while (if internal-messagep | |
2159 | (< (point) internal-messagep) | |
4b03da72 | 2160 | (and (looking-at "[a-zA-Z---]+:\\|\t\\| ") |
007852e0 | 2161 | (not (eobp)))) |
4b03da72 | 2162 | (if (looking-at "Subject: *") ; Spell check new subject fields |
7492978d RS |
2163 | (progn |
2164 | (goto-char (match-end 0)) | |
2165 | (if (and (not (looking-at ".*Re\\>")) | |
2166 | (not (looking-at "\\["))) | |
2167 | (let ((case-fold-search old-case-fold-search)) | |
2168 | (ispell-region (point) | |
2169 | (progn | |
2170 | (end-of-line) | |
2171 | (while (looking-at "\n[ \t]") | |
2172 | (end-of-line 2)) | |
2173 | (point))))))) | |
007852e0 RS |
2174 | (forward-line 1)) |
2175 | (setq case-fold-search nil) | |
2176 | ;; Skip mail header, particularly for non-english languages. | |
e7a52e41 | 2177 | (if (looking-at (concat (regexp-quote mail-header-separator) "$")) |
007852e0 | 2178 | (forward-line 1)) |
7492978d | 2179 | (while (< (point) limit) |
007852e0 RS |
2180 | ;; Skip across text cited from other messages. |
2181 | (while (and (looking-at cite-regexp-start) | |
e29702dd KH |
2182 | (< (point) limit) |
2183 | (zerop (forward-line 1)))) | |
1335d078 | 2184 | |
7492978d | 2185 | (if (< (point) limit) |
1335d078 RS |
2186 | (let* ((start (point)) |
2187 | ;; Check the next batch of lines that *aren't* cited. | |
2188 | (end-c (and (re-search-forward cite-regexp-end limit 'end) | |
2189 | (match-beginning 0))) | |
8ce8687e | 2190 | ;; Skip a block of included text. |
1335d078 | 2191 | (end-fwd (and (goto-char start) |
8ce8687e RS |
2192 | (re-search-forward ispell-message-start-skip |
2193 | limit 'end) | |
2194 | (progn (beginning-of-line) | |
2195 | (point)))) | |
1335d078 RS |
2196 | (end (or (and end-c end-fwd (min end-c end-fwd)) |
2197 | end-c end-fwd | |
a7acbbe4 | 2198 | ;; default to limit of text. |
1335d078 RS |
2199 | (marker-position limit)))) |
2200 | (goto-char start) | |
2201 | (ispell-region start end) | |
2202 | (if (and end-fwd (= end end-fwd)) | |
2203 | (progn | |
2204 | (goto-char end) | |
8ce8687e | 2205 | (re-search-forward ispell-message-end-skip limit 'end)) |
1335d078 | 2206 | (goto-char end))))) |
4b03da72 RS |
2207 | (set-marker limit nil)))) |
2208 | ||
007852e0 RS |
2209 | |
2210 | (defun ispell-non-empty-string (string) | |
2211 | (if (or (not string) (string-equal string "")) | |
2212 | "\\'\\`" ; An unmatchable string if string is null. | |
2213 | (regexp-quote string))) | |
2214 | ||
2215 | ||
2216 | ;;; ********************************************************************** | |
2217 | ;;; Buffer Local Functions | |
2218 | ;;; ********************************************************************** | |
2219 | ||
2220 | ||
2221 | (defun ispell-accept-buffer-local-defs () | |
4b03da72 | 2222 | "Load all buffer-local information, restarting ispell when necessary." |
007852e0 RS |
2223 | (ispell-buffer-local-dict) ; May kill ispell-process. |
2224 | (ispell-buffer-local-words) ; Will initialize ispell-process. | |
2225 | (ispell-buffer-local-parsing)) | |
2226 | ||
2227 | ||
007852e0 | 2228 | (defun ispell-buffer-local-parsing () |
a9210a53 | 2229 | "Place Ispell into parsing mode for this buffer. |
4b03da72 RS |
2230 | Overrides the default parsing mode. |
2231 | Includes latex/nroff modes and extended character mode." | |
007852e0 RS |
2232 | ;; (ispell-init-process) must already be called. |
2233 | (process-send-string ispell-process "!\n") ; Put process in terse mode. | |
2234 | ;; We assume all major modes with "tex-mode" in them should use latex parsing | |
2235 | (if (or (and (eq ispell-parser 'use-mode-name) | |
2236 | (string-match "[Tt][Ee][Xx]-mode" (symbol-name major-mode))) | |
2237 | (eq ispell-parser 'tex)) | |
2238 | (process-send-string ispell-process "+\n") ; set ispell mode to tex | |
2239 | (process-send-string ispell-process "-\n")) ; set mode to normal (nroff) | |
8ce8687e RS |
2240 | ;; Hard-wire test for SGML & HTML mode. |
2241 | (setq ispell-skip-sgml (memq major-mode '(sgml-mode html-mode))) | |
007852e0 RS |
2242 | ;; Set default extended character mode for given buffer, if any. |
2243 | (let ((extended-char-mode (ispell-get-extended-character-mode))) | |
2244 | (if extended-char-mode | |
2245 | (process-send-string ispell-process (concat extended-char-mode "\n")))) | |
e29702dd | 2246 | ;; Set buffer-local parsing mode and extended character mode, if specified. |
007852e0 RS |
2247 | (save-excursion |
2248 | (goto-char (point-min)) | |
2249 | ;; Uses last valid definition | |
2250 | (while (search-forward ispell-parsing-keyword nil t) | |
2251 | (let ((end (save-excursion (end-of-line) (point))) | |
2252 | (case-fold-search t) | |
2253 | string) | |
2254 | (while (re-search-forward " *\\([^ \"]+\\)" end t) | |
2255 | ;; space separated definitions. | |
2256 | (setq string (buffer-substring (match-beginning 1) (match-end 1))) | |
2257 | (cond ((string-match "latex-mode" string) | |
e29702dd | 2258 | (process-send-string ispell-process "+\n~tex\n")) |
007852e0 | 2259 | ((string-match "nroff-mode" string) |
e29702dd | 2260 | (process-send-string ispell-process "-\n~nroff")) |
007852e0 RS |
2261 | ((string-match "~" string) ; Set extended character mode. |
2262 | (process-send-string ispell-process (concat string "\n"))) | |
2263 | (t (message "Illegal Ispell Parsing argument!") | |
2264 | (sit-for 2)))))))) | |
2265 | ||
2266 | ||
2267 | ;;; Can kill the current ispell process | |
2268 | ||
2269 | (defun ispell-buffer-local-dict () | |
4b03da72 | 2270 | "Initializes local dictionary. |
007852e0 | 2271 | When a dictionary is defined in the buffer (see variable |
a9210a53 | 2272 | `ispell-dictionary-keyword'), it will override the local setting |
007852e0 RS |
2273 | from \\[ispell-change-dictionary]. |
2274 | Both should not be used to define a buffer-local dictionary." | |
2275 | (save-excursion | |
2276 | (goto-char (point-min)) | |
2277 | (let (end) | |
2278 | ;; Override the local variable definition. | |
2279 | ;; Uses last valid definition. | |
2280 | (while (search-forward ispell-dictionary-keyword nil t) | |
2281 | (setq end (save-excursion (end-of-line) (point))) | |
2282 | (if (re-search-forward " *\\([^ \"]+\\)" end t) | |
2283 | (setq ispell-local-dictionary | |
2284 | (buffer-substring (match-beginning 1) (match-end 1))))) | |
2285 | (goto-char (point-min)) | |
2286 | (while (search-forward ispell-pdict-keyword nil t) | |
2287 | (setq end (save-excursion (end-of-line) (point))) | |
2288 | (if (re-search-forward " *\\([^ \"]+\\)" end t) | |
2289 | (setq ispell-local-pdict | |
2290 | (buffer-substring (match-beginning 1) (match-end 1))))))) | |
2291 | ;; Reload if new personal dictionary defined. | |
2292 | (if (and ispell-local-pdict | |
2293 | (not (equal ispell-local-pdict ispell-personal-dictionary))) | |
2294 | (progn | |
2295 | (ispell-kill-ispell t) | |
2296 | (setq ispell-personal-dictionary ispell-local-pdict))) | |
2297 | ;; Reload if new dictionary defined. | |
2298 | (if (and ispell-local-dictionary | |
2299 | (not (equal ispell-local-dictionary ispell-dictionary))) | |
2300 | (ispell-change-dictionary ispell-local-dictionary))) | |
2301 | ||
2302 | ||
2303 | (defun ispell-buffer-local-words () | |
a9210a53 | 2304 | "Loads the buffer-local dictionary in the current buffer." |
007852e0 RS |
2305 | (if (and ispell-buffer-local-name |
2306 | (not (equal ispell-buffer-local-name (buffer-name)))) | |
2307 | (progn | |
2308 | (ispell-kill-ispell t) | |
2309 | (setq ispell-buffer-local-name nil))) | |
2310 | (ispell-init-process) | |
2311 | (save-excursion | |
2312 | (goto-char (point-min)) | |
2313 | (while (search-forward ispell-words-keyword nil t) | |
2314 | (or ispell-buffer-local-name | |
2315 | (setq ispell-buffer-local-name (buffer-name))) | |
2316 | (let ((end (save-excursion (end-of-line) (point))) | |
2317 | string) | |
e29702dd KH |
2318 | ;; buffer-local words separated by a space, and can contain |
2319 | ;; any character other than a space. | |
7195bb71 | 2320 | (while (re-search-forward " *\\([^ ]+\\)" end t) |
007852e0 | 2321 | (setq string (buffer-substring (match-beginning 1) (match-end 1))) |
4b03da72 | 2322 | (process-send-string ispell-process (concat "@" string "\n"))))))) |
007852e0 RS |
2323 | |
2324 | ||
2325 | ;;; returns optionally adjusted region-end-point. | |
2326 | ||
2327 | (defun ispell-add-per-file-word-list (word &optional reg-end) | |
2328 | "Adds new word to the per-file word list." | |
2329 | (or ispell-buffer-local-name | |
2330 | (setq ispell-buffer-local-name (buffer-name))) | |
2331 | (if (null reg-end) | |
2332 | (setq reg-end 0)) | |
2333 | (save-excursion | |
2334 | (goto-char (point-min)) | |
4b03da72 | 2335 | (let (case-fold-search line-okay search done string) |
007852e0 RS |
2336 | (while (not done) |
2337 | (setq search (search-forward ispell-words-keyword nil 'move) | |
2338 | line-okay (< (+ (length word) 1 ; 1 for space after word.. | |
2339 | (progn (end-of-line) (current-column))) | |
2340 | 80)) | |
2341 | (if (or (and search line-okay) | |
2342 | (null search)) | |
2343 | (progn | |
2344 | (setq done t) | |
2345 | (if (null search) | |
2346 | (progn | |
2347 | (open-line 1) | |
2348 | (setq string (concat comment-start " " | |
2349 | ispell-words-keyword)) | |
2350 | ;; in case the keyword is in the middle of the file.... | |
2351 | (if (> reg-end (point)) | |
2352 | (setq reg-end (+ reg-end (length string)))) | |
2353 | (insert string) | |
2354 | (if (and comment-end (not (equal "" comment-end))) | |
2355 | (save-excursion | |
2356 | (open-line 1) | |
2357 | (forward-line 1) | |
2358 | (insert comment-end))))) | |
2359 | (if (> reg-end (point)) | |
2360 | (setq reg-end (+ 1 reg-end (length word)))) | |
2361 | (insert (concat " " word))))))) | |
2362 | reg-end) | |
2363 | ||
2364 | ||
8ce8687e | 2365 | (defconst ispell-version "2.37 -- Tue Jun 13 12:05:28 EDT 1995") |
007852e0 RS |
2366 | |
2367 | (provide 'ispell) | |
2368 | ||
2369 | \f | |
2370 | ;;; LOCAL VARIABLES AND BUFFER-LOCAL VALUE EXAMPLES. | |
2371 | ||
2372 | ;;; Local Variable options: | |
2373 | ;;; mode: name(-mode) | |
2374 | ;;; eval: expression | |
2375 | ;;; local-variable: value | |
2376 | ||
2377 | ;;; The following sets the buffer local dictionary to english! | |
2378 | ||
2379 | ;;; Local Variables: | |
2380 | ;;; mode: emacs-lisp | |
2381 | ;;; comment-column: 40 | |
2382 | ;;; ispell-local-dictionary: "english" | |
2383 | ;;; End: | |
2384 | ||
2385 | ||
2386 | ;;; MORE EXAMPLES OF ISPELL BUFFER-LOCAL VALUES | |
2387 | ||
2388 | ;;; The following places this file in nroff parsing and extended char modes. | |
2389 | ;;; Local IspellParsing: nroff-mode ~nroff | |
2390 | ;;; Change IspellDict to IspellDict: to enable the following line. | |
2391 | ;;; Local IspellDict english | |
2392 | ;;; Change IspellPersDict to IspellPersDict: to enable the following line. | |
2393 | ;;; Local IspellPersDict ~/.ispell_lisp | |
2394 | ;;; The following were automatically generated by ispell using the 'A' command: | |
2395 | ; LocalWords: ispell ispell-highlight-p ispell-check-comments query-replace | |
2396 | ; LocalWords: ispell-query-replace-choices ispell-skip-tib non-nil tib | |
2397 | ; LocalWords: regexps ispell-tib-ref-beginning ispell-tib-ref-end | |
2398 | ||
2399 | ;; ispell.el ends here |