(read-face-attribute, defined-colors, color-defined-p):
[emacs.git] / lisp / textmodes / ispell.el
blob691c29b5d18d0fd3f5ca706280d83518dc1f7a7f
1 ;;; ispell.el --- Interface to International Ispell Version 3.1
3 ;; Copyright (C) 1994, 1995, 1997, 1998, 1999 Free Software Foundation, Inc.
5 ;; Authors : Ken Stevens <k.stevens@ieee.org>
6 ;; Stevens Mod Date: Fri May 7 14:25:14 PDT 1999
7 ;; Stevens Revision: 3.2
8 ;; Status : Release with 3.1.12+ ispell.
9 ;; Bug Reports : ispell-el-bugs@itcorp.com
10 ;; Web Site : http://kdstevens.com/~stevens/ispell-page.html
12 ;; This file is part of GNU Emacs.
14 ;; GNU Emacs is free software; you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; any later version.
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
26 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
27 ;; Boston, MA 02111-1307, USA.
29 ;; Note: version numbers and time stamp are not updated
30 ;; when this file is edited for release with GNU emacs.
32 ;;; Commentary:
34 ;; INSTRUCTIONS
36 ;; This code contains a section of user-settable variables that you
37 ;; should inspect prior to installation. Look past the end of the history
38 ;; list. Set them up for your locale and the preferences of the majority
39 ;; of the users. Otherwise the users may need to set a number of variables
40 ;; themselves.
41 ;; You particularly may want to change the default dictionary for your
42 ;; country and language.
43 ;; Most dictionary changes should be made in this file so all users can
44 ;; enjoy them. Local or modified dictionaries are supported in your .emacs
45 ;; file. Modify the variable `ispell-local-dictionary-alist' to include
46 ;; these dictionaries, and they will be installed when ispell.el is loaded.
48 ;; Depending on the mail system you use, you may want to include these:
49 ;; (add-hook 'news-inews-hook 'ispell-message)
50 ;; (add-hook 'mail-send-hook 'ispell-message)
51 ;; (add-hook 'mh-before-send-letter-hook 'ispell-message)
53 ;; Ispell has a TeX parser and a nroff parser (the default).
54 ;; The parsing is controlled by the variable ispell-parser. Currently
55 ;; it is just a "toggle" between TeX and nroff, but if more parsers are
56 ;; added it will be updated. See the variable description for more info.
59 ;; TABLE OF CONTENTS
61 ;; ispell-word
62 ;; ispell-region
63 ;; ispell-buffer
64 ;; ispell-message
65 ;; ispell-comments-and-strings
66 ;; ispell-continue
67 ;; ispell-complete-word
68 ;; ispell-complete-word-interior-frag
69 ;; ispell-change-dictionary
70 ;; ispell-kill-ispell
71 ;; ispell-pdict-save
72 ;; ispell-skip-region-alist
74 ;; Commands in ispell-region:
75 ;; Character replacement: Replace word with choice. May query-replace.
76 ;; ` ': Accept word this time.
77 ;; `i': Accept word and insert into private dictionary.
78 ;; `a': Accept word for this session.
79 ;; `A': Accept word and place in buffer-local dictionary.
80 ;; `r': Replace word with typed-in value. Rechecked.
81 ;; `R': Replace word with typed-in value. Query-replaced in buffer. Rechecked.
82 ;; `?': Show these commands
83 ;; `x': Exit spelling buffer. Move cursor to original point.
84 ;; `X': Exit spelling buffer. Leaves cursor at the current point, and permits
85 ;; the check to be completed later.
86 ;; `q': Quit spelling session (Kills ispell process).
87 ;; `l': Look up typed-in replacement in alternate dictionary. Wildcards okay.
88 ;; `u': Like `i', but the word is lower-cased first.
89 ;; `m': Place entered value in personal dictionary, then recheck current word.
90 ;; `C-l': redraws screen
91 ;; `C-r': recursive edit
92 ;; `C-z': suspend emacs or iconify frame
94 ;; Buffer-Local features:
95 ;; There are a number of buffer-local features that can be used to customize
96 ;; ispell for the current buffer. This includes language dictionaries,
97 ;; personal dictionaries, parsing, and local word spellings. Each of these
98 ;; local customizations are done either through local variables, or by
99 ;; including the keyword and argument(s) at the end of the buffer (usually
100 ;; prefixed by the comment characters). See the end of this file for
101 ;; examples. The local keywords and variables are:
103 ;; ispell-dictionary-keyword language-dictionary
104 ;; uses local variable ispell-local-dictionary
105 ;; ispell-pdict-keyword personal-dictionary
106 ;; uses local variable ispell-local-pdict
107 ;; ispell-parsing-keyword mode-arg extended-char-arg
108 ;; ispell-words-keyword any number of local word spellings
110 ;; Region skipping:
111 ;; Place new regular expression definitions of regions you prefer not to
112 ;; spell check in `ispell-skip-region-alist'. Mode-dependent features can
113 ;; be added to latex by modifying `ispell-tex-skip-alists'.
114 ;; `ispell-message' contains some custom skipping code for e-mail messages.
116 ;; BUGS:
117 ;; Accepting word definitions in latex mode can mess up math mode skipping.
118 ;; On some versions of emacs, growing the minibuffer fails.
119 ;; see `ispell-help-in-bufferp'.
121 ;; HISTORY
123 ;; Modifications made in latest versions:
125 ;; Revision 3.2 1999/5/7 14:25:14 kss
126 ;; Accept ispell versions 3.X.Y where X>=1
127 ;; fine tuned latex region skipping. Fixed bug in ispell-word that did not
128 ;; point in right place on words < 2 chars. Simplified ispell-minor-mode.
129 ;; Fixed bug in TeX parsing when math commands are in the comments.
130 ;; Removed calls to `when' macro.
132 ;; Revision 3.1 1998/12/1 13:21:52 kss
133 ;; Improved and fixed customize support.
134 ;; Improved and fixed comments in variables and messages.
135 ;; A coding system is now required for all languages.
136 ;; casechars improved for castellano, castellano8, and norsk dictionaries.
137 ;; Dictionary norsk7-tex removed. Dictionary polish added.
138 ;; Dictionaries redefined at load-time to support dictionary changes.
139 ;; Menu redefined at load time to support dictionary changes.
140 ;; ispell-check-version added as an alias for `check-ispell-version'.
141 ;; Spelling suggestions returned in order generated by ispell.
142 ;; Small bug fixed in matching ispell error messages.
143 ;; Robustness added to ensure `case-fold-search' doesn't get redefined.
144 ;; Fixed bug that didn't respect case of word in `ispell-complete-word'.
145 ;; Multibyte character coding support added for process interactions.
146 ;; Ensure ispell process has terminated before starting new process.
147 ;; This can otherwise confuse process filters and hang ispell.
148 ;; Improved skipping support for sgml.
149 ;; Fixed bug using ^M rather than \r in `ispell-minor-check'.
150 ;; Improved message reference matching in `ispell-message'.
151 ;; Fixed bug in returning to nroff mode from tex mode.
154 ;;; Code:
156 ;;; Custom.el macros require recompiling this when they are not present.
157 ;;; Add in backward compatible custom support.
158 (eval-when-compile
159 (if (not (fboundp 'defcustom))
160 (defmacro defcustom (symbol value doc &rest args)
161 "Empty replacement for defcustom when not supplied."
162 `(defvar ,symbol ,value ,doc))))
164 (eval-when-compile
165 (if (fboundp 'defgroup)
166 (defgroup ispell nil
167 "User variables for emacs ispell interface."
168 :group 'applications)))
171 ;;; **********************************************************************
172 ;;; The following variables should be set according to personal preference
173 ;;; and location of binaries:
174 ;;; **********************************************************************
177 ;;; ******* THIS FILE IS WRITTEN FOR ISPELL VERSION 3.1+
179 (defcustom ispell-highlight-p 'block
180 "*Highlight spelling errors when non-nil.
181 When set to `block', assumes a block cursor with TTY displays."
182 :type '(choice (const block) (const :tag "off" nil) (const :tag "on" t))
183 :group 'ispell)
185 (defcustom ispell-highlight-face 'highlight
186 "*The face used for Ispell highlighting. For Emacses with overlays.
187 Possible values are `highlight', `modeline', `secondary-selection',
188 `region', and `underline'.
189 This variable can be set by the user to whatever face they desire.
190 It's most convenient if the cursor color and highlight color are
191 slightly different."
192 :type 'face
193 :group 'ispell)
195 (defcustom ispell-check-comments t
196 "*Spelling of comments checked when non-nil.
197 When set to `exclusive', ONLY comments are checked. (For code comments).
198 Warning! Not checking comments, when a comment start is embedded in strings,
199 may produce undesired results."
200 :type '(choice (const exclusive) (const :tag "off" nil) (const :tag "on" t))
201 :group 'ispell)
203 (defcustom ispell-query-replace-choices nil
204 "*Corrections made throughout region when non-nil.
205 Uses `query-replace' (\\[query-replace]) for corrections."
206 :type 'boolean
207 :group 'ispell)
209 (defcustom ispell-skip-tib nil
210 "*Does not spell check `tib' bibliography references when non-nil.
211 Skips any text between strings matching regular expressions
212 `ispell-tib-ref-beginning' and `ispell-tib-ref-end'.
214 TeX users beware: Any field starting with [. will skip until a .] -- even
215 your whole buffer -- unless you set `ispell-skip-tib' to nil. That includes
216 a [.5mm] type of number...."
217 :type 'boolean
218 :group 'ispell)
220 (defvar ispell-tib-ref-beginning "[[<]\\."
221 "Regexp matching the beginning of a Tib reference.")
223 (defvar ispell-tib-ref-end "\\.[]>]"
224 "Regexp matching the end of a Tib reference.")
226 (defcustom ispell-keep-choices-win t
227 "*When not nil, the `*Choices*' window remains for spelling session.
228 This minimizes redisplay thrashing."
229 :type 'boolean
230 :group 'ispell)
232 (defcustom ispell-choices-win-default-height 2
233 "*The default size of the `*Choices*' window, including status line.
234 Must be greater than 1."
235 :type 'integer
236 :group 'ispell)
238 (defcustom ispell-program-name "ispell"
239 "Program invoked by \\[ispell-word] and \\[ispell-region] commands."
240 :type 'string
241 :group 'ispell)
243 (defcustom ispell-alternate-dictionary
244 (cond ((file-exists-p "/usr/dict/web2") "/usr/dict/web2")
245 ((file-exists-p "/usr/share/dict/web2") "/usr/share/dict/web2")
246 ((file-exists-p "/usr/dict/words") "/usr/dict/words")
247 ((file-exists-p "/usr/lib/dict/words") "/usr/lib/dict/words")
248 ((file-exists-p "/usr/share/dict/words") "/usr/share/dict/words")
249 ((file-exists-p "/sys/dict") "/sys/dict")
250 (t "/usr/dict/words"))
251 "*Alternate dictionary for spelling help."
252 :type '(choice file (const :tag "None" nil))
253 :group 'ispell)
255 (defcustom ispell-complete-word-dict ispell-alternate-dictionary
256 "*Dictionary used for word completion."
257 :type '(choice file (const :tag "None" nil))
258 :group 'ispell)
260 (defcustom ispell-message-dictionary-alist nil
261 "*List used by `ispell-message' to select a new dictionary.
262 It consists of pairs (REGEXP . DICTIONARY). If REGEXP is found
263 in the message headers, `ispell-local-dictionary' will be set to
264 DICTIONARY if `ispell-local-dictionary' is not buffer-local.
265 E.g. you may use the following value:
266 '((\"^Newsgroups:[ \\t]*de\\\\.\" . \"deutsch8\")
267 (\"^To:[^\\n,]+\\\\.de[ \\t\\n,>]\" . \"deutsch8\"))"
268 :type '(repeat (cons regexp string))
269 :group 'ispell)
272 (defcustom ispell-grep-command "egrep"
273 "Name of the grep command for search processes."
274 :type 'string
275 :group 'ispell)
277 (defcustom ispell-grep-options "-i"
278 "String of options to use when running the program in `ispell-grep-command'.
279 Should probably be \"-i\" or \"-e\".
280 Some machines (like the NeXT) don't support \"-i\""
281 :type 'string
282 :group 'ispell)
284 (defcustom ispell-look-command
285 (cond ((file-exists-p "/bin/look") "/bin/look")
286 ((file-exists-p "/usr/local/bin/look") "/usr/local/bin/look")
287 ((file-exists-p "/usr/bin/look") "/usr/bin/look")
288 (t "look"))
289 "Name of the look command for search processes.
290 This must be an absolute file name."
291 :type 'file
292 :group 'ispell)
294 (defcustom ispell-look-p (file-exists-p ispell-look-command)
295 "*Non-nil means use `look' rather than `grep'.
296 Default is based on whether `look' seems to be available."
297 :type 'boolean
298 :group 'ispell)
300 (defcustom ispell-have-new-look nil
301 "*Non-nil means use the `-r' option (regexp) when running `look'."
302 :type 'boolean
303 :group 'ispell)
305 (defcustom ispell-look-options (if ispell-have-new-look "-dfr" "-df")
306 "String of command options for `ispell-look-command'."
307 :type 'string
308 :group 'ispell)
310 (defcustom ispell-use-ptys-p nil
311 "When non-nil, Emacs uses ptys to communicate with Ispell.
312 When nil, Emacs uses pipes."
313 :type 'boolean
314 :group 'ispell)
316 (defcustom ispell-following-word nil
317 "*Non-nil means `ispell-word' checks the word around or after point.
318 Otherwise `ispell-word' checks the preceding word."
319 :type 'boolean
320 :group 'ispell)
322 (defcustom ispell-help-in-bufferp nil
323 "*Non-nil means display interactive keymap help in a buffer.
324 The following values are supported:
325 nil Expand the minibuffer and display a short help message
326 there for a couple of seconds.
327 t Pop up a new buffer and display a short help message there
328 for a couple of seconds.
329 electric Pop up a new buffer and display a long help message there.
330 User can browse and then exit the help mode."
331 :type '(choice (const electric) (const :tag "off" nil) (const :tag "on" t))
332 :group 'ispell)
334 (defcustom ispell-quietly nil
335 "*Non-nil means suppress messages in `ispell-word'."
336 :type 'boolean
337 :group 'ispell)
339 (defcustom ispell-format-word (function upcase)
340 "*Formatting function for displaying word being spell checked.
341 The function must take one string argument and return a string."
342 :type 'function
343 :group 'ispell)
345 (defcustom ispell-use-framepop-p nil
346 "When non-nil ispell uses framepop to display choices in a dedicated frame.
347 You can set this variable to dynamically use framepop if you are in a
348 window system by evaluating the following on startup to set this variable:
349 (and window-system (condition-case () (require 'framepop) (error nil)))"
350 :type 'boolean
351 :group 'ispell)
353 ;;;###autoload
354 (defcustom ispell-personal-dictionary nil
355 "*File name of your personal spelling dictionary, or nil.
356 If nil, the default personal dictionary, \"~/.ispell_DICTNAME\" is used,
357 where DICTNAME is the name of your default dictionary."
358 :type '(choice file
359 (const :tag "default" nil))
360 :group 'ispell)
362 (defcustom ispell-silently-savep nil
363 "*When non-nil, save the personal dictionary without confirmation."
364 :type 'boolean
365 :group 'ispell)
367 ;;; This is the local dictionary to use. When nil the default dictionary will
368 ;;; be used. Change set-default call to use a new default dictionary.
369 (defcustom ispell-local-dictionary nil
370 "If non-nil, the dictionary to be used for Ispell commands.
371 The value must be a string dictionary name in `ispell-dictionary-alist'.
372 This variable becomes buffer-local when set in any fashion.
374 Setting `ispell-local-dictionary' to a value has the same effect as
375 calling \\[ispell-change-dictionary] with that value. This variable
376 is automatically set when defined in the file with either
377 `ispell-dictionary-keyword' or the Local Variable syntax.
379 To create a non-standard default dictionary (not from `ispell-dictionary-alist')
380 call function `set-default' with the new dictionary name."
381 :type '(choice string
382 (const :tag "default" nil))
383 :group 'ispell)
385 (make-variable-buffer-local 'ispell-local-dictionary)
387 ;; Call this function set up the default dictionary if not English.
388 ;;(set-default 'ispell-local-dictionary nil)
391 (defcustom ispell-extra-args nil
392 "*If non-nil, a list of extra switches to pass to the Ispell program.
393 For example, (\"-W\" \"3\") to cause it to accept all 1-3 character
394 words as correct. See also `ispell-dictionary-alist', which may be used
395 for language-specific arguments."
396 :type '(repeat string)
397 :group 'ispell)
400 ;; Define definitions here only for personal dictionaries.
401 ;;;###autoload
402 (defcustom ispell-local-dictionary-alist nil
403 "*Contains local or customized dictionary definitions.
404 See `ispell-dictionary-alist'."
405 :type '(repeat (list (choice :tag "Dictionary"
406 (string :tag "Dictionary name")
407 (const :tag "default" nil))
408 (regexp :tag "Case characters")
409 (regexp :tag "Non case characters")
410 (regexp :tag "Other characters")
411 (boolean :tag "Many other characters")
412 (repeat :tag "Ispell command line args"
413 (string :tag "Arg"))
414 (choice :tag "Extended character mode"
415 (const "~tex") (const "~plaintex")
416 (const "~nroff") (const "~list")
417 (const "~latin1") (const "~latin3")
418 (const :tag "default" nil))
419 (choice :tag "Character set"
420 (const iso-8859-1)
421 (const iso-8859-2)
422 (const koi8-r))))
423 :group 'ispell)
426 ;;; split dictionary so line length is smaller in loaddefs.el
428 ;;; First part of dictionary, shortened for loaddefs.el
429 ;;;###autoload
430 (setq
431 ispell-dictionary-alist-1
432 '((nil ; default (English.aff)
433 "[A-Za-z]" "[^A-Za-z]" "[']" nil ("-B") nil iso-8859-1)
434 ("american" ; Yankee English
435 "[A-Za-z]" "[^A-Za-z]" "[']" nil ("-B") nil iso-8859-1)
436 ("british" ; British version
437 "[A-Za-z]" "[^A-Za-z]" "[']" nil ("-B" "-d" "british") nil iso-8859-1)
438 ("castellano" ; Spanish mode
439 "[A-Z\301\311\315\321\323\332\334a-z\341\351\355\361\363\372\374]"
440 "[^A-Z\301\311\315\321\323\332\334a-z\341\351\355\361\363\372\374]"
441 "[---]" nil ("-B" "-d" "castellano") "~tex" iso-8859-1)
442 ("castellano8" ; 8 bit Spanish mode
443 "[A-Z\301\311\315\321\323\332\334a-z\341\351\355\361\363\372\374]"
444 "[^A-Z\301\311\315\321\323\332\334a-z\341\351\355\361\363\372\374]"
445 "[---]" nil ("-B" "-d" "castellano") "~latin1" iso-8859-1)))
448 ;;; Second part of dictionary, shortened for loaddefs.el
449 ;;;###autoload
450 (setq
451 ispell-dictionary-alist-2
452 '(("czech"
453 "[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]"
454 "[^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]"
455 "" nil ("-B" "-d" "czech") nil iso-8859-2)
456 ("dansk" ; Dansk.aff
457 "[A-Z\306\330\305a-z\346\370\345]" "[^A-Z\306\330\305a-z\346\370\345]"
458 "[']" nil ("-C") nil iso-8859-1)
459 ("deutsch" ; Deutsch.aff
460 "[a-zA-Z\"]" "[^a-zA-Z\"]" "[']" t ("-C") "~tex" iso-8859-1)
461 ("deutsch8"
462 "[a-zA-Z\304\326\334\344\366\337\374]"
463 "[^a-zA-Z\304\326\334\344\366\337\374]"
464 "[']" t ("-C" "-d" "deutsch") "~latin1" iso-8859-1)
465 ("english" ; make English explicitly selectable
466 "[A-Za-z]" "[^A-Za-z]" "[']" nil ("-B") nil iso-8859-1)))
469 ;;; Third part of dictionary, shortened for loaddefs.el
470 ;;;###autoload
471 (setq
472 ispell-dictionary-alist-3
473 '(("esperanto"
474 "[A-Za-z\246\254\266\274\306\330\335\336\346\370\375\376]"
475 "[^A-Za-z\246\254\266\274\306\330\335\336\346\370\375\376]"
476 "[-']" t ("-C") "~latin3" iso-8859-1)
477 ("esperanto-tex"
478 "[A-Za-z^\\]" "[^A-Za-z^\\]"
479 "[-'`\"]" t ("-C" "-d" "esperanto") "~tex" iso-8859-1)
480 ("francais7"
481 "[A-Za-z]" "[^A-Za-z]" "[`'^---]" t nil nil iso-8859-1)
482 ("francais" ; Francais.aff
483 "[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]"
484 "[^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]"
485 "[---']" t nil "~list" iso-8859-1)))
488 ;;; Fourth part of dictionary, shortened for loaddefs.el
489 ;;;###autoload
490 (setq
491 ispell-dictionary-alist-4
492 '(("francais-tex" ; Francais.aff
493 "[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\\]"
494 "[^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\\]"
495 "[---'^`\"]" t nil "~tex" iso-8859-1)
496 ("nederlands" ; Nederlands.aff
497 "[A-Za-z\300-\305\307\310-\317\322-\326\331-\334\340-\345\347\350-\357\361\362-\366\371-\374]"
498 "[^A-Za-z\300-\305\307\310-\317\322-\326\331-\334\340-\345\347\350-\357\361\362-\366\371-\374]"
499 "[']" t ("-C") nil iso-8859-1)
500 ("nederlands8" ; Dutch8.aff
501 "[A-Za-z\300-\305\307\310-\317\322-\326\331-\334\340-\345\347\350-\357\361\362-\366\371-\374]"
502 "[^A-Za-z\300-\305\307\310-\317\322-\326\331-\334\340-\345\347\350-\357\361\362-\366\371-\374]"
503 "[']" t ("-C") nil iso-8859-1)))
506 ;;; Fifth part of dictionary, shortened for loaddefs.el
507 ;;;###autoload
508 (setq
509 ispell-dictionary-alist-5
510 '(("norsk" ; 8 bit Norwegian mode
511 "[A-Za-z\305\306\307\310\311\322\324\330\345\346\347\350\351\362\364\370]"
512 "[^A-Za-z\305\306\307\310\311\322\324\330\345\346\347\350\351\362\364\370]"
513 "[\"]" nil ("-d" "norsk") "~list" iso-8859-1)
514 ("norsk7-tex" ; 7 bit Norwegian TeX mode
515 "[A-Za-z{}\\'^`]" "[^A-Za-z{}\\'^`]"
516 "[\"]" nil ("-d" "norsk") "~plaintex" iso-8859-1)
517 ("polish" ; polish mode
518 "[A-Za-z\241\243\246\254\257\261\263\266\274\277\306\312\321\323\346\352\361\363]"
519 "[^A-Za-z\241\243\246\254\257\261\263\266\274\277\306\312\321\323\346\352\361\363]"
520 "" nil ( "-d" "polish") nil iso-8859-2)))
523 ;;; Sixth part of dictionary, shortened for loaddefs.el
524 ;;;###autoload
525 (setq
526 ispell-dictionary-alist-6
527 '(("russian" ; Russian.aff (KOI8-R charset)
528 "[\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]"
529 "[^\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]"
530 "" nil ("-d" "russian") nil koi8-r)
531 ("svenska" ; Swedish mode
532 "[A-Za-z\345\344\366\351\340\374\350\346\370\347\305\304\326\311\300\334\310\306\330\307]"
533 "[^A-Za-z\345\344\366\351\340\374\350\346\370\347\305\304\326\311\300\334\310\306\330\307]"
534 "[']" nil ("-C") "~list" iso-8859-1)))
538 ;;;###autoload
539 (defcustom ispell-dictionary-alist
540 (append ispell-local-dictionary-alist ; dictionary customizations
541 ispell-dictionary-alist-1 ispell-dictionary-alist-2
542 ispell-dictionary-alist-3 ispell-dictionary-alist-4
543 ispell-dictionary-alist-5 ispell-dictionary-alist-6)
544 "An alist of dictionaries and their associated parameters.
546 Each element of this list is also a list:
548 \(DICTIONARY-NAME CASECHARS NOT-CASECHARS OTHERCHARS MANY-OTHERCHARS-P
549 ISPELL-ARGS EXTENDED-CHARACTER-MODE CHARACTER-SET\)
551 DICTIONARY-NAME is a possible string value of variable `ispell-dictionary',
552 nil means the default dictionary.
554 CASECHARS is a regular expression of valid characters that comprise a
555 word.
557 NOT-CASECHARS is the opposite regexp of CASECHARS.
559 OTHERCHARS is a regexp of characters in the NOT-CASECHARS set but which can be
560 used to construct words in some special way. If OTHERCHARS characters follow
561 and precede characters from CASECHARS, they are parsed as part of a word,
562 otherwise they become word-breaks. As an example in English, assume the
563 regular expression \"[']\" for OTHERCHARS. Then \"they're\" and
564 \"Steven's\" are parsed as single words including the \"'\" character, but
565 \"Stevens'\" does not include the quote character as part of the word.
566 If you want OTHERCHARS to be empty, use the empty string.
567 Hint: regexp syntax requires the hyphen to be declared first here.
569 MANY-OTHERCHARS-P is non-nil when multiple OTHERCHARS are allowed in a word.
570 Otherwise only a single OTHERCHARS character is allowed to be part of any
571 single word.
573 ISPELL-ARGS is a list of additional arguments passed to the ispell
574 subprocess.
576 EXTENDED-CHARACTER-MODE should be used when dictionaries are used which
577 have been configured in an Ispell affix file. (For example, umlauts
578 can be encoded as \\\"a, a\\\", \"a, ...) Defaults are ~tex and ~nroff
579 in English. This has the same effect as the command-line `-T' option.
580 The buffer Major Mode controls Ispell's parsing in tex or nroff mode,
581 but the dictionary can control the extended character mode.
582 Both defaults can be overruled in a buffer-local fashion. See
583 `ispell-parsing-keyword' for details on this.
585 CHARACTER-SET used for languages with multibyte characters.
587 Note that the CASECHARS and OTHERCHARS slots of the alist should
588 contain the same character set as casechars and otherchars in the
589 LANGUAGE.aff file \(e.g., english.aff\)."
590 :type '(repeat (list (choice :tag "Dictionary"
591 (string :tag "Dictionary name")
592 (const :tag "default" nil))
593 (regexp :tag "Case characters")
594 (regexp :tag "Non case characters")
595 (regexp :tag "Other characters")
596 (boolean :tag "Many other characters")
597 (repeat :tag "Ispell command line args"
598 (string :tag "Arg"))
599 (choice :tag "Extended character mode"
600 (const "~tex") (const "~plaintex")
601 (const "~nroff") (const "~list")
602 (const "~latin1") (const "~latin3")
603 (const :tag "default" nil))
604 (choice :tag "Character set"
605 (const iso-8859-1)
606 (const iso-8859-2)
607 (const koi8-r))))
608 :group 'ispell)
610 ;;; update the dictionaries at load time
611 (setq ispell-dictionary-alist
612 (append ispell-local-dictionary-alist ; dictionary customizations
613 ispell-dictionary-alist-1 ispell-dictionary-alist-2
614 ispell-dictionary-alist-3 ispell-dictionary-alist-4
615 ispell-dictionary-alist-5 ispell-dictionary-alist-6))
617 ;;; The preparation of the menu bar menu must be autoloaded
618 ;;; because otherwise this file gets autoloaded every time Emacs starts
619 ;;; so that it can set up the menus and determine keyboard equivalents.
621 ;;;###autoload
622 (defvar ispell-menu-map nil "Key map for ispell menu.")
623 ;;; redo menu when loading ispell to get dictionary modifications
624 (setq ispell-menu-map nil)
626 ;;;###autoload
627 (defvar ispell-menu-xemacs nil
628 "Spelling menu for XEmacs.
629 If nil when package is loaded, a standard menu will be set,
630 and added as a submenu of the \"Edit\" menu.")
632 ;;; Break out XEmacs menu and split into several calls to avoid having
633 ;;; long lines in loaddefs.el. Detect need off following constant.
635 ;;; Set up dictionary
636 ;;;###autoload
637 (defconst ispell-menu-map-needed
638 ;; only needed when not version 18 and not XEmacs.
639 (and (not ispell-menu-map)
640 (not (string-match "18\\.[0-9]+\\.[0-9]+" emacs-version))
641 (not (string-match "Lucid\\|XEmacs" emacs-version))))
643 ;;;###autoload
644 (if ispell-menu-map-needed
645 (let ((dicts (reverse (cons (cons "default" nil) ispell-dictionary-alist)))
646 name)
647 (setq ispell-menu-map (make-sparse-keymap "Spell"))
648 ;; add the dictionaries to the bottom of the list.
649 (while dicts
650 (setq name (car (car dicts))
651 dicts (cdr dicts))
652 (if (stringp name)
653 (define-key ispell-menu-map (vector (intern name))
654 (cons (concat "Select " (capitalize name))
655 (list 'lambda () '(interactive)
656 (list 'ispell-change-dictionary name))))))))
658 ;;; define commands in menu in opposite order you want them to appear.
659 ;;;###autoload
660 (if ispell-menu-map-needed
661 (progn
662 (define-key ispell-menu-map [ispell-change-dictionary]
663 '("Change Dictionary" . ispell-change-dictionary))
664 (define-key ispell-menu-map [ispell-kill-ispell]
665 '("Kill Process" . ispell-kill-ispell))
666 (define-key ispell-menu-map [ispell-pdict-save]
667 '("Save Dictionary" . (lambda () (interactive) (ispell-pdict-save t t))))
668 (define-key ispell-menu-map [ispell-complete-word]
669 '("Complete Word" . ispell-complete-word))
670 (define-key ispell-menu-map [ispell-complete-word-interior-frag]
671 '("Complete Word Frag" . ispell-complete-word-interior-frag))))
673 ;;;###autoload
674 (if ispell-menu-map-needed
675 (progn
676 (define-key ispell-menu-map [ispell-continue]
677 '("Continue Check" . ispell-continue))
678 (define-key ispell-menu-map [ispell-word]
679 '("Check Word" . ispell-word))
680 (define-key ispell-menu-map [ispell-comments-and-strings]
681 '("Check Comments" . ispell-comments-and-strings))
682 (define-key ispell-menu-map [ispell-region]
683 '("Check Region" . ispell-region))
684 (define-key ispell-menu-map [ispell-buffer]
685 '("Check Buffer" . ispell-buffer))))
687 ;;;###autoload
688 (if ispell-menu-map-needed
689 (progn
690 (define-key ispell-menu-map [ispell-message]
691 '("Check Message" . ispell-message))
692 (define-key ispell-menu-map [ispell-help]
693 ;; use (x-popup-menu last-nonmenu-event(list "" ispell-help-list)) ?
694 '("Help" . (lambda () (interactive) (describe-function 'ispell-help))))
695 (put 'ispell-region 'menu-enable 'mark-active)
696 (fset 'ispell-menu-map (symbol-value 'ispell-menu-map))))
698 ;;; XEmacs version 19 & 20
699 (if (and (not (string-match "18\\.[0-9]+\\.[0-9]+" emacs-version))
700 (string-match "Lucid\\|XEmacs" emacs-version)
701 (featurep 'menubar)
702 (null ispell-menu-xemacs)
703 (not (and (boundp 'infodock-version) infodock-version)))
704 (let ((dicts (cons (cons "default" nil) ispell-dictionary-alist))
705 (current-menubar (or current-menubar default-menubar))
706 (menu
707 '(["Help" (describe-function 'ispell-help) t]
708 ;;["Help" (popup-menu ispell-help-list) t]
709 ["Check Message" ispell-message t]
710 ["Check Buffer" ispell-buffer t]
711 ["Check Comments" ispell-comments-and-strings t]
712 ["Check Word" ispell-word t]
713 ["Check Region" ispell-region (or (not zmacs-regions) (mark))]
714 ["Continue Check" ispell-continue t]
715 ["Complete Word Frag"ispell-complete-word-interior-frag t]
716 ["Complete Word" ispell-complete-word t]
717 ["Kill Process" ispell-kill-ispell t]
719 ["Save Dictionary" (ispell-pdict-save t t) t]
720 ["Change Dictionary" ispell-change-dictionary t]))
721 name)
722 (while dicts
723 (setq name (car (car dicts))
724 dicts (cdr dicts))
725 (if (stringp name)
726 (setq menu (append menu
727 (list
728 (vector (concat "Select " (capitalize name))
729 (list 'ispell-change-dictionary name)
730 t))))))
731 (setq ispell-menu-xemacs menu)
732 (if current-menubar
733 (progn
734 (delete-menu-item '("Edit" "Spell")) ; in case already defined
735 (add-menu '("Edit") "Spell" ispell-menu-xemacs)))))
737 ;;; Allow incrementing characters as integers in XEmacs 20
738 (if (and (string-match "XEmacs" emacs-version)
739 (fboundp 'int-char))
740 (fset 'ispell-int-char 'int-char)
741 ;; Emacs and XEmacs 19 or earlier
742 (fset 'ispell-int-char 'identity))
745 ;;; **********************************************************************
746 ;;; The following are used by ispell, and should not be changed.
747 ;;; **********************************************************************
750 ;;; The version must be 3.1 or greater for this version of ispell.el
751 ;;; There is an incompatibility between version 3.1.12 and lower versions.
752 (defconst ispell-required-version '(3 1 12)
753 "Ispell versions with which this version of ispell.el is known to work.")
754 (defvar ispell-offset -1
755 "Offset that maps protocol differences between ispell 3.1 versions.")
757 ;;; This variable contains the current dictionary being used if the ispell
758 ;;; process is running. Otherwise it contains the global default.
759 (defvar ispell-dictionary nil
760 "The name of the current dictionary, or nil for the default.
761 When `ispell-local-dictionary' is nil, `ispell-dictionary' is used to select
762 the dictionary for new buffers.
764 This is passed to the ispell process using the `-d' switch and is
765 used as key in `ispell-dictionary-alist' (which see).")
767 (defun ispell-decode-string (str)
768 "Decodes multibyte character strings."
769 (if (and (boundp 'enable-multibyte-characters)
770 (fboundp 'decode-coding-string)
771 enable-multibyte-characters
772 (ispell-get-coding-system))
773 (decode-coding-string str (ispell-get-coding-system))
774 str))
776 (defun ispell-get-casechars ()
777 (ispell-decode-string
778 (nth 1 (assoc ispell-dictionary ispell-dictionary-alist))))
779 (defun ispell-get-not-casechars ()
780 (ispell-decode-string
781 (nth 2 (assoc ispell-dictionary ispell-dictionary-alist))))
782 (defun ispell-get-otherchars ()
783 (ispell-decode-string
784 (nth 3 (assoc ispell-dictionary ispell-dictionary-alist))))
785 (defun ispell-get-many-otherchars-p ()
786 (nth 4 (assoc ispell-dictionary ispell-dictionary-alist)))
787 (defun ispell-get-ispell-args ()
788 (nth 5 (assoc ispell-dictionary ispell-dictionary-alist)))
789 (defun ispell-get-extended-character-mode ()
790 (nth 6 (assoc ispell-dictionary ispell-dictionary-alist)))
791 (defun ispell-get-coding-system ()
792 (nth 7 (assoc ispell-dictionary ispell-dictionary-alist)))
794 (defvar ispell-process nil
795 "The process object for Ispell.")
797 (defvar ispell-pdict-modified-p nil
798 "Non-nil means personal dictionary has modifications to be saved.")
800 ;;; If you want to save the dictionary when quitting, must do so explicitly.
801 ;;; When non-nil, the spell session is terminated.
802 ;;; When numeric, contains cursor location in buffer, and cursor remains there.
803 (defvar ispell-quit nil)
805 (defvar ispell-filter nil
806 "Output filter from piped calls to Ispell.")
808 (defvar ispell-filter-continue nil
809 "Control variable for Ispell filter function.")
811 (defvar ispell-process-directory nil
812 "The directory where `ispell-process' was started.")
814 (defvar ispell-query-replace-marker (make-marker)
815 "Marker for `query-replace' processing.")
817 (defvar ispell-recursive-edit-marker (make-marker)
818 "Marker for return point from recursive edit.")
820 (defvar ispell-checking-message nil
821 "Non-nil when we're checking a mail message.")
823 (defconst ispell-choices-buffer "*Choices*")
825 (defvar ispell-overlay nil "Overlay variable for Ispell highlighting.")
827 ;;; *** Buffer Local Definitions ***
829 (defconst ispell-words-keyword "LocalWords: "
830 "The keyword for local oddly-spelled words to accept.
831 The keyword will be followed by any number of local word spellings.
832 There can be multiple of these keywords in the file.")
834 (defconst ispell-dictionary-keyword "Local IspellDict: "
835 "The keyword for a local dictionary to use.
836 The keyword must be followed by a correct dictionary name in
837 `ispell-dictionary-alist'. When multiple occurrences exist, the last keyword
838 definition is used.")
840 (defconst ispell-pdict-keyword "Local IspellPersDict: "
841 "The keyword for defining buffer local dictionaries.
842 Keyword must be followed by the filename of a personal dictionary.
843 The last occurring definition in the buffer will be used.")
845 (defconst ispell-parsing-keyword "Local IspellParsing: "
846 "The keyword for overriding default Ispell parsing.
847 The above keyword string should be followed by `latex-mode' or
848 `nroff-mode' to put the current buffer into the desired parsing mode.
850 Extended character mode can be changed for this buffer by placing
851 a `~' followed by an extended-character mode -- such as `~.tex'.
852 The last occurring definition in the buffer will be used.")
854 ;;;###autoload
855 (defvar ispell-skip-region-alist
856 '((ispell-words-keyword forward-line)
857 (ispell-dictionary-keyword forward-line)
858 (ispell-pdict-keyword forward-line)
859 (ispell-parsing-keyword forward-line)
860 ("^---*BEGIN PGP [A-Z ]*--*" . "^---*END PGP [A-Z ]*--*")
861 ("^---* \\(Start of \\)?[Ff]orwarded [Mm]essage" . "^---* End of [Ff]orwarded [Mm]essage")
862 ;; matches e-mail addresses, file names, http addresses, etc.
863 ("\\(/\\|\\(\\(\\w\\|-\\)+[.:@]\\)\\)\\(\\w\\|-\\)*\\([.:/@]+\\(\\w\\|-\\|~\\)+\\)+")
864 ;; This is a pretty complex regexp. It can be simplified to the following:
865 ;; "\\(\\w\\|-\\)*\\([.:/@]+\\(\\w\\|-\\|~\\)+\\)+"
866 ;; but some valid text will be skipped, e.g. "his/her". This could be
867 ;; fixed up (at the expense of a moderately more complex regexp)
868 ;; by not allowing "/" to be the character which triggers the
869 ;; identification of the computer name, e.g.:
870 ;; "\\(\\w\\|-\\)+[.:@]\\(\\w\\|-\\)*\\([.:/@]+\\(\\w\\|-\\|~\\)+\\)+"
872 "Alist expressing beginning and end of regions not to spell check.
873 The alist key must be a regular expression.
874 Valid forms include:
875 (KEY) - just skip the key.
876 (KEY . REGEXP) - skip to the end of REGEXP. REGEXP may be string or symbol.
877 (KEY REGEXP) - skip to end of REGEXP. REGEXP must be a string.
878 (KEY FUNCTION ARGS) - FUNCTION called with ARGS returns end of region.")
882 ;;;###autoload
883 (defvar ispell-tex-skip-alists
884 '((;;("%\\[" . "%\\]") ; AMStex block comment...
885 ;; All the standard LaTeX keywords from L. Lamport's guide:
886 ;; \cite, \hspace, \hspace*, \hyphenation, \include, \includeonly, \input,
887 ;; \label, \nocite, \rule (in ispell - rest included here)
888 ("\\\\addcontentsline" ispell-tex-arg-end 2)
889 ("\\\\add\\(tocontents\\|vspace\\)" ispell-tex-arg-end)
890 ("\\\\\\([aA]lph\\|arabic\\)" ispell-tex-arg-end)
891 ;;("\\\\author" ispell-tex-arg-end)
892 ("\\\\bibliographystyle" ispell-tex-arg-end)
893 ("\\\\makebox" ispell-tex-arg-end 0)
894 ;;("\\\\epsfig" ispell-tex-arg-end)
895 ("\\\\document\\(class\\|style\\)" .
896 "\\\\begin[ \t\n]*{[ \t\n]*document[ \t\n]*}"))
897 (;; delimited with \begin. In ispell: displaymath, eqnarray, eqnarray*,
898 ;; equation, minipage, picture, tabular, tabular* (ispell)
899 ("\\(figure\\|table\\)\\*?" ispell-tex-arg-end 0)
900 ("list" ispell-tex-arg-end 2)
901 ("program" . "\\\\end[ \t\n]*{[ \t\n]*program[ \t\n]*}")
902 ("verbatim\\*?" . "\\\\end[ \t\n]*{[ \t\n]*verbatim\\*?[ \t\n]*}")))
903 "*Lists of regions to be skipped in TeX mode.
904 First list is used raw.
905 Second list has key placed inside \\begin{}.
907 Delete or add any regions you want to be automatically selected
908 for skipping in latex mode.")
911 (defcustom ispell-skip-sgml 'use-mode-name
912 "*Indicates whether ispell should skip spell checking of SGML markup.
913 If t, always skip SGML markup; if nil, never skip; if non-t and non-nil,
914 guess whether SGML markup should be skipped according to the name of the
915 buffer's major mode."
916 :type '(choice (const :tag "always" t) (const :tag "never" nil)
917 (const :tag "use-mode-name" use-mode-name))
918 :group 'ispell)
920 (defvar ispell-local-pdict ispell-personal-dictionary
921 "A buffer local variable containing the current personal dictionary.
922 If non-nil, the value must be a string, which is a file name.
924 If you specify a personal dictionary for the current buffer which is
925 different from the current personal dictionary, the effect is similar
926 to calling \\[ispell-change-dictionary]. This variable is automatically
927 set when defined in the file with either `ispell-pdict-keyword' or the
928 local variable syntax.")
930 (make-variable-buffer-local 'ispell-local-pdict)
932 (defvar ispell-buffer-local-name nil
933 "Contains the buffer name if local word definitions were used.
934 Ispell is then restarted because the local words could conflict.")
936 (defvar ispell-parser 'use-mode-name
937 "*Indicates whether ispell should parse the current buffer as TeX Code.
938 Special value `use-mode-name' tries to guess using the name of `major-mode'.
939 Default parser is `nroff'.
940 Currently the only other valid parser is `tex'.
942 You can set this variable in hooks in your init file -- eg:
944 (add-hook 'tex-mode-hook (function (lambda () (setq ispell-parser 'tex))))")
946 (defvar ispell-region-end (make-marker)
947 "Marker that allows spelling continuations.")
949 (defvar ispell-check-only nil
950 "If non-nil, `ispell-word' does not try to correct the word.")
953 ;;; **********************************************************************
954 ;;; **********************************************************************
958 (and (not (string-match "18\\.[0-9]+\\.[0-9]+" emacs-version))
959 (not (boundp 'epoch::version))
960 (defalias 'ispell 'ispell-buffer)
961 (defalias 'ispell-check-version 'check-ispell-version))
964 (if (not (fboundp 'buffer-substring-no-properties))
965 (defun buffer-substring-no-properties (start end)
966 (buffer-substring start end)))
968 ;;;###autoload
969 (define-key esc-map "$" 'ispell-word)
971 ;;;###autoload
972 (defun ispell-word (&optional following quietly continue)
973 "Check spelling of word under or before the cursor.
974 If the word is not found in dictionary, display possible corrections
975 in a window allowing you to choose one.
977 If optional argument FOLLOWING is non-nil or if `ispell-following-word'
978 is non-nil when called interactively, then the following word
979 \(rather than preceding\) is checked when the cursor is not over a word.
980 When the optional argument QUIETLY is non-nil or `ispell-quietly' is non-nil
981 when called interactively, non-corrective messages are suppressed.
983 With a prefix argument (or if CONTINUE is non-nil),
984 resume interrupted spell-checking of a buffer or region.
986 Word syntax described by `ispell-dictionary-alist' (which see).
988 This will check or reload the dictionary. Use \\[ispell-change-dictionary]
989 or \\[ispell-region] to update the Ispell process."
990 (interactive (list nil nil current-prefix-arg))
991 (if continue
992 (ispell-continue)
993 (if (interactive-p)
994 (setq following ispell-following-word
995 quietly ispell-quietly))
996 (ispell-accept-buffer-local-defs) ; use the correct dictionary
997 (let ((cursor-location (point)) ; retain cursor location
998 (word (ispell-get-word following))
999 start end poss new-word replace)
1000 ;; De-structure return word info list.
1001 (setq start (car (cdr word))
1002 end (car (cdr (cdr word)))
1003 word (car word))
1005 ;; now check spelling of word if it has 3 or more characters.
1006 (cond
1007 ((> (length word) 2)
1008 (or quietly
1009 (message "Checking spelling of %s..."
1010 (funcall ispell-format-word word)))
1011 (process-send-string ispell-process "%\n") ;put in verbose mode
1012 (process-send-string ispell-process (concat "^" word "\n"))
1013 ;; wait until ispell has processed word
1014 (while (progn
1015 (accept-process-output ispell-process)
1016 (not (string= "" (car ispell-filter)))))
1017 ;;(process-send-string ispell-process "!\n") ;back to terse mode.
1018 (setq ispell-filter (cdr ispell-filter)) ; remove extra \n
1019 (if (listp ispell-filter)
1020 (setq poss (ispell-parse-output (car ispell-filter))))
1021 (cond ((eq poss t)
1022 (or quietly
1023 (message "%s is correct"
1024 (funcall ispell-format-word word))))
1025 ((stringp poss)
1026 (or quietly
1027 (message "%s is correct because of root %s"
1028 (funcall ispell-format-word word)
1029 (funcall ispell-format-word poss))))
1030 ((null poss) (message "Error in ispell process"))
1031 (ispell-check-only ; called from ispell minor mode.
1032 (beep)
1033 (message "%s is incorrect" (funcall ispell-format-word word)))
1034 (t ; prompt for correct word.
1035 (save-window-excursion
1036 (setq replace (ispell-command-loop
1037 (car (cdr (cdr poss)))
1038 (car (cdr (cdr (cdr poss))))
1039 (car poss) start end)))
1040 (cond ((equal 0 replace)
1041 (ispell-add-per-file-word-list (car poss)))
1042 (replace
1043 (setq new-word (if (atom replace) replace (car replace))
1044 cursor-location (+ (- (length word) (- end start))
1045 cursor-location))
1046 (if (not (equal new-word (car poss)))
1047 (progn
1048 (delete-region start end)
1049 (setq start (point))
1050 (insert new-word)
1051 (setq end (point))))
1052 (if (not (atom replace)) ;recheck spelling of replacement
1053 (progn
1054 (if (car (cdr replace)) ; query replace requested
1055 (save-window-excursion
1056 (query-replace word new-word t)))
1057 (ispell-region start end)))))
1058 (if (get-buffer ispell-choices-buffer)
1059 (kill-buffer ispell-choices-buffer))))
1060 (ispell-pdict-save ispell-silently-savep)
1061 (if ispell-quit (setq ispell-quit nil))))
1062 (goto-char cursor-location)))) ; return to original location
1065 (defun ispell-get-word (following &optional extra-otherchars)
1066 "Return the word for spell-checking according to ispell syntax.
1067 If optional argument FOLLOWING is non-nil or if `ispell-following-word'
1068 is non-nil when called interactively, then the following word
1069 \(rather than preceding\) is checked when the cursor is not over a word.
1070 Optional second argument contains otherchars that can be included in word
1071 many times.
1073 Word syntax described by `ispell-dictionary-alist' (which see)."
1074 (let* ((ispell-casechars (ispell-get-casechars))
1075 (ispell-not-casechars (ispell-get-not-casechars))
1076 (ispell-otherchars (ispell-get-otherchars))
1077 (ispell-many-otherchars-p (ispell-get-many-otherchars-p))
1078 (word-regexp (concat ispell-casechars
1079 "+\\("
1080 (if (not (string= "" ispell-otherchars))
1081 (concat ispell-otherchars "?"))
1082 (if extra-otherchars
1083 (concat extra-otherchars "?"))
1084 ispell-casechars
1085 "+\\)"
1086 (if (or ispell-many-otherchars-p
1087 extra-otherchars)
1088 "*" "?")))
1089 did-it-once prevpt
1090 start end word)
1091 ;; find the word
1092 (if (not (looking-at ispell-casechars))
1093 (if following
1094 (re-search-forward ispell-casechars (point-max) t)
1095 (re-search-backward ispell-casechars (point-min) t)))
1096 ;; move to front of word
1097 (re-search-backward ispell-not-casechars (point-min) 'start)
1098 (while (and (or (and (not (string= "" ispell-otherchars))
1099 (looking-at ispell-otherchars))
1100 (and extra-otherchars (looking-at extra-otherchars)))
1101 (not (bobp))
1102 (or (not did-it-once)
1103 ispell-many-otherchars-p)
1104 (not (eq prevpt (point))))
1105 (if (and extra-otherchars (looking-at extra-otherchars))
1106 (progn
1107 (backward-char 1)
1108 (if (looking-at ispell-casechars)
1109 (re-search-backward ispell-not-casechars (point-min) 'move)))
1110 (setq did-it-once t
1111 prevpt (point))
1112 (backward-char 1)
1113 (if (looking-at ispell-casechars)
1114 (re-search-backward ispell-not-casechars (point-min) 'move)
1115 (backward-char -1))))
1116 ;; Now mark the word and save to string.
1117 (if (not (re-search-forward word-regexp (point-max) t))
1118 (if ispell-check-only
1119 ;; return dummy word when just flagging misspellings
1120 (list "" (point) (point))
1121 (error "No word found to check!"))
1122 (setq start (match-beginning 0)
1123 end (point)
1124 word (buffer-substring-no-properties start end))
1125 (list word start end))))
1128 ;;; Global ispell-pdict-modified-p is set by ispell-command-loop and
1129 ;;; tracks changes in the dictionary. The global may either be
1130 ;;; a value or a list, whose value is the state of whether the
1131 ;;; dictionary needs to be saved.
1133 ;;; ###autoload
1134 (defun ispell-pdict-save (&optional no-query force-save)
1135 "Check to see if the personal dictionary has been modified.
1136 If so, ask if it needs to be saved."
1137 (interactive (list ispell-silently-savep t))
1138 (if (and ispell-pdict-modified-p (listp ispell-pdict-modified-p))
1139 (setq ispell-pdict-modified-p (car ispell-pdict-modified-p)))
1140 (if (or ispell-pdict-modified-p force-save)
1141 (if (or no-query (y-or-n-p "Personal dictionary modified. Save? "))
1142 (progn
1143 (process-send-string ispell-process "#\n") ; save dictionary
1144 (message "Personal dictionary saved."))))
1145 ;; unassert variable, even if not saved to avoid questioning.
1146 (setq ispell-pdict-modified-p nil))
1149 (defun ispell-command-loop (miss guess word start end)
1150 "Display possible corrections from list MISS.
1151 GUESS lists possibly valid affix construction of WORD.
1152 Returns nil to keep word.
1153 Returns 0 to insert locally into buffer-local dictionary.
1154 Returns string for new chosen word.
1155 Returns list for new replacement word (will be rechecked).
1156 Query-replace when list length is 2.
1157 Automatic query-replace when second element is `query-replace'.
1158 Highlights the word, which is assumed to run from START to END.
1159 Global `ispell-pdict-modified-p' becomes a list where the only value
1160 indicates whether the dictionary has been modified when option `a' or `i' is
1161 used.
1162 Global `ispell-quit' set to start location to continue spell session."
1163 (let ((textbuf (current-buffer))
1164 (count ?0)
1165 (line 2)
1166 (max-lines (- (window-height) 4)) ; assure 4 context lines.
1167 (choices miss)
1168 (window-min-height (min window-min-height
1169 ispell-choices-win-default-height))
1170 (command-characters '( ? ?i ?a ?A ?r ?R ?? ?x ?X ?q ?l ?u ?m ))
1171 (dedicated (window-dedicated-p (selected-window)))
1172 (skipped 0)
1173 char num result textwin dedicated-win highlighted)
1175 ;; setup the *Choices* buffer with valid data.
1176 (save-excursion
1177 (set-buffer (get-buffer-create ispell-choices-buffer))
1178 (setq mode-line-format (concat "-- %b -- word: " word))
1179 (and (fboundp 'set-specifier) ; prevent XEmacs modeline hiding
1180 (set-specifier has-modeline-p (cons (current-buffer) nil)))
1181 (erase-buffer)
1182 (if guess
1183 (progn
1184 (insert "Affix rules generate and capitalize "
1185 "this word as shown below:\n\t")
1186 (while guess
1187 (if (> (+ 4 (current-column) (length (car guess)))
1188 (window-width))
1189 (progn
1190 (insert "\n\t")
1191 (setq line (1+ line))))
1192 (insert (car guess) " ")
1193 (setq guess (cdr guess)))
1194 (insert "\nUse option `i' if this is a correct composition"
1195 " from the derivative root.\n")
1196 (setq line (+ line (if choices 3 2)))))
1197 (while (and choices
1198 (< (if (> (+ 7 (current-column) (length (car choices))
1199 (if (> count ?~) 3 0))
1200 (window-width))
1201 (progn
1202 (insert "\n")
1203 (setq line (1+ line)))
1204 line)
1205 max-lines))
1206 ;; not so good if there are over 20 or 30 options, but then, if
1207 ;; there are that many you don't want to scan them all anyway...
1208 (while (memq count command-characters) ; skip command characters.
1209 (setq count (ispell-int-char (1+ count))
1210 skipped (1+ skipped)))
1211 (insert "(" count ") " (car choices) " ")
1212 (setq choices (cdr choices)
1213 count (ispell-int-char (1+ count))))
1214 (setq count (ispell-int-char (- count ?0 skipped))))
1216 ;; Assure word is visible
1217 (if (not (pos-visible-in-window-p end))
1218 (sit-for 0))
1220 ;; allow temporary split of dedicated windows...
1221 (if dedicated
1222 (progn
1223 (setq dedicated-win (selected-window))
1224 (set-window-dedicated-p dedicated-win nil)))
1226 ;; Display choices for misspelled word.
1227 (ispell-show-choices line end)
1229 (select-window (setq textwin (next-window)))
1231 ;; highlight word, protecting current buffer status
1232 (unwind-protect
1233 (progn
1234 (and ispell-highlight-p
1235 (ispell-highlight-spelling-error start end t))
1236 ;; Loop until a valid choice is made.
1237 (while
1240 (setq
1241 result
1242 (progn
1243 (undo-boundary)
1244 (let (message-log-max)
1245 (message (concat "C-h or ? for more options; SPC to leave "
1246 "unchanged, Character to replace word")))
1247 (let ((inhibit-quit t))
1248 (setq char (if (fboundp 'read-char-exclusive)
1249 (read-char-exclusive)
1250 (read-char))
1251 skipped 0)
1252 (if (or quit-flag (= char ?\C-g)) ; C-g is like typing X
1253 (setq char ?X
1254 quit-flag nil)))
1255 ;; Adjust num to array offset skipping command characters.
1256 (let ((com-chars command-characters))
1257 (while com-chars
1258 (if (and (> (car com-chars) ?0) (< (car com-chars) char))
1259 (setq skipped (1+ skipped)))
1260 (setq com-chars (cdr com-chars)))
1261 (setq num (- char ?0 skipped)))
1263 (cond
1264 ((= char ? ) nil) ; accept word this time only
1265 ((= char ?i) ; accept and insert word into pers dict
1266 (process-send-string ispell-process (concat "*" word "\n"))
1267 (setq ispell-pdict-modified-p '(t)) ; dictionary modified!
1268 nil)
1269 ((or (= char ?a) (= char ?A)) ; accept word without insert
1270 (process-send-string ispell-process (concat "@" word "\n"))
1271 (if (null ispell-pdict-modified-p)
1272 (setq ispell-pdict-modified-p
1273 (list ispell-pdict-modified-p)))
1274 (if (= char ?A) 0)) ; return 0 for ispell-add buffer-local
1275 ((or (= char ?r) (= char ?R)) ; type in replacement
1276 (and (eq 'block ispell-highlight-p) ; refresh tty's
1277 (ispell-highlight-spelling-error start end nil t))
1278 (let ((result
1279 (if (or (= char ?R) ispell-query-replace-choices)
1280 (list (read-string "Query-replacement for: "
1281 word) t)
1282 (cons (read-string "Replacement for: " word)
1283 nil))))
1284 (and (eq 'block ispell-highlight-p)
1285 (ispell-highlight-spelling-error start end nil
1286 'block))
1287 result))
1288 ((or (= char ??) (= char help-char) (= char ?\C-h))
1289 (and (eq 'block ispell-highlight-p)
1290 (ispell-highlight-spelling-error start end nil t))
1291 (ispell-help)
1292 (and (eq 'block ispell-highlight-p)
1293 (ispell-highlight-spelling-error start end nil
1294 'block))
1296 ;; Quit and move point back.
1297 ((= char ?x)
1298 (ispell-pdict-save ispell-silently-savep)
1299 (message "Exited spell-checking")
1300 (setq ispell-quit t)
1301 nil)
1302 ;; Quit and preserve point.
1303 ((= char ?X)
1304 (ispell-pdict-save ispell-silently-savep)
1305 (message "%s"
1306 (substitute-command-keys
1307 (concat "Spell-checking suspended;"
1308 " use C-u \\[ispell-word] to resume")))
1309 (setq ispell-quit start)
1310 nil)
1311 ((= char ?q)
1312 (if (y-or-n-p "Really kill Ispell process? ")
1313 (progn
1314 (ispell-kill-ispell t) ; terminate process.
1315 (setq ispell-quit (or (not ispell-checking-message)
1316 (point))
1317 ispell-pdict-modified-p nil))
1318 t)) ; continue if they don't quit.
1319 ((= char ?l)
1320 (and (eq 'block ispell-highlight-p) ; refresh tty displays
1321 (ispell-highlight-spelling-error start end nil t))
1322 (let ((new-word (read-string
1323 "Lookup string (`*' is wildcard): "
1324 word))
1325 (new-line 2))
1326 (if new-word
1327 (progn
1328 (save-excursion
1329 (set-buffer (get-buffer-create
1330 ispell-choices-buffer))
1331 (erase-buffer)
1332 (setq count ?0
1333 skipped 0
1334 mode-line-format (concat
1335 "-- %b -- word: "
1336 new-word)
1337 miss (lookup-words new-word)
1338 choices miss)
1339 (while (and choices ; adjust choices window.
1340 (< (if (> (+ 7 (current-column)
1341 (length (car choices))
1342 (if (> count ?~) 3 0))
1343 (window-width))
1344 (progn
1345 (insert "\n")
1346 (setq new-line
1347 (1+ new-line)))
1348 new-line)
1349 max-lines))
1350 (while (memq count command-characters)
1351 (setq count (ispell-int-char (1+ count))
1352 skipped (1+ skipped)))
1353 (insert "(" count ") " (car choices) " ")
1354 (setq choices (cdr choices)
1355 count (ispell-int-char (1+ count))))
1356 (setq count (ispell-int-char
1357 (- count ?0 skipped))))
1358 (select-window (previous-window))
1359 (if (and (/= new-line line)
1360 (> (max line new-line)
1361 ispell-choices-win-default-height))
1362 (let* ((minh ispell-choices-win-default-height)
1363 (gr-bl (if (< line minh) ; blanks
1364 (- minh line)
1366 (shr-bl (if (< new-line minh) ; blanks
1367 (- minh new-line)
1368 0)))
1369 (if (> new-line line)
1370 (enlarge-window (- new-line line gr-bl))
1371 (shrink-window (- line new-line shr-bl)))
1372 (setq line new-line)))
1373 (select-window (next-window)))))
1374 (and (eq 'block ispell-highlight-p)
1375 (ispell-highlight-spelling-error start end nil
1376 'block))
1377 t) ; reselect from new choices
1378 ((= char ?u) ; insert lowercase into dictionary
1379 (process-send-string ispell-process
1380 (concat "*" (downcase word) "\n"))
1381 (setq ispell-pdict-modified-p '(t)) ; dictionary modified!
1382 nil)
1383 ((= char ?m) ; type in what to insert
1384 (process-send-string
1385 ispell-process (concat "*" (read-string "Insert: " word)
1386 "\n"))
1387 (setq ispell-pdict-modified-p '(t))
1388 (cons word nil))
1389 ((and (>= num 0) (< num count))
1390 (if ispell-query-replace-choices ; Query replace flag
1391 (list (nth num miss) 'query-replace)
1392 (nth num miss)))
1393 ((= char ?\C-l)
1394 (redraw-display) t)
1395 ((= char ?\C-r)
1396 (if (marker-position ispell-recursive-edit-marker)
1397 (progn
1398 (message "Only one recursive edit session supported")
1399 (beep))
1400 (set-marker ispell-recursive-edit-marker start)
1401 ;;(set-marker ispell-region-end reg-end)
1402 (and ispell-highlight-p ; unhighlight
1403 (ispell-highlight-spelling-error start end))
1404 (unwind-protect
1405 (progn
1406 (save-window-excursion (save-excursion
1407 (recursive-edit)) t)
1408 (if (not (equal (marker-buffer
1409 ispell-recursive-edit-marker)
1410 (current-buffer)))
1411 (error
1412 "Cannot continue ispell from this buffer."))
1413 (goto-char ispell-recursive-edit-marker))
1414 (set-marker ispell-recursive-edit-marker nil)))
1415 (cons word nil)) ; recheck starting at this word.
1416 ((= char ?\C-z)
1417 (funcall (key-binding "\C-z"))
1419 (t (ding) t))))))
1420 result)
1421 ;; protected
1422 (and ispell-highlight-p ; unhighlight
1423 (save-window-excursion
1424 (select-window textwin)
1425 (ispell-highlight-spelling-error start end)))
1426 (if dedicated
1427 (set-window-dedicated-p dedicated-win t)))))
1431 (defun ispell-show-choices (line end)
1432 "Shows the choices in another buffer or frame."
1433 (if ispell-use-framepop-p
1434 (progn
1435 (framepop-display-buffer (get-buffer ispell-choices-buffer))
1436 (get-buffer-window ispell-choices-buffer t)
1437 (select-window (previous-window))) ; *Choices* window
1438 ;; standard selection by splitting a small buffer out of this window.
1439 (let ((choices-window (get-buffer-window ispell-choices-buffer)))
1440 (if choices-window
1441 (if (= line (window-height choices-window))
1442 (select-window choices-window)
1443 ;; *Choices* window changed size. Adjust the choices window
1444 ;; without scrolling the spelled window when possible
1445 (let ((window-line (- line (window-height choices-window)))
1446 (visible (progn (vertical-motion -1) (point))))
1447 (if (< line ispell-choices-win-default-height)
1448 (setq window-line (+ window-line
1449 (- ispell-choices-win-default-height
1450 line))))
1451 (move-to-window-line 0)
1452 (vertical-motion window-line)
1453 (set-window-start (selected-window)
1454 (if (> (point) visible) visible (point)))
1455 (goto-char end)
1456 (select-window (previous-window)) ; *Choices* window
1457 (enlarge-window window-line)))
1458 ;; Overlay *Choices* window when it isn't showing
1459 (ispell-overlay-window (max line ispell-choices-win-default-height)))
1460 (switch-to-buffer ispell-choices-buffer)
1461 (goto-char (point-min)))))
1464 ;;;###autoload
1465 (defun ispell-help ()
1466 "Display a list of the options available when a misspelling is encountered.
1468 Selections are:
1470 DIGIT: Replace the word with a digit offered in the *Choices* buffer.
1471 SPC: Accept word this time.
1472 `i': Accept word and insert into private dictionary.
1473 `a': Accept word for this session.
1474 `A': Accept word and place in `buffer-local dictionary'.
1475 `r': Replace word with typed-in value. Rechecked.
1476 `R': Replace word with typed-in value. Query-replaced in buffer. Rechecked.
1477 `?': Show these commands.
1478 `x': Exit spelling buffer. Move cursor to original point.
1479 `X': Exit spelling buffer. Leaves cursor at the current point, and permits
1480 the aborted check to be completed later.
1481 `q': Quit spelling session (Kills ispell process).
1482 `l': Look up typed-in replacement in alternate dictionary. Wildcards okay.
1483 `u': Like `i', but the word is lower-cased first.
1484 `m': Place typed-in value in personal dictionary, then recheck current word.
1485 `C-l': redraws screen
1486 `C-r': recursive edit
1487 `C-z': suspend emacs or iconify frame"
1489 (if (equal ispell-help-in-bufferp 'electric)
1490 (progn
1491 (require 'ehelp)
1492 (with-electric-help
1493 (function (lambda ()
1494 ;;This shouldn't be necessary: with-electric-help needs
1495 ;; an optional argument telling it about the smallest
1496 ;; acceptable window-height of the help buffer.
1497 (if (< (window-height) 15)
1498 (enlarge-window (- 15 (window-height))))
1499 (princ "Selections are:
1501 DIGIT: Replace the word with a digit offered in the *Choices* buffer.
1502 SPC: Accept word this time.
1503 `i': Accept word and insert into private dictionary.
1504 `a': Accept word for this session.
1505 `A': Accept word and place in `buffer-local dictionary'.
1506 `r': Replace word with typed-in value. Rechecked.
1507 `R': Replace word with typed-in value. Query-replaced in buffer. Rechecked.
1508 `?': Show these commands.
1509 `x': Exit spelling buffer. Move cursor to original point.
1510 `X': Exit spelling buffer. Leaves cursor at the current point, and permits
1511 the aborted check to be completed later.
1512 `q': Quit spelling session (Kills ispell process).
1513 `l': Look up typed-in replacement in alternate dictionary. Wildcards okay.
1514 `u': Like `i', but the word is lower-cased first.
1515 `m': Place typed-in value in personal dictionary, then recheck current word.
1516 `C-l': redraws screen
1517 `C-r': recursive edit
1518 `C-z': suspend emacs or iconify frame")
1519 nil ;undocumented requirement of with-electric-help
1520 ))))
1523 (let ((help-1 (concat "[r/R]eplace word; [a/A]ccept for this session; "
1524 "[i]nsert into private dictionary"))
1525 (help-2 (concat "[l]ook a word up in alternate dictionary; "
1526 "e[x/X]it; [q]uit session"))
1527 (help-3 (concat "[u]ncapitalized insert into dict. "
1528 "Type 'x C-h d ispell-help' for more help")))
1529 (save-window-excursion
1530 (if ispell-help-in-bufferp
1531 (progn
1532 (ispell-overlay-window 4)
1533 (switch-to-buffer (get-buffer-create "*Ispell Help*"))
1534 (insert (concat help-1 "\n" help-2 "\n" help-3))
1535 (sit-for 5)
1536 (kill-buffer "*Ispell Help*"))
1537 (select-window (minibuffer-window))
1538 ;;(enlarge-window 2)
1539 (erase-buffer)
1540 (cond ((string-match "Lucid\\|XEmacs" emacs-version)
1541 (message help-3)
1542 (enlarge-window 1)
1543 (message help-2)
1544 (enlarge-window 1)
1545 (message help-1)
1546 (goto-char (point-min)))
1548 (if (not (string-match "18\\.[0-9]+\\.[0-9]+" emacs-version))
1549 (message nil))
1550 ;;(set-minibuffer-window (selected-window))
1551 (enlarge-window 2)
1552 (insert (concat help-1 "\n" help-2 "\n" help-3))))
1553 (sit-for 5)
1554 (erase-buffer))))))
1557 (defun lookup-words (word &optional lookup-dict)
1558 "Look up WORD in optional word-list dictionary LOOKUP-DICT.
1559 A `*' serves as a wild card. If no wild cards, `look' is used if it exists.
1560 Otherwise the variable `ispell-grep-command' contains the command used to
1561 search for the words (usually egrep).
1563 Optional second argument contains the dictionary to use; the default is
1564 `ispell-alternate-dictionary'."
1565 ;; We don't use the filter for this function, rather the result is written
1566 ;; into a buffer. Hence there is no need to save the filter values.
1567 (if (null lookup-dict)
1568 (setq lookup-dict ispell-alternate-dictionary))
1570 (let* ((process-connection-type ispell-use-ptys-p)
1571 (wild-p (string-match "\\*" word))
1572 (look-p (and ispell-look-p ; Only use look for an exact match.
1573 (or ispell-have-new-look (not wild-p))))
1574 (ispell-grep-buffer (get-buffer-create "*Ispell-Temp*")) ; result buf
1575 (prog (if look-p ispell-look-command ispell-grep-command))
1576 (args (if look-p ispell-look-options ispell-grep-options))
1577 status results loc)
1578 (unwind-protect
1579 (save-window-excursion
1580 (message "Starting \"%s\" process..." (file-name-nondirectory prog))
1581 (set-buffer ispell-grep-buffer)
1582 (if look-p
1584 ;; convert * to .*
1585 (insert "^" word "$")
1586 (while (search-backward "*" nil t) (insert "."))
1587 (setq word (buffer-string))
1588 (erase-buffer))
1589 (setq status (call-process prog nil t nil args word lookup-dict))
1590 ;; grep returns status 1 and no output when word not found, which
1591 ;; is a perfectly normal thing.
1592 (if (stringp status)
1593 (setq results (cons (format "error: %s exited with signal %s"
1594 (file-name-nondirectory prog) status)
1595 results))
1596 ;; else collect words into `results' in FIFO order
1597 (goto-char (point-max))
1598 ;; assure we've ended with \n
1599 (or (bobp) (= (preceding-char) ?\n) (insert ?\n))
1600 (while (not (bobp))
1601 (setq loc (point))
1602 (forward-line -1)
1603 (setq results (cons (buffer-substring-no-properties (point)
1604 (1- loc))
1605 results)))))
1606 ;; protected
1607 (kill-buffer ispell-grep-buffer)
1608 (if (and results (string-match ".+: " (car results)))
1609 (error "%s error: %s" ispell-grep-command (car results))))
1610 results))
1613 ;;; "ispell-filter" is a list of output lines from the generating function.
1614 ;;; Each full line (ending with \n) is a separate item on the list.
1615 ;;; "output" can contain multiple lines, part of a line, or both.
1616 ;;; "start" and "end" are used to keep bounds on lines when "output" contains
1617 ;;; multiple lines.
1618 ;;; "ispell-filter-continue" is true when we have received only part of a
1619 ;;; line as output from a generating function ("output" did not end with \n)
1620 ;;; THIS FUNCTION WILL FAIL IF THE PROCESS OUTPUT DOESN'T END WITH \n!
1621 ;;; This is the case when a process dies or fails. The default behavior
1622 ;;; in this case treats the next input received as fresh input.
1624 (defun ispell-filter (process output)
1625 "Output filter function for ispell, grep, and look."
1626 (let ((start 0)
1627 (continue t)
1628 end)
1629 (while continue
1630 (setq end (string-match "\n" output start)) ; get text up to the newline.
1631 ;; If we get out of sync and ispell-filter-continue is asserted when we
1632 ;; are not continuing, treat the next item as a separate list. When
1633 ;; ispell-filter-continue is asserted, ispell-filter *should* always be a
1634 ;; list!
1636 ;; Continue with same line (item)?
1637 (if (and ispell-filter-continue ispell-filter (listp ispell-filter))
1638 ;; Yes. Add it to the prev item
1639 (setcar ispell-filter
1640 (concat (car ispell-filter) (substring output start end)))
1641 ;; No. This is a new line and item.
1642 (setq ispell-filter
1643 (cons (substring output start end) ispell-filter)))
1644 (if (null end)
1645 ;; We've completed reading the output, but didn't finish the line.
1646 (setq ispell-filter-continue t continue nil)
1647 ;; skip over newline, this line complete.
1648 (setq ispell-filter-continue nil end (1+ end))
1649 (if (= end (length output)) ; No more lines in output
1650 (setq continue nil) ; so we can exit the filter.
1651 (setq start end)))))) ; else move start to next line of input
1654 ;;; This function destroys the mark location if it is in the word being
1655 ;;; highlighted.
1656 (defun ispell-highlight-spelling-error-generic (start end &optional highlight
1657 refresh)
1658 "Highlight the word from START to END with a kludge using `inverse-video'.
1659 When the optional third arg HIGHLIGHT is set, the word is highlighted;
1660 otherwise it is displayed normally.
1661 Uses block cursor to highlight one character.
1662 Optional REFRESH will unhighlighted then highlight, using block cursor
1663 highlighting when REFRESH is equal to `block'."
1664 (and (eq 'block ispell-highlight-p)
1665 (or (eq 'block refresh)
1666 (setq start (1+ start)))) ; On block non-refresh, inc start.
1667 (let ((modified (buffer-modified-p)) ; don't allow this fn to modify buffer
1668 (buffer-read-only nil) ; Allow highlighting read-only buffers.
1669 (text (buffer-substring-no-properties start end)) ; Save hilight region
1670 (inhibit-quit t) ; inhibit interrupt processing here.
1671 (buffer-undo-list t)) ; don't clutter the undo list.
1672 (goto-char end)
1673 (delete-region start end)
1674 (insert-char ? (- end start)) ; minimize amount of redisplay
1675 (sit-for 0) ; update display
1676 (if highlight (setq inverse-video (not inverse-video))) ; toggle video
1677 (delete-region start end) ; delete whitespace
1678 (insert text) ; insert text in inverse video.
1679 (sit-for 0) ; update display showing inverse video.
1680 (if (not highlight)
1681 (goto-char end)
1682 (setq inverse-video (not inverse-video)) ; toggle video
1683 (and (eq 'block ispell-highlight-p)
1684 (goto-char (1- start)))) ; use block cursor to "highlight" char
1685 (set-buffer-modified-p modified) ; don't modify if flag not set.
1686 (and refresh ; re-highlight
1687 (ispell-highlight-spelling-error-generic
1688 (if (eq 'block refresh) start (- start 2)) end t))))
1691 (defun ispell-highlight-spelling-error-xemacs (start end &optional highlight)
1692 "Highlight the word from START to END using `isearch-highlight'.
1693 When the optional third arg HIGHLIGHT is set, the word is highlighted,
1694 otherwise it is displayed normally."
1695 (if highlight
1696 (isearch-highlight start end)
1697 (isearch-dehighlight t))
1698 ;;(sit-for 0)
1702 (defun ispell-highlight-spelling-error-overlay (start end &optional highlight)
1703 "Highlight the word from START to END using overlays.
1704 When the optional third arg HIGHLIGHT is set, the word is highlighted
1705 otherwise it is displayed normally.
1707 The variable `ispell-highlight-face' selects the face to use for highlighting."
1708 (if highlight
1709 (progn
1710 (setq ispell-overlay (make-overlay start end))
1711 (overlay-put ispell-overlay 'face ispell-highlight-face))
1712 (delete-overlay ispell-overlay)))
1715 (defun ispell-highlight-spelling-error (start end &optional highlight refresh)
1716 (cond
1717 ((string-match "Lucid\\|XEmacs" emacs-version)
1718 (ispell-highlight-spelling-error-xemacs start end highlight))
1719 ((and (not (string-match "18\\.[0-9]+\\.[0-9]+" emacs-version))
1720 (featurep 'faces) window-system)
1721 (ispell-highlight-spelling-error-overlay start end highlight))
1722 (t (ispell-highlight-spelling-error-generic start end highlight refresh))))
1725 (defun ispell-overlay-window (height)
1726 "Create a window covering the top HEIGHT lines of the current window.
1727 Ensure that the line above point is still visible but otherwise avoid
1728 scrolling the current window. Leave the new window selected."
1729 (save-excursion
1730 (let ((oldot (save-excursion (forward-line -1) (point)))
1731 (top (save-excursion (move-to-window-line height) (point))))
1732 ;; If line above old point (line starting at oldot) would be
1733 ;; hidden by new window, scroll it to just below new win
1734 ;; otherwise set top line of other win so it doesn't scroll.
1735 (if (< oldot top) (setq top oldot))
1736 ;; NB: XEmacs 19.9 bug: If a window of size N (N includes the mode
1737 ;; line) is demanded, the last line is not visible.
1738 ;; At least this happens on AIX 3.2, XEmacs w/ Motif, font 9x15.
1739 ;; So we increment the height for this case.
1740 (if (and (string-match "Lucid\\|XEmacs" emacs-version)
1741 (string-match "19\\.9\\.[0-9]+" emacs-version))
1742 (setq height (1+ height)))
1743 ;; if frame is unsplitable, temporarily disable that...
1744 (if (cdr (assq 'unsplittable (frame-parameters (selected-frame))))
1745 (let ((frame (selected-frame)))
1746 (modify-frame-parameters frame '((unsplittable . nil)))
1747 (split-window nil height)
1748 (modify-frame-parameters frame '((unsplittable . t))))
1749 (split-window nil height))
1750 (set-window-start (next-window) top))))
1753 ;;; Should we add a compound word match return value?
1754 (defun ispell-parse-output (output)
1755 "Parse the OUTPUT string from Ispell process and return:
1756 1: t for an exact match.
1757 2: A string containing the root word matched via suffix removal.
1758 3: A list of possible correct spellings of the format:
1759 (\"ORIGINAL-WORD\" OFFSET MISS-LIST GUESS-LIST)
1760 ORIGINAL-WORD is a string of the possibly misspelled word.
1761 OFFSET is an integer giving the line offset of the word.
1762 MISS-LIST and GUESS-LIST are possibly null lists of guesses and misses.
1763 4: Nil when an error has occurred."
1764 (cond
1765 ((string= output "") t) ; for startup with pipes...
1766 ((string= output "*") t) ; exact match
1767 ((string= output "-") t) ; compound word match
1768 ((string= (substring output 0 1) "+") ; found because of root word
1769 (substring output 2)) ; return root word
1770 ((equal 0 (string-match "[\ra-zA-Z]" output))
1771 (ding) ; error message from ispell!
1772 (message (concat "Ispell error: " output))
1773 (sit-for 5)
1774 nil)
1775 (t ; need to process &, ?, and #'s
1776 (let ((type (substring output 0 1)) ; &, ?, or #
1777 (original-word (substring output 2 (string-match " " output 2)))
1778 (cur-count 0) ; contains number of misses + guesses
1779 count miss-list guess-list offset)
1780 (setq output (substring output (match-end 0))) ; skip over misspelling
1781 (if (string= type "#")
1782 (setq count 0) ; no misses for type #
1783 (setq count (string-to-int output) ; get number of misses.
1784 output (substring output (1+ (string-match " " output 1)))))
1785 (setq offset (string-to-int output))
1786 (if (string= type "#") ; No miss or guess list.
1787 (setq output nil)
1788 (setq output (substring output (1+ (string-match " " output 1)))))
1789 (while output
1790 (let ((end (string-match ", \\|\\($\\)" output))) ; end of miss/guess.
1791 (setq cur-count (1+ cur-count))
1792 (if (> cur-count count)
1793 (setq guess-list (cons (substring output 0 end) guess-list))
1794 (setq miss-list (cons (substring output 0 end) miss-list)))
1795 (if (match-end 1) ; True only when at end of line.
1796 (setq output nil) ; no more misses or guesses
1797 (setq output (substring output (+ end 2))))))
1798 (list original-word offset (nreverse miss-list)(nreverse guess-list))))))
1801 (defun check-ispell-version (&optional interactivep)
1802 ;; This is a little wasteful as we actually launch ispell twice: once
1803 ;; to make sure it's the right version, and once for real. But people
1804 ;; get confused by version mismatches *all* the time (and I've got the
1805 ;; email to prove it) so I think this is worthwhile. And the -v[ersion]
1806 ;; option is the only way I can think of to do this that works with
1807 ;; all versions, since versions earlier than 3.0.09 didn't identify
1808 ;; themselves on startup.
1809 (interactive "p")
1810 (let ((result t)
1811 (case-fold-search-val case-fold-search)
1812 ;; avoid bugs when syntax of `.' changes in various default modes
1813 (default-major-mode 'fundamental-mode)
1814 status)
1815 (save-excursion
1816 (set-buffer (get-buffer-create " *ispell-tmp*"))
1817 (erase-buffer)
1818 (setq status (call-process ispell-program-name nil t nil "-v"))
1819 (goto-char (point-min))
1820 (if interactivep
1821 (progn
1822 (end-of-line)
1823 (setq result (concat (buffer-substring-no-properties (point-min)
1824 (point))
1825 ", "
1826 ispell-version))
1827 (message result)
1828 (goto-char (point-min))))
1829 (if (not (memq status '(0 nil)))
1830 (error "%s exited with %s %s" ispell-program-name
1831 (if (stringp status) "signal" "code") status))
1832 (setq case-fold-search t
1833 status (re-search-forward
1834 (concat "\\<\\("
1835 (format "%d" (car ispell-required-version))
1836 "\\)\\.\\([0-9]*\\)\\.\\([0-9]*\\)\\>")
1837 nil t)
1838 case-fold-search case-fold-search-val)
1839 (if (or (not status) ; major version mismatch
1840 (< (car (read-from-string (buffer-substring-no-properties
1841 (match-beginning 2) (match-end 2))))
1842 (car (cdr ispell-required-version)))) ; minor version mismatch
1843 (error "%s version 3 release %d.%d.%d or greater is required"
1844 ispell-program-name (car ispell-required-version)
1845 (car (cdr ispell-required-version))
1846 (car (cdr (cdr ispell-required-version))))
1847 ;; check that it is the correct version.
1848 (if (and (= (car (read-from-string (buffer-substring-no-properties
1849 (match-beginning 2)(match-end 2))))
1850 (car (cdr ispell-required-version)))
1851 (< (car (read-from-string (buffer-substring-no-properties
1852 (match-beginning 3)(match-end 3))))
1853 (car (cdr (cdr ispell-required-version)))))
1854 (setq ispell-offset 0)))
1855 (kill-buffer (current-buffer)))
1856 result))
1859 (defun ispell-init-process ()
1860 "Check status of Ispell process and start if necessary."
1861 (if (and ispell-process
1862 (eq (process-status ispell-process) 'run)
1863 ;; If we're using a personal dictionary, assure
1864 ;; we're in the same default directory!
1865 (or (not ispell-personal-dictionary)
1866 (equal ispell-process-directory default-directory)))
1867 (setq ispell-filter nil ispell-filter-continue nil)
1868 ;; may need to restart to select new personal dictionary.
1869 (ispell-kill-ispell t)
1870 (message "Starting new Ispell process...")
1871 (sit-for 0)
1872 (check-ispell-version)
1873 (setq ispell-process
1874 (let ((process-connection-type ispell-use-ptys-p))
1875 (apply 'start-process
1876 "ispell" nil ispell-program-name
1877 "-a" ; accept single input lines
1878 "-m" ; make root/affix combos not in dict
1879 (let (args)
1880 ;; Local dictionary becomes the global dictionary in use.
1881 (if ispell-local-dictionary
1882 (setq ispell-dictionary ispell-local-dictionary))
1883 (setq args (ispell-get-ispell-args))
1884 (if ispell-dictionary ; use specified dictionary
1885 (setq args
1886 (append (list "-d" ispell-dictionary) args)))
1887 (if ispell-personal-dictionary ; use specified pers dict
1888 (setq args
1889 (append args
1890 (list "-p"
1891 (expand-file-name
1892 ispell-personal-dictionary)))))
1893 (setq args (append args ispell-extra-args))
1894 args)))
1895 ispell-filter nil
1896 ispell-filter-continue nil
1897 ispell-process-directory default-directory)
1898 (set-process-filter ispell-process 'ispell-filter)
1899 (if (and (boundp 'enable-multibyte-characters)
1900 (fboundp 'set-process-coding-system)
1901 enable-multibyte-characters)
1902 (set-process-coding-system ispell-process (ispell-get-coding-system)
1903 (ispell-get-coding-system)))
1904 ;; Get version ID line
1905 (if (not (string-match "18\\.[0-9]+\\.[0-9]+" emacs-version))
1906 (accept-process-output ispell-process 3)
1907 (accept-process-output ispell-process))
1908 ;; get more output if filter empty?
1909 (if (null ispell-filter) (accept-process-output ispell-process 3))
1910 (cond ((null ispell-filter)
1911 (error "%s did not output version line" ispell-program-name))
1912 ((and
1913 (stringp (car ispell-filter))
1914 (if (string-match "warning: " (car ispell-filter))
1915 (progn
1916 (if (not (string-match "18\\.[0-9]+\\.[0-9]+" emacs-version))
1917 (accept-process-output ispell-process 3) ; was warn msg.
1918 (accept-process-output ispell-process))
1919 (stringp (car ispell-filter)))
1920 (null (cdr ispell-filter)))
1921 (string-match "^@(#) " (car ispell-filter)))
1922 ;; got the version line as expected (we already know it's the right
1923 ;; version, so don't bother checking again.)
1924 nil)
1926 ;; Otherwise, it must be an error message. Show the user.
1927 ;; But first wait to see if some more output is going to arrive.
1928 ;; Otherwise we get cool errors like "Can't open ".
1929 (sleep-for 1)
1930 (accept-process-output ispell-process 3)
1931 (error "%s" (mapconcat 'identity ispell-filter "\n"))))
1932 (setq ispell-filter nil) ; Discard version ID line
1933 (let ((extended-char-mode (ispell-get-extended-character-mode)))
1934 (if extended-char-mode ; ~ extended character mode
1935 (process-send-string ispell-process
1936 (concat extended-char-mode "\n"))))
1937 (process-kill-without-query ispell-process)))
1939 ;;;###autoload
1940 (defun ispell-kill-ispell (&optional no-error)
1941 "Kill current Ispell process (so that you may start a fresh one).
1942 With NO-ERROR, just return non-nil if there was no Ispell running."
1943 (interactive)
1944 (if (not (and ispell-process
1945 (eq (process-status ispell-process) 'run)))
1946 (or no-error
1947 (error "There is no ispell process running!"))
1948 (process-send-eof ispell-process)
1949 (if (eq (process-status ispell-process) 'run)
1950 (accept-process-output ispell-process 1))
1951 (if (eq (process-status ispell-process) 'run)
1952 (kill-process ispell-process))
1953 (while (not (or (eq (process-status ispell-process) 'exit)
1954 (eq (process-status ispell-process) 'signal)))
1955 (sleep-for 0 250))
1956 (setq ispell-process nil)
1957 (message "Ispell process killed")
1958 nil))
1961 ;;; ispell-change-dictionary is set in some people's hooks. Maybe this should
1962 ;;; call ispell-init-process rather than wait for a spell checking command?
1964 ;;;###autoload
1965 (defun ispell-change-dictionary (dict &optional arg)
1966 "Change `ispell-dictionary' (q.v.) to DICT and kill old Ispell process.
1967 A new one will be started as soon as necessary.
1969 By just answering RET you can find out what the current dictionary is.
1971 With prefix argument, set the default directory."
1972 (interactive
1973 (list (completing-read
1974 "Use new dictionary (RET for current, SPC to complete): "
1975 (cons (cons "default" nil) ispell-dictionary-alist) nil t)
1976 current-prefix-arg))
1977 (if (equal dict "default") (setq dict nil))
1978 ;; This relies on completing-read's bug of returning "" for no match
1979 (cond ((equal dict "")
1980 (message "Using %s dictionary"
1981 (or ispell-local-dictionary ispell-dictionary "default")))
1982 ((and (equal dict ispell-dictionary)
1983 (or (null ispell-local-dictionary)
1984 (equal dict ispell-local-dictionary)))
1985 ;; Specified dictionary is the default already. No-op
1986 (and (interactive-p)
1987 (message "No change, using %s dictionary" (or dict "default"))))
1988 (t ; reset dictionary!
1989 (if (assoc dict ispell-dictionary-alist)
1990 (progn
1991 (if (or arg (null dict)) ; set default dictionary
1992 (setq ispell-dictionary dict))
1993 (if (null arg) ; set local dictionary
1994 (setq ispell-local-dictionary dict)))
1995 (error "Undefined dictionary: %s" dict))
1996 (ispell-kill-ispell t)
1997 (message "(Next %sIspell command will use %s dictionary)"
1998 (cond ((equal ispell-local-dictionary ispell-dictionary)
2000 (arg "global ")
2001 (t "local "))
2002 (or (if (or (equal ispell-local-dictionary ispell-dictionary)
2003 (null arg))
2004 ispell-local-dictionary
2005 ispell-dictionary)
2006 "default")))))
2009 ;;; Spelling of comments are checked when ispell-check-comments is non-nil.
2011 ;;;###autoload
2012 (defun ispell-region (reg-start reg-end)
2013 "Interactively check a region for spelling errors.
2014 Return non-nil if spell session completed normally."
2015 (interactive "r") ; Don't flag errors on read-only bufs.
2016 (ispell-accept-buffer-local-defs) ; set up dictionary, local words, etc.
2017 (unwind-protect
2018 (save-excursion
2019 (message "Spell checking %s using %s dictionary..."
2020 (if (and (= reg-start (point-min)) (= reg-end (point-max)))
2021 (buffer-name) "region")
2022 (or ispell-dictionary "default"))
2023 ;; Returns cursor to original location.
2024 (save-window-excursion
2025 (goto-char reg-start)
2026 (let ((transient-mark-mode nil)
2027 (case-fold-search case-fold-search)
2028 (skip-region-start (make-marker))
2029 (skip-regexp (ispell-begin-skip-region-regexp))
2030 (skip-alist ispell-skip-region-alist)
2031 key)
2032 (if (eq ispell-parser 'tex)
2033 (setq case-fold-search nil
2034 skip-alist
2035 (append (car ispell-tex-skip-alists)
2036 (car (cdr ispell-tex-skip-alists))
2037 skip-alist)))
2038 (let (message-log-max)
2039 (message "searching for regions to skip"))
2040 (if (re-search-forward skip-regexp reg-end t)
2041 (progn
2042 (setq key (buffer-substring-no-properties
2043 (match-beginning 0) (match-end 0)))
2044 (set-marker skip-region-start (- (point) (length key)))
2045 (goto-char reg-start)))
2046 (let (message-log-max)
2047 (message "Continuing spelling check using %s dictionary..."
2048 (or ispell-dictionary "default")))
2049 (set-marker ispell-region-end reg-end)
2050 (while (and (not ispell-quit)
2051 (< (point) ispell-region-end))
2052 ;; spell-check region with skipping
2053 (if (and (marker-position skip-region-start)
2054 (<= skip-region-start (point)))
2055 (progn
2056 (ispell-skip-region key skip-alist) ; moves pt past region.
2057 (setq reg-start (point))
2058 (if (and (< reg-start ispell-region-end)
2059 (re-search-forward skip-regexp
2060 ispell-region-end t))
2061 (progn
2062 (setq key (buffer-substring-no-properties
2063 (car (match-data))
2064 (car (cdr (match-data)))))
2065 (set-marker skip-region-start
2066 (- (point) (length key)))
2067 (goto-char reg-start))
2068 (set-marker skip-region-start nil))))
2069 (setq reg-end (if (marker-position skip-region-start)
2070 (min skip-region-start ispell-region-end)
2071 (marker-position ispell-region-end)))
2072 (let* ((start (point))
2073 (end (save-excursion (end-of-line) (min (point) reg-end)))
2074 (string (ispell-get-line start end reg-end)))
2075 (setq end (point)) ; "end" tracks region retrieved.
2076 (if string ; there is something to spell check!
2077 (ispell-process-line string)) ; (special start end)
2078 (goto-char end)))))
2079 (not ispell-quit))
2080 ;; protected
2081 (if (get-buffer ispell-choices-buffer)
2082 (kill-buffer ispell-choices-buffer))
2083 (if ispell-quit
2084 (progn
2085 ;; preserve or clear the region for ispell-continue.
2086 (if (not (numberp ispell-quit))
2087 (set-marker ispell-region-end nil)
2088 ;; Ispell-continue enabled - ispell-region-end is set.
2089 (goto-char ispell-quit))
2090 ;; Check for aborting
2091 (if (and ispell-checking-message (numberp ispell-quit))
2092 (progn
2093 (setq ispell-quit nil)
2094 (error "Message send aborted")))
2095 (setq ispell-quit nil))
2096 (set-marker ispell-region-end nil)
2097 ;; Only save if successful exit.
2098 (ispell-pdict-save ispell-silently-savep)
2099 (message "Spell-checking done"))))
2102 ;;; Creates the regexp for skipping a region.
2103 ;;; Makes the skip-regexp local for tex buffers adding in the
2104 ;;; tex expressions to skip as well.
2105 ;;; Call AFTER ispell-buffer-local-parsing.
2106 (defun ispell-begin-skip-region-regexp ()
2107 (let ((skip-regexp (ispell-begin-skip-region)))
2108 (if (and (null ispell-check-comments) comment-start)
2109 (setq skip-regexp (concat (regexp-quote comment-start) "\\|"
2110 skip-regexp)))
2111 (if (and (eq 'exclusive ispell-check-comments) comment-start)
2112 (setq skip-regexp (concat (if (string= "" comment-end) "^"
2113 (regexp-quote comment-end))
2114 "\\|" skip-regexp)))
2115 (if ispell-skip-tib
2116 (setq skip-regexp (concat ispell-tib-ref-beginning "\\|" skip-regexp)))
2117 (if ispell-skip-sgml
2118 (setq skip-regexp (concat "<author>" "\\|"
2119 "<[cC][oO][dD][eE]>" "\\|"
2120 "<[vV][eE][rR][bB]>" "\\|"
2121 "<[tT][tT]>" "\\|"
2122 "<[tT][tT]/" "\\|"
2123 "</" "\\|"
2124 "<" "\\|"
2125 "&" "\\|"
2126 skip-regexp)))
2127 (if (eq ispell-parser 'tex)
2128 (setq skip-regexp (concat (ispell-begin-tex-skip-regexp) "\\|"
2129 skip-regexp)))
2130 skip-regexp))
2133 (defun ispell-begin-tex-skip-regexp ()
2134 "Regular expression of tex commands to skip.
2135 Generated from `ispell-tex-skip-alists'."
2136 (concat
2137 (mapconcat (function (lambda (lst) (car lst)))
2138 (car ispell-tex-skip-alists)
2139 "\\|")
2140 "\\|"
2141 (mapconcat (function (lambda (lst)
2142 (concat "\\\\begin[ \t\n]*{[ \t\n]*"
2143 (car lst)
2144 "[ \t\n]*}")))
2145 (car (cdr ispell-tex-skip-alists))
2146 "\\|")))
2149 (defun ispell-begin-skip-region ()
2150 "Regular expression of regions to skip for all buffers.
2151 Each selection should be a key of `ispell-skip-region-alist';
2152 otherwise, the current line is skipped."
2153 (mapconcat (function (lambda (lst) (if (stringp (car lst)) (car lst)
2154 (eval (car lst)))))
2155 ispell-skip-region-alist
2156 "\\|"))
2159 (defun ispell-tex-arg-end (&optional arg)
2160 (condition-case nil
2161 (progn
2162 (while (looking-at "[ \t\n]*\\[") (forward-sexp))
2163 (forward-sexp (or arg 1)))
2164 (error
2165 (message "error skipping s-expressions at point %d." (point))
2166 (beep)
2167 (sit-for 2))))
2170 ;;; Skips to region-end from point, or a single line.
2171 ;;; Places point at end of region skipped.
2172 (defun ispell-skip-region (key alist)
2173 ;; move over key to begin checking.
2174 (forward-char (length key))
2175 (let ((start (point))
2176 alist-key null-skip)
2177 (cond
2178 ;; what about quoted comment, or comment inside strings?
2179 ((and (null ispell-check-comments) comment-start
2180 (string= key comment-start))
2181 (if (string= "" comment-end)
2182 (forward-line)
2183 (search-forward comment-end ispell-region-end t)))
2184 ((and (eq 'exclusive ispell-check-comments) comment-start
2185 (string= key comment-end))
2186 (search-forward comment-start ispell-region-end :end))
2187 ((and ispell-skip-tib (string-match ispell-tib-ref-beginning key))
2188 (re-search-forward ispell-tib-ref-end ispell-region-end t))
2189 ((and ispell-skip-sgml (string-match "<author>" key))
2190 (search-forward-regexp ".$" ispell-region-end t))
2191 ((and ispell-skip-sgml (string-match "</" key))
2192 (search-forward ">" ispell-region-end t))
2193 ((and ispell-skip-sgml (string-match "<[cC][oO][dD][eE]>" key))
2194 (search-forward-regexp "</[cC][oO][dD][eE]>" ispell-region-end t))
2195 ((and ispell-skip-sgml (string-match "<[vV][eE][rR][bB]>" key))
2196 (search-forward-regexp "</[vV][eE][rR][bB]>" ispell-region-end t))
2197 ((and ispell-skip-sgml (string-match "<[tT][tT]>" key))
2198 (search-forward-regexp "</[tT][tT]>" ispell-region-end t))
2199 ((and ispell-skip-sgml (string-match "<[tT][tT]/" key))
2200 (search-forward "/" ispell-region-end t))
2201 ((and ispell-skip-sgml (string-match "<" key))
2202 (search-forward-regexp "[/>]" ispell-region-end t))
2203 ((and ispell-skip-sgml (string-match "&" key))
2204 (search-forward ";" ispell-region-end t))
2205 ;; markings from alist
2207 (while alist
2208 (setq alist-key (eval (car (car alist))))
2209 (if (string-match alist-key key)
2210 (progn
2211 (setq alist (cdr (car alist)))
2212 (cond
2213 ((null alist) (setq null-skip t)) ; done! Just skip key.
2214 ((not (consp alist))
2215 ;; Search past end of spell region to find this region end.
2216 (re-search-forward (eval alist) (point-max) t))
2217 ((consp alist)
2218 (if (stringp alist)
2219 (re-search-forward alist (point-max) t)
2220 (setq null-skip t) ; error handling in functions!
2221 (if (consp (cdr alist))
2222 (apply (car alist) (cdr alist))
2223 (funcall (car alist))))))
2224 (setq alist nil))
2225 (setq alist (cdr alist))))))
2226 (if (and (= start (point)) (null null-skip))
2227 (progn
2228 (message "Matching region end for `%s' point %d not found"
2229 key (point))
2230 (beep)
2231 (sit-for 2)))))
2234 ;;; Grab the next line of data.
2235 ;;; Returns a string with the line data
2236 (defun ispell-get-line (start end reg-end)
2237 (let ((ispell-casechars (ispell-get-casechars))
2238 string)
2239 (cond ; LOOK AT THIS LINE AND SKIP OR PROCESS
2240 ((eolp) ; END OF LINE, just go to next line.
2241 (forward-line))
2242 ;;((looking-at "[---#@*+!%~^]") ; SKIP SPECIAL ISPELL CHARACTERS
2243 ;; (forward-char 1)) ; not needed as quoted below.
2244 ((or (re-search-forward ispell-casechars end t) ; TEXT EXISTS
2245 (re-search-forward "[][()${}]" end t)) ; or MATH COMMANDS
2246 (setq string (concat "^" (buffer-substring-no-properties start end)
2247 "\n"))
2248 (goto-char end))
2249 (t (goto-char end))) ; EMPTY LINE, skip it.
2250 string))
2253 (defun ispell-process-line (string)
2254 ;;(declare special start end)
2255 (let (poss
2256 ;; line-offset is the change so far in the size of the line.
2257 ;; The position values we get from ispell reflect the original
2258 ;; text, and correction of previous words may have shifted the
2259 ;; current word within the line.
2260 (line-offset 0))
2261 ;; send string to spell process and get input.
2262 (process-send-string ispell-process string)
2263 (while (progn
2264 (accept-process-output ispell-process)
2265 ;; Last item of output contains a blank line.
2266 (not (string= "" (car ispell-filter)))))
2267 ;; parse all inputs from the stream one word at a time.
2268 ;; Place in FIFO order and remove the blank item.
2269 (setq ispell-filter (nreverse (cdr ispell-filter)))
2270 (while (and (not ispell-quit) ispell-filter)
2271 (setq poss (ispell-parse-output (car ispell-filter)))
2272 (if (and poss (listp poss)) ; spelling error occurred.
2273 ;; Whenever we have misspellings, we can change
2274 ;; the buffer. Keep boundaries as markers.
2275 ;; Markers can move with highlighting! This destroys
2276 ;; end of region markers line-end and ispell-region-end
2277 (let ((word-start
2278 (copy-marker (+ start ispell-offset line-offset
2279 (car (cdr poss)))))
2280 (word-len (length (car poss)))
2281 (line-end (copy-marker end))
2282 (line-start (copy-marker start))
2283 recheck-region replace)
2284 (goto-char word-start)
2285 ;; Adjust the horizontal scroll & point
2286 (ispell-horiz-scroll)
2287 (goto-char (+ word-len word-start))
2288 (ispell-horiz-scroll)
2289 (goto-char word-start)
2290 (ispell-horiz-scroll)
2291 (if (/= (+ word-len (point))
2292 (progn
2293 (search-forward (car poss) (+ word-len (point)) t)
2294 (point)))
2295 ;; This occurs due to filter pipe problems
2296 (error (concat "Ispell misalignment: word "
2297 "`%s' point %d; probably incompatible versions")
2298 (car poss) (marker-position word-start)))
2300 ;; ispell-cmd-loop can go recursive & change buffer
2301 (if ispell-keep-choices-win
2302 (setq replace (ispell-command-loop
2303 (car (cdr (cdr poss)))
2304 (car (cdr (cdr (cdr poss))))
2305 (car poss) (marker-position word-start)
2306 (+ word-len (marker-position word-start))))
2307 (save-window-excursion
2308 (setq replace (ispell-command-loop
2309 (car (cdr (cdr poss)))
2310 (car (cdr (cdr (cdr poss))))
2311 (car poss) (marker-position word-start)
2312 (+ word-len (marker-position word-start))))))
2314 ;; Recheck when recursive edit changes misspelled word
2315 (goto-char word-start)
2316 (if (not (string-equal (buffer-substring-no-properties
2317 (point) (+ word-len (point)))
2318 (car poss)))
2319 (progn
2320 (set-marker line-end (point))
2321 (setq ispell-filter nil
2322 recheck-region t)))
2324 (cond
2325 ((and replace (listp replace))
2326 ;; REPLACEMENT WORD
2327 ;; Recheck line starting with the replacement word.
2328 (setq ispell-filter nil
2329 recheck-region t)
2330 (delete-region (point) (+ word-len (point)))
2331 (insert (car replace))
2332 (setq line-offset (+ line-offset (- line-end end)))
2333 ;; Only typed-in replacements need to be re-checked.
2334 (if (not (eq 'query-replace (car (cdr replace))))
2335 (backward-char (length (car replace))))
2336 (set-marker line-end (point)) ; continue checking from here.
2337 (if (car (cdr replace))
2338 (unwind-protect
2339 (save-window-excursion
2340 (delete-other-windows) ; to correctly show help.
2341 ;; Assume case-replace &
2342 ;; case-fold-search correct?
2343 (query-replace (car poss) (car replace) t))
2344 (goto-char word-start))))
2345 ((or (null replace)
2346 (equal 0 replace)) ; ACCEPT/INSERT
2347 (if (equal 0 replace) ; BUFFER-LOCAL DICT ADD
2348 (ispell-add-per-file-word-list (car poss)))
2349 ;; This avoids pointing out the word that was
2350 ;; just accepted (via 'i' or 'a') if it follows
2351 ;; on the same line.
2352 ;; Redo check following the accepted word.
2353 (if (and ispell-pdict-modified-p
2354 (listp ispell-pdict-modified-p))
2355 ;; Word accepted. Recheck line.
2356 (progn
2357 (setq ispell-pdict-modified-p ;update flag
2358 (car ispell-pdict-modified-p)
2359 ispell-filter nil
2360 recheck-region t)
2361 (set-marker line-end (marker-position word-start)))))
2362 (replace ; STRING REPLACEMENT for this word.
2363 (delete-region (point) (+ word-len (point)))
2364 (insert replace)
2365 (setq line-offset (+ line-offset (- line-end end)))
2367 (set-marker line-start (+ line-start
2368 (- (length replace)
2369 (length (car poss)))))))
2370 (if (not ispell-quit)
2371 (let (message-log-max)
2372 (message "Continuing spelling check using %s dictionary..."
2373 (or ispell-dictionary "default"))))
2374 (sit-for 0)
2375 (setq start (marker-position line-start)
2376 end (marker-position line-end))
2377 ;; Adjust markers when end of region lost from highlighting.
2378 (if (and (not recheck-region) (< end (+ word-start word-len)))
2379 (setq end (+ word-start word-len)))
2380 (if (= word-start ispell-region-end)
2381 (set-marker ispell-region-end (+ word-start word-len)))
2382 ;; going out of scope - unneeded
2383 (set-marker line-start nil)
2384 (set-marker word-start nil)
2385 (set-marker line-end nil)))
2386 ;; finished with misspelling!
2387 (setq ispell-filter (cdr ispell-filter)))))
2390 ;;;###autoload
2391 (defun ispell-comments-and-strings ()
2392 "Check comments and strings in the current buffer for spelling errors."
2393 (interactive)
2394 (goto-char (point-min))
2395 (let (state done)
2396 (while (not done)
2397 (setq done t)
2398 (setq state (parse-partial-sexp (point) (point-max)
2399 nil nil state 'syntax-table))
2400 (if (or (nth 3 state) (nth 4 state))
2401 (let ((start (point)))
2402 (setq state (parse-partial-sexp start (point-max)
2403 nil nil state 'syntax-table))
2404 (if (or (nth 3 state) (nth 4 state))
2405 (error "Unterminated string or comment"))
2406 (save-excursion
2407 (setq done (not (ispell-region start (point))))))))))
2410 ;;;###autoload
2411 (defun ispell-buffer ()
2412 "Check the current buffer for spelling errors interactively."
2413 (interactive)
2414 (ispell-region (point-min) (point-max)))
2417 ;;;###autoload
2418 (defun ispell-continue ()
2419 "Continue a halted spelling session beginning with the current word."
2420 (interactive)
2421 (if (not (marker-position ispell-region-end))
2422 (message "No session to continue. Use 'X' command when checking!")
2423 (if (not (equal (marker-buffer ispell-region-end) (current-buffer)))
2424 (message "Must continue ispell from buffer %s"
2425 (buffer-name (marker-buffer ispell-region-end)))
2426 (ispell-region
2427 ;; find beginning of current word:
2428 (car (cdr (ispell-get-word t)))
2429 (marker-position ispell-region-end)))))
2432 ;;; Horizontal scrolling
2433 (defun ispell-horiz-scroll ()
2434 "Places point within the horizontal visibility of its window area."
2435 (if truncate-lines ; display truncating lines?
2436 ;; See if display needs to be scrolled.
2437 (let ((column (- (current-column) (max (window-hscroll) 1))))
2438 (if (and (< column 0) (> (window-hscroll) 0))
2439 (scroll-right (max (- column) 10))
2440 (if (>= column (- (window-width) 2))
2441 (scroll-left (max (- column (window-width) -3) 10)))))))
2444 ;;; Interactive word completion.
2445 ;;; Forces "previous-word" processing. Do we want to make this selectable?
2447 ;;;###autoload
2448 (defun ispell-complete-word (&optional interior-frag)
2449 "Try to complete the word before or under point (see `lookup-words')
2450 If optional INTERIOR-FRAG is non-nil then the word may be a character
2451 sequence inside of a word.
2453 Standard ispell choices are then available."
2454 (interactive "P")
2455 (let ((cursor-location (point))
2456 (case-fold-search-val case-fold-search)
2457 (word (ispell-get-word nil "\\*")) ; force "previous-word" processing.
2458 start end possibilities replacement)
2459 (setq start (car (cdr word))
2460 end (car (cdr (cdr word)))
2461 word (car word)
2462 possibilities
2463 (or (string= word "") ; Will give you every word
2464 (lookup-words (concat (and interior-frag "*") word
2465 (if (or interior-frag (null ispell-look-p))
2466 "*"))
2467 ispell-complete-word-dict)))
2468 (cond ((eq possibilities t)
2469 (message "No word to complete"))
2470 ((null possibilities)
2471 (message "No match for \"%s\"" word))
2472 (t ; There is a modification...
2473 (setq case-fold-search nil) ; Try and respect case of word.
2474 (cond
2475 ((string-equal (upcase word) word)
2476 (setq possibilities (mapcar 'upcase possibilities)))
2477 ((string-equal (upcase (substring word 0 1)) (substring word 0 1))
2478 (setq possibilities (mapcar (function
2479 (lambda (pos)
2480 (if (string-equal
2481 (substring word 0 1)
2482 (substring pos 0 1))
2484 (capitalize pos))))
2485 possibilities))))
2486 (setq case-fold-search case-fold-search-val)
2487 (save-window-excursion
2488 (setq replacement
2489 (ispell-command-loop possibilities nil word start end)))
2490 (cond
2491 ((equal 0 replacement) ; BUFFER-LOCAL ADDITION
2492 (ispell-add-per-file-word-list word))
2493 (replacement ; REPLACEMENT WORD
2494 (delete-region start end)
2495 (setq word (if (atom replacement) replacement (car replacement))
2496 cursor-location (+ (- (length word) (- end start))
2497 cursor-location))
2498 (insert word)
2499 (if (not (atom replacement)) ; recheck spelling of replacement.
2500 (progn
2501 (goto-char cursor-location)
2502 (ispell-word nil t)))))
2503 (if (get-buffer ispell-choices-buffer)
2504 (kill-buffer ispell-choices-buffer))))
2505 (ispell-pdict-save ispell-silently-savep)
2506 (goto-char cursor-location)))
2509 ;;;###autoload
2510 (defun ispell-complete-word-interior-frag ()
2511 "Completes word matching character sequence inside a word."
2512 (interactive)
2513 (ispell-complete-word t))
2516 ;;; **********************************************************************
2517 ;;; Ispell Minor Mode
2518 ;;; **********************************************************************
2520 (defvar ispell-minor-mode nil
2521 "Non-nil if Ispell minor mode is enabled.")
2522 ;; Variable indicating that ispell minor mode is active.
2523 (make-variable-buffer-local 'ispell-minor-mode)
2525 (or (assq 'ispell-minor-mode minor-mode-alist)
2526 (setq minor-mode-alist
2527 (cons '(ispell-minor-mode " Spell") minor-mode-alist)))
2529 (defvar ispell-minor-keymap
2530 (let ((map (make-sparse-keymap)))
2531 (define-key map " " 'ispell-minor-check)
2532 (define-key map "\r" 'ispell-minor-check)
2533 map)
2534 "Keymap used for Ispell minor mode.")
2536 (or (not (boundp 'minor-mode-map-alist))
2537 (assoc 'ispell-minor-mode minor-mode-map-alist)
2538 (setq minor-mode-map-alist
2539 (cons (cons 'ispell-minor-mode ispell-minor-keymap)
2540 minor-mode-map-alist)))
2542 ;;;###autoload
2543 (defun ispell-minor-mode (&optional arg)
2544 "Toggle Ispell minor mode.
2545 With prefix arg, turn Ispell minor mode on iff arg is positive.
2547 In Ispell minor mode, pressing SPC or RET
2548 warns you if the previous word is incorrectly spelled.
2550 All the buffer-local variables and dictionaries are ignored -- to read
2551 them into the running ispell process, type \\[ispell-word] SPC."
2552 (interactive "P")
2553 (setq ispell-minor-mode
2554 (not (or (and (null arg) ispell-minor-mode)
2555 (<= (prefix-numeric-value arg) 0))))
2556 (force-mode-line-update))
2558 (defun ispell-minor-check ()
2559 "Check previous word then continue with the normal binding of this key.
2560 Don't check previous word when character before point is a space or newline.
2561 Don't read buffer-local settings or word lists."
2562 (interactive "*")
2563 (let ((ispell-minor-mode nil)
2564 (ispell-check-only t)
2565 (last-char (char-after (1- (point)))))
2566 (command-execute (key-binding (this-command-keys)))
2567 (if (not (or (eq last-char ?\ ) (eq last-char ?\n)
2568 (and ispell-skip-sgml (eq last-char ?>))
2569 (and ispell-skip-sgml (eq last-char ?\;))))
2570 (ispell-word nil t))))
2573 ;;; **********************************************************************
2574 ;;; Ispell Message
2575 ;;; **********************************************************************
2576 ;;; Original from D. Quinlan, E. Bradford, A. Albert, and M. Ernst
2579 (defvar ispell-message-text-end
2580 (mapconcat (function identity)
2582 ;; Don't spell check signatures
2583 "^-- $"
2584 ;; Matches postscript files.
2585 "^%!PS-Adobe-[123].0"
2586 ;; Matches uuencoded text
2587 "^begin [0-9][0-9][0-9] .*\nM.*\nM.*\nM"
2588 ;; Matches shell files (especially auto-decoding)
2589 "^#! /bin/[ck]?sh"
2590 ;; Matches context difference listing
2591 "\\(\\(^cd .*\n\\)?diff -c .*\\)?\n\\*\\*\\* .*\n--- .*\n\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*"
2592 ;; Matches unidiff difference listing
2593 "\\(diff -u .*\\)?\n--- .*\n\\+\\+\\+ .*\n@@ [-+][0-9]+,[0-9]+ [-+][0-9]+,[0-9]+ @@\n"
2594 ;; Matches reporter.el bug report
2595 "^current state:\n==============\n"
2596 ;; Matches commonly used "cut" boundaries
2597 "^\\(- \\)?[-=_]+\\s ?\\(cut here\\|Environment Follows\\)")
2598 "\\|")
2599 "*End of text which will be checked in `ispell-message'.
2600 If it is a string, limit at first occurrence of that regular expression.
2601 Otherwise, it must be a function which is called to get the limit.")
2605 ;;;###autoload
2606 (defun ispell-message ()
2607 "Check the spelling of a mail message or news post.
2608 Don't check spelling of message headers except the Subject field.
2609 Don't check included messages.
2611 To abort spell checking of a message region and send the message anyway,
2612 use the `x' command. (Any subsequent regions will be checked.)
2613 The `X' command aborts the message send so that you can edit the buffer.
2615 To spell-check whenever a message is sent, include the appropriate lines
2616 in your .emacs file:
2617 (add-hook 'message-send-hook 'ispell-message) ;; GNUS 5
2618 (add-hook 'news-inews-hook 'ispell-message) ;; GNUS 4
2619 (add-hook 'mail-send-hook 'ispell-message)
2620 (add-hook 'mh-before-send-letter-hook 'ispell-message)
2622 You can bind this to the key C-c i in GNUS or mail by adding to
2623 `news-reply-mode-hook' or `mail-mode-hook' the following lambda expression:
2624 (function (lambda () (local-set-key \"\\C-ci\" 'ispell-message)))"
2625 (interactive)
2626 (save-excursion
2627 (goto-char (point-min))
2628 (let* (
2629 ;; Nil when message came from outside (eg calling emacs as editor)
2630 ;; Non-nil marker of end of headers.
2631 (internal-messagep
2632 (re-search-forward
2633 (concat "^" (regexp-quote mail-header-separator) "$") nil t))
2634 (end-of-headers ; Start of body.
2635 (copy-marker
2636 (or internal-messagep
2637 (re-search-forward "^$" nil t)
2638 (point-min))))
2639 (limit (copy-marker ; End of region we will spell check.
2640 (cond
2641 ((not ispell-message-text-end) (point-max))
2642 ((char-or-string-p ispell-message-text-end)
2643 (if (re-search-forward ispell-message-text-end nil t)
2644 (match-beginning 0)
2645 (point-max)))
2646 (t (min (point-max) (funcall ispell-message-text-end))))))
2647 (default-prefix ; Vanilla cite prefix (just used for cite-regexp)
2648 (if (and (boundp 'mail-yank-prefix) mail-yank-prefix)
2649 (ispell-non-empty-string mail-yank-prefix)
2650 " \\|\t"))
2651 (cite-regexp ;Prefix of quoted text
2652 (cond
2653 ((featurep 'supercite) ; sc 3.0
2654 (concat "\\(" (sc-cite-regexp) "\\)" "\\|"
2655 (ispell-non-empty-string sc-reference-tag-string)))
2656 ((featurep 'sc) ; sc 2.3
2657 (concat "\\(" sc-cite-regexp "\\)" "\\|"
2658 (ispell-non-empty-string sc-reference-tag-string)))
2659 ((or (equal major-mode 'news-reply-mode) ;GNUS 4 & below
2660 (equal major-mode 'message-mode)) ;GNUS 5
2661 (concat "In article <" "\\|"
2662 "[^,;&+=\n]+ <[^,;&+=]+> writes:" "\\|"
2663 message-yank-prefix "\\|"
2664 default-prefix))
2665 ((equal major-mode 'mh-letter-mode) ; mh mail message
2666 (concat "[^,;&+=\n]+ writes:" "\\|"
2667 (ispell-non-empty-string mh-ins-buf-prefix)))
2668 ((not internal-messagep) ; Assume nn sent us this message.
2669 (concat "In [a-zA-Z.]+ you write:" "\\|"
2670 "In <[^,;&+=]+> [^,;&+=]+ writes:" "\\|"
2671 " *> *"))
2672 ((boundp 'vm-included-text-prefix) ; VM mail message
2673 (concat "[^,;&+=\n]+ writes:" "\\|"
2674 (ispell-non-empty-string vm-included-text-prefix)))
2675 (t default-prefix)))
2676 (ispell-skip-region-alist
2677 (cons (list (concat "^\\(" cite-regexp "\\)")
2678 (function forward-line))
2679 ispell-skip-region-alist))
2680 (old-case-fold-search case-fold-search)
2681 (dictionary-alist ispell-message-dictionary-alist)
2682 (ispell-checking-message t))
2684 ;; Select dictionary for message
2685 (or (local-variable-p 'ispell-local-dictionary (current-buffer))
2686 (while dictionary-alist
2687 (goto-char (point-min))
2688 (if (re-search-forward (car (car dictionary-alist))
2689 end-of-headers t)
2690 (setq ispell-local-dictionary (cdr (car dictionary-alist))
2691 dictionary-alist nil)
2692 (setq dictionary-alist (cdr dictionary-alist)))))
2694 (unwind-protect
2695 (progn
2696 ;; Spell check any original Subject:
2697 (goto-char (point-min))
2698 (setq case-fold-search t)
2699 (if (re-search-forward "^Subject: *" end-of-headers t)
2700 (progn
2701 (goto-char (match-end 0))
2702 (if (and (not (looking-at ".*Re\\>"))
2703 (not (looking-at "\\[")))
2704 (progn
2705 (setq case-fold-search old-case-fold-search)
2706 (ispell-region (point)
2707 (progn ;Tab-initiated continuation lns.
2708 (end-of-line)
2709 (while (looking-at "\n[ \t]")
2710 (end-of-line 2))
2711 (point)))))))
2712 (setq case-fold-search old-case-fold-search)
2713 (goto-char end-of-headers)
2714 (forward-line 1)
2715 (ispell-region (point) limit))
2716 (set-marker end-of-headers nil)
2717 (set-marker limit nil)))))
2720 (defun ispell-non-empty-string (string)
2721 (if (or (not string) (string-equal string ""))
2722 "\\'\\`" ; An unmatchable string if string is null.
2723 (regexp-quote string)))
2726 ;;; **********************************************************************
2727 ;;; Buffer Local Functions
2728 ;;; **********************************************************************
2731 (defun ispell-accept-buffer-local-defs ()
2732 "Load all buffer-local information, restarting Ispell when necessary."
2733 (ispell-buffer-local-dict) ; May kill ispell-process.
2734 (ispell-buffer-local-words) ; Will initialize ispell-process.
2735 (ispell-buffer-local-parsing))
2738 (defun ispell-buffer-local-parsing ()
2739 "Place Ispell into parsing mode for this buffer.
2740 Overrides the default parsing mode.
2741 Includes Latex/Nroff modes and extended character mode."
2742 ;; (ispell-init-process) must already be called.
2743 (process-send-string ispell-process "!\n") ; Put process in terse mode.
2744 ;; We assume all major modes with "tex-mode" in them should use latex parsing
2745 ;; When exclusively checking comments, set to raw text mode (nroff).
2746 (if (and (not (eq 'exclusive ispell-check-comments))
2747 (or (and (eq ispell-parser 'use-mode-name)
2748 (string-match "[Tt][Ee][Xx]-mode"
2749 (symbol-name major-mode)))
2750 (eq ispell-parser 'tex)))
2751 (progn
2752 (process-send-string ispell-process "+\n") ; set ispell mode to tex
2753 (if (not (eq ispell-parser 'tex))
2754 (set (make-local-variable 'ispell-parser) 'tex)))
2755 (process-send-string ispell-process "-\n")) ; set mode to normal (nroff)
2756 ;; If needed, test for SGML & HTML modes and set a buffer local nil/t value.
2757 (if (and ispell-skip-sgml (not (eq ispell-skip-sgml t)))
2758 (set (make-local-variable 'ispell-skip-sgml)
2759 (not (null (string-match "sgml\\|html"
2760 (downcase (symbol-name major-mode)))))))
2761 ;; Set default extended character mode for given buffer, if any.
2762 (let ((extended-char-mode (ispell-get-extended-character-mode)))
2763 (if extended-char-mode
2764 (process-send-string ispell-process (concat extended-char-mode "\n"))))
2765 ;; Set buffer-local parsing mode and extended character mode, if specified.
2766 (save-excursion
2767 (goto-char (point-max))
2768 ;; Uses last occurrence of ispell-parsing-keyword
2769 (if (search-backward ispell-parsing-keyword nil t)
2770 (let ((end (save-excursion (end-of-line) (point)))
2771 string)
2772 (search-forward ispell-parsing-keyword)
2773 (while (re-search-forward " *\\([^ \"]+\\)" end t)
2774 ;; space separated definitions.
2775 (setq string (downcase (buffer-substring-no-properties
2776 (match-beginning 1) (match-end 1))))
2777 (cond ((and (string-match "latex-mode" string)
2778 (not (eq 'exclusive ispell-check-comments)))
2779 (process-send-string ispell-process "+\n~tex\n"))
2780 ((string-match "nroff-mode" string)
2781 (process-send-string ispell-process "-\n~nroff\n"))
2782 ((string-match "~" string) ; Set extended character mode.
2783 (process-send-string ispell-process (concat string "\n")))
2784 (t (message "Invalid Ispell Parsing argument!")
2785 (sit-for 2))))))))
2788 ;;; Can kill the current ispell process
2790 (defun ispell-buffer-local-dict ()
2791 "Initializes local dictionary and local personal dictionary.
2792 When a dictionary is defined in the buffer (see variable
2793 `ispell-dictionary-keyword'), it will override the local setting
2794 from \\[ispell-change-dictionary].
2795 Both should not be used to define a buffer-local dictionary."
2796 (save-excursion
2797 (goto-char (point-min))
2798 (let (end)
2799 ;; Override the local variable definition.
2800 ;; Uses last occurrence of ispell-dictionary-keyword.
2801 (goto-char (point-max))
2802 (if (search-backward ispell-dictionary-keyword nil t)
2803 (progn
2804 (search-forward ispell-dictionary-keyword)
2805 (setq end (save-excursion (end-of-line) (point)))
2806 (if (re-search-forward " *\\([^ \"]+\\)" end t)
2807 (setq ispell-local-dictionary
2808 (buffer-substring-no-properties (match-beginning 1)
2809 (match-end 1))))))
2810 (goto-char (point-max))
2811 (if (search-backward ispell-pdict-keyword nil t)
2812 (progn
2813 (search-forward ispell-pdict-keyword)
2814 (setq end (save-excursion (end-of-line) (point)))
2815 (if (re-search-forward " *\\([^ \"]+\\)" end t)
2816 (setq ispell-local-pdict
2817 (buffer-substring-no-properties (match-beginning 1)
2818 (match-end 1))))))))
2819 ;; Reload if new personal dictionary defined.
2820 (if (and ispell-local-pdict
2821 (not (equal ispell-local-pdict ispell-personal-dictionary)))
2822 (progn
2823 (ispell-kill-ispell t)
2824 (setq ispell-personal-dictionary ispell-local-pdict)))
2825 ;; Reload if new dictionary defined.
2826 (if (and ispell-local-dictionary
2827 (not (equal ispell-local-dictionary ispell-dictionary)))
2828 (ispell-change-dictionary ispell-local-dictionary)))
2831 (defun ispell-buffer-local-words ()
2832 "Loads the buffer-local dictionary in the current buffer."
2833 (if (and ispell-buffer-local-name
2834 (not (equal ispell-buffer-local-name (buffer-name))))
2835 (progn
2836 (ispell-kill-ispell t)
2837 (setq ispell-buffer-local-name nil)))
2838 (ispell-init-process)
2839 (save-excursion
2840 (goto-char (point-min))
2841 (while (search-forward ispell-words-keyword nil t)
2842 (or ispell-buffer-local-name
2843 (setq ispell-buffer-local-name (buffer-name)))
2844 (let ((end (save-excursion (end-of-line) (point)))
2845 (ispell-casechars (ispell-get-casechars))
2846 string)
2847 ;; buffer-local words separated by a space, and can contain
2848 ;; any character other than a space. Not rigorous enough.
2849 (while (re-search-forward " *\\([^ ]+\\)" end t)
2850 (setq string (buffer-substring-no-properties (match-beginning 1)
2851 (match-end 1)))
2852 ;; This can fail when string contains a word with illegal chars.
2853 ;; Error handling needs to be added between ispell and emacs.
2854 (if (and (< 1 (length string))
2855 (equal 0 (string-match ispell-casechars string)))
2856 (process-send-string ispell-process
2857 (concat "@" string "\n"))))))))
2860 ;;; returns optionally adjusted region-end-point.
2862 (defun ispell-add-per-file-word-list (word)
2863 "Add WORD to the per-file word list."
2864 (or ispell-buffer-local-name
2865 (setq ispell-buffer-local-name (buffer-name)))
2866 (save-excursion
2867 (goto-char (point-min))
2868 (let ((old-case-fold-search case-fold-search)
2869 line-okay search done string)
2870 (while (not done)
2871 (setq case-fold-search nil
2872 search (search-forward ispell-words-keyword nil 'move)
2873 line-okay (< (+ (length word) 1 ; 1 for space after word..
2874 (progn (end-of-line) (current-column)))
2876 case-fold-search old-case-fold-search)
2877 (if (or (and search line-okay)
2878 (null search))
2879 (progn
2880 (setq done t)
2881 (if (null search)
2882 (progn
2883 (open-line 1)
2884 (setq string (concat comment-start " "
2885 ispell-words-keyword))
2886 (insert string)
2887 (if (and comment-end (not (equal "" comment-end)))
2888 (save-excursion
2889 (open-line 1)
2890 (forward-line 1)
2891 (insert comment-end)))))
2892 (insert (concat " " word))))))))
2895 (defconst ispell-version "ispell.el 3.2 -- Fri May 7 14:25:14 PDT 1999")
2897 (provide 'ispell)
2900 ;;; LOCAL VARIABLES AND BUFFER-LOCAL VALUE EXAMPLES.
2902 ;;; Local Variable options:
2903 ;;; mode: name(-mode)
2904 ;;; eval: expression
2905 ;;; local-variable: value
2907 ;;; The following sets the buffer local dictionary to `american' English
2908 ;;; and spell checks only comments.
2910 ;;; Local Variables:
2911 ;;; mode: emacs-lisp
2912 ;;; comment-column: 40
2913 ;;; ispell-check-comments: exclusive
2914 ;;; Local IspellDict: "american"
2915 ;;; End:
2918 ;;; MORE EXAMPLES OF ISPELL BUFFER-LOCAL VALUES
2920 ;;; The following places this file in nroff parsing and extended char modes.
2921 ;;; Local IspellParsing: nroff-mode ~nroff
2922 ;;; Change IspellPersDict to IspellPersDict: to enable the following line.
2923 ;;; Local IspellPersDict ~/.ispell_lisp
2924 ;;; The following were automatically generated by ispell using the 'A' command:
2925 ; LocalWords: settable alist inews mh frag pdict Wildcards iconify arg tex kss
2926 ; LocalWords: alists minibuffer bufferp autoload loaddefs aff Dansk KOI SPC op
2927 ; LocalWords: Francais Nederlands charset autoloaded popup nonmenu regexp num
2928 ; LocalWords: AMStex hspace includeonly nocite epsfig displaymath eqnarray reg
2929 ; LocalWords: minipage modeline pers dict unhighlight buf grep sync prev inc
2930 ; LocalWords: fn hilight oldot NB AIX msg init read's bufs pt cmd Quinlan eg
2931 ; LocalWords: uuencoded unidiff sc nn VM SGML eval IspellPersDict unsplitable
2932 ; LocalWords: lns
2934 ;;; ispell.el ends here