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