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