Add arch taglines
[bpt/emacs.git] / lisp / textmodes / ispell.el
1 ;;; ispell.el --- interface to International Ispell Versions 3.1 and 3.2
2
3 ;; Copyright (C) 1994, 1995, 1997, 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
4
5 ;; Author: Ken Stevens <k.stevens@ieee.org>
6 ;; Maintainer: Ken Stevens <k.stevens@ieee.org>
7 ;; Stevens Mod Date: Mon Jan 7 12:32:44 PST 2003
8 ;; Stevens Revision: 3.6
9 ;; Status : Release with 3.1.12+ and 3.2.0+ ispell.
10 ;; Bug Reports : ispell-el-bugs@itcorp.com
11 ;; Web Site : http://kdstevens.com/~stevens/ispell-page.html
12 ;; Keywords: unix wp
13
14 ;; This file is part of GNU Emacs.
15
16 ;; GNU Emacs is free software; you can redistribute it and/or modify
17 ;; it under the terms of the GNU General Public License as published by
18 ;; the Free Software Foundation; either version 2, or (at your option)
19 ;; any later version.
20
21 ;; GNU Emacs is distributed in the hope that it will be useful,
22 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 ;; GNU General Public License for more details.
25
26 ;; You should have received a copy of the GNU General Public License
27 ;; along with GNU Emacs; see the file COPYING. If not, write to the
28 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
29 ;; Boston, MA 02111-1307, USA.
30
31 ;; Note: version numbers and time stamp are not updated
32 ;; when this file is edited for release with GNU emacs.
33
34 ;;; Commentary:
35
36 ;; INSTRUCTIONS
37
38 ;; This code contains a section of user-settable variables that you
39 ;; should inspect prior to installation. Look past the end of the history
40 ;; list. Set them up for your locale and the preferences of the majority
41 ;; of the users. Otherwise the users may need to set a number of variables
42 ;; themselves.
43 ;; You particularly may want to change the default dictionary for your
44 ;; country and language.
45 ;; Most dictionary changes should be made in this file so all users can
46 ;; enjoy them. Local or modified dictionaries are supported in your .emacs
47 ;; file. Modify the variable `ispell-local-dictionary-alist' to include
48 ;; these dictionaries, and they will be installed when ispell.el is loaded.
49
50 ;; Depending on the mail system you use, you may want to include these:
51 ;; (add-hook 'news-inews-hook 'ispell-message)
52 ;; (add-hook 'mail-send-hook 'ispell-message)
53 ;; (add-hook 'mh-before-send-letter-hook 'ispell-message)
54
55 ;; Ispell has a TeX parser and a nroff parser (the default).
56 ;; The parsing is controlled by the variable ispell-parser. Currently
57 ;; it is just a "toggle" between TeX and nroff, but if more parsers are
58 ;; added it will be updated. See the variable description for more info.
59
60
61 ;; TABLE OF CONTENTS
62
63 ;; ispell-word
64 ;; ispell-region
65 ;; ispell-buffer
66 ;; ispell-message
67 ;; ispell-comments-and-strings
68 ;; ispell-continue
69 ;; ispell-complete-word
70 ;; ispell-complete-word-interior-frag
71 ;; ispell-change-dictionary
72 ;; ispell-kill-ispell
73 ;; ispell-pdict-save
74 ;; ispell-skip-region-alist
75
76 ;; Commands in ispell-region:
77 ;; Character replacement: Replace word with choice. May query-replace.
78 ;; ` ': Accept word this time.
79 ;; `i': Accept word and insert into private dictionary.
80 ;; `a': Accept word for this session.
81 ;; `A': Accept word and place in buffer-local dictionary.
82 ;; `r': Replace word with typed-in value. Rechecked.
83 ;; `R': Replace word with typed-in value. Query-replaced in buffer. Rechecked.
84 ;; `?': Show these commands
85 ;; `x': Exit spelling buffer. Move cursor to original point.
86 ;; `X': Exit spelling buffer. Leaves cursor at the current point, and permits
87 ;; the check to be completed later.
88 ;; `q': Quit spelling session (Kills ispell process).
89 ;; `l': Look up typed-in replacement in alternate dictionary. Wildcards okay.
90 ;; `u': Like `i', but the word is lower-cased first.
91 ;; `m': Place entered value in personal dictionary, then recheck current word.
92 ;; `C-l': redraws screen
93 ;; `C-r': recursive edit
94 ;; `C-z': suspend emacs or iconify frame
95
96 ;; Buffer-Local features:
97 ;; There are a number of buffer-local features that can be used to customize
98 ;; ispell for the current buffer. This includes language dictionaries,
99 ;; personal dictionaries, parsing, and local word spellings. Each of these
100 ;; local customizations are done either through local variables, or by
101 ;; including the keyword and argument(s) at the end of the buffer (usually
102 ;; prefixed by the comment characters). See the end of this file for
103 ;; examples. The local keywords and variables are:
104
105 ;; ispell-dictionary-keyword language-dictionary
106 ;; uses local variable ispell-local-dictionary
107 ;; ispell-pdict-keyword personal-dictionary
108 ;; uses local variable ispell-local-pdict
109 ;; ispell-parsing-keyword mode-arg extended-char-arg
110 ;; ispell-words-keyword any number of local word spellings
111
112 ;; Region skipping:
113 ;; Place new regular expression definitions of regions you prefer not to
114 ;; spell check in `ispell-skip-region-alist'. Mode-dependent features can
115 ;; be added to latex by modifying `ispell-tex-skip-alists'.
116 ;; `ispell-message' contains some custom skipping code for e-mail messages.
117
118 ;; BUGS:
119 ;; Need a way to select between different character mappings without separate
120 ;; dictionary entries.
121 ;; Multi-byte characters if not defined by current dictionary may result in the
122 ;; evil "misalignment error" in some versions of MULE emacs.
123 ;; On some versions of emacs, growing the minibuffer fails.
124 ;; see `ispell-help-in-bufferp'.
125 ;; Recursive edits (?C-r or ?R) inside a keyboard text replacement check (?r)
126 ;; can cause misalignment errors.
127
128 ;; HISTORY
129
130 ;; Modifications made in latest versions:
131
132 ;; Revision 3.6 2003/01/07 12:32:44 kss
133 ;; Removed extra -d LIB in dictionary defs. (Pavel Janik)
134 ;; Filtered process calls with duplicate dictionary entries.
135 ;; Fixed bug where message-text-end is inside a mime skipped region.
136 ;; Minor fixes to get ispell menus right in XEmacs
137 ;; Fixed skip regexp so it doesn't match stuff like `/.\w'.
138 ;; Detecting dictionary change not working. Fixed. kss
139 ;; function `ispell-change-dictionary' now only completes valid dicts.
140
141 ;; Revision 3.5 2001/7/11 18:43:57 kss
142 ;; Added fix for aspell to work in XEmacs (ispell-check-version).
143 ;; Added Portuguese dictionary definition.
144 ;; New feature: MIME mail message support, Fcc support.
145 ;; Bug fix: retain comment syntax on lines with region skipping. (TeX $ bug...)
146 ;; Improved allocation for graphic mode lines. (Miles Bader)
147 ;; Support -v flag for old versions of aspell. (Eli Zaretskii)
148 ;; Clear minibuffer on ^G from ispell-help (Tak Ota)
149
150 ;; Revision 3.4 2000/8/4 09:41:50 kss
151 ;; Support new color display functions.
152 ;; Fixed misalignment offset bug when replacing a string after a shift made.
153 ;; Set to standard Author/Maintainer heading,
154 ;; ensure localwords lists are separated from the text by newline. (Dave Love)
155 ;; Added dictionary definition for Italian (William Deakin)
156 ;; HTML region skipping greatly improved. (Chuck D. Phillips)
157 ;; improved menus. Fixed regexp matching http/email addresses.
158 ;; one arg always for xemacs sleep-for (gunnar Evermann)
159 ;; support for synchronous processes (Eli Zaretskii)
160
161 ;; Revision 3.3 1999/11/29 11:38:34 kss
162 ;; Only word replacements entered in from the keyboard are rechecked.
163 ;; This fixes a bug in tex parsing and misalignment.
164 ;; Exceptions exist for recursive edit and query-replace, with tex error
165 ;; condition tested. Recursive editing improved.
166 ;; XEmacs repair for when `enable-multibyte-characters' defined - Didier Verna.
167 ;; ispell-help fixed for XEmacs. Choices minibuffer now displayed in XEmacs.
168 ;; Only list valid dictionaries in Spell menu. Russian dictionary doesn't allow
169 ;; run-together words, and uses koi8-r font. Don't skip text in html <TT>
170 ;; fonts.
171
172 ;; Revision 3.2 1999/5/7 14:25:14 kss
173 ;; Accept ispell versions 3.X.Y where X>=1
174 ;; fine tuned latex region skipping. Fixed bug in ispell-word that did not
175 ;; point in right place on words < 2 chars. Simplified ispell-minor-mode.
176 ;; Fixed bug in TeX parsing when math commands are in the comments.
177 ;; Removed calls to `when' macro.
178
179 ;; Revision 3.1 1998/12/1 13:21:52 kss
180 ;; Improved and fixed customize support.
181 ;; Improved and fixed comments in variables and messages.
182 ;; A coding system is now required for all languages.
183 ;; casechars improved for castellano, castellano8, and norsk dictionaries.
184 ;; Dictionary norsk7-tex removed. Dictionary polish added.
185 ;; Dictionaries redefined at load-time to support dictionary changes.
186 ;; Menu redefined at load time to support dictionary changes.
187 ;; ispell-check-version added as an alias for `check-ispell-version'.
188 ;; Spelling suggestions returned in order generated by ispell.
189 ;; Small bug fixed in matching ispell error messages.
190 ;; Robustness added to ensure `case-fold-search' doesn't get redefined.
191 ;; Fixed bug that didn't respect case of word in `ispell-complete-word'.
192 ;; Multibyte character coding support added for process interactions.
193 ;; Ensure ispell process has terminated before starting new process.
194 ;; This can otherwise confuse process filters and hang ispell.
195 ;; Improved skipping support for SGML.
196 ;; Fixed bug using ^M rather than \r in `ispell-minor-check'.
197 ;; Improved message reference matching in `ispell-message'.
198 ;; Fixed bug in returning to nroff mode from tex mode.
199
200
201 ;;; Code:
202
203 ;;; Custom.el macros require recompiling this when they are not present.
204 ;;; Add in backward compatible custom support.
205 (eval-when-compile
206 (if (not (fboundp 'defcustom))
207 (defmacro defcustom (symbol value doc &rest args)
208 "Empty replacement for defcustom when not supplied."
209 `(defvar ,symbol ,value ,doc))))
210
211 (eval-when-compile
212 (if (not (fboundp 'defgroup))
213 (defmacro defgroup (&rest args)
214 "Empty replacement for defgroup when not supplied.")))
215
216 (defgroup ispell nil
217 "User variables for emacs ispell interface."
218 :group 'applications)
219
220 (if (not (fboundp 'buffer-substring-no-properties))
221 (defun buffer-substring-no-properties (start end)
222 (buffer-substring start end)))
223
224 (defalias 'check-ispell-version 'ispell-check-version)
225
226 ;;; **********************************************************************
227 ;;; The following variables should be set according to personal preference
228 ;;; and location of binaries:
229 ;;; **********************************************************************
230
231
232 ;;; ******* THIS FILE IS WRITTEN FOR ISPELL VERSION 3.1+
233
234 (defcustom ispell-highlight-p 'block
235 "*Highlight spelling errors when non-nil.
236 When set to `block', assumes a block cursor with TTY displays."
237 :type '(choice (const block) (const :tag "off" nil) (const :tag "on" t))
238 :group 'ispell)
239
240 (defcustom ispell-highlight-face 'highlight
241 "*The face used for Ispell highlighting. For Emacses with overlays.
242 Possible values are `highlight', `modeline', `secondary-selection',
243 `region', and `underline'.
244 This variable can be set by the user to whatever face they desire.
245 It's most convenient if the cursor color and highlight color are
246 slightly different."
247 :type 'face
248 :group 'ispell)
249
250 (defcustom ispell-check-comments t
251 "*Spelling of comments checked when non-nil.
252 When set to `exclusive', ONLY comments are checked. (For code comments).
253 Warning! Not checking comments, when a comment start is embedded in strings,
254 may produce undesired results."
255 :type '(choice (const exclusive) (const :tag "off" nil) (const :tag "on" t))
256 :group 'ispell)
257
258 (defcustom ispell-query-replace-choices nil
259 "*Corrections made throughout region when non-nil.
260 Uses `query-replace' (\\[query-replace]) for corrections."
261 :type 'boolean
262 :group 'ispell)
263
264 (defcustom ispell-skip-tib nil
265 "*Does not spell check `tib' bibliography references when non-nil.
266 Skips any text between strings matching regular expressions
267 `ispell-tib-ref-beginning' and `ispell-tib-ref-end'.
268
269 TeX users beware: Any field starting with [. will skip until a .] -- even
270 your whole buffer -- unless you set `ispell-skip-tib' to nil. That includes
271 a [.5mm] type of number...."
272 :type 'boolean
273 :group 'ispell)
274
275 (defvar ispell-tib-ref-beginning "[[<]\\."
276 "Regexp matching the beginning of a Tib reference.")
277
278 (defvar ispell-tib-ref-end "\\.[]>]"
279 "Regexp matching the end of a Tib reference.")
280
281 (defcustom ispell-keep-choices-win t
282 "*When not nil, the `*Choices*' window remains for spelling session.
283 This minimizes redisplay thrashing."
284 :type 'boolean
285 :group 'ispell)
286
287 (defcustom ispell-choices-win-default-height 2
288 "*The default size of the `*Choices*' window, including mode line.
289 Must be greater than 1."
290 :type 'integer
291 :group 'ispell)
292
293 (defcustom ispell-program-name "ispell"
294 "Program invoked by \\[ispell-word] and \\[ispell-region] commands."
295 :type 'string
296 :group 'ispell)
297
298 (defcustom ispell-alternate-dictionary
299 (cond ((file-exists-p "/usr/dict/web2") "/usr/dict/web2")
300 ((file-exists-p "/usr/share/dict/web2") "/usr/share/dict/web2")
301 ((file-exists-p "/usr/dict/words") "/usr/dict/words")
302 ((file-exists-p "/usr/lib/dict/words") "/usr/lib/dict/words")
303 ((file-exists-p "/usr/share/dict/words") "/usr/share/dict/words")
304 ((file-exists-p "/usr/share/lib/dict/words")
305 "/usr/share/lib/dict/words")
306 ((file-exists-p "/sys/dict") "/sys/dict")
307 (t "/usr/dict/words"))
308 "*Alternate dictionary for spelling help."
309 :type '(choice file (const :tag "None" nil))
310 :group 'ispell)
311
312 (defcustom ispell-complete-word-dict ispell-alternate-dictionary
313 "*Dictionary used for word completion."
314 :type '(choice file (const :tag "None" nil))
315 :group 'ispell)
316
317 (defcustom ispell-message-dictionary-alist nil
318 "*List used by `ispell-message' to select a new dictionary.
319 It consists of pairs (REGEXP . DICTIONARY). If REGEXP is found
320 in the message headers, `ispell-local-dictionary' will be set to
321 DICTIONARY if `ispell-local-dictionary' is not buffer-local.
322 E.g. you may use the following value:
323 '((\"^Newsgroups:[ \\t]*de\\\\.\" . \"deutsch8\")
324 (\"^To:[^\\n,]+\\\\.de[ \\t\\n,>]\" . \"deutsch8\"))"
325 :type '(repeat (cons regexp string))
326 :group 'ispell)
327
328
329 (defcustom ispell-message-fcc-skip 50000
330 "*Query before saving Fcc message copy if attachment larger than this value.
331 Always stores Fcc copy of message when nil."
332 :type '(choice integer (const :tag "off" nil))
333 :group 'ispell)
334
335
336 (defcustom ispell-grep-command "egrep"
337 "Name of the grep command for search processes."
338 :type 'string
339 :group 'ispell)
340
341 (defcustom ispell-grep-options "-i"
342 "String of options to use when running the program in `ispell-grep-command'.
343 Should probably be \"-i\" or \"-e\".
344 Some machines (like the NeXT) don't support \"-i\""
345 :type 'string
346 :group 'ispell)
347
348 (defcustom ispell-look-command
349 (cond ((file-exists-p "/bin/look") "/bin/look")
350 ((file-exists-p "/usr/local/bin/look") "/usr/local/bin/look")
351 ((file-exists-p "/usr/bin/look") "/usr/bin/look")
352 (t "look"))
353 "Name of the look command for search processes.
354 This must be an absolute file name."
355 :type 'file
356 :group 'ispell)
357
358 (defcustom ispell-look-p (file-exists-p ispell-look-command)
359 "*Non-nil means use `look' rather than `grep'.
360 Default is based on whether `look' seems to be available."
361 :type 'boolean
362 :group 'ispell)
363
364 (defcustom ispell-have-new-look nil
365 "*Non-nil means use the `-r' option (regexp) when running `look'."
366 :type 'boolean
367 :group 'ispell)
368
369 (defcustom ispell-look-options (if ispell-have-new-look "-dfr" "-df")
370 "String of command options for `ispell-look-command'."
371 :type 'string
372 :group 'ispell)
373
374 (defcustom ispell-use-ptys-p nil
375 "When non-nil, Emacs uses ptys to communicate with Ispell.
376 When nil, Emacs uses pipes."
377 :type 'boolean
378 :group 'ispell)
379
380 (defcustom ispell-following-word nil
381 "*Non-nil means `ispell-word' checks the word around or after point.
382 Otherwise `ispell-word' checks the preceding word."
383 :type 'boolean
384 :group 'ispell)
385
386 (defcustom ispell-help-in-bufferp nil
387 "*Non-nil means display interactive keymap help in a buffer.
388 The following values are supported:
389 nil Expand the minibuffer and display a short help message
390 there for a couple of seconds.
391 t Pop up a new buffer and display a short help message there
392 for a couple of seconds.
393 electric Pop up a new buffer and display a long help message there.
394 User can browse and then exit the help mode."
395 :type '(choice (const electric) (const :tag "off" nil) (const :tag "on" t))
396 :group 'ispell)
397
398 (defcustom ispell-quietly nil
399 "*Non-nil means suppress messages in `ispell-word'."
400 :type 'boolean
401 :group 'ispell)
402
403 (defcustom ispell-format-word (function upcase)
404 "*Formatting function for displaying word being spell checked.
405 The function must take one string argument and return a string."
406 :type 'function
407 :group 'ispell)
408
409 (defcustom ispell-use-framepop-p nil
410 "When non-nil ispell uses framepop to display choices in a dedicated frame.
411 You can set this variable to dynamically use framepop if you are in a
412 window system by evaluating the following on startup to set this variable:
413 (and window-system (condition-case () (require 'framepop) (error nil)))"
414 :type 'boolean
415 :group 'ispell)
416
417 ;;;###autoload
418 (defcustom ispell-personal-dictionary nil
419 "*File name of your personal spelling dictionary, or nil.
420 If nil, the default personal dictionary, \"~/.ispell_DICTNAME\" is used,
421 where DICTNAME is the name of your default dictionary."
422 :type '(choice file
423 (const :tag "default" nil))
424 :group 'ispell)
425
426 (defcustom ispell-silently-savep nil
427 "*When non-nil, save the personal dictionary without confirmation."
428 :type 'boolean
429 :group 'ispell)
430
431 ;;; This is the local dictionary to use. When nil the default dictionary will
432 ;;; be used. Change set-default call to use a new default dictionary.
433 (defcustom ispell-local-dictionary nil
434 "If non-nil, the dictionary to be used for Ispell commands.
435 The value must be a string dictionary name in `ispell-dictionary-alist'.
436
437 Setting `ispell-local-dictionary' to a value has the same effect as
438 calling \\[ispell-change-dictionary] with that value. This variable
439 is automatically set when defined in the file with either
440 `ispell-dictionary-keyword' or the Local Variable syntax.
441
442 To create a non-standard default dictionary (not from `ispell-dictionary-alist')
443 call function `set-default' with the new dictionary name."
444 :type '(choice string
445 (const :tag "default" nil))
446 :group 'ispell)
447
448 (make-variable-buffer-local 'ispell-local-dictionary)
449
450 ;; Call this function set up the default dictionary if not English.
451 ;;(set-default 'ispell-local-dictionary nil)
452
453
454 (defcustom ispell-extra-args nil
455 "*If non-nil, a list of extra switches to pass to the Ispell program.
456 For example, (\"-W\" \"3\") to cause it to accept all 1-3 character
457 words as correct. See also `ispell-dictionary-alist', which may be used
458 for language-specific arguments."
459 :type '(repeat string)
460 :group 'ispell)
461
462
463
464 (defcustom ispell-skip-html 'use-mode-name
465 "*Indicates whether ispell should skip spell checking of SGML markup.
466 If t, always skip SGML markup; if nil, never skip; if non-t and non-nil,
467 guess whether SGML markup should be skipped according to the name of the
468 buffer's major mode."
469 :type '(choice (const :tag "always" t) (const :tag "never" nil)
470 (const :tag "use-mode-name" use-mode-name))
471 :group 'ispell)
472
473 (make-variable-buffer-local 'ispell-skip-html)
474
475
476 ;;; Define definitions here only for personal dictionaries.
477 ;;;###autoload
478 (defcustom ispell-local-dictionary-alist nil
479 "*Contains local or customized dictionary definitions.
480
481 These will override the values in `ispell-dictionary-alist'.
482
483 Customization changes made to `ispell-dictionary-alist' will not operate
484 over emacs sessions. To make permanent changes to your dictionary
485 definitions, you will need to make your changes in this variable, save,
486 and then re-start emacs."
487 :type '(repeat (list (choice :tag "Dictionary"
488 (string :tag "Dictionary name")
489 (const :tag "default" nil))
490 (regexp :tag "Case characters")
491 (regexp :tag "Non case characters")
492 (regexp :tag "Other characters")
493 (boolean :tag "Many other characters")
494 (repeat :tag "Ispell command line args"
495 (string :tag "Arg"))
496 (choice :tag "Extended character mode"
497 (const "~tex") (const "~plaintex")
498 (const "~nroff") (const "~list")
499 (const "~latin1") (const "~latin3")
500 (const :tag "default" nil))
501 (choice :tag "Coding system"
502 (const iso-8859-1)
503 (const iso-8859-2)
504 (const koi8-r))))
505 :group 'ispell)
506
507
508 ;;; split dictionary so line length is smaller in loaddefs.el
509
510 ;;; First part of dictionary, shortened for loaddefs.el
511 ;;;###autoload
512 (setq
513 ispell-dictionary-alist-1
514 '((nil ; default (English.aff)
515 "[A-Za-z]" "[^A-Za-z]" "[']" nil ("-B") nil iso-8859-1)
516 ("american" ; Yankee English
517 "[A-Za-z]" "[^A-Za-z]" "[']" nil ("-B") nil iso-8859-1)
518 ("brasileiro" ; Brazilian mode
519 "[A-Z\301\311\315\323\332\300\310\314\322\331\303\325\307\334\302\312\324a-z\341\351\355\363\372\340\350\354\362\371\343\365\347\374\342\352\364]"
520 "[^A-Z\301\311\315\323\332\300\310\314\322\331\303\325\307\334\302\312\324a-z\341\351\355\363\372\340\350\354\362\371\343\365\347\374\342\352\364]"
521 "[']" nil nil nil iso-8859-1)
522 ("british" ; British version
523 "[A-Za-z]" "[^A-Za-z]" "[']" nil ("-B") nil iso-8859-1)
524 ("castellano" ; Spanish mode
525 "[A-Z\301\311\315\321\323\332\334a-z\341\351\355\361\363\372\374]"
526 "[^A-Z\301\311\315\321\323\332\334a-z\341\351\355\361\363\372\374]"
527 "[-]" nil ("-B") "~tex" iso-8859-1)
528 ("castellano8" ; 8 bit Spanish mode
529 "[A-Z\301\311\315\321\323\332\334a-z\341\351\355\361\363\372\374]"
530 "[^A-Z\301\311\315\321\323\332\334a-z\341\351\355\361\363\372\374]"
531 "[-]" nil ("-B" "-d" "castellano") "~latin1" iso-8859-1)))
532
533
534 ;;; Second part of dictionary, shortened for loaddefs.el
535 ;;;###autoload
536 (setq
537 ispell-dictionary-alist-2
538 '(("czech"
539 "[A-Za-z\301\311\314\315\323\332\331\335\256\251\310\330\317\253\322\341\351\354\355\363\372\371\375\276\271\350\370\357\273\362]"
540 "[^A-Za-z\301\311\314\315\323\332\331\335\256\251\310\330\317\253\322\341\351\354\355\363\372\371\375\276\271\350\370\357\273\362]"
541 "" nil ("-B") nil iso-8859-2)
542 ("dansk" ; Dansk.aff
543 "[A-Z\306\330\305a-z\346\370\345]" "[^A-Z\306\330\305a-z\346\370\345]"
544 "[']" nil ("-C") nil iso-8859-1)
545 ("deutsch" ; Deutsch.aff
546 "[a-zA-Z\"]" "[^a-zA-Z\"]" "[']" t ("-C") "~tex" iso-8859-1)
547 ("deutsch8"
548 "[a-zA-Z\304\326\334\344\366\337\374]"
549 "[^a-zA-Z\304\326\334\344\366\337\374]"
550 "[']" t ("-C" "-d" "deutsch") "~latin1" iso-8859-1)
551 ("english" ; make English explicitly selectable
552 "[A-Za-z]" "[^A-Za-z]" "[']" nil ("-B") nil iso-8859-1)))
553
554
555 ;;; Third part of dictionary, shortened for loaddefs.el
556 ;;;###autoload
557 (setq
558 ispell-dictionary-alist-3
559 '(("esperanto"
560 "[A-Za-z\246\254\266\274\306\330\335\336\346\370\375\376]"
561 "[^A-Za-z\246\254\266\274\306\330\335\336\346\370\375\376]"
562 "[-']" t ("-C") "~latin3" iso-8859-1)
563 ("esperanto-tex"
564 "[A-Za-z^\\]" "[^A-Za-z^\\]"
565 "[-'`\"]" t ("-C" "-d" "esperanto") "~tex" iso-8859-1)
566 ("francais7"
567 "[A-Za-z]" "[^A-Za-z]" "[`'^---]" t nil nil iso-8859-1)
568 ("francais" ; Francais.aff
569 "[A-Za-z\300\302\306\307\310\311\312\313\316\317\324\331\333\334\340\342\347\350\351\352\353\356\357\364\371\373\374]"
570 "[^A-Za-z\300\302\306\307\310\311\312\313\316\317\324\331\333\334\340\342\347\350\351\352\353\356\357\364\371\373\374]"
571 "[-']" t nil "~list" iso-8859-1)
572 ("francais-tex" ; Francais.aff
573 "[A-Za-z\300\302\306\307\310\311\312\313\316\317\324\331\333\334\340\342\347\350\351\352\353\356\357\364\371\373\374\\]"
574 "[^A-Za-z\300\302\306\307\310\311\312\313\316\317\324\331\333\334\340\342\347\350\351\352\353\356\357\364\371\373\374\\]"
575 "[-'^`\"]" t nil "~tex" iso-8859-1)))
576
577
578 ;;; Fourth part of dictionary, shortened for loaddefs.el
579 ;;;###autoload
580 (setq
581 ispell-dictionary-alist-4
582 '(("german" ; german.aff
583 "[a-zA-Z\"]" "[^a-zA-Z\"]" "[']" t ("-C") "~tex" iso-8859-1)
584 ("german8" ; german.aff
585 "[a-zA-Z\304\326\334\344\366\337\374]"
586 "[^a-zA-Z\304\326\334\344\366\337\374]"
587 "[']" t ("-C" "-d" "german") "~latin1" iso-8859-1)
588 ("italiano" ; Italian.aff
589 "[A-Z\300\301\310\311\314\315\322\323\331\332a-z\340\341\350\351\354\355\363\371\372]"
590 "[^A-Z\300\301\310\311\314\315\322\323\331\332a-z\340\341\350\351\354\355\363\371\372]"
591 "[-]" nil ("-B" "-d" "italian") "~tex" iso-8859-1)
592 ("nederlands" ; Nederlands.aff
593 "[A-Za-z\300-\305\307\310-\317\322-\326\331-\334\340-\345\347\350-\357\361\362-\366\371-\374]"
594 "[^A-Za-z\300-\305\307\310-\317\322-\326\331-\334\340-\345\347\350-\357\361\362-\366\371-\374]"
595 "[']" t ("-C") nil iso-8859-1)
596 ("nederlands8" ; Dutch8.aff
597 "[A-Za-z\300-\305\307\310-\317\322-\326\331-\334\340-\345\347\350-\357\361\362-\366\371-\374]"
598 "[^A-Za-z\300-\305\307\310-\317\322-\326\331-\334\340-\345\347\350-\357\361\362-\366\371-\374]"
599 "[']" t ("-C") nil iso-8859-1)))
600
601
602 ;;; Fifth part of dictionary, shortened for loaddefs.el
603 ;;;###autoload
604 (setq
605 ispell-dictionary-alist-5
606 '(("norsk" ; 8 bit Norwegian mode
607 "[A-Za-z\305\306\307\310\311\322\324\330\345\346\347\350\351\362\364\370]"
608 "[^A-Za-z\305\306\307\310\311\322\324\330\345\346\347\350\351\362\364\370]"
609 "[\"]" nil nil "~list" iso-8859-1)
610 ("norsk7-tex" ; 7 bit Norwegian TeX mode
611 "[A-Za-z{}\\'^`]" "[^A-Za-z{}\\'^`]"
612 "[\"]" nil ("-d" "norsk") "~plaintex" iso-8859-1)
613 ("polish" ; Polish mode
614 "[A-Za-z\241\243\246\254\257\261\263\266\274\277\306\312\321\323\346\352\361\363]"
615 "[^A-Za-z\241\243\246\254\257\261\263\266\274\277\306\312\321\323\346\352\361\363]"
616 "" nil nil nil iso-8859-2)
617 ("portugues" ; Portuguese mode
618 "[a-zA-Z\301\302\311\323\340\341\342\351\352\355\363\343\372]"
619 "[^a-zA-Z\301\302\311\323\340\341\342\351\352\355\363\343\372]"
620 "[']" t ("-C") "~latin1" iso-8859-1)))
621
622
623 ;;; Sixth part of dictionary, shortened for loaddefs.el
624 ;;;###autoload
625 (setq
626 ispell-dictionary-alist-6
627 ;; include Russian iso coding system too?
628 ;; "[']" t ("-d" "russian") "~latin1" iso-8859-1
629 '(("russian" ; Russian.aff (KOI8-R charset)
630 "[\341\342\367\347\344\345\263\366\372\351\352\353\354\355\356\357\360\362\363\364\365\346\350\343\376\373\375\370\371\377\374\340\361\301\302\327\307\304\305\243\326\332\311\312\313\314\315\316\317\320\322\323\324\325\306\310\303\336\333\335\330\331\337\334\300\321]"
631 "[^\341\342\367\347\344\345\263\366\372\351\352\353\354\355\356\357\360\362\363\364\365\346\350\343\376\373\375\370\371\377\374\340\361\301\302\327\307\304\305\243\326\332\311\312\313\314\315\316\317\320\322\323\324\325\306\310\303\336\333\335\330\331\337\334\300\321]"
632 "" nil nil nil koi8-r)
633 ("slovak" ; Slovakian
634 "[A-Za-z\301\304\311\315\323\332\324\300\305\245\335\256\251\310\317\253\322\341\344\351\355\363\372\364\340\345\265\375\276\271\350\357\273\362]"
635 "[^A-Za-z\301\304\311\315\323\332\324\300\305\245\335\256\251\310\317\253\322\341\344\351\355\363\372\364\340\345\265\375\276\271\350\357\273\362]"
636 "" nil ("-B") nil iso-8859-2)
637 ("svenska" ; Swedish mode
638 "[A-Za-z\345\344\366\351\340\374\350\346\370\347\305\304\326\311\300\334\310\306\330\307]"
639 "[^A-Za-z\345\344\366\351\340\374\350\346\370\347\305\304\326\311\300\334\310\306\330\307]"
640 "[']" nil ("-C") "~list" iso-8859-1)))
641
642
643 ;;;###autoload
644 (defcustom ispell-dictionary-alist
645 (append ispell-local-dictionary-alist ; dictionary customizations
646 ispell-dictionary-alist-1 ispell-dictionary-alist-2
647 ispell-dictionary-alist-3 ispell-dictionary-alist-4
648 ispell-dictionary-alist-5 ispell-dictionary-alist-6)
649 "An alist of dictionaries and their associated parameters.
650
651 Each element of this list is also a list:
652
653 \(DICTIONARY-NAME CASECHARS NOT-CASECHARS OTHERCHARS MANY-OTHERCHARS-P
654 ISPELL-ARGS EXTENDED-CHARACTER-MODE CHARACTER-SET\)
655
656 DICTIONARY-NAME is a possible string value of variable `ispell-dictionary',
657 nil means the default dictionary.
658
659 CASECHARS is a regular expression of valid characters that comprise a
660 word.
661
662 NOT-CASECHARS is the opposite regexp of CASECHARS.
663
664 OTHERCHARS is a regexp of characters in the NOT-CASECHARS set but which can be
665 used to construct words in some special way. If OTHERCHARS characters follow
666 and precede characters from CASECHARS, they are parsed as part of a word,
667 otherwise they become word-breaks. As an example in English, assume the
668 regular expression \"[']\" for OTHERCHARS. Then \"they're\" and
669 \"Steven's\" are parsed as single words including the \"'\" character, but
670 \"Stevens'\" does not include the quote character as part of the word.
671 If you want OTHERCHARS to be empty, use the empty string.
672 Hint: regexp syntax requires the hyphen to be declared first here.
673
674 MANY-OTHERCHARS-P is non-nil when multiple OTHERCHARS are allowed in a word.
675 Otherwise only a single OTHERCHARS character is allowed to be part of any
676 single word.
677
678 ISPELL-ARGS is a list of additional arguments passed to the ispell
679 subprocess.
680
681 EXTENDED-CHARACTER-MODE should be used when dictionaries are used which
682 have been configured in an Ispell affix file. (For example, umlauts
683 can be encoded as \\\"a, a\\\", \"a, ...) Defaults are ~tex and ~nroff
684 in English. This has the same effect as the command-line `-T' option.
685 The buffer Major Mode controls Ispell's parsing in tex or nroff mode,
686 but the dictionary can control the extended character mode.
687 Both defaults can be overruled in a buffer-local fashion. See
688 `ispell-parsing-keyword' for details on this.
689
690 CHARACTER-SET used for languages with multibyte characters.
691
692 Note that the CASECHARS and OTHERCHARS slots of the alist should
693 contain the same character set as casechars and otherchars in the
694 LANGUAGE.aff file \(e.g., english.aff\)."
695 :type '(repeat (list (choice :tag "Dictionary"
696 (string :tag "Dictionary name")
697 (const :tag "default" nil))
698 (regexp :tag "Case characters")
699 (regexp :tag "Non case characters")
700 (regexp :tag "Other characters")
701 (boolean :tag "Many other characters")
702 (repeat :tag "Ispell command line args"
703 (string :tag "Arg"))
704 (choice :tag "Extended character mode"
705 (const "~tex") (const "~plaintex")
706 (const "~nroff") (const "~list")
707 (const "~latin1") (const "~latin3")
708 (const :tag "default" nil))
709 (choice :tag "Coding System"
710 (const iso-8859-1)
711 (const iso-8859-2)
712 (const koi8-r))))
713 :group 'ispell)
714
715 ;;; update the dictionaries at load time
716 (setq ispell-dictionary-alist
717 (append ispell-local-dictionary-alist ; dictionary customizations
718 ispell-dictionary-alist-1 ispell-dictionary-alist-2
719 ispell-dictionary-alist-3 ispell-dictionary-alist-4
720 ispell-dictionary-alist-5 ispell-dictionary-alist-6))
721
722
723
724
725 ;;; **********************************************************************
726 ;;; The following are used by ispell, and should not be changed.
727 ;;; **********************************************************************
728
729
730
731 ;;; The version must be 3.1 or greater for this version of ispell.el
732 ;;; There is an incompatibility between version 3.1.12 and lower versions.
733 (defconst ispell-required-version '(3 1 12)
734 "Ispell versions with which this version of ispell.el is known to work.")
735 (defvar ispell-offset -1
736 "Offset that maps protocol differences between ispell 3.1 versions.")
737
738 (defconst ispell-version "ispell.el 3.6 - 7-Jan-2003")
739
740
741 (defun ispell-check-version (&optional interactivep)
742 "Ensure that `ispell-program-name' is valid and the correct version.
743 Returns version number if called interactively.
744 Otherwise returns the library directory name, if that is defined."
745 ;; This is a little wasteful as we actually launch ispell twice: once
746 ;; to make sure it's the right version, and once for real. But people
747 ;; get confused by version mismatches *all* the time (and I've got the
748 ;; email to prove it) so I think this is worthwhile. And the -v[ersion]
749 ;; option is the only way I can think of to do this that works with
750 ;; all versions, since versions earlier than 3.0.09 didn't identify
751 ;; themselves on startup.
752 (interactive "p")
753 (let ((case-fold-search-val case-fold-search)
754 ;; avoid bugs when syntax of `.' changes in various default modes
755 (default-major-mode 'fundamental-mode)
756 (default-directory (or (and (boundp 'temporary-file-directory)
757 temporary-file-directory)
758 default-directory))
759 result status)
760 (save-excursion
761 (let ((buf (get-buffer " *ispell-tmp*")))
762 (if buf (kill-buffer buf)))
763 (set-buffer (get-buffer-create " *ispell-tmp*"))
764 (erase-buffer)
765 (setq status (call-process
766 ispell-program-name nil t nil
767 ;; aspell doesn't accept the -vv switch.
768 (let ((case-fold-search
769 (memq system-type '(ms-dos windows-nt)))
770 (speller
771 (file-name-nondirectory ispell-program-name)))
772 ;; Assume anything that isn't `aspell' is Ispell.
773 (if (string-match "\\`aspell" speller) "-v" "-vv"))))
774 (goto-char (point-min))
775 (if interactivep
776 ;; report version information of ispell and ispell.el
777 (progn
778 (end-of-line)
779 (setq result (concat (buffer-substring-no-properties (point-min)
780 (point))
781 ", "
782 ispell-version))
783 (message result))
784 ;; return library directory.
785 (if (re-search-forward "LIBDIR = \\\"\\([^ \t\n]*\\)\\\"" nil t)
786 (setq result (buffer-substring (match-beginning 1) (match-end 1)))))
787 (goto-char (point-min))
788 (if (not (memq status '(0 nil)))
789 (error "%s exited with %s %s" ispell-program-name
790 (if (stringp status) "signal" "code") status))
791 (setq case-fold-search t
792 status (re-search-forward
793 (concat "\\<\\("
794 (format "%d" (car ispell-required-version))
795 "\\)\\.\\([0-9]*\\)\\.\\([0-9]*\\)\\>")
796 nil t)
797 case-fold-search case-fold-search-val)
798 (if (or (not status) ; major version mismatch
799 (< (car (read-from-string (buffer-substring-no-properties
800 (match-beginning 2) (match-end 2))))
801 (car (cdr ispell-required-version)))) ; minor version mismatch
802 (error "%s version 3 release %d.%d.%d or greater is required"
803 ispell-program-name (car ispell-required-version)
804 (car (cdr ispell-required-version))
805 (car (cdr (cdr ispell-required-version))))
806 ;; check that it is the correct version.
807 (if (and (= (car (read-from-string (buffer-substring-no-properties
808 (match-beginning 2)(match-end 2))))
809 (car (cdr ispell-required-version)))
810 (< (car (read-from-string (buffer-substring-no-properties
811 (match-beginning 3)(match-end 3))))
812 (car (cdr (cdr ispell-required-version)))))
813 (setq ispell-offset 0)))
814 (kill-buffer (current-buffer)))
815 result))
816
817
818
819 ;;; The preparation of the menu bar menu must be autoloaded
820 ;;; because otherwise this file gets autoloaded every time Emacs starts
821 ;;; so that it can set up the menus and determine keyboard equivalents.
822
823
824 ;;;###autoload
825 (defvar ispell-menu-map nil "Key map for ispell menu.")
826 ;;; redo menu when loading ispell to get dictionary modifications
827 (setq ispell-menu-map nil)
828
829 ;;;###autoload
830 (defvar ispell-menu-xemacs nil
831 "Spelling menu for XEmacs.
832 If nil when package is loaded, a standard menu will be set,
833 and added as a submenu of the \"Edit\" menu.")
834
835 ;;; Break out XEmacs menu and split into several calls to avoid having
836 ;;; long lines in loaddefs.el. Detect need off following constant.
837
838 ;;; Set up dictionary
839 ;;;###autoload
840 (defvar ispell-menu-map-needed
841 ;; only needed when not version 18 and not XEmacs.
842 (and (not ispell-menu-map)
843 (not (featurep 'xemacs))
844 'reload))
845
846 (defvar ispell-library-directory (condition-case ()
847 (ispell-check-version)
848 (error nil))
849 "Directory where ispell dictionaries reside.")
850
851 (defvar ispell-process nil
852 "The process object for Ispell.")
853
854 (defvar ispell-async-processp (and (fboundp 'kill-process)
855 (fboundp 'process-send-string)
856 (fboundp 'accept-process-output)
857 ;;(fboundp 'start-process)
858 ;;(fboundp 'set-process-filter)
859 ;;(fboundp 'process-kill-without-query)
860 )
861 "Non-nil means that the OS supports asynchronous processes.")
862
863 (defun ispell-valid-dictionary-list ()
864 "Returns a list of valid dictionaries.
865 The variable `ispell-library-directory' defines the library location."
866 (let ((dicts ispell-dictionary-alist)
867 (dict-list (cons "default" nil))
868 name load-dict)
869 (dolist (dict dicts)
870 (setq name (car dict)
871 load-dict (car (cdr (member "-d" (nth 5 dict)))))
872 ;; Include if the dictionary is in the library, or dir not defined.
873 (if (and
874 name
875 ;; include all dictionaries if lib directory not known.
876 (or (not ispell-library-directory)
877 (file-exists-p (concat ispell-library-directory
878 "/" name ".hash"))
879 (file-exists-p (concat ispell-library-directory "/" name ".has"))
880 (and load-dict
881 (or (file-exists-p (concat ispell-library-directory
882 "/" load-dict ".hash"))
883 (file-exists-p (concat ispell-library-directory
884 "/" load-dict ".has"))))))
885 (setq dict-list (cons name dict-list))))
886 dict-list))
887
888
889 ;;;###autoload
890 (if ispell-menu-map-needed
891 (let ((dicts (if (fboundp 'ispell-valid-dictionary-list)
892 (ispell-valid-dictionary-list)
893 (mapcar (lambda (x) (or (car x) "default"))
894 ispell-dictionary-alist)))
895 (dict-map (make-sparse-keymap "Dictionaries")))
896 (setq ispell-menu-map (make-sparse-keymap "Spell"))
897 ;; add the dictionaries to the bottom of the list.
898 (if (not dicts)
899 (define-key ispell-menu-map [default]
900 '("Select Default Dict"
901 "Dictionary for which Ispell was configured"
902 . (lambda () (interactive)
903 (ispell-change-dictionary "default")))))
904 (fset 'ispell-dict-map dict-map)
905 (define-key ispell-menu-map [dictionaries]
906 `(menu-item "Select Dict" ispell-dict-map))
907 (dolist (name dicts)
908 (define-key dict-map (vector (intern name))
909 (cons (concat "Select " (capitalize name) " Dict")
910 `(lambda () (interactive)
911 (ispell-change-dictionary ,name)))))))
912
913 ;;; define commands in menu in opposite order you want them to appear.
914 ;;;###autoload
915 (if ispell-menu-map-needed
916 (progn
917 (define-key ispell-menu-map [ispell-change-dictionary]
918 '(menu-item "Change Dictionary..." ispell-change-dictionary
919 :help "Supply explicit dictionary file name"))
920 (define-key ispell-menu-map [ispell-kill-ispell]
921 '(menu-item "Kill Process" ispell-kill-ispell
922 :enable (and (boundp 'ispell-process) ispell-process
923 (eq (ispell-process-status) 'run))
924 :help "Terminate Ispell subprocess"))
925 (define-key ispell-menu-map [ispell-pdict-save]
926 '(menu-item "Save Dictionary"
927 (lambda () (interactive) (ispell-pdict-save t t))
928 :help "Save personal dictionary"))
929 (define-key ispell-menu-map [ispell-customize]
930 '(menu-item "Customize..."
931 (lambda () (interactive) (customize-group 'ispell))
932 :help "Customize spell checking options"))
933 (define-key ispell-menu-map [ispell-help]
934 ;; use (x-popup-menu last-nonmenu-event(list "" ispell-help-list)) ?
935 '(menu-item "Help"
936 (lambda () (interactive) (describe-function 'ispell-help))
937 :help "Show standard Ispell keybindings and commands"))
938 (define-key ispell-menu-map [flyspell-mode]
939 '(menu-item "Automatic spell checking (Flyspell)"
940 flyspell-mode
941 :help "Check spelling while you edit the text"
942 :button (:toggle . flyspell-mode)))
943 (define-key ispell-menu-map [ispell-complete-word]
944 '(menu-item "Complete Word" ispell-complete-word
945 :help "Complete word at cursor using dictionary"))
946 (define-key ispell-menu-map [ispell-complete-word-interior-frag]
947 '(menu-item "Complete Word Fragment" ispell-complete-word-interior-frag
948 :help "Complete word fragment at cursor"))))
949
950 ;;;###autoload
951 (if ispell-menu-map-needed
952 (progn
953 (define-key ispell-menu-map [ispell-continue]
954 '(menu-item "Continue Spell-Checking" ispell-continue
955 :enable (and (boundp 'ispell-region-end)
956 (marker-position ispell-region-end)
957 (equal (marker-buffer ispell-region-end)
958 (current-buffer)))
959 :help "Continue spell checking last region"))
960 (define-key ispell-menu-map [ispell-word]
961 '(menu-item "Spell-Check Word" ispell-word
962 :help "Spell-check word at cursor"))
963 (define-key ispell-menu-map [ispell-comments-and-strings]
964 '(menu-item "Spell-Check Comments" ispell-comments-and-strings
965 :help "Spell-check only comments and strings"))))
966
967 ;;;###autoload
968 (if ispell-menu-map-needed
969 (progn
970 (define-key ispell-menu-map [ispell-region]
971 '(menu-item "Spell-Check Region" ispell-region
972 :enable mark-active
973 :help "Spell-check text in marked region"))
974 (define-key ispell-menu-map [ispell-message]
975 '(menu-item "Spell-Check Message" ispell-message
976 :help "Skip headers and included message text"))
977 (define-key ispell-menu-map [ispell-buffer]
978 '(menu-item "Spell-Check Buffer" ispell-buffer
979 :help "Check spelling of selected buffer"))
980 ;;(put 'ispell-region 'menu-enable 'mark-active)
981 (fset 'ispell-menu-map (symbol-value 'ispell-menu-map))))
982
983 ;;; XEmacs versions 19 & 20
984 (if (and (featurep 'xemacs)
985 (featurep 'menubar)
986 ;;(null ispell-menu-xemacs)
987 (not (and (boundp 'infodock-version) infodock-version)))
988 (let ((dicts (if (fboundp 'ispell-valid-dictionary-list)
989 (reverse (ispell-valid-dictionary-list))))
990 (current-menubar (or current-menubar default-menubar))
991 (menu
992 '(["Help" (describe-function 'ispell-help) t]
993 ;;["Help" (popup-menu ispell-help-list) t]
994 ["Check Message" ispell-message t]
995 ["Check Buffer" ispell-buffer t]
996 ["Check Comments" ispell-comments-and-strings t]
997 ["Check Word" ispell-word t]
998 ["Check Region" ispell-region (or (not zmacs-regions) (mark))]
999 ["Continue Check" ispell-continue t]
1000 ["Complete Word Frag"ispell-complete-word-interior-frag t]
1001 ["Complete Word" ispell-complete-word t]
1002 ["Kill Process" ispell-kill-ispell t]
1003 ["Customize..." (customize-group 'ispell) t]
1004 ;; flyspell-mode may not be bound...
1005 ;;["flyspell" flyspell-mode
1006 ;; :style toggle :selected flyspell-mode ]
1007 "-"
1008 ["Save Personal Dict"(ispell-pdict-save t t) t]
1009 ["Change Dictionary" ispell-change-dictionary t])))
1010 (if (null dicts)
1011 (setq dicts (cons "default" nil)))
1012 (dolist (name dicts)
1013 (setq menu (append menu
1014 (list
1015 (vector
1016 (concat "Select " (capitalize name))
1017 (list 'ispell-change-dictionary name)
1018 t)))))
1019 (setq ispell-menu-xemacs menu)
1020 (if current-menubar
1021 (progn
1022 (if (car (find-menu-item current-menubar '("Cmds")))
1023 (progn
1024 ;; XEmacs 21.2
1025 (delete-menu-item '("Cmds" "Spell-Check"))
1026 (add-menu '("Cmds") "Spell-Check" ispell-menu-xemacs))
1027 ;; previous
1028 (delete-menu-item '("Edit" "Spell")) ; in case already defined
1029 (add-menu '("Edit") "Spell" ispell-menu-xemacs))))))
1030
1031 ;;; Allow incrementing characters as integers in XEmacs 20
1032 (if (and (featurep 'xemacs)
1033 (fboundp 'int-char))
1034 (fset 'ispell-int-char 'int-char)
1035 ;; Emacs and XEmacs 19 or earlier
1036 (fset 'ispell-int-char 'identity))
1037
1038
1039 ;;; **********************************************************************
1040
1041
1042 ;;; This variable contains the current dictionary being used if the ispell
1043 ;;; process is running. Otherwise it contains the global default.
1044 (defvar ispell-dictionary nil
1045 "The name of the current dictionary, or nil for the default.
1046 When `ispell-local-dictionary' is nil, `ispell-dictionary' is used to select
1047 the dictionary for new buffers.
1048
1049 This is passed to the ispell process using the `-d' switch and is
1050 used as key in `ispell-dictionary-alist' (which see).")
1051
1052 (defun ispell-decode-string (str)
1053 "Decodes multibyte character strings.
1054 Protects against bogus binding of `enable-multibyte-characters' in XEmacs."
1055 (if (and (or (featurep 'xemacs)
1056 (and (boundp 'enable-multibyte-characters)
1057 enable-multibyte-characters))
1058 (fboundp 'decode-coding-string)
1059 (ispell-get-coding-system))
1060 (decode-coding-string str (ispell-get-coding-system))
1061 str))
1062
1063 (defun ispell-get-casechars ()
1064 (ispell-decode-string
1065 (nth 1 (assoc ispell-dictionary ispell-dictionary-alist))))
1066 (defun ispell-get-not-casechars ()
1067 (ispell-decode-string
1068 (nth 2 (assoc ispell-dictionary ispell-dictionary-alist))))
1069 (defun ispell-get-otherchars ()
1070 (ispell-decode-string
1071 (nth 3 (assoc ispell-dictionary ispell-dictionary-alist))))
1072 (defun ispell-get-many-otherchars-p ()
1073 (nth 4 (assoc ispell-dictionary ispell-dictionary-alist)))
1074 (defun ispell-get-ispell-args ()
1075 (nth 5 (assoc ispell-dictionary ispell-dictionary-alist)))
1076 (defun ispell-get-extended-character-mode ()
1077 (nth 6 (assoc ispell-dictionary ispell-dictionary-alist)))
1078 (defun ispell-get-coding-system ()
1079 (nth 7 (assoc ispell-dictionary ispell-dictionary-alist)))
1080
1081
1082 (defvar ispell-pdict-modified-p nil
1083 "Non-nil means personal dictionary has modifications to be saved.")
1084
1085 ;;; If you want to save the dictionary when quitting, must do so explicitly.
1086 ;;; When non-nil, the spell session is terminated.
1087 ;;; When numeric, contains cursor location in buffer, and cursor remains there.
1088 (defvar ispell-quit nil)
1089
1090 (defvar ispell-process-directory nil
1091 "The directory where `ispell-process' was started.")
1092
1093 (defvar ispell-filter nil
1094 "Output filter from piped calls to Ispell.")
1095
1096 (defvar ispell-filter-continue nil
1097 "Control variable for Ispell filter function.")
1098
1099 (defvar ispell-output-buffer nil
1100 "Buffer used for reading output of a synchronous Ispell subprocess.")
1101
1102 (defvar ispell-session-buffer nil
1103 "Buffer used for passing input to a synchronous Ispell subprocess.")
1104
1105 (defvar ispell-cmd-args nil
1106 "Command-line arguments to pass to a synchronous Ispell subprocess.")
1107
1108 (defvar ispell-query-replace-marker (make-marker)
1109 "Marker for `query-replace' processing.")
1110
1111 (defvar ispell-recursive-edit-marker (make-marker)
1112 "Marker for return point from recursive edit.")
1113
1114 (defvar ispell-checking-message nil
1115 "Non-nil when we're checking a mail message.
1116 Set to the MIME boundary locations when checking messages.")
1117
1118 (defconst ispell-choices-buffer "*Choices*")
1119
1120 (defvar ispell-overlay nil "Overlay variable for Ispell highlighting.")
1121
1122 ;;; *** Buffer Local Definitions ***
1123
1124 (defconst ispell-words-keyword "LocalWords: "
1125 "The keyword for local oddly-spelled words to accept.
1126 The keyword will be followed by any number of local word spellings.
1127 There can be multiple of these keywords in the file.")
1128
1129 (defconst ispell-dictionary-keyword "Local IspellDict: "
1130 "The keyword for a local dictionary to use.
1131 The keyword must be followed by a correct dictionary name in
1132 `ispell-dictionary-alist'. When multiple occurrences exist, the last keyword
1133 definition is used.")
1134
1135 (defconst ispell-pdict-keyword "Local IspellPersDict: "
1136 "The keyword for defining buffer local dictionaries.
1137 Keyword must be followed by the filename of a personal dictionary.
1138 The last occurring definition in the buffer will be used.")
1139
1140 (defconst ispell-parsing-keyword "Local IspellParsing: "
1141 "The keyword for overriding default Ispell parsing.
1142 The above keyword string should be followed by `latex-mode' or
1143 `nroff-mode' to put the current buffer into the desired parsing mode.
1144
1145 Extended character mode can be changed for this buffer by placing
1146 a `~' followed by an extended-character mode -- such as `~.tex'.
1147 The last occurring definition in the buffer will be used.")
1148
1149 ;;;###autoload
1150 (defvar ispell-skip-region-alist
1151 '((ispell-words-keyword forward-line)
1152 (ispell-dictionary-keyword forward-line)
1153 (ispell-pdict-keyword forward-line)
1154 (ispell-parsing-keyword forward-line)
1155 ("^---*BEGIN PGP [A-Z ]*--*" . "^---*END PGP [A-Z ]*--*")
1156 ;; assume multiline uuencoded file? "\nM.*$"?
1157 ("^begin [0-9][0-9][0-9] [^ \t]+$" . "\nend\n")
1158 ("^%!PS-Adobe-[123].0" . "\n%%EOF\n")
1159 ("^---* \\(Start of \\)?[Ff]orwarded [Mm]essage"
1160 . "^---* End of [Ff]orwarded [Mm]essage")
1161 ;; Matches e-mail addresses, file names, http addresses, etc. The `-+'
1162 ;; pattern necessary for performance reasons when `-' part of word syntax.
1163 ("\\(--+\\|\\(/\\w\\|\\(\\(\\w\\|[-_]\\)+[.:@]\\)\\)\\(\\w\\|[-_]\\)*\\([.:/@]+\\(\\w\\|[-_~=?&]\\)+\\)+\\)")
1164 ;; above checks /.\w sequences
1165 ;;("\\(--+\\|\\(/\\|\\(\\(\\w\\|[-_]\\)+[.:@]\\)\\)\\(\\w\\|[-_]\\)*\\([.:/@]+\\(\\w\\|[-_~=?&]\\)+\\)+\\)")
1166 ;; This is a pretty complex regexp. It can be simplified to the following:
1167 ;; "\\(\\w\\|[-_]\\)*\\([.:/@]+\\(\\w\\|[-_]\\|~\\)+\\)+"
1168 ;; but some valid text will be skipped, e.g. "his/her". This could be
1169 ;; fixed up (at the expense of a moderately more complex regexp)
1170 ;; by not allowing "/" to be the character which triggers the
1171 ;; identification of the computer name, e.g.:
1172 ;; "\\(\\w\\|[-_]\\)+[.:@]\\(\\w\\|[-_]\\)*\\([.:/@]+\\(\\w\\|[-_]\\|~\\)+\\)+"
1173 )
1174 "Alist expressing beginning and end of regions not to spell check.
1175 The alist key must be a regular expression.
1176 Valid forms include:
1177 (KEY) - just skip the key.
1178 (KEY . REGEXP) - skip to the end of REGEXP. REGEXP may be string or symbol.
1179 (KEY REGEXP) - skip to end of REGEXP. REGEXP must be a string.
1180 (KEY FUNCTION ARGS) - FUNCTION called with ARGS returns end of region.")
1181
1182
1183
1184 ;;;###autoload
1185 (defvar ispell-tex-skip-alists
1186 '((;;("%\\[" . "%\\]") ; AMStex block comment...
1187 ;; All the standard LaTeX keywords from L. Lamport's guide:
1188 ;; \cite, \hspace, \hspace*, \hyphenation, \include, \includeonly, \input,
1189 ;; \label, \nocite, \rule (in ispell - rest included here)
1190 ("\\\\addcontentsline" ispell-tex-arg-end 2)
1191 ("\\\\add\\(tocontents\\|vspace\\)" ispell-tex-arg-end)
1192 ("\\\\\\([aA]lph\\|arabic\\)" ispell-tex-arg-end)
1193 ;;("\\\\author" ispell-tex-arg-end)
1194 ("\\\\bibliographystyle" ispell-tex-arg-end)
1195 ("\\\\makebox" ispell-tex-arg-end 0)
1196 ("\\\\e?psfig" ispell-tex-arg-end)
1197 ("\\\\document\\(class\\|style\\)" .
1198 "\\\\begin[ \t\n]*{[ \t\n]*document[ \t\n]*}"))
1199 (;; delimited with \begin. In ispell: displaymath, eqnarray, eqnarray*,
1200 ;; equation, minipage, picture, tabular, tabular* (ispell)
1201 ("\\(figure\\|table\\)\\*?" ispell-tex-arg-end 0)
1202 ("list" ispell-tex-arg-end 2)
1203 ("program" . "\\\\end[ \t\n]*{[ \t\n]*program[ \t\n]*}")
1204 ("verbatim\\*?" . "\\\\end[ \t\n]*{[ \t\n]*verbatim\\*?[ \t\n]*}")))
1205 "*Lists of regions to be skipped in TeX mode.
1206 First list is used raw.
1207 Second list has key placed inside \\begin{}.
1208
1209 Delete or add any regions you want to be automatically selected
1210 for skipping in latex mode.")
1211
1212
1213 ;;;###autoload
1214 (defvar ispell-html-skip-alists
1215 '(("<[cC][oO][dD][eE]\\>[^>]*>" "</[cC][oO][dD][eE]*>")
1216 ("<[sS][cC][rR][iI][pP][tT]\\>[^>]*>" "</[sS][cC][rR][iI][pP][tT]>")
1217 ("<[aA][pP][pP][lL][eE][tT]\\>[^>]*>" "</[aA][pP][pP][lL][eE][tT]>")
1218 ("<[vV][eE][rR][bB]\\>[^>]*>" "<[vV][eE][rR][bB]\\>[^>]*>")
1219 ;;("<[tT][tT]\\>[^>]*>" "<[tT][tT]\\>[^>]*>")
1220 ("<[tT][tT]/" "/")
1221 ("<[^ \t\n>]" ">")
1222 ("&[^ \t\n;]" "[; \t\n]"))
1223 "*Lists of start and end keys to skip in HTML buffers.
1224 Same format as `ispell-skip-region-alist'
1225 Note - substrings of other matches must come last
1226 (e.g. \"<[tT][tT]/\" and \"<[^ \t\n>]\").")
1227
1228
1229 (defvar ispell-local-pdict ispell-personal-dictionary
1230 "A buffer local variable containing the current personal dictionary.
1231 If non-nil, the value must be a string, which is a file name.
1232
1233 If you specify a personal dictionary for the current buffer which is
1234 different from the current personal dictionary, the effect is similar
1235 to calling \\[ispell-change-dictionary]. This variable is automatically
1236 set when defined in the file with either `ispell-pdict-keyword' or the
1237 local variable syntax.")
1238
1239 (make-variable-buffer-local 'ispell-local-pdict)
1240
1241 (defvar ispell-buffer-local-name nil
1242 "Contains the buffer name if local word definitions were used.
1243 Ispell is then restarted because the local words could conflict.")
1244
1245 (defvar ispell-parser 'use-mode-name
1246 "*Indicates whether ispell should parse the current buffer as TeX Code.
1247 Special value `use-mode-name' tries to guess using the name of `major-mode'.
1248 Default parser is `nroff'.
1249 Currently the only other valid parser is `tex'.
1250
1251 You can set this variable in hooks in your init file -- eg:
1252
1253 \(add-hook 'tex-mode-hook (lambda () (setq ispell-parser 'tex)))")
1254
1255 (defvar ispell-region-end (make-marker)
1256 "Marker that allows spelling continuations.")
1257
1258 (defvar ispell-check-only nil
1259 "If non-nil, `ispell-word' does not try to correct the word.")
1260
1261
1262 ;;; **********************************************************************
1263 ;;; **********************************************************************
1264
1265
1266
1267 ;;;###autoload (define-key esc-map "$" 'ispell-word)
1268
1269
1270 (defun ispell-accept-output (&optional timeout-secs timeout-msecs)
1271 "Wait for output from ispell process, or TIMEOUT-SECS and TIMEOUT-MSECS.
1272 If asynchronous subprocesses are not supported, call `ispell-filter' and
1273 pass it the output of the last ispell invocation."
1274 (if ispell-async-processp
1275 (accept-process-output ispell-process timeout-secs timeout-msecs)
1276 (if (null ispell-process)
1277 (error "No Ispell process to read output from!")
1278 (let ((buf ispell-output-buffer)
1279 ispell-output)
1280 (if (not (bufferp buf))
1281 (setq ispell-filter nil)
1282 (save-excursion
1283 (set-buffer buf)
1284 (setq ispell-output (buffer-substring-no-properties
1285 (point-min) (point-max))))
1286 (ispell-filter t ispell-output)
1287 (save-excursion
1288 (set-buffer buf)
1289 (erase-buffer)))))))
1290
1291
1292 (defun ispell-send-string (string)
1293 "Send the string STRING to the Ispell process."
1294 (if ispell-async-processp
1295 (process-send-string ispell-process string)
1296 ;; Asynchronous subprocesses aren't supported on this losing system.
1297 ;; We keep all the directives passed to Ispell during the entire
1298 ;; session in a buffer, and pass them anew each time we invoke
1299 ;; Ispell to process another chunk of text. (Yes, I know this is a
1300 ;; terrible kludge, and it's a bit slow, but it does get the work done.)
1301 (let ((cmd (aref string 0))
1302 ;; The following commands are not passed to Ispell until
1303 ;; we have a *real* reason to invoke it.
1304 (cmds-to-defer '(?* ?@ ?~ ?+ ?- ?! ?%))
1305 (default-major-mode 'fundamental-mode)
1306 (session-buf ispell-session-buffer)
1307 (output-buf ispell-output-buffer)
1308 (ispell-args ispell-cmd-args)
1309 (defdir ispell-process-directory)
1310 prev-pos)
1311 (save-excursion
1312 (set-buffer session-buf)
1313 (setq prev-pos (point))
1314 (setq default-directory defdir)
1315 (insert string)
1316 (if (not (memq cmd cmds-to-defer))
1317 (let (coding-system-for-read coding-system-for-write status)
1318 (if (and (boundp 'enable-multibyte-characters)
1319 enable-multibyte-characters)
1320 (setq coding-system-for-read (ispell-get-coding-system)
1321 coding-system-for-write (ispell-get-coding-system)))
1322 (set-buffer output-buf)
1323 (erase-buffer)
1324 (set-buffer session-buf)
1325 (setq status
1326 (apply 'call-process-region (point-min) (point-max)
1327 ispell-program-name nil
1328 output-buf nil
1329 "-a" "-m" ispell-args))
1330 (set-buffer output-buf)
1331 (goto-char (point-min))
1332 (save-match-data
1333 (if (not (looking-at "@(#) "))
1334 (error "Ispell error: %s"
1335 (buffer-substring-no-properties
1336 (point) (progn (end-of-line) (point)))))
1337 ;; If STRING is "^Z\n", we just started Ispell and need
1338 ;; to retain its version ID line in the output buffer.
1339 ;; Otherwise, remove the ID line, as it will confuse
1340 ;; `ispell-filter'.
1341 (or (string= string "\032\n")
1342 (progn
1343 (forward-line)
1344 (delete-region (point-min) (point))))
1345 ;; If STRING begins with ^ or any normal character, we need
1346 ;; to remove the last line from the session buffer, since it
1347 ;; was just spell-checked, and we don't want to check it again.
1348 ;; The same goes for the # command, since Ispell already saved
1349 ;; the personal dictionary.
1350 (set-buffer session-buf)
1351 (delete-region prev-pos (point))
1352 ;; Ispell run synchronously saves the personal dictionary
1353 ;; after each successful command. So we can remove any
1354 ;; lines in the session buffer that insert words into the
1355 ;; dictionary.
1356 (if (memq status '(0 nil))
1357 (let ((more-lines t))
1358 (goto-char (point-min))
1359 (while more-lines
1360 (if (looking-at "^\\*")
1361 (let ((start (point)))
1362 (forward-line)
1363 (delete-region start (point)))
1364 (setq more-lines (= 0 (forward-line))))))))))))))
1365
1366
1367
1368 ;;;###autoload
1369 (defun ispell-word (&optional following quietly continue)
1370 "Check spelling of word under or before the cursor.
1371 If the word is not found in dictionary, display possible corrections
1372 in a window allowing you to choose one.
1373
1374 If optional argument FOLLOWING is non-nil or if `ispell-following-word'
1375 is non-nil when called interactively, then the following word
1376 \(rather than preceding\) is checked when the cursor is not over a word.
1377 When the optional argument QUIETLY is non-nil or `ispell-quietly' is non-nil
1378 when called interactively, non-corrective messages are suppressed.
1379
1380 With a prefix argument (or if CONTINUE is non-nil),
1381 resume interrupted spell-checking of a buffer or region.
1382
1383 Word syntax described by `ispell-dictionary-alist' (which see).
1384
1385 This will check or reload the dictionary. Use \\[ispell-change-dictionary]
1386 or \\[ispell-region] to update the Ispell process.
1387
1388 return values:
1389 nil word is correct or spelling is accepted.
1390 0 word is inserted into buffer-local definitions.
1391 \"word\" word corrected from word list.
1392 \(\"word\" arg\) word is hand entered.
1393 quit spell session exited."
1394
1395 (interactive (list nil nil current-prefix-arg))
1396 (if continue
1397 (ispell-continue)
1398 (if (interactive-p)
1399 (setq following ispell-following-word
1400 quietly ispell-quietly))
1401 (ispell-accept-buffer-local-defs) ; use the correct dictionary
1402 (let ((cursor-location (point)) ; retain cursor location
1403 (word (ispell-get-word following))
1404 start end poss new-word replace)
1405 ;; De-structure return word info list.
1406 (setq start (car (cdr word))
1407 end (car (cdr (cdr word)))
1408 word (car word))
1409
1410 ;; now check spelling of word if it has 3 or more characters.
1411 (cond
1412 ((> (length word) 2)
1413 (or quietly
1414 (message "Checking spelling of %s..."
1415 (funcall ispell-format-word word)))
1416 (ispell-send-string "%\n") ; put in verbose mode
1417 (ispell-send-string (concat "^" word "\n"))
1418 ;; wait until ispell has processed word
1419 (while (progn
1420 (ispell-accept-output)
1421 (not (string= "" (car ispell-filter)))))
1422 ;;(ispell-send-string "!\n") ;back to terse mode.
1423 (setq ispell-filter (cdr ispell-filter)) ; remove extra \n
1424 (if (and ispell-filter (listp ispell-filter))
1425 (if (> (length ispell-filter) 1)
1426 (error "Ispell and its process have different character maps")
1427 (setq poss (ispell-parse-output (car ispell-filter)))))
1428 (cond ((eq poss t)
1429 (or quietly
1430 (message "%s is correct"
1431 (funcall ispell-format-word word)))
1432 (and (fboundp 'extent-at)
1433 (extent-at start)
1434 (delete-extent (extent-at start))))
1435 ((stringp poss)
1436 (or quietly
1437 (message "%s is correct because of root %s"
1438 (funcall ispell-format-word word)
1439 (funcall ispell-format-word poss)))
1440 (and (fboundp 'extent-at)
1441 (extent-at start)
1442 (delete-extent (extent-at start))))
1443 ((null poss) (message "Error in ispell process"))
1444 (ispell-check-only ; called from ispell minor mode.
1445 (if (fboundp 'make-extent)
1446 (let ((ext (make-extent start end)))
1447 (set-extent-property ext 'face ispell-highlight-face)
1448 (set-extent-property ext 'priority 2000))
1449 (beep)
1450 (message "%s is incorrect"(funcall ispell-format-word word))))
1451 (t ; prompt for correct word.
1452 (save-window-excursion
1453 (setq replace (ispell-command-loop
1454 (car (cdr (cdr poss)))
1455 (car (cdr (cdr (cdr poss))))
1456 (car poss) start end)))
1457 (cond ((equal 0 replace)
1458 (ispell-add-per-file-word-list (car poss)))
1459 (replace
1460 (setq new-word (if (atom replace) replace (car replace))
1461 cursor-location (+ (- (length word) (- end start))
1462 cursor-location))
1463 (if (not (equal new-word (car poss)))
1464 (progn
1465 (delete-region start end)
1466 (setq start (point))
1467 (insert new-word)
1468 (setq end (point))))
1469 (if (not (atom replace)) ;recheck spelling of replacement
1470 (progn
1471 (if (car (cdr replace)) ; query replace requested
1472 (save-window-excursion
1473 (query-replace word new-word t)))
1474 (goto-char start)
1475 ;; single word could be split into multiple words
1476 (setq ispell-quit (not (ispell-region start end)))
1477 ))))
1478 ;; keep if rechecking word and we keep choices win.
1479 (if (get-buffer ispell-choices-buffer)
1480 (kill-buffer ispell-choices-buffer))))
1481 (ispell-pdict-save ispell-silently-savep)
1482 ;; NB: Cancels ispell-quit incorrectly if called from ispell-region
1483 (if ispell-quit (setq ispell-quit nil replace 'quit))))
1484 (goto-char cursor-location) ; return to original location
1485 replace)))
1486
1487
1488 (defun ispell-get-word (following &optional extra-otherchars)
1489 "Return the word for spell-checking according to ispell syntax.
1490 If optional argument FOLLOWING is non-nil or if `ispell-following-word'
1491 is non-nil when called interactively, then the following word
1492 \(rather than preceding\) is checked when the cursor is not over a word.
1493 Optional second argument contains otherchars that can be included in word
1494 many times.
1495
1496 Word syntax described by `ispell-dictionary-alist' (which see)."
1497 (let* ((ispell-casechars (ispell-get-casechars))
1498 (ispell-not-casechars (ispell-get-not-casechars))
1499 (ispell-otherchars (ispell-get-otherchars))
1500 (ispell-many-otherchars-p (ispell-get-many-otherchars-p))
1501 (word-regexp (concat ispell-casechars
1502 "+\\("
1503 (if (not (string= "" ispell-otherchars))
1504 (concat ispell-otherchars "?"))
1505 (if extra-otherchars
1506 (concat extra-otherchars "?"))
1507 ispell-casechars
1508 "+\\)"
1509 (if (or ispell-many-otherchars-p
1510 extra-otherchars)
1511 "*" "?")))
1512 did-it-once prevpt
1513 start end word)
1514 ;; find the word
1515 (if (not (looking-at ispell-casechars))
1516 (if following
1517 (re-search-forward ispell-casechars (point-max) t)
1518 (re-search-backward ispell-casechars (point-min) t)))
1519 ;; move to front of word
1520 (re-search-backward ispell-not-casechars (point-min) 'start)
1521 (while (and (or (and (not (string= "" ispell-otherchars))
1522 (looking-at ispell-otherchars))
1523 (and extra-otherchars (looking-at extra-otherchars)))
1524 (not (bobp))
1525 (or (not did-it-once)
1526 ispell-many-otherchars-p)
1527 (not (eq prevpt (point))))
1528 (if (and extra-otherchars (looking-at extra-otherchars))
1529 (progn
1530 (backward-char 1)
1531 (if (looking-at ispell-casechars)
1532 (re-search-backward ispell-not-casechars (point-min) 'move)))
1533 (setq did-it-once t
1534 prevpt (point))
1535 (backward-char 1)
1536 (if (looking-at ispell-casechars)
1537 (re-search-backward ispell-not-casechars (point-min) 'move)
1538 (backward-char -1))))
1539 ;; Now mark the word and save to string.
1540 (if (not (re-search-forward word-regexp (point-max) t))
1541 (if ispell-check-only
1542 ;; return dummy word when just flagging misspellings
1543 (list "" (point) (point))
1544 (error "No word found to check!"))
1545 (setq start (match-beginning 0)
1546 end (point)
1547 word (buffer-substring-no-properties start end))
1548 (list word start end))))
1549
1550
1551 ;;; Global ispell-pdict-modified-p is set by ispell-command-loop and
1552 ;;; tracks changes in the dictionary. The global may either be
1553 ;;; a value or a list, whose value is the state of whether the
1554 ;;; dictionary needs to be saved.
1555
1556 ;;;###autoload
1557 (defun ispell-pdict-save (&optional no-query force-save)
1558 "Check to see if the personal dictionary has been modified.
1559 If so, ask if it needs to be saved."
1560 (interactive (list ispell-silently-savep t))
1561 (if (and ispell-pdict-modified-p (listp ispell-pdict-modified-p))
1562 (setq ispell-pdict-modified-p (car ispell-pdict-modified-p)))
1563 (if (or ispell-pdict-modified-p force-save)
1564 (if (or no-query (y-or-n-p "Personal dictionary modified. Save? "))
1565 (progn
1566 (ispell-send-string "#\n") ; save dictionary
1567 (message "Personal dictionary saved."))))
1568 ;; unassert variable, even if not saved to avoid questioning.
1569 (setq ispell-pdict-modified-p nil))
1570
1571
1572 (defun ispell-command-loop (miss guess word start end)
1573 "Display possible corrections from list MISS.
1574 GUESS lists possibly valid affix construction of WORD.
1575 Returns nil to keep word.
1576 Returns 0 to insert locally into buffer-local dictionary.
1577 Returns string for new chosen word.
1578 Returns list for new replacement word (will be rechecked).
1579 Query-replace when list length is 2.
1580 Automatic query-replace when second element is `query-replace'.
1581 Highlights the word, which is assumed to run from START to END.
1582 Global `ispell-pdict-modified-p' becomes a list where the only value
1583 indicates whether the dictionary has been modified when option `a' or `i' is
1584 used.
1585 Global `ispell-quit' set to start location to continue spell session."
1586 (let ((count ?0)
1587 (line ispell-choices-win-default-height)
1588 ;; ensure 4 context lines.
1589 (max-lines (- (ispell-adjusted-window-height) 4))
1590 (choices miss)
1591 (window-min-height (min window-min-height
1592 ispell-choices-win-default-height))
1593 (command-characters '( ? ?i ?a ?A ?r ?R ?? ?x ?X ?q ?l ?u ?m ))
1594 (dedicated (window-dedicated-p (selected-window)))
1595 (skipped 0)
1596 char num result textwin dedicated-win)
1597
1598 ;; setup the *Choices* buffer with valid data.
1599 (save-excursion
1600 (set-buffer (get-buffer-create ispell-choices-buffer))
1601 (setq mode-line-format (concat "-- %b -- word: " word))
1602 ;; XEmacs: no need for horizontal scrollbar in choices window
1603 (and (fboundp 'set-specifier)
1604 (boundp 'horizontal-scrollbar-visible-p)
1605 (set-specifier horizontal-scrollbar-visible-p nil
1606 (cons (current-buffer) nil)))
1607 (erase-buffer)
1608 (if guess
1609 (progn
1610 (insert "Affix rules generate and capitalize "
1611 "this word as shown below:\n\t")
1612 (while guess
1613 (if (> (+ 4 (current-column) (length (car guess)))
1614 (window-width))
1615 (progn
1616 (insert "\n\t")
1617 (setq line (1+ line))))
1618 (insert (car guess) " ")
1619 (setq guess (cdr guess)))
1620 (insert "\nUse option `i' if this is a correct composition"
1621 " from the derivative root.\n")
1622 (setq line (+ line (if choices 3 2)))))
1623 (while (and choices
1624 (< (if (> (+ 7 (current-column) (length (car choices))
1625 (if (> count ?~) 3 0))
1626 (window-width))
1627 (progn
1628 (insert "\n")
1629 (setq line (1+ line)))
1630 line)
1631 max-lines))
1632 ;; not so good if there are over 20 or 30 options, but then, if
1633 ;; there are that many you don't want to scan them all anyway...
1634 (while (memq count command-characters) ; skip command characters.
1635 (setq count (ispell-int-char (1+ count))
1636 skipped (1+ skipped)))
1637 (insert "(" count ") " (car choices) " ")
1638 (setq choices (cdr choices)
1639 count (ispell-int-char (1+ count))))
1640 (setq count (ispell-int-char (- count ?0 skipped))))
1641
1642 ;; ensure word is visible
1643 (if (not (pos-visible-in-window-p end))
1644 (sit-for 0))
1645
1646 ;; allow temporary split of dedicated windows...
1647 (if dedicated
1648 (progn
1649 (setq dedicated-win (selected-window))
1650 (set-window-dedicated-p dedicated-win nil)))
1651
1652 ;; Display choices for misspelled word.
1653 (ispell-show-choices line end)
1654 (select-window (setq textwin (next-window)))
1655
1656 ;; highlight word, protecting current buffer status
1657 (unwind-protect
1658 (progn
1659 (and ispell-highlight-p
1660 (ispell-highlight-spelling-error start end t))
1661 ;; Loop until a valid choice is made.
1662 (while
1663 (eq
1664 t
1665 (setq
1666 result
1667 (progn
1668 (undo-boundary)
1669 (let (message-log-max)
1670 (message (concat "C-h or ? for more options; SPC to leave "
1671 "unchanged, Character to replace word")))
1672 (let ((inhibit-quit t))
1673 (setq char (if (fboundp 'read-char-exclusive)
1674 (read-char-exclusive)
1675 (read-char))
1676 skipped 0)
1677 (if (or quit-flag (= char ?\C-g)) ; C-g is like typing X
1678 (setq char ?X
1679 quit-flag nil)))
1680 ;; Adjust num to array offset skipping command characters.
1681 (let ((com-chars command-characters))
1682 (while com-chars
1683 (if (and (> (car com-chars) ?0) (< (car com-chars) char))
1684 (setq skipped (1+ skipped)))
1685 (setq com-chars (cdr com-chars)))
1686 (setq num (- char ?0 skipped)))
1687
1688 (cond
1689 ((= char ? ) nil) ; accept word this time only
1690 ((= char ?i) ; accept and insert word into pers dict
1691 (ispell-send-string (concat "*" word "\n"))
1692 (setq ispell-pdict-modified-p '(t)) ; dictionary modified!
1693 nil)
1694 ((or (= char ?a) (= char ?A)) ; accept word without insert
1695 (ispell-send-string (concat "@" word "\n"))
1696 (if (null ispell-pdict-modified-p)
1697 (setq ispell-pdict-modified-p
1698 (list ispell-pdict-modified-p)))
1699 (if (= char ?A) 0)) ; return 0 for ispell-add buffer-local
1700 ((or (= char ?r) (= char ?R)) ; type in replacement
1701 (and (eq 'block ispell-highlight-p) ; refresh tty's
1702 (ispell-highlight-spelling-error start end nil t))
1703 (let ((result
1704 (if (or (= char ?R) ispell-query-replace-choices)
1705 (list (read-string
1706 (format "Query-replacement for %s: "word)
1707 word)
1708 t)
1709 (cons (read-string "Replacement for: " word)
1710 nil))))
1711 (and (eq 'block ispell-highlight-p)
1712 (ispell-highlight-spelling-error start end nil
1713 'block))
1714 result))
1715 ((or (= char ??) (= char help-char) (= char ?\C-h))
1716 (and (eq 'block ispell-highlight-p)
1717 (ispell-highlight-spelling-error start end nil t))
1718 (ispell-help)
1719 (and (eq 'block ispell-highlight-p)
1720 (ispell-highlight-spelling-error start end nil
1721 'block))
1722 t)
1723 ;; Quit and move point back.
1724 ((= char ?x)
1725 (ispell-pdict-save ispell-silently-savep)
1726 (message "Exited spell-checking")
1727 (setq ispell-quit t)
1728 nil)
1729 ;; Quit and preserve point.
1730 ((= char ?X)
1731 (ispell-pdict-save ispell-silently-savep)
1732 (message "%s"
1733 (substitute-command-keys
1734 (concat "Spell-checking suspended;"
1735 " use C-u \\[ispell-word] to resume")))
1736 (setq ispell-quit start)
1737 nil)
1738 ((= char ?q)
1739 (if (y-or-n-p "Really kill Ispell process? ")
1740 (progn
1741 (ispell-kill-ispell t) ; terminate process.
1742 (setq ispell-quit (or (not ispell-checking-message)
1743 (point))
1744 ispell-pdict-modified-p nil))
1745 t)) ; continue if they don't quit.
1746 ((= char ?l)
1747 (and (eq 'block ispell-highlight-p) ; refresh tty displays
1748 (ispell-highlight-spelling-error start end nil t))
1749 (let ((new-word (read-string
1750 "Lookup string (`*' is wildcard): "
1751 word)))
1752 (if new-word
1753 (progn
1754 (save-excursion
1755 (set-buffer (get-buffer-create
1756 ispell-choices-buffer))
1757 (erase-buffer)
1758 (setq count ?0
1759 skipped 0
1760 mode-line-format (concat
1761 "-- %b -- word: "
1762 new-word)
1763 miss (lookup-words new-word)
1764 choices miss
1765 line ispell-choices-win-default-height)
1766 (while (and choices ; adjust choices window.
1767 (< (if (> (+ 7 (current-column)
1768 (length (car choices))
1769 (if (> count ?~) 3 0))
1770 (window-width))
1771 (progn
1772 (insert "\n")
1773 (setq line (1+ line)))
1774 line)
1775 max-lines))
1776 (while (memq count command-characters)
1777 (setq count (ispell-int-char (1+ count))
1778 skipped (1+ skipped)))
1779 (insert "(" count ") " (car choices) " ")
1780 (setq choices (cdr choices)
1781 count (ispell-int-char (1+ count))))
1782 (setq count (ispell-int-char
1783 (- count ?0 skipped))))
1784 (ispell-show-choices line end)
1785 (select-window (next-window)))))
1786 (and (eq 'block ispell-highlight-p)
1787 (ispell-highlight-spelling-error start end nil
1788 'block))
1789 t) ; reselect from new choices
1790 ((= char ?u) ; insert lowercase into dictionary
1791 (ispell-send-string (concat "*" (downcase word) "\n"))
1792 (setq ispell-pdict-modified-p '(t)) ; dictionary modified!
1793 nil)
1794 ((= char ?m) ; type in what to insert
1795 (ispell-send-string
1796 (concat "*" (read-string "Insert: " word) "\n"))
1797 (setq ispell-pdict-modified-p '(t))
1798 (cons word nil))
1799 ((and (>= num 0) (< num count))
1800 (if ispell-query-replace-choices ; Query replace flag
1801 (list (nth num miss) 'query-replace)
1802 (nth num miss)))
1803 ((= char ?\C-l)
1804 (redraw-display) t)
1805 ((= char ?\C-r)
1806 ;; This may have alignment errors if current line is edited
1807 (if (marker-position ispell-recursive-edit-marker)
1808 (progn
1809 (message "Only one recursive edit session supported")
1810 (beep)
1811 (sit-for 2))
1812 (set-marker ispell-recursive-edit-marker start)
1813 ;;(set-marker ispell-region-end reg-end)
1814 (and ispell-highlight-p ; unhighlight
1815 (ispell-highlight-spelling-error start end))
1816 (unwind-protect
1817 (progn
1818 (message
1819 "%s"
1820 (substitute-command-keys
1821 (concat "Exit recursive edit with"
1822 " \\[exit-recursive-edit]")))
1823 (save-window-excursion (save-excursion
1824 (recursive-edit))))
1825 ;; protected
1826 (goto-char ispell-recursive-edit-marker)
1827 (if (not (equal (marker-buffer
1828 ispell-recursive-edit-marker)
1829 (current-buffer)))
1830 (progn
1831 (set-marker ispell-recursive-edit-marker nil)
1832 (error
1833 "Cannot continue ispell from this buffer.")))
1834 (set-marker ispell-recursive-edit-marker nil)))
1835 (list word nil)) ; recheck starting at this word.
1836 ((= char ?\C-z)
1837 (funcall (key-binding "\C-z"))
1838 t)
1839 (t (ding) t))))))
1840 result)
1841 ;; protected
1842 (and ispell-highlight-p ; unhighlight
1843 (save-window-excursion
1844 (select-window textwin)
1845 (ispell-highlight-spelling-error start end)))
1846 (if dedicated
1847 (set-window-dedicated-p dedicated-win t)))))
1848
1849
1850
1851 (defun ispell-show-choices (line end)
1852 "Shows the choices in another buffer or frame."
1853 (if (and ispell-use-framepop-p (fboundp 'framepop-display-buffer))
1854 (progn
1855 (framepop-display-buffer (get-buffer ispell-choices-buffer))
1856 (get-buffer-window ispell-choices-buffer t)
1857 (select-window (previous-window))) ; *Choices* window
1858 ;; standard selection by splitting a small buffer out of this window.
1859 (let ((choices-window (get-buffer-window ispell-choices-buffer)))
1860 (if choices-window
1861 (if (= line (ispell-adjusted-window-height choices-window))
1862 (select-window choices-window)
1863 ;; *Choices* window changed size. Adjust the choices window
1864 ;; without scrolling the spelled window when possible
1865 (let ((window-line
1866 (- line (ispell-adjusted-window-height choices-window)))
1867 (visible (progn (vertical-motion -1) (point))))
1868 (if (< line ispell-choices-win-default-height)
1869 (setq window-line (+ window-line
1870 (- ispell-choices-win-default-height
1871 line))))
1872 (move-to-window-line 0)
1873 (vertical-motion window-line)
1874 (set-window-start (selected-window)
1875 (if (> (point) visible) visible (point)))
1876 (goto-char end)
1877 (select-window choices-window)
1878 (enlarge-window window-line)))
1879 ;; Overlay *Choices* window when it isn't showing
1880 (ispell-overlay-window (max line ispell-choices-win-default-height)))
1881 (switch-to-buffer ispell-choices-buffer)
1882 (goto-char (point-min)))))
1883
1884
1885 ;;;###autoload
1886 (defun ispell-help ()
1887 "Display a list of the options available when a misspelling is encountered.
1888
1889 Selections are:
1890
1891 DIGIT: Replace the word with a digit offered in the *Choices* buffer.
1892 SPC: Accept word this time.
1893 `i': Accept word and insert into private dictionary.
1894 `a': Accept word for this session.
1895 `A': Accept word and place in `buffer-local dictionary'.
1896 `r': Replace word with typed-in value. Rechecked.
1897 `R': Replace word with typed-in value. Query-replaced in buffer. Rechecked.
1898 `?': Show these commands.
1899 `x': Exit spelling buffer. Move cursor to original point.
1900 `X': Exit spelling buffer. Leaves cursor at the current point, and permits
1901 the aborted check to be completed later.
1902 `q': Quit spelling session (Kills ispell process).
1903 `l': Look up typed-in replacement in alternate dictionary. Wildcards okay.
1904 `u': Like `i', but the word is lower-cased first.
1905 `m': Place typed-in value in personal dictionary, then recheck current word.
1906 `C-l': redraws screen
1907 `C-r': recursive edit
1908 `C-z': suspend emacs or iconify frame"
1909
1910 (if (equal ispell-help-in-bufferp 'electric)
1911 (progn
1912 (require 'ehelp)
1913 (with-electric-help
1914 (function (lambda ()
1915 ;;This shouldn't be necessary: with-electric-help needs
1916 ;; an optional argument telling it about the smallest
1917 ;; acceptable window-height of the help buffer.
1918 ;;(if (< (window-height) 15)
1919 ;; (enlarge-window
1920 ;; (- 15 (ispell-adjusted-window-height))))
1921 (princ "Selections are:
1922
1923 DIGIT: Replace the word with a digit offered in the *Choices* buffer.
1924 SPC: Accept word this time.
1925 `i': Accept word and insert into private dictionary.
1926 `a': Accept word for this session.
1927 `A': Accept word and place in `buffer-local dictionary'.
1928 `r': Replace word with typed-in value. Rechecked.
1929 `R': Replace word with typed-in value. Query-replaced in buffer. Rechecked.
1930 `?': Show these commands.
1931 `x': Exit spelling buffer. Move cursor to original point.
1932 `X': Exit spelling buffer. Leaves cursor at the current point, and permits
1933 the aborted check to be completed later.
1934 `q': Quit spelling session (Kills ispell process).
1935 `l': Look up typed-in replacement in alternate dictionary. Wildcards okay.
1936 `u': Like `i', but the word is lower-cased first.
1937 `m': Place typed-in value in personal dictionary, then recheck current word.
1938 `C-l': redraws screen
1939 `C-r': recursive edit
1940 `C-z': suspend emacs or iconify frame")
1941 nil ;undocumented requirement of with-electric-help
1942 ))))
1943
1944
1945 (let ((help-1 (concat "[r/R]eplace word; [a/A]ccept for this session; "
1946 "[i]nsert into private dictionary"))
1947 (help-2 (concat "[l]ook a word up in alternate dictionary; "
1948 "e[x/X]it; [q]uit session"))
1949 (help-3 (concat "[u]ncapitalized insert into dict. "
1950 "Type 'x C-h d ispell-help' for more help")))
1951 (save-window-excursion
1952 (if ispell-help-in-bufferp
1953 (progn
1954 (ispell-overlay-window 4)
1955 (switch-to-buffer (get-buffer-create "*Ispell Help*"))
1956 (insert (concat help-1 "\n" help-2 "\n" help-3))
1957 (sit-for 5)
1958 (kill-buffer "*Ispell Help*"))
1959 (unwind-protect
1960 (progn
1961 (select-window (minibuffer-window))
1962 (erase-buffer)
1963 (message nil)
1964 ;;(set-minibuffer-window (selected-window))
1965 (enlarge-window 2)
1966 (insert (concat help-1 "\n" help-2 "\n" help-3))
1967 (sit-for 5))
1968 (erase-buffer)))))))
1969
1970
1971 (defun lookup-words (word &optional lookup-dict)
1972 "Look up WORD in optional word-list dictionary LOOKUP-DICT.
1973 A `*' serves as a wild card. If no wild cards, `look' is used if it exists.
1974 Otherwise the variable `ispell-grep-command' contains the command used to
1975 search for the words (usually egrep).
1976
1977 Optional second argument contains the dictionary to use; the default is
1978 `ispell-alternate-dictionary'."
1979 ;; We don't use the filter for this function, rather the result is written
1980 ;; into a buffer. Hence there is no need to save the filter values.
1981 (if (null lookup-dict)
1982 (setq lookup-dict ispell-alternate-dictionary))
1983
1984 (let* ((process-connection-type ispell-use-ptys-p)
1985 (wild-p (string-match "\\*" word))
1986 (look-p (and ispell-look-p ; Only use look for an exact match.
1987 (or ispell-have-new-look (not wild-p))))
1988 (ispell-grep-buffer (get-buffer-create "*Ispell-Temp*")) ; result buf
1989 (prog (if look-p ispell-look-command ispell-grep-command))
1990 (args (if look-p ispell-look-options ispell-grep-options))
1991 status results loc)
1992 (unwind-protect
1993 (save-window-excursion
1994 (message "Starting \"%s\" process..." (file-name-nondirectory prog))
1995 (set-buffer ispell-grep-buffer)
1996 (if look-p
1997 nil
1998 ;; convert * to .*
1999 (insert "^" word "$")
2000 (while (search-backward "*" nil t) (insert "."))
2001 (setq word (buffer-string))
2002 (erase-buffer))
2003 (setq status (if lookup-dict
2004 (call-process prog nil t nil args word lookup-dict)
2005 (call-process prog nil t nil args word)))
2006 ;; grep returns status 1 and no output when word not found, which
2007 ;; is a perfectly normal thing.
2008 (if (stringp status)
2009 (setq results (cons (format "error: %s exited with signal %s"
2010 (file-name-nondirectory prog) status)
2011 results))
2012 ;; else collect words into `results' in FIFO order
2013 (goto-char (point-max))
2014 ;; assure we've ended with \n
2015 (or (bobp) (= (preceding-char) ?\n) (insert ?\n))
2016 (while (not (bobp))
2017 (setq loc (point))
2018 (forward-line -1)
2019 (setq results (cons (buffer-substring-no-properties (point)
2020 (1- loc))
2021 results)))))
2022 ;; protected
2023 (kill-buffer ispell-grep-buffer)
2024 (if (and results (string-match ".+: " (car results)))
2025 (error "%s error: %s" ispell-grep-command (car results))))
2026 results))
2027
2028
2029 ;;; "ispell-filter" is a list of output lines from the generating function.
2030 ;;; Each full line (ending with \n) is a separate item on the list.
2031 ;;; "output" can contain multiple lines, part of a line, or both.
2032 ;;; "start" and "end" are used to keep bounds on lines when "output" contains
2033 ;;; multiple lines.
2034 ;;; "ispell-filter-continue" is true when we have received only part of a
2035 ;;; line as output from a generating function ("output" did not end with \n)
2036 ;;; THIS FUNCTION WILL FAIL IF THE PROCESS OUTPUT DOESN'T END WITH \n!
2037 ;;; This is the case when a process dies or fails. The default behavior
2038 ;;; in this case treats the next input received as fresh input.
2039
2040 (defun ispell-filter (process output)
2041 "Output filter function for ispell, grep, and look."
2042 (let ((start 0)
2043 (continue t)
2044 end)
2045 (while continue
2046 (setq end (string-match "\n" output start)) ; get text up to the newline.
2047 ;; If we get out of sync and ispell-filter-continue is asserted when we
2048 ;; are not continuing, treat the next item as a separate list. When
2049 ;; ispell-filter-continue is asserted, ispell-filter *should* always be a
2050 ;; list!
2051
2052 ;; Continue with same line (item)?
2053 (if (and ispell-filter-continue ispell-filter (listp ispell-filter))
2054 ;; Yes. Add it to the prev item
2055 (setcar ispell-filter
2056 (concat (car ispell-filter) (substring output start end)))
2057 ;; No. This is a new line and item.
2058 (setq ispell-filter
2059 (cons (substring output start end) ispell-filter)))
2060 (if (null end)
2061 ;; We've completed reading the output, but didn't finish the line.
2062 (setq ispell-filter-continue t continue nil)
2063 ;; skip over newline, this line complete.
2064 (setq ispell-filter-continue nil end (1+ end))
2065 (if (= end (length output)) ; No more lines in output
2066 (setq continue nil) ; so we can exit the filter.
2067 (setq start end)))))) ; else move start to next line of input
2068
2069
2070 ;;; This function destroys the mark location if it is in the word being
2071 ;;; highlighted.
2072 (defun ispell-highlight-spelling-error-generic (start end &optional highlight
2073 refresh)
2074 "Highlight the word from START to END with a kludge using `inverse-video'.
2075 When the optional third arg HIGHLIGHT is set, the word is highlighted;
2076 otherwise it is displayed normally.
2077 Uses block cursor to highlight one character.
2078 Optional REFRESH will unhighlighted then highlight, using block cursor
2079 highlighting when REFRESH is equal to `block'."
2080 (and (eq 'block ispell-highlight-p)
2081 (or (eq 'block refresh)
2082 (setq start (1+ start)))) ; On block non-refresh, inc start.
2083 (let ((modified (buffer-modified-p)) ; don't allow this fn to modify buffer
2084 (buffer-read-only nil) ; Allow highlighting read-only buffers.
2085 (text (buffer-substring-no-properties start end)) ; Save hilight region
2086 (inhibit-quit t) ; inhibit interrupt processing here.
2087 (buffer-undo-list t)) ; don't clutter the undo list.
2088 (goto-char end)
2089 (delete-region start end)
2090 (insert-char ? (- end start)) ; minimize amount of redisplay
2091 (sit-for 0) ; update display
2092 (if highlight (setq inverse-video (not inverse-video))) ; toggle video
2093 (delete-region start end) ; delete whitespace
2094 (insert text) ; insert text in inverse video.
2095 (sit-for 0) ; update display showing inverse video.
2096 (if (not highlight)
2097 (goto-char end)
2098 (setq inverse-video (not inverse-video)) ; toggle video
2099 (and (eq 'block ispell-highlight-p)
2100 (goto-char (1- start)))) ; use block cursor to "highlight" char
2101 (set-buffer-modified-p modified) ; don't modify if flag not set.
2102 (and refresh ; re-highlight
2103 (ispell-highlight-spelling-error-generic
2104 (if (eq 'block refresh) start (- start 2)) end t))))
2105
2106
2107 (defun ispell-highlight-spelling-error-xemacs (start end &optional highlight)
2108 "Highlight the word from START to END using `isearch-highlight'.
2109 When the optional third arg HIGHLIGHT is set, the word is highlighted,
2110 otherwise it is displayed normally."
2111 (if highlight
2112 (isearch-highlight start end)
2113 (isearch-dehighlight t))
2114 ;;(sit-for 0)
2115 )
2116
2117
2118 (defun ispell-highlight-spelling-error-overlay (start end &optional highlight)
2119 "Highlight the word from START to END using overlays.
2120 When the optional third arg HIGHLIGHT is set, the word is highlighted
2121 otherwise it is displayed normally.
2122
2123 The variable `ispell-highlight-face' selects the face to use for highlighting."
2124 (if highlight
2125 (progn
2126 (setq ispell-overlay (make-overlay start end))
2127 (overlay-put ispell-overlay 'face ispell-highlight-face))
2128 (delete-overlay ispell-overlay)))
2129
2130
2131 (defun ispell-highlight-spelling-error (start end &optional highlight refresh)
2132 (cond
2133 ((featurep 'xemacs)
2134 (ispell-highlight-spelling-error-xemacs start end highlight))
2135 ((and (featurep 'faces)
2136 (or (and (fboundp 'display-color-p) (display-color-p))
2137 window-system))
2138 (ispell-highlight-spelling-error-overlay start end highlight))
2139 (t (ispell-highlight-spelling-error-generic start end highlight refresh))))
2140
2141 (defun ispell-adjusted-window-height (&optional window)
2142 "Like `window-height', adjusted to correct for the effect of tall mode-lines.
2143 The value returned is actually the nominal number of text-lines in the
2144 window plus 1. On a terminal, this is the same value returned by
2145 `window-height', but if the window has a mode-line is taller than a normal
2146 text line, the returned value may be smaller than that from
2147 `window-height'."
2148 (cond ((fboundp 'window-text-height)
2149 (1+ (window-text-height window)))
2150 ((or (and (fboundp 'display-graphic-p) (display-graphic-p))
2151 (and (featurep 'xemacs) window-system))
2152 (1- (window-height window)))
2153 (t
2154 (window-height window))))
2155
2156 (defun ispell-overlay-window (height)
2157 "Create a window covering the top HEIGHT lines of the current window.
2158 Ensure that the line above point is still visible but otherwise avoid
2159 scrolling the current window. Leave the new window selected."
2160 (save-excursion
2161 (let ((oldot (save-excursion (vertical-motion -1) (point)))
2162 (top (save-excursion (move-to-window-line height) (point))))
2163 ;; If line above old point (line starting at oldot) would be
2164 ;; hidden by new window, scroll it to just below new win
2165 ;; otherwise set top line of other win so it doesn't scroll.
2166 (if (< oldot top) (setq top oldot))
2167 ;; if frame is unsplitable, temporarily disable that...
2168 (if (cdr (assq 'unsplittable (frame-parameters (selected-frame))))
2169 (let ((frame (selected-frame)))
2170 (modify-frame-parameters frame '((unsplittable . nil)))
2171 (split-window nil height)
2172 (modify-frame-parameters frame '((unsplittable . t))))
2173 (split-window nil height))
2174 (let ((deficit (- height (ispell-adjusted-window-height))))
2175 (when (> deficit 0)
2176 ;; Number of lines the window is still too short. We ensure that
2177 ;; there are at least (1- HEIGHT) lines visible in the window.
2178 (enlarge-window deficit)
2179 (goto-char top)
2180 (vertical-motion deficit)
2181 (setq top (min (point) oldot))))
2182 (set-window-start (next-window) top))))
2183
2184
2185 ;;; Should we add a compound word match return value?
2186 (defun ispell-parse-output (output &optional accept-list shift)
2187 "Parse the OUTPUT string from Ispell process and return:
2188 1: t for an exact match.
2189 2: A string containing the root word matched via suffix removal.
2190 3: A list of possible correct spellings of the format:
2191 (\"ORIGINAL-WORD\" OFFSET MISS-LIST GUESS-LIST)
2192 ORIGINAL-WORD is a string of the possibly misspelled word.
2193 OFFSET is an integer giving the line offset of the word.
2194 MISS-LIST and GUESS-LIST are possibly null lists of guesses and misses.
2195 4: nil when an error has occurred.
2196
2197 Optional second arg ACCEPT-LIST is list of words already accepted.
2198 Optional third arg SHIFT is an offset to apply based on previous corrections."
2199 (cond
2200 ((string= output "") t) ; for startup with pipes...
2201 ((string= output "*") t) ; exact match
2202 ((string= output "-") t) ; compound word match
2203 ((eq (aref output 0) ?+) ; found because of root word
2204 (substring output 2)) ; return root word
2205 ((equal 0 (string-match "[\ra-zA-Z]" output))
2206 (ding) ; error message from ispell!
2207 (message (concat "Ispell error: " output))
2208 (sit-for 5)
2209 nil)
2210 (t ; need to process &, ?, and #'s
2211 (let ((type (aref output 0)) ; &, ?, or #
2212 (original-word (substring output 2 (string-match " " output 2)))
2213 (cur-count 0) ; contains number of misses + guesses
2214 count miss-list guess-list offset)
2215 (setq output (substring output (match-end 0))) ; skip over misspelling
2216 (if (eq type ?#)
2217 (setq count 0) ; no misses for type #
2218 (setq count (string-to-int output) ; get number of misses.
2219 output (substring output (1+ (string-match " " output 1)))))
2220 (setq offset (string-to-int output))
2221 (if (eq type ?#) ; No miss or guess list.
2222 (setq output nil)
2223 (setq output (substring output (1+ (string-match " " output 1)))))
2224 (while output
2225 (let ((end (string-match ", \\|\\($\\)" output))) ; end of miss/guess.
2226 (setq cur-count (1+ cur-count))
2227 (if (> cur-count count)
2228 (setq guess-list (cons (substring output 0 end) guess-list))
2229 (setq miss-list (cons (substring output 0 end) miss-list)))
2230 (if (match-end 1) ; True only when at end of line.
2231 (setq output nil) ; no more misses or guesses
2232 (setq output (substring output (+ end 2))))))
2233 ;; return results. Accept word if it was already accepted.
2234 ;; adjust offset.
2235 (if (member original-word accept-list)
2236 t
2237 (list original-word
2238 (if (numberp shift) (+ shift offset) offset)
2239 (nreverse miss-list) (nreverse guess-list)))))))
2240
2241
2242 (defun ispell-process-status ()
2243 "Return the status of the Ispell process.
2244 When asynchronous processes are not supported, `run' is always returned."
2245 (if ispell-async-processp
2246 (process-status ispell-process)
2247 (and ispell-process 'run)))
2248
2249
2250 (defun ispell-start-process ()
2251 "Start the ispell process, with support for no asynchronous processes.
2252 Keeps argument list for future ispell invocations for no async support."
2253 (let (args)
2254 ;; Local dictionary becomes the global dictionary in use.
2255 (if ispell-local-dictionary
2256 (setq ispell-dictionary ispell-local-dictionary))
2257 (setq args (ispell-get-ispell-args))
2258 (if (and ispell-dictionary ; use specified dictionary
2259 (not (member "-d" args))) ; only define if not overridden
2260 (setq args
2261 (append (list "-d" ispell-dictionary) args)))
2262 (if ispell-personal-dictionary ; use specified pers dict
2263 (setq args
2264 (append args
2265 (list "-p"
2266 (expand-file-name ispell-personal-dictionary)))))
2267 (setq args (append args ispell-extra-args))
2268
2269 (if ispell-async-processp
2270 (let ((process-connection-type ispell-use-ptys-p))
2271 (apply 'start-process
2272 "ispell" nil ispell-program-name
2273 "-a" ; accept single input lines
2274 "-m" ; make root/affix combos not in dict
2275 args))
2276 (setq ispell-cmd-args args
2277 ispell-output-buffer (generate-new-buffer " *ispell-output*")
2278 ispell-session-buffer (generate-new-buffer " *ispell-session*"))
2279 (ispell-send-string "\032\n") ; so Ispell prints version and exits
2280 t)))
2281
2282
2283
2284 (defun ispell-init-process ()
2285 "Check status of Ispell process and start if necessary."
2286 (if (and ispell-process
2287 (eq (ispell-process-status) 'run)
2288 ;; If we're using a personal dictionary, ensure
2289 ;; we're in the same default directory!
2290 (or (not ispell-personal-dictionary)
2291 (equal ispell-process-directory default-directory)))
2292 (setq ispell-filter nil ispell-filter-continue nil)
2293 ;; may need to restart to select new personal dictionary.
2294 (ispell-kill-ispell t)
2295 (message "Starting new Ispell process...")
2296 (sit-for 0)
2297 (setq ispell-library-directory (ispell-check-version)
2298 ispell-process-directory default-directory
2299 ispell-process (ispell-start-process)
2300 ispell-filter nil
2301 ispell-filter-continue nil)
2302 (if ispell-async-processp
2303 (set-process-filter ispell-process 'ispell-filter))
2304 ;; protect against bogus binding of `enable-multibyte-characters' in XEmacs
2305 (if (and (or (featurep 'xemacs)
2306 (and (boundp 'enable-multibyte-characters)
2307 enable-multibyte-characters))
2308 (fboundp 'set-process-coding-system))
2309 (set-process-coding-system ispell-process (ispell-get-coding-system)
2310 (ispell-get-coding-system)))
2311 ;; Get version ID line
2312 (ispell-accept-output 3)
2313 ;; get more output if filter empty?
2314 (if (null ispell-filter) (ispell-accept-output 3))
2315 (cond ((null ispell-filter)
2316 (error "%s did not output version line" ispell-program-name))
2317 ((and
2318 (stringp (car ispell-filter))
2319 (if (string-match "warning: " (car ispell-filter))
2320 (progn
2321 (ispell-accept-output 3) ; was warn msg.
2322 (stringp (car ispell-filter)))
2323 (null (cdr ispell-filter)))
2324 (string-match "^@(#) " (car ispell-filter)))
2325 ;; got the version line as expected (we already know it's the right
2326 ;; version, so don't bother checking again.)
2327 nil)
2328 (t
2329 ;; Otherwise, it must be an error message. Show the user.
2330 ;; But first wait to see if some more output is going to arrive.
2331 ;; Otherwise we get cool errors like "Can't open ".
2332 (sleep-for 1)
2333 (ispell-accept-output 3)
2334 (error "%s" (mapconcat 'identity ispell-filter "\n"))))
2335 (setq ispell-filter nil) ; Discard version ID line
2336 (let ((extended-char-mode (ispell-get-extended-character-mode)))
2337 (if extended-char-mode ; ~ extended character mode
2338 (ispell-send-string (concat extended-char-mode "\n"))))
2339 (if ispell-async-processp
2340 (process-kill-without-query ispell-process))))
2341
2342 ;;;###autoload
2343 (defun ispell-kill-ispell (&optional no-error)
2344 "Kill current Ispell process (so that you may start a fresh one).
2345 With NO-ERROR, just return non-nil if there was no Ispell running."
2346 (interactive)
2347 (if (not (and ispell-process
2348 (eq (ispell-process-status) 'run)))
2349 (or no-error
2350 (error "There is no ispell process running!"))
2351 (if ispell-async-processp
2352 (progn
2353 (process-send-eof ispell-process)
2354 (if (eq (ispell-process-status) 'run)
2355 (ispell-accept-output 1))
2356 (if (eq (ispell-process-status) 'run)
2357 (kill-process ispell-process))
2358 (while (not (or (eq (ispell-process-status) 'exit)
2359 (eq (ispell-process-status) 'signal)))
2360 (sleep-for 0.25)))
2361 ;; synchronous processes
2362 (ispell-send-string "\n") ; make sure side effects occurred.
2363 (kill-buffer ispell-output-buffer)
2364 (kill-buffer ispell-session-buffer)
2365 (setq ispell-output-buffer nil
2366 ispell-session-buffer nil))
2367 (setq ispell-process nil)
2368 (message "Ispell process killed")
2369 nil))
2370
2371
2372 ;;; ispell-change-dictionary is set in some people's hooks. Maybe this should
2373 ;;; call ispell-init-process rather than wait for a spell checking command?
2374
2375 ;;;###autoload
2376 (defun ispell-change-dictionary (dict &optional arg)
2377 "Change `ispell-dictionary' (q.v.) to DICT and kill old Ispell process.
2378 A new one will be started as soon as necessary.
2379
2380 By just answering RET you can find out what the current dictionary is.
2381
2382 With prefix argument, set the default dictionary."
2383 (interactive
2384 (list (completing-read
2385 "Use new dictionary (RET for current, SPC to complete): "
2386 (and (fboundp 'ispell-valid-dictionary-list)
2387 (mapcar (lambda (x)(cons x nil)) (ispell-valid-dictionary-list)))
2388 nil t)
2389 current-prefix-arg))
2390 (if (equal dict "default") (setq dict nil))
2391 ;; This relies on completing-read's bug of returning "" for no match
2392 (cond ((equal dict "")
2393 (message "Using %s dictionary"
2394 (or ispell-local-dictionary ispell-dictionary "default")))
2395 ((and (equal dict ispell-dictionary)
2396 (or (null ispell-local-dictionary)
2397 (equal dict ispell-local-dictionary)))
2398 ;; Specified dictionary is the default already. No-op
2399 (and (interactive-p)
2400 (message "No change, using %s dictionary" (or dict "default"))))
2401 (t ; reset dictionary!
2402 (if (assoc dict ispell-dictionary-alist)
2403 (progn
2404 (if (or arg (null dict)) ; set default dictionary
2405 (setq ispell-dictionary dict))
2406 (if (null arg) ; set local dictionary
2407 (setq ispell-local-dictionary dict)))
2408 (error "Undefined dictionary: %s" dict))
2409 (ispell-kill-ispell t)
2410 (message "(Next %sIspell command will use %s dictionary)"
2411 (cond ((equal ispell-local-dictionary ispell-dictionary)
2412 "")
2413 (arg "global ")
2414 (t "local "))
2415 (or (if (or (equal ispell-local-dictionary ispell-dictionary)
2416 (null arg))
2417 ispell-local-dictionary
2418 ispell-dictionary)
2419 "default")))))
2420
2421
2422 ;;; Spelling of comments are checked when ispell-check-comments is non-nil.
2423
2424 ;;;###autoload
2425 (defun ispell-region (reg-start reg-end &optional recheckp shift)
2426 "Interactively check a region for spelling errors.
2427 Return nil if spell session is quit,
2428 otherwise returns shift offset amount for last line processed."
2429 (interactive "r") ; Don't flag errors on read-only bufs.
2430 (if (not recheckp)
2431 (ispell-accept-buffer-local-defs)) ; set up dictionary, local words, etc.
2432 (let ((skip-region-start (make-marker))
2433 (rstart (make-marker)))
2434 (unwind-protect
2435 (save-excursion
2436 (message "Spell checking %s using %s dictionary..."
2437 (if (and (= reg-start (point-min)) (= reg-end (point-max)))
2438 (buffer-name) "region")
2439 (or ispell-dictionary "default"))
2440 ;; Returns cursor to original location.
2441 (save-window-excursion
2442 (goto-char reg-start)
2443 (let ((transient-mark-mode)
2444 (case-fold-search case-fold-search)
2445 (query-fcc t)
2446 in-comment key)
2447 (let (message-log-max)
2448 (message "searching for regions to skip"))
2449 (if (re-search-forward (ispell-begin-skip-region-regexp) reg-end t)
2450 (progn
2451 (setq key (buffer-substring-no-properties
2452 (match-beginning 0) (match-end 0)))
2453 (set-marker skip-region-start (- (point) (length key)))
2454 (goto-char reg-start)))
2455 (let (message-log-max)
2456 (message "Continuing spelling check using %s dictionary..."
2457 (or ispell-dictionary "default")))
2458 (set-marker rstart reg-start)
2459 (set-marker ispell-region-end reg-end)
2460 (while (and (not ispell-quit)
2461 (< (point) ispell-region-end))
2462 ;; spell-check region with skipping
2463 (if (and (marker-position skip-region-start)
2464 (<= skip-region-start (point)))
2465 (progn
2466 ;; If region inside line comment, must keep comment start.
2467 (setq in-comment (point)
2468 in-comment
2469 (and comment-start
2470 (or (null comment-end) (string= "" comment-end))
2471 (save-excursion
2472 (beginning-of-line)
2473 (re-search-forward comment-start in-comment t))
2474 comment-start))
2475 ;; Can change skip-regexps (in ispell-message)
2476 (ispell-skip-region key) ; moves pt past region.
2477 (set-marker rstart (point))
2478 ;; check for saving large attachments...
2479 (setq query-fcc (and query-fcc
2480 (ispell-ignore-fcc skip-region-start
2481 rstart)))
2482 (if (and (< rstart ispell-region-end)
2483 (re-search-forward
2484 (ispell-begin-skip-region-regexp)
2485 ispell-region-end t))
2486 (progn
2487 (setq key (buffer-substring-no-properties
2488 (car (match-data))
2489 (car (cdr (match-data)))))
2490 (set-marker skip-region-start
2491 (- (point) (length key)))
2492 (goto-char rstart))
2493 (set-marker skip-region-start nil))))
2494 (setq reg-end (max (point)
2495 (if (marker-position skip-region-start)
2496 (min skip-region-start ispell-region-end)
2497 (marker-position ispell-region-end))))
2498 (let* ((start (point))
2499 (end (save-excursion (end-of-line) (min (point) reg-end)))
2500 (string (ispell-get-line start end in-comment)))
2501 (if in-comment ; account for comment chars added
2502 (setq start (- start (length in-comment))
2503 in-comment nil))
2504 (setq end (point)) ; "end" tracks region retrieved.
2505 (if string ; there is something to spell check!
2506 ;; (special start end)
2507 (setq shift (ispell-process-line string
2508 (and recheckp shift))))
2509 (goto-char end)))))
2510 (if ispell-quit
2511 nil
2512 (or shift 0)))
2513 ;; protected
2514 (if (and (not (and recheckp ispell-keep-choices-win))
2515 (get-buffer ispell-choices-buffer))
2516 (kill-buffer ispell-choices-buffer))
2517 (set-marker skip-region-start nil)
2518 (set-marker rstart nil)
2519 (if ispell-quit
2520 (progn
2521 ;; preserve or clear the region for ispell-continue.
2522 (if (not (numberp ispell-quit))
2523 (set-marker ispell-region-end nil)
2524 ;; Ispell-continue enabled - ispell-region-end is set.
2525 (goto-char ispell-quit))
2526 ;; Check for aborting
2527 (if (and ispell-checking-message (numberp ispell-quit))
2528 (progn
2529 (setq ispell-quit nil)
2530 (error "Message send aborted")))
2531 (if (not recheckp) (setq ispell-quit nil)))
2532 (if (not recheckp) (set-marker ispell-region-end nil))
2533 ;; Only save if successful exit.
2534 (ispell-pdict-save ispell-silently-savep)
2535 (message "Spell-checking done")))))
2536
2537
2538 (defun ispell-begin-skip-region-regexp ()
2539 "Returns a regexp of the search keys for region skipping.
2540 Includes `ispell-skip-region-alist' plus tex, tib, html, and comment keys.
2541 Must call after ispell-buffer-local-parsing due to dependence on mode."
2542 ;; start with regions generic to all buffers
2543 (let ((skip-regexp (ispell-begin-skip-region ispell-skip-region-alist)))
2544 ;; Comments
2545 (if (and (null ispell-check-comments) comment-start)
2546 (setq skip-regexp (concat (regexp-quote comment-start) "\\|"
2547 skip-regexp)))
2548 (if (and (eq 'exclusive ispell-check-comments) comment-start)
2549 ;; search from end of current comment to start of next comment.
2550 (setq skip-regexp (concat (if (string= "" comment-end) "^"
2551 (regexp-quote comment-end))
2552 "\\|" skip-regexp)))
2553 ;; tib
2554 (if ispell-skip-tib
2555 (setq skip-regexp (concat ispell-tib-ref-beginning "\\|" skip-regexp)))
2556 ;; html stuff
2557 (if ispell-skip-html
2558 (setq skip-regexp (concat
2559 (ispell-begin-skip-region ispell-html-skip-alists)
2560 "\\|"
2561 skip-regexp)))
2562 ;; tex
2563 (if (eq ispell-parser 'tex)
2564 (setq skip-regexp (concat (ispell-begin-tex-skip-regexp) "\\|"
2565 skip-regexp)))
2566 ;; messages
2567 (if (and ispell-checking-message
2568 (not (eq t ispell-checking-message)))
2569 (setq skip-regexp (concat
2570 (mapconcat (lambda (lst) (car lst))
2571 ispell-checking-message
2572 "\\|")
2573 "\\|"
2574 skip-regexp)))
2575
2576 ;; return new regexp
2577 skip-regexp))
2578
2579
2580 (defun ispell-begin-skip-region (skip-alist)
2581 "Regular expression for start of regions to skip generated from SKIP-ALIST.
2582 Each selection should be a key of SKIP-ALIST;
2583 otherwise, the current line is skipped."
2584 (mapconcat (lambda (lst) (if (stringp (car lst)) (car lst) (eval (car lst))))
2585 skip-alist
2586 "\\|"))
2587
2588
2589 (defun ispell-begin-tex-skip-regexp ()
2590 "Regular expression of tex commands to skip.
2591 Generated from `ispell-tex-skip-alists'."
2592 (concat
2593 ;; raw tex keys
2594 (mapconcat (function (lambda (lst) (car lst)))
2595 (car ispell-tex-skip-alists)
2596 "\\|")
2597 "\\|"
2598 ;; keys wrapped in begin{}
2599 (mapconcat (function (lambda (lst)
2600 (concat "\\\\begin[ \t\n]*{[ \t\n]*"
2601 (car lst)
2602 "[ \t\n]*}")))
2603 (car (cdr ispell-tex-skip-alists))
2604 "\\|")))
2605
2606
2607 (defun ispell-skip-region-list ()
2608 "Returns a list describing key and body regions to skip for this buffer.
2609 Includes regions defined by `ispell-skip-region-alist', tex mode,
2610 `ispell-html-skip-alists', and `ispell-checking-message'.
2611 Manual checking must include comments and tib references.
2612 The list is of the form described by variable `ispell-skip-region-alist'.
2613 Must call after `ispell-buffer-local-parsing' due to dependence on mode."
2614 (let ((skip-alist ispell-skip-region-alist))
2615 ;; only additional explicit region definition is tex.
2616 (if (eq ispell-parser 'tex)
2617 (setq case-fold-search nil
2618 skip-alist (append (car ispell-tex-skip-alists)
2619 (car (cdr ispell-tex-skip-alists))
2620 skip-alist)))
2621 (if ispell-skip-html
2622 (setq skip-alist (append ispell-html-skip-alists skip-alist)))
2623 (if (and ispell-checking-message
2624 (not (eq t ispell-checking-message)))
2625 (setq skip-alist (append ispell-checking-message skip-alist)))
2626 skip-alist))
2627
2628
2629 (defun ispell-tex-arg-end (&optional arg)
2630 "Skip across ARG number of braces."
2631 (condition-case nil
2632 (progn
2633 (while (looking-at "[ \t\n]*\\[") (forward-sexp))
2634 (forward-sexp (or arg 1)))
2635 (error
2636 (message "error skipping s-expressions at point %d." (point))
2637 (beep)
2638 (sit-for 2))))
2639
2640
2641 (defun ispell-ignore-fcc (start end)
2642 "Deletes the Fcc: message header when large attachments are included.
2643 Return value `nil' if file with large attachments are saved.
2644 This can be used to avoid multiple questions for multiple large attachments.
2645 Returns point to starting location afterwards."
2646 (let ((result t))
2647 (if (and ispell-checking-message ispell-message-fcc-skip)
2648 (if (< ispell-message-fcc-skip (- end start))
2649 (let (case-fold-search head-end)
2650 (goto-char (point-min))
2651 (setq head-end
2652 (or (re-search-forward
2653 (concat "^" (regexp-quote mail-header-separator) "$")
2654 nil t)
2655 (re-search-forward "^$" nil t)
2656 (point-min)))
2657 (goto-char (point-min))
2658 (if (re-search-forward "^Fcc:" head-end t)
2659 (if (y-or-n-p
2660 "Save copy of this message with large attachments? ")
2661 (setq result nil)
2662 (beginning-of-line)
2663 (kill-line 1)))
2664 (goto-char end))))
2665 result))
2666
2667
2668 (defun ispell-skip-region (key)
2669 "Skips across KEY and then to end of region.
2670 Key lookup determines region to skip.
2671 Point is placed at end of skipped region."
2672 ;; move over key to begin checking.
2673 (forward-char (length key))
2674 (let ((start (point))
2675 ;; Regenerate each call... This function can change region definition.
2676 (alist (ispell-skip-region-list))
2677 alist-key null-skip)
2678 (cond
2679 ;; what about quoted comment, or comment inside strings?
2680 ((and (null ispell-check-comments) comment-start
2681 (string= key comment-start))
2682 (if (string= "" comment-end)
2683 (forward-line)
2684 (search-forward comment-end ispell-region-end t)))
2685 ((and (eq 'exclusive ispell-check-comments) comment-start
2686 (string= key comment-end))
2687 (search-forward comment-start ispell-region-end :end))
2688 ((and ispell-skip-tib (string-match ispell-tib-ref-beginning key))
2689 (re-search-forward ispell-tib-ref-end ispell-region-end t))
2690 ;; markings from alist
2691 (t
2692 (while alist
2693 (setq alist-key (eval (car (car alist))))
2694 (if (string-match alist-key key)
2695 (progn
2696 (setq alist (cdr (car alist)))
2697 (cond
2698 ((null alist) (setq null-skip t)) ; done! Just skip key.
2699 ((not (consp alist))
2700 ;; Search past end of spell region to find this region end.
2701 (re-search-forward (eval alist) (point-max) t))
2702 ((and (= 1 (length alist))
2703 (stringp (car alist)))
2704 (re-search-forward (car alist) (point-max) t))
2705 (t
2706 (setq null-skip t) ; error handling in functions!
2707 (if (consp (cdr alist))
2708 (apply (car alist) (cdr alist))
2709 (funcall (car alist)))))
2710 (setq alist nil))
2711 (setq alist (cdr alist))))))
2712 (if (and (= start (point)) (null null-skip))
2713 (progn
2714 (message "Matching region end for `%s' point %d not found"
2715 key (point))
2716 (beep)
2717 (sit-for 2)))))
2718
2719
2720 ;;; Grab the next line of data.
2721 ;;; Returns a string with the line data
2722 (defun ispell-get-line (start end in-comment)
2723 (let ((ispell-casechars (ispell-get-casechars))
2724 string)
2725 (cond ; LOOK AT THIS LINE AND SKIP OR PROCESS
2726 ((eolp) ; END OF LINE, just go to next line.
2727 (forward-line))
2728 ;;((looking-at "[-#@*+!%~^]") ; SKIP SPECIAL ISPELL CHARACTERS
2729 ;; (forward-char 1)) ; not needed as quoted below.
2730 ((or (re-search-forward ispell-casechars end t) ; TEXT EXISTS
2731 (re-search-forward "[][()${}]" end t)) ; or MATH COMMANDS
2732 (setq string (concat "^" in-comment
2733 (buffer-substring-no-properties start end)
2734 "\n"))
2735 (goto-char end))
2736 (t (goto-char end))) ; EMPTY LINE, skip it.
2737 string))
2738
2739
2740 ;;; Avoid error messages when compiling for these dynamic variables.
2741 (eval-when-compile
2742 (defvar start)
2743 (defvar end))
2744
2745 (defun ispell-process-line (string shift)
2746 "Sends a LINE of text to ispell and processes the result.
2747 This will modify the buffer for spelling errors.
2748 Requires variables START and END to be defined in its lexical scope.
2749 Returns the sum shift due to changes in word replacements."
2750 ;;(declare special start end)
2751 (let (poss accept-list)
2752 (if (not (numberp shift))
2753 (setq shift 0))
2754 ;; send string to spell process and get input.
2755 (ispell-send-string string)
2756 (while (progn
2757 (ispell-accept-output)
2758 ;; Last item of output contains a blank line.
2759 (not (string= "" (car ispell-filter)))))
2760 ;; parse all inputs from the stream one word at a time.
2761 ;; Place in FIFO order and remove the blank item.
2762 (setq ispell-filter (nreverse (cdr ispell-filter)))
2763 (while (and (not ispell-quit) ispell-filter)
2764 ;; get next word, accounting for accepted words and start shifts
2765 (setq poss (ispell-parse-output (car ispell-filter)
2766 accept-list shift))
2767 (if (and poss (listp poss)) ; spelling error occurred.
2768 ;; Whenever we have misspellings, we can change
2769 ;; the buffer. Keep boundaries as markers.
2770 ;; Markers can move with highlighting! This destroys
2771 ;; end of region markers line-end and ispell-region-end
2772 (let ((word-start
2773 (copy-marker (+ start ispell-offset (car (cdr poss)))))
2774 (word-len (length (car poss)))
2775 (line-end (copy-marker end))
2776 (line-start (copy-marker start))
2777 recheck-region replace)
2778 (goto-char word-start)
2779 ;; Adjust the horizontal scroll & point
2780 (ispell-horiz-scroll)
2781 (goto-char (+ word-len word-start))
2782 (ispell-horiz-scroll)
2783 (goto-char word-start)
2784 (ispell-horiz-scroll)
2785
2786 ;; Alignment cannot be tracked and this error will occur when
2787 ;; `query-replace' makes multiple corrections on the starting line.
2788 (if (/= (+ word-len (point))
2789 (progn
2790 ;; NB: Search can fail with Mule coding systems that don't
2791 ;; display properly. Ignore the error in this case?
2792 (search-forward (car poss) (+ word-len (point)) t)
2793 (point)))
2794 ;; This occurs due to filter pipe problems
2795 (error (concat "Ispell misalignment: word "
2796 "`%s' point %d; probably incompatible versions")
2797 (car poss) (marker-position word-start)))
2798 ;; ispell-cmd-loop can go recursive & change buffer
2799 (if ispell-keep-choices-win
2800 (setq replace (ispell-command-loop
2801 (car (cdr (cdr poss)))
2802 (car (cdr (cdr (cdr poss))))
2803 (car poss) (marker-position word-start)
2804 (+ word-len (marker-position word-start))))
2805 (save-window-excursion
2806 (setq replace (ispell-command-loop
2807 (car (cdr (cdr poss)))
2808 (car (cdr (cdr (cdr poss))))
2809 (car poss) (marker-position word-start)
2810 (+ word-len (marker-position word-start))))))
2811
2812 (goto-char word-start)
2813 ;; Recheck when query replace edit changes misspelled word.
2814 ;; Error in tex mode when a potential math mode change exists.
2815 (if (and replace (listp replace) (= 2 (length replace)))
2816 (if (and (eq ispell-parser 'tex)
2817 (string-match "[\\\\][]()[]\\|\\\\begin\\|\\$"
2818 (regexp-quote string)))
2819 (error
2820 "Don't start query replace on a line with math characters"
2821 )
2822 (set-marker line-end (point))
2823 (setq ispell-filter nil
2824 recheck-region t)))
2825
2826 ;; insert correction if needed
2827 (cond
2828 ((or (null replace)
2829 (equal 0 replace)) ; ACCEPT/INSERT
2830 (if (equal 0 replace) ; BUFFER-LOCAL DICT ADD
2831 (ispell-add-per-file-word-list (car poss)))
2832 ;; do not recheck accepted word on this line
2833 (setq accept-list (cons (car poss) accept-list)))
2834 (t ; replacement word selected or entered
2835 (delete-region (point) (+ word-len (point)))
2836 (if (not (listp replace))
2837 (progn
2838 (insert replace) ; insert dictionary word
2839 (setq accept-list (cons replace accept-list)))
2840 (let ((replace-word (car replace)))
2841 ;; Recheck hand entered replacement word
2842 (insert replace-word)
2843 (if (car (cdr replace))
2844 (save-window-excursion
2845 (delete-other-windows) ; to correctly show help.
2846 ;; Assume case-replace &
2847 ;; case-fold-search correct?
2848 (query-replace (car poss) (car replace) t)))
2849 (goto-char word-start)
2850 ;; do not recheck if already accepted
2851 (if (member replace-word accept-list)
2852 (setq accept-list (cons replace-word accept-list)
2853 replace replace-word)
2854 (let ((region-end (copy-marker ispell-region-end)))
2855 (setq recheck-region ispell-filter
2856 ispell-filter nil ; save filter
2857 shift 0 ; already accounted
2858 shift (ispell-region
2859 word-start
2860 (+ word-start (length replace-word))
2861 t shift))
2862 (if (null shift) ; quitting check.
2863 (setq shift 0))
2864 (set-marker ispell-region-end region-end)
2865 (set-marker region-end nil)
2866 (setq ispell-filter recheck-region
2867 recheck-region nil
2868 replace replace-word)))))
2869
2870 (setq shift (+ shift (- (length replace) word-len)))
2871
2872 ;; Move line-start across word...
2873 ;; new shift function does this now...
2874 ;;(set-marker line-start (+ line-start
2875 ;; (- (length replace)
2876 ;; (length (car poss)))))
2877 ))
2878 (if (not ispell-quit)
2879 (let (message-log-max)
2880 (message "Continuing spelling check using %s dictionary..."
2881 (or ispell-dictionary "default"))))
2882 (sit-for 0)
2883 (setq start (marker-position line-start)
2884 end (marker-position line-end))
2885 ;; Adjust markers when end of region lost from highlighting.
2886 (if (and (not recheck-region) (< end (+ word-start word-len)))
2887 (setq end (+ word-start word-len)))
2888 (if (= word-start ispell-region-end)
2889 (set-marker ispell-region-end (+ word-start word-len)))
2890 ;; going out of scope - unneeded
2891 (set-marker line-start nil)
2892 (set-marker word-start nil)
2893 (set-marker line-end nil)))
2894 ;; finished with misspelling!
2895 (setq ispell-filter (cdr ispell-filter)))
2896 shift))
2897
2898
2899 ;;;###autoload
2900 (defun ispell-comments-and-strings ()
2901 "Check comments and strings in the current buffer for spelling errors."
2902 (interactive)
2903 (goto-char (point-min))
2904 (let (state done)
2905 (while (not done)
2906 (setq done t)
2907 (setq state (parse-partial-sexp (point) (point-max)
2908 nil nil state 'syntax-table))
2909 (if (or (nth 3 state) (nth 4 state))
2910 (let ((start (point)))
2911 (setq state (parse-partial-sexp start (point-max)
2912 nil nil state 'syntax-table))
2913 (if (or (nth 3 state) (nth 4 state))
2914 (error "Unterminated string or comment"))
2915 (save-excursion
2916 (setq done (not (ispell-region start (point))))))))))
2917
2918
2919 ;;;###autoload
2920 (defun ispell-buffer ()
2921 "Check the current buffer for spelling errors interactively."
2922 (interactive)
2923 (ispell-region (point-min) (point-max)))
2924
2925
2926 ;;;###autoload
2927 (defun ispell-continue ()
2928 "Continue a halted spelling session beginning with the current word."
2929 (interactive)
2930 (if (not (marker-position ispell-region-end))
2931 (message "No session to continue. Use 'X' command when checking!")
2932 (if (not (equal (marker-buffer ispell-region-end) (current-buffer)))
2933 (message "Must continue ispell from buffer %s"
2934 (buffer-name (marker-buffer ispell-region-end)))
2935 (ispell-region
2936 ;; find beginning of current word:
2937 (car (cdr (ispell-get-word t)))
2938 (marker-position ispell-region-end)))))
2939
2940
2941 ;;; Horizontal scrolling
2942 (defun ispell-horiz-scroll ()
2943 "Places point within the horizontal visibility of its window area."
2944 (if truncate-lines ; display truncating lines?
2945 ;; See if display needs to be scrolled.
2946 (let ((column (- (current-column) (max (window-hscroll) 1))))
2947 (if (and (< column 0) (> (window-hscroll) 0))
2948 (scroll-right (max (- column) 10))
2949 (if (>= column (- (window-width) 2))
2950 (scroll-left (max (- column (window-width) -3) 10)))))))
2951
2952
2953 ;;; Interactive word completion.
2954 ;;; Forces "previous-word" processing. Do we want to make this selectable?
2955
2956 ;;;###autoload
2957 (defun ispell-complete-word (&optional interior-frag)
2958 "Try to complete the word before or under point (see `lookup-words').
2959 If optional INTERIOR-FRAG is non-nil then the word may be a character
2960 sequence inside of a word.
2961
2962 Standard ispell choices are then available."
2963 (interactive "P")
2964 (let ((cursor-location (point))
2965 (case-fold-search-val case-fold-search)
2966 (word (ispell-get-word nil "\\*")) ; force "previous-word" processing.
2967 start end possibilities replacement)
2968 (setq start (car (cdr word))
2969 end (car (cdr (cdr word)))
2970 word (car word)
2971 possibilities
2972 (or (string= word "") ; Will give you every word
2973 (lookup-words (concat (and interior-frag "*") word
2974 (if (or interior-frag (null ispell-look-p))
2975 "*"))
2976 ispell-complete-word-dict)))
2977 (cond ((eq possibilities t)
2978 (message "No word to complete"))
2979 ((null possibilities)
2980 (message "No match for \"%s\"" word))
2981 (t ; There is a modification...
2982 (setq case-fold-search nil) ; Try and respect case of word.
2983 (cond
2984 ((string-equal (upcase word) word)
2985 (setq possibilities (mapcar 'upcase possibilities)))
2986 ((eq (upcase (aref word 0)) (aref word 0))
2987 (setq possibilities (mapcar (function
2988 (lambda (pos)
2989 (if (eq (aref word 0) (aref pos 0))
2990 pos
2991 (capitalize pos))))
2992 possibilities))))
2993 (setq case-fold-search case-fold-search-val)
2994 (save-window-excursion
2995 (setq replacement
2996 (ispell-command-loop possibilities nil word start end)))
2997 (cond
2998 ((equal 0 replacement) ; BUFFER-LOCAL ADDITION
2999 (ispell-add-per-file-word-list word))
3000 (replacement ; REPLACEMENT WORD
3001 (delete-region start end)
3002 (setq word (if (atom replacement) replacement (car replacement))
3003 cursor-location (+ (- (length word) (- end start))
3004 cursor-location))
3005 (insert word)
3006 (if (not (atom replacement)) ; recheck spelling of replacement.
3007 (progn
3008 (goto-char cursor-location)
3009 (ispell-word nil t)))))
3010 (if (get-buffer ispell-choices-buffer)
3011 (kill-buffer ispell-choices-buffer))))
3012 (ispell-pdict-save ispell-silently-savep)
3013 (goto-char cursor-location)))
3014
3015
3016 ;;;###autoload
3017 (defun ispell-complete-word-interior-frag ()
3018 "Completes word matching character sequence inside a word."
3019 (interactive)
3020 (ispell-complete-word t))
3021
3022
3023 ;;;###autoload
3024 (defun ispell ()
3025 "Interactively check a region or buffer for spelling errors.
3026 If `transient-mark-mode' is on, and a region is active, spell-check
3027 that region. Otherwise spell-check the buffer.
3028
3029 Ispell dictionaries are not distributed with Emacs. If you are
3030 looking for a dictionary, please see the distribution of the GNU ispell
3031 program, or do an Internet search; there are various dictionaries
3032 available on the net."
3033 (interactive)
3034 (if (and (boundp 'transient-mark-mode) transient-mark-mode
3035 (boundp 'mark-active) mark-active)
3036 (ispell-region (region-beginning) (region-end))
3037 (ispell-buffer)))
3038
3039
3040 ;;; **********************************************************************
3041 ;;; Ispell Minor Mode
3042 ;;; **********************************************************************
3043
3044 (defvar ispell-minor-mode nil
3045 "Non-nil if Ispell minor mode is enabled.")
3046 ;; Variable indicating that ispell minor mode is active.
3047 (make-variable-buffer-local 'ispell-minor-mode)
3048
3049 (or (assq 'ispell-minor-mode minor-mode-alist)
3050 (setq minor-mode-alist
3051 (cons '(ispell-minor-mode " Spell") minor-mode-alist)))
3052
3053 (defvar ispell-minor-keymap
3054 (let ((map (make-sparse-keymap)))
3055 (define-key map " " 'ispell-minor-check)
3056 (define-key map "\r" 'ispell-minor-check)
3057 map)
3058 "Keymap used for Ispell minor mode.")
3059
3060 (or (not (boundp 'minor-mode-map-alist))
3061 (assoc 'ispell-minor-mode minor-mode-map-alist)
3062 (setq minor-mode-map-alist
3063 (cons (cons 'ispell-minor-mode ispell-minor-keymap)
3064 minor-mode-map-alist)))
3065
3066 ;;;###autoload
3067 (defun ispell-minor-mode (&optional arg)
3068 "Toggle Ispell minor mode.
3069 With prefix arg, turn Ispell minor mode on iff arg is positive.
3070
3071 In Ispell minor mode, pressing SPC or RET
3072 warns you if the previous word is incorrectly spelled.
3073
3074 All the buffer-local variables and dictionaries are ignored -- to read
3075 them into the running ispell process, type \\[ispell-word] SPC."
3076 (interactive "P")
3077 (setq ispell-minor-mode
3078 (not (or (and (null arg) ispell-minor-mode)
3079 (<= (prefix-numeric-value arg) 0))))
3080 (force-mode-line-update))
3081
3082 (defun ispell-minor-check ()
3083 "Check previous word then continue with the normal binding of this key.
3084 Don't check previous word when character before point is a space or newline.
3085 Don't read buffer-local settings or word lists."
3086 (interactive "*")
3087 (let ((ispell-minor-mode nil)
3088 (ispell-check-only t)
3089 (last-char (char-after (1- (point)))))
3090 (command-execute (key-binding (this-command-keys)))
3091 (if (not (or (eq last-char ?\ ) (eq last-char ?\n)
3092 (and ispell-skip-html (eq last-char ?>))
3093 (and ispell-skip-html (eq last-char ?\;))))
3094 (ispell-word nil t))))
3095
3096
3097 ;;; **********************************************************************
3098 ;;; Ispell Message
3099 ;;; **********************************************************************
3100
3101 (defvar ispell-message-text-end
3102 (mapconcat (function identity)
3103 '(
3104 ;; Don't spell check signatures
3105 "^-- $"
3106 ;; Matches postscript files.
3107 ;;"^%!PS-Adobe-[123].0"
3108 ;; Matches uuencoded text
3109 ;;"^begin [0-9][0-9][0-9] .*\nM.*\nM.*\nM"
3110 ;; Matches shell files (especially auto-decoding)
3111 "^#! /bin/[ck]?sh"
3112 ;; Matches context difference listing
3113 "\\(\\(^cd .*\n\\)?diff -c .*\\)?\n\\*\\*\\* .*\n--- .*\n\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*"
3114 ;; Matches unidiff difference listing
3115 "\\(diff -u .*\\)?\n--- .*\n\\+\\+\\+ .*\n@@ [-+][0-9]+,[0-9]+ [-+][0-9]+,[0-9]+ @@\n"
3116 ;; Matches reporter.el bug report
3117 "^current state:\n==============\n"
3118 ;; Matches commonly used "cut" boundaries
3119 "^\\(- \\)?[-=_]+\\s ?\\(cut here\\|Environment Follows\\)")
3120 "\\|")
3121 "*End of text which will be checked in `ispell-message'.
3122 If it is a string, limit at first occurrence of that regular expression.
3123 Otherwise, it must be a function which is called to get the limit.")
3124
3125
3126 (defun ispell-mime-multipartp (&optional limit)
3127 "Return multipart message start boundary or nil if none."
3128 ;; caller must ensure `case-fold-search' is set to `t'
3129 (and
3130 (re-search-forward
3131 "Content-Type: *multipart/\\([^ \t\n]*;[ \t]*[\n]?[ \t]*\\)+boundary="
3132 limit t)
3133 (let (boundary)
3134 (if (looking-at "\"")
3135 (let (start)
3136 (forward-char)
3137 (setq start (point))
3138 (while (not (looking-at "\""))
3139 (forward-char 1))
3140 (setq boundary (buffer-substring-no-properties start (point))))
3141 (let ((start (point)))
3142 (while (looking-at "[-0-9a-zA-Z'()+_,./:=?]")
3143 (forward-char))
3144 (setq boundary (buffer-substring-no-properties start (point)))))
3145 (if (< (length boundary) 1)
3146 (setq boundary nil)
3147 (concat "--" boundary)))))
3148
3149
3150 (defun ispell-mime-skip-part (boundary)
3151 "Moves point across header, or entire MIME part if message is encoded.
3152 All specified types except `7bit' `8bit' and `quoted-printable' are considered
3153 encoded and therefore skipped. See rfc 1521, 2183, ...
3154 If no boundary is given, then entire message is skipped.
3155
3156 This starts one line ABOVE the MIME content messages, on the boundary marker,
3157 for operation with the generic region-skipping code.
3158 This places new MIME boundaries into variable `ispell-checking-message'."
3159 (forward-line) ; skip over boundary to headers
3160 (let ((save-case-fold-search case-fold-search)
3161 (continuep t)
3162 textp)
3163 (setq case-fold-search t
3164 ispell-skip-html nil)
3165 (while continuep
3166 (setq continuep nil)
3167 (if (looking-at "Content-Type: *text/")
3168 (progn
3169 (goto-char (match-end 0))
3170 (if (looking-at "html")
3171 (setq ispell-skip-html t))
3172 (setq textp t
3173 continuep t)
3174 (re-search-forward "\\(.*;[ \t]*[\n]\\)*.*$" nil t)
3175 (forward-line)))
3176 (if (looking-at "Content-Transfer-Encoding: *\\([^ \t\n]*\\)")
3177 (let ((match (buffer-substring (match-beginning 1) (match-end 1))))
3178 (setq textp (member (upcase match)
3179 ;; only spell check the following encodings:
3180 '("7BIT" "8BIT" "QUOTED-PRINTABLE" "BINARY"))
3181 continuep t)
3182 (goto-char (match-end 0))
3183 (re-search-forward "\\(.*;[ \t]*[\n]\\)*.*$" nil t)
3184 (forward-line)))
3185 ;; hierarchical boundary definition
3186 (if (looking-at "Content-Type: *multipart/")
3187 (let ((new-boundary (ispell-mime-multipartp)))
3188 (if (string-match new-boundary boundary)
3189 (setq continuep t)
3190 ;; first pass redefine skip function to include new boundary
3191 ;;(re-search-backward boundary nil t)
3192 (forward-line)
3193 (setq ispell-checking-message
3194 (cons
3195 (list new-boundary 'ispell-mime-skip-part new-boundary)
3196 (if (eq t ispell-checking-message) nil
3197 ispell-checking-message))
3198 textp t
3199 continuep t)))
3200 ;; Skip all MIME headers that don't affect spelling
3201 (if (looking-at "Content-[^ \t]*: *\\(.*;[ \t]*[\n]\\)*.*$")
3202 (progn
3203 (setq continuep t)
3204 (goto-char (match-end 0))
3205 (forward-line)))))
3206
3207 (setq case-fold-search save-case-fold-search)
3208 (if textp
3209 (point)
3210 ;; encoded message. Skip to boundary, or entire message.
3211 (if (not boundary)
3212 (goto-char (point-max))
3213 (re-search-forward boundary nil t)
3214 (beginning-of-line)
3215 (point)))))
3216
3217
3218 ;;;###autoload
3219 (defun ispell-message ()
3220 "Check the spelling of a mail message or news post.
3221 Don't check spelling of message headers except the Subject field.
3222 Don't check included messages.
3223
3224 To abort spell checking of a message region and send the message anyway,
3225 use the `x' command. (Any subsequent regions will be checked.)
3226 The `X' command aborts the message send so that you can edit the buffer.
3227
3228 To spell-check whenever a message is sent, include the appropriate lines
3229 in your .emacs file:
3230 (add-hook 'message-send-hook 'ispell-message) ;; GNUS 5
3231 (add-hook 'news-inews-hook 'ispell-message) ;; GNUS 4
3232 (add-hook 'mail-send-hook 'ispell-message)
3233 (add-hook 'mh-before-send-letter-hook 'ispell-message)
3234
3235 You can bind this to the key C-c i in GNUS or mail by adding to
3236 `news-reply-mode-hook' or `mail-mode-hook' the following lambda expression:
3237 (function (lambda () (local-set-key \"\\C-ci\" 'ispell-message)))"
3238 (interactive)
3239 (save-excursion
3240 (goto-char (point-min))
3241 (let* (boundary mimep
3242 (ispell-skip-region-alist-save ispell-skip-region-alist)
3243 ;; Nil when message came from outside (eg calling emacs as editor)
3244 ;; Non-nil marker of end of headers.
3245 (internal-messagep
3246 (re-search-forward
3247 (concat "^" (regexp-quote mail-header-separator) "$") nil t))
3248 (end-of-headers ; Start of body.
3249 (copy-marker
3250 (or internal-messagep
3251 (re-search-forward "^$" nil t)
3252 (point-min))))
3253 (limit (copy-marker ; End of region we will spell check.
3254 (cond
3255 ((not ispell-message-text-end) (point-max))
3256 ((char-or-string-p ispell-message-text-end)
3257 (if (re-search-forward ispell-message-text-end nil t)
3258 (match-beginning 0)
3259 (point-max)))
3260 (t (min (point-max) (funcall ispell-message-text-end))))))
3261 (default-prefix ; Vanilla cite prefix (just used for cite-regexp)
3262 (if (and (boundp 'mail-yank-prefix) mail-yank-prefix)
3263 (ispell-non-empty-string mail-yank-prefix)
3264 " \\|\t"))
3265 (cite-regexp ;Prefix of quoted text
3266 (cond
3267 ((functionp 'sc-cite-regexp) ; sc 3.0
3268 (concat "\\(" (sc-cite-regexp) "\\)" "\\|"
3269 (ispell-non-empty-string sc-reference-tag-string)))
3270 ((boundp 'sc-cite-regexp) ; sc 2.3
3271 (concat "\\(" sc-cite-regexp "\\)" "\\|"
3272 (ispell-non-empty-string sc-reference-tag-string)))
3273 ((or (equal major-mode 'news-reply-mode) ;GNUS 4 & below
3274 (equal major-mode 'message-mode)) ;GNUS 5
3275 (concat "In article <" "\\|"
3276 "[^,;&+=\n]+ <[^,;&+=]+> writes:" "\\|"
3277 message-yank-prefix "\\|"
3278 default-prefix))
3279 ((equal major-mode 'mh-letter-mode) ; mh mail message
3280 (concat "[^,;&+=\n]+ writes:" "\\|"
3281 (ispell-non-empty-string mh-ins-buf-prefix)))
3282 ((not internal-messagep) ; Assume nn sent us this message.
3283 (concat "In [a-zA-Z.]+ you write:" "\\|"
3284 "In <[^,;&+=]+> [^,;&+=]+ writes:" "\\|"
3285 " *> *"))
3286 ((boundp 'vm-included-text-prefix) ; VM mail message
3287 (concat "[^,;&+=\n]+ writes:" "\\|"
3288 (ispell-non-empty-string vm-included-text-prefix)))
3289 (t default-prefix)))
3290 (ispell-skip-region-alist
3291 (cons (list (concat "^\\(" cite-regexp "\\)")
3292 (function forward-line))
3293 ispell-skip-region-alist))
3294 (old-case-fold-search case-fold-search)
3295 (dictionary-alist ispell-message-dictionary-alist)
3296 (ispell-checking-message t))
3297
3298 ;; Select dictionary for message
3299 (or (local-variable-p 'ispell-local-dictionary (current-buffer))
3300 (while dictionary-alist
3301 (goto-char (point-min))
3302 (if (re-search-forward (car (car dictionary-alist))
3303 end-of-headers t)
3304 (setq ispell-local-dictionary (cdr (car dictionary-alist))
3305 dictionary-alist nil)
3306 (setq dictionary-alist (cdr dictionary-alist)))))
3307
3308 (unwind-protect
3309 (progn
3310 ;; Spell check any original Subject:
3311 (goto-char (point-min))
3312 (setq case-fold-search t
3313 mimep (re-search-forward "MIME-Version:" end-of-headers t))
3314 (goto-char (point-min))
3315 (if (re-search-forward "^Subject: *" end-of-headers t)
3316 (progn
3317 (goto-char (match-end 0))
3318 (if (and (not (looking-at ".*Re\\>"))
3319 (not (looking-at "\\[")))
3320 (progn
3321 (setq case-fold-search old-case-fold-search)
3322 (ispell-region (point)
3323 (progn ;Tab-initiated continuation lns.
3324 (end-of-line)
3325 (while (looking-at "\n[ \t]")
3326 (end-of-line 2))
3327 (point)))))))
3328 (if mimep
3329 (progn
3330 (goto-char (point-min))
3331 (setq boundary (ispell-mime-multipartp end-of-headers))))
3332 ;; Adjust message limit to MIME message if necessary.
3333 (and boundary
3334 (re-search-forward (concat boundary "--") nil t)
3335 (re-search-backward boundary nil t)
3336 (< (point) (marker-position limit))
3337 (set-marker limit (point)))
3338 (goto-char (point-min))
3339 ;; Select type or skip checking if this is a non-multipart message
3340 ;; Point moved to end of buffer if region is encoded.
3341 (if (and mimep (not boundary))
3342 (let (skip-regexp) ; protect from `ispell-mime-skip-part'
3343 (goto-char (point-min))
3344 (re-search-forward "Content-[^ \t]*:" end-of-headers t)
3345 (forward-line -1) ; following fn starts one line above
3346 (ispell-mime-skip-part nil)
3347 ;; if message-text-end region, limit may be less than point.
3348 (if (> (point) limit)
3349 (set-marker limit (point)))))
3350 (goto-char (max end-of-headers (point)))
3351 (forward-line 1)
3352 (setq case-fold-search old-case-fold-search)
3353 ;; Define MIME regions to skip.
3354 (if boundary
3355 (setq ispell-checking-message
3356 (list (list boundary 'ispell-mime-skip-part boundary))))
3357 (ispell-region (point) limit))
3358 (set-marker end-of-headers nil)
3359 (set-marker limit nil)
3360 (setq ispell-skip-region-alist ispell-skip-region-alist-save
3361 ispell-skip-html nil
3362 case-fold-search old-case-fold-search)))))
3363
3364
3365 (defun ispell-non-empty-string (string)
3366 (if (or (not string) (string-equal string ""))
3367 "\\'\\`" ; An unmatchable string if string is null.
3368 (regexp-quote string)))
3369
3370
3371 ;;; **********************************************************************
3372 ;;; Buffer Local Functions
3373 ;;; **********************************************************************
3374
3375
3376 (defun ispell-accept-buffer-local-defs ()
3377 "Load all buffer-local information, restarting Ispell when necessary."
3378 (ispell-buffer-local-dict) ; May kill ispell-process.
3379 (ispell-buffer-local-words) ; Will initialize ispell-process.
3380 (ispell-buffer-local-parsing))
3381
3382
3383 (defun ispell-buffer-local-parsing ()
3384 "Place Ispell into parsing mode for this buffer.
3385 Overrides the default parsing mode.
3386 Includes Latex/Nroff modes and extended character mode."
3387 ;; (ispell-init-process) must already be called.
3388 (ispell-send-string "!\n") ; Put process in terse mode.
3389 ;; We assume all major modes with "tex-mode" in them should use latex parsing
3390 ;; When exclusively checking comments, set to raw text mode (nroff).
3391 (if (and (not (eq 'exclusive ispell-check-comments))
3392 (or (and (eq ispell-parser 'use-mode-name)
3393 (string-match "[Tt][Ee][Xx]-mode"
3394 (symbol-name major-mode)))
3395 (eq ispell-parser 'tex)))
3396 (progn
3397 (ispell-send-string "+\n") ; set ispell mode to tex
3398 (if (not (eq ispell-parser 'tex))
3399 (set (make-local-variable 'ispell-parser) 'tex)))
3400 (ispell-send-string "-\n")) ; set mode to normal (nroff)
3401 ;; If needed, test for SGML & HTML modes and set a buffer local nil/t value.
3402 (if (and ispell-skip-html (not (eq ispell-skip-html t)))
3403 (setq ispell-skip-html
3404 (not (null (string-match "sgml\\|html\\|xml"
3405 (downcase (symbol-name major-mode)))))))
3406 ;; Set default extended character mode for given buffer, if any.
3407 (let ((extended-char-mode (ispell-get-extended-character-mode)))
3408 (if extended-char-mode
3409 (ispell-send-string (concat extended-char-mode "\n"))))
3410 ;; Set buffer-local parsing mode and extended character mode, if specified.
3411 (save-excursion
3412 (goto-char (point-max))
3413 ;; Uses last occurrence of ispell-parsing-keyword
3414 (if (search-backward ispell-parsing-keyword nil t)
3415 (let ((end (save-excursion (end-of-line) (point)))
3416 string)
3417 (search-forward ispell-parsing-keyword)
3418 (while (re-search-forward " *\\([^ \"]+\\)" end t)
3419 ;; space separated definitions.
3420 (setq string (downcase (buffer-substring-no-properties
3421 (match-beginning 1) (match-end 1))))
3422 (cond ((and (string-match "latex-mode" string)
3423 (not (eq 'exclusive ispell-check-comments)))
3424 (ispell-send-string "+\n~tex\n"))
3425 ((string-match "nroff-mode" string)
3426 (ispell-send-string "-\n~nroff\n"))
3427 ((string-match "~" string) ; Set extended character mode.
3428 (ispell-send-string (concat string "\n")))
3429 (t (message "Invalid Ispell Parsing argument!")
3430 (sit-for 2))))))))
3431
3432
3433 ;;; Can kill the current ispell process
3434
3435 (defun ispell-buffer-local-dict ()
3436 "Initializes local dictionary and local personal dictionary.
3437 When a dictionary is defined in the buffer (see variable
3438 `ispell-dictionary-keyword'), it will override the local setting
3439 from \\[ispell-change-dictionary].
3440 Both should not be used to define a buffer-local dictionary."
3441 (save-excursion
3442 (goto-char (point-min))
3443 (let (end)
3444 ;; Override the local variable definition.
3445 ;; Uses last occurrence of ispell-dictionary-keyword.
3446 (goto-char (point-max))
3447 (if (search-backward ispell-dictionary-keyword nil t)
3448 (progn
3449 (search-forward ispell-dictionary-keyword)
3450 (setq end (save-excursion (end-of-line) (point)))
3451 (if (re-search-forward " *\\([^ \"]+\\)" end t)
3452 (setq ispell-local-dictionary
3453 (buffer-substring-no-properties (match-beginning 1)
3454 (match-end 1))))))
3455 (goto-char (point-max))
3456 (if (search-backward ispell-pdict-keyword nil t)
3457 (progn
3458 (search-forward ispell-pdict-keyword)
3459 (setq end (save-excursion (end-of-line) (point)))
3460 (if (re-search-forward " *\\([^ \"]+\\)" end t)
3461 (setq ispell-local-pdict
3462 (buffer-substring-no-properties (match-beginning 1)
3463 (match-end 1))))))))
3464 ;; Reload if new personal dictionary defined.
3465 (if (and ispell-local-pdict
3466 (not (equal ispell-local-pdict ispell-personal-dictionary)))
3467 (progn
3468 (ispell-kill-ispell t)
3469 (setq ispell-personal-dictionary ispell-local-pdict)))
3470 ;; Reload if new dictionary defined.
3471 (if (not (equal ispell-local-dictionary ispell-dictionary))
3472 (ispell-change-dictionary ispell-local-dictionary)))
3473
3474
3475 (defun ispell-buffer-local-words ()
3476 "Loads the buffer-local dictionary in the current buffer."
3477 (if (and ispell-buffer-local-name
3478 (not (equal ispell-buffer-local-name (buffer-name))))
3479 (progn
3480 (ispell-kill-ispell t)
3481 (setq ispell-buffer-local-name nil)))
3482 (ispell-init-process)
3483 (save-excursion
3484 (goto-char (point-min))
3485 (while (search-forward ispell-words-keyword nil t)
3486 (or ispell-buffer-local-name
3487 (setq ispell-buffer-local-name (buffer-name)))
3488 (let ((end (save-excursion (end-of-line) (point)))
3489 (ispell-casechars (ispell-get-casechars))
3490 string)
3491 ;; buffer-local words separated by a space, and can contain
3492 ;; any character other than a space. Not rigorous enough.
3493 (while (re-search-forward " *\\([^ ]+\\)" end t)
3494 (setq string (buffer-substring-no-properties (match-beginning 1)
3495 (match-end 1)))
3496 ;; This can fail when string contains a word with illegal chars.
3497 ;; Error handling needs to be added between ispell and emacs.
3498 (if (and (< 1 (length string))
3499 (equal 0 (string-match ispell-casechars string)))
3500 (ispell-send-string (concat "@" string "\n"))))))))
3501
3502
3503 ;;; returns optionally adjusted region-end-point.
3504
3505 (defun ispell-add-per-file-word-list (word)
3506 "Add WORD to the per-file word list."
3507 (or ispell-buffer-local-name
3508 (setq ispell-buffer-local-name (buffer-name)))
3509 (save-excursion
3510 (goto-char (point-min))
3511 (let ((old-case-fold-search case-fold-search)
3512 line-okay search done found)
3513 (while (not done)
3514 (setq case-fold-search nil
3515 search (search-forward ispell-words-keyword nil 'move)
3516 found (or found search)
3517 line-okay (< (+ (length word) 1 ; 1 for space after word..
3518 (progn (end-of-line) (current-column)))
3519 80)
3520 case-fold-search old-case-fold-search)
3521 (if (or (and search line-okay)
3522 (null search))
3523 (progn
3524 (setq done t)
3525 (if (null search)
3526 (progn
3527 (open-line 1)
3528 (unless found (newline))
3529 (insert (concat comment-start " " ispell-words-keyword))
3530 (if (> (length comment-end) 0)
3531 (save-excursion
3532 (newline)
3533 (insert comment-end)))))
3534 (insert (concat " " word))))))))
3535
3536 (add-to-list 'debug-ignored-errors "^No word found to check!$")
3537
3538 (provide 'ispell)
3539
3540 \f
3541 ;;; LOCAL VARIABLES AND BUFFER-LOCAL VALUE EXAMPLES.
3542
3543 ;;; Local Variable options:
3544 ;;; mode: name(-mode)
3545 ;;; eval: expression
3546 ;;; local-variable: value
3547
3548 ;;; The following sets the buffer local dictionary to `american' English
3549 ;;; and spell checks only comments.
3550
3551 ;;; Local Variables:
3552 ;;; mode: emacs-lisp
3553 ;;; comment-column: 40
3554 ;;; ispell-check-comments: exclusive
3555 ;;; ispell-local-dictionary: "american"
3556 ;;; End:
3557
3558
3559 ;;; MORE EXAMPLES OF ISPELL BUFFER-LOCAL VALUES
3560
3561 ;;; The following places this file in nroff parsing and extended char modes.
3562 ;;; Local IspellParsing: nroff-mode ~nroff
3563 ;;; Change IspellPersDict to IspellPersDict: to enable the following line.
3564 ;;; Local IspellPersDict ~/.ispell_lisp
3565 ;;; The following were automatically generated by ispell using the 'A' command:
3566 ; LocalWords: settable alist inews mh frag pdict Wildcards iconify arg tex kss
3567 ; LocalWords: alists minibuffer bufferp autoload loaddefs aff Dansk KOI SPC op
3568 ; LocalWords: Francais Nederlands charset autoloaded popup nonmenu regexp num
3569 ; LocalWords: AMStex hspace includeonly nocite epsfig displaymath eqnarray reg
3570 ; LocalWords: minipage modeline pers dict unhighlight buf grep sync prev inc
3571 ; LocalWords: fn hilight oldot NB AIX msg init read's bufs pt cmd Quinlan eg
3572 ; LocalWords: uuencoded unidiff sc nn VM SGML eval IspellPersDict unsplitable
3573 ; LocalWords: lns XEmacs HTML casechars Multibyte
3574
3575 ;;; arch-tag: 4941b9f9-3b7c-4a76-a4ed-5fa8b6010ef5
3576 ;;; ispell.el ends here