1 ;;; ispell.el --- Interface to International Ispell Version 3.1
3 ;; Copyright (C) 1994, 1995, 1997, 1998 Free Software Foundation, Inc.
5 ;; Authors : Ken Stevens <k.stevens@ieee.org>
6 ;; Stevens Mod Date: Tue Apr 28 14:40:01 PDT 1998
7 ;; Stevens Revision: 3.0
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)
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.
36 ;; This code contains a section of user-settable variables that you should
37 ;; inspect prior to installation. Look past the end of the history list.
38 ;; Set them up for your locale and the preferences of the majority of the
39 ;; users. Otherwise the users may need to set a number of variables
41 ;; You particularly may want to change the default dictionary for your
42 ;; country and language.
44 ;; Depending on the mail system you use, you may want to include these:
46 ;; (add-hook 'news-inews-hook 'ispell-message)
47 ;; (add-hook 'mail-send-hook 'ispell-message)
48 ;; (add-hook 'mh-before-send-letter-hook 'ispell-message)
51 ;; Ispell has a TeX parser and a nroff parser (the default).
52 ;; The parsing is controlled by the variable ispell-parser. Currently
53 ;; it is just a "toggle" between TeX and nroff, but if more parsers are
54 ;; added it will be updated. See the variable description for more info.
63 ;; ispell-comments-and-strings
65 ;; ispell-complete-word
66 ;; ispell-complete-word-interior-frag
67 ;; ispell-change-dictionary
70 ;; ispell-skip-region-alist
72 ;; Commands in ispell-region:
73 ;; Character replacement: Replace word with choice. May query-replace.
74 ;; ` ': Accept word this time.
75 ;; `i': Accept word and insert into private dictionary.
76 ;; `a': Accept word for this session.
77 ;; `A': Accept word and place in buffer-local dictionary.
78 ;; `r': Replace word with typed-in value. Rechecked.
79 ;; `R': Replace word with typed-in value. Query-replaced in buffer. Rechecked.
80 ;; `?': Show these commands
81 ;; `x': Exit spelling buffer. Move cursor to original point.
82 ;; `X': Exit spelling buffer. Leaves cursor at the current point, and permits
83 ;; the check to be completed later.
84 ;; `q': Quit spelling session (Kills ispell process).
85 ;; `l': Look up typed-in replacement in alternate dictionary. Wildcards okay.
86 ;; `u': Like `i', but the word is lower-cased first.
87 ;; `m': Place entered value in personal dictionary, then recheck current word.
88 ;; `C-l': redraws screen
89 ;; `C-r': recursive edit
90 ;; `C-z': suspend emacs or iconify frame
92 ;; Buffer-Local features:
93 ;; There are a number of buffer-local features that can be used to customize
94 ;; ispell for the current buffer. This includes language dictionaries,
95 ;; personal dictionaries, parsing, and local word spellings. Each of these
96 ;; local customizations are done either through local variables, or by
97 ;; including the keyword and argument(s) at the end of the buffer (usually
98 ;; prefixed by the comment characters). See the end of this file for
99 ;; examples. The local keywords and variables are:
101 ;; ispell-dictionary-keyword language-dictionary
102 ;; uses local variable ispell-local-dictionary
103 ;; ispell-pdict-keyword personal-dictionary
104 ;; uses local variable ispell-local-pdict
105 ;; ispell-parsing-keyword mode-arg extended-char-arg
106 ;; ispell-words-keyword any number of local word spellings
109 ;; Place new regular expression definitions of regions you prefer not to
110 ;; spell check in `ispell-skip-region-alist'. Mode-dependent features can
111 ;; be added to latex by modifying `ispell-tex-skip-alists'.
112 ;; `ispell-message' contains some custom skipping code for e-mail messages.
115 ;; Highlighting in version 19 still doesn't work on tty's.
116 ;; On some versions of emacs, growing the minibuffer fails.
117 ;; Autoloading ispell can result in problems if you need to use a local or
118 ;; modified dictionary. Place the following in your .emacs file to
119 ;; override the autoload definitions:
120 ;; (setq ispell-dictionary-alist (cons '(dictionary ...)
121 ;; ispell-dictionary-alist))
122 ;; (setq ispell-menu-map nil)
123 ;; (load-library "ispell")
127 ;;; Custom.el macros require recompiling this when they are not present.
128 ;;; Add in backward compatible custom support.
130 (if (not (fboundp 'defcustom
))
131 (defmacro defcustom
(symbol value doc
&rest args
)
132 "Empty replacement for defcustom when not supplied."
133 `(defvar ,symbol
,value
,doc
))))
136 (if (fboundp 'defgroup
)
138 "User variables for emacs ispell interface."
139 :group
'applications
)))
142 ;;; **********************************************************************
143 ;;; The following variables should be set according to personal preference
144 ;;; and location of binaries:
145 ;;; **********************************************************************
148 ;;; ******* THIS FILE IS WRITTEN FOR ISPELL VERSION 3.1
151 (defcustom ispell-highlight-p
'block
152 "*Highlight spelling errors when non-nil.
153 When set to `block', assumes a block cursor with TTY displays."
154 :type
'(choice (const block
) (const t
) (const nil
))
157 (defcustom ispell-highlight-face
'highlight
158 "*The face used for Ispell highlighting. For Emacses with overlays.
159 Possible values are `highlight', `modeline', `secondary-selection',
160 `region', and `underline'.
161 This variable can be set by the user to whatever face they desire.
162 It's most convenient if the cursor color and highlight color are
167 (defcustom ispell-check-comments t
168 "*Spelling of comments checked when non-nil.
169 When set to `exclusive', ONLY comments are checked. (For code comments).
170 Warning! Not checking comments, when a comment start is embedded in strings,
171 may produce undesired results."
172 :type
'(choice (const exclusive
) (const t
) (const nil
))
175 (defcustom ispell-query-replace-choices nil
176 "*Corrections made throughout region when non-nil.
177 Uses `query-replace' (\\[query-replace]) for corrections."
181 (defcustom ispell-skip-tib nil
182 "*Does not spell check `tib' bibliography references when non-nil.
183 Skips any text between strings matching regular expressions
184 `ispell-tib-ref-beginning' and `ispell-tib-ref-end'.
186 TeX users beware: Any field starting with [. will skip until a .] -- even
187 your whole buffer -- unless you set `ispell-skip-tib' to nil. That includes
188 a [.5mm] type of number...."
192 (defvar ispell-tib-ref-beginning
"[[<]\\."
193 "Regexp matching the beginning of a Tib reference.")
195 (defvar ispell-tib-ref-end
"\\.[]>]"
196 "Regexp matching the end of a Tib reference.")
198 (defcustom ispell-keep-choices-win t
199 "*When not nil, the `*Choices*' window remains for spelling session.
200 This minimizes redisplay thrashing."
204 (defcustom ispell-choices-win-default-height
2
205 "*The default size of the `*Choices*' window, including status line.
206 Must be greater than 1."
210 (defcustom ispell-program-name
"ispell"
211 "Program invoked by \\[ispell-word] and \\[ispell-region] commands."
215 (defcustom ispell-alternate-dictionary
216 (cond ((file-exists-p "/usr/dict/web2") "/usr/dict/web2")
217 ((file-exists-p "/usr/share/dict/web2") "/usr/share/dict/web2")
218 ((file-exists-p "/usr/dict/words") "/usr/dict/words")
219 ((file-exists-p "/usr/lib/dict/words") "/usr/lib/dict/words")
220 ((file-exists-p "/usr/share/dict/words") "/usr/share/dict/words")
221 ((file-exists-p "/sys/dict") "/sys/dict")
222 (t "/usr/dict/words"))
223 "*Alternate dictionary for spelling help."
227 (defcustom ispell-complete-word-dict ispell-alternate-dictionary
228 "*Dictionary used for word completion."
232 (defcustom ispell-message-dictionary-alist nil
233 "*List used by `ispell-message' to select a new dictionary.
234 It consists of pairs (REGEXP . DICTIONARY). If REGEXP is found
235 in the message headers, `ispell-local-dictionary' will be set to
236 DICTIONARY if `ispell-local-dictionary' is not buffer-local.
237 E.g. you may use the following value:
238 '((\"^Newsgroups:[ \\t]*de\\\\.\" . \"deutsch8\")
239 (\"^To:[^\\n,]+\\\\.de[ \\t\\n,>]\" . \"deutsch8\"))"
240 :type
'(repeat (cons regexp string
))
244 (defcustom ispell-grep-command
"egrep"
245 "Name of the grep command for search processes."
249 (defcustom ispell-grep-options
"-i"
250 "String of options to use when running the program in `ispell-grep-command'.
251 Should probably be \"-i\" or \"-e\".
252 Some machines (like the NeXT) don't support \"-i\""
256 (defcustom ispell-look-command
257 (cond ((file-exists-p "/bin/look") "/bin/look")
258 ((file-exists-p "/usr/local/bin/look") "/usr/local/bin/look")
259 ((file-exists-p "/usr/bin/look") "/usr/bin/look")
261 "Name of the look command for search processes.
262 This must be an absolute file name."
266 (defcustom ispell-look-p
(file-exists-p ispell-look-command
)
267 "*Non-nil means use `look' rather than `grep'.
268 Default is based on whether `look' seems to be available."
272 (defcustom ispell-have-new-look nil
273 "*Non-nil means use the `-r' option (regexp) when running `look'."
277 (defcustom ispell-look-options
(if ispell-have-new-look
"-dfr" "-df")
278 "String of command options for `ispell-look-command'."
282 (defcustom ispell-use-ptys-p nil
283 "When non-nil, Emacs uses ptys to communicate with Ispell.
284 When nil, Emacs uses pipes."
288 (defcustom ispell-following-word nil
289 "*Non-nil means `ispell-word' checks the word around or after point.
290 Otherwise `ispell-word' checks the preceding word."
294 (defcustom ispell-help-in-bufferp nil
295 "*Non-nil means display interactive keymap help in a buffer.
296 The following valued are supported:
297 nil Expand the minibuffer and display a short help message
298 there for a couple of seconds.
299 t Pop up a new buffer and display a short help message there
300 for a couple of seconds.
301 electric Pop up a new buffer and display a long help message there.
302 User can browse and then exit the help mode."
303 :type
'(choice (const electric
) (const t
) (const nil
))
307 (defcustom ispell-quietly nil
308 "*Non-nil means suppress messages in `ispell-word'."
312 (defcustom ispell-format-word
(function upcase
)
313 "*Formatting function for displaying word being spell checked.
314 The function must take one string argument and return a string."
318 (defcustom ispell-use-framepop-p nil
319 "When non-nil ispell uses framepop to display choices in a dedicated frame.
320 You can set this variable to dynamically use framepop if you are in a
321 window system by evaluating the following on startup to set this variable:
322 (and window-system (condition-case () (require 'framepop) (error nil)))"
327 (defcustom ispell-personal-dictionary nil
328 "*File name of your personal spelling dictionary, or nil.
329 If nil, the default personal dictionary, \"~/.ispell_DICTNAME\" is used,
330 where DICTNAME is the name of your default dictionary."
332 (const :tag
"default" nil
))
335 (defcustom ispell-silently-savep nil
336 "*When non-nil, save the personal dictionary without confirmation."
340 ;;; This is the local dictionary to use. When nil the default dictionary will
341 ;;; be used. Change set-default call to use a new default dictionary.
342 (defcustom ispell-local-dictionary nil
343 "If non-nil, the dictionary to be used for Ispell commands.
344 The value must be a string dictionary name in `ispell-dictionary-alist'.
345 This variable becomes buffer-local when set in any fashion.
347 Setting ispell-local-dictionary to a value has the same effect as
348 calling \\[ispell-change-dictionary] with that value. This variable
349 is automatically set when defined in the file with either
350 `ispell-dictionary-keyword' or the Local Variable syntax.
352 To create a non-standard default dictionary (not from ispell-dictionary-alist)
353 call function set-default with the new dictionary name."
354 :type
'(choice string
355 (const :tag
"default" nil
))
358 (make-variable-buffer-local 'ispell-local-dictionary
)
360 ;; Call this function set up the default dictionary if not English.
361 ;;(set-default 'ispell-local-dictionary nil)
364 (defcustom ispell-extra-args nil
365 "*If non-nil, a list of extra switches to pass to the Ispell program.
366 For example, (\"-W\" \"3\") to cause it to accept all 1-3 character
367 words as correct. See also `ispell-dictionary-alist', which may be used
368 for language-specific arguments."
369 :type
'(repeat string
)
372 ;;; The preparation of the menu bar menu must be autoloaded
373 ;;; because otherwise this file gets autoloaded every time Emacs starts
374 ;;; so that it can set up the menus and determine keyboard equivalents.
376 ;;; split dictionary so line length is smaller in loaddefs.el
379 (defvar ispell-dictionary-alist-1
380 '((nil ; default (English.aff)
381 "[A-Za-z]" "[^A-Za-z]" "[']" nil
("-B") nil nil
)
382 ("american" ; make English explicitly selectable
383 "[A-Za-z]" "[^A-Za-z]" "[']" nil
("-B") nil nil
)
384 ("british" ; British version
385 "[A-Za-z]" "[^A-Za-z]" "[']" nil
("-B" "-d" "british") nil nil
)
386 ("castellano" ; Spanish mode
387 "[A-Z\301\311\315\323\332\334\321a-z\341\351\355\363\372\374\361]"
388 "[^A-Z\301\311\315\323\332\334\321a-z\341\351\355\363\372\374\361]"
389 "[---]" nil
("-B" "-d" "castellano") "~tex" iso-latin-1
)
390 ("castellano8" ; 8 bit Spanish mode
391 "[A-Z\301\311\315\323\332\334\321a-z\341\351\355\363\372\374\361]"
392 "[^A-Z\301\311\315\323\332\334\321a-z\341\351\355\363\372\374\361]"
393 "[---]" nil
("-B" "-d" "castellano") "~latin1" iso-latin-1
)
395 "[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]"
396 "[^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]"
397 "" nil
("-B" "-d" "czech") nil iso-latin-2
)
399 "[A-Z\306\330\305a-z\346\370\345]" "[^A-Z\306\330\305a-z\346\370\345]"
400 "[']" nil
("-C") nil iso-latin-1
)
401 ("deutsch" ; Deutsch.aff
402 "[a-zA-Z\"]" "[^a-zA-Z\"]" "[']" t
("-C") "~tex" nil
)
404 "[a-zA-Z\304\326\334\344\366\337\374]"
405 "[^a-zA-Z\304\326\334\344\366\337\374]"
406 "[']" t
("-C" "-d" "deutsch") "~latin1" iso-latin-1
)
407 ("english" ; make English explicitly selectable
408 "[A-Za-z]" "[^A-Za-z]" "[']" nil
("-B") nil nil
))
409 "First half of dictionary, shortened for loaddefs.el")
412 (defvar ispell-dictionary-alist-2
414 "[A-Za-z\246\254\266\274\306\330\335\336\346\370\375\376]"
415 "[^A-Za-z\246\254\266\274\306\330\335\336\346\370\375\376]"
416 "[-']" t
("-C") "~latin3" nil
)
418 "[A-Za-z^\\]" "[^A-Za-z^\\]" "[-'`\"]" t
("-C" "-d" "esperanto") "~tex"
421 "[A-Za-z]" "[^A-Za-z]" "[`'^---]" t nil nil nil
)
422 ("francais" ; Francais.aff
423 "[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]"
424 "[^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]"
425 "[---']" t nil
"~list" iso-latin-1
)
426 ("francais-tex" ; Francais.aff
427 "[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\\]"
428 "[^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\\]"
429 "[---'^`\"]" t nil
"~tex" iso-latin-1
)
430 ("nederlands" ; Nederlands.aff
431 "[A-Za-z\300-\305\307\310-\317\322-\326\331-\334\340-\345\347\350-\357\361\362-\366\371-\374]"
432 "[^A-Za-z\300-\305\307\310-\317\322-\326\331-\334\340-\345\347\350-\357\361\362-\366\371-\374]"
433 "[']" t
("-C") nil iso-latin-1
)
434 ("nederlands8" ; Dutch8.aff
435 "[A-Za-z\300-\305\307\310-\317\322-\326\331-\334\340-\345\347\350-\357\361\362-\366\371-\374]"
436 "[^A-Za-z\300-\305\307\310-\317\322-\326\331-\334\340-\345\347\350-\357\361\362-\366\371-\374]"
437 "[']" t
("-C") nil iso-latin-1
)
438 ("norsk" ;8 bit Norwegian mode
439 "[A-Za-z\351\346\370\345\350\364\362\311\306\330\305\310\324\322]"
440 "[^A-Za-z\351\346\370\345\350\364\362\311\306\330\305\310\324\322]"
441 "[']" nil
("-C" "-d" "norsk") "~list" nil
)
442 ("russian" ; russian.aff (KOI8-R charset)
443 "[\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]"
444 "[^\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]"
445 "[']" t
("-C" "-d" "russian") "~latin1" iso-latin-1
)
446 ("svenska" ;7 bit Swedish mode
447 "[A-Za-z}{|\\133\\135\\\\]" "[^A-Za-z}{|\\133\\135\\\\]"
448 "[']" nil
("-C") nil nil
)
449 ("svenska8" ;8 bit Swedish mode
450 "[A-Za-z\345\344\366\305\304\366]" "[^A-Za-z\345\344\366\305\304\366]"
451 "[']" nil
("-C" "-d" "svenska") "~list" ; Add `"-T" "list"' instead?
453 "Second half of dictionary, shortened for loaddefs.el")
455 ;;; The preparation of the menu bar menu must be autoloaded
456 ;;; because otherwise this file gets autoloaded every time Emacs starts
457 ;;; so that it can set up the menus and determine keyboard equivalents.
460 (defcustom ispell-dictionary-alist
461 (append ispell-dictionary-alist-1 ispell-dictionary-alist-2
)
462 "An alist of dictionaries and their associated parameters.
464 Each element of this list is also a list:
466 \(DICTIONARY-NAME CASECHARS NOT-CASECHARS OTHERCHARS MANY-OTHERCHARS-P
467 ISPELL-ARGS EXTENDED-CHARACTER-MODE CHARACTER-SET\)
469 DICTIONARY-NAME is a possible string value of variable `ispell-dictionary',
470 nil means the default dictionary.
472 CASECHARS is a regular expression of valid characters that comprise a
475 NOT-CASECHARS is the opposite regexp of CASECHARS.
477 OTHERCHARS is a regexp of characters in the NOT-CASECHARS set but which can be
478 used to construct words in some special way. If OTHERCHARS characters follow
479 and precede characters from CASECHARS, they are parsed as part of a word,
480 otherwise they become word-breaks. As an example in English, assume the
481 regular expression \"[']\" for OTHERCHARS. Then \"they're\" and
482 \"Steven's\" are parsed as single words including the \"'\" character, but
483 \"Stevens'\" does not include the quote character as part of the word.
484 If you want OTHERCHARS to be empty, use the empty string.
485 Hint: regexp syntax requires the hyphen to be declared first here.
487 MANY-OTHERCHARS-P is non-nil when multiple OTHERCHARS are allowed in a word.
488 Otherwise only a single OTHERCHARS character is allowed to be part of any
491 ISPELL-ARGS is a list of additional arguments passed to the ispell
494 EXTENDED-CHARACTER-MODE should be used when dictionaries are used which
495 have been configured in an Ispell affix file. (For example, umlauts
496 can be encoded as \\\"a, a\\\", \"a, ...) Defaults are ~tex and ~nroff
497 in English. This has the same effect as the command-line `-T' option.
498 The buffer Major Mode controls Ispell's parsing in tex or nroff mode,
499 but the dictionary can control the extended character mode.
500 Both defaults can be overruled in a buffer-local fashion. See
501 `ispell-parsing-keyword' for details on this.
503 CHARACTER-SET used for languages with multibyte characters.
505 Note that the CASECHARS and OTHERCHARS slots of the alist should
506 contain the same character set as casechars and otherchars in the
507 LANGUAGE.aff file \(e.g., english.aff\)."
508 :type
'(repeat (list (choice :tag
"Dictionary"
509 (string :tag
"Dictionary name")
510 (const :tag
"default" nil
))
511 (regexp :tag
"Case characters")
512 (regexp :tag
"Non case characters")
513 (regexp :tag
"Other characters")
514 (boolean :tag
"Many other characters")
515 (repeat :tag
"Ispell command line args"
517 (choice :tag
"Extended character mode"
518 (const "~tex") (const "~list") (const "~nroff")
519 (const "~latin3") (const "~latin1")
520 (const :tag
"default" nil
))
521 (choice :tag
"Character set"
524 (const :tag
"default" nil
))))
529 (defvar ispell-menu-map nil
"Key map for ispell menu")
532 (defvar ispell-menu-xemacs nil
533 "Spelling menu for XEmacs.
534 If nil when package is loaded, a standard menu will be set,
535 and added as a submenu of the \"Edit\" menu.")
537 ;;; Break out XEmacs menu and split into several calls to avoid having
538 ;;; long lines in loaddefs.el. Detect need off following constant.
540 ;;; Set up dictionary
542 (defconst ispell-menu-map-needed
543 ;; only needed when not version 18 and not XEmacs.
544 (and (not ispell-menu-map
)
545 (not (string-match "18\\.[0-9]+\\.[0-9]+" emacs-version
))
546 (not (string-match "Lucid\\|XEmacs" emacs-version
))))
549 (if ispell-menu-map-needed
550 (let ((dicts (reverse (cons (cons "default" nil
) ispell-dictionary-alist
)))
552 (setq ispell-menu-map
(make-sparse-keymap "Spell"))
553 ;; add the dictionaries to the bottom of the list.
555 (setq name
(car (car dicts
))
558 (define-key ispell-menu-map
(vector (intern name
))
559 (cons (concat "Select " (capitalize name
))
560 (list 'lambda
() '(interactive)
561 (list 'ispell-change-dictionary name
))))))))
563 ;;; define commands in menu in opposite order you want them to appear.
565 (if ispell-menu-map-needed
567 (define-key ispell-menu-map
[ispell-change-dictionary
]
568 '("Change Dictionary" . ispell-change-dictionary
))
569 (define-key ispell-menu-map
[ispell-kill-ispell
]
570 '("Kill Process" . ispell-kill-ispell
))
571 (define-key ispell-menu-map
[ispell-pdict-save
]
572 '("Save Dictionary" .
(lambda () (interactive) (ispell-pdict-save t t
))))
573 (define-key ispell-menu-map
[ispell-complete-word
]
574 '("Complete Word" . ispell-complete-word
))
575 (define-key ispell-menu-map
[ispell-complete-word-interior-frag
]
576 '("Complete Word Frag" . ispell-complete-word-interior-frag
))))
579 (if ispell-menu-map-needed
581 (define-key ispell-menu-map
[ispell-continue
]
582 '("Continue Check" . ispell-continue
))
583 (define-key ispell-menu-map
[ispell-word
]
584 '("Check Word" . ispell-word
))
585 (define-key ispell-menu-map
[ispell-comments-and-strings
]
586 '("Check Comments" . ispell-comments-and-strings
))
587 (define-key ispell-menu-map
[ispell-region
]
588 '("Check Region" . ispell-region
))
589 (define-key ispell-menu-map
[ispell-buffer
]
590 '("Check Buffer" . ispell-buffer
))))
593 (if ispell-menu-map-needed
595 (define-key ispell-menu-map
[ispell-message
]
596 '("Check Message" . ispell-message
))
597 (define-key ispell-menu-map
[ispell-help
]
598 ;; use (x-popup-menu last-nonmenu-event(list "" ispell-help-list)) ?
599 '("Help" .
(lambda () (interactive) (describe-function 'ispell-help
))))
600 (put 'ispell-region
'menu-enable
'mark-active
)
601 (fset 'ispell-menu-map
(symbol-value 'ispell-menu-map
))))
603 ;;; XEmacs version 19 & 20
604 (if (and (not (string-match "18\\.[0-9]+\\.[0-9]+" emacs-version
))
605 (string-match "Lucid\\|XEmacs" emacs-version
)
607 (null ispell-menu-xemacs
)
608 (not (and (boundp 'infodock-version
) infodock-version
)))
609 (let ((dicts (cons (cons "default" nil
) ispell-dictionary-alist
))
610 (current-menubar (or current-menubar default-menubar
))
612 '(["Help" (describe-function 'ispell-help
) t
]
613 ;;["Help" (popup-menu ispell-help-list) t]
614 ["Check Message" ispell-message t
]
615 ["Check Buffer" ispell-buffer t
]
616 ["Check Comments" ispell-comments-and-strings t
]
617 ["Check Word" ispell-word t
]
618 ["Check Region" ispell-region
(or (not zmacs-regions
) (mark))]
619 ["Continue Check" ispell-continue t
]
620 ["Complete Word Frag"ispell-complete-word-interior-frag t
]
621 ["Complete Word" ispell-complete-word t
]
622 ["Kill Process" ispell-kill-ispell t
]
624 ["Save Dictionary" (ispell-pdict-save t t
) t
]
625 ["Change Dictionary" ispell-change-dictionary t
]))
628 (setq name
(car (car dicts
))
631 (setq menu
(append menu
633 (vector (concat "Select " (capitalize name
))
634 (list 'ispell-change-dictionary name
)
636 (setq ispell-menu-xemacs menu
)
639 (delete-menu-item '("Edit" "Spell")) ; in case already defined
640 (add-menu '("Edit") "Spell" ispell-menu-xemacs
)))))
642 ;;; Allow incrementing characters as integers in XEmacs 20
643 (if (and (string-match "XEmacs" emacs-version
)
645 (fset 'ispell-int-char
'int-char
)
646 ;; Emacs and XEmacs 19 or earlier
647 (fset 'ispell-int-char
'identity
))
650 ;;; **********************************************************************
651 ;;; The following are used by ispell, and should not be changed.
652 ;;; **********************************************************************
655 ;;; The version must be 3.1 or greater for this version of ispell.el
656 ;;; There is an incompatibility between version 3.1.12 and lower versions.
657 (defconst ispell-required-version
'("3.1." 12)
658 "Ispell versions with which this version of ispell.el is known to work.")
659 (defvar ispell-offset -
1
660 "Offset that maps protocol differences between ispell 3.1 versions.")
662 ;;; This variable contains the current dictionary being used if the ispell
663 ;;; process is running. Otherwise it contains the global default.
664 (defvar ispell-dictionary nil
665 "The name of the current dictionary, or nil for the default.
666 When `ispell-local-dictionary' is nil, `ispell-dictionary' is used to select
667 the dictionary for new buffers.
669 This is passed to the ispell process using the `-d' switch and is
670 used as key in `ispell-dictionary-alist' (which see).")
672 (defun ispell-decode-string (str)
673 "Decodes multibyte character strings."
674 (if (and (boundp 'enable-multibyte-characters
)
675 (fboundp 'decode-coding-string
)
676 enable-multibyte-characters
677 (ispell-get-coding-system))
678 (decode-coding-string str
(ispell-get-coding-system))
681 (defun ispell-get-casechars ()
682 (ispell-decode-string
683 (nth 1 (assoc ispell-dictionary ispell-dictionary-alist
))))
684 (defun ispell-get-not-casechars ()
685 (ispell-decode-string
686 (nth 2 (assoc ispell-dictionary ispell-dictionary-alist
))))
687 (defun ispell-get-otherchars ()
688 (ispell-decode-string
689 (nth 3 (assoc ispell-dictionary ispell-dictionary-alist
))))
690 (defun ispell-get-many-otherchars-p ()
691 (nth 4 (assoc ispell-dictionary ispell-dictionary-alist
)))
692 (defun ispell-get-ispell-args ()
693 (nth 5 (assoc ispell-dictionary ispell-dictionary-alist
)))
694 (defun ispell-get-extended-character-mode ()
695 (nth 6 (assoc ispell-dictionary ispell-dictionary-alist
)))
696 (defun ispell-get-coding-system ()
697 (nth 7 (assoc ispell-dictionary ispell-dictionary-alist
)))
699 (defvar ispell-process nil
700 "The process object for Ispell.")
702 (defvar ispell-pdict-modified-p nil
703 "Non-nil means personal dictionary has modifications to be saved.")
705 ;;; If you want to save the dictionary when quitting, must do so explicitly.
706 ;;; When non-nil, the spell session is terminated.
707 ;;; When numeric, contains cursor location in buffer, and cursor remains there.
708 (defvar ispell-quit nil
)
710 (defvar ispell-filter nil
711 "Output filter from piped calls to Ispell.")
713 (defvar ispell-filter-continue nil
714 "Control variable for Ispell filter function.")
716 (defvar ispell-process-directory nil
717 "The directory where `ispell-process' was started.")
719 (defvar ispell-query-replace-marker
(make-marker)
720 "Marker for `query-replace' processing.")
722 (defvar ispell-recursive-edit-marker
(make-marker)
723 "Marker for return point from recursive edit.")
725 (defvar ispell-checking-message nil
726 "Non-nil when we're checking a mail message")
728 (defconst ispell-choices-buffer
"*Choices*")
730 (defvar ispell-overlay nil
"Overlay variable for Ispell highlighting.")
732 ;;; *** Buffer Local Definitions ***
734 (defconst ispell-words-keyword
"LocalWords: "
735 "The keyword for local oddly-spelled words to accept.
736 The keyword will be followed by any number of local word spellings.
737 There can be multiple of these keywords in the file.")
739 (defconst ispell-dictionary-keyword
"Local IspellDict: "
740 "The keyword for a local dictionary to use.
741 The keyword must be followed by a correct dictionary name in
742 `ispell-dictionary-alist'. When multiple occurrences exist, the last keyword
743 definition is used.")
745 (defconst ispell-pdict-keyword
"Local IspellPersDict: "
746 "The keyword for defining buffer local dictionaries.
747 Keyword must be followed by the filename of a personal dictionary.
748 The last occurring definition in the buffer will be used.")
750 (defconst ispell-parsing-keyword
"Local IspellParsing: "
751 "The keyword for overriding default Ispell parsing.
752 The above keyword string should be followed by `latex-mode' or
753 `nroff-mode' to put the current buffer into the desired parsing mode.
755 Extended character mode can be changed for this buffer by placing
756 a `~' followed by an extended-character mode -- such as `~.tex'.
757 The last occurring definition in the buffer will be used.")
760 (defvar ispell-skip-region-alist
761 '((ispell-words-keyword forward-line
)
762 (ispell-dictionary-keyword forward-line
)
763 (ispell-pdict-keyword forward-line
)
764 (ispell-parsing-keyword forward-line
)
765 ("^---*BEGIN PGP [A-Z ]*--*" .
"^---*END PGP [A-Z ]*--*")
766 ("^---* \\(Start of \\)?[Ff]orwarded [Mm]essage" .
"^---* End of [Ff]orwarded [Mm]essage")
767 ;; matches e-mail addresses, file names, http addresses, etc.
768 ("\\(/\\|\\(\\(\\w\\|-\\)+[.:@]\\)\\)\\(\\w\\|-\\)*\\([.:/@]+\\(\\w\\|-\\|~\\)+\\)+")
769 ;; This is a pretty complex regexp. It can be simplified to the following:
770 ;; "\\(\\w\\|-\\)*\\([.:/@]+\\(\\w\\|-\\|~\\)+\\)+"
771 ;; but some valid text will be skipped, e.g. "his/herr". This could be
772 ;; fixed up (at the expense of a moderately more complex regexp)
773 ;; by not allowing "/" to be the character which triggers the
774 ;; identification of the computer name, e.g.:
775 ;; "\\(\\w\\|-\\)+[.:@]\\(\\w\\|-\\)*\\([.:/@]+\\(\\w\\|-\\|~\\)+\\)+"
777 "Alist expressing beginning and end of regions not to spell check.
778 The alist key must be a regular expression.
780 (KEY) - just skip the key.
781 (KEY . REGEXP) - skip to the end of REGEXP. REGEXP may be string or symbol.
782 (KEY REGEXP) - skip to end of REGEXP. REGEXP must be a string.
783 (KEY FUNCTION ARGS) - FUNCTION called with ARGS returns end of region.")
788 (defvar ispell-tex-skip-alists
790 ;; All the standard LaTeX keywords from L. Lamport's guide:
791 ;; \cite, \hspace, \hspace*, \hyphenation, \include, \includeonly, \input,
792 ;; \label, \nocite, \rule (in ispell - rest included here)
793 ("\\\\addcontentsline" ispell-tex-arg-end
2)
794 ("\\\\add\\(tocontents\\|vspace\\)" ispell-tex-arg-end
)
795 ("\\\\\\([aA]lph\\|arabic\\)" ispell-tex-arg-end
)
796 ("\\\\author" ispell-tex-arg-end
)
797 ("\\\\bibliographystyle" ispell-tex-arg-end
)
798 ("\\\\makebox" ispell-tex-arg-end
0)
799 ;;("\\\\epsfig" ispell-tex-arg-end)
800 ("\\\\document\\(class\\|style\\)" .
801 "\\\\begin[ \t\n]*{[ \t\n]*document[ \t\n]*}"))
802 (;; delimited with \begin. In ispell: displaymath, eqnarray, eqnarray*,
803 ;; equation, minipage, picture, tabular, tabular* (ispell)
804 ("\\(figure\\|table\\)\\*?" ispell-tex-arg-end
0)
805 ("list" ispell-tex-arg-end
2)
806 ("program" .
"\\\\end[ \t\n]*{[ \t\n]*program[ \t\n]*}")
807 ("verbatim\\*?" .
"\\\\end[ \t\n]*{[ \t\n]*verbatim\\*?[ \t\n]*}")))
808 "*Lists of regions to be skipped in TeX mode.
809 First list is used raw.
810 Second list has key placed inside \\begin{}.
812 Delete or add any regions you want to be automatically selected
813 for skipping in latex mode.")
816 (defcustom ispell-skip-sgml
'use-mode-name
817 "*Indicates whether ispell should skip spell checking of SGML markup.
818 If t, always skip SGML markup; if nil, never skip; if non-t and non-nil,
819 guess whether SGML markup should be skipped according to the name of the
820 buffer's major mode."
821 :type
'(choice (const use-mode-name
) (const t
) (const nil
))
824 (defvar ispell-local-pdict ispell-personal-dictionary
825 "A buffer local variable containing the current personal dictionary.
826 If non-nil, the value must be a string, which is a file name.
828 If you specify a personal dictionary for the current buffer which is
829 different from the current personal dictionary, the effect is similar
830 to calling \\[ispell-change-dictionary]. This variable is automatically
831 set when defined in the file with either `ispell-pdict-keyword' or the
832 local variable syntax.")
834 (make-variable-buffer-local 'ispell-local-pdict
)
836 (defvar ispell-buffer-local-name nil
837 "Contains the buffer name if local word definitions were used.
838 Ispell is then restarted because the local words could conflict.")
840 (defvar ispell-parser
'use-mode-name
841 "*Indicates whether ispell should parse the current buffer as TeX Code.
842 Special value `use-mode-name' tries to guess using the name of major-mode.
843 Default parser is `nroff'.
844 Currently the only other valid parser is `tex'.
846 You can set this variable in hooks in your init file -- eg:
848 (add-hook 'tex-mode-hook (function (lambda () (setq ispell-parser 'tex))))")
850 (defvar ispell-region-end
(make-marker)
851 "Marker that allows spelling continuations.")
853 (defvar ispell-check-only nil
854 "If non-nil, `ispell-word' does not try to correct the word.")
857 ;;; **********************************************************************
858 ;;; **********************************************************************
862 (and (not (string-match "18\\.[0-9]+\\.[0-9]+" emacs-version
))
863 (not (boundp 'epoch
::version
))
864 (defalias 'ispell
'ispell-buffer
))
866 (if (not (fboundp 'buffer-substring-no-properties
))
867 (defun buffer-substring-no-properties (start end
)
868 (buffer-substring start end
)))
871 (define-key esc-map
"$" 'ispell-word
)
874 (defun ispell-word (&optional following quietly continue
)
875 "Check spelling of word under or before the cursor.
876 If the word is not found in dictionary, display possible corrections
877 in a window allowing you to choose one.
879 With a prefix argument (or if CONTINUE is non-nil),
880 resume interrupted spell-checking of a buffer or region.
882 If optional argument FOLLOWING is non-nil or if `ispell-following-word'
883 is non-nil when called interactively, then the following word
884 \(rather than preceding\) is checked when the cursor is not over a word.
885 When the optional argument QUIETLY is non-nil or `ispell-quietly' is non-nil
886 when called interactively, non-corrective messages are suppressed.
888 Word syntax described by `ispell-dictionary-alist' (which see).
890 This will check or reload the dictionary. Use \\[ispell-change-dictionary]
891 or \\[ispell-region] to update the Ispell process."
892 (interactive (list nil nil current-prefix-arg
))
896 (setq following ispell-following-word
897 quietly ispell-quietly
))
898 (ispell-accept-buffer-local-defs) ; use the correct dictionary
899 (let ((cursor-location (point)) ; retain cursor location
900 (word (ispell-get-word following
))
901 start end poss new-word replace
)
902 ;; De-structure return word info list.
903 (setq start
(car (cdr word
))
904 end
(car (cdr (cdr word
)))
907 ;; now check spelling of word if it has 3 or more characters.
908 (when (> (length word
) 2)
910 (message "Checking spelling of %s..."
911 (funcall ispell-format-word word
)))
912 (process-send-string ispell-process
"%\n") ;put in verbose mode
913 (process-send-string ispell-process
(concat "^" word
"\n"))
914 ;; wait until ispell has processed word
916 (accept-process-output ispell-process
)
917 (not (string= "" (car ispell-filter
)))))
918 ;;(process-send-string ispell-process "!\n") ;back to terse mode.
919 (setq ispell-filter
(cdr ispell-filter
)) ; remove extra \n
920 (if (listp ispell-filter
)
921 (setq poss
(ispell-parse-output (car ispell-filter
))))
924 (message "%s is correct"
925 (funcall ispell-format-word word
))))
928 (message "%s is correct because of root %s"
929 (funcall ispell-format-word word
)
930 (funcall ispell-format-word poss
))))
931 ((null poss
) (message "Error in ispell process"))
932 (ispell-check-only ; called from ispell minor mode.
934 (message "%s is incorrect" (funcall ispell-format-word word
)))
935 (t ; prompt for correct word.
936 (save-window-excursion
937 (setq replace
(ispell-command-loop
938 (car (cdr (cdr poss
)))
939 (car (cdr (cdr (cdr poss
))))
940 (car poss
) start end
)))
941 (cond ((equal 0 replace
)
942 (ispell-add-per-file-word-list (car poss
)))
944 (setq new-word
(if (atom replace
) replace
(car replace
))
945 cursor-location
(+ (- (length word
) (- end start
))
947 (if (not (equal new-word
(car poss
)))
949 (delete-region start end
)
953 (if (not (atom replace
)) ;recheck spelling of replacement
955 (if (car (cdr replace
)) ; query replace requested
956 (save-window-excursion
957 (query-replace word new-word t
)))
958 (ispell-region start end
)))))
959 (if (get-buffer ispell-choices-buffer
)
960 (kill-buffer ispell-choices-buffer
))))
961 (goto-char cursor-location
) ; return to original location
962 (ispell-pdict-save ispell-silently-savep
)
963 (if ispell-quit
(setq ispell-quit nil
))))))
966 (defun ispell-get-word (following &optional extra-otherchars
)
967 "Return the word for spell-checking according to ispell syntax.
968 If optional argument FOLLOWING is non-nil or if `ispell-following-word'
969 is non-nil when called interactively, then the following word
970 \(rather than preceding\) is checked when the cursor is not over a word.
971 Optional second argument contains otherchars that can be included in word
974 Word syntax described by `ispell-dictionary-alist' (which see)."
975 (let* ((ispell-casechars (ispell-get-casechars))
976 (ispell-not-casechars (ispell-get-not-casechars))
977 (ispell-otherchars (ispell-get-otherchars))
978 (ispell-many-otherchars-p (ispell-get-many-otherchars-p))
979 (word-regexp (concat ispell-casechars
981 (if (not (string= "" ispell-otherchars
))
982 (concat ispell-otherchars
"?"))
984 (concat extra-otherchars
"?"))
987 (if (or ispell-many-otherchars-p
993 (if (not (looking-at ispell-casechars
))
995 (re-search-forward ispell-casechars
(point-max) t
)
996 (re-search-backward ispell-casechars
(point-min) t
)))
997 ;; move to front of word
998 (re-search-backward ispell-not-casechars
(point-min) 'start
)
999 (while (and (or (and (not (string= "" ispell-otherchars
))
1000 (looking-at ispell-otherchars
))
1001 (and extra-otherchars
(looking-at extra-otherchars
)))
1003 (or (not did-it-once
)
1004 ispell-many-otherchars-p
)
1005 (not (eq prevpt
(point))))
1006 (if (and extra-otherchars
(looking-at extra-otherchars
))
1009 (if (looking-at ispell-casechars
)
1010 (re-search-backward ispell-not-casechars
(point-min) 'move
)))
1014 (if (looking-at ispell-casechars
)
1015 (re-search-backward ispell-not-casechars
(point-min) 'move
)
1016 (backward-char -
1))))
1017 ;; Now mark the word and save to string.
1018 (if (not (re-search-forward word-regexp
(point-max) t
))
1019 (if ispell-check-only
1020 ;; return dummy word when just flagging misspellings
1021 (list "" (point) (point))
1022 (error "No word found to check!"))
1023 (setq start
(match-beginning 0)
1025 word
(buffer-substring-no-properties start end
))
1026 (list word start end
))))
1029 ;;; Global ispell-pdict-modified-p is set by ispell-command-loop and
1030 ;;; tracks changes in the dictionary. The global may either be
1031 ;;; a value or a list, whose value is the state of whether the
1032 ;;; dictionary needs to be saved.
1035 (defun ispell-pdict-save (&optional no-query force-save
)
1036 "Check to see if the personal dictionary has been modified.
1037 If so, ask if it needs to be saved."
1038 (interactive (list ispell-silently-savep t
))
1039 (if (and ispell-pdict-modified-p
(listp ispell-pdict-modified-p
))
1040 (setq ispell-pdict-modified-p
(car ispell-pdict-modified-p
)))
1041 (if (or ispell-pdict-modified-p force-save
)
1042 (if (or no-query
(y-or-n-p "Personal dictionary modified. Save? "))
1044 (process-send-string ispell-process
"#\n")
1045 (message "Personal dictionary saved."))))
1046 ;; unassert variable, even if not saved to avoid questioning.
1047 (setq ispell-pdict-modified-p nil
))
1050 (defun ispell-command-loop (miss guess word start end
)
1051 "Display possible corrections from list MISS.
1052 GUESS lists possibly valid affix construction of WORD.
1053 Returns nil to keep word.
1054 Returns 0 to insert locally into buffer-local dictionary.
1055 Returns string for new chosen word.
1056 Returns list for new replacement word (will be rechecked).
1057 Query-replace when list length is 2.
1058 Automatic query-replace when second element is `query-replace'.
1059 Highlights the word, which is assumed to run from START to END.
1060 Global `ispell-pdict-modified-p' becomes a list where the only value
1061 indicates whether the dictionary has been modified when option `a' or `i' is
1063 Global `ispell-quit' set to start location to continue spell session."
1064 (let ((textbuf (current-buffer))
1067 (max-lines (- (window-height) 4)) ; assure 4 context lines.
1069 (window-min-height (min window-min-height
1070 ispell-choices-win-default-height
))
1071 (command-characters '( ? ?i ?a ?A ?r ?R ?? ?x ?X ?q ?l ?u ?m
))
1072 (dedicated (window-dedicated-p (selected-window)))
1074 char num result textwin dedicated-win highlighted
)
1076 ;; setup the *Choices* buffer with valid data.
1078 (set-buffer (get-buffer-create ispell-choices-buffer
))
1079 (setq mode-line-format
(concat "-- %b -- word: " word
))
1080 (and (fboundp 'set-specifier
) ; prevent XEmacs modeline hiding
1081 (set-specifier has-modeline-p
(cons (current-buffer) nil
)))
1085 (insert "Affix rules generate and capitalize "
1086 "this word as shown below:\n\t")
1088 (if (> (+ 4 (current-column) (length (car guess
)))
1092 (setq line
(1+ line
))))
1093 (insert (car guess
) " ")
1094 (setq guess
(cdr guess
)))
1095 (insert "\nUse option `i' if this is a correct composition"
1096 " from the derivative root.\n")
1097 (setq line
(+ line
(if choices
3 2)))))
1099 (< (if (> (+ 7 (current-column) (length (car choices
))
1100 (if (> count ?~
) 3 0))
1104 (setq line
(1+ line
)))
1107 ;; not so good if there are over 20 or 30 options, but then, if
1108 ;; there are that many you don't want to scan them all anyway...
1109 (while (memq count command-characters
) ; skip command characters.
1110 (setq count
(ispell-int-char (1+ count
))
1111 skipped
(1+ skipped
)))
1112 (insert "(" count
") " (car choices
) " ")
1113 (setq choices
(cdr choices
)
1114 count
(ispell-int-char (1+ count
))))
1115 (setq count
(ispell-int-char (- count ?
0 skipped
))))
1117 ;; Assure word is visible
1118 (if (not (pos-visible-in-window-p end
))
1121 ;; allow temporary split of dedicated windows...
1124 (setq dedicated-win
(selected-window))
1125 (set-window-dedicated-p dedicated-win nil
)))
1127 ;; Display choices for misspelled word.
1128 (ispell-show-choices line end
)
1130 (select-window (setq textwin
(next-window)))
1132 ;; highlight word, protecting current buffer status
1135 (and ispell-highlight-p
1136 (ispell-highlight-spelling-error start end t
))
1137 ;; Loop until a valid choice is made.
1145 (let (message-log-max)
1146 (message (concat "C-h or ? for more options; SPC to leave "
1147 "unchanged, Character to replace word")))
1148 (let ((inhibit-quit t
))
1149 (setq char
(if (fboundp 'read-char-exclusive
)
1150 (read-char-exclusive)
1153 (if (or quit-flag
(= char ?\C-g
)) ; C-g is like typing X
1156 ;; Adjust num to array offset skipping command characters.
1157 (let ((com-chars command-characters
))
1159 (if (and (> (car com-chars
) ?
0) (< (car com-chars
) char
))
1160 (setq skipped
(1+ skipped
)))
1161 (setq com-chars
(cdr com-chars
)))
1162 (setq num
(- char ?
0 skipped
)))
1165 ((= char ?
) nil
) ; accept word this time only
1166 ((= char ?i
) ; accept and insert word into pers dict
1167 (process-send-string ispell-process
(concat "*" word
"\n"))
1168 (setq ispell-pdict-modified-p
'(t)) ; dictionary modified!
1170 ((or (= char ?a
) (= char ?A
)) ; accept word without insert
1171 (process-send-string ispell-process
(concat "@" word
"\n"))
1172 (if (null ispell-pdict-modified-p
)
1173 (setq ispell-pdict-modified-p
1174 (list ispell-pdict-modified-p
)))
1175 (if (= char ?A
) 0)) ; return 0 for ispell-add buffer-local
1176 ((or (= char ?r
) (= char ?R
)) ; type in replacement
1177 (and (eq 'block ispell-highlight-p
) ; refresh tty's
1178 (ispell-highlight-spelling-error start end nil t
))
1180 (if (or (= char ?R
) ispell-query-replace-choices
)
1181 (list (read-string "Query-replacement for: "
1183 (cons (read-string "Replacement for: " word
)
1185 (and (eq 'block ispell-highlight-p
)
1186 (ispell-highlight-spelling-error start end nil
1189 ((or (= char ??
) (= char help-char
) (= char ?\C-h
))
1190 (and (eq 'block ispell-highlight-p
)
1191 (ispell-highlight-spelling-error start end nil t
))
1193 (and (eq 'block ispell-highlight-p
)
1194 (ispell-highlight-spelling-error start end nil
1197 ;; Quit and move point back.
1199 (ispell-pdict-save ispell-silently-savep
)
1200 (message "Exited spell-checking")
1201 (setq ispell-quit t
)
1203 ;; Quit and preserve point.
1205 (ispell-pdict-save ispell-silently-savep
)
1207 (substitute-command-keys
1208 (concat "Spell-checking suspended;"
1209 " use C-u \\[ispell-word] to resume")))
1210 (setq ispell-quit start
)
1213 (if (y-or-n-p "Really kill Ispell process? ")
1215 (ispell-kill-ispell t
) ; terminate process.
1216 (setq ispell-quit
(or (not ispell-checking-message
)
1218 ispell-pdict-modified-p nil
))
1219 t
)) ; continue if they don't quit.
1221 (and (eq 'block ispell-highlight-p
) ; refresh tty displays
1222 (ispell-highlight-spelling-error start end nil t
))
1223 (let ((new-word (read-string
1224 "Lookup string (`*' is wildcard): "
1230 (set-buffer (get-buffer-create
1231 ispell-choices-buffer
))
1235 mode-line-format
(concat
1238 miss
(lookup-words new-word
)
1240 (while (and choices
; adjust choices window.
1241 (< (if (> (+ 7 (current-column)
1242 (length (car choices
))
1243 (if (> count ?~
) 3 0))
1251 (while (memq count command-characters
)
1252 (setq count
(ispell-int-char (1+ count
))
1253 skipped
(1+ skipped
)))
1254 (insert "(" count
") " (car choices
) " ")
1255 (setq choices
(cdr choices
)
1256 count
(ispell-int-char (1+ count
))))
1257 (setq count
(ispell-int-char
1258 (- count ?
0 skipped
))))
1259 (select-window (previous-window))
1260 (if (and (/= new-line line
)
1261 (> (max line new-line
)
1262 ispell-choices-win-default-height
))
1263 (let* ((minh ispell-choices-win-default-height
)
1264 (gr-bl (if (< line minh
) ; blanks
1267 (shr-bl (if (< new-line minh
) ; blanks
1270 (if (> new-line line
)
1271 (enlarge-window (- new-line line gr-bl
))
1272 (shrink-window (- line new-line shr-bl
)))
1273 (setq line new-line
)))
1274 (select-window (next-window)))))
1275 (and (eq 'block ispell-highlight-p
)
1276 (ispell-highlight-spelling-error start end nil
1278 t
) ; reselect from new choices
1280 (process-send-string ispell-process
1281 (concat "*" (downcase word
) "\n"))
1282 (setq ispell-pdict-modified-p
'(t)) ; dictionary modified!
1284 ((= char ?m
) ; type in what to insert
1285 (process-send-string
1286 ispell-process
(concat "*" (read-string "Insert: " word
)
1288 (setq ispell-pdict-modified-p
'(t))
1290 ((and (>= num
0) (< num count
))
1291 (if ispell-query-replace-choices
; Query replace flag
1292 (list (nth num miss
) 'query-replace
)
1297 (if (marker-position ispell-recursive-edit-marker
)
1299 (message "Only one recursive edit session supported")
1301 (set-marker ispell-recursive-edit-marker start
)
1302 ;;(set-marker ispell-region-end reg-end)
1303 (and ispell-highlight-p
; unhighlight
1304 (ispell-highlight-spelling-error start end
))
1307 (save-window-excursion (save-excursion
1308 (recursive-edit)) t
)
1309 (if (not (equal (marker-buffer
1310 ispell-recursive-edit-marker
)
1313 "Cannot continue ispell from this buffer."))
1314 (goto-char ispell-recursive-edit-marker
))
1315 (set-marker ispell-recursive-edit-marker nil
)))
1316 (cons word nil
)) ; recheck starting at this word.
1318 (funcall (key-binding "\C-z"))
1323 (and ispell-highlight-p
; unhighlight
1324 (save-window-excursion
1325 (select-window textwin
)
1326 (ispell-highlight-spelling-error start end
)))
1328 (set-window-dedicated-p dedicated-win t
)))))
1332 (defun ispell-show-choices (line end
)
1333 "Shows the choices in another buffer or frame."
1334 (if ispell-use-framepop-p
1336 (framepop-display-buffer (get-buffer ispell-choices-buffer
))
1337 (get-buffer-window ispell-choices-buffer t
)
1338 (select-window (previous-window))) ; *Choices* window
1339 ;; standard selection by splitting a small buffer out of this window.
1340 (let ((choices-window (get-buffer-window ispell-choices-buffer
)))
1342 (if (= line
(window-height choices-window
))
1343 (select-window choices-window
)
1344 ;; *Choices* window changed size. Adjust the choices window
1345 ;; without scrolling the spelled window when possible
1346 (let ((window-line (- line
(window-height choices-window
)))
1347 (visible (progn (vertical-motion -
1) (point))))
1348 (if (< line ispell-choices-win-default-height
)
1349 (setq window-line
(+ window-line
1350 (- ispell-choices-win-default-height
1352 (move-to-window-line 0)
1353 (vertical-motion window-line
)
1354 (set-window-start (selected-window)
1355 (if (> (point) visible
) visible
(point)))
1357 (select-window (previous-window)) ; *Choices* window
1358 (enlarge-window window-line
)))
1359 ;; Overlay *Choices* window when it isn't showing
1360 (ispell-overlay-window (max line ispell-choices-win-default-height
)))
1361 (switch-to-buffer ispell-choices-buffer
)
1362 (goto-char (point-min)))))
1366 (defun ispell-help ()
1367 "Display a list of the options available when a misspelling is encountered.
1371 DIGIT: Replace the word with a digit offered in the *Choices* buffer.
1372 SPC: Accept word this time.
1373 `i': Accept word and insert into private dictionary.
1374 `a': Accept word for this session.
1375 `A': Accept word and place in `buffer-local dictionary'.
1376 `r': Replace word with typed-in value. Rechecked.
1377 `R': Replace word with typed-in value. Query-replaced in buffer. Rechecked.
1378 `?': Show these commands.
1379 `x': Exit spelling buffer. Move cursor to original point.
1380 `X': Exit spelling buffer. Leaves cursor at the current point, and permits
1381 the aborted check to be completed later.
1382 `q': Quit spelling session (Kills ispell process).
1383 `l': Look up typed-in replacement in alternate dictionary. Wildcards okay.
1384 `u': Like `i', but the word is lower-cased first.
1385 `m': Place typed-in value in personal dictionary, then recheck current word.
1386 `C-l': redraws screen
1387 `C-r': recursive edit
1388 `C-z': suspend emacs or iconify frame"
1390 (if (equal ispell-help-in-bufferp
'electric
)
1394 (function (lambda ()
1395 ;;This shouldn't be necessary: with-electric-help needs
1396 ;; an optional argument telling it about the smallest
1397 ;; acceptable window-height of the help buffer.
1398 (if (< (window-height) 15)
1399 (enlarge-window (- 15 (window-height))))
1400 (princ "Selections are:
1402 DIGIT: Replace the word with a digit offered in the *Choices* buffer.
1403 SPC: Accept word this time.
1404 `i': Accept word and insert into private dictionary.
1405 `a': Accept word for this session.
1406 `A': Accept word and place in `buffer-local dictionary'.
1407 `r': Replace word with typed-in value. Rechecked.
1408 `R': Replace word with typed-in value. Query-replaced in buffer. Rechecked.
1409 `?': Show these commands.
1410 `x': Exit spelling buffer. Move cursor to original point.
1411 `X': Exit spelling buffer. Leaves cursor at the current point, and permits
1412 the aborted check to be completed later.
1413 `q': Quit spelling session (Kills ispell process).
1414 `l': Look up typed-in replacement in alternate dictionary. Wildcards okay.
1415 `u': Like `i', but the word is lower-cased first.
1416 `m': Place typed-in value in personal dictionary, then recheck current word.
1417 `C-l': redraws screen
1418 `C-r': recursive edit
1419 `C-z': suspend emacs or iconify frame")
1420 nil
;undocumented requirement of with-electric-help
1424 (let ((help-1 (concat "[r/R]eplace word; [a/A]ccept for this session; "
1425 "[i]nsert into private dictionary"))
1426 (help-2 (concat "[l]ook a word up in alternate dictionary; "
1427 "e[x/X]it; [q]uit session"))
1428 (help-3 (concat "[u]ncapitalized insert into dict. "
1429 "Type 'x C-h d ispell-help' for more help")))
1430 (save-window-excursion
1431 (if ispell-help-in-bufferp
1433 (ispell-overlay-window 4)
1434 (switch-to-buffer (get-buffer-create "*Ispell Help*"))
1435 (insert (concat help-1
"\n" help-2
"\n" help-3
))
1437 (kill-buffer "*Ispell Help*"))
1438 (select-window (minibuffer-window))
1439 ;;(enlarge-window 2)
1441 (cond ((string-match "Lucid\\|XEmacs" emacs-version
)
1447 (goto-char (point-min)))
1449 (if (not (string-match "18\\.[0-9]+\\.[0-9]+" emacs-version
))
1451 ;;(set-minibuffer-window (selected-window))
1453 (insert (concat help-1
"\n" help-2
"\n" help-3
))))
1458 (defun lookup-words (word &optional lookup-dict
)
1459 "Look up word in word-list dictionary.
1460 A `*' serves as a wild card. If no wild cards, `look' is used if it exists.
1461 Otherwise the variable `ispell-grep-command' contains the command used to
1462 search for the words (usually egrep).
1464 Optional second argument contains the dictionary to use; the default is
1465 `ispell-alternate-dictionary'."
1466 ;; We don't use the filter for this function, rather the result is written
1467 ;; into a buffer. Hence there is no need to save the filter values.
1468 (if (null lookup-dict
)
1469 (setq lookup-dict ispell-alternate-dictionary
))
1471 (let* ((process-connection-type ispell-use-ptys-p
)
1472 (wild-p (string-match "\\*" word
))
1473 (look-p (and ispell-look-p
; Only use look for an exact match.
1474 (or ispell-have-new-look
(not wild-p
))))
1475 (ispell-grep-buffer (get-buffer-create "*Ispell-Temp*")) ; result buf
1476 (prog (if look-p ispell-look-command ispell-grep-command
))
1477 (args (if look-p ispell-look-options ispell-grep-options
))
1480 (save-window-excursion
1481 (message "Starting \"%s\" process..." (file-name-nondirectory prog
))
1482 (set-buffer ispell-grep-buffer
)
1486 (insert "^" word
"$")
1487 (while (search-backward "*" nil t
) (insert "."))
1488 (setq word
(buffer-string))
1490 (setq status
(call-process prog nil t nil args word lookup-dict
))
1491 ;; grep returns status 1 and no output when word not found, which
1492 ;; is a perfectly normal thing.
1493 (if (stringp status
)
1494 (setq results
(cons (format "error: %s exited with signal %s"
1495 (file-name-nondirectory prog
) status
)
1497 ;; else collect words into `results' in FIFO order
1498 (goto-char (point-max))
1499 ;; assure we've ended with \n
1500 (or (bobp) (= (preceding-char) ?
\n) (insert ?
\n))
1504 (setq results
(cons (buffer-substring-no-properties (point)
1508 (kill-buffer ispell-grep-buffer
)
1509 (if (and results
(string-match ".+: " (car results
)))
1510 (error "%s error: %s" ispell-grep-command
(car results
))))
1514 ;;; "ispell-filter" is a list of output lines from the generating function.
1515 ;;; Each full line (ending with \n) is a separate item on the list.
1516 ;;; "output" can contain multiple lines, part of a line, or both.
1517 ;;; "start" and "end" are used to keep bounds on lines when "output" contains
1519 ;;; "ispell-filter-continue" is true when we have received only part of a
1520 ;;; line as output from a generating function ("output" did not end with \n)
1521 ;;; THIS FUNCTION WILL FAIL IF THE PROCESS OUTPUT DOESN'T END WITH \n!
1522 ;;; This is the case when a process dies or fails. The default behavior
1523 ;;; in this case treats the next input received as fresh input.
1525 (defun ispell-filter (process output
)
1526 "Output filter function for ispell, grep, and look."
1531 (setq end
(string-match "\n" output start
)) ; get text up to the newline.
1532 ;; If we get out of sync and ispell-filter-continue is asserted when we
1533 ;; are not continuing, treat the next item as a separate list. When
1534 ;; ispell-filter-continue is asserted, ispell-filter *should* always be a
1537 ;; Continue with same line (item)?
1538 (if (and ispell-filter-continue ispell-filter
(listp ispell-filter
))
1539 ;; Yes. Add it to the prev item
1540 (setcar ispell-filter
1541 (concat (car ispell-filter
) (substring output start end
)))
1542 ;; No. This is a new line and item.
1544 (cons (substring output start end
) ispell-filter
)))
1546 ;; We've completed reading the output, but didn't finish the line.
1547 (setq ispell-filter-continue t continue nil
)
1548 ;; skip over newline, this line complete.
1549 (setq ispell-filter-continue nil end
(1+ end
))
1550 (if (= end
(length output
)) ; No more lines in output
1551 (setq continue nil
) ; so we can exit the filter.
1552 (setq start end
)))))) ; else move start to next line of input
1555 ;;; This function destroys the mark location if it is in the word being
1557 (defun ispell-highlight-spelling-error-generic (start end
&optional highlight
1559 "Highlight the word from START to END with a kludge using `inverse-video'.
1560 When the optional third arg HIGHLIGHT is set, the word is highlighted;
1561 otherwise it is displayed normally.
1562 Uses block cursor to highlight one character.
1563 Optional REFRESH will unhighlighted then highlight, using block cursor
1564 highlighting when REFRESH is equal to `block'."
1565 (and (eq 'block ispell-highlight-p
)
1566 (or (eq 'block refresh
)
1567 (setq start
(1+ start
)))) ; On block non-refresh, inc start.
1568 (let ((modified (buffer-modified-p)) ; don't allow this fn to modify buffer
1569 (buffer-read-only nil
) ; Allow highlighting read-only buffers.
1570 (text (buffer-substring-no-properties start end
)) ; Save hilight region
1571 (inhibit-quit t
) ; inhibit interrupt processing here.
1572 (buffer-undo-list t
)) ; don't clutter the undo list.
1574 (delete-region start end
)
1575 (insert-char ?
(- end start
)) ; minimize amount of redisplay
1576 (sit-for 0) ; update display
1577 (if highlight
(setq inverse-video
(not inverse-video
))) ; toggle video
1578 (delete-region start end
) ; delete whitespace
1579 (insert text
) ; insert text in inverse video.
1580 (sit-for 0) ; update display showing inverse video.
1583 (setq inverse-video
(not inverse-video
)) ; toggle video
1584 (and (eq 'block ispell-highlight-p
)
1585 (goto-char (1- start
)))) ; use block cursor to "highlight" char
1586 (set-buffer-modified-p modified
) ; don't modify if flag not set.
1587 (and refresh
; re-highlight
1588 (ispell-highlight-spelling-error-generic
1589 (if (eq 'block refresh
) start
(- start
2)) end t
))))
1592 (defun ispell-highlight-spelling-error-xemacs (start end
&optional highlight
)
1593 "Highlight the word from START to END using `isearch-highlight'.
1594 When the optional third arg HIGHLIGHT is set, the word is highlighted,
1595 otherwise it is displayed normally."
1597 (isearch-highlight start end
)
1598 (isearch-dehighlight t
))
1603 (defun ispell-highlight-spelling-error-overlay (start end
&optional highlight
)
1604 "Highlight the word from START to END using overlays.
1605 When the optional third arg HIGHLIGHT is set, the word is highlighted
1606 otherwise it is displayed normally.
1608 The variable `ispell-highlight-face' selects the face to use for highlighting."
1611 (setq ispell-overlay
(make-overlay start end
))
1612 (overlay-put ispell-overlay
'face ispell-highlight-face
))
1613 (delete-overlay ispell-overlay
)))
1616 (defun ispell-highlight-spelling-error (start end
&optional highlight refresh
)
1618 ((string-match "Lucid\\|XEmacs" emacs-version
)
1619 (ispell-highlight-spelling-error-xemacs start end highlight
))
1620 ((and (not (string-match "18\\.[0-9]+\\.[0-9]+" emacs-version
))
1621 (featurep 'faces
) window-system
)
1622 (ispell-highlight-spelling-error-overlay start end highlight
))
1623 (t (ispell-highlight-spelling-error-generic start end highlight refresh
))))
1626 (defun ispell-overlay-window (height)
1627 "Create a window covering the top HEIGHT lines of the current window.
1628 Ensure that the line above point is still visible but otherwise avoid
1629 scrolling the current window. Leave the new window selected."
1631 (let ((oldot (save-excursion (forward-line -
1) (point)))
1632 (top (save-excursion (move-to-window-line height
) (point))))
1633 ;; If line above old point (line starting at olddot) would be
1634 ;; hidden by new window, scroll it to just below new win
1635 ;; otherwise set top line of other win so it doesn't scroll.
1636 (if (< oldot top
) (setq top oldot
))
1637 ;; NB: XEmacs 19.9 bug: If a window of size N (N includes the mode
1638 ;; line) is demanded, the last line is not visible.
1639 ;; At least this happens on AIX 3.2, XEmacs w/ Motif, font 9x15.
1640 ;; So we increment the height for this case.
1641 (if (and (string-match "Lucid\\|XEmacs" emacs-version
)
1642 (string-match "19\\.9\\.[0-9]+" emacs-version
))
1643 (setq height
(1+ height
)))
1644 ;; if frame is unsplitable, temporarily disable that...
1645 (if (cdr (assq 'unsplittable
(frame-parameters (selected-frame))))
1646 (let ((frame (selected-frame)))
1647 (modify-frame-parameters frame
'((unsplittable . nil
)))
1648 (split-window nil height
)
1649 (modify-frame-parameters frame
'((unsplittable . t
))))
1650 (split-window nil height
))
1651 (set-window-start (next-window) top
))))
1654 ;;; Should we add a compound word match return value?
1655 (defun ispell-parse-output (output)
1656 "Parse the OUTPUT string from Ispell process and return:
1657 1: t for an exact match.
1658 2: A string containing the root word matched via suffix removal.
1659 3: A list of possible correct spellings of the format:
1660 (\"ORIGINAL-WORD\" OFFSET MISS-LIST GUESS-LIST)
1661 ORIGINAL-WORD is a string of the possibly misspelled word.
1662 OFFSET is an integer giving the line offset of the word.
1663 MISS-LIST and GUESS-LIST are possibly null lists of guesses and misses.
1664 4: Nil when an error has occurred."
1666 ((string= output
"") t
) ; for startup with pipes...
1667 ((string= output
"*") t
) ; exact match
1668 ((string= output
"-") t
) ; compound word match
1669 ((string= (substring output
0 1) "+") ; found because of root word
1670 (substring output
2)) ; return root word
1671 ((equal 0 (string-match "[\
a-zA-Z]" output
))
1672 (ding) ; error message from ispell!
1673 (message (concat "Ispell error: " output
))
1676 (t ; need to process &, ?, and #'s
1677 (let ((type (substring output
0 1)) ; &, ?, or #
1678 (original-word (substring output
2 (string-match " " output
2)))
1679 (cur-count 0) ; contains number of misses + guesses
1680 count miss-list guess-list offset
)
1681 (setq output
(substring output
(match-end 0))) ; skip over misspelling
1682 (if (string= type
"#")
1683 (setq count
0) ; no misses for type #
1684 (setq count
(string-to-int output
) ; get number of misses.
1685 output
(substring output
(1+ (string-match " " output
1)))))
1686 (setq offset
(string-to-int output
))
1687 (if (string= type
"#") ; No miss or guess list.
1689 (setq output
(substring output
(1+ (string-match " " output
1)))))
1691 (let ((end (string-match ", \\|\\($\\)" output
))) ; end of miss/guess.
1692 (setq cur-count
(1+ cur-count
))
1693 (if (> cur-count count
)
1694 (setq guess-list
(cons (substring output
0 end
) guess-list
))
1695 (setq miss-list
(cons (substring output
0 end
) miss-list
)))
1696 (if (match-end 1) ; True only when at end of line.
1697 (setq output nil
) ; no more misses or guesses
1698 (setq output
(substring output
(+ end
2))))))
1699 (list original-word offset miss-list guess-list
)))))
1702 (defun check-ispell-version (&optional interactivep
)
1703 ;; This is a little wasteful as we actually launch ispell twice: once
1704 ;; to make sure it's the right version, and once for real. But people
1705 ;; get confused by version mismatches *all* the time (and I've got the
1706 ;; email to prove it) so I think this is worthwhile. And the -v[ersion]
1707 ;; option is the only way I can think of to do this that works with
1708 ;; all versions, since versions earlier than 3.0.09 didn't identify
1709 ;; themselves on startup.
1712 (let (case-fold-search status
1713 ;; avoid bugs when syntax of `.' changes in various default modes
1714 (default-major-mode 'fundamental-mode
)
1716 (set-buffer (get-buffer-create " *ispell-tmp*"))
1717 (setq case-fold-search t
)
1719 (setq status
(call-process ispell-program-name nil t nil
"-v"))
1720 (goto-char (point-min))
1724 (setq result
(concat (buffer-substring-no-properties (point-min)
1729 (goto-char (point-min))))
1730 (if (not (memq status
'(0 nil
)))
1731 (error "%s exited with %s %s" ispell-program-name
1732 (if (stringp status
) "signal" "code") status
))
1733 (if (not (re-search-forward
1735 (regexp-quote (car ispell-required-version
))
1736 "\\)\\([0-9]*\\)\\>")
1738 (error "%s version 3 release %s%s or greater is required"
1739 ispell-program-name
(car ispell-required-version
)
1740 (car (cdr ispell-required-version
)))
1741 ;; check that it is the correct version.
1742 (if (< (car (read-from-string (buffer-substring-no-properties
1743 (match-beginning 2) (match-end 2))))
1744 (car (cdr ispell-required-version
)))
1745 (setq ispell-offset
0)))
1746 (kill-buffer (current-buffer))
1750 (defun ispell-init-process ()
1751 "Check status of Ispell process and start if necessary."
1752 (if (and ispell-process
1753 (eq (process-status ispell-process
) 'run
)
1754 ;; If we're using a personal dictionary, assure
1755 ;; we're in the same default directory!
1756 (or (not ispell-personal-dictionary
)
1757 (equal ispell-process-directory default-directory
)))
1758 (setq ispell-filter nil ispell-filter-continue nil
)
1759 ;; may need to restart to select new personal dictionary.
1760 (ispell-kill-ispell t
)
1761 (message "Starting new Ispell process...")
1763 (check-ispell-version)
1764 (setq ispell-process
1765 (let ((process-connection-type ispell-use-ptys-p
))
1766 (apply 'start-process
1767 "ispell" nil ispell-program-name
1768 "-a" ; accept single input lines
1769 "-m" ; make root/affix combos not in dict
1771 ;; Local dictionary becomes the global dictionary in use.
1772 (if ispell-local-dictionary
1773 (setq ispell-dictionary ispell-local-dictionary
))
1774 (setq args
(ispell-get-ispell-args))
1775 (if ispell-dictionary
; use specified dictionary
1777 (append (list "-d" ispell-dictionary
) args
)))
1778 (if ispell-personal-dictionary
; use specified pers dict
1783 ispell-personal-dictionary
)))))
1784 (setq args
(append args ispell-extra-args
))
1787 ispell-filter-continue nil
1788 ispell-process-directory default-directory
)
1789 (set-process-filter ispell-process
'ispell-filter
)
1790 (if (and (boundp 'enable-multibyte-characters
)
1791 (fboundp 'set-process-coding-system
)
1792 enable-multibyte-characters
)
1793 (set-process-coding-system ispell-process
(ispell-get-coding-system)))
1794 ;; Get version ID line
1795 (if (not (string-match "18\\.[0-9]+\\.[0-9]+" emacs-version
))
1796 (accept-process-output ispell-process
5)
1797 (accept-process-output ispell-process
))
1798 ;; get more output if filter empty?
1799 (if (null ispell-filter
) (accept-process-output ispell-process
5))
1800 (cond ((null ispell-filter
)
1801 (error "%s did not output version line" ispell-program-name
))
1803 (stringp (car ispell-filter
))
1804 (if (string-match "warning: " (car ispell-filter
))
1806 (if (not (string-match "18\\.[0-9]+\\.[0-9]+" emacs-version
))
1807 (accept-process-output ispell-process
5) ; was warn msg.
1808 (accept-process-output ispell-process
))
1809 (stringp (car ispell-filter
)))
1810 (null (cdr ispell-filter
)))
1811 (string-match "^@(#) " (car ispell-filter
)))
1812 ;; got the version line as expected (we already know it's the right
1813 ;; version, so don't bother checking again.)
1816 ;; Otherwise, it must be an error message. Show the user.
1817 ;; But first wait to see if some more output is going to arrive.
1818 ;; Otherwise we get cool errors like "Can't open ".
1820 (accept-process-output)
1821 (error "%s" (mapconcat 'identity ispell-filter
"\n"))))
1822 (setq ispell-filter nil
) ; Discard version ID line
1823 (let ((extended-char-mode (ispell-get-extended-character-mode)))
1824 (if extended-char-mode
1825 (process-send-string ispell-process
1826 (concat extended-char-mode
"\n"))))
1827 (process-kill-without-query ispell-process
)))
1830 (defun ispell-kill-ispell (&optional no-error
)
1831 "Kill current Ispell process (so that you may start a fresh one).
1832 With NO-ERROR, just return non-nil if there was no Ispell running."
1834 (if (not (and ispell-process
1835 (eq (process-status ispell-process
) 'run
)))
1837 (error "There is no ispell process running!"))
1838 (kill-process ispell-process
)
1839 (setq ispell-process nil
)
1840 (message "Ispell process killed")
1844 ;;; ispell-change-dictionary is set in some people's hooks. Maybe this should
1845 ;;; call ispell-init-process rather than wait for a spell checking command?
1848 (defun ispell-change-dictionary (dict &optional arg
)
1849 "Change `ispell-dictionary' (q.v.) and kill old Ispell process.
1850 A new one will be started as soon as necessary.
1852 By just answering RET you can find out what the current dictionary is.
1854 With prefix argument, set the default directory."
1856 (list (completing-read
1857 "Use new dictionary (RET for current, SPC to complete): "
1858 (cons (cons "default" nil
) ispell-dictionary-alist
) nil t
)
1859 current-prefix-arg
))
1860 (if (equal dict
"default") (setq dict nil
))
1861 ;; This relies on completing-read's bug of returning "" for no match
1862 (cond ((equal dict
"")
1863 (message "Using %s dictionary"
1864 (or ispell-local-dictionary ispell-dictionary
"default")))
1865 ((and (equal dict ispell-dictionary
)
1866 (or (null ispell-local-dictionary
)
1867 (equal dict ispell-local-dictionary
)))
1868 ;; Specified dictionary is the default already. No-op
1869 (and (interactive-p)
1870 (message "No change, using %s dictionary" (or dict
"default"))))
1871 (t ; reset dictionary!
1872 (if (assoc dict ispell-dictionary-alist
)
1874 (if (or arg
(null dict
)) ; set default dictionary
1875 (setq ispell-dictionary dict
))
1876 (if (null arg
) ; set local dictionary
1877 (setq ispell-local-dictionary dict
)))
1878 (error "Undefined dictionary: %s" dict
))
1879 (ispell-kill-ispell t
)
1880 (message "(Next %sIspell command will use %s dictionary)"
1881 (cond ((equal ispell-local-dictionary ispell-dictionary
)
1885 (or (if (or (equal ispell-local-dictionary ispell-dictionary
)
1887 ispell-local-dictionary
1892 ;;; Spelling of comments are checked when ispell-check-comments is non-nil.
1895 (defun ispell-region (reg-start reg-end
)
1896 "Interactively check a region for spelling errors.
1897 Return non-nil if not aborted."
1898 (interactive "r") ; Don't flag errors on read-only bufs.
1899 (ispell-accept-buffer-local-defs) ; set up dictionary, local words, etc.
1902 (message "Spell checking %s using %s dictionary..."
1903 (if (and (= reg-start
(point-min)) (= reg-end
(point-max)))
1904 (buffer-name) "region")
1905 (or ispell-dictionary
"default"))
1906 ;; Returns cursor to original location.
1907 (save-window-excursion
1908 (goto-char reg-start
)
1909 (let ((transient-mark-mode nil
)
1910 (case-fold-search case-fold-search
)
1911 (skip-region-start (make-marker))
1912 (skip-regexp (ispell-begin-skip-region-regexp))
1913 (skip-alist ispell-skip-region-alist
)
1915 (if (eq ispell-parser
'tex
)
1916 (setq case-fold-search nil
1918 (append (car ispell-tex-skip-alists
)
1919 (car (cdr ispell-tex-skip-alists
))
1921 (let (message-log-max)
1922 (message "searching for regions to skip"))
1923 (if (re-search-forward skip-regexp reg-end t
)
1925 (setq key
(buffer-substring-no-properties
1926 (match-beginning 0) (match-end 0)))
1927 (set-marker skip-region-start
(- (point) (length key
)))
1928 (goto-char reg-start
)))
1929 (let (message-log-max)
1930 (message "Continuing spelling check using %s dictionary..."
1931 (or ispell-dictionary
"default")))
1932 (set-marker ispell-region-end reg-end
)
1933 (while (and (not ispell-quit
)
1934 (< (point) ispell-region-end
))
1935 ;; spell-check region with skipping
1936 (if (and (marker-position skip-region-start
)
1937 (<= skip-region-start
(point)))
1939 (ispell-skip-region key skip-alist
) ; moves pt past region.
1940 (setq reg-start
(point))
1941 (if (and (< reg-start ispell-region-end
)
1942 (re-search-forward skip-regexp
1943 ispell-region-end t
))
1945 (setq key
(buffer-substring-no-properties
1947 (car (cdr (match-data)))))
1948 (set-marker skip-region-start
1949 (- (point) (length key
)))
1950 (goto-char reg-start
))
1951 (set-marker skip-region-start nil
))))
1952 (setq reg-end
(if (marker-position skip-region-start
)
1953 (min skip-region-start ispell-region-end
)
1954 (marker-position ispell-region-end
)))
1955 (let* ((start (point))
1956 (end (save-excursion (end-of-line) (min (point) reg-end
)))
1957 (string (ispell-get-line start end reg-end
)))
1958 (setq end
(point)) ; "end" tracks region retrieved.
1959 (if string
; there is something to spell check!
1960 (ispell-process-line string
)) ; (special start end)
1965 (if (get-buffer ispell-choices-buffer
)
1966 (kill-buffer ispell-choices-buffer
))
1969 ;; preserve or clear the region for ispell-continue.
1970 (if (not (numberp ispell-quit
))
1971 (set-marker ispell-region-end nil
)
1972 ;; Ispell-continue enabled - ispell-region-end is set.
1973 (goto-char ispell-quit
))
1974 ;; Check for aborting
1975 (if (and ispell-checking-message
(numberp ispell-quit
))
1977 (setq ispell-quit nil
)
1978 (error "Message send aborted.")))
1979 (setq ispell-quit nil
))
1980 (set-marker ispell-region-end nil
)
1981 ;; Only save if successful exit.
1982 (ispell-pdict-save ispell-silently-savep
)
1983 (message "Spell-checking done"))))
1986 ;;; Creates the regexp for skipping a region.
1987 ;;; Makes the skip-regexp local for tex buffers adding in the
1988 ;;; tex expressions to skip as well.
1989 ;;; Call AFTER ispell-buffer-local-parsing.
1990 (defun ispell-begin-skip-region-regexp ()
1991 (let ((skip-regexp (ispell-begin-skip-region)))
1992 (if (and (null ispell-check-comments
) comment-start
)
1993 (setq skip-regexp
(concat (regexp-quote comment-start
) "\\|"
1995 (if (and (eq 'exclusive ispell-check-comments
) comment-start
)
1996 (setq skip-regexp
(concat (if (string= "" comment-end
) "^"
1997 (regexp-quote comment-end
))
1998 "\\|" skip-regexp
)))
2000 (setq skip-regexp
(concat ispell-tib-ref-beginning
"\\|" skip-regexp
)))
2001 (if ispell-skip-sgml
2002 (setq skip-regexp
(concat "[<&]\\|" skip-regexp
)))
2003 (if (eq ispell-parser
'tex
)
2004 (setq skip-regexp
(concat (ispell-begin-tex-skip-regexp) "\\|"
2009 ;;; Regular expression of tex commands to skip.
2010 ;;; Generated from `ispell-tex-skip-alists'
2011 (defun ispell-begin-tex-skip-regexp ()
2013 (mapconcat (function (lambda (lst) (car lst
)))
2014 (car ispell-tex-skip-alists
)
2017 (mapconcat (function (lambda (lst)
2018 (concat "\\\\begin[ \t\n]*{[ \t\n]*"
2021 (car (cdr ispell-tex-skip-alists
))
2025 ;;; Regular expression of regions to skip for all buffers.
2026 ;;; Each selection should be a key of `ispell-skip-region-alist'
2027 ;;; otherwise, the current line is skipped.
2028 (defun ispell-begin-skip-region ()
2029 (mapconcat (function (lambda (lst) (if (stringp (car lst
)) (car lst
)
2031 ispell-skip-region-alist
2035 (defun ispell-tex-arg-end (&optional arg
)
2038 (while (looking-at "[ \t\n]*\\[") (forward-sexp))
2039 (forward-sexp (or arg
1)))
2041 (message "error skipping s-expressions at point %d." (point))
2046 ;;; Skips to region-end from point, or a single line.
2047 ;;; Places point at end of region skipped.
2048 (defun ispell-skip-region (key alist
)
2049 ;; move over key to begin checking.
2050 (forward-char (length key
))
2051 (let ((start (point))
2052 alist-key null-skip
)
2054 ;; what about quoted comment, or comment inside strings?
2055 ((and (null ispell-check-comments
) comment-start
2056 (string= key comment-start
))
2057 (if (string= "" comment-end
)
2059 (search-forward comment-end ispell-region-end t
)))
2060 ((and (eq 'exclusive ispell-check-comments
) comment-start
2061 (string= key comment-end
))
2062 (search-forward comment-start ispell-region-end
:end
))
2063 ((and ispell-skip-tib
(string-match ispell-tib-ref-beginning key
))
2064 (re-search-forward ispell-tib-ref-end ispell-region-end t
))
2065 ((and ispell-skip-sgml
(string-match "<" key
))
2066 (search-forward ">" ispell-region-end t
))
2067 ((and ispell-skip-sgml
(string-match "&" key
))
2068 (search-forward ";" ispell-region-end t
))
2069 ;; markings from alist
2072 (setq alist-key
(eval (car (car alist
))))
2073 (if (string-match alist-key key
)
2075 (setq alist
(cdr (car alist
)))
2077 ((null alist
) (setq null-skip t
)) ; done! Just skip key.
2078 ((not (consp alist
))
2079 ;; Search past end of spell region to find this region end.
2080 (re-search-forward (eval alist
) (point-max) t
))
2083 (re-search-forward alist
(point-max) t
)
2084 (setq null-skip t
) ; error handling in functions!
2085 (if (consp (cdr alist
))
2086 (apply (car alist
) (cdr alist
))
2087 (funcall (car alist
))))))
2089 (setq alist
(cdr alist
))))))
2090 (if (and (= start
(point)) (null null-skip
))
2092 (message "Matching region end for `%s' point %d not found"
2098 ;;; Grab the next line of data.
2099 ;;; Returns a string with the line data
2100 (defun ispell-get-line (start end reg-end
)
2101 (let ((ispell-casechars (ispell-get-casechars))
2103 (cond ; LOOK AT THIS LINE AND SKIP OR PROCESS
2104 ((eolp) ; END OF LINE, just go to next line.
2106 ((looking-at "[---#@*+!%~^]") ; SKIP SPECIAL ISPELL CHARACTERS
2108 ((or (re-search-forward ispell-casechars end t
) ; TEXT EXISTS
2109 (re-search-forward "[][()${}]" end t
)) ; or MATH COMMANDS
2110 (setq string
(concat "^" (buffer-substring-no-properties start end
)
2113 (t (goto-char end
))) ; EMPTY LINE, skip it.
2117 (defun ispell-process-line (string)
2118 ;;(declare special start end)
2120 ;; send string to spell process and get input.
2121 (process-send-string ispell-process string
)
2123 (accept-process-output ispell-process
)
2124 ;; Last item of output contains a blank line.
2125 (not (string= "" (car ispell-filter
)))))
2126 ;; parse all inputs from the stream one word at a time.
2127 ;; Place in FIFO order and remove the blank item.
2128 (setq ispell-filter
(nreverse (cdr ispell-filter
)))
2129 (while (and (not ispell-quit
) ispell-filter
)
2130 (setq poss
(ispell-parse-output (car ispell-filter
)))
2131 (if (and poss
(listp poss
)) ; spelling error occurred.
2132 ;; Whenever we have misspellings, we can change
2133 ;; the buffer. Keep boundaries as markers.
2134 ;; Markers can move with highlighting! This destroys
2135 ;; end of region markers line-end and ispell-region-end
2138 (if (and (boundp 'enable-multibyte-characters
)
2139 enable-multibyte-characters
2140 (ispell-get-coding-system))
2141 ;; skip over multibyte characters correctly
2143 (goto-char (+ start ispell-offset
))
2144 (forward-char (car (cdr poss
)))
2146 (+ start ispell-offset
(car (cdr poss
))))))
2147 (word-len (length (car poss
)))
2148 (line-end (copy-marker end
))
2149 (line-start (copy-marker start
))
2150 recheck-region replace
)
2151 (goto-char word-start
)
2152 ;; Adjust the horizontal scroll & point
2153 (ispell-horiz-scroll)
2154 (goto-char (+ word-len word-start
))
2155 (ispell-horiz-scroll)
2156 (goto-char word-start
)
2157 (ispell-horiz-scroll)
2158 (if (/= (+ word-len
(point))
2160 (search-forward (car poss
) (+ word-len
(point)) t
)
2162 ;; This occurs due to filter pipe problems
2163 (error (concat "Ispell misalignment: word "
2164 "`%s' point %d; probably incompatible versions")
2165 (car poss
) (marker-position word-start
)))
2167 ;; ispell-cmd-loop can go recursive & change buffer
2168 (if ispell-keep-choices-win
2169 (setq replace
(ispell-command-loop
2170 (car (cdr (cdr poss
)))
2171 (car (cdr (cdr (cdr poss
))))
2172 (car poss
) (marker-position word-start
)
2173 (+ word-len
(marker-position word-start
))))
2174 (save-window-excursion
2175 (setq replace
(ispell-command-loop
2176 (car (cdr (cdr poss
)))
2177 (car (cdr (cdr (cdr poss
))))
2178 (car poss
) (marker-position word-start
)
2179 (+ word-len
(marker-position word-start
))))))
2181 ;; Recheck when recursive edit changes misspelled word
2182 (goto-char word-start
)
2183 (if (not (string-equal (buffer-substring-no-properties
2184 (point) (+ word-len
(point)))
2187 (set-marker line-end
(point))
2188 (setq ispell-filter nil
2192 ((and replace
(listp replace
))
2194 ;; Recheck line starting with the replacement word.
2195 (setq ispell-filter nil
2197 (delete-region (point) (+ word-len
(point)))
2198 (insert (car replace
))
2199 ;; Only typed-in replacements need to be re-checked.
2200 (if (not (eq 'query-replace
(car (cdr replace
))))
2201 (backward-char (length (car replace
))))
2202 (set-marker line-end
(point)) ; continue checking from here.
2203 (if (car (cdr replace
))
2205 (save-window-excursion
2206 (delete-other-windows) ; to correctly show help.
2207 ;; Assume case-replace &
2208 ;; case-fold-search correct?
2209 (query-replace (car poss
) (car replace
) t
))
2210 (goto-char word-start
))))
2212 (equal 0 replace
)) ; ACCEPT/INSERT
2213 (if (equal 0 replace
) ; BUFFER-LOCAL DICT ADD
2214 (ispell-add-per-file-word-list (car poss
)))
2215 ;; This avoids pointing out the word that was
2216 ;; just accepted (via 'i' or 'a') if it follows
2217 ;; on the same line.
2218 ;; Redo check following the accepted word.
2219 (if (and ispell-pdict-modified-p
2220 (listp ispell-pdict-modified-p
))
2221 ;; Word accepted. Recheck line.
2223 (setq ispell-pdict-modified-p
;update flag
2224 (car ispell-pdict-modified-p
)
2227 (set-marker line-end
(marker-position word-start
)))))
2228 (replace ; STRING REPLACEMENT for this word.
2229 (delete-region (point) (+ word-len
(point)))
2231 (set-marker line-start
(+ line-start
2233 (length (car poss
)))))))
2234 (if (not ispell-quit
)
2235 (let (message-log-max)
2236 (message "Continuing spelling check using %s dictionary..."
2237 (or ispell-dictionary
"default"))))
2239 (setq start
(marker-position line-start
)
2240 end
(marker-position line-end
))
2241 ;; Adjust markers when end of region lost from highlighting.
2242 (if (and (not recheck-region
) (< end
(+ word-start word-len
)))
2243 (setq end
(+ word-start word-len
)))
2244 (if (= word-start ispell-region-end
)
2245 (set-marker ispell-region-end
(+ word-start word-len
)))
2246 ;; going out of scope - unneeded
2247 (set-marker line-start nil
)
2248 (set-marker word-start nil
)
2249 (set-marker line-end nil
)))
2250 ;; finished with misspelling!
2251 (setq ispell-filter
(cdr ispell-filter
)))))
2255 (defun ispell-comments-and-strings ()
2256 "Check comments and strings in the current buffer for spelling errors."
2258 (goto-char (point-min))
2262 (setq state
(parse-partial-sexp (point) (point-max)
2263 nil nil state
'syntax-table
))
2264 (when (or (nth 3 state
) (nth 4 state
))
2265 (let ((start (point)))
2266 (setq state
(parse-partial-sexp start
(point-max)
2267 nil nil state
'syntax-table
))
2268 (when (or (nth 3 state
) (nth 4 state
))
2269 (error "Unterminated string or comment."))
2271 (setq done
(not (ispell-region start
(point))))))))))
2275 (defun ispell-buffer ()
2276 "Check the current buffer for spelling errors interactively."
2278 (ispell-region (point-min) (point-max)))
2282 (defun ispell-continue ()
2284 "Continue a halted spelling session beginning with the current word."
2285 (if (not (marker-position ispell-region-end
))
2286 (message "No session to continue. Use 'X' command when checking!")
2287 (if (not (equal (marker-buffer ispell-region-end
) (current-buffer)))
2288 (message "Must continue ispell from buffer %s"
2289 (buffer-name (marker-buffer ispell-region-end
)))
2291 ;; find beginning of current word:
2292 (car (cdr (ispell-get-word t
)))
2293 (marker-position ispell-region-end
)))))
2296 ;;; Horizontal scrolling
2297 (defun ispell-horiz-scroll ()
2298 "Places point within the horizontal visibility of its window area."
2299 (if truncate-lines
; display truncating lines?
2300 ;; See if display needs to be scrolled.
2301 (let ((column (- (current-column) (max (window-hscroll) 1))))
2302 (if (and (< column
0) (> (window-hscroll) 0))
2303 (scroll-right (max (- column
) 10))
2304 (if (>= column
(- (window-width) 2))
2305 (scroll-left (max (- column
(window-width) -
3) 10)))))))
2308 ;;; Interactive word completion.
2309 ;;; Forces "previous-word" processing. Do we want to make this selectable?
2312 (defun ispell-complete-word (&optional interior-frag
)
2313 "Look up word before or under point in dictionary (see lookup-words command)
2314 and try to complete it. If optional INTERIOR-FRAG is non-nil then the word
2315 may be a character sequence inside of a word.
2317 Standard ispell choices are then available."
2319 (let ((cursor-location (point))
2321 (word (ispell-get-word nil
"\\*")) ; force "previous-word" processing.
2322 start end possibilities replacement
)
2323 (setq start
(car (cdr word
))
2324 end
(car (cdr (cdr word
)))
2327 (or (string= word
"") ; Will give you every word
2328 (lookup-words (concat (and interior-frag
"*") word
2329 (if (or interior-frag
(null ispell-look-p
))
2331 ispell-complete-word-dict
)))
2332 (cond ((eq possibilities t
)
2333 (message "No word to complete"))
2334 ((null possibilities
)
2335 (message "No match for \"%s\"" word
))
2336 (t ; There is a modification...
2337 (cond ; Try and respect case of word.
2338 ((string-match "^[^A-Z]+$" word
)
2339 (setq possibilities
(mapcar 'downcase possibilities
)))
2340 ((string-match "^[^a-z]+$" word
)
2341 (setq possibilities
(mapcar 'upcase possibilities
)))
2342 ((string-match "^[A-Z]" word
)
2343 (setq possibilities
(mapcar 'capitalize possibilities
))))
2344 (save-window-excursion
2346 (ispell-command-loop possibilities nil word start end
)))
2348 ((equal 0 replacement
) ; BUFFER-LOCAL ADDITION
2349 (ispell-add-per-file-word-list word
))
2350 (replacement ; REPLACEMENT WORD
2351 (delete-region start end
)
2352 (setq word
(if (atom replacement
) replacement
(car replacement
))
2353 cursor-location
(+ (- (length word
) (- end start
))
2356 (if (not (atom replacement
)) ; recheck spelling of replacement.
2358 (goto-char cursor-location
)
2359 (ispell-word nil t
)))))
2360 (if (get-buffer ispell-choices-buffer
)
2361 (kill-buffer ispell-choices-buffer
))))
2362 (ispell-pdict-save ispell-silently-savep
)
2363 (goto-char cursor-location
)))
2367 (defun ispell-complete-word-interior-frag ()
2368 "Completes word matching character sequence inside a word."
2370 (ispell-complete-word t
))
2373 ;;; **********************************************************************
2374 ;;; Ispell Minor Mode
2375 ;;; **********************************************************************
2377 (defvar ispell-minor-mode nil
2378 "Non-nil if Ispell minor mode is enabled.")
2379 ;; Variable indicating that ispell minor mode is active.
2380 (make-variable-buffer-local 'ispell-minor-mode
)
2382 (or (assq 'ispell-minor-mode minor-mode-alist
)
2383 (setq minor-mode-alist
2384 (cons '(ispell-minor-mode " Spell") minor-mode-alist
)))
2386 (defvar ispell-minor-keymap
2387 (let ((map (make-sparse-keymap)))
2388 (define-key map
" " 'ispell-minor-check
)
2389 (define-key map
"\r" 'ispell-minor-check
)
2391 "Keymap used for Ispell minor mode.")
2393 (or (not (boundp 'minor-mode-map-alist
))
2394 (assoc 'ispell-minor-mode minor-mode-map-alist
)
2395 (setq minor-mode-map-alist
2396 (cons (cons 'ispell-minor-mode ispell-minor-keymap
)
2397 minor-mode-map-alist
)))
2400 (defun ispell-minor-mode (&optional arg
)
2401 "Toggle Ispell minor mode.
2402 With prefix arg, turn Ispell minor mode on iff arg is positive.
2404 In Ispell minor mode, pressing SPC or RET
2405 warns you if the previous word is incorrectly spelled.
2407 All the buffer-local variables and dictionaries are ignored -- to read
2408 them into the running ispell process, type \\[ispell-word] SPC."
2410 (setq ispell-minor-mode
2411 (not (or (and (null arg
) ispell-minor-mode
)
2412 (<= (prefix-numeric-value arg
) 0))))
2413 (force-mode-line-update))
2415 (defun ispell-minor-check ()
2416 "Check previous word then continue with the normal binding of this key.
2417 Don't check previous word when character before point is a space or newline.
2418 Don't read buffer-local settings or word lists."
2420 (let ((ispell-minor-mode nil
)
2421 (ispell-check-only t
)
2422 (last-char (char-after (1- (point)))))
2423 (if (or (eq last-char ?\
) (eq last-char ?
\n))
2425 (save-window-excursion
2427 (narrow-to-region (save-excursion (forward-line -
1) (point)) (point))
2428 (ispell-word nil t
))))
2429 (call-interactively (key-binding (this-command-keys)))))
2432 ;;; **********************************************************************
2434 ;;; **********************************************************************
2435 ;;; Original from D. Quinlan, E. Bradford, A. Albert, and M. Ernst
2438 (defvar ispell-message-text-end
2439 (mapconcat (function identity
)
2441 ;; Don't spell check signatures
2443 ;; Matches postscript files.
2444 "^%!PS-Adobe-[123].0"
2445 ;; Matches uuencoded text
2446 "^begin [0-9][0-9][0-9] .*\nM.*\nM.*\nM"
2447 ;; Matches shell files (esp. auto-decoding)
2449 ;; Matches context difference listing
2450 "\\(\\(^cd .*\n\\)?diff -c .*\\)?\n\\*\\*\\* .*\n--- .*\n\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*"
2451 ;; Matches unidiff difference listing
2452 "\\(diff -u .*\\)?\n--- .*\n\\+\\+\\+ .*\n@@ [-+][0-9]+,[0-9]+ [-+][0-9]+,[0-9]+ @@\n"
2453 ;; Matches reporter.el bug report
2454 "^current state:\n==============\n"
2455 ;; Matches commonly used "cut" boundaries
2456 "^\\(- \\)?[-=_]+\\s ?\\(cut here\\|Environment Follows\\)")
2458 "*End of text which will be checked in ispell-message.
2459 If it is a string, limit at first occurrence of that regular expression.
2460 Otherwise, it must be a function which is called to get the limit.")
2465 (defun ispell-message ()
2466 "Check the spelling of a mail message or news post.
2467 Don't check spelling of message headers except the Subject field.
2468 Don't check included messages.
2470 To abort spell checking of a message region and send the message anyway,
2471 use the `x' command. (Any subsequent regions will be checked.)
2472 The `X' command aborts the message send so that you can edit the buffer.
2474 To spell-check whenever a message is sent, include the appropriate lines
2475 in your .emacs file:
2476 (add-hook 'message-send-hook 'ispell-message) ;; GNUS 5
2477 (add-hook 'news-inews-hook 'ispell-message) ;; GNUS 4
2478 (add-hook 'mail-send-hook 'ispell-message)
2479 (add-hook 'mh-before-send-letter-hook 'ispell-message)
2481 You can bind this to the key C-c i in GNUS or mail by adding to
2482 `news-reply-mode-hook' or `mail-mode-hook' the following lambda expression:
2483 (function (lambda () (local-set-key \"\\C-ci\" 'ispell-message)))"
2486 (goto-char (point-min))
2488 ;; Nil when message came from outside (eg calling emacs as editor)
2489 ;; Non-nil marker of end of headers.
2492 (concat "^" (regexp-quote mail-header-separator
) "$") nil t
))
2493 (end-of-headers ; Start of body.
2495 (or internal-messagep
2496 (re-search-forward "^$" nil t
)
2498 (limit (copy-marker ; End of region we will spell check.
2500 ((not ispell-message-text-end
) (point-max))
2501 ((char-or-string-p ispell-message-text-end
)
2502 (if (re-search-forward ispell-message-text-end nil t
)
2505 (t (min (point-max) (funcall ispell-message-text-end
))))))
2506 (default-prefix ; Vanilla cite prefix (just used for cite-regexp)
2507 (if (and (boundp 'mail-yank-prefix
) mail-yank-prefix
)
2508 (ispell-non-empty-string mail-yank-prefix
)
2510 (cite-regexp ;Prefix of quoted text
2512 ((featurep 'supercite
) ; sc 3.0
2513 (concat "\\(" (sc-cite-regexp) "\\)" "\\|"
2514 (ispell-non-empty-string sc-reference-tag-string
)))
2515 ((featurep 'sc
) ; sc 2.3
2516 (concat "\\(" sc-cite-regexp
"\\)" "\\|"
2517 (ispell-non-empty-string sc-reference-tag-string
)))
2518 ((or (equal major-mode
'news-reply-mode
) ;GNUS 4 & below
2519 (equal major-mode
'message-mode
)) ;GNUS 5
2520 (concat "In article <" "\\|"
2521 "[^,;&+=]+ <[^,;&+=]+> writes:" "\\|"
2523 ((equal major-mode
'mh-letter-mode
) ; mh mail message
2524 (ispell-non-empty-string mh-ins-buf-prefix
))
2525 ((not internal-messagep
) ; Assume nn sent us this message.
2526 (concat "In [a-zA-Z.]+ you write:" "\\|"
2527 "In <[^,;&+=]+> [^,;&+=]+ writes:" "\\|"
2529 ((boundp 'vm-included-text-prefix
) ; VM mail message
2530 (concat "[^,;&+=]+ writes:" "\\|"
2531 (ispell-non-empty-string vm-included-text-prefix
)))
2532 (t default-prefix
)))
2533 (ispell-skip-region-alist
2534 (cons (list (concat "^\\(" cite-regexp
"\\)")
2535 (function forward-line
))
2536 ispell-skip-region-alist
))
2537 (old-case-fold-search case-fold-search
)
2538 (case-fold-search t
)
2539 (dictionary-alist ispell-message-dictionary-alist
)
2540 (ispell-checking-message t
))
2542 ;; Select dictionary for message
2543 (or (local-variable-p 'ispell-local-dictionary
(current-buffer))
2544 (while dictionary-alist
2545 (goto-char (point-min))
2546 (if (re-search-forward (car (car dictionary-alist
))
2548 (setq ispell-local-dictionary
(cdr (car dictionary-alist
))
2549 dictionary-alist nil
)
2550 (setq dictionary-alist
(cdr dictionary-alist
)))))
2554 ;; Spell check any original Subject:
2555 (goto-char (point-min))
2556 (if (re-search-forward "^Subject: *" end-of-headers t
)
2558 (goto-char (match-end 0))
2559 (if (and (not (looking-at ".*Re\\>"))
2560 (not (looking-at "\\[")))
2561 (let ((case-fold-search old-case-fold-search
))
2562 (ispell-region (point)
2563 (progn ;Tab-initiated continuation lns.
2565 (while (looking-at "\n[ \t]")
2568 (goto-char end-of-headers
)
2570 (ispell-region (point) limit
))
2571 (set-marker end-of-headers nil
)
2572 (set-marker limit nil
)))))
2575 (defun ispell-non-empty-string (string)
2576 (if (or (not string
) (string-equal string
""))
2577 "\\'\\`" ; An unmatchable string if string is null.
2578 (regexp-quote string
)))
2581 ;;; **********************************************************************
2582 ;;; Buffer Local Functions
2583 ;;; **********************************************************************
2586 (defun ispell-accept-buffer-local-defs ()
2587 "Load all buffer-local information, restarting Ispell when necessary."
2588 (ispell-buffer-local-dict) ; May kill ispell-process.
2589 (ispell-buffer-local-words) ; Will initialize ispell-process.
2590 (ispell-buffer-local-parsing))
2593 (defun ispell-buffer-local-parsing ()
2594 "Place Ispell into parsing mode for this buffer.
2595 Overrides the default parsing mode.
2596 Includes Latex/Nroff modes and extended character mode."
2597 ;; (ispell-init-process) must already be called.
2598 (process-send-string ispell-process
"!\n") ; Put process in terse mode.
2599 ;; We assume all major modes with "tex-mode" in them should use latex parsing
2600 (if (or (and (eq ispell-parser
'use-mode-name
)
2601 (string-match "[Tt][Ee][Xx]-mode" (symbol-name major-mode
)))
2602 (eq ispell-parser
'tex
))
2604 (process-send-string ispell-process
"+\n") ; set ispell mode to tex
2605 (if (not (eq ispell-parser
'tex
))
2606 (set (make-local-variable 'ispell-parser
) 'tex
)))
2607 (process-send-string ispell-process
"-\n")) ; set mode to normal (nroff)
2608 ;; If needed, test for SGML & HTML modes and set a buffer local nil/t value.
2609 (if (and ispell-skip-sgml
(not (eq ispell-skip-sgml t
)))
2610 (set (make-local-variable 'ispell-skip-sgml
)
2611 (not (null (let ((case-fold-search t
))
2612 (string-match "sgml\\|html"
2613 (symbol-name major-mode
)))))))
2614 ;; Set default extended character mode for given buffer, if any.
2615 (let ((extended-char-mode (ispell-get-extended-character-mode)))
2616 (if extended-char-mode
2617 (process-send-string ispell-process
(concat extended-char-mode
"\n"))))
2618 ;; Set buffer-local parsing mode and extended character mode, if specified.
2620 (goto-char (point-max))
2621 ;; Uses last occurrence of ispell-parsing-keyword
2622 (if (search-backward ispell-parsing-keyword nil t
)
2623 (let ((end (save-excursion (end-of-line) (point)))
2624 (case-fold-search t
)
2626 (search-forward ispell-parsing-keyword
)
2627 (while (re-search-forward " *\\([^ \"]+\\)" end t
)
2628 ;; space separated definitions.
2629 (setq string
(buffer-substring-no-properties (match-beginning 1)
2631 (cond ((string-match "latex-mode" string
)
2632 (process-send-string ispell-process
"+\n~tex\n"))
2633 ((string-match "nroff-mode" string
)
2634 (process-send-string ispell-process
"-\n~nroff"))
2635 ((string-match "~" string
) ; Set extended character mode.
2636 (process-send-string ispell-process
(concat string
"\n")))
2637 (t (message "Invalid Ispell Parsing argument!")
2641 ;;; Can kill the current ispell process
2643 (defun ispell-buffer-local-dict ()
2644 "Initializes local dictionary and local personal dictionary.
2645 When a dictionary is defined in the buffer (see variable
2646 `ispell-dictionary-keyword'), it will override the local setting
2647 from \\[ispell-change-dictionary].
2648 Both should not be used to define a buffer-local dictionary."
2650 (goto-char (point-min))
2652 ;; Override the local variable definition.
2653 ;; Uses last occurrence of ispell-dictionary-keyword.
2654 (goto-char (point-max))
2655 (if (search-backward ispell-dictionary-keyword nil t
)
2657 (search-forward ispell-dictionary-keyword
)
2658 (setq end
(save-excursion (end-of-line) (point)))
2659 (if (re-search-forward " *\\([^ \"]+\\)" end t
)
2660 (setq ispell-local-dictionary
2661 (buffer-substring-no-properties (match-beginning 1)
2663 (goto-char (point-max))
2664 (if (search-backward ispell-pdict-keyword nil t
)
2666 (search-forward ispell-pdict-keyword
)
2667 (setq end
(save-excursion (end-of-line) (point)))
2668 (if (re-search-forward " *\\([^ \"]+\\)" end t
)
2669 (setq ispell-local-pdict
2670 (buffer-substring-no-properties (match-beginning 1)
2671 (match-end 1))))))))
2672 ;; Reload if new personal dictionary defined.
2673 (if (and ispell-local-pdict
2674 (not (equal ispell-local-pdict ispell-personal-dictionary
)))
2676 (ispell-kill-ispell t
)
2677 (setq ispell-personal-dictionary ispell-local-pdict
)))
2678 ;; Reload if new dictionary defined.
2679 (if (and ispell-local-dictionary
2680 (not (equal ispell-local-dictionary ispell-dictionary
)))
2681 (ispell-change-dictionary ispell-local-dictionary
)))
2684 (defun ispell-buffer-local-words ()
2685 "Loads the buffer-local dictionary in the current buffer."
2686 (if (and ispell-buffer-local-name
2687 (not (equal ispell-buffer-local-name
(buffer-name))))
2689 (ispell-kill-ispell t
)
2690 (setq ispell-buffer-local-name nil
)))
2691 (ispell-init-process)
2693 (goto-char (point-min))
2694 (while (search-forward ispell-words-keyword nil t
)
2695 (or ispell-buffer-local-name
2696 (setq ispell-buffer-local-name
(buffer-name)))
2697 (let ((end (save-excursion (end-of-line) (point)))
2698 (ispell-casechars (ispell-get-casechars))
2700 ;; buffer-local words separated by a space, and can contain
2701 ;; any character other than a space. Not rigorous enough.
2702 (while (re-search-forward " *\\([^ ]+\\)" end t
)
2703 (setq string
(buffer-substring-no-properties (match-beginning 1)
2705 ;; This can fail when string contains a word with illegal chars.
2706 ;; Error handling needs to be added between ispell and emacs.
2707 (if (and (< 1 (length string
))
2708 (equal 0 (string-match ispell-casechars string
)))
2709 (process-send-string ispell-process
2710 (concat "@" string
"\n"))))))))
2713 ;;; returns optionally adjusted region-end-point.
2715 (defun ispell-add-per-file-word-list (word)
2716 "Adds new word to the per-file word list."
2717 (or ispell-buffer-local-name
2718 (setq ispell-buffer-local-name
(buffer-name)))
2720 (goto-char (point-min))
2721 (let (case-fold-search line-okay search done string
)
2723 (setq search
(search-forward ispell-words-keyword nil
'move
)
2724 line-okay
(< (+ (length word
) 1 ; 1 for space after word..
2725 (progn (end-of-line) (current-column)))
2727 (if (or (and search line-okay
)
2734 (setq string
(concat comment-start
" "
2735 ispell-words-keyword
))
2737 (if (and comment-end
(not (equal "" comment-end
)))
2741 (insert comment-end
)))))
2742 (insert (concat " " word
))))))))
2745 (defconst ispell-version
"ispell.el 3.0 -- Tue Apr 28 14:40:01 PDT 1998")
2750 ;;; LOCAL VARIABLES AND BUFFER-LOCAL VALUE EXAMPLES.
2752 ;;; Local Variable options:
2753 ;;; mode: name(-mode)
2754 ;;; eval: expression
2755 ;;; local-variable: value
2757 ;;; The following sets the buffer local dictionary to 'american' English
2758 ;;; and spell checks only comments.
2760 ;;; Local Variables:
2761 ;;; mode: emacs-lisp
2762 ;;; comment-column: 40
2763 ;;; ispell-check-comments: exclusive
2764 ;;; Local IspellDict: "american"
2768 ;;; MORE EXAMPLES OF ISPELL BUFFER-LOCAL VALUES
2770 ;;; The following places this file in nroff parsing and extended char modes.
2771 ;;; Local IspellParsing: nroff-mode ~nroff
2772 ;;; Change IspellPersDict to IspellPersDict: to enable the following line.
2773 ;;; Local IspellPersDict ~/.ispell_lisp
2774 ;;; The following were automatically generated by ispell using the 'A' command:
2775 ; LocalWords: Moellmann copyleft Dansk russian KOI charset minipage hspace mh
2776 ; LocalWords: unsplitable includeonly nocite epsfig displaymath eqnarray init
2777 ; LocalWords: settable autoload inews frag pdict alist Wildcards iconify arg
2778 ; LocalWords: tex alists minibuffer Autoloading setq changelog kss stevens reg
2779 ; LocalWords: Castellano framepop sgml modeline Wedler Dirk Froembgen fn Gerd
2780 ; LocalWords: pgp NZST Vignaux autoloaded loaddefs aff Francais Nederlands SPC
2781 ; LocalWords: popup nonmenu regexp herr num pers dict unhighlight ccept uit NB
2782 ; LocalWords: buf grep sync prev inc hilight olddot AIX ersion msg read's op
2783 ; LocalWords: bufs pt multibyte cmd Quinlan uuencoded esp unidiff eg sc
2784 ; LocalWords: VM lns HTML eval american IspellPersDict
2786 ;;; ispell.el ends here