Commit | Line | Data |
---|---|---|
007852e0 RS |
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 | |
8893ad8c RS |
349 | "When t, Emacs uses pty's to communicate with Ispell. |
350 | When nil, Emacs uses pipes.") | |
007852e0 RS |
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 | ||
29bff366 | 388 | ;;;###autoload |
007852e0 RS |
389 | (defvar ispell-dictionary-alist ; sk 9-Aug-1991 18:28 |
390 | '((nil ; default (english.aff) | |
26add1bf | 391 | "[A-Za-z]" "[^A-Za-z]" "[-']" nil ("-B") nil) |
007852e0 | 392 | ("english" ; make english explicitly selectable |
26add1bf | 393 | "[A-Za-z]" "[^A-Za-z]" "[-']" nil ("-B") nil) |
007852e0 | 394 | ("deutsch" ; deutsch.aff |
26add1bf | 395 | "[a-zA-Z\"]" "[^a-zA-Z\"]" "[-']" t ("-C") nil) |
007852e0 RS |
396 | ("deutsch8" |
397 | "[a-zA-Z\304\326\334\344\366\337\374]" | |
398 | "[^a-zA-Z\304\326\334\344\366\337\374]" | |
26add1bf | 399 | "[-']" t ("-C" "-d" "deutsch") "~latin1") |
007852e0 RS |
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]" | |
26add1bf | 403 | "[-']" t ("-C") nil) |
007852e0 RS |
404 | ("svenska" ;7 bit swedish mode |
405 | "[A-Za-z}{|\\133\\135\\\\]" "[^A-Za-z}{|\\133\\135\\\\]" | |
26add1bf | 406 | "[-']" nil ("-C") nil) |
007852e0 RS |
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]" | |
26add1bf | 409 | "[-']" nil ("-C" "-d" "svenska") "~list") ; Add `"-T" "list"' instead? |
007852e0 | 410 | ("francais" |
26add1bf | 411 | "[A-Za-z]" "[^A-Za-z]" "[-`'\^]" nil nil nil) |
a004e502 | 412 | ("danish" ; danish.aff |
007852e0 | 413 | "[A-Z\306\330\305a-z\346\370\345]" "[^A-Z\306\330\305a-z\346\370\345]" |
26add1bf | 414 | "[-]" nil ("-C") nil) |
007852e0 RS |
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 | ||
7d687545 | 461 | ;;;###autoload |
007852e0 | 462 | (defvar ispell-menu-map nil) |
7d687545 RS |
463 | ;;;###autoload |
464 | (if (null ispell-menu-map) | |
007852e0 RS |
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 | ||
a870f917 RS |
629 | ;;;###autoload (define-key global-map "\M-$" 'ispell-word) |
630 | ||
007852e0 RS |
631 | ;;;###autoload |
632 | (defun ispell-word (&optional following quietly) | |
633 | "Check spelling of word under or before the cursor. | |
634 | If word not found in dictionary, display possible corrections in a window | |
635 | and let user select. | |
636 | If optional argument FOLLOWING is non-nil or if ispell-following-word | |
637 | is non-nil when called interactively, then the following word | |
638 | \(rather than preceding\) will be checked when the cursor is not over a word. | |
639 | When the optional argument QUIETLY is non-nil or ispell-quietly is non-nil | |
640 | when called interactively, non-corrective messages are suppressed. | |
641 | ||
642 | Word syntax described by ispell-dictionary-alist (which see). | |
643 | ||
644 | This will check or reload the dictionary. Use \\[ispell-change-dictionary] | |
645 | or \\[ispell-region] to update the ispell process." | |
646 | (interactive) | |
647 | (if (interactive-p) | |
648 | (setq following ispell-following-word | |
649 | quietly ispell-quietly)) | |
650 | (ispell-buffer-local-dict) ; use the correct dictionary | |
651 | (let ((cursor-location (point)) ; retain cursor location | |
652 | ispell-keep-choices-win ; override global to force creation | |
653 | (word (ispell-get-word following)) | |
654 | start end poss replace) | |
655 | ;; destructure return word info list. | |
656 | (setq start (car (cdr word)) | |
657 | end (car (cdr (cdr word))) | |
658 | word (car word)) | |
659 | ||
660 | ;; now check spelling of word. | |
661 | (or quietly | |
662 | (message "Checking spelling of %s..." | |
663 | (funcall ispell-format-word word))) | |
664 | (ispell-init-process) ; erases ispell output buffer | |
665 | (process-send-string ispell-process "%\n") ;put in verbose mode | |
666 | (process-send-string ispell-process (concat "^" word "\n")) | |
667 | ;; wait until ispell has processed word | |
668 | (while (progn | |
669 | (accept-process-output ispell-process) | |
670 | (not (string= "" (car ispell-filter))))) | |
671 | ;;(process-send-string ispell-process "!\n") ;back to terse mode. | |
672 | (setq ispell-filter (cdr ispell-filter)) | |
673 | (if (listp ispell-filter) | |
674 | (setq poss (ispell-parse-output (car ispell-filter)))) | |
675 | (cond ((eq poss t) | |
676 | (or quietly | |
677 | (message "%s is correct." (funcall ispell-format-word word)))) | |
678 | ((stringp poss) | |
679 | (or quietly | |
680 | (message "%s is correct because of root %s" | |
681 | (funcall ispell-format-word word) | |
682 | (funcall ispell-format-word poss)))) | |
683 | ((null poss) (message "Error in ispell process")) | |
684 | (t ; prompt for correct word. | |
685 | (unwind-protect | |
686 | (progn | |
687 | (if ispell-highlight-p | |
688 | (highlight-spelling-error start end t)) ; highlight word | |
689 | (setq replace (ispell-command-loop | |
690 | (car (cdr (cdr poss))) | |
691 | (car (cdr (cdr (cdr poss)))) | |
692 | (car poss)))) | |
693 | ;; protected | |
694 | (if ispell-highlight-p ; clear highlight | |
695 | (highlight-spelling-error start end))) | |
696 | (cond ((equal 0 replace) | |
697 | (ispell-add-per-file-word-list (car poss))) | |
698 | (replace | |
699 | (delete-region start end) | |
700 | (setq word (if (atom replace) replace (car replace)) | |
701 | cursor-location (+ (- (length word) (- end start)) | |
702 | cursor-location)) | |
703 | (insert word) | |
704 | (if (not (atom replace)) ; recheck spelling of replacement | |
705 | (progn | |
706 | (goto-char cursor-location) | |
707 | (ispell-word following quietly))))) | |
708 | (if (get-buffer ispell-choices-buffer) | |
709 | (kill-buffer ispell-choices-buffer)))) | |
710 | (goto-char cursor-location) ; return to original location | |
711 | (ispell-pdict-save ispell-silently-savep) | |
712 | (if ispell-quit (setq ispell-quit nil)))) | |
713 | ||
714 | ||
715 | (defun ispell-get-word (following &optional extra-otherchars) | |
716 | "Return the word for spell-checking according to ispell syntax. | |
717 | If optional argument FOLLOWING is non-nil or if ispell-following-word | |
718 | is non-nil when called interactively, then the following word | |
719 | \(rather than preceeding\) will be checked when the cursor is not over a word. | |
720 | Optional second argument contains otherchars that can be included in word | |
721 | many times. | |
722 | ||
723 | Word syntax described by ispell-dictionary-alist (which see)." | |
724 | (let* ((ispell-casechars (ispell-get-casechars)) | |
725 | (ispell-not-casechars (ispell-get-not-casechars)) | |
726 | (ispell-otherchars (ispell-get-otherchars)) | |
727 | (ispell-many-otherchars-p (ispell-get-many-otherchars-p)) | |
728 | (word-regexp (concat ispell-casechars | |
729 | "+\\(" | |
730 | ispell-otherchars | |
731 | "?" | |
732 | (if extra-otherchars | |
733 | (concat extra-otherchars "?")) | |
734 | ispell-casechars | |
735 | "+\\)" | |
736 | (if (or ispell-many-otherchars-p | |
737 | extra-otherchars) | |
738 | "*" "?"))) | |
739 | did-it-once | |
740 | start end word) | |
741 | ;; find the word | |
742 | (if (not (looking-at ispell-casechars)) | |
743 | (if following | |
744 | (re-search-forward ispell-casechars (point-max) t) | |
745 | (re-search-backward ispell-casechars (point-min) t))) | |
746 | ;; move to front of word | |
747 | (re-search-backward ispell-not-casechars (point-min) 'start) | |
748 | (while (and (or (looking-at ispell-otherchars) | |
749 | (and extra-otherchars (looking-at extra-otherchars))) | |
750 | (not (bobp)) | |
751 | (or (not did-it-once) | |
752 | ispell-many-otherchars-p)) | |
753 | (if (and extra-otherchars (looking-at extra-otherchars)) | |
754 | (progn | |
755 | (backward-char 1) | |
756 | (if (looking-at ispell-casechars) | |
757 | (re-search-backward ispell-not-casechars (point-min) 'move))) | |
758 | (setq did-it-once t) | |
759 | (backward-char 1) | |
760 | (if (looking-at ispell-casechars) | |
761 | (re-search-backward ispell-not-casechars (point-min) 'move) | |
762 | (backward-char -1)))) | |
763 | ;; Now mark the word and save to string. | |
764 | (or (re-search-forward word-regexp (point-max) t) | |
765 | (error "No word found to check!")) | |
766 | (setq start (match-beginning 0) | |
767 | end (point) | |
768 | word (buffer-substring start end)) | |
769 | (list word start end))) | |
770 | ||
771 | ||
772 | ;;; Global ispell-pdict-modified-p is set by ispell-command-loop and | |
773 | ;;; tracks changes in the dictionary. The global may either be | |
774 | ;;; a value or a list, whose value is the state of whether the | |
775 | ;;; dictionary needs to be saved. | |
776 | ||
829b9e73 | 777 | ;;;###autoload |
007852e0 RS |
778 | (defun ispell-pdict-save (&optional no-query force-save) |
779 | "Check to see if the personal dictionary has been modified. | |
780 | If so, ask if it needs to be saved." | |
781 | (interactive (list ispell-silently-savep t)) | |
782 | (if (and ispell-pdict-modified-p (listp ispell-pdict-modified-p)) | |
783 | (setq ispell-pdict-modified-p (car ispell-pdict-modified-p))) | |
784 | (if (or ispell-pdict-modified-p force-save) | |
785 | (if (or no-query (y-or-n-p "Personal dictionary modified. Save? ")) | |
786 | (process-send-string ispell-process "#\n"))) | |
787 | ;; unassert variable, even if not saved to avoid questioning. | |
788 | (setq ispell-pdict-modified-p nil)) | |
789 | ||
790 | ||
791 | (defun ispell-command-loop (miss guess word) | |
792 | "Display possible corrections from list MISS. | |
793 | GUESS lists possibly valid affix construction of WORD. | |
794 | Returns nil to keep word. | |
795 | 0 to insert locally into buffer-local dictionary. | |
796 | string for new chosen word. | |
797 | list for new replacement word (will be rechecked). | |
798 | Optional second argument means replace misspelling in | |
799 | the rest of the region. | |
800 | Global ispell-pdict-modified-p becomes a list where the only value | |
801 | indicates whether the dictionary has been modified when option a or i is | |
802 | used." | |
803 | (unwind-protect | |
804 | (save-window-excursion | |
805 | (let ((count ?0) | |
806 | (line 2) | |
807 | (max-lines (- (window-height) 4)) ; assure 4 context lines. | |
808 | (choices miss) | |
809 | (window-min-height (min window-min-height | |
810 | ispell-choices-win-default-height)) | |
811 | (command-characters '( ? ?i ?a ?A ?r ?R ?? ?x ?X ?q ?l ?u ?m )) | |
812 | (skipped 0) | |
813 | char num result) | |
814 | (save-excursion | |
815 | (if ispell-keep-choices-win | |
816 | (select-window (previous-window)) | |
817 | (set-buffer (get-buffer-create ispell-choices-buffer)) | |
818 | (setq mode-line-format "-- %b --")) | |
819 | (if (equal (get-buffer ispell-choices-buffer) (current-buffer)) | |
820 | (erase-buffer) | |
821 | (error "Bogus, dude! I should be in the *Choices* buffer, but I'm not!")) | |
822 | (if guess | |
823 | (progn | |
824 | (insert | |
825 | "Affix rules generate and capitalize this word as shown below:\n\t") | |
826 | (while guess | |
827 | (if (> (+ 4 (current-column) (length (car guess))) | |
828 | (window-width)) | |
829 | (progn | |
830 | (insert "\n\t") | |
831 | (setq line (1+ line)))) | |
832 | (insert (car guess) " ") | |
833 | (setq guess (cdr guess))) | |
834 | (insert "\nUse option \"i\" if this is a correct composition from the derivative root.\n") | |
835 | (setq line (+ line (if choices 3 2))))) | |
836 | (while (and choices | |
837 | (< (if (> (+ 7 (current-column) (length (car choices)) | |
838 | (if (> count ?~) 3 0)) | |
839 | (window-width)) | |
840 | (progn | |
841 | (insert "\n") | |
842 | (setq line (1+ line))) | |
843 | line) | |
844 | max-lines)) | |
845 | ;; not so good if there are over 20 or 30 options, but then, if | |
846 | ;; there are that many you don't want to have to scan them all anyway... | |
847 | (while (memq count command-characters) ; skip command characters. | |
848 | (setq count (1+ count) | |
849 | skipped (1+ skipped))) | |
850 | (insert "(" count ") " (car choices) " ") | |
851 | (setq choices (cdr choices) | |
852 | count (1+ count))) | |
853 | (setq count (- count ?0 skipped))) | |
854 | ||
855 | (if ispell-keep-choices-win | |
856 | (if (> line ispell-keep-choices-win) | |
857 | (progn | |
858 | (switch-to-buffer ispell-choices-buffer) | |
859 | (select-window (next-window)) | |
860 | (save-excursion | |
861 | (let ((cur-point (point))) | |
862 | (move-to-window-line (- line ispell-keep-choices-win)) | |
863 | (if (<= (point) cur-point) | |
864 | (set-window-start (selected-window) (point))))) | |
865 | (select-window (previous-window)) | |
866 | (enlarge-window (- line ispell-keep-choices-win)) | |
867 | (goto-char (point-min)))) | |
868 | (ispell-overlay-window (max line ispell-choices-win-default-height))) | |
869 | (switch-to-buffer ispell-choices-buffer) | |
870 | (goto-char (point-min)) | |
871 | (select-window (next-window)) | |
872 | (while | |
873 | (eq | |
874 | t | |
875 | (setq | |
876 | result | |
877 | (progn | |
878 | (undo-boundary) | |
879 | (message "C-h or ? for more options; SPC to leave unchanged, Character to replace word") | |
880 | (setq char (read-char) | |
881 | skipped 0) | |
882 | ;; Adjust num to array offset skipping command characters. | |
883 | (let ((com-chars command-characters)) | |
884 | (while com-chars | |
885 | (if (and (> (car com-chars) ?0) (< (car com-chars) char)) | |
886 | (setq skipped (1+ skipped))) | |
887 | (setq com-chars (cdr com-chars))) | |
888 | (setq num (- char ?0 skipped))) | |
889 | ||
890 | (cond | |
891 | ((= char ? ) nil) ; accept word this time only | |
892 | ((= char ?i) ; accept and insert word into pers dict | |
893 | (process-send-string ispell-process (concat "*" word "\n")) | |
894 | (setq ispell-pdict-modified-p '(t)) ; dictionary was modified! | |
895 | nil) | |
896 | ((or (= char ?a) (= char ?A)) ; accept word, don't insert in dict | |
897 | (process-send-string ispell-process (concat "@" word "\n")) | |
898 | (if (null ispell-pdict-modified-p) | |
899 | (setq ispell-pdict-modified-p | |
900 | (list ispell-pdict-modified-p))) | |
901 | (if (= char ?A) 0)) ; return 0 for ispell-add buffer-local | |
902 | ((or (= char ?r) (= char ?R)) ; type in replacement | |
903 | (if (or (= char ?R) ispell-query-replace-choices) | |
904 | (list (read-string "Query-replacement for: " word) t) | |
905 | (cons (read-string "Replacement for: " word) nil))) | |
906 | ((or (= char ??) (= char help-char) (= char ?\C-h)) | |
907 | (ispell-help) | |
908 | t) | |
909 | ;; quit or quit and stay at this point. | |
910 | ((or (= char ?x) (= char ?X)) ; quit. | |
911 | (ispell-pdict-save ispell-silently-savep) | |
912 | (message "exited ispell") | |
913 | (setq ispell-quit (if (= char ?X) (point) t)) | |
914 | nil) | |
915 | ((or (= char ?q) | |
916 | (= char (nth 3 (current-input-mode)))) ; C-g | |
917 | (if (y-or-n-p "Really quit ignoring changes? ") | |
918 | (progn | |
919 | (ispell-kill-ispell t) ; terminate process. | |
920 | (setq ispell-quit t | |
921 | ispell-pdict-modified-p nil)) | |
922 | t)) ; continue if they don't quit. | |
923 | ((= char ?l) | |
924 | (let ((new-word (read-string "Lookup string ('*' is wildcard): " | |
925 | word)) | |
926 | (new-line 2)) | |
927 | (if new-word | |
928 | (progn | |
929 | (save-excursion | |
930 | (set-buffer (get-buffer-create ispell-choices-buffer)) | |
931 | (erase-buffer) | |
932 | (setq count ?0 | |
933 | skipped 0 | |
934 | mode-line-format "-- %b --" | |
935 | miss (lookup-words new-word) | |
936 | choices miss) | |
937 | (while (and choices ; adjust choices window. | |
938 | (< (if (> (+ 7 (current-column) | |
939 | (length (car choices)) | |
940 | (if (> count ?~) 3 0)) | |
941 | (window-width)) | |
942 | (progn | |
943 | (insert "\n") | |
944 | (setq new-line (1+ new-line))) | |
945 | new-line) | |
946 | max-lines)) | |
947 | (while (memq count command-characters) | |
948 | (setq count (1+ count) | |
949 | skipped (1+ skipped))) | |
950 | (insert "(" count ") " (car choices) " ") | |
951 | (setq choices (cdr choices) | |
952 | count (1+ count))) | |
953 | (setq count (- count ?0 skipped))) | |
954 | (select-window (previous-window)) | |
955 | (if (/= new-line line) | |
956 | (progn | |
957 | (if (> new-line line) | |
958 | (enlarge-window (- new-line line)) | |
959 | (shrink-window (- line new-line))) | |
960 | (setq line new-line))) | |
961 | (select-window (next-window))))) | |
962 | t) ; reselect from new choices | |
963 | ((= char ?u) | |
964 | (process-send-string ispell-process | |
965 | (concat "*" (downcase word) "\n")) | |
966 | (setq ispell-pdict-modified-p '(t)) ; dictionary was modified! | |
967 | nil) | |
968 | ((= char ?m) ; type in what to insert | |
969 | (process-send-string | |
970 | ispell-process (concat "*" (read-string "Insert: " word) "\n")) | |
971 | (setq ispell-pdict-modified-p '(t)) | |
972 | (cons word nil)) | |
973 | ((and (>= num 0) (< num count)) | |
974 | (if ispell-query-replace-choices ; Query replace when flag set. | |
975 | (list (nth num miss) 'query-replace) | |
976 | (nth num miss))) | |
977 | ((= char ?\C-l) | |
978 | (redraw-display) t) | |
979 | ((= char ?\C-r) | |
980 | (save-window-excursion (recursive-edit)) t) | |
981 | ((= char ?\C-z) | |
982 | (suspend-emacs) t) | |
983 | (t (ding) t)))))) | |
984 | result)) | |
985 | (if (not ispell-keep-choices-win) (bury-buffer ispell-choices-buffer)))) | |
986 | ||
987 | ||
829b9e73 | 988 | ;;;###autoload |
007852e0 RS |
989 | (defun ispell-help () |
990 | "This gives a list of the options available when a misspelling is encountered. | |
991 | ||
992 | Selections are: | |
993 | ||
994 | DIGIT: Replace the word with a digit offered in the *Choices* buffer. | |
995 | ' ': Accept word this time. | |
996 | 'i': Accept word and insert into private dictionary. | |
997 | 'a': Accept word for this session. | |
998 | 'A': Accept word and place in `buffer-local dictionary'. | |
999 | 'r': Replace word with typed-in value. Rechecked. | |
1000 | 'R': Replace word with typed-in value. Query-replaced in buffer. Rechecked. | |
1001 | '?': Show these commands. | |
1002 | 'x': Exit spelling buffer. Move cursor to original point. | |
1003 | 'X': Exit spelling buffer. Leaves cursor at the current point, and permits | |
1004 | the aborted check to be completed later. | |
1005 | 'q': Quit spelling session (Kills ispell process). | |
1006 | 'l': Look up typed-in replacement in alternate dictionary. Wildcards okay. | |
1007 | 'u': Like 'i', but the word is lower-cased first. | |
1008 | 'm': Like 'i', but allows one to include dictionary completion information. | |
1009 | 'C-l': redraws screen | |
1010 | 'C-r': recursive edit | |
1011 | 'C-z': suspend emacs" | |
1012 | ||
1013 | (let ((help-1 "[r/R]eplace word; [a/A]ccept for this session; [i]nsert into private dictionary") | |
1014 | (help-2 "[l]ook a word up in alternate dictionary; e[x/X]it; [q]uit session") | |
1015 | (help-3 "[u]ncapitalized insert into dictionary. Type 'C-h d ispell-help' for more help")) | |
1016 | (save-window-excursion | |
1017 | (if ispell-help-in-bufferp | |
1018 | (progn | |
1019 | (ispell-overlay-window 4) | |
1020 | (switch-to-buffer (get-buffer-create "*Ispell Help*")) | |
1021 | (insert (concat help-1 "\n" help-2 "\n" help-3)) | |
1022 | (sit-for 5) | |
1023 | (kill-buffer "*Ispell Help*")) | |
1024 | (select-window (minibuffer-window)) | |
1025 | (enlarge-window 2) | |
1026 | (erase-buffer) | |
1027 | (cond ((string-match "Lucid" emacs-version) | |
1028 | (message help-3) | |
1029 | (enlarge-window 1) | |
1030 | (message help-2) | |
1031 | (enlarge-window 1) | |
1032 | (message help-1)) | |
1033 | (t | |
1034 | (if (string-match "^19\\." emacs-version) | |
1035 | (message nil)) | |
1036 | (enlarge-window 2) | |
1037 | (insert (concat help-1 "\n" help-2 "\n" help-3)))) | |
1038 | (sit-for 5) | |
1039 | (erase-buffer))))) | |
1040 | ||
1041 | ||
1042 | (defun lookup-words (word &optional lookup-dict) | |
1043 | "Look up word in word-list dictionary. | |
1044 | A '*' is used for wild cards. If no wild cards, 'look' is used if it exists. | |
1045 | Otherwise the variable ispell-grep-command contains the command used to | |
1046 | search for the words (usually egrep). | |
1047 | Optional second argument contains the dictionary to use, the default is | |
1048 | ispell-alternate-dictionary." | |
1049 | ;; We don't use the filter for this function, rather the result is written | |
1050 | ;; into a buffer. Hence there is no need to save the filter values. | |
1051 | (if (null lookup-dict) | |
1052 | (setq lookup-dict ispell-alternate-dictionary)) | |
1053 | ||
1054 | (let* ((process-connection-type ispell-use-ptys-p) | |
1055 | (wild-p (string-match "\\*" word)) | |
1056 | (look-p (and ispell-look-p ; Only use look for an exact match. | |
1057 | (or ispell-have-new-look (not wild-p)))) | |
1058 | (ispell-grep-buffer (get-buffer-create "*Ispell-Temp*")) ; result buf | |
1059 | (prog (if look-p ispell-look-command ispell-grep-command)) | |
1060 | (args (if look-p ispell-look-options ispell-grep-options)) | |
1061 | status results loc) | |
1062 | (unwind-protect | |
1063 | (save-window-excursion | |
1064 | (message "Starting \"%s\" process..." (file-name-nondirectory prog)) | |
1065 | (set-buffer ispell-grep-buffer) | |
1066 | (if look-p | |
1067 | nil | |
1068 | ;; convert * to .* | |
1069 | (insert "^" word "$") | |
1070 | (while (search-backward "*" nil t) (insert ".")) | |
1071 | (setq word (buffer-string)) | |
1072 | (erase-buffer)) | |
1073 | (setq status (call-process prog nil t nil args word lookup-dict)) | |
1074 | ;; grep returns status 1 and no output when word not found, which | |
1075 | ;; is a perfectly normal thing. | |
1076 | (if (stringp status) | |
1077 | (setq results (cons (format "error: %s exited with signal %s" | |
1078 | (file-name-nondirectory prog) status) | |
1079 | results)) | |
1080 | ;; else collect words into `results' in FIFO order | |
1081 | (goto-char (point-max)) | |
1082 | ;; assure we've ended with \n | |
1083 | (or (bobp) (= (preceding-char) ?\n) (insert ?\n)) | |
1084 | (while (not (bobp)) | |
1085 | (setq loc (point)) | |
1086 | (forward-line -1) | |
1087 | (setq results (cons (buffer-substring (point) (1- loc)) | |
1088 | results))))) | |
1089 | ;; protected | |
1090 | (kill-buffer ispell-grep-buffer) | |
1091 | (if (and results (string-match ".+: " (car results))) | |
1092 | (error "%s error: %s" ispell-grep-command (car results)))) | |
1093 | results)) | |
1094 | ||
1095 | ||
1096 | ;;; "ispell-filter" is a list of output lines from the generating function. | |
1097 | ;;; Each full line (ending with \n) is a separate item on the list. | |
1098 | ;;; "output" can contain multiple lines, part of a line, or both. | |
1099 | ;;; "start" and "end" are used to keep bounds on lines when "output" contains | |
1100 | ;;; multiple lines. | |
1101 | ;;; "ispell-filter-continue" is true when we have received only part of a | |
1102 | ;;; line as output from a generating function ("output" did not end with \n) | |
1103 | ;;; NOTE THAT THIS FUNCTION WILL FAIL IF THE PROCESS OUTPUT DOESNT END WITH \n! | |
1104 | ;;; This is the case when a process dies or fails. The default behavior | |
1105 | ;;; in this case treats the next input received as fresh input. | |
1106 | ||
1107 | (defun ispell-filter (process output) | |
1108 | "Output filter function for ispell, grep, and look." | |
1109 | (let ((start 0) | |
1110 | (continue t) | |
1111 | end) | |
1112 | (while continue | |
1113 | (setq end (string-match "\n" output start)) ; get text up to the newline. | |
1114 | ;; If we get out of sync and ispell-filter-continue is asserted when we | |
1115 | ;; are not continuing, treat the next item as a separate list. When | |
1116 | ;; ispell-filter-continue is asserted, ispell-filter *should* always be a | |
1117 | ;; list! | |
1118 | ||
1119 | ;; Continue with same line (item)? | |
1120 | (if (and ispell-filter-continue ispell-filter (listp ispell-filter)) | |
1121 | ;; Yes. Add it to the prev item | |
1122 | (setcar ispell-filter | |
1123 | (concat (car ispell-filter) (substring output start end))) | |
1124 | ;; No. This is a new line and item. | |
1125 | (setq ispell-filter | |
1126 | (cons (substring output start end) ispell-filter))) | |
1127 | (if (null end) | |
1128 | ;; We've completed reading the output, but didn't finish the line. | |
1129 | (setq ispell-filter-continue t continue nil) | |
1130 | ;; skip over newline, this line complete. | |
1131 | (setq ispell-filter-continue nil end (1+ end)) | |
1132 | (if (= end (length output)) ; No more lines in output | |
1133 | (setq continue nil) ; so we can exit the filter. | |
1134 | (setq start end)))))) ; else move start to next line of input | |
1135 | ||
1136 | ||
1137 | ;;; This function destroys the mark location if it is in the word being | |
1138 | ;;; highlighted. | |
1139 | (defun highlight-spelling-error-generic (start end &optional highlight) | |
1140 | "Highlight the word from START to END by deleting and reinserting it | |
1141 | while toggling the variable \"inverse-video\". When the optional | |
1142 | third arg HIGHLIGHT is set, the word is highlighted otherwise it is | |
1143 | displayed normally." | |
1144 | (let ((modified (buffer-modified-p)) ; don't allow this fn to modify buffer | |
1145 | (buffer-read-only nil) ; Allow highlighting read-only buffers. | |
1146 | (text (buffer-substring start end)) ; Save highlight region | |
1147 | (inhibit-quit t) ; inhibit interrupt processing here. | |
1148 | (buffer-undo-list nil)) ; don't clutter the undo list. | |
1149 | (delete-region start end) | |
1150 | (insert-char ? (- end start)) ; mimimize amount of redisplay | |
1151 | (sit-for 0) ; update display | |
1152 | (if highlight (setq inverse-video (not inverse-video))) ; toggle video | |
1153 | (delete-region start end) ; delete whitespace | |
1154 | (insert text) ; insert text in inverse video. | |
1155 | (sit-for 0) ; update display showing inverse video. | |
1156 | (if highlight (setq inverse-video (not inverse-video))) ; toggle video | |
1157 | (set-buffer-modified-p modified))) ; don't modify if flag not set. | |
1158 | ||
1159 | ||
1160 | (defun highlight-spelling-error-lucid (start end &optional highlight) | |
1161 | "Highlight the word from START to END using isearch-highlight. When | |
1162 | the optional third arg HIGHLIGHT is set, the word is highlighted | |
1163 | otherwise it is displayed normally." | |
1164 | (if highlight | |
1165 | (isearch-highlight start end) | |
1166 | (isearch-dehighlight t)) | |
1167 | ;;(sit-for 0) | |
1168 | ) | |
1169 | ||
1170 | ||
1171 | (defun highlight-spelling-error-overlay (start end &optional highlight) | |
1172 | "Highlight the word from START to END using overlays. When the | |
1173 | optional third arg HIGHLIGHT is set, the word is highlighted otherwise | |
1174 | it is displayed normally. | |
1175 | The variable ispell-highlight-face selects the face that will be used | |
1176 | for highlighting." | |
1177 | (if highlight | |
1178 | (progn | |
1179 | (setq ispell-overlay (make-overlay start end)) | |
1180 | (overlay-put ispell-overlay 'face ispell-highlight-face)) | |
1181 | (delete-overlay ispell-overlay))) | |
1182 | ||
1183 | ||
1184 | ;;; Choose a highlight function at load time. | |
1185 | (fset 'highlight-spelling-error | |
1186 | (symbol-function | |
1187 | (cond | |
1188 | ((string-match "Lucid" emacs-version) 'highlight-spelling-error-lucid) | |
1189 | ((and (string-match "^19\\." emacs-version) | |
1190 | (featurep 'faces)) 'highlight-spelling-error-overlay) | |
1191 | (t 'highlight-spelling-error-generic)))) | |
1192 | ||
1193 | ||
1194 | (defun ispell-overlay-window (height) | |
1195 | "Create a (usually small) window covering the top HEIGHT lines of the | |
1196 | current window. Ensure that the line above point is still visible but | |
1197 | otherwise avoid scrolling the current window. Should leave the old | |
1198 | window selected." | |
1199 | (save-excursion | |
1200 | (let ((oldot (save-excursion (forward-line -1) (point))) | |
1201 | (top (save-excursion (move-to-window-line height) (point)))) | |
1202 | ;; If line above old point (line starting at olddot) would be | |
1203 | ;; hidden by new window, scroll it to just below new win | |
1204 | ;; otherwise set top line of other win so it doesn't scroll. | |
1205 | (if (< oldot top) (setq top oldot)) | |
1206 | (split-window nil height) | |
1207 | (set-window-start (next-window) top)))) | |
1208 | ||
1209 | ||
1210 | ;;; Should we add a compound word match return value? | |
1211 | (defun ispell-parse-output (output) | |
1212 | "Parse the OUTPUT string of 'ispell' and return: | |
1213 | 1: T for an exact match. | |
1214 | 2: A string containing the root word for a match via suffix removal. | |
1215 | 3: A list of possible correct spellings of the format: | |
1216 | '(\"original-word\" offset miss-list guess-list) | |
1217 | original-word is a string of the possibly misspelled word. | |
1218 | offset is an integer giving the line offset of the word. | |
1219 | miss-list and guess-list are possibly null lists of guesses and misses." | |
1220 | (cond | |
1221 | ((string= output "") t) ; for startup with pipes... | |
1222 | ((string= output "*") t) ; exact match | |
1223 | ((string= output "-") t) ; compound word match | |
1224 | ((string= (substring output 0 1) "+") ; found cuz of root word | |
1225 | (substring output 2)) ; return root word | |
1226 | (t ; need to process &, ?, and #'s | |
1227 | (let ((type (substring output 0 1)) ; &, ?, or # | |
1228 | (original-word (substring output 2 (string-match " " output 2))) | |
1229 | (cur-count 0) ; contains number of misses + guesses | |
1230 | count miss-list guess-list offset) | |
1231 | (setq output (substring output (match-end 0))) ; skip over misspelling | |
1232 | (if (string= type "#") | |
1233 | (setq count 0) ; no misses for type # | |
1234 | (setq count (string-to-int output) ; get number of misses. | |
1235 | output (substring output (1+ (string-match " " output 1))))) | |
1236 | (setq offset (string-to-int output)) | |
1237 | (if (string= type "#") ; No miss or guess list. | |
1238 | (setq output nil) | |
1239 | (setq output (substring output (1+ (string-match " " output 1))))) | |
1240 | (while output | |
1241 | (let ((end (string-match ", \\|\\($\\)" output))) ; end of miss/guess. | |
1242 | (setq cur-count (1+ cur-count)) | |
1243 | (if (> cur-count count) | |
1244 | (setq guess-list (cons (substring output 0 end) guess-list)) | |
1245 | (setq miss-list (cons (substring output 0 end) miss-list))) | |
1246 | (if (match-end 1) ; True only when at end of line. | |
1247 | (setq output nil) ; no more misses or guesses | |
1248 | (setq output (substring output (+ end 2)))))) | |
1249 | (list original-word offset miss-list guess-list))))) | |
1250 | ||
1251 | ||
1252 | (defun check-ispell-version () | |
1253 | ;; This is a little wasteful as we actually launch ispell twice: once | |
1254 | ;; to make sure it's the right version, and once for real. But people | |
1255 | ;; get confused by version mismatches *all* the time (and I've got the | |
1256 | ;; email to prove it) so I think this is worthwhile. And the -v[ersion] | |
1257 | ;; option is the only way I can think of to do this that works with | |
1258 | ;; all versions, since versions earlier than 3.0.09 didn't identify | |
1259 | ;; themselves on startup. | |
1260 | ;; | |
1261 | ;; If the ispell.el file ever supports more than one version of the | |
1262 | ;; external ispell program, then this should be reworked to accept more | |
1263 | ;; than one version, but until that happens, doing so would be false | |
1264 | ;; generality. | |
1265 | ;; | |
1266 | (save-excursion | |
1267 | (set-buffer (get-buffer-create " *ispell-tmp*")) | |
1268 | (erase-buffer) | |
1269 | (let ((status (call-process ispell-program-name nil t nil "-v")) | |
1270 | (case-fold-search t)) | |
1271 | (goto-char (point-min)) | |
1272 | (cond ((not (memq status '(0 nil))) | |
1273 | (error "%s exited with %s %s" ispell-program-name | |
1274 | (if (stringp status) "signal" "code") status)) | |
1275 | ((not (re-search-forward | |
1276 | (concat "\\b\\(" | |
1277 | (mapconcat 'regexp-quote | |
1278 | ispell-required-versions | |
1279 | "\\|") | |
1280 | "\\)\\b") | |
1281 | nil t)) | |
1282 | (error "version mismatch: ispell.el is for %s, %s is %s" | |
1283 | (car ispell-required-versions) | |
1284 | ispell-program-name | |
1285 | (if (re-search-forward "version \\([0-9][0-9.]+\\)\\b" | |
1286 | nil t) | |
1287 | (buffer-substring (match-beginning 1) (match-end 1)) | |
1288 | "an unknown version")))) | |
1289 | (kill-buffer (current-buffer))))) | |
1290 | ||
1291 | ||
1292 | (defun ispell-init-process () | |
1293 | "Check status of 'ispell' process and start if necessary." | |
1294 | (if (and ispell-process | |
1295 | (eq (process-status ispell-process) 'run) | |
1296 | ;; If we're using a personal dictionary, assure | |
1297 | ;; we're in the same default directory! | |
1298 | (or (not ispell-personal-dictionary) | |
1299 | (equal ispell-process-directory default-directory))) | |
1300 | (setq ispell-filter nil ispell-filter-continue nil) | |
1301 | ;; may need to restart to select new personal dictionary. | |
1302 | (ispell-kill-ispell t) | |
1303 | (message "Starting new ispell process...") | |
1304 | (sit-for 0) | |
1305 | (check-ispell-version) | |
1306 | (setq ispell-process | |
1307 | (let ((process-connection-type ispell-use-ptys-p)) | |
1308 | (apply 'start-process | |
1309 | "ispell" nil ispell-program-name | |
1310 | "-a" ; accept single input lines | |
1311 | "-m" ; make root/affix combos not in dict | |
1312 | (let (args) | |
1313 | ;; Local dictionary becomes the global dictionary in use. | |
1314 | (if ispell-local-dictionary | |
1315 | (setq ispell-dictionary ispell-local-dictionary)) | |
1316 | (setq args (ispell-get-ispell-args)) | |
1317 | (if ispell-dictionary ; use specified dictionary | |
1318 | (setq args | |
1319 | (append (list "-d" ispell-dictionary) args))) | |
1320 | (if ispell-personal-dictionary ; use specified pers dict | |
1321 | (setq args | |
1322 | (append args | |
1323 | (list "-p" | |
1324 | (expand-file-name | |
1325 | ispell-personal-dictionary))))) | |
1326 | args))) | |
1327 | ispell-filter nil | |
1328 | ispell-filter-continue nil | |
1329 | ispell-process-directory default-directory) | |
1330 | (set-process-filter ispell-process 'ispell-filter) | |
1331 | (accept-process-output ispell-process) ; Get version ID line | |
1332 | (cond ((null ispell-filter) | |
1333 | (error "%s did not output version line")) | |
1334 | ((and (null (cdr ispell-filter)) | |
1335 | (stringp (car ispell-filter)) | |
1336 | (string-match "^@(#) " (car ispell-filter))) | |
1337 | ;; got the version line as expected (we already know it's the right | |
1338 | ;; version, so don't bother checking again.) | |
1339 | nil) | |
1340 | (t | |
1341 | ;; Otherwise, it must be an error message. Show the user. | |
1342 | ;; But first wait to see if some more output is going to arrive. | |
1343 | ;; Otherwise we get cool errors like "Can't open ". | |
1344 | (sleep-for 1) | |
1345 | (accept-process-output) | |
1346 | (error "%s" (mapconcat 'identity ispell-filter "\n")))) | |
1347 | (setq ispell-filter nil) ; Discard version ID line | |
1348 | (let ((extended-char-mode (ispell-get-extended-character-mode))) | |
1349 | (if extended-char-mode | |
1350 | (process-send-string ispell-process | |
1351 | (concat extended-char-mode "\n")))) | |
1352 | (process-kill-without-query ispell-process))) | |
1353 | ||
1354 | ||
829b9e73 | 1355 | ;;;###autoload |
007852e0 RS |
1356 | (defun ispell-kill-ispell (&optional no-error) |
1357 | "Kill current ispell process (so that you may start a fresh one). | |
1358 | With NO-ERROR, just return non-nil if there was no ispell running." | |
1359 | (interactive) | |
1360 | (if (not (and ispell-process | |
1361 | (eq (process-status ispell-process) 'run))) | |
1362 | (or no-error | |
1363 | (error "There is no ispell process running!")) | |
1364 | (kill-process ispell-process) | |
1365 | (setq ispell-process nil) | |
1366 | (message "Killed ispell process.") | |
1367 | nil)) | |
1368 | ||
1369 | ||
1370 | ;;;###autoload | |
1371 | (defun ispell-change-dictionary (dict &optional arg) | |
1372 | "Change ispell-dictionary (q.v.) and kill old ispell process. | |
1373 | A new one will be started as soon as necessary. | |
1374 | ||
1375 | By just answering RET you can find out what the current dictionary is. | |
1376 | ||
1377 | With prefix argument, set the default directory." | |
1378 | (interactive | |
1379 | (list (completing-read | |
1380 | "Use new dictionary (RET for current, SPC to complete): " | |
1381 | (cons (cons "default" nil) ispell-dictionary-alist) nil t) | |
1382 | current-prefix-arg)) | |
1383 | (if (equal dict "default") (setq dict nil)) | |
1384 | ;; This relies on completing-read's bug of returning "" for no match | |
1385 | (cond ((equal dict "") | |
1386 | (message "Using %s dictionary" | |
1387 | (or ispell-local-dictionary ispell-dictionary "default"))) | |
1388 | ((and (equal dict ispell-dictionary) | |
1389 | (equal dict ispell-local-dictionary)) | |
1390 | ;; Specified dictionary is the default already. No-op | |
1391 | (message "No change, using %s dictionary" (or dict "default"))) | |
1392 | (t ; reset dictionary! | |
1393 | (if (assoc dict ispell-dictionary-alist) | |
1394 | (progn | |
1395 | (if (or arg (null dict)) ; set default dictionary | |
1396 | (setq ispell-dictionary dict)) | |
1397 | (if (null arg) ; set local dictionary | |
1398 | (setq ispell-local-dictionary dict))) | |
1399 | (error "Illegal dictionary: %s" dict)) | |
1400 | (ispell-kill-ispell t) | |
1401 | (message "(Next %sispell command will use %s dictionary)" | |
1402 | (cond ((equal ispell-local-dictionary ispell-dictionary) | |
1403 | "") | |
1404 | (arg "global ") | |
1405 | (t "local ")) | |
1406 | (or (if (or (equal ispell-local-dictionary ispell-dictionary) | |
1407 | (null arg)) | |
1408 | ispell-local-dictionary | |
1409 | ispell-dictionary) | |
1410 | "default"))))) | |
1411 | ||
1412 | ||
1413 | ;;; Spelling of comments are checked when ispell-check-comments is non-nil. | |
1414 | ||
1415 | ;;;###autoload | |
1416 | (defun ispell-region (reg-start reg-end) | |
1417 | "Interactively check a region for spelling errors." | |
1418 | (interactive "r") ; Don't flag errors on read-only bufs. | |
1419 | (ispell-accept-buffer-local-defs) ; set up dictionary, local words, etc. | |
1420 | (unwind-protect | |
1421 | (save-excursion | |
1422 | (message "Spelling %s..." | |
1423 | (if (and (= reg-start (point-min)) (= reg-end (point-max))) | |
1424 | (buffer-name) "region")) | |
1425 | (sit-for 0) | |
1426 | ;; must be top level now, not inside ispell-command-loop for keeping window. | |
1427 | (save-window-excursion | |
1428 | (if ispell-keep-choices-win | |
1429 | (let ((window-min-height ispell-choices-win-default-height)) | |
1430 | ;; This keeps the default window size when choices window saved. | |
1431 | (setq ispell-keep-choices-win ispell-choices-win-default-height) | |
1432 | (ispell-overlay-window ispell-choices-win-default-height) | |
1433 | (switch-to-buffer (get-buffer-create ispell-choices-buffer)) | |
1434 | (setq mode-line-format "-- %b --") | |
1435 | (erase-buffer) | |
1436 | (select-window (next-window)) | |
1437 | (sit-for 0))) | |
1438 | (goto-char reg-start) | |
1439 | (let ((transient-mark-mode nil)) | |
1440 | (while (and (not ispell-quit) (< (point) reg-end)) | |
1441 | (let ((start (point)) | |
1442 | (offset-change 0) | |
1443 | (end (save-excursion (end-of-line) (min (point) reg-end))) | |
1444 | (ispell-casechars (ispell-get-casechars)) | |
1445 | string) | |
1446 | (cond ; LOOK AT THIS LINE AND SKIP OR PROCESS | |
1447 | ((eolp) ; END OF LINE, just go to next line. | |
1448 | (forward-char 1)) | |
1449 | ((and (null ispell-check-comments) ; SKIPING COMMENTS | |
1450 | comment-start ; skip comments that start on the line. | |
1451 | (search-forward comment-start end t)) ; a comment is on this line. | |
1452 | (if (= (- (point) start) (length comment-start)) | |
1453 | ;; comment starts the line. We can skip the entire line or region | |
1454 | (if (string= "" comment-end) ; skip to next line over comment | |
1455 | (beginning-of-line 2) | |
1456 | (search-forward comment-end reg-end 'limit)) ; jmp to comment end | |
1457 | ;; Comment starts later on line. Check for spelling before comment. | |
1458 | (let ((limit (- (point) (length comment-start)))) | |
1459 | (goto-char (1- limit)) | |
1460 | (if (looking-at "\\\\") ; "quoted" comment, don't skip | |
1461 | ;; quoted comment. Skip over comment-start and continue. | |
1462 | (if (= start (1- limit)) | |
1463 | (setq limit (+ limit (length comment-start))) | |
1464 | (setq limit (1- limit)))) | |
1465 | (goto-char start) | |
1466 | ;; Only check if there are "casechars" or math chars before comment | |
1467 | (if (or (re-search-forward ispell-casechars limit t) | |
1468 | (re-search-forward "[][()$]" limit t)) | |
1469 | (setq string (concat "^" (buffer-substring start limit) "\n"))) | |
1470 | (goto-char limit)))) | |
1471 | ((and ispell-skip-tib ; SKIP TIB REFERENCES! | |
1472 | (re-search-forward ispell-tib-ref-beginning end t)) | |
1473 | (if (= (- (point) 2) start) ; tib ref is 2 chars. | |
1474 | ;; Skip to end of tib ref, not necessarily on this line. | |
1475 | ;; Return an error if tib ref not found | |
1476 | (if (not (re-search-forward ispell-tib-ref-end reg-end t)) | |
1477 | (progn | |
1478 | (ispell-pdict-save ispell-silently-savep) | |
1479 | (ding) | |
1480 | (message "Open tib reference. Set ispell-skip-tib to nil to avoid this error.") | |
1481 | (setq ispell-quit (- (point) 2)))) ; leave dot at error loc. | |
1482 | ;; tib ref starts later on line. Check spelling before tib. | |
1483 | (let ((limit (- (point) 2))) | |
1484 | (goto-char start) | |
1485 | (if (or (re-search-forward ispell-casechars limit t) | |
1486 | (re-search-forward "[][()$]" limit t)) | |
1487 | (setq string (concat "^" (buffer-substring start limit) "\n"))) | |
1488 | (goto-char limit)))) | |
26add1bf | 1489 | ((looking-at "[-#@*+!%~^]") ; SKIP SPECIAL ISPELL CHARACTERS |
007852e0 RS |
1490 | (forward-char 1)) |
1491 | ((or (re-search-forward ispell-casechars end t) ; TEXT EXISTS... | |
1492 | (re-search-forward "[][()$]" end t)) ; or MATH COMMANDS... | |
1493 | (setq string (concat "^" (buffer-substring start end) "\n")) | |
1494 | (goto-char end)) | |
1495 | (t (beginning-of-line 2))) ; EMPTY LINE, skip it. | |
1496 | ||
1497 | (setq end (point)) ; "end" tracks end of region to check. | |
1498 | ||
1499 | (if string ; there is something to spell! | |
1500 | (let (poss) | |
1501 | ;; send string to spell process and get input. | |
1502 | (process-send-string ispell-process string) | |
1503 | (while (progn | |
1504 | (accept-process-output ispell-process) | |
1505 | ;; Last item of output contains a blank line. | |
1506 | (not (string= "" (car ispell-filter))))) | |
1507 | ;; parse all inputs from the stream one word at a time. | |
1508 | ;; Place in FIFO order and remove the blank item. | |
1509 | (setq ispell-filter (nreverse (cdr ispell-filter))) | |
1510 | (while (and (not ispell-quit) ispell-filter) | |
1511 | (setq poss (ispell-parse-output (car ispell-filter))) | |
1512 | (if (listp poss) ; spelling error occurred. | |
1513 | (let* ((word-start (+ start offset-change (car (cdr poss)))) | |
1514 | (word-end (+ word-start (length (car poss)))) | |
1515 | replace) | |
1516 | (goto-char word-start) | |
1517 | ;; The following lines adjust the horizontal scroll & point | |
1518 | (horiz-scroll) | |
1519 | (goto-char word-end) | |
1520 | (horiz-scroll) | |
1521 | (goto-char word-start) | |
1522 | (horiz-scroll) | |
1523 | (if (/= word-end (progn | |
1524 | (search-forward (car poss) word-end t) | |
1525 | (point))) | |
1526 | ;; This usually occurs due to filter pipe problems | |
1527 | (error "***ispell misalignment: word \"%s\" point %d; please retry." | |
1528 | (car poss) word-start)) | |
1529 | (unwind-protect | |
1530 | (progn | |
1531 | (if ispell-highlight-p | |
1532 | (highlight-spelling-error word-start word-end t)) | |
1533 | (sit-for 0) ; update screen display | |
1534 | (setq replace (ispell-command-loop | |
1535 | (car (cdr (cdr poss))) | |
1536 | (car (cdr (cdr (cdr poss)))) | |
1537 | (car poss)))) | |
1538 | ;; protected | |
1539 | (if ispell-highlight-p | |
1540 | (highlight-spelling-error word-start word-end))) | |
1541 | (cond | |
1542 | ((and replace (listp replace)) | |
1543 | ;; REPLACEMENT WORD entered. Recheck line starting with | |
1544 | ;; the replacement word. | |
1545 | (setq ispell-filter nil | |
1546 | string (buffer-substring word-start word-end)) | |
1547 | (let ((change (- (length (car replace)) ; adjust | |
1548 | (length (car poss))))) ; regions | |
1549 | (setq reg-end (+ reg-end change) | |
1550 | offset-change (+ offset-change change))) | |
1551 | (delete-region word-start word-end) | |
1552 | (insert (car replace)) | |
1553 | ;; I only need to recheck typed-in replacements. | |
1554 | (if (not (eq 'query-replace (car (cdr replace)))) | |
1555 | (backward-char (length (car replace)))) | |
1556 | (setq end (point)) ; reposition in region to recheck | |
1557 | ;; when second arg exists, query-replace, saving regions | |
1558 | (if (car (cdr replace)) | |
1559 | (unwind-protect | |
1560 | (save-window-excursion ; save if help is called. | |
1561 | (set-marker ispell-query-replace-marker reg-end) | |
1562 | ;; Assume case-replace & case-fold-search correct? | |
1563 | (query-replace string (car replace) t)) | |
1564 | ;; protected | |
1565 | (setq reg-end (marker-position | |
1566 | ispell-query-replace-marker)) | |
1567 | (set-marker ispell-query-replace-marker nil)))) | |
1568 | ((or (null replace) (equal 0 replace)) ; ACCEPT/INSERT | |
1569 | (if (equal 0 replace) ; BUFFER-LOCAL DICTIONARY ADD | |
1570 | (setq reg-end (ispell-add-per-file-word-list | |
1571 | (car poss) reg-end))) | |
1572 | ;; This prevents us from pointing out the word that was | |
1573 | ;; just accepted (via 'i' or 'a') if it follows on the | |
1574 | ;; same line. (The drawback of processing entire lines.) | |
1575 | ;; Redo check following the accepted word. | |
1576 | (if (and ispell-pdict-modified-p | |
1577 | (listp ispell-pdict-modified-p)) | |
1578 | ;; We have accepted or inserted a word. Re-check line | |
1579 | (setq ispell-pdict-modified-p ; fix update flag | |
1580 | (car ispell-pdict-modified-p) | |
1581 | ispell-filter nil ; don't continue check. | |
1582 | end word-start))) ; reposition continue loc | |
1583 | (replace ; STRING REPLACEMENT for this word. | |
1584 | (delete-region word-start word-end) | |
1585 | (insert replace) | |
1586 | (let ((change (- (length replace) (length (car poss))))) | |
1587 | (setq reg-end (+ reg-end change) | |
1588 | offset-change (+ offset-change change) | |
1589 | end (+ end change))))) | |
1590 | (if (not ispell-quit) | |
1591 | (message "continuing spelling check...")) | |
1592 | (sit-for 0))) | |
1593 | (setq ispell-filter (cdr ispell-filter))))) ; finished with line | |
1594 | (goto-char end))))) | |
1595 | (not ispell-quit)) | |
1596 | ;; protected | |
1597 | (if (get-buffer ispell-choices-buffer) | |
1598 | (kill-buffer ispell-choices-buffer)) | |
1599 | (if ispell-quit | |
1600 | (progn | |
1601 | ;; preserve or clear the region for ispell-continue. | |
1602 | (if (not (numberp ispell-quit)) | |
1603 | (set-marker ispell-region-end nil) | |
1604 | ;; Enable ispell-continue. | |
1605 | (set-marker ispell-region-end reg-end) | |
1606 | (goto-char ispell-quit)) | |
1607 | ;; Check for aborting | |
1608 | (if (and ispell-checking-message (numberp ispell-quit)) | |
1609 | (progn | |
1610 | (setq ispell-quit nil) | |
1611 | (error "Message send aborted."))) | |
1612 | (setq ispell-quit nil)) | |
1613 | (set-marker ispell-region-end nil) | |
1614 | ;; Only save if successful exit. | |
1615 | (ispell-pdict-save ispell-silently-savep) | |
1616 | (message "Spell done.")))) | |
1617 | ||
1618 | ||
1619 | ||
1620 | ;;;###autoload | |
1621 | (defun ispell-buffer () | |
1622 | "Check the current buffer for spelling errors interactively." | |
1623 | (interactive) | |
1624 | (ispell-region (point-min) (point-max))) | |
1625 | ||
829b9e73 | 1626 | ;;;###autoload |
007852e0 RS |
1627 | (defun ispell-continue () |
1628 | (interactive) | |
1629 | "Continue a spelling session after making some changes." | |
1630 | (if (not (marker-position ispell-region-end)) | |
1631 | (message "No session to continue. Use 'X' command when checking!") | |
1632 | (if (not (equal (marker-buffer ispell-region-end) (current-buffer))) | |
1633 | (message "Must continue ispell from buffer %s" | |
1634 | (buffer-name (marker-buffer ispell-region-end))) | |
1635 | (ispell-region (point) (marker-position ispell-region-end))))) | |
1636 | ||
1637 | ||
1638 | ;;; Horizontal scrolling | |
1639 | (defun horiz-scroll () | |
1640 | "This function checks if the point is within the horizontal | |
1641 | visibility of its window area." | |
1642 | (if truncate-lines ; display truncating lines? | |
1643 | ;; See if display needs to be scrolled. | |
1644 | (let ((column (- (current-column) (max (window-hscroll) 1)))) | |
1645 | (if (and (< column 0) (> (window-hscroll) 0)) | |
1646 | (scroll-right (max (- column) 10)) | |
1647 | (if (>= column (- (window-width) 2)) | |
1648 | (scroll-left (max (- column (window-width) -3) 10))))))) | |
1649 | ||
1650 | ||
1651 | ;;; Interactive word completion. | |
1652 | ;;; Forces "previous-word" processing. Do we want to make this selectable? | |
1653 | ||
1654 | ;;;###autoload | |
1655 | (defun ispell-complete-word (&optional interior-frag) | |
1656 | "Look up word before or under point in dictionary (see lookup-words command) | |
1657 | and try to complete it. If optional INTERIOR-FRAG is non-nil then the word | |
1658 | may be a character sequence inside of a word. | |
1659 | ||
1660 | Standard ispell choices are then available." | |
1661 | (interactive "P") | |
1662 | (let ((cursor-location (point)) | |
1663 | ispell-keep-choices-win | |
1664 | (word (ispell-get-word nil "\\*")) ; force "previous-word" processing. | |
1665 | start end possibilities replacement) | |
1666 | (setq start (car (cdr word)) | |
1667 | end (car (cdr (cdr word))) | |
1668 | word (car word) | |
1669 | possibilities | |
1670 | (or (string= word "") ; Will give you every word | |
1671 | (lookup-words (concat (if interior-frag "*") word "*") | |
1672 | ispell-complete-word-dict))) | |
1673 | (cond ((eq possibilities t) | |
1674 | (message "No word to complete")) | |
1675 | ((null possibilities) | |
1676 | (message "No match for \"%s\"" word)) | |
1677 | (t ; There is a modification... | |
1678 | (unwind-protect | |
1679 | (progn | |
1680 | (if ispell-highlight-p | |
1681 | (highlight-spelling-error start end t)) ; highlight word | |
1682 | (setq replacement (ispell-command-loop possibilities nil word))) | |
1683 | ;; protected | |
1684 | (if ispell-highlight-p | |
1685 | (highlight-spelling-error start end))) ; un-highlight | |
1686 | (cond | |
1687 | ((equal 0 replacement) ; BUFFER-LOCAL ADDITION | |
1688 | (ispell-add-per-file-word-list word)) | |
1689 | (replacement ; REPLACEMENT WORD | |
1690 | (delete-region start end) | |
1691 | (setq word (if (atom replacement) replacement (car replacement)) | |
1692 | cursor-location (+ (- (length word) (- end start)) | |
1693 | cursor-location)) | |
1694 | (insert word) | |
1695 | (if (not (atom replacement)) ; recheck spelling of replacement. | |
1696 | (progn | |
1697 | (goto-char cursor-location) | |
1698 | (ispell-word nil t))))) | |
1699 | (if (get-buffer ispell-choices-buffer) | |
1700 | (kill-buffer ispell-choices-buffer)))) | |
1701 | (ispell-pdict-save ispell-silently-savep) | |
1702 | (goto-char cursor-location))) | |
1703 | ||
1704 | ||
1705 | ;;;###autoload | |
1706 | (defun ispell-complete-word-interior-frag () | |
1707 | "Runs `ispell-complete-word' assuming that the word is a character sequence | |
1708 | inside of a word." | |
1709 | (interactive) | |
1710 | (ispell-complete-word t)) | |
1711 | ||
1712 | ||
1713 | ;;; ********************************************************************** | |
1714 | ;;; Ispell Message | |
1715 | ;;; ********************************************************************** | |
7492978d RS |
1716 | ;;; Original from D. Quinlan, E. Bradford, A. Albert, and M. Ernst |
1717 | ||
1718 | ||
1719 | (defvar ispell-message-text-end | |
1720 | (mapconcat (function identity) | |
1721 | '( | |
1722 | ;; Matches postscript files. | |
1723 | "^%!PS-Adobe-2.0" | |
1724 | ;; Matches uuencoded text | |
1725 | "^begin [0-9][0-9][0-9] .*\nM.*\nM.*\nM" | |
1726 | ;; Matches shell files (esp. auto-decoding) | |
1727 | "^#! /bin/sh" | |
1728 | ;; Matches difference listing | |
1729 | "diff -c .*\n\\*\\*\\* .*\n--- " | |
1730 | ;; Matches "----------------- cut here" | |
1731 | "^[-=]+\\s cut here") | |
1732 | "\\|") | |
1733 | "*End of text which will be checked in ispell-message. | |
1734 | If it is a string, limit at first occurence of that regular expression. | |
1735 | Otherwise, it must be a function which is called to get the limit.") | |
007852e0 RS |
1736 | |
1737 | ;;;###autoload | |
1738 | (defun ispell-message () | |
1739 | "Check the spelling of a mail message or news post. | |
1740 | Don't check spelling of message headers except the Subject field. | |
1741 | Don't check included messages. | |
1742 | ||
1743 | To abort spell checking of a message REGION and send the message anyway, | |
1744 | use the 'x' or 'q' command. (Any subsequent regions will be checked.) | |
1745 | The 'X' command aborts the message send so that you can edit the buffer. | |
1746 | ||
1747 | To spell-check whenever a message is sent, include the appropriate lines | |
1748 | in your .emacs file: | |
1749 | (add-hook 'news-inews-hook 'ispell-message) | |
1750 | (add-hook 'mail-send-hook 'ispell-message) | |
1751 | (add-hook 'mh-before-send-letter-hook 'ispell-message) | |
1752 | ||
1753 | Or you can bind the function C-c i in gnus or mail by setting | |
1754 | news-reply-mode-hook or mail-mode-hook to the following lambda expression: | |
1755 | (function (lambda () (local-set-key \"\\C-ci\" 'ispell-message)))" | |
1756 | (interactive) | |
7492978d RS |
1757 | (save-excursion |
1758 | (beginning-of-buffer) | |
1759 | (let* ((internal-messagep | |
1760 | (search-forward mail-header-separator nil t)) | |
ae9fdfe5 | 1761 | (limit (copy-marker |
7492978d RS |
1762 | (cond |
1763 | ((not ispell-message-text-end) (point-max)) | |
1764 | ((char-or-string-p ispell-message-text-end) | |
1765 | (if (re-search-forward ispell-message-text-end nil t) | |
1766 | (match-beginning 0) | |
1767 | (point-max))) | |
ae9fdfe5 | 1768 | (t (min (point-max) (funcall ispell-message-text-end)))))) |
7492978d RS |
1769 | (cite-regexp ;Prefix of inserted text |
1770 | (cond | |
1771 | ((featurep 'supercite) ; sc 3.0 | |
1772 | (concat "\\(" (sc-cite-regexp) "\\)" "\\|" | |
1773 | (ispell-non-empty-string sc-reference-tag-string))) | |
1774 | ((featurep 'sc) ; sc 2.3 | |
1775 | (concat "\\(" sc-cite-regexp "\\)" "\\|" | |
1776 | (ispell-non-empty-string sc-reference-tag-string))) | |
1777 | ((equal major-mode 'news-reply-mode) ;Gnus | |
1778 | (concat "In article <" "\\|" | |
1779 | (if mail-yank-prefix | |
1780 | (ispell-non-empty-string mail-yank-prefix) | |
1781 | "^ \\|^\t"))) | |
1782 | ((equal major-mode 'mh-letter-mode) ; mh mail message | |
1783 | (ispell-non-empty-string mh-ins-buf-prefix)) | |
1784 | ((not internal-messagep) ; Assume nn sent us this message. | |
1785 | (concat "In [a-zA-Z.]+ you write:" "\\|" | |
1786 | "In <[^,;&+=]+> [^,;&+=]+ writes:" "\\|" | |
1787 | " *> *")) | |
1788 | ((boundp 'vm-included-text-prefix) ; VM mail message | |
1789 | (concat "[^,;&+=]+ writes:" "\\|" | |
1790 | (ispell-non-empty-string vm-included-text-prefix))) | |
1791 | (mail-yank-prefix ; vanilla mail message. | |
1792 | (ispell-non-empty-string mail-yank-prefix)) | |
1793 | (t "^ \\|^\t"))) | |
007852e0 RS |
1794 | (cite-regexp-start (concat "^[ \t]*$\\|" cite-regexp)) |
1795 | (cite-regexp-end (concat "^\\(" cite-regexp "\\)")) | |
1796 | (old-case-fold-search case-fold-search) | |
1797 | (case-fold-search t) | |
1798 | (ispell-checking-message t)) | |
1799 | (save-excursion | |
1800 | (beginning-of-buffer) | |
1801 | ;; Skip header fields except Subject: without Re:'s | |
1802 | ;;(search-forward mail-header-separator nil t) | |
1803 | (while (if internal-messagep | |
1804 | (< (point) internal-messagep) | |
26add1bf | 1805 | (and (looking-at "[-a-zA-Z]+:\\|\t\\| ") |
007852e0 | 1806 | (not (eobp)))) |
7492978d RS |
1807 | |
1808 | ;; spell check Subject: field without Re:'s. | |
1809 | (if (looking-at "Subject: *") | |
1810 | (progn | |
1811 | (goto-char (match-end 0)) | |
1812 | (if (and (not (looking-at ".*Re\\>")) | |
1813 | (not (looking-at "\\["))) | |
1814 | (let ((case-fold-search old-case-fold-search)) | |
1815 | (ispell-region (point) | |
1816 | (progn | |
1817 | (end-of-line) | |
1818 | (while (looking-at "\n[ \t]") | |
1819 | (end-of-line 2)) | |
1820 | (point))))))) | |
007852e0 RS |
1821 | (forward-line 1)) |
1822 | (setq case-fold-search nil) | |
1823 | ;; Skip mail header, particularly for non-english languages. | |
1824 | (if (looking-at mail-header-separator) | |
1825 | (forward-line 1)) | |
7492978d | 1826 | (while (< (point) limit) |
007852e0 RS |
1827 | ;; Skip across text cited from other messages. |
1828 | (while (and (looking-at cite-regexp-start) | |
7492978d | 1829 | (< (point) limit)) |
007852e0 | 1830 | (forward-line 1)) |
7492978d | 1831 | (if (< (point) limit) |
007852e0 RS |
1832 | ;; Check the next batch of lines that *aren't* cited. |
1833 | (let ((end (save-excursion | |
7492978d RS |
1834 | (if (re-search-forward cite-regexp-end limit 'end) |
1835 | (match-beginning 0) | |
29491e32 | 1836 | (marker-position limit))))) |
007852e0 | 1837 | (ispell-region (point) end) |
ae9fdfe5 RS |
1838 | (goto-char end))))) |
1839 | (set-marker limit nil)))) | |
007852e0 RS |
1840 | |
1841 | (defun ispell-non-empty-string (string) | |
1842 | (if (or (not string) (string-equal string "")) | |
1843 | "\\'\\`" ; An unmatchable string if string is null. | |
1844 | (regexp-quote string))) | |
1845 | ||
1846 | ||
1847 | ;;; ********************************************************************** | |
1848 | ;;; Buffer Local Functions | |
1849 | ;;; ********************************************************************** | |
1850 | ||
1851 | ||
1852 | (defun ispell-accept-buffer-local-defs () | |
1853 | "Loads all buffer-local information, restarting ispell when necessary." | |
1854 | (ispell-buffer-local-dict) ; May kill ispell-process. | |
1855 | (ispell-buffer-local-words) ; Will initialize ispell-process. | |
1856 | (ispell-buffer-local-parsing)) | |
1857 | ||
1858 | ||
1859 | ;;; Currently ispell version 3.0.09 (beta) doesn't fully support the "~" | |
1860 | ;;; pipe mode command. Should be fixed in the next release. | |
1861 | ||
1862 | (defun ispell-buffer-local-parsing () | |
1863 | "Places ispell into parsing mode for this buffer. | |
1864 | This overrides the default parsing mode. | |
1865 | This includes latex/nroff modes and extended character mode." | |
1866 | ;; (ispell-init-process) must already be called. | |
1867 | (process-send-string ispell-process "!\n") ; Put process in terse mode. | |
1868 | ;; We assume all major modes with "tex-mode" in them should use latex parsing | |
1869 | (if (or (and (eq ispell-parser 'use-mode-name) | |
1870 | (string-match "[Tt][Ee][Xx]-mode" (symbol-name major-mode))) | |
1871 | (eq ispell-parser 'tex)) | |
1872 | (process-send-string ispell-process "+\n") ; set ispell mode to tex | |
1873 | (process-send-string ispell-process "-\n")) ; set mode to normal (nroff) | |
1874 | ;; Set default extended character mode for given buffer, if any. | |
1875 | (let ((extended-char-mode (ispell-get-extended-character-mode))) | |
1876 | (if extended-char-mode | |
1877 | (process-send-string ispell-process (concat extended-char-mode "\n")))) | |
1878 | ;; Set buffer-local parsing mode and extended charater mode, if specified. | |
1879 | (save-excursion | |
1880 | (goto-char (point-min)) | |
1881 | ;; Uses last valid definition | |
1882 | (while (search-forward ispell-parsing-keyword nil t) | |
1883 | (let ((end (save-excursion (end-of-line) (point))) | |
1884 | (case-fold-search t) | |
1885 | string) | |
1886 | (while (re-search-forward " *\\([^ \"]+\\)" end t) | |
1887 | ;; space separated definitions. | |
1888 | (setq string (buffer-substring (match-beginning 1) (match-end 1))) | |
1889 | (cond ((string-match "latex-mode" string) | |
1890 | (process-send-string ispell-process "+\n")) | |
1891 | ((string-match "nroff-mode" string) | |
1892 | (process-send-string ispell-process "-\n")) | |
1893 | ((string-match "~" string) ; Set extended character mode. | |
1894 | (process-send-string ispell-process (concat string "\n"))) | |
1895 | (t (message "Illegal Ispell Parsing argument!") | |
1896 | (sit-for 2)))))))) | |
1897 | ||
1898 | ||
1899 | ;;; Can kill the current ispell process | |
1900 | ||
1901 | (defun ispell-buffer-local-dict () | |
1902 | "Does necessary local dictionary initialization. | |
1903 | When a dictionary is defined in the buffer (see variable | |
1904 | ispell-dictionary-keyword), it will override the local setting | |
1905 | from \\[ispell-change-dictionary]. | |
1906 | Both should not be used to define a buffer-local dictionary." | |
1907 | (save-excursion | |
1908 | (goto-char (point-min)) | |
1909 | (let (end) | |
1910 | ;; Override the local variable definition. | |
1911 | ;; Uses last valid definition. | |
1912 | (while (search-forward ispell-dictionary-keyword nil t) | |
1913 | (setq end (save-excursion (end-of-line) (point))) | |
1914 | (if (re-search-forward " *\\([^ \"]+\\)" end t) | |
1915 | (setq ispell-local-dictionary | |
1916 | (buffer-substring (match-beginning 1) (match-end 1))))) | |
1917 | (goto-char (point-min)) | |
1918 | (while (search-forward ispell-pdict-keyword nil t) | |
1919 | (setq end (save-excursion (end-of-line) (point))) | |
1920 | (if (re-search-forward " *\\([^ \"]+\\)" end t) | |
1921 | (setq ispell-local-pdict | |
1922 | (buffer-substring (match-beginning 1) (match-end 1))))))) | |
1923 | ;; Reload if new personal dictionary defined. | |
1924 | (if (and ispell-local-pdict | |
1925 | (not (equal ispell-local-pdict ispell-personal-dictionary))) | |
1926 | (progn | |
1927 | (ispell-kill-ispell t) | |
1928 | (setq ispell-personal-dictionary ispell-local-pdict))) | |
1929 | ;; Reload if new dictionary defined. | |
1930 | (if (and ispell-local-dictionary | |
1931 | (not (equal ispell-local-dictionary ispell-dictionary))) | |
1932 | (ispell-change-dictionary ispell-local-dictionary))) | |
1933 | ||
1934 | ||
1935 | (defun ispell-buffer-local-words () | |
1936 | "Loads the buffer-local \"dictionary\" in the current buffer." | |
1937 | (if (and ispell-buffer-local-name | |
1938 | (not (equal ispell-buffer-local-name (buffer-name)))) | |
1939 | (progn | |
1940 | (ispell-kill-ispell t) | |
1941 | (setq ispell-buffer-local-name nil))) | |
1942 | (ispell-init-process) | |
1943 | (save-excursion | |
1944 | (goto-char (point-min)) | |
1945 | (while (search-forward ispell-words-keyword nil t) | |
1946 | (or ispell-buffer-local-name | |
1947 | (setq ispell-buffer-local-name (buffer-name))) | |
1948 | (let ((end (save-excursion (end-of-line) (point))) | |
1949 | string) | |
1950 | (while (re-search-forward " *\\([^ \"]+\\)" end t) | |
1951 | (setq string (buffer-substring (match-beginning 1) (match-end 1))) | |
1952 | (process-send-string | |
1953 | ispell-process (concat "@" (buffer-substring (match-beginning 1) | |
1954 | (match-end 1)) | |
1955 | "\n"))))))) | |
1956 | ||
1957 | ||
1958 | ;;; returns optionally adjusted region-end-point. | |
1959 | ||
1960 | (defun ispell-add-per-file-word-list (word &optional reg-end) | |
1961 | "Adds new word to the per-file word list." | |
1962 | (or ispell-buffer-local-name | |
1963 | (setq ispell-buffer-local-name (buffer-name))) | |
1964 | (if (null reg-end) | |
1965 | (setq reg-end 0)) | |
1966 | (save-excursion | |
1967 | (goto-char (point-min)) | |
1968 | (let ((case-fold-search nil) | |
1969 | line-okay search done string) | |
1970 | (while (not done) | |
1971 | (setq search (search-forward ispell-words-keyword nil 'move) | |
1972 | line-okay (< (+ (length word) 1 ; 1 for space after word.. | |
1973 | (progn (end-of-line) (current-column))) | |
1974 | 80)) | |
1975 | (if (or (and search line-okay) | |
1976 | (null search)) | |
1977 | (progn | |
1978 | (setq done t) | |
1979 | (if (null search) | |
1980 | (progn | |
1981 | (open-line 1) | |
1982 | (setq string (concat comment-start " " | |
1983 | ispell-words-keyword)) | |
1984 | ;; in case the keyword is in the middle of the file.... | |
1985 | (if (> reg-end (point)) | |
1986 | (setq reg-end (+ reg-end (length string)))) | |
1987 | (insert string) | |
1988 | (if (and comment-end (not (equal "" comment-end))) | |
1989 | (save-excursion | |
1990 | (open-line 1) | |
1991 | (forward-line 1) | |
1992 | (insert comment-end))))) | |
1993 | (if (> reg-end (point)) | |
1994 | (setq reg-end (+ 1 reg-end (length word)))) | |
1995 | (insert (concat " " word))))))) | |
1996 | reg-end) | |
1997 | ||
1998 | ||
1999 | (defconst ispell-version "2.26 Tue Feb 15 16:11:14 MST 1994") | |
2000 | ||
2001 | (provide 'ispell) | |
2002 | ||
2003 | \f | |
2004 | ;;; LOCAL VARIABLES AND BUFFER-LOCAL VALUE EXAMPLES. | |
2005 | ||
2006 | ;;; Local Variable options: | |
2007 | ;;; mode: name(-mode) | |
2008 | ;;; eval: expression | |
2009 | ;;; local-variable: value | |
2010 | ||
2011 | ;;; The following sets the buffer local dictionary to english! | |
2012 | ||
2013 | ;;; Local Variables: | |
2014 | ;;; mode: emacs-lisp | |
2015 | ;;; comment-column: 40 | |
2016 | ;;; ispell-local-dictionary: "english" | |
2017 | ;;; End: | |
2018 | ||
2019 | ||
2020 | ;;; MORE EXAMPLES OF ISPELL BUFFER-LOCAL VALUES | |
2021 | ||
2022 | ;;; The following places this file in nroff parsing and extended char modes. | |
2023 | ;;; Local IspellParsing: nroff-mode ~nroff | |
2024 | ;;; Change IspellDict to IspellDict: to enable the following line. | |
2025 | ;;; Local IspellDict english | |
2026 | ;;; Change IspellPersDict to IspellPersDict: to enable the following line. | |
2027 | ;;; Local IspellPersDict ~/.ispell_lisp | |
2028 | ;;; The following were automatically generated by ispell using the 'A' command: | |
2029 | ; LocalWords: ispell ispell-highlight-p ispell-check-comments query-replace | |
2030 | ; LocalWords: ispell-query-replace-choices ispell-skip-tib non-nil tib | |
2031 | ; LocalWords: regexps ispell-tib-ref-beginning ispell-tib-ref-end | |
2032 | ||
2033 | ;; ispell.el ends here |