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