1 ;;; ispell.el --- interface to International Ispell Versions 3.1 and 3.2
3 ;; Copyright (C) 1994-1995, 1997-2012 Free Software Foundation, Inc.
5 ;; Author: Ken Stevens <k.stevens@ieee.org>
6 ;; Maintainer: Ken Stevens <k.stevens@ieee.org>
7 ;; Stevens Mod Date: Mon Jan 7 12:32:44 PST 2003
8 ;; Stevens Revision: 3.6
9 ;; Status : Release with 3.1.12+ and 3.2.0+ ispell.
10 ;; Bug Reports : ispell-el-bugs@itcorp.com
11 ;; Web Site : http://kdstevens.com/~stevens/ispell-page.html
14 ;; This file is part of GNU Emacs.
16 ;; GNU Emacs is free software: you can redistribute it and/or modify
17 ;; it under the terms of the GNU General Public License as published by
18 ;; the Free Software Foundation, either version 3 of the License, or
19 ;; (at your option) any later version.
21 ;; GNU Emacs is distributed in the hope that it will be useful,
22 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 ;; GNU General Public License for more details.
26 ;; You should have received a copy of the GNU General Public License
27 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
29 ;; Note: version numbers and time stamp are not updated
30 ;; when this file is edited for release with GNU Emacs.
36 ;; This code contains a section of user-settable variables that you
37 ;; should inspect prior to installation. Look past the end of the history
38 ;; list. Set them up for your locale and the preferences of the majority
39 ;; of the users. Otherwise the users may need to set a number of variables
41 ;; You particularly may want to change the default dictionary for your
42 ;; country and language.
43 ;; Most dictionary changes should be made in this file so all users can
44 ;; enjoy them. Local or modified dictionaries are supported in your .emacs
45 ;; file. Use the variable `ispell-local-dictionary-alist' to specify
46 ;; your own dictionaries.
48 ;; Depending on the mail system you use, you may want to include these:
49 ;; (add-hook 'news-inews-hook 'ispell-message)
50 ;; (add-hook 'mail-send-hook 'ispell-message)
51 ;; (add-hook 'mh-before-send-letter-hook 'ispell-message)
53 ;; Ispell has a TeX parser and a nroff parser (the default).
54 ;; The parsing is controlled by the variable ispell-parser. Currently
55 ;; it is just a "toggle" between TeX and nroff, but if more parsers are
56 ;; added it will be updated. See the variable description for more info.
65 ;; ispell-comments-and-strings
67 ;; ispell-complete-word
68 ;; ispell-complete-word-interior-frag
69 ;; ispell-change-dictionary
72 ;; ispell-skip-region-alist
74 ;; Commands in ispell-region:
75 ;; Character replacement: Replace word with choice. May query-replace.
76 ;; ` ': Accept word this time.
77 ;; `i': Accept word and insert into private dictionary.
78 ;; `a': Accept word for this session.
79 ;; `A': Accept word and place in buffer-local dictionary.
80 ;; `r': Replace word with typed-in value. Rechecked.
81 ;; `R': Replace word with typed-in value. Query-replaced in buffer. Rechecked.
82 ;; `?': Show these commands
83 ;; `x': Exit spelling buffer. Move cursor to original point.
84 ;; `X': Exit spelling buffer. Leaves cursor at the current point, and permits
85 ;; the check to be completed later.
86 ;; `q': Quit spelling session (Kills ispell process).
87 ;; `l': Look up typed-in replacement in alternate dictionary. Wildcards okay.
88 ;; `u': Like `i', but the word is lower-cased first.
89 ;; `m': Place entered value in personal dictionary, then recheck current word.
90 ;; `C-l': redraws screen
91 ;; `C-r': recursive edit
92 ;; `C-z': suspend Emacs or iconify frame
94 ;; Buffer-Local features:
95 ;; There are a number of buffer-local features that can be used to customize
96 ;; ispell for the current buffer. This includes language dictionaries,
97 ;; personal dictionaries, parsing, and local word spellings. Each of these
98 ;; local customizations are done either through local variables, or by
99 ;; including the keyword and argument(s) at the end of the buffer (usually
100 ;; prefixed by the comment characters). See the end of this file for
101 ;; examples. The local keywords and variables are:
103 ;; ispell-dictionary-keyword language-dictionary
104 ;; uses local variable ispell-local-dictionary
105 ;; ispell-pdict-keyword personal-dictionary
106 ;; uses local variable ispell-local-pdict
107 ;; ispell-parsing-keyword mode-arg extended-char-arg
108 ;; ispell-words-keyword any number of local word spellings
111 ;; Place new regular expression definitions of regions you prefer not to
112 ;; spell check in `ispell-skip-region-alist'. Mode-dependent features can
113 ;; be added to latex by modifying `ispell-tex-skip-alists'.
114 ;; `ispell-message' contains some custom skipping code for e-mail messages.
117 ;; Need a way to select between different character mappings without separate
118 ;; dictionary entries.
119 ;; Multi-byte characters if not defined by current dictionary may result in the
120 ;; evil "misalignment error" in some versions of MULE Emacs.
121 ;; On some versions of Emacs, growing the minibuffer fails.
122 ;; see `ispell-help-in-bufferp'.
123 ;; Recursive edits (?C-r or ?R) inside a keyboard text replacement check (?r)
124 ;; can cause misalignment errors.
128 ;; Modifications made in latest versions:
130 ;; Revision 3.6 2003/01/07 12:32:44 kss
131 ;; Removed extra -d LIB in dictionary defs. (Pavel Janik)
132 ;; Filtered process calls with duplicate dictionary entries.
133 ;; Fixed bug where message-text-end is inside a mime skipped region.
134 ;; Minor fixes to get ispell menus right in XEmacs
135 ;; Fixed skip regexp so it doesn't match stuff like `/.\w'.
136 ;; Detecting dictionary change not working. Fixed. kss
137 ;; function `ispell-change-dictionary' now only completes valid dicts.
139 ;; Revision 3.5 2001/7/11 18:43:57 kss
140 ;; Added fix for aspell to work in XEmacs (ispell-check-version).
141 ;; Added Portuguese dictionary definition.
142 ;; New feature: MIME mail message support, Fcc support.
143 ;; Bug fix: retain comment syntax on lines with region skipping. (TeX $ bug...)
144 ;; Improved allocation for graphic mode lines. (Miles Bader)
145 ;; Support -v flag for old versions of aspell. (Eli Zaretskii)
146 ;; Clear minibuffer on ^G from ispell-help (Tak Ota)
148 ;; Revision 3.4 2000/8/4 09:41:50 kss
149 ;; Support new color display functions.
150 ;; Fixed misalignment offset bug when replacing a string after a shift made.
151 ;; Set to standard Author/Maintainer heading,
152 ;; ensure localwords lists are separated from the text by newline. (Dave Love)
153 ;; Added dictionary definition for Italian (William Deakin)
154 ;; HTML region skipping greatly improved. (Chuck D. Phillips)
155 ;; improved menus. Fixed regexp matching http/email addresses.
156 ;; one arg always for XEmacs sleep-for (gunnar Evermann)
157 ;; support for synchronous processes (Eli Zaretskii)
159 ;; Revision 3.3 1999/11/29 11:38:34 kss
160 ;; Only word replacements entered in from the keyboard are rechecked.
161 ;; This fixes a bug in tex parsing and misalignment.
162 ;; Exceptions exist for recursive edit and query-replace, with tex error
163 ;; condition tested. Recursive editing improved.
164 ;; XEmacs repair for when `enable-multibyte-characters' defined - Didier Verna.
165 ;; ispell-help fixed for XEmacs. Choices minibuffer now displayed in XEmacs.
166 ;; Only list valid dictionaries in Spell menu. Russian dictionary doesn't allow
167 ;; run-together words, and uses koi8-r font. Don't skip text in html <TT>
170 ;; Revision 3.2 1999/5/7 14:25:14 kss
171 ;; Accept ispell versions 3.X.Y where X>=1
172 ;; fine tuned latex region skipping. Fixed bug in ispell-word that did not
173 ;; point in right place on words < 2 chars. Simplified ispell-minor-mode.
174 ;; Fixed bug in TeX parsing when math commands are in the comments.
175 ;; Removed calls to `when' macro.
177 ;; Revision 3.1 1998/12/1 13:21:52 kss
178 ;; Improved and fixed customize support.
179 ;; Improved and fixed comments in variables and messages.
180 ;; A coding system is now required for all languages.
181 ;; casechars improved for castellano, castellano8, and norsk dictionaries.
182 ;; Dictionary norsk7-tex removed. Dictionary polish added.
183 ;; Dictionaries redefined at load-time to support dictionary changes.
184 ;; Menu redefined at load time to support dictionary changes.
185 ;; ispell-check-version added as an alias for `check-ispell-version'.
186 ;; Spelling suggestions returned in order generated by ispell.
187 ;; Small bug fixed in matching ispell error messages.
188 ;; Robustness added to ensure `case-fold-search' doesn't get redefined.
189 ;; Fixed bug that didn't respect case of word in `ispell-complete-word'.
190 ;; Multibyte character coding support added for process interactions.
191 ;; Ensure ispell process has terminated before starting new process.
192 ;; This can otherwise confuse process filters and hang ispell.
193 ;; Improved skipping support for SGML.
194 ;; Fixed bug using ^M rather than \r in `ispell-minor-check'.
195 ;; Improved message reference matching in `ispell-message'.
196 ;; Fixed bug in returning to nroff mode from tex mode.
198 ;;; Compatibility code for XEmacs and (not too) older emacsen:
200 (eval-and-compile ;; Protect against declare-function undefined in XEmacs
201 (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
203 (declare-function ispell-check-minver "ispell" (v1 v2))
204 (declare-function ispell-looking-back "ispell"
205 (regexp &optional limit &rest ignored))
207 (if (fboundp 'version<=)
208 (defalias 'ispell-check-minver 'version<=)
209 (defun ispell-check-minver (minver version)
210 "Check if string VERSION is at least string MINVER.
211 Both must be in [0-9]+.[0-9]+... format. This is a fallback
212 compatibility function in case `version<=' is not available."
215 start-ver start-mver)
216 ;; Loop until an absolute greater or smaller condition is reached
217 ;; or until no elements are left in any of version and minver. In
218 ;; this case version is exactly the minimal, so return OK.
221 (if (string-match "[0-9]+" version start-ver)
222 (setq start-ver (match-end 0)
223 ver (string-to-number (match-string 0 version))))
224 (if (string-match "[0-9]+" minver start-mver)
225 (setq start-mver (match-end 0)
226 mver (string-to-number (match-string 0 minver))))
230 (or ver (setq ver 0))
231 (or mver (setq mver 0))
232 ;; If none of below conditions match, this element is the
233 ;; same. Go checking next element.
239 (setq pending nil))))
242 ;; XEmacs does not have looking-back
243 (if (fboundp 'looking-back)
244 (defalias 'ispell-looking-back 'looking-back)
245 (defun ispell-looking-back (regexp &optional limit &rest ignored)
246 "Return non-nil if text before point matches regular expression REGEXP.
247 Like `looking-at' except matches before point, and is slower.
248 LIMIT if non-nil speeds up the search by specifying a minimum
249 starting position, to avoid checking matches that would start
252 This is a stripped down compatibility function for use when
253 full featured `looking-back' function is missing."
255 (re-search-backward (concat "\\(?:" regexp "\\)\\=") limit t))))
259 (defvar mail-yank-prefix)
262 "User variables for Emacs ispell interface."
263 :group 'applications)
265 (if (not (fboundp 'buffer-substring-no-properties))
266 (defun buffer-substring-no-properties (start end)
267 (buffer-substring start end)))
269 (defalias 'check-ispell-version 'ispell-check-version)
271 ;;; **********************************************************************
272 ;;; The following variables should be set according to personal preference
273 ;;; and location of binaries:
274 ;;; **********************************************************************
277 ;;; ******* THIS FILE IS WRITTEN FOR ISPELL VERSION 3.1+
279 (defcustom ispell-highlight-p 'block
280 "Highlight spelling errors when non-nil.
281 When set to `block', assumes a block cursor with TTY displays."
282 :type '(choice (const block) (const :tag "off" nil) (const :tag "on" t))
285 (defcustom ispell-lazy-highlight (boundp 'lazy-highlight-cleanup)
286 "Controls the lazy-highlighting of spelling errors.
287 When non-nil, all text in the buffer matching the current spelling
288 error is highlighted lazily using isearch lazy highlighting (see
289 `lazy-highlight-initial-delay' and `lazy-highlight-interval')."
291 :group 'lazy-highlight
295 (defcustom ispell-highlight-face (if ispell-lazy-highlight 'isearch 'highlight)
296 "The face used for Ispell highlighting. For Emacsen with overlays.
297 Possible values are `highlight', `modeline', `secondary-selection',
298 `region', and `underline'.
299 This variable can be set by the user to whatever face they desire.
300 It's most convenient if the cursor color and highlight color are
305 (defcustom ispell-check-comments t
306 "Spelling of comments checked when non-nil.
307 When set to `exclusive', ONLY comments are checked. (For code comments).
308 Warning! Not checking comments, when a comment start is embedded in strings,
309 may produce undesired results."
310 :type '(choice (const exclusive) (const :tag "off" nil) (const :tag "on" t))
313 (put 'ispell-check-comments 'safe-local-variable
314 (lambda (a) (memq a '(nil t exclusive))))
316 (defcustom ispell-query-replace-choices nil
317 "Corrections made throughout region when non-nil.
318 Uses `query-replace' (\\[query-replace]) for corrections."
322 (defcustom ispell-skip-tib nil
323 "Does not spell check `tib' bibliography references when non-nil.
324 Skips any text between strings matching regular expressions
325 `ispell-tib-ref-beginning' and `ispell-tib-ref-end'.
327 TeX users beware: Any text between [. and .] will be skipped -- even if
328 that's your whole buffer -- unless you set `ispell-skip-tib' to nil.
329 That includes the [.5mm] type of number..."
333 (defvar ispell-tib-ref-beginning "[[<]\\."
334 "Regexp matching the beginning of a Tib reference.")
336 (defvar ispell-tib-ref-end "\\.[]>]"
337 "Regexp matching the end of a Tib reference.")
339 (defcustom ispell-keep-choices-win t
340 "If non-nil, keep the `*Choices*' window for the entire spelling session.
341 This minimizes redisplay thrashing."
345 (defcustom ispell-choices-win-default-height 2
346 "The default size of the `*Choices*' window, including the mode line.
347 Must be greater than 1."
351 (defcustom ispell-program-name
352 (or (locate-file "aspell" exec-path exec-suffixes 'file-executable-p)
353 (locate-file "ispell" exec-path exec-suffixes 'file-executable-p)
354 (locate-file "hunspell" exec-path exec-suffixes 'file-executable-p)
356 "Program invoked by \\[ispell-word] and \\[ispell-region] commands."
360 (defcustom ispell-alternate-dictionary
361 (cond ((file-readable-p "/usr/dict/web2") "/usr/dict/web2")
362 ((file-readable-p "/usr/share/dict/web2") "/usr/share/dict/web2")
363 ((file-readable-p "/usr/dict/words") "/usr/dict/words")
364 ((file-readable-p "/usr/lib/dict/words") "/usr/lib/dict/words")
365 ((file-readable-p "/usr/share/dict/words") "/usr/share/dict/words")
366 ((file-readable-p "/usr/share/lib/dict/words")
367 "/usr/share/lib/dict/words")
368 ((file-readable-p "/sys/dict") "/sys/dict"))
369 "Alternate plain word-list dictionary for spelling help."
370 :type '(choice file (const :tag "None" nil))
373 (defcustom ispell-complete-word-dict nil
374 "Plain word-list dictionary used for word completion if
375 different from `ispell-alternate-dictionary'."
376 :type '(choice file (const :tag "None" nil))
379 (defcustom ispell-message-dictionary-alist nil
380 "List used by `ispell-message' to select a new dictionary.
381 It consists of pairs (REGEXP . DICTIONARY). If REGEXP is found
382 in the message headers, `ispell-local-dictionary' will be set to
383 DICTIONARY if `ispell-local-dictionary' is not buffer-local.
384 E.g. you may use the following value:
385 '((\"^Newsgroups:[ \\t]*de\\\\.\" . \"deutsch8\")
386 (\"^To:[^\\n,]+\\\\.de[ \\t\\n,>]\" . \"deutsch8\"))"
387 :type '(repeat (cons regexp string))
391 (defcustom ispell-message-fcc-skip 50000
392 "Query before saving Fcc message copy if attachment larger than this value.
393 Always stores Fcc copy of message when nil."
394 :type '(choice integer (const :tag "off" nil))
398 (defcustom ispell-grep-command
399 ;; MS-Windows/MS-DOS have `egrep' as a Unix shell script, so they
400 ;; cannot invoke it. Use "grep -E" instead (see ispell-grep-options
402 (if (memq system-type '(windows-nt ms-dos)) "grep" "egrep")
403 "Name of the grep command for search processes."
407 (defcustom ispell-grep-options
408 (if (memq system-type '(windows-nt ms-dos)) "-Ei" "-i")
409 "String of options to use when running the program in `ispell-grep-command'.
410 Should probably be \"-i\" or \"-e\".
411 Some machines (like the NeXT) don't support \"-i\"."
415 (defcustom ispell-look-command
416 (cond ((file-exists-p "/bin/look") "/bin/look")
417 ((file-exists-p "/usr/local/bin/look") "/usr/local/bin/look")
418 ((file-exists-p "/usr/bin/look") "/usr/bin/look")
420 "Name of the look command for search processes.
421 This must be an absolute file name."
425 (defcustom ispell-look-p (file-exists-p ispell-look-command)
426 "Non-nil means use `look' rather than `grep'.
427 Default is based on whether `look' seems to be available."
431 (defcustom ispell-have-new-look nil
432 "Non-nil means use the `-r' option (regexp) when running `look'."
436 (defcustom ispell-look-options (if ispell-have-new-look "-dfr" "-df")
437 "String of command options for `ispell-look-command'."
441 (defcustom ispell-use-ptys-p nil
442 "When non-nil, Emacs uses ptys to communicate with Ispell.
443 When nil, Emacs uses pipes."
447 (defcustom ispell-following-word nil
448 "Non-nil means `ispell-word' checks the word around or after point.
449 Otherwise `ispell-word' checks the preceding word."
453 (defcustom ispell-help-in-bufferp nil
454 "Non-nil means display interactive keymap help in a buffer.
455 The following values are supported:
456 nil Expand the minibuffer and display a short help message
457 there for a couple of seconds.
458 t Pop up a new buffer and display a short help message there
459 for a couple of seconds.
460 electric Pop up a new buffer and display a long help message there.
461 User can browse and then exit the help mode."
462 :type '(choice (const electric) (const :tag "off" nil) (const :tag "on" t))
465 (defcustom ispell-quietly nil
466 "Non-nil means suppress messages in `ispell-word'."
470 (defcustom ispell-format-word-function (function upcase)
471 "Formatting function for displaying word being spell checked.
472 The function must take one string argument and return a string."
475 (defvaralias 'ispell-format-word 'ispell-format-word-function)
477 (defcustom ispell-use-framepop-p nil
478 "When non-nil ispell uses framepop to display choices in a dedicated frame.
479 You can set this variable to dynamically use framepop if you are in a
480 window system by evaluating the following on startup to set this variable:
481 (and window-system (condition-case () (require 'framepop) (error nil)))"
486 (defcustom ispell-personal-dictionary nil
487 "File name of your personal spelling dictionary, or nil.
488 If nil, the default personal dictionary, (\"~/.ispell_DICTNAME\" for ispell or
489 \"~/.aspell.LANG.pws\" for aspell) is used, where DICTNAME is the name of your
490 default dictionary and LANG the two letter language code."
492 (const :tag "default" nil))
495 (defcustom ispell-silently-savep nil
496 "When non-nil, save personal dictionary without asking for confirmation."
500 (defvar ispell-local-dictionary-overridden nil
501 "Non-nil means the user has explicitly set this buffer's Ispell dictionary.")
502 (make-variable-buffer-local 'ispell-local-dictionary-overridden)
504 (defcustom ispell-local-dictionary nil
505 "If non-nil, the dictionary to be used for Ispell commands in this buffer.
506 The value must be a string dictionary name,
507 or nil, which means use the global setting in `ispell-dictionary'.
508 Dictionary names are defined in `ispell-local-dictionary-alist'
509 and `ispell-dictionary-alist'.
511 Setting `ispell-local-dictionary' to a value has the same effect as
512 calling \\[ispell-change-dictionary] with that value. This variable
513 is automatically set when defined in the file with either
514 `ispell-dictionary-keyword' or the Local Variable syntax."
515 :type '(choice string
516 (const :tag "default" nil))
519 (put 'ispell-local-dictionary 'safe-local-variable 'string-or-null-p)
521 (make-variable-buffer-local 'ispell-local-dictionary)
523 (defcustom ispell-dictionary nil
524 "Default dictionary to use if `ispell-local-dictionary' is nil."
525 :type '(choice string
526 (const :tag "default" nil))
529 (defcustom ispell-extra-args nil
530 "If non-nil, a list of extra switches to pass to the Ispell program.
531 For example, (\"-W\" \"3\") to cause it to accept all 1-3 character
532 words as correct. See also `ispell-dictionary-alist', which may be used
533 for language-specific arguments."
534 :type '(repeat string)
539 (defcustom ispell-skip-html 'use-mode-name
540 "Indicates whether ispell should skip spell checking of SGML markup.
541 If t, always skip SGML markup; if nil, never skip; if non-t and non-nil,
542 guess whether SGML markup should be skipped according to the name of the
543 buffer's major mode."
544 :type '(choice (const :tag "always" t) (const :tag "never" nil)
545 (const :tag "use-mode-name" use-mode-name))
548 (make-variable-buffer-local 'ispell-skip-html)
551 (defcustom ispell-local-dictionary-alist nil
552 "List of local or customized dictionary definitions.
553 These can override the values in `ispell-dictionary-alist'.
555 To make permanent changes to your dictionary definitions, you
556 will need to make your changes in this variable, save, and then
558 :type '(repeat (list (choice :tag "Dictionary"
559 (string :tag "Dictionary name")
560 (const :tag "default" nil))
561 (regexp :tag "Case characters")
562 (regexp :tag "Non case characters")
563 (regexp :tag "Other characters")
564 (boolean :tag "Many other characters")
565 (repeat :tag "Ispell command line args"
567 (choice :tag "Extended character mode"
568 (const "~tex") (const "~plaintex")
569 (const "~nroff") (const "~list")
570 (const "~latin1") (const "~latin3")
571 (const :tag "default" nil))
572 (coding-system :tag "Coding System")))
576 (defvar ispell-dictionary-base-alist
578 ;; The default dictionary. It may be English.aff, or any other
579 ;; dictionary depending on locale and such things. We should probably
580 ;; ask ispell what dictionary it's using, but until we do that, let's
581 ;; just use a minimal regexp. [:alpha:] will later be set if possible.
582 "[A-Za-z]" "[^A-Za-z]" "[']" nil ("-B") nil iso-8859-1)
583 ("american" ; Yankee English
584 "[A-Za-z]" "[^A-Za-z]" "[']" nil ("-B") nil iso-8859-1)
585 ("brasileiro" ; Brazilian mode
586 "[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]"
587 "[^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]"
588 "[']" nil nil nil iso-8859-1)
589 ("british" ; British version
590 "[A-Za-z]" "[^A-Za-z]" "[']" nil ("-B") nil iso-8859-1)
591 ("castellano" ; Spanish mode
592 "[A-Z\301\311\315\321\323\332\334a-z\341\351\355\361\363\372\374]"
593 "[^A-Z\301\311\315\321\323\332\334a-z\341\351\355\361\363\372\374]"
594 "[-]" nil ("-B") "~tex" iso-8859-1)
595 ("castellano8" ; 8 bit Spanish mode
596 "[A-Z\301\311\315\321\323\332\334a-z\341\351\355\361\363\372\374]"
597 "[^A-Z\301\311\315\321\323\332\334a-z\341\351\355\361\363\372\374]"
598 "[-]" nil ("-B" "-d" "castellano") "~latin1" iso-8859-1)
600 "[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]"
601 "[^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]"
602 "" nil ("-B") nil iso-8859-2)
604 "[A-Z\306\330\305a-z\346\370\345]" "[^A-Z\306\330\305a-z\346\370\345]"
605 "[']" nil ("-C") nil iso-8859-1)
606 ("deutsch" ; Deutsch.aff
607 "[a-zA-Z\"]" "[^a-zA-Z\"]" "[']" t ("-C") "~tex" iso-8859-1)
609 "[a-zA-Z\304\326\334\344\366\337\374]"
610 "[^a-zA-Z\304\326\334\344\366\337\374]"
611 "[']" t ("-C" "-d" "deutsch") "~latin1" iso-8859-1)
612 ("english" ; make English explicitly selectable
613 "[A-Za-z]" "[^A-Za-z]" "[']" nil ("-B") nil iso-8859-1)
615 "[A-Za-z\246\254\266\274\306\330\335\336\346\370\375\376]"
616 "[^A-Za-z\246\254\266\274\306\330\335\336\346\370\375\376]"
617 "[-']" t ("-C") "~latin3" iso-8859-3)
619 "[A-Za-z^\\]" "[^A-Za-z^\\]"
620 "[-'`\"]" t ("-C" "-d" "esperanto") "~tex" iso-8859-3)
622 "[A-Za-z\345\344\366\305\304\326]"
623 "[^A-Za-z\345\344\366\305\304\326]"
624 "[:]" nil ("-C") "~list" iso-8859-1)
626 "[A-Za-z]" "[^A-Za-z]" "[`'^-]" t nil nil iso-8859-1)
627 ("francais" ; Francais.aff
628 "[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]"
629 "[^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]"
630 "[-'.@]" t nil "~list" iso-8859-1)
631 ("francais-tex" ; Francais.aff
632 "[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\\]"
633 "[^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\\]"
634 "[-'^`\".@]" t nil "~tex" iso-8859-1)
635 ("german" ; german.aff
636 "[a-zA-Z\"]" "[^a-zA-Z\"]" "[']" t ("-C") "~tex" iso-8859-1)
637 ("german8" ; german.aff
638 "[a-zA-Z\304\326\334\344\366\337\374]"
639 "[^a-zA-Z\304\326\334\344\366\337\374]"
640 "[']" t ("-C" "-d" "german") "~latin1" iso-8859-1)
641 ("italiano" ; Italian.aff
642 "[A-Z\300\301\310\311\314\315\322\323\331\332a-z\340\341\350\351\354\355\363\371\372]"
643 "[^A-Z\300\301\310\311\314\315\322\323\331\332a-z\340\341\350\351\354\355\363\371\372]"
644 "[-.]" nil ("-B" "-d" "italian") "~tex" iso-8859-1)
645 ("nederlands" ; Nederlands.aff
646 "[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]"
647 "[^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]"
648 "[']" t ("-C") nil iso-8859-1)
649 ("nederlands8" ; Dutch8.aff
650 "[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]"
651 "[^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]"
652 "[']" t ("-C") nil iso-8859-1)
653 ("norsk" ; 8 bit Norwegian mode
654 "[A-Za-z\305\306\307\310\311\322\324\330\345\346\347\350\351\362\364\370]"
655 "[^A-Za-z\305\306\307\310\311\322\324\330\345\346\347\350\351\362\364\370]"
656 "[\"]" nil nil "~list" iso-8859-1)
657 ("norsk7-tex" ; 7 bit Norwegian TeX mode
658 "[A-Za-z{}\\'^`]" "[^A-Za-z{}\\'^`]"
659 "[\"]" nil ("-d" "norsk") "~plaintex" iso-8859-1)
660 ("polish" ; Polish mode
661 "[A-Za-z\241\243\246\254\257\261\263\266\274\277\306\312\321\323\346\352\361\363]"
662 "[^A-Za-z\241\243\246\254\257\261\263\266\274\277\306\312\321\323\346\352\361\363]"
663 "[.]" nil nil nil iso-8859-2)
664 ("portugues" ; Portuguese mode
665 "[a-zA-Z\301\302\307\311\323\340\341\342\351\352\355\363\343\347\372]"
666 "[^a-zA-Z\301\302\307\311\323\340\341\342\351\352\355\363\343\347\372]"
667 "[']" t ("-C") "~latin1" iso-8859-1)
668 ("russian" ; Russian.aff (KOI8-R charset)
669 "[\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]"
670 "[^\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]"
671 "" nil nil nil koi8-r)
672 ("russianw" ; russianw.aff (CP1251 charset)
673 "[\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]"
674 "[^\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]"
675 "" nil nil nil windows-1251)
676 ("slovak" ; Slovakian
677 "[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]"
678 "[^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]"
679 "" nil ("-B") nil iso-8859-2)
680 ("slovenian" ; Slovenian
681 "[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]"
682 "[^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]"
683 "" nil ("-B" "-d" "slovenian") nil iso-8859-2)
684 ("svenska" ; Swedish mode
685 "[A-Za-z\345\344\366\351\340\374\350\346\370\347\305\304\326\311\300\334\310\306\330\307]"
686 "[^A-Za-z\345\344\366\351\340\374\350\346\370\347\305\304\326\311\300\334\310\306\330\307]"
687 "[']" nil ("-C") "~list" iso-8859-1)
688 ("hebrew" "[\340\341\342\343\344\345\346\347\350\351\353\352\354\356\355\360\357\361\362\364\363\367\366\365\370\371\372]" "[^\340\341\342\343\344\345\346\347\350\351\353\352\354\356\355\360\357\361\362\364\363\367\366\365\370\371\372]" "" nil ("-B") nil cp1255))
689 "Base value for `ispell-dictionary-alist'.")
691 (defvar ispell-dictionary-alist nil
692 "An alist of dictionaries and their associated parameters.
694 Each element of this list is also a list:
696 \(DICTIONARY-NAME CASECHARS NOT-CASECHARS OTHERCHARS MANY-OTHERCHARS-P
697 ISPELL-ARGS EXTENDED-CHARACTER-MODE CHARACTER-SET\)
699 DICTIONARY-NAME is a possible string value of variable `ispell-dictionary',
700 nil means the default dictionary.
702 CASECHARS is a regular expression of valid characters that comprise a word.
704 NOT-CASECHARS is the opposite regexp of CASECHARS.
706 OTHERCHARS is a regexp of characters in the NOT-CASECHARS set but which can be
707 used to construct words in some special way. If OTHERCHARS characters follow
708 and precede characters from CASECHARS, they are parsed as part of a word,
709 otherwise they become word-breaks. As an example in English, assume the
710 regular expression \"[']\" for OTHERCHARS. Then \"they're\" and
711 \"Steven's\" are parsed as single words including the \"'\" character, but
712 \"Stevens'\" does not include the quote character as part of the word.
713 If you want OTHERCHARS to be empty, use the empty string.
714 Hint: regexp syntax requires the hyphen to be declared first here.
716 CASECHARS, NOT-CASECHARS, and OTHERCHARS must be unibyte strings
717 containing bytes of CHARACTER-SET. In addition, if they contain
718 non-ASCII bytes, the regular expression must be a single
719 `character set' construct that doesn't specify a character range
722 MANY-OTHERCHARS-P is non-nil when multiple OTHERCHARS are allowed in a word.
723 Otherwise only a single OTHERCHARS character is allowed to be part of any
726 ISPELL-ARGS is a list of additional arguments passed to the ispell
729 EXTENDED-CHARACTER-MODE should be used when dictionaries are used which
730 have been configured in an Ispell affix file. (For example, umlauts
731 can be encoded as \\\"a, a\\\", \"a, ...) Defaults are ~tex and ~nroff
732 in English. This has the same effect as the command-line `-T' option.
733 The buffer Major Mode controls Ispell's parsing in tex or nroff mode,
734 but the dictionary can control the extended character mode.
735 Both defaults can be overruled in a buffer-local fashion. See
736 `ispell-parsing-keyword' for details on this.
738 CHARACTER-SET used to encode text sent to the ispell subprocess
739 when the language uses non-ASCII characters.
741 Note that with \"ispell\" as the speller, the CASECHARS and
742 OTHERCHARS slots of the alist should contain the same character
743 set as casechars and otherchars in the LANGUAGE.aff file \(e.g.,
744 english.aff\). aspell and hunspell don't have this limitation.")
746 (defvar ispell-really-aspell nil) ; Non-nil if we can use aspell extensions.
747 (defvar ispell-really-hunspell nil) ; Non-nil if we can use hunspell extensions.
748 (defvar ispell-encoding8-command nil
749 "Command line option prefix to select encoding if supported, nil otherwise.
750 If setting the encoding is supported by spellchecker and is selectable from
751 the command line, this variable will contain \"--encoding=\" for aspell
752 and \"-i \" for hunspell, so the appropriate mime charset can be selected.
753 That will be set in `ispell-check-version' for hunspell >= 1.1.6 and
756 For aspell, non-nil also means to try to automatically find its dictionaries.
758 Earlier aspell versions do not consistently support charset encoding. Handling
759 this would require some extra guessing in `ispell-aspell-find-dictionary'.")
761 (defvar ispell-aspell-supports-utf8 nil
762 "Non-nil if aspell has consistent command line UTF-8 support. Obsolete.
763 ispell.el and flyspell.el will use for this purpose the more generic
764 variable `ispell-encoding8-command' for both aspell and hunspell. Is left
765 here just for backwards compatibility.")
767 (make-obsolete-variable 'ispell-aspell-supports-utf8
768 'ispell-encoding8-command "23.1")
770 (defvar ispell-emacs-alpha-regexp
771 (if (string-match "^[[:alpha:]]+$" "abcde")
774 "[[:alpha:]] if Emacs supports [:alpha:] regexp, nil
775 otherwise (current XEmacs does not support it).")
777 ;;; **********************************************************************
778 ;;; The following are used by ispell, and should not be changed.
779 ;;; **********************************************************************
783 ;; The version must be 3.1 or greater for this version of ispell.el
784 ;; There is an incompatibility between version 3.1.12 and lower versions.
785 (defconst ispell-required-version '(3 1 12)
786 "Ispell versions with which this version of ispell.el is known to work.")
787 (defvar ispell-offset -1
788 "Offset that maps protocol differences between ispell 3.1 versions.")
790 (defconst ispell-version "ispell.el 3.6 - 7-Jan-2003")
793 (defun ispell-check-version (&optional interactivep)
794 "Ensure that `ispell-program-name' is valid and has the correct version.
795 Returns version number if called interactively.
796 Otherwise returns the library directory name, if that is defined."
797 ;; This is a little wasteful as we actually launch ispell twice: once
798 ;; to make sure it's the right version, and once for real. But people
799 ;; get confused by version mismatches *all* the time (and I've got the
800 ;; email to prove it) so I think this is worthwhile. And the -v[ersion]
801 ;; option is the only way I can think of to do this that works with
802 ;; all versions, since versions earlier than 3.0.09 didn't identify
803 ;; themselves on startup.
805 (let ((default-directory (or (and (boundp 'temporary-file-directory)
806 temporary-file-directory)
808 result status ispell-program-version)
811 (setq status (ispell-call-process
812 ispell-program-name nil t nil
813 ;; aspell doesn't accept the -vv switch.
814 (let ((case-fold-search
815 (memq system-type '(ms-dos windows-nt)))
817 (file-name-nondirectory ispell-program-name)))
818 ;; Assume anything that isn't `aspell' is Ispell.
819 (if (string-match "\\`aspell" speller) "-v" "-vv"))))
820 (goto-char (point-min))
822 ;; report version information of ispell and ispell.el
825 (setq result (concat (buffer-substring-no-properties (point-min)
829 (message "%s" result))
830 ;; return library directory.
831 (if (re-search-forward "LIBDIR = \\\"\\([^ \t\n]*\\)\\\"" nil t)
832 (setq result (match-string 1))))
833 (goto-char (point-min))
834 (if (not (memq status '(0 nil)))
835 (error "%s exited with %s %s" ispell-program-name
836 (if (stringp status) "signal" "code") status))
838 ;; Get relevant version strings. Only xx.yy.... format works well
839 (let (case-fold-search)
840 (setq ispell-program-version
841 (and (search-forward-regexp "\\([0-9]+\\.[0-9\\.]+\\)" nil t)
844 ;; Make sure these variables are (re-)initialized to the default value
845 (setq ispell-really-aspell nil
846 ispell-aspell-supports-utf8 nil
847 ispell-really-hunspell nil
848 ispell-encoding8-command nil)
850 (goto-char (point-min))
851 (or (setq ispell-really-aspell
852 (and (search-forward-regexp
853 "(but really Aspell \\([0-9]+\\.[0-9\\.-]+\\)?)" nil t)
855 (setq ispell-really-hunspell
856 (and (search-forward-regexp
857 "(but really Hunspell \\([0-9]+\\.[0-9\\.-]+\\)?)"
861 (let ((aspell-minver "0.50")
862 (aspell8-minver "0.60")
863 (ispell0-minver "3.1.0")
864 (ispell-minver "3.1.12")
865 (hunspell8-minver "1.1.6"))
867 (if (ispell-check-minver ispell0-minver ispell-program-version)
868 (or (ispell-check-minver ispell-minver ispell-program-version)
869 (setq ispell-offset 0))
870 (error "%s release %s or greater is required"
875 (ispell-really-aspell
876 (if (ispell-check-minver aspell-minver ispell-really-aspell)
877 (if (ispell-check-minver aspell8-minver ispell-really-aspell)
879 (setq ispell-aspell-supports-utf8 t)
880 (setq ispell-encoding8-command "--encoding=")))
881 (setq ispell-really-aspell nil)))
882 (ispell-really-hunspell
883 (if (ispell-check-minver hunspell8-minver ispell-really-hunspell)
884 (setq ispell-encoding8-command "-i")
885 (setq ispell-really-hunspell nil))))))
888 (defun ispell-call-process (&rest args)
889 "Like `call-process' but defend against bad `default-directory'."
890 (let ((default-directory default-directory))
891 (unless (and (file-directory-p default-directory)
892 (file-readable-p default-directory))
893 (setq default-directory (expand-file-name "~/")))
894 (apply 'call-process args)))
896 (defun ispell-call-process-region (&rest args)
897 "Like `call-process-region' but defend against bad `default-directory'."
898 (let ((default-directory default-directory))
899 (unless (and (file-directory-p default-directory)
900 (file-readable-p default-directory))
901 (setq default-directory (expand-file-name "~/")))
902 (apply 'call-process-region args)))
906 ;; The preparation of the menu bar menu must be autoloaded
907 ;; because otherwise this file gets autoloaded every time Emacs starts
908 ;; so that it can set up the menus and determine keyboard equivalents.
911 (defvar ispell-menu-map nil "Key map for ispell menu.")
912 ;;; redo menu when loading ispell to get dictionary modifications
913 (setq ispell-menu-map nil)
916 (defvar ispell-menu-xemacs nil
917 "Spelling menu for XEmacs.
918 If nil when package is loaded, a standard menu will be set,
919 and added as a submenu of the \"Edit\" menu.")
921 ;; Break out XEmacs menu and split into several calls to avoid having
922 ;; long lines in loaddefs.el. Detect need off following constant.
924 ;;; Set up dictionary
926 (defvar ispell-menu-map-needed
927 ;; only needed when not version 18 and not XEmacs.
928 (and (not ispell-menu-map)
929 (not (featurep 'xemacs))
932 (defvar ispell-library-directory (condition-case ()
933 (ispell-check-version)
935 "Directory where ispell dictionaries reside.")
937 (defvar ispell-process nil
938 "The process object for Ispell.")
940 (defvar ispell-async-processp (and (fboundp 'delete-process)
941 (fboundp 'process-send-string)
942 (fboundp 'accept-process-output)
943 ;;(fboundp 'start-process)
944 ;;(fboundp 'set-process-filter)
945 ;;(fboundp 'process-kill-without-query)
947 "Non-nil means that the OS supports asynchronous processes.")
949 ;; Make ispell.el work better with aspell.
951 (defvar ispell-aspell-dictionary-alist nil
952 "An alist of parsed aspell dicts and associated parameters.
955 (defun ispell-find-aspell-dictionaries ()
956 "Find Aspell's dictionaries, and record in `ispell-dictionary-alist'."
957 (unless (and ispell-really-aspell ispell-encoding8-command)
958 (error "This function only works with aspell >= 0.60"))
962 (ispell-call-process ispell-program-name nil t nil "dicts")
964 ;; Search for the named dictionaries.
967 (mapcar #'ispell-aspell-find-dictionary dictionaries))))
968 ;; Ensure aspell's alias dictionary will override standard
970 (setq found (ispell-aspell-add-aliases found))
971 ;; Merge into FOUND any elements from the standard ispell-dictionary-alist
972 ;; which have no element in FOUND at all.
973 (dolist (dict ispell-dictionary-alist)
974 (unless (assoc (car dict) found)
975 (setq found (nconc found (list dict)))))
976 (setq ispell-aspell-dictionary-alist found)
977 ;; Add a default entry
979 '(nil "[[:alpha:]]" "[^[:alpha:]]" "[']" nil ("-B") nil utf-8)))
980 (push default-dict ispell-aspell-dictionary-alist))))
982 (defvar ispell-aspell-data-dir nil
983 "Data directory of Aspell.")
985 (defvar ispell-aspell-dict-dir nil
986 "Dictionary directory of Aspell.")
988 (defun ispell-get-aspell-config-value (key)
989 "Return value of Aspell configuration option KEY.
990 Assumes that value contains no whitespace."
992 (ispell-call-process ispell-program-name nil t nil "config" key)
993 (car (split-string (buffer-string)))))
995 (defun ispell-aspell-find-dictionary (dict-name)
996 "For aspell dictionary DICT-NAME, return a list of parameters if an
997 associated data file is found or nil otherwise. List format is that
998 of `ispell-dictionary-base-alist' elements."
999 ;; Make sure `ispell-aspell-data-dir' is defined
1000 (or ispell-aspell-data-dir
1001 (setq ispell-aspell-data-dir
1002 (ispell-get-aspell-config-value "data-dir")))
1003 ;; Try finding associated datafile
1005 (concat ispell-aspell-data-dir "/"
1006 ;; Strip out variant, country code, etc.
1007 (and (string-match "^[[:alpha:]]+" dict-name)
1008 (match-string 0 dict-name)) ".dat"))
1010 (concat ispell-aspell-data-dir "/"
1011 ;; Strip out anything but xx_YY.
1012 (and (string-match "^[[:alpha:]_]+" dict-name)
1013 (match-string 0 dict-name)) ".dat"))
1015 (if (file-readable-p datafile1)
1017 (if (file-readable-p datafile2)
1023 (insert-file-contents data-file)
1024 ;; There is zero or one line with special characters declarations.
1025 (when (search-forward-regexp "^special" nil t)
1026 (let ((specials (split-string
1027 (buffer-substring (point)
1028 (progn (end-of-line) (point))))))
1029 ;; The line looks like: special ' -** - -** . -** : -*-
1030 ;; -** means that this character
1031 ;; - doesn't appear at word start
1032 ;; * may appear in the middle of a word
1033 ;; * may appear at word end
1034 ;; `otherchars' is about the middle case.
1036 (when (eq (aref (cadr specials) 1) ?*)
1037 (push (car specials) otherchars))
1038 (setq specials (cddr specials)))))
1042 (regexp-opt otherchars)
1043 t ; We can't tell, so set this to t
1044 (list "-d" dict-name)
1045 nil ; aspell doesn't support this
1046 ;; Here we specify the encoding to use while communicating with
1047 ;; aspell. This doesn't apply to command line arguments, so
1048 ;; just don't pass words to spellcheck as arguments...
1051 (defun ispell-aspell-add-aliases (alist)
1052 "Find aspell's dictionary aliases and add them to dictionary ALIST.
1053 Return the new dictionary alist."
1055 (file-expand-wildcards
1056 (concat (or ispell-aspell-dict-dir
1057 (setq ispell-aspell-dict-dir
1058 (ispell-get-aspell-config-value "dict-dir")))
1060 (dolist (alias-file aliases)
1062 (insert-file-contents alias-file)
1063 ;; Look for a line "add FOO.multi", extract FOO
1064 (when (search-forward-regexp "^add \\([^.]+\\)\\.multi" nil t)
1065 (let* ((aliasname (file-name-sans-extension
1066 (file-name-nondirectory alias-file)))
1067 (already-exists-p (assoc aliasname alist))
1068 (realname (match-string 1))
1069 (realdict (assoc realname alist)))
1070 (when (and realdict (not already-exists-p))
1071 (push (cons aliasname (cdr realdict)) alist))))))
1074 ;; Set params according to the selected spellchecker
1076 (defvar ispell-last-program-name nil
1077 "Last value of `ispell-program-name'. Internal use.")
1079 (defvar ispell-initialize-spellchecker-hook nil
1080 "Normal hook run on spellchecker initialization.
1081 This hook is run when a spellchecker is used for the first
1082 time, before `ispell-dictionary-alist' is set. It is intended for
1083 sysadmins to override entries in `ispell-dictionary-base-alist'
1084 by putting those overrides in `ispell-base-dicts-override-alist', which is
1085 a dynamically scoped var with same format as `ispell-dictionary-alist'.
1086 This alist will not override the auto-detected values (e.g. if a recent
1087 aspell is used along with Emacs).")
1089 (defun ispell-set-spellchecker-params ()
1090 "Initialize some spellchecker parameters when changed or first used."
1091 (unless (eq ispell-last-program-name ispell-program-name)
1092 (setq ispell-last-program-name ispell-program-name)
1093 (ispell-kill-ispell t)
1094 (if (and (condition-case ()
1096 (setq ispell-library-directory (ispell-check-version))
1099 ispell-really-aspell
1100 ispell-encoding8-command
1101 ispell-emacs-alpha-regexp)
1102 (unless ispell-aspell-dictionary-alist
1103 (ispell-find-aspell-dictionaries)))
1105 ;; Substitute ispell-dictionary-alist with the list of dictionaries
1106 ;; corresponding to the given spellchecker. If a recent aspell, use
1107 ;; the list of really installed dictionaries and add to it elements
1108 ;; of the original list that are not present there. Allow distro info.
1109 (let ((found-dicts-alist
1110 (if (and ispell-really-aspell
1111 ispell-encoding8-command)
1112 ispell-aspell-dictionary-alist
1114 ispell-base-dicts-override-alist ; Override only base-dicts-alist
1117 (run-hooks 'ispell-initialize-spellchecker-hook)
1119 ;; Add dicts to ``ispell-dictionary-alist'' unless already present.
1120 (dolist (dict (append found-dicts-alist
1121 ispell-base-dicts-override-alist
1122 ispell-dictionary-base-alist))
1123 (unless (assoc (car dict) all-dicts-alist)
1124 (add-to-list 'all-dicts-alist dict)))
1125 (setq ispell-dictionary-alist all-dicts-alist))
1127 ;; If Emacs flavor supports [:alpha:] use it for global dicts. If
1128 ;; spellchecker also supports UTF-8 via command-line option use it
1129 ;; in communication. This does not affect definitions in ~/.emacs.
1130 (if ispell-emacs-alpha-regexp
1131 (let (tmp-dicts-alist)
1132 (dolist (adict ispell-dictionary-alist)
1133 (add-to-list 'tmp-dicts-alist
1135 (nth 0 adict) ; dict name
1136 "[[:alpha:]]" ; casechars
1137 "[^[:alpha:]]" ; not-casechars
1138 (nth 3 adict) ; otherchars
1139 (nth 4 adict) ; many-otherchars-p
1140 (nth 5 adict) ; ispell-args
1141 (nth 6 adict) ; extended-character-mode
1142 (if ispell-encoding8-command
1145 (setq ispell-dictionary-alist tmp-dicts-alist)))))
1147 (defun ispell-valid-dictionary-list ()
1148 "Return a list of valid dictionaries.
1149 The variable `ispell-library-directory' defines their location."
1150 ;; Initialize variables and dictionaries alists for desired spellchecker.
1151 ;; Make sure ispell.el is loaded to avoid some autoload loops in XEmacs
1152 ;; (and may be others)
1153 (if (featurep 'ispell)
1154 (ispell-set-spellchecker-params))
1156 (let ((dicts (append ispell-local-dictionary-alist ispell-dictionary-alist))
1157 (dict-list (cons "default" nil))
1159 (dolist (dict dicts)
1160 (setq name (car dict)
1161 dict-bname (or (car (cdr (member "-d" (nth 5 dict))))
1163 ;; Include if the dictionary is in the library, or dir not defined.
1166 ;; For Aspell, we already know which dictionaries exist.
1167 (or ispell-really-aspell
1168 ;; Include all dictionaries if lib directory not known.
1169 ;; Same for Hunspell, where ispell-library-directory is nil.
1170 (not ispell-library-directory)
1171 (file-exists-p (concat ispell-library-directory
1172 "/" dict-bname ".hash"))
1173 (file-exists-p (concat ispell-library-directory
1174 "/" dict-bname ".has"))))
1175 (push name dict-list)))
1178 ;;; define commands in menu in opposite order you want them to appear.
1180 (if ispell-menu-map-needed
1182 (setq ispell-menu-map (make-sparse-keymap "Spell"))
1183 (define-key ispell-menu-map [ispell-change-dictionary]
1184 `(menu-item ,(purecopy "Change Dictionary...") ispell-change-dictionary
1185 :help ,(purecopy "Supply explicit dictionary file name")))
1186 (define-key ispell-menu-map [ispell-kill-ispell]
1187 `(menu-item ,(purecopy "Kill Process") ispell-kill-ispell
1188 :enable (and (boundp 'ispell-process) ispell-process
1189 (eq (ispell-process-status) 'run))
1190 :help ,(purecopy "Terminate Ispell subprocess")))
1191 (define-key ispell-menu-map [ispell-pdict-save]
1192 `(menu-item ,(purecopy "Save Dictionary")
1193 (lambda () (interactive) (ispell-pdict-save t t))
1194 :help ,(purecopy "Save personal dictionary")))
1195 (define-key ispell-menu-map [ispell-customize]
1196 `(menu-item ,(purecopy "Customize...")
1197 (lambda () (interactive) (customize-group 'ispell))
1198 :help ,(purecopy "Customize spell checking options")))
1199 (define-key ispell-menu-map [ispell-help]
1200 ;; use (x-popup-menu last-nonmenu-event(list "" ispell-help-list)) ?
1201 `(menu-item ,(purecopy "Help")
1202 (lambda () (interactive) (describe-function 'ispell-help))
1203 :help ,(purecopy "Show standard Ispell keybindings and commands")))
1204 (define-key ispell-menu-map [flyspell-mode]
1205 `(menu-item ,(purecopy "Automatic spell checking (Flyspell)")
1207 :help ,(purecopy "Check spelling while you edit the text")
1208 :button (:toggle . (bound-and-true-p flyspell-mode))))
1209 (define-key ispell-menu-map [ispell-complete-word]
1210 `(menu-item ,(purecopy "Complete Word") ispell-complete-word
1211 :help ,(purecopy "Complete word at cursor using dictionary")))
1212 (define-key ispell-menu-map [ispell-complete-word-interior-frag]
1213 `(menu-item ,(purecopy "Complete Word Fragment")
1214 ispell-complete-word-interior-frag
1215 :help ,(purecopy "Complete word fragment at cursor")))))
1218 (if ispell-menu-map-needed
1220 (define-key ispell-menu-map [ispell-continue]
1221 `(menu-item ,(purecopy "Continue Spell-Checking") ispell-continue
1222 :enable (and (boundp 'ispell-region-end)
1223 (marker-position ispell-region-end)
1224 (equal (marker-buffer ispell-region-end)
1226 :help ,(purecopy "Continue spell checking last region")))
1227 (define-key ispell-menu-map [ispell-word]
1228 `(menu-item ,(purecopy "Spell-Check Word") ispell-word
1229 :help ,(purecopy "Spell-check word at cursor")))
1230 (define-key ispell-menu-map [ispell-comments-and-strings]
1231 `(menu-item ,(purecopy "Spell-Check Comments")
1232 ispell-comments-and-strings
1233 :help ,(purecopy "Spell-check only comments and strings")))))
1236 (if ispell-menu-map-needed
1238 (define-key ispell-menu-map [ispell-region]
1239 `(menu-item ,(purecopy "Spell-Check Region") ispell-region
1241 :help ,(purecopy "Spell-check text in marked region")))
1242 (define-key ispell-menu-map [ispell-message]
1243 `(menu-item ,(purecopy "Spell-Check Message") ispell-message
1244 :visible (eq major-mode 'mail-mode)
1245 :help ,(purecopy "Skip headers and included message text")))
1246 (define-key ispell-menu-map [ispell-buffer]
1247 `(menu-item ,(purecopy "Spell-Check Buffer") ispell-buffer
1248 :help ,(purecopy "Check spelling of selected buffer")))
1249 ;;(put 'ispell-region 'menu-enable 'mark-active)
1250 (fset 'ispell-menu-map (symbol-value 'ispell-menu-map))))
1252 ;;; XEmacs versions 19 & 20
1253 (if (and (featurep 'xemacs)
1255 ;;(null ispell-menu-xemacs)
1256 (not (and (boundp 'infodock-version) infodock-version)))
1257 (let ((dicts (if (fboundp 'ispell-valid-dictionary-list)
1258 (reverse (ispell-valid-dictionary-list))))
1259 (current-menubar (or current-menubar default-menubar))
1261 '(["Help" (describe-function 'ispell-help) t]
1262 ;;["Help" (popup-menu ispell-help-list) t]
1263 ["Check Message" ispell-message t]
1264 ["Check Buffer" ispell-buffer t]
1265 ["Check Comments" ispell-comments-and-strings t]
1266 ["Check Word" ispell-word t]
1267 ["Check Region" ispell-region (or (not zmacs-regions) (mark))]
1268 ["Continue Check" ispell-continue t]
1269 ["Complete Word Frag"ispell-complete-word-interior-frag t]
1270 ["Complete Word" ispell-complete-word t]
1271 ["Kill Process" ispell-kill-ispell t]
1272 ["Customize..." (customize-group 'ispell) t]
1273 ;; flyspell-mode may not be bound...
1274 ;;["flyspell" flyspell-mode
1275 ;; :style toggle :selected flyspell-mode ]
1277 ["Save Personal Dict"(ispell-pdict-save t t) t]
1278 ["Change Dictionary" ispell-change-dictionary t])))
1280 (setq dicts (cons "default" nil)))
1281 (dolist (name dicts)
1282 (setq menu (append menu
1285 (concat "Select " (capitalize name))
1286 (list 'ispell-change-dictionary name)
1288 (setq ispell-menu-xemacs menu)
1291 (if (car (find-menu-item current-menubar '("Cmds")))
1294 (delete-menu-item '("Cmds" "Spell-Check"))
1295 (add-menu '("Cmds") "Spell-Check" ispell-menu-xemacs))
1297 (delete-menu-item '("Edit" "Spell")) ; in case already defined
1298 (add-menu '("Edit") "Spell" ispell-menu-xemacs))))))
1300 (defalias 'ispell-int-char
1301 ;; Allow incrementing characters as integers in XEmacs 20
1302 (if (and (featurep 'xemacs)
1303 (fboundp 'int-char))
1305 ;; Emacs and XEmacs 19 or earlier
1309 ;;; **********************************************************************
1311 (defvar ispell-current-dictionary nil
1312 "The name of the current dictionary, or nil for the default.
1313 This is passed to the ispell process using the `-d' switch and is
1314 used as key in `ispell-local-dictionary-alist' and `ispell-dictionary-alist'.")
1316 (defvar ispell-current-personal-dictionary nil
1317 "The name of the current personal dictionary, or nil for the default.
1318 This is passed to the ispell process using the `-p' switch.")
1320 (defun ispell-decode-string (str)
1321 "Decodes multibyte character strings.
1322 Protects against bogus binding of `enable-multibyte-characters' in XEmacs."
1323 ;; FIXME: enable-multibyte-characters is read-only, so bogus bindings are
1324 ;; really nasty (they signal an error in Emacs): Who does that? --Stef
1325 (if (and (or (featurep 'xemacs)
1326 (and (boundp 'enable-multibyte-characters)
1327 enable-multibyte-characters))
1328 (fboundp 'decode-coding-string)
1329 (ispell-get-coding-system))
1330 (decode-coding-string str (ispell-get-coding-system))
1333 ;; Return a string decoded from Nth element of the current dictionary.
1334 (defun ispell-get-decoded-string (n)
1335 "Get the decoded string in slot N of the descriptor of the current dict."
1337 (assoc ispell-current-dictionary ispell-local-dictionary-alist)
1338 (assoc ispell-current-dictionary ispell-dictionary-alist)
1339 (error "No data for dictionary \"%s\", neither in `ispell-local-dictionary-alist' nor in `ispell-dictionary-alist'"
1340 ispell-current-dictionary)))
1342 (when (and (> (length str) 0)
1343 (not (multibyte-string-p str)))
1344 (setq str (ispell-decode-string str))
1345 (or (multibyte-string-p str)
1346 (setq str (string-to-multibyte str))))
1349 (defun ispell-get-casechars ()
1350 (ispell-get-decoded-string 1))
1351 (defun ispell-get-not-casechars ()
1352 (ispell-get-decoded-string 2))
1353 (defun ispell-get-otherchars ()
1354 (ispell-get-decoded-string 3))
1355 (defun ispell-get-many-otherchars-p ()
1356 (nth 4 (or (assoc ispell-current-dictionary ispell-local-dictionary-alist)
1357 (assoc ispell-current-dictionary ispell-dictionary-alist))))
1358 (defun ispell-get-ispell-args ()
1359 (nth 5 (or (assoc ispell-current-dictionary ispell-local-dictionary-alist)
1360 (assoc ispell-current-dictionary ispell-dictionary-alist))))
1361 (defun ispell-get-extended-character-mode ()
1362 (if ispell-really-hunspell ;; hunspell treats ~word as ordinary words
1363 nil ;; in pipe mode. Disable extended-char-mode
1364 (nth 6 (or (assoc ispell-current-dictionary ispell-local-dictionary-alist)
1365 (assoc ispell-current-dictionary ispell-dictionary-alist)))))
1366 (defun ispell-get-coding-system ()
1367 (nth 7 (or (assoc ispell-current-dictionary ispell-local-dictionary-alist)
1368 (assoc ispell-current-dictionary ispell-dictionary-alist))))
1371 (defvar ispell-pdict-modified-p nil
1372 "Non-nil means personal dictionary has modifications to be saved.")
1374 ;;; If you want to save the dictionary when quitting, must do so explicitly.
1375 ;;; When non-nil, the spell session is terminated.
1376 ;;; When numeric, contains cursor location in buffer, and cursor remains there.
1377 (defvar ispell-quit nil)
1379 (defvar ispell-process-directory nil
1380 "The directory where `ispell-process' was started.")
1382 (defvar ispell-filter nil
1383 "Output filter from piped calls to Ispell.")
1385 (defvar ispell-filter-continue nil
1386 "Control variable for Ispell filter function.")
1388 (defvar ispell-output-buffer nil
1389 "Buffer used for reading output of a synchronous Ispell subprocess.")
1391 (defvar ispell-session-buffer nil
1392 "Buffer used for passing input to a synchronous Ispell subprocess.")
1394 (defvar ispell-cmd-args nil
1395 "Command-line arguments to pass to a synchronous Ispell subprocess.")
1397 (defvar ispell-query-replace-marker (make-marker)
1398 "Marker for `query-replace' processing.")
1400 (defvar ispell-recursive-edit-marker (make-marker)
1401 "Marker for return point from recursive edit.")
1403 (defvar ispell-checking-message nil
1404 "Non-nil when we're checking a mail message.
1405 Set to the MIME boundary locations when checking messages.")
1407 (defconst ispell-choices-buffer "*Choices*")
1409 (defvar ispell-overlay nil "Overlay variable for Ispell highlighting.")
1411 ;;; *** Buffer Local Definitions ***
1413 (defconst ispell-words-keyword "LocalWords: "
1414 "The keyword for local oddly-spelled words to accept.
1415 The keyword will be followed by any number of local word spellings.
1416 There can be multiple instances of this keyword in the file.")
1418 (defconst ispell-dictionary-keyword "Local IspellDict: "
1419 "The keyword for a local dictionary to use.
1420 The keyword must be followed by a valid dictionary name, defined in
1421 `ispell-local-dictionary-alist' or `ispell-dictionary-alist'.
1422 When multiple occurrences exist, the last keyword
1423 definition is used.")
1425 (defconst ispell-pdict-keyword "Local IspellPersDict: "
1426 "The keyword for defining buffer local dictionaries.
1427 Keyword must be followed by the filename of a personal dictionary.
1428 The last occurring definition in the buffer will be used.")
1430 (defconst ispell-parsing-keyword "Local IspellParsing: "
1431 "The keyword for overriding default Ispell parsing.
1432 The above keyword string should be followed by `latex-mode' or
1433 `nroff-mode' to put the current buffer into the desired parsing mode.
1435 Extended character mode can be changed for this buffer by placing
1436 a `~' followed by an extended-character mode -- such as `~.tex'.
1437 The last occurring definition in the buffer will be used.")
1440 (defvar ispell-skip-region-alist
1441 `((ispell-words-keyword forward-line)
1442 (ispell-dictionary-keyword forward-line)
1443 (ispell-pdict-keyword forward-line)
1444 (ispell-parsing-keyword forward-line)
1445 (,(purecopy "^---*BEGIN PGP [A-Z ]*--*")
1446 . ,(purecopy "^---*END PGP [A-Z ]*--*"))
1447 ;; assume multiline uuencoded file? "\nM.*$"?
1448 (,(purecopy "^begin [0-9][0-9][0-9] [^ \t]+$") . ,(purecopy "\nend\n"))
1449 (,(purecopy "^%!PS-Adobe-[123].0") . ,(purecopy "\n%%EOF\n"))
1450 (,(purecopy "^---* \\(Start of \\)?[Ff]orwarded [Mm]essage")
1451 . ,(purecopy "^---* End of [Ff]orwarded [Mm]essage"))
1452 ;; Matches e-mail addresses, file names, http addresses, etc. The
1453 ;; `-+' `_+' patterns are necessary for performance reasons when
1454 ;; `-' or `_' part of word syntax.
1455 (,(purecopy "\\(--+\\|_+\\|\\(/\\w\\|\\(\\(\\w\\|[-_]\\)+[.:@]\\)\\)\\(\\w\\|[-_]\\)*\\([.:/@]+\\(\\w\\|[-_~=?&]\\)+\\)+\\)"))
1456 ;; above checks /.\w sequences
1457 ;;("\\(--+\\|\\(/\\|\\(\\(\\w\\|[-_]\\)+[.:@]\\)\\)\\(\\w\\|[-_]\\)*\\([.:/@]+\\(\\w\\|[-_~=?&]\\)+\\)+\\)")
1458 ;; This is a pretty complex regexp. It can be simplified to the following:
1459 ;; "\\(\\w\\|[-_]\\)*\\([.:/@]+\\(\\w\\|[-_]\\|~\\)+\\)+"
1460 ;; but some valid text will be skipped, e.g. "his/her". This could be
1461 ;; fixed up (at the expense of a moderately more complex regexp)
1462 ;; by not allowing "/" to be the character which triggers the
1463 ;; identification of the computer name, e.g.:
1464 ;; "\\(\\w\\|[-_]\\)+[.:@]\\(\\w\\|[-_]\\)*\\([.:/@]+\\(\\w\\|[-_]\\|~\\)+\\)+"
1466 "Alist expressing beginning and end of regions not to spell check.
1467 The alist key must be a regular expression.
1468 Valid forms include:
1469 (KEY) - just skip the key.
1470 (KEY . REGEXP) - skip to the end of REGEXP. REGEXP may be string or symbol.
1471 (KEY REGEXP) - skip to end of REGEXP. REGEXP must be a string.
1472 (KEY FUNCTION ARGS) - FUNCTION called with ARGS returns end of region.")
1473 (put 'ispell-skip-region-alist 'risky-local-variable t)
1477 (defvar ispell-tex-skip-alists
1479 '((;;("%\\[" . "%\\]") ; AMStex block comment...
1480 ;; All the standard LaTeX keywords from L. Lamport's guide:
1481 ;; \cite, \hspace, \hspace*, \hyphenation, \include, \includeonly, \input,
1482 ;; \label, \nocite, \rule (in ispell - rest included here)
1483 ("\\\\addcontentsline" ispell-tex-arg-end 2)
1484 ("\\\\add\\(tocontents\\|vspace\\)" ispell-tex-arg-end)
1485 ("\\\\\\([aA]lph\\|arabic\\)" ispell-tex-arg-end)
1486 ;;("\\\\author" ispell-tex-arg-end)
1487 ("\\\\bibliographystyle" ispell-tex-arg-end)
1488 ("\\\\makebox" ispell-tex-arg-end 0)
1489 ("\\\\e?psfig" ispell-tex-arg-end)
1490 ("\\\\document\\(class\\|style\\)" .
1491 "\\\\begin[ \t\n]*{[ \t\n]*document[ \t\n]*}"))
1492 (;; delimited with \begin. In ispell: displaymath, eqnarray, eqnarray*,
1493 ;; equation, minipage, picture, tabular, tabular* (ispell)
1494 ("\\(figure\\|table\\)\\*?" ispell-tex-arg-end 0)
1495 ("list" ispell-tex-arg-end 2)
1496 ("program" . "\\\\end[ \t\n]*{[ \t\n]*program[ \t\n]*}")
1497 ("verbatim\\*?" . "\\\\end[ \t\n]*{[ \t\n]*verbatim\\*?[ \t\n]*}"))))
1498 "Lists of regions to be skipped in TeX mode.
1499 First list is used raw.
1500 Second list has key placed inside \\begin{}.
1502 Delete or add any regions you want to be automatically selected
1503 for skipping in latex mode.")
1504 (put 'ispell-tex-skip-alist 'risky-local-variable t)
1508 (defconst ispell-html-skip-alists
1509 '(("<[cC][oO][dD][eE]\\>[^>]*>" "</[cC][oO][dD][eE]*>")
1510 ("<[sS][cC][rR][iI][pP][tT]\\>[^>]*>" "</[sS][cC][rR][iI][pP][tT]>")
1511 ("<[aA][pP][pP][lL][eE][tT]\\>[^>]*>" "</[aA][pP][pP][lL][eE][tT]>")
1512 ("<[vV][eE][rR][bB]\\>[^>]*>" "<[vV][eE][rR][bB]\\>[^>]*>")
1513 ;;("<[tT][tT]\\>[^>]*>" "<[tT][tT]\\>[^>]*>")
1516 ("&[^ \t\n;]" "[; \t\n]"))
1517 "Lists of start and end keys to skip in HTML buffers.
1518 Same format as `ispell-skip-region-alist'.
1519 Note - substrings of other matches must come last
1520 (e.g. \"<[tT][tT]/\" and \"<[^ \\t\\n>]\").")
1521 (put 'ispell-html-skip-alists 'risky-local-variable t)
1523 (defvar ispell-local-pdict ispell-personal-dictionary
1524 "A buffer local variable containing the current personal dictionary.
1525 If non-nil, the value must be a string, which is a file name.
1527 If you specify a personal dictionary for the current buffer which is
1528 different from the current personal dictionary, the effect is similar
1529 to calling \\[ispell-change-dictionary]. This variable is automatically
1530 set when defined in the file with either `ispell-pdict-keyword' or the
1531 local variable syntax.")
1533 (make-variable-buffer-local 'ispell-local-pdict)
1534 ;;;###autoload(put 'ispell-local-pdict 'safe-local-variable 'stringp)
1536 (defvar ispell-buffer-local-name nil
1537 "Contains the buffer name if local word definitions were used.
1538 Ispell is then restarted because the local words could conflict.")
1540 (defvar ispell-parser 'use-mode-name
1541 "Indicates whether ispell should parse the current buffer as TeX Code.
1542 Special value `use-mode-name' tries to guess using the name of `major-mode'.
1543 Default parser is `nroff'.
1544 Currently the only other valid parser is `tex'.
1546 You can set this variable in hooks in your init file -- eg:
1548 \(add-hook 'tex-mode-hook (lambda () (setq ispell-parser 'tex)))")
1550 (defvar ispell-region-end (make-marker)
1551 "Marker that allows spelling continuations.")
1553 (defvar ispell-check-only nil
1554 "If non-nil, `ispell-word' does not try to correct the word.")
1557 ;;; **********************************************************************
1558 ;;; **********************************************************************
1562 ;;;###autoload (define-key esc-map "$" 'ispell-word)
1565 (defun ispell-accept-output (&optional timeout-secs timeout-msecs)
1566 "Wait for output from ispell process, or TIMEOUT-SECS and TIMEOUT-MSECS.
1567 If asynchronous subprocesses are not supported, call `ispell-filter' and
1568 pass it the output of the last ispell invocation."
1569 (if ispell-async-processp
1570 (accept-process-output ispell-process timeout-secs timeout-msecs)
1571 (if (null ispell-process)
1572 (error "No Ispell process to read output from!")
1573 (let ((buf ispell-output-buffer)
1575 (if (not (bufferp buf))
1576 (setq ispell-filter nil)
1577 (with-current-buffer buf
1578 (setq ispell-output (buffer-substring-no-properties
1579 (point-min) (point-max))))
1580 (ispell-filter t ispell-output)
1581 (with-current-buffer buf
1582 (erase-buffer)))))))
1584 (defun ispell-send-replacement (misspelled replacement)
1585 "Notify aspell that MISSPELLED should be spelled REPLACEMENT.
1586 This allows it to improve the suggestion list based on actual misspellings."
1587 (and ispell-really-aspell
1588 (ispell-send-string (concat "$$ra " misspelled "," replacement "\n"))))
1591 (defun ispell-send-string (string)
1592 "Send the string STRING to the Ispell process."
1593 (if ispell-async-processp
1594 (process-send-string ispell-process string)
1595 ;; Asynchronous subprocesses aren't supported on this losing system.
1596 ;; We keep all the directives passed to Ispell during the entire
1597 ;; session in a buffer, and pass them anew each time we invoke
1598 ;; Ispell to process another chunk of text. (Yes, I know this is a
1599 ;; terrible kludge, and it's a bit slow, but it does get the work done.)
1600 (let ((cmd (aref string 0))
1601 ;; The following commands are not passed to Ispell until
1602 ;; we have a *real* reason to invoke it.
1603 (cmds-to-defer '(?* ?@ ?~ ?+ ?- ?! ?%))
1604 (session-buf ispell-session-buffer)
1605 (output-buf ispell-output-buffer)
1606 (ispell-args ispell-cmd-args)
1607 (defdir ispell-process-directory)
1609 (with-current-buffer session-buf
1610 (setq prev-pos (point))
1611 (setq default-directory defdir)
1613 (if (not (memq cmd cmds-to-defer))
1614 (let (coding-system-for-read coding-system-for-write status)
1615 (if (and (boundp 'enable-multibyte-characters)
1616 enable-multibyte-characters)
1617 (setq coding-system-for-read (ispell-get-coding-system)
1618 coding-system-for-write (ispell-get-coding-system)))
1619 (set-buffer output-buf)
1621 (set-buffer session-buf)
1623 (apply 'ispell-call-process-region
1624 (point-min) (point-max)
1625 ispell-program-name nil
1628 ;; hunspell -m option means something different
1629 (if ispell-really-hunspell "" "-m")
1631 (set-buffer output-buf)
1632 (goto-char (point-min))
1634 (if (not (looking-at "@(#) "))
1635 (error "Ispell error: %s"
1636 (buffer-substring-no-properties
1637 (point) (progn (end-of-line) (point)))))
1638 ;; If STRING is "^Z\n", we just started Ispell and need
1639 ;; to retain its version ID line in the output buffer.
1640 ;; Otherwise, remove the ID line, as it will confuse
1642 (or (string= string "\032\n")
1645 (delete-region (point-min) (point))))
1646 ;; If STRING begins with ^ or any normal character, we need
1647 ;; to remove the last line from the session buffer, since it
1648 ;; was just spell-checked, and we don't want to check it again.
1649 ;; The same goes for the # command, since Ispell already saved
1650 ;; the personal dictionary.
1651 (set-buffer session-buf)
1652 (delete-region prev-pos (point))
1653 ;; Ispell run synchronously saves the personal dictionary
1654 ;; after each successful command. So we can remove any
1655 ;; lines in the session buffer that insert words into the
1657 (if (memq status '(0 nil))
1658 (let ((more-lines t))
1659 (goto-char (point-min))
1661 (if (looking-at "^\\*")
1662 (let ((start (point)))
1664 (delete-region start (point)))
1665 (setq more-lines (= 0 (forward-line))))))))))))))
1668 ;; Insert WORD while possibly translating characters by
1669 ;; translation-table-for-input.
1670 (defun ispell-insert-word (word)
1671 (let ((pos (point)))
1673 ;; Avoid "obsolete" warnings for translation-table-for-input.
1675 (if (char-table-p translation-table-for-input)
1676 (translate-region pos (point) translation-table-for-input)))))
1679 (defun ispell-word (&optional following quietly continue region)
1680 "Check spelling of word under or before the cursor.
1681 If the word is not found in dictionary, display possible corrections
1682 in a window allowing you to choose one.
1684 If optional argument FOLLOWING is non-nil or if `ispell-following-word'
1685 is non-nil when called interactively, then the following word
1686 \(rather than preceding\) is checked when the cursor is not over a word.
1687 When the optional argument QUIETLY is non-nil or `ispell-quietly' is non-nil
1688 when called interactively, non-corrective messages are suppressed.
1690 With a prefix argument (or if CONTINUE is non-nil),
1691 resume interrupted spell-checking of a buffer or region.
1693 Interactively, in Transient Mark mode when the mark is active, call
1694 `ispell-region' to check the active region for spelling errors.
1696 Word syntax is controlled by the definition of the chosen dictionary,
1697 which is in `ispell-local-dictionary-alist' or `ispell-dictionary-alist'.
1699 This will check or reload the dictionary. Use \\[ispell-change-dictionary]
1700 or \\[ispell-region] to update the Ispell process.
1703 nil word is correct or spelling is accepted.
1704 0 word is inserted into buffer-local definitions.
1705 \"word\" word corrected from word list.
1706 \(\"word\" arg\) word is hand entered.
1707 quit spell session exited."
1708 (interactive (list ispell-following-word ispell-quietly current-prefix-arg t))
1710 ((and region (use-region-p))
1711 (ispell-region (region-beginning) (region-end)))
1712 (continue (ispell-continue))
1714 (ispell-set-spellchecker-params) ; Initialize variables and dicts alists
1715 (ispell-accept-buffer-local-defs) ; use the correct dictionary
1716 (let ((cursor-location (point)) ; retain cursor location
1717 (word (ispell-get-word following))
1718 start end poss new-word replace)
1719 ;; De-structure return word info list.
1720 (setq start (car (cdr word))
1721 end (car (cdr (cdr word)))
1724 ;; At this point it used to ignore 2-letter words.
1725 ;; But that is silly; if the user asks for it, we should do it. - rms.
1727 (message "Checking spelling of %s..."
1728 (funcall ispell-format-word-function word)))
1729 (ispell-send-string "%\n") ; put in verbose mode
1730 (ispell-send-string (concat "^" word "\n"))
1731 ;; wait until ispell has processed word
1733 (ispell-accept-output)
1734 (not (string= "" (car ispell-filter)))))
1735 ;;(ispell-send-string "!\n") ;back to terse mode.
1736 (setq ispell-filter (cdr ispell-filter)) ; remove extra \n
1737 (if (and ispell-filter (listp ispell-filter))
1738 (if (> (length ispell-filter) 1)
1739 (error "Ispell and its process have different character maps")
1740 (setq poss (ispell-parse-output (car ispell-filter)))))
1743 (message "%s is correct"
1744 (funcall ispell-format-word-function word)))
1745 (and (featurep 'xemacs)
1747 (and (fboundp 'delete-extent)
1748 (delete-extent (extent-at start)))))
1751 (message "%s is correct because of root %s"
1752 (funcall ispell-format-word-function word)
1753 (funcall ispell-format-word-function poss)))
1754 (and (featurep 'xemacs)
1756 (and (fboundp 'delete-extent)
1757 (delete-extent (extent-at start)))))
1759 (message "Error checking word %s using %s with %s dictionary"
1760 (funcall ispell-format-word-function word)
1761 (file-name-nondirectory ispell-program-name)
1762 (or ispell-current-dictionary "default")))
1763 (ispell-check-only ; called from ispell minor mode.
1764 (if (fboundp 'make-extent)
1765 (if (fboundp 'set-extent-property)
1766 (let ((ext (make-extent start end)))
1767 (set-extent-property ext 'face ispell-highlight-face)
1768 (set-extent-property ext 'priority 2000)))
1770 (message "%s is incorrect"
1771 (funcall ispell-format-word-function word))))
1772 (t ; prompt for correct word.
1773 (save-window-excursion
1774 (setq replace (ispell-command-loop
1775 (car (cdr (cdr poss)))
1776 (car (cdr (cdr (cdr poss))))
1777 (car poss) start end)))
1778 (cond ((equal 0 replace)
1779 (ispell-add-per-file-word-list (car poss)))
1781 (setq new-word (if (atom replace) replace (car replace))
1782 cursor-location (+ (- (length word) (- end start))
1784 (if (not (equal new-word (car poss)))
1787 ;; Insert first and then delete,
1788 ;; to avoid collapsing markers before and after
1789 ;; into a single place.
1790 (ispell-insert-word new-word)
1791 (delete-region (point) end)
1792 ;; It is meaningless to preserve the cursor position
1793 ;; inside a word that has changed.
1794 (setq cursor-location (point))
1795 (setq end (point))))
1796 (if (not (atom replace)) ;recheck spelling of replacement
1798 (if (car (cdr replace)) ; query replace requested
1799 (save-window-excursion
1800 (query-replace word new-word t)))
1802 ;; single word could be split into multiple words
1803 (setq ispell-quit (not (ispell-region start end)))
1805 ;; keep if rechecking word and we keep choices win.
1806 (if (get-buffer ispell-choices-buffer)
1807 (kill-buffer ispell-choices-buffer))))
1808 (ispell-pdict-save ispell-silently-savep)
1809 ;; NB: Cancels ispell-quit incorrectly if called from ispell-region
1810 (if ispell-quit (setq ispell-quit nil replace 'quit))
1811 (goto-char cursor-location) ; return to original location
1815 (defun ispell-get-word (following &optional extra-otherchars)
1816 "Return the word for spell-checking according to ispell syntax.
1817 If optional argument FOLLOWING is non-nil or if `ispell-following-word'
1818 is non-nil when called interactively, then the following word
1819 \(rather than preceding\) is checked when the cursor is not over a word.
1820 Optional second argument contains otherchars that can be included in word
1821 many times (see the doc string of `ispell-dictionary-alist' for details
1824 Word syntax is controlled by the definition of the chosen dictionary,
1825 which is in `ispell-local-dictionary-alist' or `ispell-dictionary-alist'."
1826 (ispell-set-spellchecker-params) ; Initialize variables and dicts alists
1827 (let* ((ispell-casechars (ispell-get-casechars))
1828 (ispell-not-casechars (ispell-get-not-casechars))
1829 (ispell-otherchars (ispell-get-otherchars))
1830 (ispell-many-otherchars-p (ispell-get-many-otherchars-p))
1831 (word-regexp (concat ispell-casechars
1833 (if (not (string= "" ispell-otherchars))
1834 (concat ispell-otherchars "?"))
1835 (if extra-otherchars
1836 (concat extra-otherchars "?"))
1839 (if (or ispell-many-otherchars-p
1845 (if (not (looking-at ispell-casechars))
1847 (re-search-forward ispell-casechars (point-max) t)
1848 (re-search-backward ispell-casechars (point-min) t)))
1849 ;; move to front of word
1850 (re-search-backward ispell-not-casechars (point-min) 'start)
1851 (while (and (or (and (not (string= "" ispell-otherchars))
1852 (looking-at ispell-otherchars))
1853 (and extra-otherchars (looking-at extra-otherchars)))
1855 (or (not did-it-once)
1856 ispell-many-otherchars-p)
1857 (not (eq prevpt (point))))
1858 (if (and extra-otherchars (looking-at extra-otherchars))
1861 (if (looking-at ispell-casechars)
1862 (re-search-backward ispell-not-casechars (point-min) 'move)))
1866 (if (looking-at ispell-casechars)
1867 (re-search-backward ispell-not-casechars (point-min) 'move)
1868 (backward-char -1))))
1869 ;; Now mark the word and save to string.
1870 (if (not (re-search-forward word-regexp (point-max) t))
1871 (if ispell-check-only
1872 ;; return dummy word when just flagging misspellings
1873 (list "" (point) (point))
1874 (error "No word found to check!"))
1875 (setq start (copy-marker (match-beginning 0))
1877 word (buffer-substring-no-properties start end))
1878 (list word start end))))
1881 ;;; Global ispell-pdict-modified-p is set by ispell-command-loop and
1882 ;;; tracks changes in the dictionary. The global may either be
1883 ;;; a value or a list, whose value is the state of whether the
1884 ;;; dictionary needs to be saved.
1887 (defun ispell-pdict-save (&optional no-query force-save)
1888 "Check to see if the personal dictionary has been modified.
1889 If so, ask if it needs to be saved."
1890 (interactive (list ispell-silently-savep t))
1891 (if (and ispell-pdict-modified-p (listp ispell-pdict-modified-p))
1892 (setq ispell-pdict-modified-p (car ispell-pdict-modified-p)))
1893 (if (or ispell-pdict-modified-p force-save)
1894 (if (or no-query (y-or-n-p "Personal dictionary modified. Save? "))
1896 (ispell-send-string "#\n") ; save dictionary
1897 (message "Personal dictionary saved."))))
1898 ;; unassert variable, even if not saved to avoid questioning.
1899 (setq ispell-pdict-modified-p nil))
1902 (defun ispell-command-loop (miss guess word start end)
1903 "Display possible corrections from list MISS.
1904 GUESS lists possibly valid affix construction of WORD.
1905 Returns nil to keep word.
1906 Returns 0 to insert locally into buffer-local dictionary.
1907 Returns string for new chosen word.
1908 Returns list for new replacement word (will be rechecked).
1909 Query-replace when list length is 2.
1910 Automatic query-replace when second element is `query-replace'.
1911 Highlights the word, which is assumed to run from START to END.
1912 Global `ispell-pdict-modified-p' becomes a list where the only value
1913 indicates whether the dictionary has been modified when option `a'
1915 Global `ispell-quit' set to start location to continue spell session."
1917 (line ispell-choices-win-default-height)
1918 ;; ensure 4 context lines.
1919 (max-lines (- (ispell-adjusted-window-height) 4))
1921 (window-min-height (min window-min-height
1922 ispell-choices-win-default-height))
1923 (command-characters '( ? ?i ?a ?A ?r ?R ?? ?x ?X ?q ?l ?u ?m ))
1924 (dedicated (window-dedicated-p (selected-window)))
1926 char num result textwin dedicated-win)
1928 ;; setup the *Choices* buffer with valid data.
1929 (with-current-buffer (get-buffer-create ispell-choices-buffer)
1930 (setq mode-line-format
1932 "-- %b -- word: " word
1933 " -- dict: " (or ispell-current-dictionary "default")
1934 " -- prog: " (file-name-nondirectory ispell-program-name)))
1935 ;; XEmacs: no need for horizontal scrollbar in choices window
1937 (and (fboundp 'set-specifier)
1938 (boundp 'horizontal-scrollbar-visible-p)
1939 (set-specifier horizontal-scrollbar-visible-p nil
1940 (cons (current-buffer) nil))))
1944 (insert "Affix rules generate and capitalize "
1945 "this word as shown below:\n\t")
1947 (if (> (+ 4 (current-column) (length (car guess)))
1951 (setq line (1+ line))))
1952 (insert (car guess) " ")
1953 (setq guess (cdr guess)))
1954 (insert "\nUse option `i' to accept this spelling and put it in your private dictionary.\n")
1955 (setq line (+ line (if choices 3 2)))))
1957 (< (if (> (+ 7 (current-column) (length (car choices))
1958 (if (> count ?~) 3 0))
1962 (setq line (1+ line)))
1965 ;; not so good if there are over 20 or 30 options, but then, if
1966 ;; there are that many you don't want to scan them all anyway...
1967 (while (memq count command-characters) ; skip command characters.
1968 (setq count (ispell-int-char (1+ count))
1969 skipped (1+ skipped)))
1970 (insert "(" count ") " (car choices) " ")
1971 (setq choices (cdr choices)
1972 count (ispell-int-char (1+ count))))
1973 (setq count (ispell-int-char (- count ?0 skipped))))
1975 ;; ensure word is visible
1976 (if (not (pos-visible-in-window-p end))
1979 ;; allow temporary split of dedicated windows...
1982 (setq dedicated-win (selected-window))
1983 (set-window-dedicated-p dedicated-win nil)))
1985 ;; Display choices for misspelled word.
1986 (ispell-show-choices line end)
1987 (select-window (setq textwin (next-window)))
1989 ;; highlight word, protecting current buffer status
1992 (and ispell-highlight-p
1993 (ispell-highlight-spelling-error start end t))
1994 ;; Loop until a valid choice is made.
2002 (let (message-log-max)
2003 (message (concat "C-h or ? for more options; SPC to leave "
2004 "unchanged, Character to replace word")))
2005 (let ((inhibit-quit t)
2007 (setq char nil skipped 0)
2008 ;; If the user types C-g, or generates some other
2009 ;; non-character event (such as a frame switch
2010 ;; event), stop ispell. As a special exception,
2011 ;; ignore mouse events occurring in the same frame.
2012 (while (and input-valid (not (characterp char)))
2013 (setq char (read-key))
2015 (or (characterp char)
2016 (and (mouse-event-p char)
2017 (eq (selected-frame)
2019 (posn-window (event-start char))))))))
2020 (when (or quit-flag (not input-valid) (= char ?\C-g))
2021 (setq char ?X quit-flag nil)))
2022 ;; Adjust num to array offset skipping command characters.
2023 (let ((com-chars command-characters))
2025 (if (and (> (car com-chars) ?0) (< (car com-chars) char))
2026 (setq skipped (1+ skipped)))
2027 (setq com-chars (cdr com-chars)))
2028 (setq num (- char ?0 skipped)))
2031 ((= char ? ) nil) ; accept word this time only
2032 ((= char ?i) ; accept and insert word into pers dict
2033 (ispell-send-string (concat "*" word "\n"))
2034 (setq ispell-pdict-modified-p '(t)) ; dictionary modified!
2036 ((or (= char ?a) (= char ?A)) ; accept word without insert
2037 (ispell-send-string (concat "@" word "\n"))
2038 (if (null ispell-pdict-modified-p)
2039 (setq ispell-pdict-modified-p
2040 (list ispell-pdict-modified-p)))
2041 (if (= char ?A) 0)) ; return 0 for ispell-add buffer-local
2042 ((or (= char ?r) (= char ?R)) ; type in replacement
2043 (and (eq 'block ispell-highlight-p) ; refresh tty's
2044 (ispell-highlight-spelling-error start end nil t))
2046 (if (or (= char ?R) ispell-query-replace-choices)
2048 (format "Query-replacement for %s: "word)
2051 (cons (read-string "Replacement for: " word)
2053 (and (eq 'block ispell-highlight-p)
2054 (ispell-highlight-spelling-error start end nil
2057 ((or (= char ??) (= char help-char) (= char ?\C-h))
2058 (and (eq 'block ispell-highlight-p)
2059 (ispell-highlight-spelling-error start end nil t))
2061 (and (eq 'block ispell-highlight-p)
2062 (ispell-highlight-spelling-error start end nil
2065 ;; Quit and move point back.
2067 (ispell-pdict-save ispell-silently-savep)
2068 (message "Exited spell-checking")
2069 (setq ispell-quit t)
2071 ;; Quit and preserve point.
2073 (ispell-pdict-save ispell-silently-savep)
2075 (substitute-command-keys
2076 (concat "Spell-checking suspended;"
2077 " use C-u \\[ispell-word] to resume")))
2078 (setq ispell-quit start)
2081 (if (y-or-n-p "Really kill Ispell process? ")
2083 (ispell-kill-ispell t) ; terminate process.
2084 (setq ispell-quit (or (not ispell-checking-message)
2086 ispell-pdict-modified-p nil))
2087 t)) ; continue if they don't quit.
2089 (and (eq 'block ispell-highlight-p) ; refresh tty displays
2090 (ispell-highlight-spelling-error start end nil t))
2091 (let ((new-word (read-string
2092 "Lookup string (`*' is wildcard): "
2096 (with-current-buffer (get-buffer-create
2097 ispell-choices-buffer)
2101 mode-line-format ;; setup the *Choices* buffer with valid data.
2102 (concat "-- %b -- word: " new-word
2104 (or ispell-complete-word-dict
2105 ispell-alternate-dictionary))
2106 miss (lookup-words new-word)
2108 line ispell-choices-win-default-height)
2109 (while (and choices ; adjust choices window.
2110 (< (if (> (+ 7 (current-column)
2111 (length (car choices))
2112 (if (> count ?~) 3 0))
2116 (setq line (1+ line)))
2119 (while (memq count command-characters)
2120 (setq count (ispell-int-char (1+ count))
2121 skipped (1+ skipped)))
2122 (insert "(" count ") " (car choices) " ")
2123 (setq choices (cdr choices)
2124 count (ispell-int-char (1+ count))))
2125 (setq count (ispell-int-char
2126 (- count ?0 skipped))))
2127 (ispell-show-choices line end)
2128 (select-window (next-window)))))
2129 (and (eq 'block ispell-highlight-p)
2130 (ispell-highlight-spelling-error start end nil
2132 t) ; reselect from new choices
2133 ((= char ?u) ; insert lowercase into dictionary
2134 (ispell-send-string (concat "*" (downcase word) "\n"))
2135 (setq ispell-pdict-modified-p '(t)) ; dictionary modified!
2137 ((= char ?m) ; type in what to insert
2139 (concat "*" (read-string "Insert: " word) "\n"))
2140 (setq ispell-pdict-modified-p '(t))
2142 ((and (>= num 0) (< num count))
2143 (if ispell-query-replace-choices ; Query replace flag
2144 (list (nth num miss) 'query-replace)
2149 ;; This may have alignment errors if current line is edited
2150 (if (marker-position ispell-recursive-edit-marker)
2152 (message "Only one recursive edit session supported")
2155 (set-marker ispell-recursive-edit-marker start)
2156 ;;(set-marker ispell-region-end reg-end)
2157 (and ispell-highlight-p ; unhighlight
2158 (ispell-highlight-spelling-error start end))
2163 (substitute-command-keys
2164 (concat "Exit recursive edit with"
2165 " \\[exit-recursive-edit]")))
2166 (save-window-excursion (save-excursion
2169 (goto-char ispell-recursive-edit-marker)
2170 (if (not (equal (marker-buffer
2171 ispell-recursive-edit-marker)
2174 (set-marker ispell-recursive-edit-marker nil)
2176 "Cannot continue ispell from this buffer.")))
2177 (set-marker ispell-recursive-edit-marker nil)))
2178 (list word nil)) ; recheck starting at this word.
2180 (funcall (key-binding "\C-z"))
2185 (and ispell-highlight-p ; unhighlight
2186 (save-window-excursion
2187 (select-window textwin)
2188 (ispell-highlight-spelling-error start end)))
2190 (set-window-dedicated-p dedicated-win t)))))
2194 (defun ispell-show-choices (line end)
2195 "Show the choices in another buffer or frame."
2196 (if (and ispell-use-framepop-p (fboundp 'framepop-display-buffer))
2198 (framepop-display-buffer (get-buffer ispell-choices-buffer))
2199 ;; (get-buffer-window ispell-choices-buffer t)
2200 (select-window (previous-window))) ; *Choices* window
2201 ;; standard selection by splitting a small buffer out of this window.
2202 (let ((choices-window (get-buffer-window ispell-choices-buffer)))
2204 (if (= line (ispell-adjusted-window-height choices-window))
2205 (select-window choices-window)
2206 ;; *Choices* window changed size. Adjust the choices window
2207 ;; without scrolling the spelled window when possible
2209 (- line (ispell-adjusted-window-height choices-window)))
2210 (visible (progn (vertical-motion -1) (point))))
2211 (if (< line ispell-choices-win-default-height)
2212 (setq window-line (+ window-line
2213 (- ispell-choices-win-default-height
2215 (move-to-window-line 0)
2216 (vertical-motion window-line)
2217 (set-window-start (selected-window)
2218 (if (> (point) visible) visible (point)))
2220 (select-window choices-window)
2221 (enlarge-window window-line)))
2222 ;; Overlay *Choices* window when it isn't showing
2223 (ispell-overlay-window (max line ispell-choices-win-default-height)))
2224 (switch-to-buffer ispell-choices-buffer)
2225 (goto-char (point-min)))))
2229 (defun ispell-help ()
2230 "Display a list of the options available when a misspelling is encountered.
2234 DIGIT: Replace the word with a digit offered in the *Choices* buffer.
2235 SPC: Accept word this time.
2236 `i': Accept word and insert into private dictionary.
2237 `a': Accept word for this session.
2238 `A': Accept word and place in `buffer-local dictionary'.
2239 `r': Replace word with typed-in value. Rechecked.
2240 `R': Replace word with typed-in value. Query-replaced in buffer. Rechecked.
2241 `?': Show these commands.
2242 `x': Exit spelling buffer. Move cursor to original point.
2243 `X': Exit spelling buffer. Leaves cursor at the current point, and permits
2244 the aborted check to be completed later.
2245 `q': Quit spelling session (Kills ispell process).
2246 `l': Look up typed-in replacement in alternate dictionary. Wildcards okay.
2247 `u': Like `i', but the word is lower-cased first.
2248 `m': Place typed-in value in personal dictionary, then recheck current word.
2249 `C-l': Redraw screen.
2250 `C-r': Recursive edit.
2251 `C-z': Suspend Emacs or iconify frame."
2253 (if (equal ispell-help-in-bufferp 'electric)
2257 (function (lambda ()
2258 ;;This shouldn't be necessary: with-electric-help needs
2259 ;; an optional argument telling it about the smallest
2260 ;; acceptable window-height of the help buffer.
2261 ;;(if (< (window-height) 15)
2263 ;; (- 15 (ispell-adjusted-window-height))))
2264 (princ "Selections are:
2266 DIGIT: Replace the word with a digit offered in the *Choices* buffer.
2267 SPC: Accept word this time.
2268 `i': Accept word and insert into private dictionary.
2269 `a': Accept word for this session.
2270 `A': Accept word and place in `buffer-local dictionary'.
2271 `r': Replace word with typed-in value. Rechecked.
2272 `R': Replace word with typed-in value. Query-replaced in buffer. Rechecked.
2273 `?': Show these commands.
2274 `x': Exit spelling buffer. Move cursor to original point.
2275 `X': Exit spelling buffer. Leaves cursor at the current point, and permits
2276 the aborted check to be completed later.
2277 `q': Quit spelling session (Kills ispell process).
2278 `l': Look up typed-in replacement in alternate dictionary. Wildcards okay.
2279 `u': Like `i', but the word is lower-cased first.
2280 `m': Place typed-in value in personal dictionary, then recheck current word.
2281 `C-l': Redraw screen.
2282 `C-r': Recursive edit.
2283 `C-z': Suspend Emacs or iconify frame.")
2287 (let ((help-1 (concat "[r/R]eplace word; [a/A]ccept for this session; "
2288 "[i]nsert into private dictionary"))
2289 (help-2 (concat "[l]ook a word up in alternate dictionary; "
2290 "e[x/X]it; [q]uit session"))
2291 (help-3 (concat "[u]ncapitalized insert into dict. "
2292 "Type 'x C-h f ispell-help' for more help")))
2293 (save-window-excursion
2294 (if ispell-help-in-bufferp
2296 (ispell-overlay-window 4)
2297 (switch-to-buffer (get-buffer-create "*Ispell Help*"))
2298 (insert (concat help-1 "\n" help-2 "\n" help-3))
2300 (kill-buffer "*Ispell Help*"))
2302 (let ((resize-mini-windows 'grow-only))
2303 (select-window (minibuffer-window))
2306 ;;(set-minibuffer-window (selected-window))
2308 (insert (concat help-1 "\n" help-2 "\n" help-3))
2310 (erase-buffer)))))))
2313 (defun lookup-words (word &optional lookup-dict)
2314 "Look up WORD in optional word-list dictionary LOOKUP-DICT.
2315 A `*' serves as a wild card. If no wild cards, `look' is used if it exists.
2316 Otherwise the variable `ispell-grep-command' contains the command used to
2317 search for the words (usually egrep).
2319 Optional second argument contains the dictionary to use; the default is
2320 `ispell-alternate-dictionary', overridden by `ispell-complete-word-dict'
2322 ;; We don't use the filter for this function, rather the result is written
2323 ;; into a buffer. Hence there is no need to save the filter values.
2324 (if (null lookup-dict)
2325 (setq lookup-dict (or ispell-complete-word-dict
2326 ispell-alternate-dictionary)))
2329 (unless (file-readable-p lookup-dict)
2330 (error "lookup-words error: Unreadable or missing plain word-list %s."
2332 (error (concat "lookup-words error: No plain word-list found at system"
2333 "default locations. "
2334 "Customize `ispell-alternate-dictionary' to set yours.")))
2336 (let* ((process-connection-type ispell-use-ptys-p)
2337 (wild-p (string-match "\\*" word))
2338 (look-p (and ispell-look-p ; Only use look for an exact match.
2339 (or ispell-have-new-look (not wild-p))))
2340 (prog (if look-p ispell-look-command ispell-grep-command))
2341 (args (if look-p ispell-look-options ispell-grep-options))
2344 (message "Starting \"%s\" process..." (file-name-nondirectory prog))
2348 (insert "^" word "$")
2349 (while (search-backward "*" nil t) (insert "."))
2350 (setq word (buffer-string))
2352 (setq status (apply 'ispell-call-process prog nil t nil
2353 (nconc (if (and args (> (length args) 0))
2358 (if lookup-dict (list lookup-dict)))))
2359 ;; `grep' returns status 1 and no output when word not found, which
2360 ;; is a perfectly normal thing.
2361 (if (stringp status)
2362 (error "error: %s exited with signal %s"
2363 (file-name-nondirectory prog) status)
2364 ;; Else collect words into `results' in FIFO order.
2365 (goto-char (point-max))
2366 ;; Assure we've ended with \n.
2367 (or (bobp) (= (preceding-char) ?\n) (insert ?\n))
2371 (push (buffer-substring-no-properties (point)
2374 (if (and results (string-match ".+: " (car results)))
2375 (error "%s error: %s" ispell-grep-command (car results)))
2379 ;; "ispell-filter" is a list of output lines from the generating function.
2380 ;; Each full line (ending with \n) is a separate item on the list.
2381 ;; "output" can contain multiple lines, part of a line, or both.
2382 ;; "start" and "end" are used to keep bounds on lines when "output" contains
2384 ;; "ispell-filter-continue" is true when we have received only part of a
2385 ;; line as output from a generating function ("output" did not end with \n)
2386 ;; THIS FUNCTION WILL FAIL IF THE PROCESS OUTPUT DOESN'T END WITH \n!
2387 ;; This is the case when a process dies or fails. The default behavior
2388 ;; in this case treats the next input received as fresh input.
2390 (defun ispell-filter (process output)
2391 "Output filter function for ispell, grep, and look."
2396 (setq end (string-match "\n" output start)) ; get text up to the newline.
2397 ;; If we get out of sync and ispell-filter-continue is asserted when we
2398 ;; are not continuing, treat the next item as a separate list. When
2399 ;; ispell-filter-continue is asserted, ispell-filter *should* always be a
2402 ;; Continue with same line (item)?
2403 (if (and ispell-filter-continue ispell-filter (listp ispell-filter))
2404 ;; Yes. Add it to the prev item
2405 (setcar ispell-filter
2406 (concat (car ispell-filter) (substring output start end)))
2407 ;; No. This is a new line and item.
2409 (cons (substring output start end) ispell-filter)))
2411 ;; We've completed reading the output, but didn't finish the line.
2412 (setq ispell-filter-continue t continue nil)
2413 ;; skip over newline, this line complete.
2414 (setq ispell-filter-continue nil end (1+ end))
2415 (if (= end (length output)) ; No more lines in output
2416 (setq continue nil) ; so we can exit the filter.
2417 (setq start end)))))) ; else move start to next line of input
2420 ;;; This function destroys the mark location if it is in the word being
2422 (defun ispell-highlight-spelling-error-generic (start end &optional highlight
2424 "Highlight the word from START to END with a kludge using `inverse-video'.
2425 When the optional third arg HIGHLIGHT is set, the word is highlighted;
2426 otherwise it is displayed normally.
2427 Uses block cursor to highlight one character.
2428 Optional REFRESH will unhighlighted then highlight, using block cursor
2429 highlighting when REFRESH is equal to `block'."
2430 (and (eq 'block ispell-highlight-p)
2431 (or (eq 'block refresh)
2432 (setq start (1+ start)))) ; On block non-refresh, inc start.
2433 (let ((modified (buffer-modified-p)) ; don't allow this fn to modify buffer
2434 (buffer-read-only nil) ; Allow highlighting read-only buffers.
2435 (text (buffer-substring-no-properties start end))
2436 ; Save highlight region.
2437 (inhibit-quit t) ; inhibit interrupt processing here.
2438 (buffer-undo-list t)) ; don't clutter the undo list.
2440 (delete-region start end)
2441 (insert-char ? (- end start)) ; minimize amount of redisplay
2442 (sit-for 0) ; update display
2443 (if highlight (setq inverse-video (not inverse-video))) ; toggle video
2444 (delete-region start end) ; delete whitespace
2445 (insert text) ; insert text in inverse video.
2446 (sit-for 0) ; update display showing inverse video.
2449 (setq inverse-video (not inverse-video)) ; toggle video
2450 (and (eq 'block ispell-highlight-p)
2451 (goto-char (1- start)))) ; use block cursor to "highlight" char
2452 (set-buffer-modified-p modified) ; don't modify if flag not set.
2453 (and refresh ; re-highlight
2454 (ispell-highlight-spelling-error-generic
2455 (if (eq 'block refresh) start (- start 2)) end t))))
2458 (defun ispell-highlight-spelling-error-xemacs (start end &optional highlight)
2459 "Highlight the word from START to END using `isearch-highlight'.
2460 When the optional third arg HIGHLIGHT is set, the word is highlighted,
2461 otherwise it is displayed normally."
2463 (isearch-highlight start end)
2464 (isearch-dehighlight))
2469 (defun ispell-highlight-spelling-error-overlay (start end &optional highlight)
2470 "Highlight the word from START to END using overlays.
2471 When the optional third arg HIGHLIGHT is set, the word is highlighted
2472 otherwise it is displayed normally.
2474 The variable `ispell-highlight-face' selects the face to use for highlighting."
2477 (move-overlay ispell-overlay start end (current-buffer))
2478 (setq ispell-overlay (make-overlay start end))
2479 (overlay-put ispell-overlay 'priority 1001) ;higher than lazy overlays
2480 (overlay-put ispell-overlay 'face ispell-highlight-face))
2482 (delete-overlay ispell-overlay)))
2483 (if (and ispell-lazy-highlight (boundp 'lazy-highlight-cleanup))
2485 (let ((isearch-string
2488 (regexp-quote (buffer-substring-no-properties start end))
2491 (isearch-case-fold-search nil))
2492 (isearch-lazy-highlight-new-loop
2493 (if (boundp 'reg-start) reg-start)
2494 (if (boundp 'reg-end) reg-end)))
2495 (lazy-highlight-cleanup lazy-highlight-cleanup)
2496 (setq isearch-lazy-highlight-last-string nil))))
2499 (defun ispell-highlight-spelling-error (start end &optional highlight refresh)
2502 (ispell-highlight-spelling-error-xemacs start end highlight))
2503 ((and (featurep 'faces)
2504 (or (and (fboundp 'display-color-p) (display-color-p))
2506 (ispell-highlight-spelling-error-overlay start end highlight))
2507 (t (ispell-highlight-spelling-error-generic start end highlight refresh))))
2509 (defun ispell-adjusted-window-height (&optional window)
2510 "Like `window-height', adjusted to correct for the effect of tall mode-lines.
2511 The value returned is actually the nominal number of text-lines in the
2512 window plus 1. On a terminal, this is the same value returned by
2513 `window-height', but if the window has a mode-line is taller than a normal
2514 text line, the returned value may be smaller than that from
2516 (cond ((fboundp 'window-text-height)
2517 (1+ (window-text-height window)))
2518 ((or (and (fboundp 'display-graphic-p) (display-graphic-p))
2519 (and (featurep 'xemacs) window-system))
2520 (1- (window-height window)))
2522 (window-height window))))
2524 (defun ispell-overlay-window (height)
2525 "Create a window covering the top HEIGHT lines of the current window.
2526 Ensure that the line above point is still visible but otherwise avoid
2527 scrolling the current window. Leave the new window selected."
2529 (let ((oldot (save-excursion (vertical-motion -1) (point)))
2530 (top (save-excursion (move-to-window-line height) (point))))
2531 ;; If line above old point (line starting at oldot) would be
2532 ;; hidden by new window, scroll it to just below new win
2533 ;; otherwise set top line of other win so it doesn't scroll.
2534 (if (< oldot top) (setq top oldot))
2535 ;; if frame is unsplittable, temporarily disable that...
2536 (if (cdr (assq 'unsplittable (frame-parameters (selected-frame))))
2537 (let ((frame (selected-frame)))
2538 (modify-frame-parameters frame '((unsplittable . nil)))
2539 (split-window nil height)
2540 (modify-frame-parameters frame '((unsplittable . t))))
2541 (split-window nil height))
2542 (let ((deficit (- height (ispell-adjusted-window-height))))
2544 ;; Number of lines the window is still too short. We ensure that
2545 ;; there are at least (1- HEIGHT) lines visible in the window.
2546 (enlarge-window deficit)
2548 (vertical-motion deficit)
2549 (setq top (min (point) oldot))))
2550 (set-window-start (next-window) top))))
2553 ;;; Should we add a compound word match return value?
2554 (defun ispell-parse-output (output &optional accept-list shift)
2555 "Parse the OUTPUT string from Ispell process and return:
2556 1: t for an exact match.
2557 2: A string containing the root word matched via suffix removal.
2558 3: A list of possible correct spellings of the format:
2559 (\"ORIGINAL-WORD\" OFFSET MISS-LIST GUESS-LIST)
2560 ORIGINAL-WORD is a string of the possibly misspelled word.
2561 OFFSET is an integer giving the line offset of the word.
2562 MISS-LIST and GUESS-LIST are possibly null lists of guesses and misses.
2563 4: nil when an error has occurred.
2565 Optional second arg ACCEPT-LIST is list of words already accepted.
2566 Optional third arg SHIFT is an offset to apply based on previous corrections."
2568 ((string= output "") t) ; for startup with pipes...
2569 ((string= output "*") t) ; exact match
2570 ((string= output "-") t) ; compound word match
2571 ((eq (aref output 0) ?+) ; found because of root word
2572 (substring output 2)) ; return root word
2573 ((equal 0 (string-match "[\ra-zA-Z]" output))
2574 (ding) ; error message from ispell!
2575 (message "Ispell error: %s" output)
2578 (t ; need to process &, ?, and #'s
2579 (let ((type (aref output 0)) ; &, ?, or #
2580 (original-word (substring output 2 (string-match " " output 2)))
2581 (cur-count 0) ; contains number of misses + guesses
2582 count miss-list guess-list offset)
2583 (setq output (substring output (match-end 0))) ; skip over misspelling
2585 (setq count 0) ; no misses for type #
2586 (setq count (string-to-number output) ; get number of misses.
2587 output (substring output (1+ (string-match " " output 1)))))
2588 (setq offset (string-to-number output))
2589 (setq output (if (eq type ?#) ; No miss or guess list.
2591 (substring output (1+ (string-match " " output 1)))))
2593 (let ((end (string-match ", \\|\\($\\)" output))) ; end of miss/guess.
2594 (setq cur-count (1+ cur-count))
2595 (if (> cur-count count)
2596 (push (substring output 0 end) guess-list)
2597 (push (substring output 0 end) miss-list))
2598 (setq output (if (match-end 1) ; True only when at end of line.
2599 nil ; No more misses or guesses.
2600 (substring output (+ end 2))))))
2601 ;; return results. Accept word if it was already accepted.
2603 (if (member original-word accept-list)
2606 (if (numberp shift) (+ shift offset) offset)
2607 (nreverse miss-list) (nreverse guess-list)))))))
2610 (defun ispell-process-status ()
2611 "Return the status of the Ispell process.
2612 When asynchronous processes are not supported, `run' is always returned."
2613 (if ispell-async-processp
2614 (process-status ispell-process)
2615 (and ispell-process 'run)))
2618 (defun ispell-start-process ()
2619 "Start the ispell process, with support for no asynchronous processes.
2620 Keeps argument list for future ispell invocations for no async support."
2621 ;; Local dictionary becomes the global dictionary in use.
2622 (setq ispell-current-dictionary
2623 (or ispell-local-dictionary ispell-dictionary))
2624 (setq ispell-current-personal-dictionary
2625 (or ispell-local-pdict ispell-personal-dictionary))
2626 (let* ((default-directory
2627 (if (and (file-directory-p default-directory)
2628 (file-readable-p default-directory))
2630 ;; Defend against bad `default-directory'.
2631 (expand-file-name "~/")))
2632 (orig-args (ispell-get-ispell-args))
2635 (if (and ispell-current-dictionary ; Not for default dict (nil)
2636 (not (member "-d" orig-args))) ; Only define if not overridden.
2637 (list "-d" ispell-current-dictionary))
2639 (if ispell-current-personal-dictionary ; Use specified pers dict.
2641 (expand-file-name ispell-current-personal-dictionary)))
2642 ;; If we are using recent aspell or hunspell, make sure we use the
2643 ;; right encoding for communication. ispell or older aspell/hunspell
2644 ;; does not support this.
2645 (if ispell-encoding8-command
2646 (if ispell-really-hunspell
2647 (list ispell-encoding8-command
2648 (upcase (symbol-name (ispell-get-coding-system))))
2650 (concat ispell-encoding8-command
2651 (symbol-name (ispell-get-coding-system))))))
2652 ispell-extra-args)))
2654 ;; Initially we don't know any buffer's local words.
2655 (setq ispell-buffer-local-name nil)
2657 (if ispell-async-processp
2658 (let ((process-connection-type ispell-use-ptys-p))
2659 (apply 'start-process
2660 "ispell" nil ispell-program-name
2661 "-a" ; Accept single input lines.
2662 ;; Make root/affix combos not in dict.
2663 ;; hunspell -m option means different.
2664 (if ispell-really-hunspell "" "-m")
2666 (setq ispell-cmd-args args
2667 ispell-output-buffer (generate-new-buffer " *ispell-output*")
2668 ispell-session-buffer (generate-new-buffer " *ispell-session*"))
2669 (ispell-send-string "\032\n") ; so Ispell prints version and exits
2673 (defun ispell-init-process ()
2674 "Check status of Ispell process and start if necessary."
2675 (let* (;; Basename of dictionary used by the spell-checker
2676 (dict-bname (or (car (cdr (member "-d" (ispell-get-ispell-args))))
2677 ispell-current-dictionary))
2678 ;; Use "~/" as default-directory unless using Ispell with per-dir
2679 ;; personal dictionaries and not in a minibuffer under XEmacs
2681 (if (or ispell-really-aspell
2682 ispell-really-hunspell
2683 ;; Protect against bad default-directory
2684 (not (and (file-directory-p default-directory)
2685 (file-readable-p default-directory)))
2686 ;; Ispell and per-dir personal dicts available
2687 (not (or (file-readable-p (concat default-directory
2689 (file-readable-p (concat default-directory
2693 ;; Ispell, in a minibuffer, and XEmacs
2694 (and (window-minibuffer-p)
2695 (not (fboundp 'minibuffer-selected-window))))
2696 (expand-file-name "~/")
2697 (expand-file-name default-directory))))
2698 ;; Check if process needs restart
2699 (if (and ispell-process
2700 (eq (ispell-process-status) 'run)
2701 ;; Unless we are using an explicit personal dictionary, ensure
2702 ;; we're in the same default directory! Restart check for
2703 ;; personal dictionary is done in
2704 ;; `ispell-internal-change-dictionary', called from
2705 ;; `ispell-buffer-local-dict'
2706 (or (or ispell-local-pdict ispell-personal-dictionary)
2707 (equal ispell-process-directory default-directory)))
2708 (setq ispell-filter nil ispell-filter-continue nil)
2709 ;; may need to restart to select new personal dictionary.
2710 (ispell-kill-ispell t)
2711 (message "Starting new Ispell process [%s] ..."
2712 (or ispell-local-dictionary ispell-dictionary "default"))
2714 (setq ispell-library-directory (ispell-check-version)
2715 ispell-process (ispell-start-process)
2717 ispell-filter-continue nil
2718 ispell-process-directory default-directory)
2720 (unless (equal ispell-process-directory (expand-file-name "~/"))
2721 ;; At this point, `ispell-process-directory' will be "~/" unless using
2722 ;; Ispell with directory-specific dicts and not in XEmacs minibuffer.
2723 ;; If not, kill ispell process when killing buffer. It may be in a
2724 ;; removable device that would otherwise become un-mountable.
2725 (with-current-buffer
2726 (if (and (window-minibuffer-p) ;; In minibuffer
2727 (fboundp 'minibuffer-selected-window)) ;; Not XEmacs.
2728 ;; In this case kill ispell only when parent buffer is killed
2729 ;; to avoid over and over ispell kill.
2730 (window-buffer (minibuffer-selected-window))
2732 ;; 'local does not automatically make hook buffer-local in XEmacs.
2733 (if (featurep 'xemacs)
2734 (make-local-hook 'kill-buffer-hook))
2735 (add-hook 'kill-buffer-hook
2736 (lambda () (ispell-kill-ispell t)) nil 'local)))
2738 (if ispell-async-processp
2739 (set-process-filter ispell-process 'ispell-filter))
2740 ;; Protect against XEmacs bogus binding of `enable-multibyte-characters'.
2741 (if (and (or (featurep 'xemacs)
2742 (and (boundp 'enable-multibyte-characters)
2743 enable-multibyte-characters))
2744 (fboundp 'set-process-coding-system))
2745 (set-process-coding-system ispell-process (ispell-get-coding-system)
2746 (ispell-get-coding-system)))
2747 ;; Get version ID line
2748 (ispell-accept-output 3)
2749 ;; get more output if filter empty?
2750 (if (null ispell-filter) (ispell-accept-output 3))
2751 (cond ((null ispell-filter)
2752 (error "%s did not output version line" ispell-program-name))
2754 (stringp (car ispell-filter))
2755 (if (string-match "warning: " (car ispell-filter))
2757 (ispell-accept-output 3) ; was warn msg.
2758 (stringp (car ispell-filter)))
2759 (null (cdr ispell-filter)))
2760 (string-match "^@(#) " (car ispell-filter)))
2761 ;; got the version line as expected (we already know it's the right
2762 ;; version, so don't bother checking again.)
2765 ;; Otherwise, it must be an error message. Show the user.
2766 ;; But first wait to see if some more output is going to arrive.
2767 ;; Otherwise we get cool errors like "Can't open ".
2769 (ispell-accept-output 3)
2770 (error "%s" (mapconcat 'identity ispell-filter "\n"))))
2771 (setq ispell-filter nil) ; Discard version ID line
2772 (let ((extended-char-mode (ispell-get-extended-character-mode)))
2773 (if extended-char-mode ; ~ extended character mode
2774 (ispell-send-string (concat extended-char-mode "\n"))))
2775 (if ispell-async-processp
2776 (if (featurep 'emacs)
2777 (set-process-query-on-exit-flag ispell-process nil)
2778 (if (fboundp 'set-process-query-on-exit-flag)
2779 (set-process-query-on-exit-flag ispell-process nil)
2780 (process-kill-without-query ispell-process)))))))
2783 (defun ispell-kill-ispell (&optional no-error)
2784 "Kill current Ispell process (so that you may start a fresh one).
2785 With NO-ERROR, just return non-nil if there was no Ispell running."
2787 ;; This hook is typically used by flyspell to flush some variables used
2788 ;; to optimize the common cases.
2789 (run-hooks 'ispell-kill-ispell-hook)
2790 (if (not (and ispell-process
2791 (eq (ispell-process-status) 'run)))
2793 (error "There is no ispell process running!"))
2794 (if ispell-async-processp
2795 (delete-process ispell-process)
2796 ;; synchronous processes
2797 (ispell-send-string "\n") ; make sure side effects occurred.
2798 (kill-buffer ispell-output-buffer)
2799 (kill-buffer ispell-session-buffer)
2800 (setq ispell-output-buffer nil
2801 ispell-session-buffer nil))
2802 (setq ispell-process nil)
2803 (message "Ispell process killed")
2806 ;;; ispell-change-dictionary is set in some people's hooks. Maybe this should
2807 ;;; call ispell-init-process rather than wait for a spell checking command?
2810 (defun ispell-change-dictionary (dict &optional arg)
2811 "Change to dictionary DICT for Ispell.
2812 With a prefix arg, set it \"globally\", for all buffers.
2813 Without a prefix arg, set it \"locally\", just for this buffer.
2815 By just answering RET you can find out what the current dictionary is."
2817 (list (completing-read
2818 "Use new dictionary (RET for current, SPC to complete): "
2819 (and (fboundp 'ispell-valid-dictionary-list)
2820 (mapcar 'list (ispell-valid-dictionary-list)))
2822 current-prefix-arg))
2823 (ispell-set-spellchecker-params) ; Initialize variables and dicts alists
2824 (unless arg (ispell-buffer-local-dict 'no-reload))
2825 (if (equal dict "default") (setq dict nil))
2826 ;; This relies on completing-read's bug of returning "" for no match
2827 (cond ((equal dict "")
2828 (ispell-internal-change-dictionary)
2829 (message "Using %s dictionary"
2830 (or (and (not arg) ispell-local-dictionary)
2831 ispell-dictionary "default")))
2832 ((equal dict (or (and (not arg) ispell-local-dictionary)
2833 ispell-dictionary "default"))
2834 ;; Specified dictionary is the default already. Could reload
2835 ;; the dictionaries if needed.
2836 (ispell-internal-change-dictionary)
2837 (and (interactive-p)
2838 (message "No change, using %s dictionary" dict)))
2839 (t ; reset dictionary!
2840 (if (or (assoc dict ispell-local-dictionary-alist)
2841 (assoc dict ispell-dictionary-alist))
2843 ;; set default dictionary
2844 (setq ispell-dictionary dict)
2845 ;; set local dictionary
2846 (setq ispell-local-dictionary dict)
2847 (setq ispell-local-dictionary-overridden t))
2848 (error "Undefined dictionary: %s" dict))
2849 (ispell-internal-change-dictionary)
2850 (message "%s Ispell dictionary set to %s"
2851 (if arg "Global" "Local")
2854 (defun ispell-internal-change-dictionary ()
2855 "Update the dictionary and the personal dictionary used by Ispell.
2856 This may kill the Ispell process; if so, a new one will be started
2858 (let ((dict (or ispell-local-dictionary ispell-dictionary))
2859 (pdict (or ispell-local-pdict ispell-personal-dictionary)))
2860 (unless (and (equal ispell-current-dictionary dict)
2861 (equal ispell-current-personal-dictionary pdict))
2862 (ispell-kill-ispell t)
2863 (setq ispell-current-dictionary dict
2864 ispell-current-personal-dictionary pdict))))
2866 ;; Avoid error messages when compiling for these dynamic variables.
2867 (defvar ispell-start)
2870 ;; Spelling of comments are checked when ispell-check-comments is non-nil.
2873 (defun ispell-region (reg-start reg-end &optional recheckp shift)
2874 "Interactively check a region for spelling errors.
2875 Return nil if spell session was terminated, otherwise returns shift offset
2876 amount for last line processed."
2877 (interactive "r") ; Don't flag errors on read-only bufs.
2878 (ispell-set-spellchecker-params) ; Initialize variables and dicts alists
2880 (ispell-accept-buffer-local-defs)) ; set up dictionary, local words, etc.
2881 (let ((skip-region-start (make-marker))
2882 (rstart (make-marker)))
2885 (message "Spell-checking %s using %s with %s dictionary..."
2886 (if (and (= reg-start (point-min)) (= reg-end (point-max)))
2887 (buffer-name) "region")
2888 (file-name-nondirectory ispell-program-name)
2889 (or ispell-current-dictionary "default"))
2890 ;; Returns cursor to original location.
2891 (save-window-excursion
2892 (goto-char reg-start)
2893 (let ((transient-mark-mode)
2894 (case-fold-search case-fold-search)
2897 (let (message-log-max)
2898 (message "searching for regions to skip"))
2899 (if (re-search-forward (ispell-begin-skip-region-regexp) reg-end t)
2901 (setq key (match-string-no-properties 0))
2902 (set-marker skip-region-start (- (point) (length key)))
2903 (goto-char reg-start)))
2904 (let (message-log-max)
2906 "Continuing spelling check using %s with %s dictionary..."
2907 (file-name-nondirectory ispell-program-name)
2908 (or ispell-current-dictionary "default")))
2909 (set-marker rstart reg-start)
2910 (set-marker ispell-region-end reg-end)
2911 (while (and (not ispell-quit)
2912 (< (point) ispell-region-end))
2913 ;; spell-check region with skipping
2914 (if (and (marker-position skip-region-start)
2915 (<= skip-region-start (point)))
2917 ;; If region inside line comment, must keep comment start.
2918 (setq in-comment (point)
2921 (or (null comment-end) (string= "" comment-end))
2924 (re-search-forward comment-start in-comment t))
2926 ;; Can change skip-regexps (in ispell-message)
2927 (ispell-skip-region key) ; moves pt past region.
2928 (set-marker rstart (point))
2929 ;; check for saving large attachments...
2930 (setq query-fcc (and query-fcc
2931 (ispell-ignore-fcc skip-region-start
2933 (if (and (< rstart ispell-region-end)
2935 (ispell-begin-skip-region-regexp)
2936 ispell-region-end t))
2938 (setq key (match-string-no-properties 0))
2939 (set-marker skip-region-start
2940 (- (point) (length key)))
2942 (set-marker skip-region-start nil))))
2943 (setq reg-end (max (point)
2944 (if (marker-position skip-region-start)
2945 (min skip-region-start ispell-region-end)
2946 (marker-position ispell-region-end))))
2947 (let* ((ispell-start (point))
2948 (ispell-end (min (point-at-eol) reg-end))
2949 (string (ispell-get-line
2950 ispell-start ispell-end in-comment)))
2951 (if in-comment ; account for comment chars added
2952 (setq ispell-start (- ispell-start (length in-comment))
2954 (setq ispell-end (point)) ; "end" tracks region retrieved.
2955 (if string ; there is something to spell check!
2956 ;; (special start end)
2957 (setq shift (ispell-process-line string
2958 (and recheckp shift))))
2959 (goto-char ispell-end)))))
2964 (if (and (not (and recheckp ispell-keep-choices-win))
2965 (get-buffer ispell-choices-buffer))
2966 (kill-buffer ispell-choices-buffer))
2967 (set-marker skip-region-start nil)
2968 (set-marker rstart nil)
2971 ;; preserve or clear the region for ispell-continue.
2972 (if (not (numberp ispell-quit))
2973 (set-marker ispell-region-end nil)
2974 ;; Ispell-continue enabled - ispell-region-end is set.
2975 (goto-char ispell-quit))
2976 ;; Check for aborting
2977 (if (and ispell-checking-message (numberp ispell-quit))
2979 (setq ispell-quit nil)
2980 (error "Message send aborted")))
2981 (if (not recheckp) (setq ispell-quit nil)))
2982 (if (not recheckp) (set-marker ispell-region-end nil))
2983 ;; Only save if successful exit.
2984 (ispell-pdict-save ispell-silently-savep)
2985 (message "Spell-checking %s using %s with %s dictionary...done"
2986 (if (and (= reg-start (point-min)) (= reg-end (point-max)))
2987 (buffer-name) "region")
2988 (file-name-nondirectory ispell-program-name)
2989 (or ispell-current-dictionary "default"))))))
2992 (defun ispell-begin-skip-region-regexp ()
2993 "Return a regexp of the search keys for region skipping.
2994 Includes `ispell-skip-region-alist' plus tex, tib, html, and comment keys.
2995 Must be called after `ispell-buffer-local-parsing' due to dependence on mode."
3001 (if (and ispell-checking-message
3002 (not (eq t ispell-checking-message)))
3003 (mapconcat #'car ispell-checking-message "\\|"))
3005 (if (eq ispell-parser 'tex)
3006 (ispell-begin-tex-skip-regexp))
3008 (if ispell-skip-html
3009 (ispell-begin-skip-region ispell-html-skip-alists))
3011 (if ispell-skip-tib ispell-tib-ref-beginning)
3013 (if (and (eq 'exclusive ispell-check-comments) comment-start)
3014 ;; search from end of current comment to start of next comment.
3015 (if (string= "" comment-end) "^" (regexp-quote comment-end)))
3016 (if (and (null ispell-check-comments) comment-start)
3017 (regexp-quote comment-start))
3018 (ispell-begin-skip-region ispell-skip-region-alist)))
3022 (defun ispell-begin-skip-region (skip-alist)
3023 "Regular expression for start of regions to skip generated from SKIP-ALIST.
3024 Each selection should be a key of SKIP-ALIST;
3025 otherwise, the current line is skipped."
3026 (mapconcat (lambda (lst) (if (stringp (car lst)) (car lst) (eval (car lst))))
3031 (defun ispell-begin-tex-skip-regexp ()
3032 "Regular expression of tex commands to skip.
3033 Generated from `ispell-tex-skip-alists'."
3036 (mapconcat (function (lambda (lst) (car lst)))
3037 (car ispell-tex-skip-alists)
3040 ;; keys wrapped in begin{}
3041 (mapconcat (function (lambda (lst)
3042 (concat "\\\\begin[ \t\n]*{[ \t\n]*"
3045 (car (cdr ispell-tex-skip-alists))
3049 (defun ispell-skip-region-list ()
3050 "Return a list describing key and body regions to skip for this buffer.
3051 Includes regions defined by `ispell-skip-region-alist', tex mode,
3052 `ispell-html-skip-alists', and `ispell-checking-message'.
3053 Manual checking must include comments and tib references.
3054 The list is of the form described by variable `ispell-skip-region-alist'.
3055 Must be called after `ispell-buffer-local-parsing' due to dependence on mode."
3056 (let ((skip-alist ispell-skip-region-alist))
3057 ;; only additional explicit region definition is tex.
3058 (if (eq ispell-parser 'tex)
3059 (setq case-fold-search nil
3060 skip-alist (append (car ispell-tex-skip-alists)
3061 (car (cdr ispell-tex-skip-alists))
3063 (if ispell-skip-html
3064 (setq skip-alist (append ispell-html-skip-alists skip-alist)))
3065 (if (and ispell-checking-message
3066 (not (eq t ispell-checking-message)))
3067 (setq skip-alist (append ispell-checking-message skip-alist)))
3071 (defun ispell-tex-arg-end (&optional arg)
3072 "Skip across ARG number of braces."
3075 (while (looking-at "[ \t\n]*\\[") (forward-sexp))
3076 (forward-sexp (or arg 1)))
3078 (message "Error skipping s-expressions at point %d." (point))
3083 (defun ispell-ignore-fcc (start end)
3084 "Delete the Fcc: message header when large attachments are included.
3085 Return value `nil' if file with large attachments is saved.
3086 This can be used to avoid multiple questions for multiple large attachments.
3087 Returns point to starting location afterwards."
3089 (if (and ispell-checking-message ispell-message-fcc-skip)
3090 (if (< ispell-message-fcc-skip (- end start))
3091 (let (case-fold-search head-end)
3092 (goto-char (point-min))
3094 (or (re-search-forward
3095 (concat "^" (regexp-quote mail-header-separator) "$")
3097 (re-search-forward "^$" nil t)
3099 (goto-char (point-min))
3100 (if (re-search-forward "^Fcc:" head-end t)
3102 "Save copy of this message with large attachments? ")
3110 (defun ispell-skip-region (key)
3111 "Skip across KEY and then to end of region.
3112 Key lookup determines region to skip.
3113 Point is placed at end of skipped region."
3114 ;; move over key to begin checking.
3115 (forward-char (length key))
3116 (let ((start (point))
3117 ;; Regenerate each call... This function can change region definition.
3118 (alist (ispell-skip-region-list))
3119 alist-key null-skip)
3121 ;; what about quoted comment, or comment inside strings?
3122 ((and (null ispell-check-comments) comment-start
3123 (string= key comment-start))
3124 (if (string= "" comment-end)
3126 (search-forward comment-end ispell-region-end t)))
3127 ((and (eq 'exclusive ispell-check-comments) comment-start
3128 (string= key comment-end))
3129 (search-forward comment-start ispell-region-end :end))
3130 ((and ispell-skip-tib (string-match ispell-tib-ref-beginning key))
3131 (re-search-forward ispell-tib-ref-end ispell-region-end t))
3132 ;; markings from alist
3135 (setq alist-key (eval (car (car alist))))
3136 (if (string-match alist-key key)
3138 (setq alist (cdr (car alist)))
3140 ((null alist) (setq null-skip t)) ; done! Just skip key.
3141 ((not (consp alist))
3142 ;; Search past end of spell region to find this region end.
3143 (re-search-forward (eval alist) (point-max) t))
3144 ((and (= 1 (length alist))
3145 (stringp (car alist)))
3146 (re-search-forward (car alist) (point-max) t))
3148 (setq null-skip t) ; error handling in functions!
3149 (if (consp (cdr alist))
3150 (apply (car alist) (cdr alist))
3151 (funcall (car alist)))))
3153 (setq alist (cdr alist))))))
3154 (if (and (= start (point)) (null null-skip))
3156 (message "Matching region end for `%s' point %d not found"
3162 (defun ispell-get-line (start end in-comment)
3163 "Grab the next line of data.
3164 Returns a string with the line data."
3165 (let ((ispell-casechars (ispell-get-casechars))
3167 (cond ; LOOK AT THIS LINE AND SKIP OR PROCESS
3168 ((eolp) ; END OF LINE, just go to next line.
3170 ;;((looking-at "[-#@*+!%~^]") ; SKIP SPECIAL ISPELL CHARACTERS
3171 ;; (forward-char 1)) ; not needed as quoted below.
3172 ((or (re-search-forward ispell-casechars end t) ; TEXT EXISTS
3173 (re-search-forward "[][()${}]" end t)) ; or MATH COMMANDS
3174 (setq string (concat "^" in-comment
3175 (buffer-substring-no-properties start end)
3178 (t (goto-char end))) ; EMPTY LINE, skip it.
3182 (defun ispell-looking-at (string)
3183 (let ((coding (ispell-get-coding-system))
3184 (len (length string)))
3185 (and (<= (+ (point) len) (point-max))
3186 (equal (encode-coding-string string coding)
3187 (encode-coding-string (buffer-substring-no-properties
3188 (point) (+ (point) len))
3191 (defun ispell-process-line (string shift)
3192 "Send STRING, a line of text, to ispell and process the result.
3193 This will modify the buffer for spelling errors.
3194 Requires variables ISPELL-START and ISPELL-END to be defined in its
3196 Returns the sum SHIFT due to changes in word replacements."
3197 ;;(declare special ispell-start ispell-end)
3198 (let (poss accept-list)
3199 (if (not (numberp shift))
3201 ;; send string to spell process and get input.
3202 (ispell-send-string string)
3204 (ispell-accept-output)
3205 ;; Last item of output contains a blank line.
3206 (not (string= "" (car ispell-filter)))))
3207 ;; parse all inputs from the stream one word at a time.
3208 ;; Place in FIFO order and remove the blank item.
3209 (setq ispell-filter (nreverse (cdr ispell-filter)))
3210 (while (and (not ispell-quit) ispell-filter)
3211 ;; get next word, accounting for accepted words and start shifts
3212 (setq poss (ispell-parse-output (car ispell-filter)
3214 (if (and poss (listp poss)) ; spelling error occurred.
3215 ;; Whenever we have misspellings, we can change
3216 ;; the buffer. Keep boundaries as markers.
3217 ;; Markers can move with highlighting! This destroys
3218 ;; end of region markers line-end and ispell-region-end
3220 (copy-marker (+ ispell-start ispell-offset (car (cdr poss)))))
3221 (word-len (length (car poss)))
3222 (line-end (copy-marker ispell-end))
3223 (line-start (copy-marker ispell-start))
3224 recheck-region replace)
3225 (goto-char word-start)
3226 ;; Adjust the horizontal scroll & point
3227 (ispell-horiz-scroll)
3228 (goto-char (+ word-len word-start))
3229 (ispell-horiz-scroll)
3230 (goto-char word-start)
3231 (ispell-horiz-scroll)
3233 ;; Alignment cannot be tracked and this error will occur when
3234 ;; `query-replace' makes multiple corrections on the starting line.
3235 (or (ispell-looking-at (car poss))
3236 ;; This occurs due to filter pipe problems
3237 (error (concat "Ispell misalignment: word "
3238 "`%s' point %d; probably incompatible versions")
3239 (car poss) (marker-position word-start)))
3240 ;; ispell-cmd-loop can go recursive & change buffer
3241 (if ispell-keep-choices-win
3242 (setq replace (ispell-command-loop
3243 (car (cdr (cdr poss)))
3244 (car (cdr (cdr (cdr poss))))
3245 (car poss) (marker-position word-start)
3246 (+ word-len (marker-position word-start))))
3247 (save-window-excursion
3248 (setq replace (ispell-command-loop
3249 (car (cdr (cdr poss)))
3250 (car (cdr (cdr (cdr poss))))
3251 (car poss) (marker-position word-start)
3252 (+ word-len (marker-position word-start))))))
3254 (goto-char word-start)
3255 ;; Recheck when query replace edit changes misspelled word.
3256 ;; Error in tex mode when a potential math mode change exists.
3257 (if (and replace (listp replace) (= 2 (length replace)))
3258 (if (and (eq ispell-parser 'tex)
3259 (string-match "[\\\\][]()[]\\|\\\\begin\\|\\$"
3260 (regexp-quote string)))
3262 "Don't start query replace on a line with math characters"
3264 (set-marker line-end (point))
3265 (setq ispell-filter nil
3268 ;; insert correction if needed
3271 (equal 0 replace)) ; ACCEPT/INSERT
3272 (if (equal 0 replace) ; BUFFER-LOCAL DICT ADD
3273 (ispell-add-per-file-word-list (car poss)))
3274 ;; do not recheck accepted word on this line
3275 (setq accept-list (cons (car poss) accept-list)))
3276 (t ; replacement word selected or entered
3277 (delete-region (point) (+ word-len (point)))
3278 (if (not (listp replace))
3280 (ispell-insert-word replace) ; insert dictionary word
3281 (ispell-send-replacement (car poss) replace)
3282 (setq accept-list (cons replace accept-list)))
3283 (let ((replace-word (car replace)))
3284 ;; Recheck hand entered replacement word
3285 (insert replace-word)
3286 (ispell-send-replacement (car poss) replace-word)
3287 (if (car (cdr replace))
3288 (save-window-excursion
3289 (delete-other-windows) ; to correctly show help.
3290 ;; Assume case-replace &
3291 ;; case-fold-search correct?
3292 (query-replace (car poss) (car replace) t)))
3293 (goto-char word-start)
3294 ;; do not recheck if already accepted
3295 (if (member replace-word accept-list)
3296 (setq accept-list (cons replace-word accept-list)
3297 replace replace-word)
3298 (let ((region-end (copy-marker ispell-region-end)))
3299 (setq recheck-region ispell-filter
3300 ispell-filter nil ; save filter
3301 shift 0 ; already accounted
3302 shift (ispell-region
3304 (+ word-start (length replace-word))
3306 (if (null shift) ; quitting check.
3308 (set-marker ispell-region-end region-end)
3309 (set-marker region-end nil)
3310 (setq ispell-filter recheck-region
3312 replace replace-word)))))
3314 (setq shift (+ shift (- (length replace) word-len)))
3316 ;; Move line-start across word...
3317 ;; new shift function does this now...
3318 ;;(set-marker line-start (+ line-start
3319 ;; (- (length replace)
3320 ;; (length (car poss)))))
3322 (if (not ispell-quit)
3323 ;; FIXME: remove redundancy with identical code above.
3324 (let (message-log-max)
3326 "Continuing spelling check using %s with %s dictionary..."
3327 (file-name-nondirectory ispell-program-name)
3328 (or ispell-current-dictionary "default"))))
3330 (setq ispell-start (marker-position line-start)
3331 ispell-end (marker-position line-end))
3332 ;; Adjust markers when end of region lost from highlighting.
3333 (if (and (not recheck-region)
3334 (< ispell-end (+ word-start word-len)))
3335 (setq ispell-end (+ word-start word-len)))
3336 (if (= word-start ispell-region-end)
3337 (set-marker ispell-region-end (+ word-start word-len)))
3338 ;; going out of scope - unneeded
3339 (set-marker line-start nil)
3340 (set-marker word-start nil)
3341 (set-marker line-end nil)))
3342 ;; finished with misspelling!
3343 (setq ispell-filter (cdr ispell-filter)))
3348 (defun ispell-comments-and-strings ()
3349 "Check comments and strings in the current buffer for spelling errors."
3351 (goto-char (point-min))
3355 (setq state (parse-partial-sexp (point) (point-max)
3356 nil nil state 'syntax-table))
3357 (if (or (nth 3 state) (nth 4 state))
3358 (let ((start (point)))
3359 (setq state (parse-partial-sexp start (point-max)
3360 nil nil state 'syntax-table))
3361 (if (or (nth 3 state) (nth 4 state))
3362 (error "Unterminated string or comment"))
3364 (setq done (not (ispell-region start (point))))))))))
3368 (defun ispell-buffer ()
3369 "Check the current buffer for spelling errors interactively."
3371 (ispell-region (point-min) (point-max)))
3375 (defun ispell-continue ()
3376 "Continue a halted spelling session beginning with the current word."
3378 (if (not (marker-position ispell-region-end))
3379 (message "No session to continue. Use 'X' command when checking!")
3380 (if (not (equal (marker-buffer ispell-region-end) (current-buffer)))
3381 (message "Must continue ispell from buffer %s"
3382 (buffer-name (marker-buffer ispell-region-end)))
3384 ;; find beginning of current word:
3385 (car (cdr (ispell-get-word t)))
3386 (marker-position ispell-region-end)))))
3389 ;;; Horizontal scrolling
3390 (defun ispell-horiz-scroll ()
3391 "Place point within the horizontal visibility of its window area."
3392 (if truncate-lines ; display truncating lines?
3393 ;; See if display needs to be scrolled.
3394 (let ((column (- (current-column) (max (window-hscroll) 1))))
3395 (if (and (< column 0) (> (window-hscroll) 0))
3396 (scroll-right (max (- column) 10))
3397 (if (>= column (- (window-width) 2))
3398 (scroll-left (max (- column (window-width) -3) 10)))))))
3401 ;;; Interactive word completion.
3402 ;; Forces "previous-word" processing. Do we want to make this selectable?
3405 (defun ispell-complete-word (&optional interior-frag)
3406 "Try to complete the word before or under point (see `lookup-words').
3407 If optional INTERIOR-FRAG is non-nil then the word may be a character
3408 sequence inside of a word.
3410 Standard ispell choices are then available."
3412 (let ((cursor-location (point))
3413 (case-fold-search-val case-fold-search)
3414 (word (ispell-get-word nil "\\*")) ; force "previous-word" processing.
3415 start end possibilities replacement)
3416 (setq start (car (cdr word))
3417 end (car (cdr (cdr word)))
3420 (or (string= word "") ; Will give you every word
3421 (lookup-words (concat (and interior-frag "*") word
3422 (if (or interior-frag (null ispell-look-p))
3424 (or ispell-complete-word-dict
3425 ispell-alternate-dictionary))))
3426 (cond ((eq possibilities t)
3427 (message "No word to complete"))
3428 ((null possibilities)
3429 (message "No match for \"%s\"" word))
3430 (t ; There is a modification...
3431 (setq case-fold-search nil) ; Try and respect case of word.
3433 ((string-equal (upcase word) word)
3434 (setq possibilities (mapcar 'upcase possibilities)))
3435 ((eq (upcase (aref word 0)) (aref word 0))
3436 (setq possibilities (mapcar (function
3438 (if (eq (aref word 0) (aref pos 0))
3442 (setq case-fold-search case-fold-search-val)
3443 (save-window-excursion
3445 (ispell-command-loop possibilities nil word start end)))
3447 ((equal 0 replacement) ; BUFFER-LOCAL ADDITION
3448 (ispell-add-per-file-word-list word))
3449 (replacement ; REPLACEMENT WORD
3450 (delete-region start end)
3451 (setq word (if (atom replacement) replacement (car replacement))
3452 cursor-location (+ (- (length word) (- end start))
3454 (ispell-insert-word word)
3455 (if (not (atom replacement)) ; recheck spelling of replacement.
3457 (goto-char cursor-location)
3458 (ispell-word nil t)))))
3459 (if (get-buffer ispell-choices-buffer)
3460 (kill-buffer ispell-choices-buffer))))
3461 (ispell-pdict-save ispell-silently-savep)
3462 (goto-char cursor-location)))
3466 (defun ispell-complete-word-interior-frag ()
3467 "Completes word matching character sequence inside a word."
3469 (ispell-complete-word t))
3474 "Interactively check a region or buffer for spelling errors.
3475 If `transient-mark-mode' is on, and a region is active, spell-check
3476 that region. Otherwise spell-check the buffer.
3478 Ispell dictionaries are not distributed with Emacs. If you are
3479 looking for a dictionary, please see the distribution of the GNU ispell
3480 program, or do an Internet search; there are various dictionaries
3481 available on the net."
3483 (if (and (boundp 'transient-mark-mode) transient-mark-mode
3484 (boundp 'mark-active) mark-active)
3485 (ispell-region (region-beginning) (region-end))
3489 ;;; **********************************************************************
3490 ;;; Ispell Minor Mode
3491 ;;; **********************************************************************
3493 (defvar ispell-minor-keymap
3494 (let ((map (make-sparse-keymap)))
3495 (define-key map " " 'ispell-minor-check)
3496 (define-key map "\r" 'ispell-minor-check)
3498 "Keymap used for Ispell minor mode.")
3501 (define-minor-mode ispell-minor-mode
3502 "Toggle last-word spell checking (Ispell minor mode).
3503 With a prefix argument ARG, enable Ispell minor mode if ARG is
3504 positive, and disable it otherwise. If called from Lisp, enable
3505 the mode if ARG is omitted or nil.
3507 Ispell minor mode is a buffer-local minor mode. When enabled,
3508 typing SPC or RET warns you if the previous word is incorrectly
3511 All the buffer-local variables and dictionaries are ignored. To
3512 read them into the running ispell process, type \\[ispell-word]
3515 For spell-checking \"on the fly\", not just after typing SPC or
3516 RET, use `flyspell-mode'."
3517 nil " Spell" ispell-minor-keymap)
3519 (defun ispell-minor-check ()
3520 "Check previous word, then continue with the normal binding of this key.
3521 Don't check previous word when character before point is a space or newline.
3522 Don't read buffer-local settings or word lists."
3524 (let ((ispell-minor-mode nil)
3525 (ispell-check-only t)
3526 (last-char (char-after (1- (point)))))
3527 (command-execute (key-binding (this-command-keys)))
3528 (if (not (or (eq last-char ?\ ) (eq last-char ?\n)
3529 (and ispell-skip-html (eq last-char ?>))
3530 (and ispell-skip-html (eq last-char ?\;))))
3531 (ispell-word nil t))))
3534 ;;; **********************************************************************
3536 ;;; **********************************************************************
3538 (defvar ispell-message-text-end
3539 (mapconcat (function identity)
3541 ;; Don't spell check signatures
3543 ;; Matches PostScript files.
3544 ;;"^%!PS-Adobe-[123].0"
3545 ;; Matches uuencoded text
3546 ;;"^begin [0-9][0-9][0-9] .*\nM.*\nM.*\nM"
3547 ;; Matches shell files (especially auto-decoding)
3549 ;; Matches context difference listing
3550 "\\(\\(^cd .*\n\\)?diff -c .*\\)?\n\\*\\*\\* .*\n--- .*\n\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*"
3551 ;; Matches unidiff difference listing
3552 "\\(diff -u .*\\)?\n--- .*\n\\+\\+\\+ .*\n@@ [-+][0-9]+,[0-9]+ [-+][0-9]+,[0-9]+ @@"
3553 ;; Matches reporter.el bug report
3554 "^current state:\n==============\n"
3555 ;; Matches commonly used "cut" boundaries
3556 "^\\(- \\)?[-=_]+\\s ?\\(cut here\\|Environment Follows\\)")
3558 "Text beyond which `ispell-message' will not spell-check.
3559 If it is a string, limit is the first occurrence of that regular expression.
3560 Otherwise, it must be a function which is called to get the limit.")
3561 (put 'ispell-message-text-end 'risky-local-variable t)
3564 (defun ispell-mime-multipartp (&optional limit)
3565 "Return multipart message start boundary or nil if none."
3566 ;; caller must ensure `case-fold-search' is set to `t'
3569 "Content-Type: *multipart/\\([^ \t\n]*;[ \t]*[\n]?[ \t]*\\)+boundary="
3572 (if (looking-at "\"")
3575 (setq start (point))
3576 (while (not (looking-at "\""))
3578 (setq boundary (buffer-substring-no-properties start (point))))
3579 (let ((start (point)))
3580 (while (looking-at "[-0-9a-zA-Z'()+_,./:=?]")
3582 (setq boundary (buffer-substring-no-properties start (point)))))
3583 (if (< (length boundary) 1)
3585 (concat "--" boundary)))))
3588 (defun ispell-mime-skip-part (boundary)
3589 "Move point across header, or entire MIME part if message is encoded.
3590 All specified types except `7bit' `8bit' and `quoted-printable' are considered
3591 encoded and therefore skipped. See rfc 1521, 2183, ...
3592 If no boundary is given, then entire message is skipped.
3594 This starts one line ABOVE the MIME content messages, on the boundary marker,
3595 for operation with the generic region-skipping code.
3596 This places new MIME boundaries into variable `ispell-checking-message'."
3597 (forward-line) ; skip over boundary to headers
3598 (let ((save-case-fold-search case-fold-search)
3601 (setq case-fold-search t
3602 ispell-skip-html nil)
3604 (setq continuep nil)
3605 (if (looking-at "Content-Type: *text/")
3607 (goto-char (match-end 0))
3608 (if (looking-at "html")
3609 (setq ispell-skip-html t))
3612 (re-search-forward "\\(.*;[ \t]*[\n]\\)*.*$" nil t)
3614 (if (looking-at "Content-Transfer-Encoding: *\\([^ \t\n]*\\)")
3615 (let ((match (buffer-substring (match-beginning 1) (match-end 1))))
3616 (setq textp (member (upcase match)
3617 ;; only spell check the following encodings:
3618 '("7BIT" "8BIT" "QUOTED-PRINTABLE" "BINARY"))
3620 (goto-char (match-end 0))
3621 (re-search-forward "\\(.*;[ \t]*[\n]\\)*.*$" nil t)
3623 ;; hierarchical boundary definition
3624 (if (looking-at "Content-Type: *multipart/")
3625 (let ((new-boundary (ispell-mime-multipartp)))
3626 (if (string-match new-boundary boundary)
3628 ;; first pass redefine skip function to include new boundary
3629 ;;(re-search-backward boundary nil t)
3631 (setq ispell-checking-message
3633 (list new-boundary 'ispell-mime-skip-part new-boundary)
3634 (if (eq t ispell-checking-message) nil
3635 ispell-checking-message))
3638 ;; Skip all MIME headers that don't affect spelling
3639 (if (looking-at "Content-[^ \t]*: *\\(.*;[ \t]*[\n]\\)*.*$")
3642 (goto-char (match-end 0))
3645 (setq case-fold-search save-case-fold-search)
3648 ;; encoded message. Skip to boundary, or entire message.
3650 (goto-char (point-max))
3651 (re-search-forward boundary nil t)
3657 (defun ispell-message ()
3658 "Check the spelling of a mail message or news post.
3659 Don't check spelling of message headers except the Subject field.
3660 Don't check included messages.
3662 To abort spell checking of a message region and send the message anyway,
3663 use the `x' command. (Any subsequent regions will be checked.)
3664 The `X' command aborts sending the message so that you can edit the buffer.
3666 To spell-check whenever a message is sent, include the appropriate lines
3667 in your .emacs file:
3668 (add-hook 'message-send-hook 'ispell-message) ;; GNUS 5
3669 (add-hook 'news-inews-hook 'ispell-message) ;; GNUS 4
3670 (add-hook 'mail-send-hook 'ispell-message)
3671 (add-hook 'mh-before-send-letter-hook 'ispell-message)
3673 You can bind this to the key C-c i in GNUS or mail by adding to
3674 `news-reply-mode-hook' or `mail-mode-hook' the following lambda expression:
3675 (function (lambda () (local-set-key \"\\C-ci\" 'ispell-message)))"
3678 (goto-char (point-min))
3679 (let* (boundary mimep
3680 (ispell-skip-region-alist-save ispell-skip-region-alist)
3681 ;; Nil when message came from outside (eg calling Emacs as editor)
3682 ;; Non-nil marker of end of headers.
3685 (concat "^" (regexp-quote mail-header-separator) "$") nil t))
3686 (end-of-headers ; Start of body.
3688 (or internal-messagep
3689 (re-search-forward "^$" nil t)
3691 (limit (copy-marker ; End of region we will spell check.
3693 ((not ispell-message-text-end) (point-max))
3694 ((char-or-string-p ispell-message-text-end)
3695 (if (re-search-forward ispell-message-text-end nil t)
3698 (t (min (point-max) (funcall ispell-message-text-end))))))
3699 (default-prefix ; Vanilla cite prefix (just used for cite-regexp)
3700 (if (and (boundp 'mail-yank-prefix) mail-yank-prefix)
3701 (ispell-non-empty-string mail-yank-prefix)
3703 (cite-regexp ;Prefix of quoted text
3705 ((functionp 'sc-cite-regexp) ; sc 3.0
3707 (concat "\\(" (sc-cite-regexp) "\\)" "\\|"
3708 (ispell-non-empty-string sc-reference-tag-string))))
3709 ((boundp 'sc-cite-regexp) ; sc 2.3
3710 (concat "\\(" sc-cite-regexp "\\)" "\\|"
3712 (ispell-non-empty-string sc-reference-tag-string))))
3713 ((or (equal major-mode 'news-reply-mode) ;GNUS 4 & below
3714 (equal major-mode 'message-mode)) ;GNUS 5
3715 (concat "In article <" "\\|"
3716 "[^,;&+=\n]+ <[^,;&+=]+> writes:" "\\|"
3717 (with-no-warnings message-cite-prefix-regexp)
3720 ((equal major-mode 'mh-letter-mode) ; mh mail message
3721 (concat "[^,;&+=\n]+ writes:" "\\|"
3723 (ispell-non-empty-string mh-ins-buf-prefix))))
3724 ((not internal-messagep) ; Assume nn sent us this message.
3725 (concat "In [a-zA-Z.]+ you write:" "\\|"
3726 "In <[^,;&+=]+> [^,;&+=]+ writes:" "\\|"
3728 ((boundp 'vm-included-text-prefix) ; VM mail message
3729 (concat "[^,;&+=\n]+ writes:" "\\|"
3730 (ispell-non-empty-string vm-included-text-prefix)))
3731 (t default-prefix)))
3732 (ispell-skip-region-alist
3733 (cons (list (concat "^\\(" cite-regexp "\\)")
3734 (function forward-line))
3735 ispell-skip-region-alist))
3736 (old-case-fold-search case-fold-search)
3737 (dictionary-alist ispell-message-dictionary-alist)
3738 (ispell-checking-message t))
3740 ;; Select dictionary for message
3741 (or (local-variable-p 'ispell-local-dictionary (current-buffer))
3742 (while dictionary-alist
3743 (goto-char (point-min))
3744 (if (re-search-forward (car (car dictionary-alist))
3746 (setq ispell-local-dictionary (cdr (car dictionary-alist))
3747 dictionary-alist nil)
3748 (setq dictionary-alist (cdr dictionary-alist)))))
3752 ;; Spell check any original Subject:
3753 (goto-char (point-min))
3754 (setq case-fold-search t
3755 mimep (re-search-forward "MIME-Version:" end-of-headers t))
3756 (goto-char (point-min))
3757 (if (re-search-forward "^Subject: *" end-of-headers t)
3759 (goto-char (match-end 0))
3760 (if (and (not (looking-at ".*Re\\>"))
3761 (not (looking-at "\\[")))
3763 (setq case-fold-search old-case-fold-search)
3764 (ispell-region (point)
3765 (progn ;Tab-initiated continuation lns.
3767 (while (looking-at "\n[ \t]")
3772 (goto-char (point-min))
3773 (setq boundary (ispell-mime-multipartp end-of-headers))))
3774 ;; Adjust message limit to MIME message if necessary.
3776 (re-search-forward (concat boundary "--") nil t)
3777 (re-search-backward boundary nil t)
3778 (< (point) (marker-position limit))
3779 (set-marker limit (point)))
3780 (goto-char (point-min))
3781 ;; Select type or skip checking if this is a non-multipart message
3782 ;; Point moved to end of buffer if region is encoded.
3783 (when (and mimep (not boundary))
3784 (goto-char (point-min))
3785 (re-search-forward "Content-[^ \t]*:" end-of-headers t)
3786 (forward-line -1) ; following fn starts one line above
3787 (ispell-mime-skip-part nil)
3788 ;; if message-text-end region, limit may be less than point.
3789 (if (> (point) limit)
3790 (set-marker limit (point))))
3791 (goto-char (max end-of-headers (point)))
3793 (setq case-fold-search old-case-fold-search)
3794 ;; Define MIME regions to skip.
3796 (setq ispell-checking-message
3797 (list (list boundary 'ispell-mime-skip-part boundary))))
3798 (ispell-region (point) limit))
3799 (set-marker end-of-headers nil)
3800 (set-marker limit nil)
3801 (setq ispell-skip-region-alist ispell-skip-region-alist-save
3802 ispell-skip-html nil
3803 case-fold-search old-case-fold-search)))))
3806 (defun ispell-non-empty-string (string)
3807 (if (or (not string) (string-equal string ""))
3808 "\\'\\`" ; An unmatchable string if string is null.
3809 (regexp-quote string)))
3812 ;;; **********************************************************************
3813 ;;; Buffer Local Functions
3814 ;;; **********************************************************************
3817 (defun ispell-accept-buffer-local-defs ()
3818 "Load all buffer-local information, restarting Ispell when necessary."
3819 (ispell-buffer-local-dict) ; May kill ispell-process.
3820 (ispell-buffer-local-words) ; Will initialize ispell-process.
3821 (ispell-buffer-local-parsing))
3824 (defun ispell-buffer-local-parsing ()
3825 "Place Ispell into parsing mode for this buffer.
3826 Overrides the default parsing mode.
3827 Includes LaTeX/Nroff modes and extended character mode."
3828 ;; (ispell-init-process) must already be called.
3829 (ispell-send-string "!\n") ; Put process in terse mode.
3830 ;; We assume all major modes with "tex-mode" in them should use latex parsing
3831 ;; When exclusively checking comments, set to raw text mode (nroff).
3832 (if (and (not (eq 'exclusive ispell-check-comments))
3833 (or (and (eq ispell-parser 'use-mode-name)
3834 (string-match "[Tt][Ee][Xx]-mode"
3835 (symbol-name major-mode)))
3836 (eq ispell-parser 'tex)))
3838 (ispell-send-string "+\n") ; set ispell mode to tex
3839 (if (not (eq ispell-parser 'tex))
3840 (set (make-local-variable 'ispell-parser) 'tex)))
3841 (ispell-send-string "-\n")) ; set mode to normal (nroff)
3842 ;; If needed, test for SGML & HTML modes and set a buffer local nil/t value.
3843 (if (and ispell-skip-html (not (eq ispell-skip-html t)))
3844 (setq ispell-skip-html
3845 (not (null (string-match "sgml\\|html\\|xml"
3846 (downcase (symbol-name major-mode)))))))
3847 ;; Set default extended character mode for given buffer, if any.
3848 (let ((extended-char-mode (ispell-get-extended-character-mode)))
3849 (if extended-char-mode
3850 (ispell-send-string (concat extended-char-mode "\n"))))
3851 ;; Set buffer-local parsing mode and extended character mode, if specified.
3853 (goto-char (point-max))
3854 ;; Uses last occurrence of ispell-parsing-keyword
3855 (if (search-backward ispell-parsing-keyword nil t)
3856 (let ((end (point-at-eol))
3858 (search-forward ispell-parsing-keyword)
3859 (while (re-search-forward " *\\([^ \"]+\\)" end t)
3860 ;; space separated definitions.
3861 (setq string (downcase (match-string-no-properties 1)))
3862 (cond ((and (string-match "latex-mode" string)
3863 (not (eq 'exclusive ispell-check-comments)))
3864 (ispell-send-string "+\n~tex\n"))
3865 ((string-match "nroff-mode" string)
3866 (ispell-send-string "-\n~nroff\n"))
3867 ((string-match "~" string) ; Set extended character mode.
3868 (ispell-send-string (concat string "\n")))
3869 (t (message "Invalid Ispell Parsing argument!")
3873 ;; Can kill the current ispell process
3875 (defun ispell-buffer-local-dict (&optional no-reload)
3876 "Initializes local dictionary and local personal dictionary.
3877 If optional NO-RELOAD is non-nil, do not reload any dictionary.
3878 When a dictionary is defined in the buffer (see variable
3879 `ispell-dictionary-keyword'), it will override the local setting
3880 from \\[ispell-change-dictionary].
3881 Both should not be used to define a buffer-local dictionary."
3883 (goto-char (point-min))
3885 ;; Override the local variable definition.
3886 ;; Uses last occurrence of ispell-dictionary-keyword.
3887 (goto-char (point-max))
3888 (unless ispell-local-dictionary-overridden
3889 (if (search-backward ispell-dictionary-keyword nil t)
3891 (search-forward ispell-dictionary-keyword)
3892 (setq end (point-at-eol))
3893 (if (re-search-forward " *\\([^ \"]+\\)" end t)
3894 (setq ispell-local-dictionary
3895 (match-string-no-properties 1))))))
3896 (goto-char (point-max))
3897 (if (search-backward ispell-pdict-keyword nil t)
3899 (search-forward ispell-pdict-keyword)
3900 (setq end (point-at-eol))
3901 (if (re-search-forward " *\\([^ \"]+\\)" end t)
3902 (setq ispell-local-pdict
3903 (match-string-no-properties 1)))))))
3905 ;; Reload if new dictionary (maybe the personal one) defined.
3906 (ispell-internal-change-dictionary)))
3909 (defun ispell-buffer-local-words ()
3910 "Load the buffer-local dictionary in the current buffer."
3911 ;; If there's an existing ispell process that's wrong for this use,
3913 (if (and ispell-buffer-local-name
3914 (not (equal ispell-buffer-local-name (buffer-name))))
3915 (ispell-kill-ispell t))
3916 ;; Actually start a new ispell process, because we need
3917 ;; to send commands now to specify the local words to it.
3918 (ispell-init-process)
3920 (goto-char (point-min))
3921 (while (search-forward ispell-words-keyword nil t)
3922 (or ispell-buffer-local-name
3923 (setq ispell-buffer-local-name (buffer-name)))
3924 (let ((end (point-at-eol))
3925 (ispell-casechars (ispell-get-casechars))
3927 ;; buffer-local words separated by a space, and can contain
3928 ;; any character other than a space. Not rigorous enough.
3929 (while (re-search-forward " *\\([^ ]+\\)" end t)
3930 (setq string (match-string-no-properties 1))
3931 ;; This can fail when string contains a word with invalid chars.
3932 ;; Error handling needs to be added between ispell and Emacs.
3933 (if (and (< 1 (length string))
3934 (equal 0 (string-match ispell-casechars string)))
3935 (ispell-send-string (concat "@" string "\n"))))))))
3938 ;;; returns optionally adjusted region-end-point.
3940 ;; If comment-padright is defined, newcomment must be loaded.
3941 (declare-function comment-add "newcomment" (arg))
3943 (defun ispell-add-per-file-word-list (word)
3944 "Add WORD to the per-file word list."
3945 (or ispell-buffer-local-name
3946 (setq ispell-buffer-local-name (buffer-name)))
3948 (goto-char (point-min))
3949 (let (line-okay search done found)
3951 (let ((case-fold-search nil))
3952 (setq search (search-forward ispell-words-keyword nil 'move)
3953 found (or found search)
3954 line-okay (< (+ (length word) 1 ; 1 for space after word..
3955 (progn (end-of-line) (current-column)))
3957 (if (or (and search line-okay)
3964 (unless found (newline))
3965 (insert (if comment-start
3967 (if (fboundp 'comment-padright)
3968 ;; Try and use the proper comment marker,
3969 ;; e.g. ";;" rather than ";".
3970 (comment-padright comment-start
3975 ispell-words-keyword)
3976 (if (and comment-end (> (length comment-end) 0))
3979 (insert comment-end)))))
3980 (insert (concat " " word))))))))
3982 (add-to-list 'debug-ignored-errors "^No word found to check!$")
3987 ;;; LOCAL VARIABLES AND BUFFER-LOCAL VALUE EXAMPLES.
3989 ;; Local Variable options:
3990 ;; mode: name(-mode)
3992 ;; local-variable: value
3994 ;; The following sets the buffer local dictionary to `american' English
3995 ;; and spell checks only comments.
3999 ;; comment-column: 40
4000 ;; ispell-check-comments: exclusive
4001 ;; ispell-local-dictionary: "american"
4005 ;;; MORE EXAMPLES OF ISPELL BUFFER-LOCAL VALUES
4007 ;; The following places this file in nroff parsing and extended char modes.
4008 ;; Local IspellParsing: nroff-mode ~nroff
4009 ;; Change IspellPersDict to IspellPersDict: to enable the following line.
4010 ;; Local IspellPersDict ~/.ispell_lisp
4011 ;; The following were automatically generated by ispell using the 'A' command:
4012 ; LocalWords: settable alist inews mh frag pdict Wildcards iconify arg tex kss
4013 ; LocalWords: alists minibuffer bufferp autoload loaddefs aff Dansk KOI SPC op
4014 ; LocalWords: Francais Nederlands charset autoloaded popup nonmenu regexp num
4015 ; LocalWords: AMStex hspace includeonly nocite epsfig displaymath eqnarray reg
4016 ; LocalWords: minipage modeline pers dict unhighlight buf grep sync prev inc
4017 ; LocalWords: fn oldot NB AIX msg init read's bufs pt cmd Quinlan eg
4018 ; LocalWords: uuencoded unidiff sc nn VM SGML eval IspellPersDict
4019 ; LocalWords: lns XEmacs HTML casechars Multibyte
4021 ;;; ispell.el ends here