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))
206 (declare-function ispell-with-no-warnings (&rest body))
208 (if (fboundp 'version<=)
209 (defalias 'ispell-check-minver 'version<=)
210 (defun ispell-check-minver (minver version)
211 "Check if string VERSION is at least string MINVER.
212 Both must be in [0-9]+.[0-9]+... format. This is a fallback
213 compatibility function in case `version<=' is not available."
216 start-ver start-mver)
217 ;; Loop until an absolute greater or smaller condition is reached
218 ;; or until no elements are left in any of version and minver. In
219 ;; this case version is exactly the minimal, so return OK.
222 (if (string-match "[0-9]+" version start-ver)
223 (setq start-ver (match-end 0)
224 ver (string-to-number (match-string 0 version))))
225 (if (string-match "[0-9]+" minver start-mver)
226 (setq start-mver (match-end 0)
227 mver (string-to-number (match-string 0 minver))))
231 (or ver (setq ver 0))
232 (or mver (setq mver 0))
233 ;; If none of below conditions match, this element is the
234 ;; same. Go checking next element.
240 (setq pending nil))))
243 ;; XEmacs does not have looking-back
244 (if (fboundp 'looking-back)
245 (defalias 'ispell-looking-back 'looking-back)
246 (defun ispell-looking-back (regexp &optional limit &rest ignored)
247 "Return non-nil if text before point matches regular expression REGEXP.
248 Like `looking-at' except matches before point, and is slower.
249 LIMIT if non-nil speeds up the search by specifying a minimum
250 starting position, to avoid checking matches that would start
253 This is a stripped down compatibility function for use when
254 full featured `looking-back' function is missing."
256 (re-search-backward (concat "\\(?:" regexp "\\)\\=") limit t))))
258 ;;; XEmacs21 does not have `with-no-warnings'
260 (if (fboundp 'with-no-warnings)
261 (defalias 'ispell-with-no-warnings 'with-no-warnings)
262 (defun ispell-with-no-warnings (&rest body)
263 "Like `progn', but prevents compiler warnings in the body."
264 ;; Taken from Emacs' byte-run.el
265 ;; The implementation for the interpreter is basically trivial.
270 (defvar mail-yank-prefix)
273 "User variables for Emacs ispell interface."
274 :group 'applications)
276 (if (not (fboundp 'buffer-substring-no-properties))
277 (defun buffer-substring-no-properties (start end)
278 (buffer-substring start end)))
280 (defalias 'check-ispell-version 'ispell-check-version)
282 ;;; **********************************************************************
283 ;;; The following variables should be set according to personal preference
284 ;;; and location of binaries:
285 ;;; **********************************************************************
288 ;;; ******* THIS FILE IS WRITTEN FOR ISPELL VERSION 3.1+
290 (defcustom ispell-highlight-p 'block
291 "Highlight spelling errors when non-nil.
292 When set to `block', assumes a block cursor with TTY displays."
293 :type '(choice (const block) (const :tag "off" nil) (const :tag "on" t))
296 (defcustom ispell-lazy-highlight (boundp 'lazy-highlight-cleanup)
297 "Controls the lazy-highlighting of spelling errors.
298 When non-nil, all text in the buffer matching the current spelling
299 error is highlighted lazily using isearch lazy highlighting (see
300 `lazy-highlight-initial-delay' and `lazy-highlight-interval')."
302 :group 'lazy-highlight
306 (defcustom ispell-highlight-face (if ispell-lazy-highlight 'isearch 'highlight)
307 "The face used for Ispell highlighting. For Emacsen with overlays.
308 Possible values are `highlight', `modeline', `secondary-selection',
309 `region', and `underline'.
310 This variable can be set by the user to whatever face they desire.
311 It's most convenient if the cursor color and highlight color are
316 (defcustom ispell-check-comments t
317 "Spelling of comments checked when non-nil.
318 When set to `exclusive', ONLY comments are checked. (For code comments).
319 Warning! Not checking comments, when a comment start is embedded in strings,
320 may produce undesired results."
321 :type '(choice (const exclusive) (const :tag "off" nil) (const :tag "on" t))
324 (put 'ispell-check-comments 'safe-local-variable
325 (lambda (a) (memq a '(nil t exclusive))))
327 (defcustom ispell-query-replace-choices nil
328 "Corrections made throughout region when non-nil.
329 Uses `query-replace' (\\[query-replace]) for corrections."
333 (defcustom ispell-skip-tib nil
334 "Does not spell check `tib' bibliography references when non-nil.
335 Skips any text between strings matching regular expressions
336 `ispell-tib-ref-beginning' and `ispell-tib-ref-end'.
338 TeX users beware: Any text between [. and .] will be skipped -- even if
339 that's your whole buffer -- unless you set `ispell-skip-tib' to nil.
340 That includes the [.5mm] type of number..."
344 (defvar ispell-tib-ref-beginning "[[<]\\."
345 "Regexp matching the beginning of a Tib reference.")
347 (defvar ispell-tib-ref-end "\\.[]>]"
348 "Regexp matching the end of a Tib reference.")
350 (defcustom ispell-keep-choices-win t
351 "If non-nil, keep the `*Choices*' window for the entire spelling session.
352 This minimizes redisplay thrashing."
356 (defcustom ispell-choices-win-default-height 2
357 "The default size of the `*Choices*' window, including the mode line.
358 Must be greater than 1."
362 (defcustom ispell-program-name
363 (or (executable-find "aspell")
364 (executable-find "ispell")
365 (executable-find "hunspell")
367 "Program invoked by \\[ispell-word] and \\[ispell-region] commands."
371 (defcustom ispell-alternate-dictionary
372 (cond ((file-readable-p "/usr/dict/web2") "/usr/dict/web2")
373 ((file-readable-p "/usr/share/dict/web2") "/usr/share/dict/web2")
374 ((file-readable-p "/usr/dict/words") "/usr/dict/words")
375 ((file-readable-p "/usr/lib/dict/words") "/usr/lib/dict/words")
376 ((file-readable-p "/usr/share/dict/words") "/usr/share/dict/words")
377 ((file-readable-p "/usr/share/lib/dict/words")
378 "/usr/share/lib/dict/words")
379 ((file-readable-p "/sys/dict") "/sys/dict"))
380 "Alternate plain word-list dictionary for spelling help."
381 :type '(choice file (const :tag "None" nil))
384 (defcustom ispell-complete-word-dict nil
385 "Plain word-list dictionary used for word completion if
386 different from `ispell-alternate-dictionary'."
387 :type '(choice file (const :tag "None" nil))
390 (defcustom ispell-message-dictionary-alist nil
391 "List used by `ispell-message' to select a new dictionary.
392 It consists of pairs (REGEXP . DICTIONARY). If REGEXP is found
393 in the message headers, `ispell-local-dictionary' will be set to
394 DICTIONARY if `ispell-local-dictionary' is not buffer-local.
395 E.g. you may use the following value:
396 '((\"^Newsgroups:[ \\t]*de\\\\.\" . \"deutsch8\")
397 (\"^To:[^\\n,]+\\\\.de[ \\t\\n,>]\" . \"deutsch8\"))"
398 :type '(repeat (cons regexp string))
402 (defcustom ispell-message-fcc-skip 50000
403 "Query before saving Fcc message copy if attachment larger than this value.
404 Always stores Fcc copy of message when nil."
405 :type '(choice integer (const :tag "off" nil))
409 (defcustom ispell-grep-command
410 ;; MS-Windows/MS-DOS have `egrep' as a Unix shell script, so they
411 ;; cannot invoke it. Use "grep -E" instead (see ispell-grep-options
413 (if (memq system-type '(windows-nt ms-dos)) "grep" "egrep")
414 "Name of the grep command for search processes."
418 (defcustom ispell-grep-options
419 (if (memq system-type '(windows-nt ms-dos)) "-Ei" "-i")
420 "String of options to use when running the program in `ispell-grep-command'.
421 Should probably be \"-i\" or \"-e\".
422 Some machines (like the NeXT) don't support \"-i\"."
426 (defcustom ispell-look-command
427 (cond ((file-exists-p "/bin/look") "/bin/look")
428 ((file-exists-p "/usr/local/bin/look") "/usr/local/bin/look")
429 ((file-exists-p "/usr/bin/look") "/usr/bin/look")
431 "Name of the look command for search processes.
432 This must be an absolute file name."
436 (defcustom ispell-look-p (file-exists-p ispell-look-command)
437 "Non-nil means use `look' rather than `grep'.
438 Default is based on whether `look' seems to be available."
442 (defcustom ispell-have-new-look nil
443 "Non-nil means use the `-r' option (regexp) when running `look'."
447 (defcustom ispell-look-options (if ispell-have-new-look "-dfr" "-df")
448 "String of command options for `ispell-look-command'."
452 (defcustom ispell-use-ptys-p nil
453 "When non-nil, Emacs uses ptys to communicate with Ispell.
454 When nil, Emacs uses pipes."
458 (defcustom ispell-following-word nil
459 "Non-nil means `ispell-word' checks the word around or after point.
460 Otherwise `ispell-word' checks the preceding word."
464 (defcustom ispell-help-in-bufferp nil
465 "Non-nil means display interactive keymap help in a buffer.
466 The following values are supported:
467 nil Expand the minibuffer and display a short help message
468 there for a couple of seconds.
469 t Pop up a new buffer and display a short help message there
470 for a couple of seconds.
471 electric Pop up a new buffer and display a long help message there.
472 User can browse and then exit the help mode."
473 :type '(choice (const electric) (const :tag "off" nil) (const :tag "on" t))
476 (defcustom ispell-quietly nil
477 "Non-nil means suppress messages in `ispell-word'."
481 (defcustom ispell-format-word-function (function upcase)
482 "Formatting function for displaying word being spell checked.
483 The function must take one string argument and return a string."
486 (defvaralias 'ispell-format-word 'ispell-format-word-function)
488 (defcustom ispell-use-framepop-p nil
489 "When non-nil ispell uses framepop to display choices in a dedicated frame.
490 You can set this variable to dynamically use framepop if you are in a
491 window system by evaluating the following on startup to set this variable:
492 (and window-system (condition-case () (require 'framepop) (error nil)))"
497 (defcustom ispell-personal-dictionary nil
498 "File name of your personal spelling dictionary, or nil.
499 If nil, the default personal dictionary, (\"~/.ispell_DICTNAME\" for ispell or
500 \"~/.aspell.LANG.pws\" for aspell) is used, where DICTNAME is the name of your
501 default dictionary and LANG the two letter language code."
503 (const :tag "default" nil))
506 (defcustom ispell-silently-savep nil
507 "When non-nil, save personal dictionary without asking for confirmation."
511 (defvar ispell-local-dictionary-overridden nil
512 "Non-nil means the user has explicitly set this buffer's Ispell dictionary.")
513 (make-variable-buffer-local 'ispell-local-dictionary-overridden)
515 (defcustom ispell-local-dictionary nil
516 "If non-nil, the dictionary to be used for Ispell commands in this buffer.
517 The value must be a string dictionary name,
518 or nil, which means use the global setting in `ispell-dictionary'.
519 Dictionary names are defined in `ispell-local-dictionary-alist'
520 and `ispell-dictionary-alist'.
522 Setting `ispell-local-dictionary' to a value has the same effect as
523 calling \\[ispell-change-dictionary] with that value. This variable
524 is automatically set when defined in the file with either
525 `ispell-dictionary-keyword' or the Local Variable syntax."
526 :type '(choice string
527 (const :tag "default" nil))
530 (put 'ispell-local-dictionary 'safe-local-variable 'string-or-null-p)
532 (make-variable-buffer-local 'ispell-local-dictionary)
534 (defcustom ispell-dictionary nil
535 "Default dictionary to use if `ispell-local-dictionary' is nil."
536 :type '(choice string
537 (const :tag "default" nil))
540 (defcustom ispell-extra-args nil
541 "If non-nil, a list of extra switches to pass to the Ispell program.
542 For example, (\"-W\" \"3\") to cause it to accept all 1-3 character
543 words as correct. See also `ispell-dictionary-alist', which may be used
544 for language-specific arguments."
545 :type '(repeat string)
550 (defcustom ispell-skip-html 'use-mode-name
551 "Indicates whether ispell should skip spell checking of SGML markup.
552 If t, always skip SGML markup; if nil, never skip; if non-t and non-nil,
553 guess whether SGML markup should be skipped according to the name of the
554 buffer's major mode."
555 :type '(choice (const :tag "always" t) (const :tag "never" nil)
556 (const :tag "use-mode-name" use-mode-name))
559 (make-variable-buffer-local 'ispell-skip-html)
562 (defcustom ispell-local-dictionary-alist nil
563 "List of local or customized dictionary definitions.
564 These can override the values in `ispell-dictionary-alist'.
566 To make permanent changes to your dictionary definitions, you
567 will need to make your changes in this variable, save, and then
569 :type '(repeat (list (choice :tag "Dictionary"
570 (string :tag "Dictionary name")
571 (const :tag "default" nil))
572 (regexp :tag "Case characters")
573 (regexp :tag "Non case characters")
574 (regexp :tag "Other characters")
575 (boolean :tag "Many other characters")
576 (repeat :tag "Ispell command line args"
578 (choice :tag "Extended character mode"
579 (const "~tex") (const "~plaintex")
580 (const "~nroff") (const "~list")
581 (const "~latin1") (const "~latin3")
582 (const :tag "default" nil))
583 (coding-system :tag "Coding System")))
587 (defvar ispell-dictionary-base-alist
589 ;; The default dictionary. It may be English.aff, or any other
590 ;; dictionary depending on locale and such things. We should probably
591 ;; ask ispell what dictionary it's using, but until we do that, let's
592 ;; just use a minimal regexp. [:alpha:] will later be set if possible.
593 "[A-Za-z]" "[^A-Za-z]" "[']" nil ("-B") nil iso-8859-1)
594 ("american" ; Yankee English
595 "[A-Za-z]" "[^A-Za-z]" "[']" nil ("-B") nil iso-8859-1)
596 ("brasileiro" ; Brazilian mode
597 "[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]"
598 "[^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]"
599 "[']" nil nil nil iso-8859-1)
600 ("british" ; British version
601 "[A-Za-z]" "[^A-Za-z]" "[']" nil ("-B") nil iso-8859-1)
602 ("castellano" ; Spanish mode
603 "[A-Z\301\311\315\321\323\332\334a-z\341\351\355\361\363\372\374]"
604 "[^A-Z\301\311\315\321\323\332\334a-z\341\351\355\361\363\372\374]"
605 "[-]" nil ("-B") "~tex" iso-8859-1)
606 ("castellano8" ; 8 bit Spanish mode
607 "[A-Z\301\311\315\321\323\332\334a-z\341\351\355\361\363\372\374]"
608 "[^A-Z\301\311\315\321\323\332\334a-z\341\351\355\361\363\372\374]"
609 "[-]" nil ("-B" "-d" "castellano") "~latin1" iso-8859-1)
611 "[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]"
612 "[^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]"
613 "" nil ("-B") nil iso-8859-2)
615 "[A-Z\306\330\305a-z\346\370\345]" "[^A-Z\306\330\305a-z\346\370\345]"
616 "[']" nil ("-C") nil iso-8859-1)
617 ("deutsch" ; Deutsch.aff
618 "[a-zA-Z\"]" "[^a-zA-Z\"]" "[']" t ("-C") "~tex" iso-8859-1)
620 "[a-zA-Z\304\326\334\344\366\337\374]"
621 "[^a-zA-Z\304\326\334\344\366\337\374]"
622 "[']" t ("-C" "-d" "deutsch") "~latin1" iso-8859-1)
623 ("english" ; make English explicitly selectable
624 "[A-Za-z]" "[^A-Za-z]" "[']" nil ("-B") nil iso-8859-1)
626 "[A-Za-z\246\254\266\274\306\330\335\336\346\370\375\376]"
627 "[^A-Za-z\246\254\266\274\306\330\335\336\346\370\375\376]"
628 "[-']" t ("-C") "~latin3" iso-8859-3)
630 "[A-Za-z^\\]" "[^A-Za-z^\\]"
631 "[-'`\"]" t ("-C" "-d" "esperanto") "~tex" iso-8859-3)
633 "[A-Za-z\345\344\366\305\304\326]"
634 "[^A-Za-z\345\344\366\305\304\326]"
635 "[:]" nil ("-C") "~list" iso-8859-1)
637 "[A-Za-z]" "[^A-Za-z]" "[`'^-]" t nil nil iso-8859-1)
638 ("francais" ; Francais.aff
639 "[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]"
640 "[^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]"
641 "[-'.@]" t nil "~list" iso-8859-1)
642 ("francais-tex" ; Francais.aff
643 "[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\\]"
644 "[^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\\]"
645 "[-'^`\".@]" t nil "~tex" iso-8859-1)
646 ("german" ; german.aff
647 "[a-zA-Z\"]" "[^a-zA-Z\"]" "[']" t ("-C") "~tex" iso-8859-1)
648 ("german8" ; german.aff
649 "[a-zA-Z\304\326\334\344\366\337\374]"
650 "[^a-zA-Z\304\326\334\344\366\337\374]"
651 "[']" t ("-C" "-d" "german") "~latin1" iso-8859-1)
652 ("italiano" ; Italian.aff
653 "[A-Z\300\301\310\311\314\315\322\323\331\332a-z\340\341\350\351\354\355\363\371\372]"
654 "[^A-Z\300\301\310\311\314\315\322\323\331\332a-z\340\341\350\351\354\355\363\371\372]"
655 "[-.]" nil ("-B" "-d" "italian") "~tex" iso-8859-1)
656 ("nederlands" ; Nederlands.aff
657 "[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]"
658 "[^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]"
659 "[']" t ("-C") nil iso-8859-1)
660 ("nederlands8" ; Dutch8.aff
661 "[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]"
662 "[^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]"
663 "[']" t ("-C") nil iso-8859-1)
664 ("norsk" ; 8 bit Norwegian mode
665 "[A-Za-z\305\306\307\310\311\322\324\330\345\346\347\350\351\362\364\370]"
666 "[^A-Za-z\305\306\307\310\311\322\324\330\345\346\347\350\351\362\364\370]"
667 "[\"]" nil nil "~list" iso-8859-1)
668 ("norsk7-tex" ; 7 bit Norwegian TeX mode
669 "[A-Za-z{}\\'^`]" "[^A-Za-z{}\\'^`]"
670 "[\"]" nil ("-d" "norsk") "~plaintex" iso-8859-1)
671 ("polish" ; Polish mode
672 "[A-Za-z\241\243\246\254\257\261\263\266\274\277\306\312\321\323\346\352\361\363]"
673 "[^A-Za-z\241\243\246\254\257\261\263\266\274\277\306\312\321\323\346\352\361\363]"
674 "[.]" nil nil nil iso-8859-2)
675 ("portugues" ; Portuguese mode
676 "[a-zA-Z\301\302\307\311\323\340\341\342\351\352\355\363\343\347\372]"
677 "[^a-zA-Z\301\302\307\311\323\340\341\342\351\352\355\363\343\347\372]"
678 "[']" t ("-C") "~latin1" iso-8859-1)
679 ("russian" ; Russian.aff (KOI8-R charset)
680 "[\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]"
681 "[^\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]"
682 "" nil nil nil koi8-r)
683 ("russianw" ; russianw.aff (CP1251 charset)
684 "[\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]"
685 "[^\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]"
686 "" nil nil nil windows-1251)
687 ("slovak" ; Slovakian
688 "[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]"
689 "[^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]"
690 "" nil ("-B") nil iso-8859-2)
691 ("slovenian" ; Slovenian
692 "[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]"
693 "[^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]"
694 "" nil ("-B" "-d" "slovenian") nil iso-8859-2)
695 ("svenska" ; Swedish mode
696 "[A-Za-z\345\344\366\351\340\374\350\346\370\347\305\304\326\311\300\334\310\306\330\307]"
697 "[^A-Za-z\345\344\366\351\340\374\350\346\370\347\305\304\326\311\300\334\310\306\330\307]"
698 "[']" nil ("-C") "~list" iso-8859-1)
699 ("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))
700 "Base value for `ispell-dictionary-alist'.")
702 (defvar ispell-dictionary-alist nil
703 "An alist of dictionaries and their associated parameters.
705 Each element of this list is also a list:
707 \(DICTIONARY-NAME CASECHARS NOT-CASECHARS OTHERCHARS MANY-OTHERCHARS-P
708 ISPELL-ARGS EXTENDED-CHARACTER-MODE CHARACTER-SET\)
710 DICTIONARY-NAME is a possible string value of variable `ispell-dictionary',
711 nil means the default dictionary.
713 CASECHARS is a regular expression of valid characters that comprise a word.
715 NOT-CASECHARS is the opposite regexp of CASECHARS.
717 OTHERCHARS is a regexp of characters in the NOT-CASECHARS set but which can be
718 used to construct words in some special way. If OTHERCHARS characters follow
719 and precede characters from CASECHARS, they are parsed as part of a word,
720 otherwise they become word-breaks. As an example in English, assume the
721 regular expression \"[']\" for OTHERCHARS. Then \"they're\" and
722 \"Steven's\" are parsed as single words including the \"'\" character, but
723 \"Stevens'\" does not include the quote character as part of the word.
724 If you want OTHERCHARS to be empty, use the empty string.
725 Hint: regexp syntax requires the hyphen to be declared first here.
727 CASECHARS, NOT-CASECHARS, and OTHERCHARS must be unibyte strings
728 containing bytes of CHARACTER-SET. In addition, if they contain
729 non-ASCII bytes, the regular expression must be a single
730 `character set' construct that doesn't specify a character range
733 MANY-OTHERCHARS-P is non-nil when multiple OTHERCHARS are allowed in a word.
734 Otherwise only a single OTHERCHARS character is allowed to be part of any
737 ISPELL-ARGS is a list of additional arguments passed to the ispell
740 EXTENDED-CHARACTER-MODE should be used when dictionaries are used which
741 have been configured in an Ispell affix file. (For example, umlauts
742 can be encoded as \\\"a, a\\\", \"a, ...) Defaults are ~tex and ~nroff
743 in English. This has the same effect as the command-line `-T' option.
744 The buffer Major Mode controls Ispell's parsing in tex or nroff mode,
745 but the dictionary can control the extended character mode.
746 Both defaults can be overruled in a buffer-local fashion. See
747 `ispell-parsing-keyword' for details on this.
749 CHARACTER-SET used to encode text sent to the ispell subprocess
750 when the language uses non-ASCII characters.
752 Note that with \"ispell\" as the speller, the CASECHARS and
753 OTHERCHARS slots of the alist should contain the same character
754 set as casechars and otherchars in the LANGUAGE.aff file \(e.g.,
755 english.aff\). aspell and hunspell don't have this limitation.")
757 (defvar ispell-really-aspell nil) ; Non-nil if we can use aspell extensions.
758 (defvar ispell-really-hunspell nil) ; Non-nil if we can use hunspell extensions.
759 (defvar ispell-encoding8-command nil
760 "Command line option prefix to select encoding if supported, nil otherwise.
761 If setting the encoding is supported by spellchecker and is selectable from
762 the command line, this variable will contain \"--encoding=\" for aspell
763 and \"-i \" for hunspell, so the appropriate mime charset can be selected.
764 That will be set in `ispell-check-version' for hunspell >= 1.1.6 and
767 For aspell, non-nil also means to try to automatically find its dictionaries.
769 Earlier aspell versions do not consistently support charset encoding. Handling
770 this would require some extra guessing in `ispell-aspell-find-dictionary'.")
772 (defvar ispell-aspell-supports-utf8 nil
773 "Non-nil if aspell has consistent command line UTF-8 support. Obsolete.
774 ispell.el and flyspell.el will use for this purpose the more generic
775 variable `ispell-encoding8-command' for both aspell and hunspell. Is left
776 here just for backwards compatibility.")
778 (make-obsolete-variable 'ispell-aspell-supports-utf8
779 'ispell-encoding8-command "23.1")
781 (defvar ispell-emacs-alpha-regexp
782 (if (string-match "^[[:alpha:]]+$" "abcde")
785 "[[:alpha:]] if Emacs supports [:alpha:] regexp, nil
786 otherwise (current XEmacs does not support it).")
788 ;;; **********************************************************************
789 ;;; The following are used by ispell, and should not be changed.
790 ;;; **********************************************************************
794 ;; The version must be 3.1 or greater for this version of ispell.el
795 ;; There is an incompatibility between version 3.1.12 and lower versions.
796 (defconst ispell-required-version '(3 1 12)
797 "Ispell versions with which this version of ispell.el is known to work.")
798 (defvar ispell-offset -1
799 "Offset that maps protocol differences between ispell 3.1 versions.")
801 (defconst ispell-version "ispell.el 3.6 - 7-Jan-2003")
804 (defun ispell-check-version (&optional interactivep)
805 "Ensure that `ispell-program-name' is valid and has the correct version.
806 Returns version number if called interactively.
807 Otherwise returns the library directory name, if that is defined."
808 ;; This is a little wasteful as we actually launch ispell twice: once
809 ;; to make sure it's the right version, and once for real. But people
810 ;; get confused by version mismatches *all* the time (and I've got the
811 ;; email to prove it) so I think this is worthwhile. And the -v[ersion]
812 ;; option is the only way I can think of to do this that works with
813 ;; all versions, since versions earlier than 3.0.09 didn't identify
814 ;; themselves on startup.
816 (let ((default-directory (or (and (boundp 'temporary-file-directory)
817 temporary-file-directory)
819 result status ispell-program-version)
822 (setq status (ispell-call-process
823 ispell-program-name nil t nil
824 ;; aspell doesn't accept the -vv switch.
825 (let ((case-fold-search
826 (memq system-type '(ms-dos windows-nt)))
828 (file-name-nondirectory ispell-program-name)))
829 ;; Assume anything that isn't `aspell' is Ispell.
830 (if (string-match "\\`aspell" speller) "-v" "-vv"))))
831 (goto-char (point-min))
833 ;; report version information of ispell and ispell.el
836 (setq result (concat (buffer-substring-no-properties (point-min)
840 (message "%s" result))
841 ;; return library directory.
842 (if (re-search-forward "LIBDIR = \\\"\\([^ \t\n]*\\)\\\"" nil t)
843 (setq result (match-string 1))))
844 (goto-char (point-min))
845 (if (not (memq status '(0 nil)))
846 (error "%s exited with %s %s" ispell-program-name
847 (if (stringp status) "signal" "code") status))
849 ;; Get relevant version strings. Only xx.yy.... format works well
850 (let (case-fold-search)
851 (setq ispell-program-version
852 (and (search-forward-regexp "\\([0-9]+\\.[0-9\\.]+\\)" nil t)
855 ;; Make sure these variables are (re-)initialized to the default value
856 (setq ispell-really-aspell nil
857 ispell-aspell-supports-utf8 nil
858 ispell-really-hunspell nil
859 ispell-encoding8-command nil)
861 (goto-char (point-min))
862 (or (setq ispell-really-aspell
863 (and (search-forward-regexp
864 "(but really Aspell \\([0-9]+\\.[0-9\\.-]+\\)?)" nil t)
866 (setq ispell-really-hunspell
867 (and (search-forward-regexp
868 "(but really Hunspell \\([0-9]+\\.[0-9\\.-]+\\)?)"
872 (let ((aspell-minver "0.50")
873 (aspell8-minver "0.60")
874 (ispell0-minver "3.1.0")
875 (ispell-minver "3.1.12")
876 (hunspell8-minver "1.1.6"))
878 (if (ispell-check-minver ispell0-minver ispell-program-version)
879 (or (ispell-check-minver ispell-minver ispell-program-version)
880 (setq ispell-offset 0))
881 (error "%s release %s or greater is required"
886 (ispell-really-aspell
887 (if (ispell-check-minver aspell-minver ispell-really-aspell)
888 (if (ispell-check-minver aspell8-minver ispell-really-aspell)
890 (setq ispell-aspell-supports-utf8 t)
891 (setq ispell-encoding8-command "--encoding=")))
892 (setq ispell-really-aspell nil)))
893 (ispell-really-hunspell
894 (if (ispell-check-minver hunspell8-minver ispell-really-hunspell)
895 (setq ispell-encoding8-command "-i")
896 (setq ispell-really-hunspell nil))))))
899 (defun ispell-call-process (&rest args)
900 "Like `call-process' but defend against bad `default-directory'."
901 (let ((default-directory default-directory))
902 (unless (and (file-directory-p default-directory)
903 (file-readable-p default-directory))
904 (setq default-directory (expand-file-name "~/")))
905 (apply 'call-process args)))
907 (defun ispell-call-process-region (&rest args)
908 "Like `call-process-region' but defend against bad `default-directory'."
909 (let ((default-directory default-directory))
910 (unless (and (file-directory-p default-directory)
911 (file-readable-p default-directory))
912 (setq default-directory (expand-file-name "~/")))
913 (apply 'call-process-region args)))
917 ;; The preparation of the menu bar menu must be autoloaded
918 ;; because otherwise this file gets autoloaded every time Emacs starts
919 ;; so that it can set up the menus and determine keyboard equivalents.
922 (defvar ispell-menu-map nil "Key map for ispell menu.")
923 ;; Redo menu when loading ispell to get dictionary modifications
924 (setq ispell-menu-map nil)
927 (defvar ispell-menu-xemacs nil
928 "Spelling menu for XEmacs.
929 If nil when package is loaded, a standard menu will be set,
930 and added as a submenu of the \"Edit\" menu.")
932 ;; Break out XEmacs menu and split into several calls to avoid having
933 ;; long lines in loaddefs.el. Detect need off following constant.
935 ;;; Set up dictionary
937 (defvar ispell-menu-map-needed
938 ;; only needed when not version 18 and not XEmacs.
939 (and (not ispell-menu-map)
940 (not (featurep 'xemacs))
943 (defvar ispell-library-directory (condition-case ()
944 (ispell-check-version)
946 "Directory where ispell dictionaries reside.")
948 (defvar ispell-process nil
949 "The process object for Ispell.")
951 (defvar ispell-async-processp (and (fboundp 'delete-process)
952 (fboundp 'process-send-string)
953 (fboundp 'accept-process-output)
954 ;;(fboundp 'start-process)
955 ;;(fboundp 'set-process-filter)
956 ;;(fboundp 'process-kill-without-query)
958 "Non-nil means that the OS supports asynchronous processes.")
960 ;; Make ispell.el work better with aspell.
962 (defvar ispell-aspell-dictionary-alist nil
963 "An alist of parsed aspell dicts and associated parameters.
966 (defun ispell-find-aspell-dictionaries ()
967 "Find Aspell's dictionaries, and record in `ispell-dictionary-alist'."
968 (unless (and ispell-really-aspell ispell-encoding8-command)
969 (error "This function only works with aspell >= 0.60"))
973 (ispell-call-process ispell-program-name nil t nil "dicts")
975 ;; Search for the named dictionaries.
978 (mapcar #'ispell-aspell-find-dictionary dictionaries))))
979 ;; Ensure aspell's alias dictionary will override standard
981 (setq found (ispell-aspell-add-aliases found))
982 ;; Merge into FOUND any elements from the standard ispell-dictionary-base-alist
983 ;; which have no element in FOUND at all.
984 (dolist (dict ispell-dictionary-base-alist)
985 (unless (assoc (car dict) found)
986 (setq found (nconc found (list dict)))))
987 (setq ispell-aspell-dictionary-alist found)
988 ;; Add a default entry
990 '(nil "[[:alpha:]]" "[^[:alpha:]]" "[']" nil ("-B") nil utf-8)))
991 (push default-dict ispell-aspell-dictionary-alist))))
993 (defvar ispell-aspell-data-dir nil
994 "Data directory of Aspell.")
996 (defvar ispell-aspell-dict-dir nil
997 "Dictionary directory of Aspell.")
999 (defun ispell-get-aspell-config-value (key)
1000 "Return value of Aspell configuration option KEY.
1001 Assumes that value contains no whitespace."
1003 (ispell-call-process ispell-program-name nil t nil "config" key)
1004 (car (split-string (buffer-string)))))
1006 (defun ispell-aspell-find-dictionary (dict-name)
1007 "For aspell dictionary DICT-NAME, return a list of parameters if an
1008 associated data file is found or nil otherwise. List format is that
1009 of `ispell-dictionary-base-alist' elements."
1010 ;; Make sure `ispell-aspell-data-dir' is defined
1011 (or ispell-aspell-data-dir
1012 (setq ispell-aspell-data-dir
1013 (ispell-get-aspell-config-value "data-dir")))
1014 ;; Try finding associated datafile
1016 (concat ispell-aspell-data-dir "/"
1017 ;; Strip out variant, country code, etc.
1018 (and (string-match "^[[:alpha:]]+" dict-name)
1019 (match-string 0 dict-name)) ".dat"))
1021 (concat ispell-aspell-data-dir "/"
1022 ;; Strip out anything but xx_YY.
1023 (and (string-match "^[[:alpha:]_]+" dict-name)
1024 (match-string 0 dict-name)) ".dat"))
1026 (if (file-readable-p datafile1)
1028 (if (file-readable-p datafile2)
1034 (insert-file-contents data-file)
1035 ;; There is zero or one line with special characters declarations.
1036 (when (search-forward-regexp "^special" nil t)
1037 (let ((specials (split-string
1038 (buffer-substring (point)
1039 (progn (end-of-line) (point))))))
1040 ;; The line looks like: special ' -** - -** . -** : -*-
1041 ;; -** means that this character
1042 ;; - doesn't appear at word start
1043 ;; * may appear in the middle of a word
1044 ;; * may appear at word end
1045 ;; `otherchars' is about the middle case.
1047 (when (eq (aref (cadr specials) 1) ?*)
1048 (push (car specials) otherchars))
1049 (setq specials (cddr specials)))))
1053 (regexp-opt otherchars)
1054 t ; We can't tell, so set this to t
1055 (list "-d" dict-name)
1056 nil ; aspell doesn't support this
1057 ;; Here we specify the encoding to use while communicating with
1058 ;; aspell. This doesn't apply to command line arguments, so
1059 ;; just don't pass words to spellcheck as arguments...
1062 (defun ispell-aspell-add-aliases (alist)
1063 "Find aspell's dictionary aliases and add them to dictionary ALIST.
1064 Return the new dictionary alist."
1066 (file-expand-wildcards
1067 (concat (or ispell-aspell-dict-dir
1068 (setq ispell-aspell-dict-dir
1069 (ispell-get-aspell-config-value "dict-dir")))
1071 (dolist (alias-file aliases)
1073 (insert-file-contents alias-file)
1074 ;; Look for a line "add FOO.multi", extract FOO
1075 (when (search-forward-regexp "^add \\([^.]+\\)\\.multi" nil t)
1076 (let* ((aliasname (file-name-sans-extension
1077 (file-name-nondirectory alias-file)))
1078 (already-exists-p (assoc aliasname alist))
1079 (realname (match-string 1))
1080 (realdict (assoc realname alist)))
1081 (when (and realdict (not already-exists-p))
1082 (push (cons aliasname (cdr realdict)) alist))))))
1085 ;; Set params according to the selected spellchecker
1087 (defvar ispell-last-program-name nil
1088 "Last value of `ispell-program-name'. Internal use.")
1090 (defvar ispell-initialize-spellchecker-hook nil
1091 "Normal hook run on spellchecker initialization.
1092 This hook is run when a spellchecker is used for the first
1093 time, before `ispell-dictionary-alist' is set. It is intended for
1094 sysadmins to override entries in `ispell-dictionary-base-alist'
1095 by putting those overrides in `ispell-base-dicts-override-alist', which is
1096 a dynamically scoped var with same format as `ispell-dictionary-alist'.
1097 This alist will not override the auto-detected values (e.g. if a recent
1098 aspell is used along with Emacs).")
1100 (defun ispell-set-spellchecker-params ()
1101 "Initialize some spellchecker parameters when changed or first used."
1102 (unless (eq ispell-last-program-name ispell-program-name)
1103 (setq ispell-last-program-name ispell-program-name)
1104 (ispell-kill-ispell t)
1105 (if (and (condition-case ()
1107 (setq ispell-library-directory (ispell-check-version))
1110 ispell-really-aspell
1111 ispell-encoding8-command
1112 ispell-emacs-alpha-regexp)
1113 (unless ispell-aspell-dictionary-alist
1114 (ispell-find-aspell-dictionaries)))
1116 ;; Substitute ispell-dictionary-alist with the list of dictionaries
1117 ;; corresponding to the given spellchecker. If a recent aspell, use
1118 ;; the list of really installed dictionaries and add to it elements
1119 ;; of the original list that are not present there. Allow distro info.
1120 (let ((found-dicts-alist
1121 (if (and ispell-really-aspell
1122 ispell-encoding8-command)
1123 ispell-aspell-dictionary-alist
1125 ispell-base-dicts-override-alist ; Override only base-dicts-alist
1128 (run-hooks 'ispell-initialize-spellchecker-hook)
1130 ;; Add dicts to ``ispell-dictionary-alist'' unless already present.
1131 (dolist (dict (append found-dicts-alist
1132 ispell-base-dicts-override-alist
1133 ispell-dictionary-base-alist))
1134 (unless (assoc (car dict) all-dicts-alist)
1135 (add-to-list 'all-dicts-alist dict)))
1136 (setq ispell-dictionary-alist all-dicts-alist))
1138 ;; If Emacs flavor supports [:alpha:] use it for global dicts. If
1139 ;; spellchecker also supports UTF-8 via command-line option use it
1140 ;; in communication. This does not affect definitions in ~/.emacs.
1141 (if ispell-emacs-alpha-regexp
1142 (let (tmp-dicts-alist)
1143 (dolist (adict ispell-dictionary-alist)
1144 (add-to-list 'tmp-dicts-alist
1146 (nth 0 adict) ; dict name
1147 "[[:alpha:]]" ; casechars
1148 "[^[:alpha:]]" ; not-casechars
1149 (nth 3 adict) ; otherchars
1150 (nth 4 adict) ; many-otherchars-p
1151 (nth 5 adict) ; ispell-args
1152 (nth 6 adict) ; extended-character-mode
1153 (if ispell-encoding8-command
1156 (setq ispell-dictionary-alist tmp-dicts-alist)))))
1158 (defun ispell-valid-dictionary-list ()
1159 "Return a list of valid dictionaries.
1160 The variable `ispell-library-directory' defines their location."
1161 ;; Initialize variables and dictionaries alists for desired spellchecker.
1162 ;; Make sure ispell.el is loaded to avoid some autoload loops in XEmacs
1163 ;; (and may be others)
1164 (if (featurep 'ispell)
1165 (ispell-set-spellchecker-params))
1167 (let ((dicts (append ispell-local-dictionary-alist ispell-dictionary-alist))
1168 (dict-list (cons "default" nil))
1170 (dolist (dict dicts)
1171 (setq name (car dict)
1172 dict-bname (or (car (cdr (member "-d" (nth 5 dict))))
1174 ;; Include if the dictionary is in the library, or dir not defined.
1177 ;; For Aspell, we already know which dictionaries exist.
1178 (or ispell-really-aspell
1179 ;; Include all dictionaries if lib directory not known.
1180 ;; Same for Hunspell, where ispell-library-directory is nil.
1181 (not ispell-library-directory)
1182 (file-exists-p (concat ispell-library-directory
1183 "/" dict-bname ".hash"))
1184 (file-exists-p (concat ispell-library-directory
1185 "/" dict-bname ".has"))))
1186 (push name dict-list)))
1189 ;; Define commands in menu in opposite order you want them to appear.
1191 (if ispell-menu-map-needed
1193 (setq ispell-menu-map (make-sparse-keymap "Spell"))
1194 (define-key ispell-menu-map [ispell-change-dictionary]
1195 `(menu-item ,(purecopy "Change Dictionary...") ispell-change-dictionary
1196 :help ,(purecopy "Supply explicit dictionary file name")))
1197 (define-key ispell-menu-map [ispell-kill-ispell]
1198 `(menu-item ,(purecopy "Kill Process")
1199 (lambda () (interactive) (ispell-kill-ispell nil 'clear))
1200 :enable (and (boundp 'ispell-process) ispell-process
1201 (eq (ispell-process-status) 'run))
1202 :help ,(purecopy "Terminate Ispell subprocess")))
1203 (define-key ispell-menu-map [ispell-pdict-save]
1204 `(menu-item ,(purecopy "Save Dictionary")
1205 (lambda () (interactive) (ispell-pdict-save t t))
1206 :help ,(purecopy "Save personal dictionary")))
1207 (define-key ispell-menu-map [ispell-customize]
1208 `(menu-item ,(purecopy "Customize...")
1209 (lambda () (interactive) (customize-group 'ispell))
1210 :help ,(purecopy "Customize spell checking options")))
1211 (define-key ispell-menu-map [ispell-help]
1212 ;; use (x-popup-menu last-nonmenu-event(list "" ispell-help-list)) ?
1213 `(menu-item ,(purecopy "Help")
1214 (lambda () (interactive) (describe-function 'ispell-help))
1215 :help ,(purecopy "Show standard Ispell keybindings and commands")))
1216 (define-key ispell-menu-map [flyspell-mode]
1217 `(menu-item ,(purecopy "Automatic spell checking (Flyspell)")
1219 :help ,(purecopy "Check spelling while you edit the text")
1220 :button (:toggle . (bound-and-true-p flyspell-mode))))
1221 (define-key ispell-menu-map [ispell-complete-word]
1222 `(menu-item ,(purecopy "Complete Word") ispell-complete-word
1223 :help ,(purecopy "Complete word at cursor using dictionary")))
1224 (define-key ispell-menu-map [ispell-complete-word-interior-frag]
1225 `(menu-item ,(purecopy "Complete Word Fragment")
1226 ispell-complete-word-interior-frag
1227 :help ,(purecopy "Complete word fragment at cursor")))))
1230 (if ispell-menu-map-needed
1232 (define-key ispell-menu-map [ispell-continue]
1233 `(menu-item ,(purecopy "Continue Spell-Checking") ispell-continue
1234 :enable (and (boundp 'ispell-region-end)
1235 (marker-position ispell-region-end)
1236 (equal (marker-buffer ispell-region-end)
1238 :help ,(purecopy "Continue spell checking last region")))
1239 (define-key ispell-menu-map [ispell-word]
1240 `(menu-item ,(purecopy "Spell-Check Word") ispell-word
1241 :help ,(purecopy "Spell-check word at cursor")))
1242 (define-key ispell-menu-map [ispell-comments-and-strings]
1243 `(menu-item ,(purecopy "Spell-Check Comments")
1244 ispell-comments-and-strings
1245 :help ,(purecopy "Spell-check only comments and strings")))))
1248 (if ispell-menu-map-needed
1250 (define-key ispell-menu-map [ispell-region]
1251 `(menu-item ,(purecopy "Spell-Check Region") ispell-region
1253 :help ,(purecopy "Spell-check text in marked region")))
1254 (define-key ispell-menu-map [ispell-message]
1255 `(menu-item ,(purecopy "Spell-Check Message") ispell-message
1256 :visible (eq major-mode 'mail-mode)
1257 :help ,(purecopy "Skip headers and included message text")))
1258 (define-key ispell-menu-map [ispell-buffer]
1259 `(menu-item ,(purecopy "Spell-Check Buffer") ispell-buffer
1260 :help ,(purecopy "Check spelling of selected buffer")))
1261 ;;(put 'ispell-region 'menu-enable 'mark-active)
1262 (fset 'ispell-menu-map (symbol-value 'ispell-menu-map))))
1264 ;;; XEmacs versions 19 & 20
1265 (if (and (featurep 'xemacs)
1267 ;;(null ispell-menu-xemacs)
1268 (not (and (boundp 'infodock-version) infodock-version)))
1269 (let ((dicts (if (fboundp 'ispell-valid-dictionary-list)
1270 (reverse (ispell-valid-dictionary-list))))
1271 (current-menubar (or current-menubar default-menubar))
1273 '(["Help" (describe-function 'ispell-help) t]
1274 ;;["Help" (popup-menu ispell-help-list) t]
1275 ["Check Message" ispell-message t]
1276 ["Check Buffer" ispell-buffer t]
1277 ["Check Comments" ispell-comments-and-strings t]
1278 ["Check Word" ispell-word t]
1279 ["Check Region" ispell-region (or (not zmacs-regions) (mark))]
1280 ["Continue Check" ispell-continue t]
1281 ["Complete Word Frag"ispell-complete-word-interior-frag t]
1282 ["Complete Word" ispell-complete-word t]
1283 ["Kill Process" (ispell-kill-ispell nil 'clear) t]
1284 ["Customize..." (customize-group 'ispell) t]
1285 ;; flyspell-mode may not be bound...
1286 ;;["flyspell" flyspell-mode
1287 ;; :style toggle :selected flyspell-mode ]
1289 ["Save Personal Dict"(ispell-pdict-save t t) t]
1290 ["Change Dictionary" ispell-change-dictionary t])))
1292 (setq dicts (cons "default" nil)))
1293 (dolist (name dicts)
1294 (setq menu (append menu
1297 (concat "Select " (capitalize name))
1298 (list 'ispell-change-dictionary name)
1300 (setq ispell-menu-xemacs menu)
1303 (if (car (find-menu-item current-menubar '("Cmds")))
1306 (delete-menu-item '("Cmds" "Spell-Check"))
1307 (add-menu '("Cmds") "Spell-Check" ispell-menu-xemacs))
1309 (delete-menu-item '("Edit" "Spell")) ; in case already defined
1310 (add-menu '("Edit") "Spell" ispell-menu-xemacs))))))
1312 (defalias 'ispell-int-char
1313 ;; Allow incrementing characters as integers in XEmacs 20
1314 (if (and (featurep 'xemacs)
1315 (fboundp 'int-char))
1317 ;; Emacs and XEmacs 19 or earlier
1321 ;;; **********************************************************************
1323 (defvar ispell-current-dictionary nil
1324 "The name of the current dictionary, or nil for the default.
1325 This is passed to the ispell process using the `-d' switch and is
1326 used as key in `ispell-local-dictionary-alist' and `ispell-dictionary-alist'.")
1328 (defvar ispell-current-personal-dictionary nil
1329 "The name of the current personal dictionary, or nil for the default.
1330 This is passed to the ispell process using the `-p' switch.")
1332 (defun ispell-decode-string (str)
1333 "Decodes multibyte character strings.
1334 Protects against bogus binding of `enable-multibyte-characters' in XEmacs."
1335 ;; FIXME: enable-multibyte-characters is read-only, so bogus bindings are
1336 ;; really nasty (they signal an error in Emacs): Who does that? --Stef
1337 (if (and (or (featurep 'xemacs)
1338 (and (boundp 'enable-multibyte-characters)
1339 enable-multibyte-characters))
1340 (fboundp 'decode-coding-string)
1341 (ispell-get-coding-system))
1342 (decode-coding-string str (ispell-get-coding-system))
1345 ;; Return a string decoded from Nth element of the current dictionary.
1346 (defun ispell-get-decoded-string (n)
1347 "Get the decoded string in slot N of the descriptor of the current dict."
1349 (assoc ispell-current-dictionary ispell-local-dictionary-alist)
1350 (assoc ispell-current-dictionary ispell-dictionary-alist)
1351 (error "No data for dictionary \"%s\", neither in `ispell-local-dictionary-alist' nor in `ispell-dictionary-alist'"
1352 ispell-current-dictionary)))
1354 (when (and (> (length str) 0)
1355 (not (multibyte-string-p str)))
1356 (setq str (ispell-decode-string str))
1357 (or (multibyte-string-p str)
1358 (setq str (string-to-multibyte str))))
1361 (defun ispell-get-casechars ()
1362 (ispell-get-decoded-string 1))
1363 (defun ispell-get-not-casechars ()
1364 (ispell-get-decoded-string 2))
1365 (defun ispell-get-otherchars ()
1366 (ispell-get-decoded-string 3))
1367 (defun ispell-get-many-otherchars-p ()
1368 (nth 4 (or (assoc ispell-current-dictionary ispell-local-dictionary-alist)
1369 (assoc ispell-current-dictionary ispell-dictionary-alist))))
1370 (defun ispell-get-ispell-args ()
1371 (nth 5 (or (assoc ispell-current-dictionary ispell-local-dictionary-alist)
1372 (assoc ispell-current-dictionary ispell-dictionary-alist))))
1373 (defun ispell-get-extended-character-mode ()
1374 (if ispell-really-hunspell ;; hunspell treats ~word as ordinary words
1375 nil ;; in pipe mode. Disable extended-char-mode
1376 (nth 6 (or (assoc ispell-current-dictionary ispell-local-dictionary-alist)
1377 (assoc ispell-current-dictionary ispell-dictionary-alist)))))
1378 (defun ispell-get-coding-system ()
1379 (nth 7 (or (assoc ispell-current-dictionary ispell-local-dictionary-alist)
1380 (assoc ispell-current-dictionary ispell-dictionary-alist))))
1383 (defvar ispell-pdict-modified-p nil
1384 "Non-nil means personal dictionary has modifications to be saved.")
1386 ;; If you want to save the dictionary when quitting, must do so explicitly.
1387 ;; When non-nil, the spell session is terminated.
1388 ;; When numeric, contains cursor location in buffer, and cursor remains there.
1389 (defvar ispell-quit nil)
1391 (defvar ispell-process-directory nil
1392 "The directory where `ispell-process' was started.")
1394 (defvar ispell-filter nil
1395 "Output filter from piped calls to Ispell.")
1397 (defvar ispell-filter-continue nil
1398 "Control variable for Ispell filter function.")
1400 (defvar ispell-output-buffer nil
1401 "Buffer used for reading output of a synchronous Ispell subprocess.")
1403 (defvar ispell-session-buffer nil
1404 "Buffer used for passing input to a synchronous Ispell subprocess.")
1406 (defvar ispell-cmd-args nil
1407 "Command-line arguments to pass to a synchronous Ispell subprocess.")
1409 (defvar ispell-query-replace-marker (make-marker)
1410 "Marker for `query-replace' processing.")
1412 (defvar ispell-recursive-edit-marker (make-marker)
1413 "Marker for return point from recursive edit.")
1415 (defvar ispell-checking-message nil
1416 "Non-nil when we're checking a mail message.
1417 Set to the MIME boundary locations when checking messages.")
1419 (defconst ispell-choices-buffer "*Choices*")
1421 (defvar ispell-overlay nil "Overlay variable for Ispell highlighting.")
1423 ;;; *** Buffer Local Definitions ***
1425 (defconst ispell-words-keyword "LocalWords: "
1426 "The keyword for local oddly-spelled words to accept.
1427 The keyword will be followed by any number of local word spellings.
1428 There can be multiple instances of this keyword in the file.")
1430 (defconst ispell-dictionary-keyword "Local IspellDict: "
1431 "The keyword for a local dictionary to use.
1432 The keyword must be followed by a valid dictionary name, defined in
1433 `ispell-local-dictionary-alist' or `ispell-dictionary-alist'.
1434 When multiple occurrences exist, the last keyword
1435 definition is used.")
1437 (defconst ispell-pdict-keyword "Local IspellPersDict: "
1438 "The keyword for defining buffer local dictionaries.
1439 Keyword must be followed by the filename of a personal dictionary.
1440 The last occurring definition in the buffer will be used.")
1442 (defconst ispell-parsing-keyword "Local IspellParsing: "
1443 "The keyword for overriding default Ispell parsing.
1444 The above keyword string should be followed by `latex-mode' or
1445 `nroff-mode' to put the current buffer into the desired parsing mode.
1447 Extended character mode can be changed for this buffer by placing
1448 a `~' followed by an extended-character mode -- such as `~.tex'.
1449 The last occurring definition in the buffer will be used.")
1452 (defvar ispell-skip-region-alist
1453 `((ispell-words-keyword forward-line)
1454 (ispell-dictionary-keyword forward-line)
1455 (ispell-pdict-keyword forward-line)
1456 (ispell-parsing-keyword forward-line)
1457 (,(purecopy "^---*BEGIN PGP [A-Z ]*--*")
1458 . ,(purecopy "^---*END PGP [A-Z ]*--*"))
1459 ;; assume multiline uuencoded file? "\nM.*$"?
1460 (,(purecopy "^begin [0-9][0-9][0-9] [^ \t]+$") . ,(purecopy "\nend\n"))
1461 (,(purecopy "^%!PS-Adobe-[123].0") . ,(purecopy "\n%%EOF\n"))
1462 (,(purecopy "^---* \\(Start of \\)?[Ff]orwarded [Mm]essage")
1463 . ,(purecopy "^---* End of [Ff]orwarded [Mm]essage"))
1464 ;; Matches e-mail addresses, file names, http addresses, etc. The
1465 ;; `-+' `_+' patterns are necessary for performance reasons when
1466 ;; `-' or `_' part of word syntax.
1467 (,(purecopy "\\(--+\\|_+\\|\\(/\\w\\|\\(\\(\\w\\|[-_]\\)+[.:@]\\)\\)\\(\\w\\|[-_]\\)*\\([.:/@]+\\(\\w\\|[-_~=?&]\\)+\\)+\\)"))
1468 ;; above checks /.\w sequences
1469 ;;("\\(--+\\|\\(/\\|\\(\\(\\w\\|[-_]\\)+[.:@]\\)\\)\\(\\w\\|[-_]\\)*\\([.:/@]+\\(\\w\\|[-_~=?&]\\)+\\)+\\)")
1470 ;; This is a pretty complex regexp. It can be simplified to the following:
1471 ;; "\\(\\w\\|[-_]\\)*\\([.:/@]+\\(\\w\\|[-_]\\|~\\)+\\)+"
1472 ;; but some valid text will be skipped, e.g. "his/her". This could be
1473 ;; fixed up (at the expense of a moderately more complex regexp)
1474 ;; by not allowing "/" to be the character which triggers the
1475 ;; identification of the computer name, e.g.:
1476 ;; "\\(\\w\\|[-_]\\)+[.:@]\\(\\w\\|[-_]\\)*\\([.:/@]+\\(\\w\\|[-_]\\|~\\)+\\)+"
1478 "Alist expressing beginning and end of regions not to spell check.
1479 The alist key must be a regular expression.
1480 Valid forms include:
1481 (KEY) - just skip the key.
1482 (KEY . REGEXP) - skip to the end of REGEXP. REGEXP may be string or symbol.
1483 (KEY REGEXP) - skip to end of REGEXP. REGEXP must be a string.
1484 (KEY FUNCTION ARGS) - FUNCTION called with ARGS returns end of region.")
1485 (put 'ispell-skip-region-alist 'risky-local-variable t)
1489 (defvar ispell-tex-skip-alists
1491 '((;;("%\\[" . "%\\]") ; AMStex block comment...
1492 ;; All the standard LaTeX keywords from L. Lamport's guide:
1493 ;; \cite, \hspace, \hspace*, \hyphenation, \include, \includeonly, \input,
1494 ;; \label, \nocite, \rule (in ispell - rest included here)
1495 ("\\\\addcontentsline" ispell-tex-arg-end 2)
1496 ("\\\\add\\(tocontents\\|vspace\\)" ispell-tex-arg-end)
1497 ("\\\\\\([aA]lph\\|arabic\\)" ispell-tex-arg-end)
1498 ;;("\\\\author" ispell-tex-arg-end)
1499 ("\\\\bibliographystyle" ispell-tex-arg-end)
1500 ("\\\\makebox" ispell-tex-arg-end 0)
1501 ("\\\\e?psfig" ispell-tex-arg-end)
1502 ("\\\\document\\(class\\|style\\)" .
1503 "\\\\begin[ \t\n]*{[ \t\n]*document[ \t\n]*}"))
1504 (;; delimited with \begin. In ispell: displaymath, eqnarray, eqnarray*,
1505 ;; equation, minipage, picture, tabular, tabular* (ispell)
1506 ("\\(figure\\|table\\)\\*?" ispell-tex-arg-end 0)
1507 ("list" ispell-tex-arg-end 2)
1508 ("program" . "\\\\end[ \t\n]*{[ \t\n]*program[ \t\n]*}")
1509 ("verbatim\\*?" . "\\\\end[ \t\n]*{[ \t\n]*verbatim\\*?[ \t\n]*}"))))
1510 "Lists of regions to be skipped in TeX mode.
1511 First list is used raw.
1512 Second list has key placed inside \\begin{}.
1514 Delete or add any regions you want to be automatically selected
1515 for skipping in latex mode.")
1516 (put 'ispell-tex-skip-alist 'risky-local-variable t)
1520 (defconst ispell-html-skip-alists
1521 '(("<[cC][oO][dD][eE]\\>[^>]*>" "</[cC][oO][dD][eE]*>")
1522 ("<[sS][cC][rR][iI][pP][tT]\\>[^>]*>" "</[sS][cC][rR][iI][pP][tT]>")
1523 ("<[aA][pP][pP][lL][eE][tT]\\>[^>]*>" "</[aA][pP][pP][lL][eE][tT]>")
1524 ("<[vV][eE][rR][bB]\\>[^>]*>" "<[vV][eE][rR][bB]\\>[^>]*>")
1525 ;;("<[tT][tT]\\>[^>]*>" "<[tT][tT]\\>[^>]*>")
1528 ("&[^ \t\n;]" "[; \t\n]"))
1529 "Lists of start and end keys to skip in HTML buffers.
1530 Same format as `ispell-skip-region-alist'.
1531 Note - substrings of other matches must come last
1532 (e.g. \"<[tT][tT]/\" and \"<[^ \\t\\n>]\").")
1533 (put 'ispell-html-skip-alists 'risky-local-variable t)
1535 (defvar ispell-local-pdict ispell-personal-dictionary
1536 "A buffer local variable containing the current personal dictionary.
1537 If non-nil, the value must be a string, which is a file name.
1539 If you specify a personal dictionary for the current buffer which is
1540 different from the current personal dictionary, the effect is similar
1541 to calling \\[ispell-change-dictionary]. This variable is automatically
1542 set when defined in the file with either `ispell-pdict-keyword' or the
1543 local variable syntax.")
1545 (make-variable-buffer-local 'ispell-local-pdict)
1546 ;;;###autoload(put 'ispell-local-pdict 'safe-local-variable 'stringp)
1548 (defvar ispell-buffer-local-name nil
1549 "Contains the buffer name if local word definitions were used.
1550 Ispell is then restarted because the local words could conflict.")
1552 (defvar ispell-buffer-session-localwords nil
1553 "List of words accepted for session in this buffer.")
1555 (make-variable-buffer-local 'ispell-buffer-session-localwords)
1557 (defvar ispell-parser 'use-mode-name
1558 "Indicates whether ispell should parse the current buffer as TeX Code.
1559 Special value `use-mode-name' tries to guess using the name of `major-mode'.
1560 Default parser is `nroff'.
1561 Currently the only other valid parser is `tex'.
1563 You can set this variable in hooks in your init file -- eg:
1565 \(add-hook 'tex-mode-hook (lambda () (setq ispell-parser 'tex)))")
1567 (defvar ispell-region-end (make-marker)
1568 "Marker that allows spelling continuations.")
1570 (defvar ispell-check-only nil
1571 "If non-nil, `ispell-word' does not try to correct the word.")
1574 ;;; **********************************************************************
1575 ;;; **********************************************************************
1579 ;;;###autoload (define-key esc-map "$" 'ispell-word)
1582 (defun ispell-accept-output (&optional timeout-secs timeout-msecs)
1583 "Wait for output from ispell process, or TIMEOUT-SECS and TIMEOUT-MSECS.
1584 If asynchronous subprocesses are not supported, call `ispell-filter' and
1585 pass it the output of the last ispell invocation."
1586 (if ispell-async-processp
1587 (accept-process-output ispell-process timeout-secs timeout-msecs)
1588 (if (null ispell-process)
1589 (error "No Ispell process to read output from!")
1590 (let ((buf ispell-output-buffer)
1592 (if (not (bufferp buf))
1593 (setq ispell-filter nil)
1594 (with-current-buffer buf
1595 (setq ispell-output (buffer-substring-no-properties
1596 (point-min) (point-max))))
1597 (ispell-filter t ispell-output)
1598 (with-current-buffer buf
1599 (erase-buffer)))))))
1601 (defun ispell-send-replacement (misspelled replacement)
1602 "Notify aspell that MISSPELLED should be spelled REPLACEMENT.
1603 This allows it to improve the suggestion list based on actual misspellings."
1604 (and ispell-really-aspell
1605 (ispell-send-string (concat "$$ra " misspelled "," replacement "\n"))))
1608 (defun ispell-send-string (string)
1609 "Send the string STRING to the Ispell process."
1610 (if ispell-async-processp
1611 (process-send-string ispell-process string)
1612 ;; Asynchronous subprocesses aren't supported on this losing system.
1613 ;; We keep all the directives passed to Ispell during the entire
1614 ;; session in a buffer, and pass them anew each time we invoke
1615 ;; Ispell to process another chunk of text. (Yes, I know this is a
1616 ;; terrible kludge, and it's a bit slow, but it does get the work done.)
1617 (let ((cmd (aref string 0))
1618 ;; The following commands are not passed to Ispell until
1619 ;; we have a *real* reason to invoke it.
1620 (cmds-to-defer '(?* ?@ ?~ ?+ ?- ?! ?%))
1621 (session-buf ispell-session-buffer)
1622 (output-buf ispell-output-buffer)
1623 (ispell-args ispell-cmd-args)
1624 (defdir ispell-process-directory)
1626 (with-current-buffer session-buf
1627 (setq prev-pos (point))
1628 (setq default-directory defdir)
1630 (if (not (memq cmd cmds-to-defer))
1631 (let (coding-system-for-read coding-system-for-write status)
1632 (if (and (boundp 'enable-multibyte-characters)
1633 enable-multibyte-characters)
1634 (setq coding-system-for-read (ispell-get-coding-system)
1635 coding-system-for-write (ispell-get-coding-system)))
1636 (set-buffer output-buf)
1638 (set-buffer session-buf)
1640 (apply 'ispell-call-process-region
1641 (point-min) (point-max)
1642 ispell-program-name nil
1645 ;; hunspell -m option means something different
1646 (if ispell-really-hunspell "" "-m")
1648 (set-buffer output-buf)
1649 (goto-char (point-min))
1651 (if (not (looking-at "@(#) "))
1652 (error "Ispell error: %s"
1653 (buffer-substring-no-properties
1654 (point) (progn (end-of-line) (point)))))
1655 ;; If STRING is "^Z\n", we just started Ispell and need
1656 ;; to retain its version ID line in the output buffer.
1657 ;; Otherwise, remove the ID line, as it will confuse
1659 (or (string= string "\032\n")
1662 (delete-region (point-min) (point))))
1663 ;; If STRING begins with ^ or any normal character, we need
1664 ;; to remove the last line from the session buffer, since it
1665 ;; was just spell-checked, and we don't want to check it again.
1666 ;; The same goes for the # command, since Ispell already saved
1667 ;; the personal dictionary.
1668 (set-buffer session-buf)
1669 (delete-region prev-pos (point))
1670 ;; Ispell run synchronously saves the personal dictionary
1671 ;; after each successful command. So we can remove any
1672 ;; lines in the session buffer that insert words into the
1674 (if (memq status '(0 nil))
1675 (let ((more-lines t))
1676 (goto-char (point-min))
1678 (if (looking-at "^\\*")
1679 (let ((start (point)))
1681 (delete-region start (point)))
1682 (setq more-lines (= 0 (forward-line))))))))))))))
1686 (defun ispell-word (&optional following quietly continue region)
1687 "Check spelling of word under or before the cursor.
1688 If the word is not found in dictionary, display possible corrections
1689 in a window allowing you to choose one.
1691 If optional argument FOLLOWING is non-nil or if `ispell-following-word'
1692 is non-nil when called interactively, then the following word
1693 \(rather than preceding\) is checked when the cursor is not over a word.
1694 When the optional argument QUIETLY is non-nil or `ispell-quietly' is non-nil
1695 when called interactively, non-corrective messages are suppressed.
1697 With a prefix argument (or if CONTINUE is non-nil),
1698 resume interrupted spell-checking of a buffer or region.
1700 Interactively, in Transient Mark mode when the mark is active, call
1701 `ispell-region' to check the active region for spelling errors.
1703 Word syntax is controlled by the definition of the chosen dictionary,
1704 which is in `ispell-local-dictionary-alist' or `ispell-dictionary-alist'.
1706 This will check or reload the dictionary. Use \\[ispell-change-dictionary]
1707 or \\[ispell-region] to update the Ispell process.
1710 nil word is correct or spelling is accepted.
1711 0 word is inserted into buffer-local definitions.
1712 \"word\" word corrected from word list.
1713 \(\"word\" arg\) word is hand entered.
1714 quit spell session exited."
1715 (interactive (list ispell-following-word ispell-quietly current-prefix-arg t))
1718 (if (featurep 'emacs)
1720 (and (boundp 'transient-mark-mode) transient-mark-mode
1721 (boundp 'mark-active) mark-active
1722 (not (eq (region-beginning) (region-end))))))
1723 (ispell-region (region-beginning) (region-end)))
1724 (continue (ispell-continue))
1726 (ispell-set-spellchecker-params) ; Initialize variables and dicts alists
1727 (ispell-accept-buffer-local-defs) ; use the correct dictionary
1728 (let ((cursor-location (point)) ; retain cursor location
1729 (word (ispell-get-word following))
1730 start end poss new-word replace)
1731 ;; De-structure return word info list.
1732 (setq start (car (cdr word))
1733 end (car (cdr (cdr word)))
1736 ;; At this point it used to ignore 2-letter words.
1737 ;; But that is silly; if the user asks for it, we should do it. - rms.
1739 (message "Checking spelling of %s..."
1740 (funcall ispell-format-word-function word)))
1741 (ispell-send-string "%\n") ; put in verbose mode
1742 (ispell-send-string (concat "^" word "\n"))
1743 ;; wait until ispell has processed word
1745 (ispell-accept-output)
1746 (not (string= "" (car ispell-filter)))))
1747 ;;(ispell-send-string "!\n") ;back to terse mode.
1748 (setq ispell-filter (cdr ispell-filter)) ; remove extra \n
1749 (if (and ispell-filter (listp ispell-filter))
1750 (if (> (length ispell-filter) 1)
1751 (error "Ispell and its process have different character maps")
1752 (setq poss (ispell-parse-output (car ispell-filter)))))
1755 (message "%s is correct"
1756 (funcall ispell-format-word-function word)))
1757 (and (featurep 'xemacs)
1759 (and (fboundp 'delete-extent)
1760 (delete-extent (extent-at start)))))
1763 (message "%s is correct because of root %s"
1764 (funcall ispell-format-word-function word)
1765 (funcall ispell-format-word-function poss)))
1766 (and (featurep 'xemacs)
1768 (and (fboundp 'delete-extent)
1769 (delete-extent (extent-at start)))))
1771 (message "Error checking word %s using %s with %s dictionary"
1772 (funcall ispell-format-word-function word)
1773 (file-name-nondirectory ispell-program-name)
1774 (or ispell-current-dictionary "default")))
1775 (ispell-check-only ; called from ispell minor mode.
1776 (if (fboundp 'make-extent)
1777 (if (fboundp 'set-extent-property)
1778 (let ((ext (make-extent start end)))
1779 (set-extent-property ext 'face ispell-highlight-face)
1780 (set-extent-property ext 'priority 2000)))
1782 (message "%s is incorrect"
1783 (funcall ispell-format-word-function word))))
1784 (t ; prompt for correct word.
1785 (save-window-excursion
1786 (setq replace (ispell-command-loop
1787 (car (cdr (cdr poss)))
1788 (car (cdr (cdr (cdr poss))))
1789 (car poss) start end)))
1790 (cond ((equal 0 replace)
1791 (ispell-add-per-file-word-list (car poss)))
1793 (setq new-word (if (atom replace) replace (car replace))
1794 cursor-location (+ (- (length word) (- end start))
1796 (if (not (equal new-word (car poss)))
1799 ;; Insert first and then delete,
1800 ;; to avoid collapsing markers before and after
1801 ;; into a single place.
1803 (delete-region (point) end)
1804 ;; It is meaningless to preserve the cursor position
1805 ;; inside a word that has changed.
1806 (setq cursor-location (point))
1807 (setq end (point))))
1808 (if (not (atom replace)) ;recheck spelling of replacement
1810 (if (car (cdr replace)) ; query replace requested
1811 (save-window-excursion
1812 (query-replace word new-word t)))
1814 ;; single word could be split into multiple words
1815 (setq ispell-quit (not (ispell-region start end)))
1817 ;; keep if rechecking word and we keep choices win.
1818 (if (get-buffer ispell-choices-buffer)
1819 (kill-buffer ispell-choices-buffer))))
1820 (ispell-pdict-save ispell-silently-savep)
1821 ;; NB: Cancels ispell-quit incorrectly if called from ispell-region
1822 (if ispell-quit (setq ispell-quit nil replace 'quit))
1823 (goto-char cursor-location) ; return to original location
1827 (defun ispell-get-word (following &optional extra-otherchars)
1828 "Return the word for spell-checking according to ispell syntax.
1829 If optional argument FOLLOWING is non-nil or if `ispell-following-word'
1830 is non-nil when called interactively, then the following word
1831 \(rather than preceding\) is checked when the cursor is not over a word.
1832 Optional second argument contains otherchars that can be included in word
1833 many times (see the doc string of `ispell-dictionary-alist' for details
1836 Word syntax is controlled by the definition of the chosen dictionary,
1837 which is in `ispell-local-dictionary-alist' or `ispell-dictionary-alist'."
1838 (ispell-set-spellchecker-params) ; Initialize variables and dicts alists
1839 (let* ((ispell-casechars (ispell-get-casechars))
1840 (ispell-not-casechars (ispell-get-not-casechars))
1841 (ispell-otherchars (ispell-get-otherchars))
1842 (ispell-many-otherchars-p (ispell-get-many-otherchars-p))
1843 (word-regexp (concat ispell-casechars
1845 (if (not (string= "" ispell-otherchars))
1846 (concat ispell-otherchars "?"))
1847 (if extra-otherchars
1848 (concat extra-otherchars "?"))
1851 (if (or ispell-many-otherchars-p
1857 (if (not (looking-at ispell-casechars))
1859 (re-search-forward ispell-casechars (point-max) t)
1860 (re-search-backward ispell-casechars (point-min) t)))
1861 ;; move to front of word
1862 (re-search-backward ispell-not-casechars (point-min) 'start)
1863 (while (and (or (and (not (string= "" ispell-otherchars))
1864 (looking-at ispell-otherchars))
1865 (and extra-otherchars (looking-at extra-otherchars)))
1867 (or (not did-it-once)
1868 ispell-many-otherchars-p)
1869 (not (eq prevpt (point))))
1870 (if (and extra-otherchars (looking-at extra-otherchars))
1873 (if (looking-at ispell-casechars)
1874 (re-search-backward ispell-not-casechars (point-min) 'move)))
1878 (if (looking-at ispell-casechars)
1879 (re-search-backward ispell-not-casechars (point-min) 'move)
1880 (backward-char -1))))
1881 ;; Now mark the word and save to string.
1882 (if (not (re-search-forward word-regexp (point-max) t))
1883 (if ispell-check-only
1884 ;; return dummy word when just flagging misspellings
1885 (list "" (point) (point))
1886 (error "No word found to check!"))
1887 (setq start (copy-marker (match-beginning 0))
1889 word (buffer-substring-no-properties start end))
1890 (list word start end))))
1893 ;; Global ispell-pdict-modified-p is set by ispell-command-loop and
1894 ;; tracks changes in the dictionary. The global may either be
1895 ;; a value or a list, whose value is the state of whether the
1896 ;; dictionary needs to be saved.
1899 (defun ispell-pdict-save (&optional no-query force-save)
1900 "Check to see if the personal dictionary has been modified.
1901 If so, ask if it needs to be saved."
1902 (interactive (list ispell-silently-savep t))
1903 (if (and ispell-pdict-modified-p (listp ispell-pdict-modified-p))
1904 (setq ispell-pdict-modified-p (car ispell-pdict-modified-p)))
1905 (if (or ispell-pdict-modified-p force-save)
1906 (if (or no-query (y-or-n-p "Personal dictionary modified. Save? "))
1908 (ispell-send-string "#\n") ; save dictionary
1909 (message "Personal dictionary saved."))))
1910 ;; unassert variable, even if not saved to avoid questioning.
1911 (setq ispell-pdict-modified-p nil))
1914 (defun ispell-command-loop (miss guess word start end)
1915 "Display possible corrections from list MISS.
1916 GUESS lists possibly valid affix construction of WORD.
1917 Returns nil to keep word.
1918 Returns 0 to insert locally into buffer-local dictionary.
1919 Returns string for new chosen word.
1920 Returns list for new replacement word (will be rechecked).
1921 Query-replace when list length is 2.
1922 Automatic query-replace when second element is `query-replace'.
1923 Highlights the word, which is assumed to run from START to END.
1924 Global `ispell-pdict-modified-p' becomes a list where the only value
1925 indicates whether the dictionary has been modified when option `a'
1927 Global `ispell-quit' set to start location to continue spell session."
1929 (line ispell-choices-win-default-height)
1930 ;; ensure 4 context lines.
1931 (max-lines (- (ispell-adjusted-window-height) 4))
1933 (window-min-height (min window-min-height
1934 ispell-choices-win-default-height))
1935 (command-characters '( ? ?i ?a ?A ?r ?R ?? ?x ?X ?q ?l ?u ?m ))
1936 (dedicated (window-dedicated-p (selected-window)))
1938 char num result textwin dedicated-win)
1940 ;; setup the *Choices* buffer with valid data.
1941 (with-current-buffer (get-buffer-create ispell-choices-buffer)
1942 (setq mode-line-format
1944 "-- %b -- word: " word
1945 " -- dict: " (or ispell-current-dictionary "default")
1946 " -- prog: " (file-name-nondirectory ispell-program-name)))
1947 ;; XEmacs: no need for horizontal scrollbar in choices window
1948 (ispell-with-no-warnings
1949 (and (fboundp 'set-specifier)
1950 (boundp 'horizontal-scrollbar-visible-p)
1951 (set-specifier horizontal-scrollbar-visible-p nil
1952 (cons (current-buffer) nil))))
1956 (insert "Affix rules generate and capitalize "
1957 "this word as shown below:\n\t")
1959 (if (> (+ 4 (current-column) (length (car guess)))
1963 (setq line (1+ line))))
1964 (insert (car guess) " ")
1965 (setq guess (cdr guess)))
1966 (insert "\nUse option `i' to accept this spelling and put it in your private dictionary.\n")
1967 (setq line (+ line (if choices 3 2)))))
1969 (< (if (> (+ 7 (current-column) (length (car choices))
1970 (if (> count ?~) 3 0))
1974 (setq line (1+ line)))
1977 ;; not so good if there are over 20 or 30 options, but then, if
1978 ;; there are that many you don't want to scan them all anyway...
1979 (while (memq count command-characters) ; skip command characters.
1980 (setq count (ispell-int-char (1+ count))
1981 skipped (1+ skipped)))
1982 (insert "(" count ") " (car choices) " ")
1983 (setq choices (cdr choices)
1984 count (ispell-int-char (1+ count))))
1985 (setq count (ispell-int-char (- count ?0 skipped))))
1987 ;; ensure word is visible
1988 (if (not (pos-visible-in-window-p end))
1991 ;; allow temporary split of dedicated windows...
1994 (setq dedicated-win (selected-window))
1995 (set-window-dedicated-p dedicated-win nil)))
1997 ;; Display choices for misspelled word.
1998 (ispell-show-choices line end)
1999 (select-window (setq textwin (next-window)))
2001 ;; highlight word, protecting current buffer status
2004 (and ispell-highlight-p
2005 (ispell-highlight-spelling-error start end t))
2006 ;; Loop until a valid choice is made.
2014 (let (message-log-max)
2015 (message (concat "C-h or ? for more options; SPC to leave "
2016 "unchanged, Character to replace word")))
2017 (let ((inhibit-quit t)
2019 (setq char nil skipped 0)
2020 ;; If the user types C-g, or generates some other
2021 ;; non-character event (such as a frame switch
2022 ;; event), stop ispell. As a special exception,
2023 ;; ignore mouse events occurring in the same frame.
2024 (while (and input-valid (not (characterp char)))
2025 (setq char (read-key))
2027 (or (characterp char)
2028 (and (mouse-event-p char)
2029 (eq (selected-frame)
2031 (posn-window (event-start char))))))))
2032 (when (or quit-flag (not input-valid) (= char ?\C-g))
2033 (setq char ?X quit-flag nil)))
2034 ;; Adjust num to array offset skipping command characters.
2035 (let ((com-chars command-characters))
2037 (if (and (> (car com-chars) ?0) (< (car com-chars) char))
2038 (setq skipped (1+ skipped)))
2039 (setq com-chars (cdr com-chars)))
2040 (setq num (- char ?0 skipped)))
2043 ((= char ? ) nil) ; accept word this time only
2044 ((= char ?i) ; accept and insert word into pers dict
2045 (ispell-send-string (concat "*" word "\n"))
2046 (setq ispell-pdict-modified-p '(t)) ; dictionary modified!
2048 ((or (= char ?a) (= char ?A)) ; accept word without insert
2049 (ispell-send-string (concat "@" word "\n"))
2050 (add-to-list 'ispell-buffer-session-localwords word)
2051 (or ispell-buffer-local-name ; session localwords might conflict
2052 (setq ispell-buffer-local-name (buffer-name)))
2053 (if (null ispell-pdict-modified-p)
2054 (setq ispell-pdict-modified-p
2055 (list ispell-pdict-modified-p)))
2056 (if (= char ?A) 0)) ; return 0 for ispell-add buffer-local
2057 ((or (= char ?r) (= char ?R)) ; type in replacement
2058 (and (eq 'block ispell-highlight-p) ; refresh tty's
2059 (ispell-highlight-spelling-error start end nil t))
2061 (if (or (= char ?R) ispell-query-replace-choices)
2063 (format "Query-replacement for %s: "word)
2066 (cons (read-string "Replacement for: " word)
2068 (and (eq 'block ispell-highlight-p)
2069 (ispell-highlight-spelling-error start end nil
2072 ((or (= char ??) (= char help-char) (= char ?\C-h))
2073 (and (eq 'block ispell-highlight-p)
2074 (ispell-highlight-spelling-error start end nil t))
2076 (and (eq 'block ispell-highlight-p)
2077 (ispell-highlight-spelling-error start end nil
2080 ;; Quit and move point back.
2082 (ispell-pdict-save ispell-silently-savep)
2083 (message "Exited spell-checking")
2084 (setq ispell-quit t)
2086 ;; Quit and preserve point.
2088 (ispell-pdict-save ispell-silently-savep)
2090 (substitute-command-keys
2091 (concat "Spell-checking suspended;"
2092 " use C-u \\[ispell-word] to resume")))
2093 (setq ispell-quit start)
2096 (if (y-or-n-p "Really kill Ispell process? ")
2098 (ispell-kill-ispell t) ; terminate process.
2099 (setq ispell-quit (or (not ispell-checking-message)
2101 ispell-pdict-modified-p nil))
2102 t)) ; continue if they don't quit.
2104 (and (eq 'block ispell-highlight-p) ; refresh tty displays
2105 (ispell-highlight-spelling-error start end nil t))
2106 (let ((new-word (read-string
2107 "Lookup string (`*' is wildcard): "
2111 (with-current-buffer (get-buffer-create
2112 ispell-choices-buffer)
2116 mode-line-format ;; setup the *Choices* buffer with valid data.
2117 (concat "-- %b -- word: " new-word
2119 (or ispell-complete-word-dict
2120 ispell-alternate-dictionary))
2121 miss (lookup-words new-word)
2123 line ispell-choices-win-default-height)
2124 (while (and choices ; adjust choices window.
2125 (< (if (> (+ 7 (current-column)
2126 (length (car choices))
2127 (if (> count ?~) 3 0))
2131 (setq line (1+ line)))
2134 (while (memq count command-characters)
2135 (setq count (ispell-int-char (1+ count))
2136 skipped (1+ skipped)))
2137 (insert "(" count ") " (car choices) " ")
2138 (setq choices (cdr choices)
2139 count (ispell-int-char (1+ count))))
2140 (setq count (ispell-int-char
2141 (- count ?0 skipped))))
2142 (ispell-show-choices line end)
2143 (select-window (next-window)))))
2144 (and (eq 'block ispell-highlight-p)
2145 (ispell-highlight-spelling-error start end nil
2147 t) ; reselect from new choices
2148 ((= char ?u) ; insert lowercase into dictionary
2149 (ispell-send-string (concat "*" (downcase word) "\n"))
2150 (setq ispell-pdict-modified-p '(t)) ; dictionary modified!
2152 ((= char ?m) ; type in what to insert
2154 (concat "*" (read-string "Insert: " word) "\n"))
2155 (setq ispell-pdict-modified-p '(t))
2157 ((and (>= num 0) (< num count))
2158 (if ispell-query-replace-choices ; Query replace flag
2159 (list (nth num miss) 'query-replace)
2164 ;; This may have alignment errors if current line is edited
2165 (if (marker-position ispell-recursive-edit-marker)
2167 (message "Only one recursive edit session supported")
2170 (set-marker ispell-recursive-edit-marker start)
2171 ;;(set-marker ispell-region-end reg-end)
2172 (and ispell-highlight-p ; unhighlight
2173 (ispell-highlight-spelling-error start end))
2178 (substitute-command-keys
2179 (concat "Exit recursive edit with"
2180 " \\[exit-recursive-edit]")))
2181 (save-window-excursion (save-excursion
2184 (goto-char ispell-recursive-edit-marker)
2185 (if (not (equal (marker-buffer
2186 ispell-recursive-edit-marker)
2189 (set-marker ispell-recursive-edit-marker nil)
2191 "Cannot continue ispell from this buffer.")))
2192 (set-marker ispell-recursive-edit-marker nil)))
2193 (list word nil)) ; recheck starting at this word.
2195 (funcall (key-binding "\C-z"))
2200 (and ispell-highlight-p ; unhighlight
2201 (save-window-excursion
2202 (select-window textwin)
2203 (ispell-highlight-spelling-error start end)))
2205 (set-window-dedicated-p dedicated-win t)))))
2209 (defun ispell-show-choices (line end)
2210 "Show the choices in another buffer or frame."
2211 (if (and ispell-use-framepop-p (fboundp 'framepop-display-buffer))
2213 (framepop-display-buffer (get-buffer ispell-choices-buffer))
2214 ;; (get-buffer-window ispell-choices-buffer t)
2215 (select-window (previous-window))) ; *Choices* window
2216 ;; standard selection by splitting a small buffer out of this window.
2217 (let ((choices-window (get-buffer-window ispell-choices-buffer)))
2219 (if (= line (ispell-adjusted-window-height choices-window))
2220 (select-window choices-window)
2221 ;; *Choices* window changed size. Adjust the choices window
2222 ;; without scrolling the spelled window when possible
2224 (- line (ispell-adjusted-window-height choices-window)))
2225 (visible (progn (vertical-motion -1) (point))))
2226 (if (< line ispell-choices-win-default-height)
2227 (setq window-line (+ window-line
2228 (- ispell-choices-win-default-height
2230 (move-to-window-line 0)
2231 (vertical-motion window-line)
2232 (set-window-start (selected-window)
2233 (if (> (point) visible) visible (point)))
2235 (select-window choices-window)
2236 (enlarge-window window-line)))
2237 ;; Overlay *Choices* window when it isn't showing
2238 (ispell-overlay-window (max line ispell-choices-win-default-height)))
2239 (switch-to-buffer ispell-choices-buffer)
2240 (goto-char (point-min)))))
2244 (defun ispell-help ()
2245 "Display a list of the options available when a misspelling is encountered.
2249 DIGIT: Replace the word with a digit offered in the *Choices* buffer.
2250 SPC: Accept word this time.
2251 `i': Accept word and insert into private dictionary.
2252 `a': Accept word for this session.
2253 `A': Accept word and place in `buffer-local dictionary'.
2254 `r': Replace word with typed-in value. Rechecked.
2255 `R': Replace word with typed-in value. Query-replaced in buffer. Rechecked.
2256 `?': Show these commands.
2257 `x': Exit spelling buffer. Move cursor to original point.
2258 `X': Exit spelling buffer. Leaves cursor at the current point, and permits
2259 the aborted check to be completed later.
2260 `q': Quit spelling session (Kills ispell process).
2261 `l': Look up typed-in replacement in alternate dictionary. Wildcards okay.
2262 `u': Like `i', but the word is lower-cased first.
2263 `m': Place typed-in value in personal dictionary, then recheck current word.
2264 `C-l': Redraw screen.
2265 `C-r': Recursive edit.
2266 `C-z': Suspend Emacs or iconify frame."
2268 (if (equal ispell-help-in-bufferp 'electric)
2272 (function (lambda ()
2273 ;;This shouldn't be necessary: with-electric-help needs
2274 ;; an optional argument telling it about the smallest
2275 ;; acceptable window-height of the help buffer.
2276 ;;(if (< (window-height) 15)
2278 ;; (- 15 (ispell-adjusted-window-height))))
2279 (princ "Selections are:
2281 DIGIT: Replace the word with a digit offered in the *Choices* buffer.
2282 SPC: Accept word this time.
2283 `i': Accept word and insert into private dictionary.
2284 `a': Accept word for this session.
2285 `A': Accept word and place in `buffer-local dictionary'.
2286 `r': Replace word with typed-in value. Rechecked.
2287 `R': Replace word with typed-in value. Query-replaced in buffer. Rechecked.
2288 `?': Show these commands.
2289 `x': Exit spelling buffer. Move cursor to original point.
2290 `X': Exit spelling buffer. Leaves cursor at the current point, and permits
2291 the aborted check to be completed later.
2292 `q': Quit spelling session (Kills ispell process).
2293 `l': Look up typed-in replacement in alternate dictionary. Wildcards okay.
2294 `u': Like `i', but the word is lower-cased first.
2295 `m': Place typed-in value in personal dictionary, then recheck current word.
2296 `C-l': Redraw screen.
2297 `C-r': Recursive edit.
2298 `C-z': Suspend Emacs or iconify frame.")
2302 (let ((help-1 (concat "[r/R]eplace word; [a/A]ccept for this session; "
2303 "[i]nsert into private dictionary"))
2304 (help-2 (concat "[l]ook a word up in alternate dictionary; "
2305 "e[x/X]it; [q]uit session"))
2306 (help-3 (concat "[u]ncapitalized insert into dict. "
2307 "Type 'x C-h f ispell-help' for more help")))
2308 (save-window-excursion
2309 (if ispell-help-in-bufferp
2311 (ispell-overlay-window 4)
2312 (switch-to-buffer (get-buffer-create "*Ispell Help*"))
2313 (insert (concat help-1 "\n" help-2 "\n" help-3))
2315 (kill-buffer "*Ispell Help*"))
2317 (let ((resize-mini-windows 'grow-only))
2318 (select-window (minibuffer-window))
2321 ;;(set-minibuffer-window (selected-window))
2323 (insert (concat help-1 "\n" help-2 "\n" help-3))
2325 (erase-buffer)))))))
2328 (defun lookup-words (word &optional lookup-dict)
2329 "Look up WORD in optional word-list dictionary LOOKUP-DICT.
2330 A `*' serves as a wild card. If no wild cards, `look' is used if it exists.
2331 Otherwise the variable `ispell-grep-command' contains the command used to
2332 search for the words (usually egrep).
2334 Optional second argument contains the dictionary to use; the default is
2335 `ispell-alternate-dictionary', overridden by `ispell-complete-word-dict'
2337 ;; We don't use the filter for this function, rather the result is written
2338 ;; into a buffer. Hence there is no need to save the filter values.
2339 (if (null lookup-dict)
2340 (setq lookup-dict (or ispell-complete-word-dict
2341 ispell-alternate-dictionary)))
2344 (unless (file-readable-p lookup-dict)
2345 (error "lookup-words error: Unreadable or missing plain word-list %s."
2347 (error (concat "lookup-words error: No plain word-list found at system"
2348 "default locations. "
2349 "Customize `ispell-alternate-dictionary' to set yours.")))
2351 (let* ((process-connection-type ispell-use-ptys-p)
2352 (wild-p (string-match "\\*" word))
2353 (look-p (and ispell-look-p ; Only use look for an exact match.
2354 (or ispell-have-new-look (not wild-p))))
2355 (prog (if look-p ispell-look-command ispell-grep-command))
2356 (args (if look-p ispell-look-options ispell-grep-options))
2359 (message "Starting \"%s\" process..." (file-name-nondirectory prog))
2363 (insert "^" word "$")
2364 (while (search-backward "*" nil t) (insert "."))
2365 (setq word (buffer-string))
2367 (setq status (apply 'ispell-call-process prog nil t nil
2368 (nconc (if (and args (> (length args) 0))
2373 (if lookup-dict (list lookup-dict)))))
2374 ;; `grep' returns status 1 and no output when word not found, which
2375 ;; is a perfectly normal thing.
2376 (if (stringp status)
2377 (error "error: %s exited with signal %s"
2378 (file-name-nondirectory prog) status)
2379 ;; Else collect words into `results' in FIFO order.
2380 (goto-char (point-max))
2381 ;; Assure we've ended with \n.
2382 (or (bobp) (= (preceding-char) ?\n) (insert ?\n))
2386 (push (buffer-substring-no-properties (point)
2389 (if (and results (string-match ".+: " (car results)))
2390 (error "%s error: %s" ispell-grep-command (car results)))
2394 ;; "ispell-filter" is a list of output lines from the generating function.
2395 ;; Each full line (ending with \n) is a separate item on the list.
2396 ;; "output" can contain multiple lines, part of a line, or both.
2397 ;; "start" and "end" are used to keep bounds on lines when "output" contains
2399 ;; "ispell-filter-continue" is true when we have received only part of a
2400 ;; line as output from a generating function ("output" did not end with \n)
2401 ;; THIS FUNCTION WILL FAIL IF THE PROCESS OUTPUT DOESN'T END WITH \n!
2402 ;; This is the case when a process dies or fails. The default behavior
2403 ;; in this case treats the next input received as fresh input.
2405 (defun ispell-filter (process output)
2406 "Output filter function for ispell, grep, and look."
2411 (setq end (string-match "\n" output start)) ; get text up to the newline.
2412 ;; If we get out of sync and ispell-filter-continue is asserted when we
2413 ;; are not continuing, treat the next item as a separate list. When
2414 ;; ispell-filter-continue is asserted, ispell-filter *should* always be a
2417 ;; Continue with same line (item)?
2418 (if (and ispell-filter-continue ispell-filter (listp ispell-filter))
2419 ;; Yes. Add it to the prev item
2420 (setcar ispell-filter
2421 (concat (car ispell-filter) (substring output start end)))
2422 ;; No. This is a new line and item.
2424 (cons (substring output start end) ispell-filter)))
2426 ;; We've completed reading the output, but didn't finish the line.
2427 (setq ispell-filter-continue t continue nil)
2428 ;; skip over newline, this line complete.
2429 (setq ispell-filter-continue nil end (1+ end))
2430 (if (= end (length output)) ; No more lines in output
2431 (setq continue nil) ; so we can exit the filter.
2432 (setq start end)))))) ; else move start to next line of input
2435 ;; This function destroys the mark location if it is in the word being
2437 (defun ispell-highlight-spelling-error-generic (start end &optional highlight
2439 "Highlight the word from START to END with a kludge using `inverse-video'.
2440 When the optional third arg HIGHLIGHT is set, the word is highlighted;
2441 otherwise it is displayed normally.
2442 Uses block cursor to highlight one character.
2443 Optional REFRESH will unhighlighted then highlight, using block cursor
2444 highlighting when REFRESH is equal to `block'."
2445 (and (eq 'block ispell-highlight-p)
2446 (or (eq 'block refresh)
2447 (setq start (1+ start)))) ; On block non-refresh, inc start.
2448 (let ((modified (buffer-modified-p)) ; don't allow this fn to modify buffer
2449 (buffer-read-only nil) ; Allow highlighting read-only buffers.
2450 (text (buffer-substring-no-properties start end))
2451 ; Save highlight region.
2452 (inhibit-quit t) ; inhibit interrupt processing here.
2453 (buffer-undo-list t)) ; don't clutter the undo list.
2455 (delete-region start end)
2456 (insert-char ? (- end start)) ; minimize amount of redisplay
2457 (sit-for 0) ; update display
2458 (if highlight (setq inverse-video (not inverse-video))) ; toggle video
2459 (delete-region start end) ; delete whitespace
2460 (insert text) ; insert text in inverse video.
2461 (sit-for 0) ; update display showing inverse video.
2464 (setq inverse-video (not inverse-video)) ; toggle video
2465 (and (eq 'block ispell-highlight-p)
2466 (goto-char (1- start)))) ; use block cursor to "highlight" char
2467 (set-buffer-modified-p modified) ; don't modify if flag not set.
2468 (and refresh ; re-highlight
2469 (ispell-highlight-spelling-error-generic
2470 (if (eq 'block refresh) start (- start 2)) end t))))
2473 (defun ispell-highlight-spelling-error-xemacs (start end &optional highlight)
2474 "Highlight the word from START to END using `isearch-highlight'.
2475 When the optional third arg HIGHLIGHT is set, the word is highlighted,
2476 otherwise it is displayed normally."
2478 (isearch-highlight start end)
2479 (isearch-dehighlight))
2484 (defun ispell-highlight-spelling-error-overlay (start end &optional highlight)
2485 "Highlight the word from START to END using overlays.
2486 When the optional third arg HIGHLIGHT is set, the word is highlighted
2487 otherwise it is displayed normally.
2489 The variable `ispell-highlight-face' selects the face to use for highlighting."
2492 (move-overlay ispell-overlay start end (current-buffer))
2493 (setq ispell-overlay (make-overlay start end))
2494 (overlay-put ispell-overlay 'priority 1001) ;higher than lazy overlays
2495 (overlay-put ispell-overlay 'face ispell-highlight-face))
2497 (delete-overlay ispell-overlay)))
2498 (if (and ispell-lazy-highlight (boundp 'lazy-highlight-cleanup))
2500 (let ((isearch-string
2503 (regexp-quote (buffer-substring-no-properties start end))
2506 (isearch-case-fold-search nil))
2507 (isearch-lazy-highlight-new-loop
2508 (if (boundp 'reg-start) reg-start)
2509 (if (boundp 'reg-end) reg-end)))
2510 (lazy-highlight-cleanup lazy-highlight-cleanup)
2511 (setq isearch-lazy-highlight-last-string nil))))
2514 (defun ispell-highlight-spelling-error (start end &optional highlight refresh)
2517 (ispell-highlight-spelling-error-xemacs start end highlight))
2518 ((and (featurep 'faces)
2519 (or (and (fboundp 'display-color-p) (display-color-p))
2521 (ispell-highlight-spelling-error-overlay start end highlight))
2522 (t (ispell-highlight-spelling-error-generic start end highlight refresh))))
2524 (defun ispell-adjusted-window-height (&optional window)
2525 "Like `window-height', adjusted to correct for the effect of tall mode-lines.
2526 The value returned is actually the nominal number of text-lines in the
2527 window plus 1. On a terminal, this is the same value returned by
2528 `window-height', but if the window has a mode-line is taller than a normal
2529 text line, the returned value may be smaller than that from
2531 (cond ((fboundp 'window-text-height)
2532 (1+ (window-text-height window)))
2533 ((or (and (fboundp 'display-graphic-p) (display-graphic-p))
2534 (and (featurep 'xemacs) window-system))
2535 (1- (window-height window)))
2537 (window-height window))))
2539 (defun ispell-overlay-window (height)
2540 "Create a window covering the top HEIGHT lines of the current window.
2541 Ensure that the line above point is still visible but otherwise avoid
2542 scrolling the current window. Leave the new window selected."
2544 (let ((oldot (save-excursion (vertical-motion -1) (point)))
2545 (top (save-excursion (move-to-window-line height) (point))))
2546 ;; If line above old point (line starting at oldot) would be
2547 ;; hidden by new window, scroll it to just below new win
2548 ;; otherwise set top line of other win so it doesn't scroll.
2549 (if (< oldot top) (setq top oldot))
2550 ;; if frame is unsplittable, temporarily disable that...
2551 (if (cdr (assq 'unsplittable (frame-parameters (selected-frame))))
2552 (let ((frame (selected-frame)))
2553 (modify-frame-parameters frame '((unsplittable . nil)))
2554 (split-window nil height)
2555 (modify-frame-parameters frame '((unsplittable . t))))
2556 (split-window nil height))
2557 (let ((deficit (- height (ispell-adjusted-window-height))))
2559 ;; Number of lines the window is still too short. We ensure that
2560 ;; there are at least (1- HEIGHT) lines visible in the window.
2561 (enlarge-window deficit)
2563 (vertical-motion deficit)
2564 (setq top (min (point) oldot))))
2565 (set-window-start (next-window) top))))
2568 ;; Should we add a compound word match return value?
2569 (defun ispell-parse-output (output &optional accept-list shift)
2570 "Parse the OUTPUT string from Ispell process and return:
2571 1: t for an exact match.
2572 2: A string containing the root word matched via suffix removal.
2573 3: A list of possible correct spellings of the format:
2574 (\"ORIGINAL-WORD\" OFFSET MISS-LIST GUESS-LIST)
2575 ORIGINAL-WORD is a string of the possibly misspelled word.
2576 OFFSET is an integer giving the line offset of the word.
2577 MISS-LIST and GUESS-LIST are possibly null lists of guesses and misses.
2578 4: nil when an error has occurred.
2580 Optional second arg ACCEPT-LIST is list of words already accepted.
2581 Optional third arg SHIFT is an offset to apply based on previous corrections."
2583 ((string= output "") t) ; for startup with pipes...
2584 ((string= output "*") t) ; exact match
2585 ((string= output "-") t) ; compound word match
2586 ((eq (aref output 0) ?+) ; found because of root word
2587 (substring output 2)) ; return root word
2588 ((equal 0 (string-match "[\ra-zA-Z]" output))
2589 (ding) ; error message from ispell!
2590 (message "Ispell error: %s" output)
2593 (t ; need to process &, ?, and #'s
2594 (let ((type (aref output 0)) ; &, ?, or #
2595 (original-word (substring output 2 (string-match " " output 2)))
2596 (cur-count 0) ; contains number of misses + guesses
2597 count miss-list guess-list offset)
2598 (setq output (substring output (match-end 0))) ; skip over misspelling
2600 (setq count 0) ; no misses for type #
2601 (setq count (string-to-number output) ; get number of misses.
2602 output (substring output (1+ (string-match " " output 1)))))
2603 (setq offset (string-to-number output))
2604 (setq output (if (eq type ?#) ; No miss or guess list.
2606 (substring output (1+ (string-match " " output 1)))))
2608 (let ((end (string-match ", \\|\\($\\)" output))) ; end of miss/guess.
2609 (setq cur-count (1+ cur-count))
2610 (if (> cur-count count)
2611 (push (substring output 0 end) guess-list)
2612 (push (substring output 0 end) miss-list))
2613 (setq output (if (match-end 1) ; True only when at end of line.
2614 nil ; No more misses or guesses.
2615 (substring output (+ end 2))))))
2616 ;; return results. Accept word if it was already accepted.
2618 (if (member original-word accept-list)
2621 (if (numberp shift) (+ shift offset) offset)
2622 (nreverse miss-list) (nreverse guess-list)))))))
2625 (defun ispell-process-status ()
2626 "Return the status of the Ispell process.
2627 When asynchronous processes are not supported, `run' is always returned."
2628 (if ispell-async-processp
2629 (process-status ispell-process)
2630 (and ispell-process 'run)))
2633 (defun ispell-start-process ()
2634 "Start the Ispell process, with support for no asynchronous processes.
2635 Keeps argument list for future Ispell invocations for no async support."
2636 ;; Local dictionary becomes the global dictionary in use.
2637 (setq ispell-current-dictionary
2638 (or ispell-local-dictionary ispell-dictionary))
2639 (setq ispell-current-personal-dictionary
2640 (or ispell-local-pdict ispell-personal-dictionary))
2641 (let* ((default-directory
2642 (if (and (file-directory-p default-directory)
2643 (file-readable-p default-directory))
2645 ;; Defend against bad `default-directory'.
2646 (expand-file-name "~/")))
2647 (orig-args (ispell-get-ispell-args))
2650 (if (and ispell-current-dictionary ; Not for default dict (nil)
2651 (not (member "-d" orig-args))) ; Only define if not overridden.
2652 (list "-d" ispell-current-dictionary))
2654 (if ispell-current-personal-dictionary ; Use specified pers dict.
2656 (expand-file-name ispell-current-personal-dictionary)))
2657 ;; If we are using recent aspell or hunspell, make sure we use the
2658 ;; right encoding for communication. ispell or older aspell/hunspell
2659 ;; does not support this.
2660 (if ispell-encoding8-command
2661 (if ispell-really-hunspell
2662 (list ispell-encoding8-command
2663 (upcase (symbol-name (ispell-get-coding-system))))
2665 (concat ispell-encoding8-command
2666 (symbol-name (ispell-get-coding-system))))))
2667 ispell-extra-args)))
2669 ;; Initially we don't know any buffer's local words.
2670 (setq ispell-buffer-local-name nil)
2672 (if ispell-async-processp
2673 (let ((process-connection-type ispell-use-ptys-p))
2674 (apply 'start-process
2675 "ispell" nil ispell-program-name
2676 "-a" ; Accept single input lines.
2677 ;; Make root/affix combos not in dict.
2678 ;; hunspell -m option means different.
2679 (if ispell-really-hunspell "" "-m")
2681 (setq ispell-cmd-args args
2682 ispell-output-buffer (generate-new-buffer " *ispell-output*")
2683 ispell-session-buffer (generate-new-buffer " *ispell-session*"))
2684 (ispell-send-string "\032\n") ; so Ispell prints version and exits
2688 (defun ispell-init-process ()
2689 "Check status of Ispell process and start if necessary."
2690 (let* (;; Basename of dictionary used by the spell-checker
2691 (dict-bname (or (car (cdr (member "-d" (ispell-get-ispell-args))))
2692 ispell-current-dictionary))
2693 ;; Use "~/" as default-directory unless using Ispell with per-dir
2694 ;; personal dictionaries and not in a minibuffer under XEmacs
2696 (if (or ispell-really-aspell
2697 ispell-really-hunspell
2698 ;; Protect against bad default-directory
2699 (not (and (file-directory-p default-directory)
2700 (file-readable-p default-directory)))
2701 ;; Ispell and per-dir personal dicts available
2702 (not (or (file-readable-p (concat default-directory
2704 (file-readable-p (concat default-directory
2708 ;; Ispell, in a minibuffer, and XEmacs
2709 (and (window-minibuffer-p)
2710 (not (fboundp 'minibuffer-selected-window))))
2711 (expand-file-name "~/")
2712 (expand-file-name default-directory))))
2713 ;; Check if process needs restart
2714 (if (and ispell-process
2715 (eq (ispell-process-status) 'run)
2716 ;; Unless we are using an explicit personal dictionary, ensure
2717 ;; we're in the same default directory! Restart check for
2718 ;; personal dictionary is done in
2719 ;; `ispell-internal-change-dictionary', called from
2720 ;; `ispell-buffer-local-dict'
2721 (or (or ispell-local-pdict ispell-personal-dictionary)
2722 (equal ispell-process-directory default-directory)))
2723 (setq ispell-filter nil ispell-filter-continue nil)
2724 ;; may need to restart to select new personal dictionary.
2725 (ispell-kill-ispell t)
2726 (message "Starting new Ispell process [%s::%s] ..."
2728 (or ispell-local-dictionary ispell-dictionary "default"))
2730 (setq ispell-library-directory (ispell-check-version)
2731 ispell-process (ispell-start-process)
2733 ispell-filter-continue nil
2734 ispell-process-directory default-directory)
2736 (unless (equal ispell-process-directory (expand-file-name "~/"))
2737 ;; At this point, `ispell-process-directory' will be "~/" unless using
2738 ;; Ispell with directory-specific dicts and not in XEmacs minibuffer.
2739 ;; If not, kill ispell process when killing buffer. It may be in a
2740 ;; removable device that would otherwise become un-mountable.
2741 (with-current-buffer
2742 (if (and (window-minibuffer-p) ;; In minibuffer
2743 (fboundp 'minibuffer-selected-window)) ;; Not XEmacs.
2744 ;; In this case kill ispell only when parent buffer is killed
2745 ;; to avoid over and over ispell kill.
2746 (window-buffer (minibuffer-selected-window))
2748 ;; 'local does not automatically make hook buffer-local in XEmacs.
2749 (if (featurep 'xemacs)
2750 (make-local-hook 'kill-buffer-hook))
2751 (add-hook 'kill-buffer-hook
2752 (lambda () (ispell-kill-ispell t)) nil 'local)))
2754 (if ispell-async-processp
2755 (set-process-filter ispell-process 'ispell-filter))
2756 ;; Protect against XEmacs bogus binding of `enable-multibyte-characters'.
2757 (if (and (or (featurep 'xemacs)
2758 (and (boundp 'enable-multibyte-characters)
2759 enable-multibyte-characters))
2760 (fboundp 'set-process-coding-system))
2761 (set-process-coding-system ispell-process (ispell-get-coding-system)
2762 (ispell-get-coding-system)))
2763 ;; Get version ID line
2764 (ispell-accept-output 3)
2765 ;; get more output if filter empty?
2766 (if (null ispell-filter) (ispell-accept-output 3))
2767 (cond ((null ispell-filter)
2768 (error "%s did not output version line" ispell-program-name))
2770 (stringp (car ispell-filter))
2771 (if (string-match "warning: " (car ispell-filter))
2773 (ispell-accept-output 3) ; was warn msg.
2774 (stringp (car ispell-filter)))
2775 (null (cdr ispell-filter)))
2776 (string-match "^@(#) " (car ispell-filter)))
2777 ;; got the version line as expected (we already know it's the right
2778 ;; version, so don't bother checking again.)
2781 ;; Otherwise, it must be an error message. Show the user.
2782 ;; But first wait to see if some more output is going to arrive.
2783 ;; Otherwise we get cool errors like "Can't open ".
2785 (ispell-accept-output 3)
2786 (error "%s" (mapconcat 'identity ispell-filter "\n"))))
2787 (setq ispell-filter nil) ; Discard version ID line
2788 (let ((extended-char-mode (ispell-get-extended-character-mode)))
2789 (if extended-char-mode ; ~ extended character mode
2790 (ispell-send-string (concat extended-char-mode "\n"))))
2791 (if ispell-async-processp
2792 (if (featurep 'emacs)
2793 (set-process-query-on-exit-flag ispell-process nil)
2794 (if (fboundp 'set-process-query-on-exit-flag)
2795 (set-process-query-on-exit-flag ispell-process nil)
2796 (process-kill-without-query ispell-process)))))))
2799 (defun ispell-kill-ispell (&optional no-error clear)
2800 "Kill current Ispell process (so that you may start a fresh one).
2801 With NO-ERROR, just return non-nil if there was no Ispell running.
2802 With CLEAR, buffer session localwords are cleaned."
2804 ;; This hook is typically used by flyspell to flush some variables used
2805 ;; to optimize the common cases.
2806 (run-hooks 'ispell-kill-ispell-hook)
2807 (if (or clear (interactive-p))
2808 (setq ispell-buffer-session-localwords nil))
2809 (if (not (and ispell-process
2810 (eq (ispell-process-status) 'run)))
2812 (error "There is no Ispell process running!"))
2813 (if ispell-async-processp
2814 (delete-process ispell-process)
2815 ;; Synchronous processes.
2816 (ispell-send-string "\n") ; Make sure side effects occurred.
2817 (kill-buffer ispell-output-buffer)
2818 (kill-buffer ispell-session-buffer)
2819 (setq ispell-output-buffer nil
2820 ispell-session-buffer nil))
2821 (setq ispell-process nil)
2822 (message "Ispell process killed")
2825 ;; ispell-change-dictionary is set in some people's hooks. Maybe this should
2826 ;; call ispell-init-process rather than wait for a spell checking command?
2829 (defun ispell-change-dictionary (dict &optional arg)
2830 "Change to dictionary DICT for Ispell.
2831 With a prefix arg, set it \"globally\", for all buffers.
2832 Without a prefix arg, set it \"locally\", just for this buffer.
2834 By just answering RET you can find out what the current dictionary is."
2836 (list (completing-read
2837 "Use new dictionary (RET for current, SPC to complete): "
2838 (and (fboundp 'ispell-valid-dictionary-list)
2839 (mapcar 'list (ispell-valid-dictionary-list)))
2841 current-prefix-arg))
2842 (ispell-set-spellchecker-params) ; Initialize variables and dicts alists
2843 (unless arg (ispell-buffer-local-dict 'no-reload))
2844 (if (equal dict "default") (setq dict nil))
2845 ;; This relies on completing-read's bug of returning "" for no match
2846 (cond ((equal dict "")
2847 (ispell-internal-change-dictionary)
2848 (message "Using %s dictionary"
2849 (or (and (not arg) ispell-local-dictionary)
2850 ispell-dictionary "default")))
2851 ((equal dict (or (and (not arg) ispell-local-dictionary)
2852 ispell-dictionary "default"))
2853 ;; Specified dictionary is the default already. Could reload
2854 ;; the dictionaries if needed.
2855 (ispell-internal-change-dictionary)
2856 (and (interactive-p)
2857 (message "No change, using %s dictionary" dict)))
2858 (t ; reset dictionary!
2859 (if (or (assoc dict ispell-local-dictionary-alist)
2860 (assoc dict ispell-dictionary-alist))
2862 ;; set default dictionary
2863 (setq ispell-dictionary dict)
2864 ;; set local dictionary
2865 (setq ispell-local-dictionary dict)
2866 (setq ispell-local-dictionary-overridden t))
2867 (error "Undefined dictionary: %s" dict))
2868 (ispell-internal-change-dictionary)
2869 (setq ispell-buffer-session-localwords nil)
2870 (message "%s Ispell dictionary set to %s"
2871 (if arg "Global" "Local")
2874 (defun ispell-internal-change-dictionary ()
2875 "Update the dictionary and the personal dictionary used by Ispell.
2876 This may kill the Ispell process; if so, a new one will be started
2878 (let ((dict (or ispell-local-dictionary ispell-dictionary))
2879 (pdict (or ispell-local-pdict ispell-personal-dictionary)))
2880 (unless (and (equal ispell-current-dictionary dict)
2881 (equal ispell-current-personal-dictionary pdict))
2882 (ispell-kill-ispell t)
2883 (setq ispell-current-dictionary dict
2884 ispell-current-personal-dictionary pdict))))
2886 ;; Avoid error messages when compiling for these dynamic variables.
2887 (defvar ispell-start)
2890 ;; Spelling of comments are checked when ispell-check-comments is non-nil.
2893 (defun ispell-region (reg-start reg-end &optional recheckp shift)
2894 "Interactively check a region for spelling errors.
2895 Return nil if spell session was terminated, otherwise returns shift offset
2896 amount for last line processed."
2897 (interactive "r") ; Don't flag errors on read-only bufs.
2898 (ispell-set-spellchecker-params) ; Initialize variables and dicts alists
2900 (ispell-accept-buffer-local-defs)) ; set up dictionary, local words, etc.
2901 (let ((skip-region-start (make-marker))
2902 (rstart (make-marker)))
2905 (message "Spell-checking %s using %s with %s dictionary..."
2906 (if (and (= reg-start (point-min)) (= reg-end (point-max)))
2907 (buffer-name) "region")
2908 (file-name-nondirectory ispell-program-name)
2909 (or ispell-current-dictionary "default"))
2910 ;; Returns cursor to original location.
2911 (save-window-excursion
2912 (goto-char reg-start)
2913 (let ((transient-mark-mode)
2914 (case-fold-search case-fold-search)
2917 (let (message-log-max)
2918 (message "searching for regions to skip"))
2919 (if (re-search-forward (ispell-begin-skip-region-regexp) reg-end t)
2921 (setq key (match-string-no-properties 0))
2922 (set-marker skip-region-start (- (point) (length key)))
2923 (goto-char reg-start)))
2924 (let (message-log-max)
2926 "Continuing spelling check using %s with %s dictionary..."
2927 (file-name-nondirectory ispell-program-name)
2928 (or ispell-current-dictionary "default")))
2929 (set-marker rstart reg-start)
2930 (set-marker ispell-region-end reg-end)
2931 (while (and (not ispell-quit)
2932 (< (point) ispell-region-end))
2933 ;; spell-check region with skipping
2934 (if (and (marker-position skip-region-start)
2935 (<= skip-region-start (point)))
2937 ;; If region inside line comment, must keep comment start.
2938 (setq in-comment (point)
2941 (or (null comment-end) (string= "" comment-end))
2944 (re-search-forward comment-start in-comment t))
2946 ;; Can change skip-regexps (in ispell-message)
2947 (ispell-skip-region key) ; moves pt past region.
2948 (set-marker rstart (point))
2949 ;; check for saving large attachments...
2950 (setq query-fcc (and query-fcc
2951 (ispell-ignore-fcc skip-region-start
2953 (if (and (< rstart ispell-region-end)
2955 (ispell-begin-skip-region-regexp)
2956 ispell-region-end t))
2958 (setq key (match-string-no-properties 0))
2959 (set-marker skip-region-start
2960 (- (point) (length key)))
2962 (set-marker skip-region-start nil))))
2963 (setq reg-end (max (point)
2964 (if (marker-position skip-region-start)
2965 (min skip-region-start ispell-region-end)
2966 (marker-position ispell-region-end))))
2967 (let* ((ispell-start (point))
2968 (ispell-end (min (point-at-eol) reg-end))
2969 (string (ispell-get-line
2970 ispell-start ispell-end in-comment)))
2971 (if in-comment ; account for comment chars added
2972 (setq ispell-start (- ispell-start (length in-comment))
2974 (setq ispell-end (point)) ; "end" tracks region retrieved.
2975 (if string ; there is something to spell check!
2976 ;; (special start end)
2977 (setq shift (ispell-process-line string
2978 (and recheckp shift))))
2979 (goto-char ispell-end)))))
2984 (if (and (not (and recheckp ispell-keep-choices-win))
2985 (get-buffer ispell-choices-buffer))
2986 (kill-buffer ispell-choices-buffer))
2987 (set-marker skip-region-start nil)
2988 (set-marker rstart nil)
2991 ;; preserve or clear the region for ispell-continue.
2992 (if (not (numberp ispell-quit))
2993 (set-marker ispell-region-end nil)
2994 ;; Ispell-continue enabled - ispell-region-end is set.
2995 (goto-char ispell-quit))
2996 ;; Check for aborting
2997 (if (and ispell-checking-message (numberp ispell-quit))
2999 (setq ispell-quit nil)
3000 (error "Message send aborted")))
3001 (if (not recheckp) (setq ispell-quit nil)))
3002 (if (not recheckp) (set-marker ispell-region-end nil))
3003 ;; Only save if successful exit.
3004 (ispell-pdict-save ispell-silently-savep)
3005 (message "Spell-checking %s using %s with %s dictionary...done"
3006 (if (and (= reg-start (point-min)) (= reg-end (point-max)))
3007 (buffer-name) "region")
3008 (file-name-nondirectory ispell-program-name)
3009 (or ispell-current-dictionary "default"))))))
3012 (defun ispell-begin-skip-region-regexp ()
3013 "Return a regexp of the search keys for region skipping.
3014 Includes `ispell-skip-region-alist' plus tex, tib, html, and comment keys.
3015 Must be called after `ispell-buffer-local-parsing' due to dependence on mode."
3021 (if (and ispell-checking-message
3022 (not (eq t ispell-checking-message)))
3023 (mapconcat #'car ispell-checking-message "\\|"))
3025 (if (eq ispell-parser 'tex)
3026 (ispell-begin-tex-skip-regexp))
3028 (if ispell-skip-html
3029 (ispell-begin-skip-region ispell-html-skip-alists))
3031 (if ispell-skip-tib ispell-tib-ref-beginning)
3033 (if (and (eq 'exclusive ispell-check-comments) comment-start)
3034 ;; search from end of current comment to start of next comment.
3035 (if (string= "" comment-end) "^" (regexp-quote comment-end)))
3036 (if (and (null ispell-check-comments) comment-start)
3037 (regexp-quote comment-start))
3038 (ispell-begin-skip-region ispell-skip-region-alist)))
3042 (defun ispell-begin-skip-region (skip-alist)
3043 "Regular expression for start of regions to skip generated from SKIP-ALIST.
3044 Each selection should be a key of SKIP-ALIST;
3045 otherwise, the current line is skipped."
3046 (mapconcat (lambda (lst) (if (stringp (car lst)) (car lst) (eval (car lst))))
3051 (defun ispell-begin-tex-skip-regexp ()
3052 "Regular expression of tex commands to skip.
3053 Generated from `ispell-tex-skip-alists'."
3056 (mapconcat (function (lambda (lst) (car lst)))
3057 (car ispell-tex-skip-alists)
3060 ;; keys wrapped in begin{}
3061 (mapconcat (function (lambda (lst)
3062 (concat "\\\\begin[ \t\n]*{[ \t\n]*"
3065 (car (cdr ispell-tex-skip-alists))
3069 (defun ispell-skip-region-list ()
3070 "Return a list describing key and body regions to skip for this buffer.
3071 Includes regions defined by `ispell-skip-region-alist', tex mode,
3072 `ispell-html-skip-alists', and `ispell-checking-message'.
3073 Manual checking must include comments and tib references.
3074 The list is of the form described by variable `ispell-skip-region-alist'.
3075 Must be called after `ispell-buffer-local-parsing' due to dependence on mode."
3076 (let ((skip-alist ispell-skip-region-alist))
3077 ;; only additional explicit region definition is tex.
3078 (if (eq ispell-parser 'tex)
3079 (setq case-fold-search nil
3080 skip-alist (append (car ispell-tex-skip-alists)
3081 (car (cdr ispell-tex-skip-alists))
3083 (if ispell-skip-html
3084 (setq skip-alist (append ispell-html-skip-alists skip-alist)))
3085 (if (and ispell-checking-message
3086 (not (eq t ispell-checking-message)))
3087 (setq skip-alist (append ispell-checking-message skip-alist)))
3091 (defun ispell-tex-arg-end (&optional arg)
3092 "Skip across ARG number of braces."
3095 (while (looking-at "[ \t\n]*\\[") (forward-sexp))
3096 (forward-sexp (or arg 1)))
3098 (message "Error skipping s-expressions at point %d." (point))
3103 (defun ispell-ignore-fcc (start end)
3104 "Delete the Fcc: message header when large attachments are included.
3105 Return value `nil' if file with large attachments is saved.
3106 This can be used to avoid multiple questions for multiple large attachments.
3107 Returns point to starting location afterwards."
3109 (if (and ispell-checking-message ispell-message-fcc-skip)
3110 (if (< ispell-message-fcc-skip (- end start))
3111 (let (case-fold-search head-end)
3112 (goto-char (point-min))
3114 (or (re-search-forward
3115 (concat "^" (regexp-quote mail-header-separator) "$")
3117 (re-search-forward "^$" nil t)
3119 (goto-char (point-min))
3120 (if (re-search-forward "^Fcc:" head-end t)
3122 "Save copy of this message with large attachments? ")
3130 (defun ispell-skip-region (key)
3131 "Skip across KEY and then to end of region.
3132 Key lookup determines region to skip.
3133 Point is placed at end of skipped region."
3134 ;; move over key to begin checking.
3135 (forward-char (length key))
3136 (let ((start (point))
3137 ;; Regenerate each call... This function can change region definition.
3138 (alist (ispell-skip-region-list))
3139 alist-key null-skip)
3141 ;; what about quoted comment, or comment inside strings?
3142 ((and (null ispell-check-comments) comment-start
3143 (string= key comment-start))
3144 (if (string= "" comment-end)
3146 (search-forward comment-end ispell-region-end t)))
3147 ((and (eq 'exclusive ispell-check-comments) comment-start
3148 (string= key comment-end))
3149 (search-forward comment-start ispell-region-end :end))
3150 ((and ispell-skip-tib (string-match ispell-tib-ref-beginning key))
3151 (re-search-forward ispell-tib-ref-end ispell-region-end t))
3152 ;; markings from alist
3155 (setq alist-key (eval (car (car alist))))
3156 (if (string-match alist-key key)
3158 (setq alist (cdr (car alist)))
3160 ((null alist) (setq null-skip t)) ; done! Just skip key.
3161 ((not (consp alist))
3162 ;; Search past end of spell region to find this region end.
3163 (re-search-forward (eval alist) (point-max) t))
3164 ((and (= 1 (length alist))
3165 (stringp (car alist)))
3166 (re-search-forward (car alist) (point-max) t))
3168 (setq null-skip t) ; error handling in functions!
3169 (if (consp (cdr alist))
3170 (apply (car alist) (cdr alist))
3171 (funcall (car alist)))))
3173 (setq alist (cdr alist))))))
3174 (if (and (= start (point)) (null null-skip))
3176 (message "Matching region end for `%s' point %d not found"
3182 (defun ispell-get-line (start end in-comment)
3183 "Grab the next line of data.
3184 Returns a string with the line data."
3185 (let ((ispell-casechars (ispell-get-casechars))
3187 (cond ; LOOK AT THIS LINE AND SKIP OR PROCESS
3188 ((eolp) ; END OF LINE, just go to next line.
3190 ;;((looking-at "[-#@*+!%~^]") ; SKIP SPECIAL ISPELL CHARACTERS
3191 ;; (forward-char 1)) ; not needed as quoted below.
3192 ((or (re-search-forward ispell-casechars end t) ; TEXT EXISTS
3193 (re-search-forward "[][()${}]" end t)) ; or MATH COMMANDS
3194 (setq string (concat "^" in-comment
3195 (buffer-substring-no-properties start end)
3198 (t (goto-char end))) ; EMPTY LINE, skip it.
3202 (defun ispell-looking-at (string)
3203 (let ((coding (ispell-get-coding-system))
3204 (len (length string)))
3205 (and (<= (+ (point) len) (point-max))
3206 (equal (encode-coding-string string coding)
3207 (encode-coding-string (buffer-substring-no-properties
3208 (point) (+ (point) len))
3211 (defun ispell-process-line (string shift)
3212 "Send STRING, a line of text, to ispell and process the result.
3213 This will modify the buffer for spelling errors.
3214 Requires variables ISPELL-START and ISPELL-END to be defined in its
3216 Returns the sum SHIFT due to changes in word replacements."
3217 ;;(declare special ispell-start ispell-end)
3218 (let (poss accept-list)
3219 (if (not (numberp shift))
3221 ;; send string to spell process and get input.
3222 (ispell-send-string string)
3224 (ispell-accept-output)
3225 ;; Last item of output contains a blank line.
3226 (not (string= "" (car ispell-filter)))))
3227 ;; parse all inputs from the stream one word at a time.
3228 ;; Place in FIFO order and remove the blank item.
3229 (setq ispell-filter (nreverse (cdr ispell-filter)))
3230 (while (and (not ispell-quit) ispell-filter)
3231 ;; get next word, accounting for accepted words and start shifts
3232 (setq poss (ispell-parse-output (car ispell-filter)
3234 (if (and poss (listp poss)) ; spelling error occurred.
3235 ;; Whenever we have misspellings, we can change
3236 ;; the buffer. Keep boundaries as markers.
3237 ;; Markers can move with highlighting! This destroys
3238 ;; end of region markers line-end and ispell-region-end
3240 (copy-marker (+ ispell-start ispell-offset (car (cdr poss)))))
3241 (word-len (length (car poss)))
3242 (line-end (copy-marker ispell-end))
3243 (line-start (copy-marker ispell-start))
3244 recheck-region replace)
3245 (goto-char word-start)
3246 ;; Adjust the horizontal scroll & point
3247 (ispell-horiz-scroll)
3248 (goto-char (+ word-len word-start))
3249 (ispell-horiz-scroll)
3250 (goto-char word-start)
3251 (ispell-horiz-scroll)
3253 ;; Alignment cannot be tracked and this error will occur when
3254 ;; `query-replace' makes multiple corrections on the starting line.
3255 (or (ispell-looking-at (car poss))
3256 ;; This occurs due to filter pipe problems
3257 (error (concat "Ispell misalignment: word "
3258 "`%s' point %d; probably incompatible versions")
3259 (car poss) (marker-position word-start)))
3260 ;; ispell-cmd-loop can go recursive & change buffer
3261 (if ispell-keep-choices-win
3262 (setq replace (ispell-command-loop
3263 (car (cdr (cdr poss)))
3264 (car (cdr (cdr (cdr poss))))
3265 (car poss) (marker-position word-start)
3266 (+ word-len (marker-position word-start))))
3267 (save-window-excursion
3268 (setq replace (ispell-command-loop
3269 (car (cdr (cdr poss)))
3270 (car (cdr (cdr (cdr poss))))
3271 (car poss) (marker-position word-start)
3272 (+ word-len (marker-position word-start))))))
3274 (goto-char word-start)
3275 ;; Recheck when query replace edit changes misspelled word.
3276 ;; Error in tex mode when a potential math mode change exists.
3277 (if (and replace (listp replace) (= 2 (length replace)))
3278 (if (and (eq ispell-parser 'tex)
3279 (string-match "[\\\\][]()[]\\|\\\\begin\\|\\$"
3280 (regexp-quote string)))
3282 "Don't start query replace on a line with math characters"
3284 (set-marker line-end (point))
3285 (setq ispell-filter nil
3288 ;; insert correction if needed
3291 (equal 0 replace)) ; ACCEPT/INSERT
3292 (if (equal 0 replace) ; BUFFER-LOCAL DICT ADD
3293 (ispell-add-per-file-word-list (car poss)))
3294 ;; do not recheck accepted word on this line
3295 (setq accept-list (cons (car poss) accept-list)))
3296 (t ; replacement word selected or entered
3297 (delete-region (point) (+ word-len (point)))
3298 (if (not (listp replace))
3300 (insert replace) ; insert dictionary word
3301 (ispell-send-replacement (car poss) replace)
3302 (setq accept-list (cons replace accept-list)))
3303 (let ((replace-word (car replace)))
3304 ;; Recheck hand entered replacement word
3305 (insert replace-word)
3306 (ispell-send-replacement (car poss) replace-word)
3307 (if (car (cdr replace))
3308 (save-window-excursion
3309 (delete-other-windows) ; to correctly show help.
3310 ;; Assume case-replace &
3311 ;; case-fold-search correct?
3312 (query-replace (car poss) (car replace) t)))
3313 (goto-char word-start)
3314 ;; do not recheck if already accepted
3315 (if (member replace-word accept-list)
3316 (setq accept-list (cons replace-word accept-list)
3317 replace replace-word)
3318 (let ((region-end (copy-marker ispell-region-end)))
3319 (setq recheck-region ispell-filter
3320 ispell-filter nil ; save filter
3321 shift 0 ; already accounted
3322 shift (ispell-region
3324 (+ word-start (length replace-word))
3326 (if (null shift) ; quitting check.
3328 (set-marker ispell-region-end region-end)
3329 (set-marker region-end nil)
3330 (setq ispell-filter recheck-region
3332 replace replace-word)))))
3334 (setq shift (+ shift (- (length replace) word-len)))
3336 ;; Move line-start across word...
3337 ;; new shift function does this now...
3338 ;;(set-marker line-start (+ line-start
3339 ;; (- (length replace)
3340 ;; (length (car poss)))))
3342 (if (not ispell-quit)
3343 ;; FIXME: remove redundancy with identical code above.
3344 (let (message-log-max)
3346 "Continuing spelling check using %s with %s dictionary..."
3347 (file-name-nondirectory ispell-program-name)
3348 (or ispell-current-dictionary "default"))))
3350 (setq ispell-start (marker-position line-start)
3351 ispell-end (marker-position line-end))
3352 ;; Adjust markers when end of region lost from highlighting.
3353 (if (and (not recheck-region)
3354 (< ispell-end (+ word-start word-len)))
3355 (setq ispell-end (+ word-start word-len)))
3356 (if (= word-start ispell-region-end)
3357 (set-marker ispell-region-end (+ word-start word-len)))
3358 ;; going out of scope - unneeded
3359 (set-marker line-start nil)
3360 (set-marker word-start nil)
3361 (set-marker line-end nil)))
3362 ;; finished with misspelling!
3363 (setq ispell-filter (cdr ispell-filter)))
3368 (defun ispell-comments-and-strings ()
3369 "Check comments and strings in the current buffer for spelling errors."
3371 (goto-char (point-min))
3375 (setq state (parse-partial-sexp (point) (point-max)
3376 nil nil state 'syntax-table))
3377 (if (or (nth 3 state) (nth 4 state))
3378 (let ((start (point)))
3379 (setq state (parse-partial-sexp start (point-max)
3380 nil nil state 'syntax-table))
3381 (if (or (nth 3 state) (nth 4 state))
3382 (error "Unterminated string or comment"))
3384 (setq done (not (ispell-region start (point))))))))))
3388 (defun ispell-buffer ()
3389 "Check the current buffer for spelling errors interactively."
3391 (ispell-region (point-min) (point-max)))
3395 (defun ispell-continue ()
3396 "Continue a halted spelling session beginning with the current word."
3398 (if (not (marker-position ispell-region-end))
3399 (message "No session to continue. Use 'X' command when checking!")
3400 (if (not (equal (marker-buffer ispell-region-end) (current-buffer)))
3401 (message "Must continue ispell from buffer %s"
3402 (buffer-name (marker-buffer ispell-region-end)))
3404 ;; find beginning of current word:
3405 (car (cdr (ispell-get-word t)))
3406 (marker-position ispell-region-end)))))
3409 ;;; Horizontal scrolling
3410 (defun ispell-horiz-scroll ()
3411 "Place point within the horizontal visibility of its window area."
3412 (if truncate-lines ; display truncating lines?
3413 ;; See if display needs to be scrolled.
3414 (let ((column (- (current-column) (max (window-hscroll) 1))))
3415 (if (and (< column 0) (> (window-hscroll) 0))
3416 (scroll-right (max (- column) 10))
3417 (if (>= column (- (window-width) 2))
3418 (scroll-left (max (- column (window-width) -3) 10)))))))
3421 ;;; Interactive word completion.
3422 ;; Forces "previous-word" processing. Do we want to make this selectable?
3425 (defun ispell-complete-word (&optional interior-frag)
3426 "Try to complete the word before or under point (see `lookup-words').
3427 If optional INTERIOR-FRAG is non-nil then the word may be a character
3428 sequence inside of a word.
3430 Standard ispell choices are then available."
3431 ;; FIXME: completion-at-point-function.
3433 (let ((cursor-location (point))
3434 (case-fold-search-val case-fold-search)
3435 (word (ispell-get-word nil "\\*")) ; force "previous-word" processing.
3436 start end possibilities replacement)
3437 (setq start (car (cdr word))
3438 end (car (cdr (cdr word)))
3441 (or (string= word "") ; Will give you every word
3442 (lookup-words (concat (and interior-frag "*") word
3443 (if (or interior-frag (null ispell-look-p))
3445 (or ispell-complete-word-dict
3446 ispell-alternate-dictionary))))
3447 (cond ((eq possibilities t)
3448 (message "No word to complete"))
3449 ((null possibilities)
3450 (message "No match for \"%s\"" word))
3451 (t ; There is a modification...
3452 (setq case-fold-search nil) ; Try and respect case of word.
3454 ((string-equal (upcase word) word)
3455 (setq possibilities (mapcar 'upcase possibilities)))
3456 ((eq (upcase (aref word 0)) (aref word 0))
3457 (setq possibilities (mapcar (function
3459 (if (eq (aref word 0) (aref pos 0))
3463 (setq case-fold-search case-fold-search-val)
3464 (save-window-excursion
3466 (ispell-command-loop possibilities nil word start end)))
3468 ((equal 0 replacement) ; BUFFER-LOCAL ADDITION
3469 (ispell-add-per-file-word-list word))
3470 (replacement ; REPLACEMENT WORD
3471 (delete-region start end)
3472 (setq word (if (atom replacement) replacement (car replacement))
3473 cursor-location (+ (- (length word) (- end start))
3476 (if (not (atom replacement)) ; recheck spelling of replacement.
3478 (goto-char cursor-location)
3479 (ispell-word nil t)))))
3480 (if (get-buffer ispell-choices-buffer)
3481 (kill-buffer ispell-choices-buffer))))
3482 (ispell-pdict-save ispell-silently-savep)
3483 (goto-char cursor-location)))
3487 (defun ispell-complete-word-interior-frag ()
3488 "Completes word matching character sequence inside a word."
3490 (ispell-complete-word t))
3495 "Interactively check a region or buffer for spelling errors.
3496 If `transient-mark-mode' is on, and a region is active, spell-check
3497 that region. Otherwise spell-check the buffer.
3499 Ispell dictionaries are not distributed with Emacs. If you are
3500 looking for a dictionary, please see the distribution of the GNU ispell
3501 program, or do an Internet search; there are various dictionaries
3502 available on the net."
3504 (if (and (boundp 'transient-mark-mode) transient-mark-mode
3505 (boundp 'mark-active) mark-active)
3506 (ispell-region (region-beginning) (region-end))
3510 ;;; **********************************************************************
3511 ;;; Ispell Minor Mode
3512 ;;; **********************************************************************
3514 (defvar ispell-minor-keymap
3515 (let ((map (make-sparse-keymap)))
3516 (define-key map " " 'ispell-minor-check)
3517 (define-key map "\r" 'ispell-minor-check)
3519 "Keymap used for Ispell minor mode.")
3522 (define-minor-mode ispell-minor-mode
3523 "Toggle last-word spell checking (Ispell minor mode).
3524 With a prefix argument ARG, enable Ispell minor mode if ARG is
3525 positive, and disable it otherwise. If called from Lisp, enable
3526 the mode if ARG is omitted or nil.
3528 Ispell minor mode is a buffer-local minor mode. When enabled,
3529 typing SPC or RET warns you if the previous word is incorrectly
3532 All the buffer-local variables and dictionaries are ignored. To
3533 read them into the running ispell process, type \\[ispell-word]
3536 For spell-checking \"on the fly\", not just after typing SPC or
3537 RET, use `flyspell-mode'."
3538 nil " Spell" ispell-minor-keymap)
3540 (defun ispell-minor-check ()
3541 "Check previous word, then continue with the normal binding of this key.
3542 Don't check previous word when character before point is a space or newline.
3543 Don't read buffer-local settings or word lists."
3545 (let ((ispell-minor-mode nil)
3546 (ispell-check-only t)
3547 (last-char (char-after (1- (point)))))
3548 (command-execute (key-binding (this-command-keys)))
3549 (if (not (or (eq last-char ?\ ) (eq last-char ?\n)
3550 (and ispell-skip-html (eq last-char ?>))
3551 (and ispell-skip-html (eq last-char ?\;))))
3552 (ispell-word nil t))))
3555 ;;; **********************************************************************
3557 ;;; **********************************************************************
3559 (defvar ispell-message-text-end
3560 (mapconcat (function identity)
3562 ;; Don't spell check signatures
3564 ;; Matches PostScript files.
3565 ;;"^%!PS-Adobe-[123].0"
3566 ;; Matches uuencoded text
3567 ;;"^begin [0-9][0-9][0-9] .*\nM.*\nM.*\nM"
3568 ;; Matches shell files (especially auto-decoding)
3570 ;; Matches context difference listing
3571 "\\(\\(^cd .*\n\\)?diff -c .*\\)?\n\\*\\*\\* .*\n--- .*\n\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*"
3572 ;; Matches unidiff difference listing
3573 "\\(diff -u .*\\)?\n--- .*\n\\+\\+\\+ .*\n@@ [-+][0-9]+,[0-9]+ [-+][0-9]+,[0-9]+ @@"
3574 ;; Matches reporter.el bug report
3575 "^current state:\n==============\n"
3576 ;; Matches commonly used "cut" boundaries
3577 "^\\(- \\)?[-=_]+\\s ?\\(cut here\\|Environment Follows\\)")
3579 "Text beyond which `ispell-message' will not spell-check.
3580 If it is a string, limit is the first occurrence of that regular expression.
3581 Otherwise, it must be a function which is called to get the limit.")
3582 (put 'ispell-message-text-end 'risky-local-variable t)
3585 (defun ispell-mime-multipartp (&optional limit)
3586 "Return multipart message start boundary or nil if none."
3587 ;; caller must ensure `case-fold-search' is set to `t'
3590 "Content-Type: *multipart/\\([^ \t\n]*;[ \t]*[\n]?[ \t]*\\)+boundary="
3593 (if (looking-at "\"")
3596 (setq start (point))
3597 (while (not (looking-at "\""))
3599 (setq boundary (buffer-substring-no-properties start (point))))
3600 (let ((start (point)))
3601 (while (looking-at "[-0-9a-zA-Z'()+_,./:=?]")
3603 (setq boundary (buffer-substring-no-properties start (point)))))
3604 (if (< (length boundary) 1)
3606 (concat "--" boundary)))))
3609 (defun ispell-mime-skip-part (boundary)
3610 "Move point across header, or entire MIME part if message is encoded.
3611 All specified types except `7bit' `8bit' and `quoted-printable' are considered
3612 encoded and therefore skipped. See rfc 1521, 2183, ...
3613 If no boundary is given, then entire message is skipped.
3615 This starts one line ABOVE the MIME content messages, on the boundary marker,
3616 for operation with the generic region-skipping code.
3617 This places new MIME boundaries into variable `ispell-checking-message'."
3618 (forward-line) ; skip over boundary to headers
3619 (let ((save-case-fold-search case-fold-search)
3622 (setq case-fold-search t
3623 ispell-skip-html nil)
3625 (setq continuep nil)
3626 (if (looking-at "Content-Type: *text/")
3628 (goto-char (match-end 0))
3629 (if (looking-at "html")
3630 (setq ispell-skip-html t))
3633 (re-search-forward "\\(.*;[ \t]*[\n]\\)*.*$" nil t)
3635 (if (looking-at "Content-Transfer-Encoding: *\\([^ \t\n]*\\)")
3636 (let ((match (buffer-substring (match-beginning 1) (match-end 1))))
3637 (setq textp (member (upcase match)
3638 ;; only spell check the following encodings:
3639 '("7BIT" "8BIT" "QUOTED-PRINTABLE" "BINARY"))
3641 (goto-char (match-end 0))
3642 (re-search-forward "\\(.*;[ \t]*[\n]\\)*.*$" nil t)
3644 ;; hierarchical boundary definition
3645 (if (looking-at "Content-Type: *multipart/")
3646 (let ((new-boundary (ispell-mime-multipartp)))
3647 (if (string-match new-boundary boundary)
3649 ;; first pass redefine skip function to include new boundary
3650 ;;(re-search-backward boundary nil t)
3652 (setq ispell-checking-message
3654 (list new-boundary 'ispell-mime-skip-part new-boundary)
3655 (if (eq t ispell-checking-message) nil
3656 ispell-checking-message))
3659 ;; Skip all MIME headers that don't affect spelling
3660 (if (looking-at "Content-[^ \t]*: *\\(.*;[ \t]*[\n]\\)*.*$")
3663 (goto-char (match-end 0))
3666 (setq case-fold-search save-case-fold-search)
3669 ;; encoded message. Skip to boundary, or entire message.
3671 (goto-char (point-max))
3672 (re-search-forward boundary nil t)
3678 (defun ispell-message ()
3679 "Check the spelling of a mail message or news post.
3680 Don't check spelling of message headers except the Subject field.
3681 Don't check included messages.
3683 To abort spell checking of a message region and send the message anyway,
3684 use the `x' command. (Any subsequent regions will be checked.)
3685 The `X' command aborts sending the message so that you can edit the buffer.
3687 To spell-check whenever a message is sent, include the appropriate lines
3688 in your .emacs file:
3689 (add-hook 'message-send-hook 'ispell-message) ;; GNUS 5
3690 (add-hook 'news-inews-hook 'ispell-message) ;; GNUS 4
3691 (add-hook 'mail-send-hook 'ispell-message)
3692 (add-hook 'mh-before-send-letter-hook 'ispell-message)
3694 You can bind this to the key C-c i in GNUS or mail by adding to
3695 `news-reply-mode-hook' or `mail-mode-hook' the following lambda expression:
3696 (function (lambda () (local-set-key \"\\C-ci\" 'ispell-message)))"
3699 (goto-char (point-min))
3700 (let* (boundary mimep
3701 (ispell-skip-region-alist-save ispell-skip-region-alist)
3702 ;; Nil when message came from outside (eg calling Emacs as editor)
3703 ;; Non-nil marker of end of headers.
3706 (concat "^" (regexp-quote mail-header-separator) "$") nil t))
3707 (end-of-headers ; Start of body.
3709 (or internal-messagep
3710 (re-search-forward "^$" nil t)
3712 (limit (copy-marker ; End of region we will spell check.
3714 ((not ispell-message-text-end) (point-max))
3715 ((char-or-string-p ispell-message-text-end)
3716 (if (re-search-forward ispell-message-text-end nil t)
3719 (t (min (point-max) (funcall ispell-message-text-end))))))
3720 (default-prefix ; Vanilla cite prefix (just used for cite-regexp)
3721 (if (and (boundp 'mail-yank-prefix) mail-yank-prefix)
3722 (ispell-non-empty-string mail-yank-prefix)
3724 (cite-regexp ;Prefix of quoted text
3726 ((functionp 'sc-cite-regexp) ; sc 3.0
3727 (ispell-with-no-warnings
3728 (concat "\\(" (sc-cite-regexp) "\\)" "\\|"
3729 (ispell-non-empty-string sc-reference-tag-string))))
3730 ((boundp 'sc-cite-regexp) ; sc 2.3
3731 (concat "\\(" sc-cite-regexp "\\)" "\\|"
3732 (ispell-with-no-warnings
3733 (ispell-non-empty-string sc-reference-tag-string))))
3734 ((or (equal major-mode 'news-reply-mode) ;GNUS 4 & below
3735 (equal major-mode 'message-mode)) ;GNUS 5
3736 (concat "In article <" "\\|"
3737 "[^,;&+=\n]+ <[^,;&+=]+> writes:" "\\|"
3738 (ispell-with-no-warnings message-cite-prefix-regexp)
3741 ((equal major-mode 'mh-letter-mode) ; mh mail message
3742 (concat "[^,;&+=\n]+ writes:" "\\|"
3743 (ispell-with-no-warnings
3744 (ispell-non-empty-string mh-ins-buf-prefix))))
3745 ((not internal-messagep) ; Assume nn sent us this message.
3746 (concat "In [a-zA-Z.]+ you write:" "\\|"
3747 "In <[^,;&+=]+> [^,;&+=]+ writes:" "\\|"
3749 ((boundp 'vm-included-text-prefix) ; VM mail message
3750 (concat "[^,;&+=\n]+ writes:" "\\|"
3751 (ispell-non-empty-string vm-included-text-prefix)))
3752 (t default-prefix)))
3753 (ispell-skip-region-alist
3754 (cons (list (concat "^\\(" cite-regexp "\\)")
3755 (function forward-line))
3756 ispell-skip-region-alist))
3757 (old-case-fold-search case-fold-search)
3758 (dictionary-alist ispell-message-dictionary-alist)
3759 (ispell-checking-message t))
3761 ;; Select dictionary for message
3762 (or (local-variable-p 'ispell-local-dictionary (current-buffer))
3763 (while dictionary-alist
3764 (goto-char (point-min))
3765 (if (re-search-forward (car (car dictionary-alist))
3767 (setq ispell-local-dictionary (cdr (car dictionary-alist))
3768 dictionary-alist nil)
3769 (setq dictionary-alist (cdr dictionary-alist)))))
3773 ;; Spell check any original Subject:
3774 (goto-char (point-min))
3775 (setq case-fold-search t
3776 mimep (re-search-forward "MIME-Version:" end-of-headers t))
3777 (goto-char (point-min))
3778 (if (re-search-forward "^Subject: *" end-of-headers t)
3780 (goto-char (match-end 0))
3781 (if (and (not (looking-at ".*Re\\>"))
3782 (not (looking-at "\\[")))
3784 (setq case-fold-search old-case-fold-search)
3785 (ispell-region (point)
3786 (progn ;Tab-initiated continuation lns.
3788 (while (looking-at "\n[ \t]")
3793 (goto-char (point-min))
3794 (setq boundary (ispell-mime-multipartp end-of-headers))))
3795 ;; Adjust message limit to MIME message if necessary.
3797 (re-search-forward (concat boundary "--") nil t)
3798 (re-search-backward boundary nil t)
3799 (< (point) (marker-position limit))
3800 (set-marker limit (point)))
3801 (goto-char (point-min))
3802 ;; Select type or skip checking if this is a non-multipart message
3803 ;; Point moved to end of buffer if region is encoded.
3804 (when (and mimep (not boundary))
3805 (goto-char (point-min))
3806 (re-search-forward "Content-[^ \t]*:" end-of-headers t)
3807 (forward-line -1) ; following fn starts one line above
3808 (ispell-mime-skip-part nil)
3809 ;; if message-text-end region, limit may be less than point.
3810 (if (> (point) limit)
3811 (set-marker limit (point))))
3812 (goto-char (max end-of-headers (point)))
3814 (setq case-fold-search old-case-fold-search)
3815 ;; Define MIME regions to skip.
3817 (setq ispell-checking-message
3818 (list (list boundary 'ispell-mime-skip-part boundary))))
3819 (ispell-region (point) limit))
3820 (set-marker end-of-headers nil)
3821 (set-marker limit nil)
3822 (setq ispell-skip-region-alist ispell-skip-region-alist-save
3823 ispell-skip-html nil
3824 case-fold-search old-case-fold-search)))))
3827 (defun ispell-non-empty-string (string)
3828 (if (or (not string) (string-equal string ""))
3829 "\\'\\`" ; An unmatchable string if string is null.
3830 (regexp-quote string)))
3833 ;;; **********************************************************************
3834 ;;; Buffer Local Functions
3835 ;;; **********************************************************************
3838 (defun ispell-accept-buffer-local-defs ()
3839 "Load all buffer-local information, restarting Ispell when necessary."
3840 (ispell-buffer-local-dict) ; May kill ispell-process.
3841 (ispell-buffer-local-words) ; Will initialize ispell-process.
3842 (ispell-buffer-local-parsing))
3845 (defun ispell-buffer-local-parsing ()
3846 "Place Ispell into parsing mode for this buffer.
3847 Overrides the default parsing mode.
3848 Includes LaTeX/Nroff modes and extended character mode."
3849 ;; (ispell-init-process) must already be called.
3850 (ispell-send-string "!\n") ; Put process in terse mode.
3851 ;; We assume all major modes with "tex-mode" in them should use latex parsing
3852 ;; When exclusively checking comments, set to raw text mode (nroff).
3853 (if (and (not (eq 'exclusive ispell-check-comments))
3854 (or (and (eq ispell-parser 'use-mode-name)
3855 (string-match "[Tt][Ee][Xx]-mode"
3856 (symbol-name major-mode)))
3857 (eq ispell-parser 'tex)))
3859 (ispell-send-string "+\n") ; set ispell mode to tex
3860 (if (not (eq ispell-parser 'tex))
3861 (set (make-local-variable 'ispell-parser) 'tex)))
3862 (ispell-send-string "-\n")) ; set mode to normal (nroff)
3863 ;; If needed, test for SGML & HTML modes and set a buffer local nil/t value.
3864 (if (and ispell-skip-html (not (eq ispell-skip-html t)))
3865 (setq ispell-skip-html
3866 (not (null (string-match "sgml\\|html\\|xml"
3867 (downcase (symbol-name major-mode)))))))
3868 ;; Set default extended character mode for given buffer, if any.
3869 (let ((extended-char-mode (ispell-get-extended-character-mode)))
3870 (if extended-char-mode
3871 (ispell-send-string (concat extended-char-mode "\n"))))
3872 ;; Set buffer-local parsing mode and extended character mode, if specified.
3874 (goto-char (point-max))
3875 ;; Uses last occurrence of ispell-parsing-keyword
3876 (if (search-backward ispell-parsing-keyword nil t)
3877 (let ((end (point-at-eol))
3879 (search-forward ispell-parsing-keyword)
3880 (while (re-search-forward " *\\([^ \"]+\\)" end t)
3881 ;; space separated definitions.
3882 (setq string (downcase (match-string-no-properties 1)))
3883 (cond ((and (string-match "latex-mode" string)
3884 (not (eq 'exclusive ispell-check-comments)))
3885 (ispell-send-string "+\n~tex\n"))
3886 ((string-match "nroff-mode" string)
3887 (ispell-send-string "-\n~nroff\n"))
3888 ((string-match "~" string) ; Set extended character mode.
3889 (ispell-send-string (concat string "\n")))
3890 (t (message "Invalid Ispell Parsing argument!")
3894 ;; Can kill the current ispell process
3896 (defun ispell-buffer-local-dict (&optional no-reload)
3897 "Initializes local dictionary and local personal dictionary.
3898 If optional NO-RELOAD is non-nil, do not reload any dictionary.
3899 When a dictionary is defined in the buffer (see variable
3900 `ispell-dictionary-keyword'), it will override the local setting
3901 from \\[ispell-change-dictionary].
3902 Both should not be used to define a buffer-local dictionary."
3904 (goto-char (point-min))
3906 ;; Override the local variable definition.
3907 ;; Uses last occurrence of ispell-dictionary-keyword.
3908 (goto-char (point-max))
3909 (unless ispell-local-dictionary-overridden
3910 (if (search-backward ispell-dictionary-keyword nil t)
3912 (search-forward ispell-dictionary-keyword)
3913 (setq end (point-at-eol))
3914 (if (re-search-forward " *\\([^ \"]+\\)" end t)
3915 (setq ispell-local-dictionary
3916 (match-string-no-properties 1))))))
3917 (goto-char (point-max))
3918 (if (search-backward ispell-pdict-keyword nil t)
3920 (search-forward ispell-pdict-keyword)
3921 (setq end (point-at-eol))
3922 (if (re-search-forward " *\\([^ \"]+\\)" end t)
3923 (setq ispell-local-pdict
3924 (match-string-no-properties 1)))))))
3926 ;; Reload if new dictionary (maybe the personal one) defined.
3927 (ispell-internal-change-dictionary)))
3930 (defun ispell-buffer-local-words ()
3931 "Load the buffer-local dictionary in the current buffer."
3932 ;; If there's an existing ispell process that's wrong for this use,
3934 (if (and ispell-buffer-local-name
3935 (not (equal ispell-buffer-local-name (buffer-name))))
3936 (ispell-kill-ispell t))
3937 ;; Actually start a new ispell process, because we need
3938 ;; to send commands now to specify the local words to it.
3939 (ispell-init-process)
3940 (dolist (session-localword ispell-buffer-session-localwords)
3941 (ispell-send-string (concat "@" session-localword "\n")))
3942 (or ispell-buffer-local-name
3943 (if ispell-buffer-session-localwords
3944 (setq ispell-buffer-local-name (buffer-name))))
3946 (goto-char (point-min))
3947 (while (search-forward ispell-words-keyword nil t)
3948 (or ispell-buffer-local-name
3949 (setq ispell-buffer-local-name (buffer-name)))
3950 (let ((end (point-at-eol))
3951 (ispell-casechars (ispell-get-casechars))
3953 ;; buffer-local words separated by a space, and can contain
3954 ;; any character other than a space. Not rigorous enough.
3955 (while (re-search-forward " *\\([^ ]+\\)" end t)
3956 (setq string (match-string-no-properties 1))
3957 ;; This can fail when string contains a word with invalid chars.
3958 ;; Error handling needs to be added between ispell and Emacs.
3959 (if (and (< 1 (length string))
3960 (equal 0 (string-match ispell-casechars string)))
3961 (ispell-send-string (concat "@" string "\n"))))))))
3964 ;; Returns optionally adjusted region-end-point.
3966 ;; If comment-padright is defined, newcomment must be loaded.
3967 (declare-function comment-add "newcomment" (arg))
3969 (defun ispell-add-per-file-word-list (word)
3970 "Add WORD to the per-file word list."
3971 (or ispell-buffer-local-name
3972 (setq ispell-buffer-local-name (buffer-name)))
3974 (goto-char (point-min))
3975 (let (line-okay search done found)
3977 (let ((case-fold-search nil))
3978 (setq search (search-forward ispell-words-keyword nil 'move)
3979 found (or found search)
3980 line-okay (< (+ (length word) 1 ; 1 for space after word..
3981 (progn (end-of-line) (current-column)))
3983 (if (or (and search line-okay)
3990 (unless found (newline))
3991 (insert (if comment-start
3993 (if (fboundp 'comment-padright)
3994 ;; Try and use the proper comment marker,
3995 ;; e.g. ";;" rather than ";".
3996 (comment-padright comment-start
4001 ispell-words-keyword)
4002 (if (and comment-end (> (length comment-end) 0))
4005 (insert comment-end)))))
4006 (insert (concat " " word))))))))
4008 (add-to-list 'debug-ignored-errors "^No word found to check!$")
4013 ;;; LOCAL VARIABLES AND BUFFER-LOCAL VALUE EXAMPLES.
4015 ;; Local Variable options:
4016 ;; mode: name(-mode)
4018 ;; local-variable: value
4020 ;; The following sets the buffer local dictionary to `american' English
4021 ;; and spell checks only comments.
4025 ;; comment-column: 40
4026 ;; ispell-check-comments: exclusive
4027 ;; ispell-local-dictionary: "american"
4031 ;;; MORE EXAMPLES OF ISPELL BUFFER-LOCAL VALUES
4033 ;; The following places this file in nroff parsing and extended char modes.
4034 ;; Local IspellParsing: nroff-mode ~nroff
4035 ;; Change IspellPersDict to IspellPersDict: to enable the following line.
4036 ;; Local IspellPersDict ~/.ispell_lisp
4037 ;; The following were automatically generated by ispell using the 'A' command:
4038 ; LocalWords: settable alist inews mh frag pdict Wildcards iconify arg tex kss
4039 ; LocalWords: alists minibuffer bufferp autoload loaddefs aff Dansk KOI SPC op
4040 ; LocalWords: Francais Nederlands charset autoloaded popup nonmenu regexp num
4041 ; LocalWords: AMStex hspace includeonly nocite epsfig displaymath eqnarray reg
4042 ; LocalWords: minipage modeline pers dict unhighlight buf grep sync prev inc
4043 ; LocalWords: fn oldot NB AIX msg init read's bufs pt cmd Quinlan eg
4044 ; LocalWords: uuencoded unidiff sc nn VM SGML eval IspellPersDict
4045 ; LocalWords: lns XEmacs HTML casechars Multibyte
4047 ;;; ispell.el ends here