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