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