1 ;;; ispell.el --- interface to International Ispell Versions 3.1 and 3.2
3 ;; Copyright (C) 1994-1995, 1997-2012 Free Software Foundation, Inc.
5 ;; Author: Ken Stevens <k.stevens@ieee.org>
6 ;; Maintainer: Ken Stevens <k.stevens@ieee.org>
7 ;; Stevens Mod Date: Mon Jan 7 12:32:44 PST 2003
8 ;; Stevens Revision: 3.6
9 ;; Status : Release with 3.1.12+ and 3.2.0+ ispell.
10 ;; Bug Reports : ispell-el-bugs@itcorp.com
11 ;; Web Site : http://kdstevens.com/~stevens/ispell-page.html
14 ;; This file is part of GNU Emacs.
16 ;; GNU Emacs is free software: you can redistribute it and/or modify
17 ;; it under the terms of the GNU General Public License as published by
18 ;; the Free Software Foundation, either version 3 of the License, or
19 ;; (at your option) any later version.
21 ;; GNU Emacs is distributed in the hope that it will be useful,
22 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 ;; GNU General Public License for more details.
26 ;; You should have received a copy of the GNU General Public License
27 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
29 ;; Note: version numbers and time stamp are not updated
30 ;; when this file is edited for release with GNU Emacs.
36 ;; This code contains a section of user-settable variables that you
37 ;; should inspect prior to installation. Look past the end of the history
38 ;; list. Set them up for your locale and the preferences of the majority
39 ;; of the users. Otherwise the users may need to set a number of variables
41 ;; You particularly may want to change the default dictionary for your
42 ;; country and language.
43 ;; Most dictionary changes should be made in this file so all users can
44 ;; enjoy them. Local or modified dictionaries are supported in your .emacs
45 ;; file. Use the variable `ispell-local-dictionary-alist' to specify
46 ;; your own dictionaries.
48 ;; Depending on the mail system you use, you may want to include these:
49 ;; (add-hook 'news-inews-hook 'ispell-message)
50 ;; (add-hook 'mail-send-hook 'ispell-message)
51 ;; (add-hook 'mh-before-send-letter-hook 'ispell-message)
53 ;; Ispell has a TeX parser and a nroff parser (the default).
54 ;; The parsing is controlled by the variable ispell-parser. Currently
55 ;; it is just a "toggle" between TeX and nroff, but if more parsers are
56 ;; added it will be updated. See the variable description for more info.
65 ;; ispell-comments-and-strings
67 ;; ispell-complete-word
68 ;; ispell-complete-word-interior-frag
69 ;; ispell-change-dictionary
72 ;; ispell-skip-region-alist
74 ;; Commands in ispell-region:
75 ;; Character replacement: Replace word with choice. May query-replace.
76 ;; ` ': Accept word this time.
77 ;; `i': Accept word and insert into private dictionary.
78 ;; `a': Accept word for this session.
79 ;; `A': Accept word and place in buffer-local dictionary.
80 ;; `r': Replace word with typed-in value. Rechecked.
81 ;; `R': Replace word with typed-in value. Query-replaced in buffer. Rechecked.
82 ;; `?': Show these commands
83 ;; `x': Exit spelling buffer. Move cursor to original point.
84 ;; `X': Exit spelling buffer. Leaves cursor at the current point, and permits
85 ;; the check to be completed later.
86 ;; `q': Quit spelling session (Kills ispell process).
87 ;; `l': Look up typed-in replacement in alternate dictionary. Wildcards okay.
88 ;; `u': Like `i', but the word is lower-cased first.
89 ;; `m': Place entered value in personal dictionary, then recheck current word.
90 ;; `C-l': redraws screen
91 ;; `C-r': recursive edit
92 ;; `C-z': suspend Emacs or iconify frame
94 ;; Buffer-Local features:
95 ;; There are a number of buffer-local features that can be used to customize
96 ;; ispell for the current buffer. This includes language dictionaries,
97 ;; personal dictionaries, parsing, and local word spellings. Each of these
98 ;; local customizations are done either through local variables, or by
99 ;; including the keyword and argument(s) at the end of the buffer (usually
100 ;; prefixed by the comment characters). See the end of this file for
101 ;; examples. The local keywords and variables are:
103 ;; ispell-dictionary-keyword language-dictionary
104 ;; uses local variable ispell-local-dictionary
105 ;; ispell-pdict-keyword personal-dictionary
106 ;; uses local variable ispell-local-pdict
107 ;; ispell-parsing-keyword mode-arg extended-char-arg
108 ;; ispell-words-keyword any number of local word spellings
111 ;; Place new regular expression definitions of regions you prefer not to
112 ;; spell check in `ispell-skip-region-alist'. Mode-dependent features can
113 ;; be added to latex by modifying `ispell-tex-skip-alists'.
114 ;; `ispell-message' contains some custom skipping code for e-mail messages.
117 ;; Need a way to select between different character mappings without separate
118 ;; dictionary entries.
119 ;; Multi-byte characters if not defined by current dictionary may result in the
120 ;; evil "misalignment error" in some versions of MULE Emacs.
121 ;; On some versions of Emacs, growing the minibuffer fails.
122 ;; see `ispell-help-in-bufferp'.
123 ;; Recursive edits (?C-r or ?R) inside a keyboard text replacement check (?r)
124 ;; can cause misalignment errors.
128 ;; Modifications made in latest versions:
130 ;; Revision 3.6 2003/01/07 12:32:44 kss
131 ;; Removed extra -d LIB in dictionary defs. (Pavel Janik)
132 ;; Filtered process calls with duplicate dictionary entries.
133 ;; Fixed bug where message-text-end is inside a mime skipped region.
134 ;; Minor fixes to get ispell menus right in XEmacs
135 ;; Fixed skip regexp so it doesn't match stuff like `/.\w'.
136 ;; Detecting dictionary change not working. Fixed. kss
137 ;; function `ispell-change-dictionary' now only completes valid dicts.
139 ;; Revision 3.5 2001/7/11 18:43:57 kss
140 ;; Added fix for aspell to work in XEmacs (ispell-check-version).
141 ;; Added Portuguese dictionary definition.
142 ;; New feature: MIME mail message support, Fcc support.
143 ;; Bug fix: retain comment syntax on lines with region skipping. (TeX $ bug...)
144 ;; Improved allocation for graphic mode lines. (Miles Bader)
145 ;; Support -v flag for old versions of aspell. (Eli Zaretskii)
146 ;; Clear minibuffer on ^G from ispell-help (Tak Ota)
148 ;; Revision 3.4 2000/8/4 09:41:50 kss
149 ;; Support new color display functions.
150 ;; Fixed misalignment offset bug when replacing a string after a shift made.
151 ;; Set to standard Author/Maintainer heading,
152 ;; ensure localwords lists are separated from the text by newline. (Dave Love)
153 ;; Added dictionary definition for Italian (William Deakin)
154 ;; HTML region skipping greatly improved. (Chuck D. Phillips)
155 ;; improved menus. Fixed regexp matching http/email addresses.
156 ;; one arg always for XEmacs sleep-for (gunnar Evermann)
157 ;; support for synchronous processes (Eli Zaretskii)
159 ;; Revision 3.3 1999/11/29 11:38:34 kss
160 ;; Only word replacements entered in from the keyboard are rechecked.
161 ;; This fixes a bug in tex parsing and misalignment.
162 ;; Exceptions exist for recursive edit and query-replace, with tex error
163 ;; condition tested. Recursive editing improved.
164 ;; XEmacs repair for when `enable-multibyte-characters' defined - Didier Verna.
165 ;; ispell-help fixed for XEmacs. Choices minibuffer now displayed in XEmacs.
166 ;; Only list valid dictionaries in Spell menu. Russian dictionary doesn't allow
167 ;; run-together words, and uses koi8-r font. Don't skip text in html <TT>
170 ;; Revision 3.2 1999/5/7 14:25:14 kss
171 ;; Accept ispell versions 3.X.Y where X>=1
172 ;; fine tuned latex region skipping. Fixed bug in ispell-word that did not
173 ;; point in right place on words < 2 chars. Simplified ispell-minor-mode.
174 ;; Fixed bug in TeX parsing when math commands are in the comments.
175 ;; Removed calls to `when' macro.
177 ;; Revision 3.1 1998/12/1 13:21:52 kss
178 ;; Improved and fixed customize support.
179 ;; Improved and fixed comments in variables and messages.
180 ;; A coding system is now required for all languages.
181 ;; casechars improved for castellano, castellano8, and norsk dictionaries.
182 ;; Dictionary norsk7-tex removed. Dictionary polish added.
183 ;; Dictionaries redefined at load-time to support dictionary changes.
184 ;; Menu redefined at load time to support dictionary changes.
185 ;; ispell-check-version added as an alias for `check-ispell-version'.
186 ;; Spelling suggestions returned in order generated by ispell.
187 ;; Small bug fixed in matching ispell error messages.
188 ;; Robustness added to ensure `case-fold-search' doesn't get redefined.
189 ;; Fixed bug that didn't respect case of word in `ispell-complete-word'.
190 ;; Multibyte character coding support added for process interactions.
191 ;; Ensure ispell process has terminated before starting new process.
192 ;; This can otherwise confuse process filters and hang ispell.
193 ;; Improved skipping support for SGML.
194 ;; Fixed bug using ^M rather than \r in `ispell-minor-check'.
195 ;; Improved message reference matching in `ispell-message'.
196 ;; Fixed bug in returning to nroff mode from tex mode.
198 ;;; Compatibility code for XEmacs and (not too) older emacsen:
200 (eval-and-compile ;; Protect against declare-function undefined in XEmacs
201 (unless (fboundp 'declare-function
) (defmacro declare-function
(&rest r
))))
203 (declare-function ispell-check-minver
"ispell" (v1 v2
))
204 (declare-function ispell-looking-back
"ispell"
205 (regexp &optional limit
&rest ignored
))
207 (if (fboundp 'version
<=)
208 (defalias 'ispell-check-minver
'version
<=)
209 (defun ispell-check-minver (minver version
)
210 "Check if string VERSION is at least string MINVER.
211 Both must be in [0-9]+.[0-9]+... format. This is a fallback
212 compatibility function in case `version<=' is not available."
215 start-ver start-mver
)
216 ;; Loop until an absolute greater or smaller condition is reached
217 ;; or until no elements are left in any of version and minver. In
218 ;; this case version is exactly the minimal, so return OK.
221 (if (string-match "[0-9]+" version start-ver
)
222 (setq start-ver
(match-end 0)
223 ver
(string-to-number (match-string 0 version
))))
224 (if (string-match "[0-9]+" minver start-mver
)
225 (setq start-mver
(match-end 0)
226 mver
(string-to-number (match-string 0 minver
))))
230 (or ver
(setq ver
0))
231 (or mver
(setq mver
0))
232 ;; If none of below conditions match, this element is the
233 ;; same. Go checking next element.
239 (setq pending nil
))))
242 ;; XEmacs does not have looking-back
243 (if (fboundp 'looking-back
)
244 (defalias 'ispell-looking-back
'looking-back
)
245 (defun ispell-looking-back (regexp &optional limit
&rest ignored
)
246 "Return non-nil if text before point matches regular expression REGEXP.
247 Like `looking-at' except matches before point, and is slower.
248 LIMIT if non-nil speeds up the search by specifying a minimum
249 starting position, to avoid checking matches that would start
252 This is a stripped down compatibility function for use when
253 full featured `looking-back' function is missing."
255 (re-search-backward (concat "\\(?:" regexp
"\\)\\=") limit t
))))
259 (defvar mail-yank-prefix
)
262 "User variables for Emacs ispell interface."
263 :group
'applications
)
265 (if (not (fboundp 'buffer-substring-no-properties
))
266 (defun buffer-substring-no-properties (start end
)
267 (buffer-substring start end
)))
269 (defalias 'check-ispell-version
'ispell-check-version
)
271 ;;; **********************************************************************
272 ;;; The following variables should be set according to personal preference
273 ;;; and location of binaries:
274 ;;; **********************************************************************
277 ;;; ******* THIS FILE IS WRITTEN FOR ISPELL VERSION 3.1+
279 (defcustom ispell-highlight-p
'block
280 "*Highlight spelling errors when non-nil.
281 When set to `block', assumes a block cursor with TTY displays."
282 :type
'(choice (const block
) (const :tag
"off" nil
) (const :tag
"on" t
))
285 (defcustom ispell-lazy-highlight
(boundp 'lazy-highlight-cleanup
)
286 "*Controls the lazy-highlighting of spelling errors.
287 When non-nil, all text in the buffer matching the current spelling
288 error is highlighted lazily using isearch lazy highlighting (see
289 `lazy-highlight-initial-delay' and `lazy-highlight-interval')."
291 :group
'lazy-highlight
295 (defcustom ispell-highlight-face
(if ispell-lazy-highlight
'isearch
'highlight
)
296 "*The face used for Ispell highlighting. For Emacsen with overlays.
297 Possible values are `highlight', `modeline', `secondary-selection',
298 `region', and `underline'.
299 This variable can be set by the user to whatever face they desire.
300 It's most convenient if the cursor color and highlight color are
305 (defcustom ispell-check-comments t
306 "*Spelling of comments checked when non-nil.
307 When set to `exclusive', ONLY comments are checked. (For code comments).
308 Warning! Not checking comments, when a comment start is embedded in strings,
309 may produce undesired results."
310 :type
'(choice (const exclusive
) (const :tag
"off" nil
) (const :tag
"on" t
))
313 (put 'ispell-check-comments
'safe-local-variable
314 (lambda (a) (memq a
'(nil t exclusive
))))
316 (defcustom ispell-query-replace-choices nil
317 "*Corrections made throughout region when non-nil.
318 Uses `query-replace' (\\[query-replace]) for corrections."
322 (defcustom ispell-skip-tib nil
323 "*Does not spell check `tib' bibliography references when non-nil.
324 Skips any text between strings matching regular expressions
325 `ispell-tib-ref-beginning' and `ispell-tib-ref-end'.
327 TeX users beware: Any text between [. and .] will be skipped -- even if
328 that's your whole buffer -- unless you set `ispell-skip-tib' to nil.
329 That includes the [.5mm] type of number..."
333 (defvar ispell-tib-ref-beginning
"[[<]\\."
334 "Regexp matching the beginning of a Tib reference.")
336 (defvar ispell-tib-ref-end
"\\.[]>]"
337 "Regexp matching the end of a Tib reference.")
339 (defcustom ispell-keep-choices-win t
340 "*If non-nil, keep the `*Choices*' window for the entire spelling session.
341 This minimizes redisplay thrashing."
345 (defcustom ispell-choices-win-default-height
2
346 "*The default size of the `*Choices*' window, including the mode line.
347 Must be greater than 1."
351 (defcustom ispell-program-name
352 (or (locate-file "aspell" exec-path exec-suffixes
'file-executable-p
)
353 (locate-file "ispell" exec-path exec-suffixes
'file-executable-p
)
354 (locate-file "hunspell" exec-path exec-suffixes
'file-executable-p
)
356 "Program invoked by \\[ispell-word] and \\[ispell-region] commands."
360 (defcustom ispell-alternate-dictionary
361 (cond ((file-readable-p "/usr/dict/web2") "/usr/dict/web2")
362 ((file-readable-p "/usr/share/dict/web2") "/usr/share/dict/web2")
363 ((file-readable-p "/usr/dict/words") "/usr/dict/words")
364 ((file-readable-p "/usr/lib/dict/words") "/usr/lib/dict/words")
365 ((file-readable-p "/usr/share/dict/words") "/usr/share/dict/words")
366 ((file-readable-p "/usr/share/lib/dict/words")
367 "/usr/share/lib/dict/words")
368 ((file-readable-p "/sys/dict") "/sys/dict"))
369 "*Alternate plain word-list dictionary for spelling help."
370 :type
'(choice file
(const :tag
"None" nil
))
373 (defcustom ispell-complete-word-dict nil
374 "*Plain word-list dictionary used for word completion if
375 different from `ispell-alternate-dictionary'."
376 :type
'(choice file
(const :tag
"None" nil
))
379 (defcustom ispell-message-dictionary-alist nil
380 "*List used by `ispell-message' to select a new dictionary.
381 It consists of pairs (REGEXP . DICTIONARY). If REGEXP is found
382 in the message headers, `ispell-local-dictionary' will be set to
383 DICTIONARY if `ispell-local-dictionary' is not buffer-local.
384 E.g. you may use the following value:
385 '((\"^Newsgroups:[ \\t]*de\\\\.\" . \"deutsch8\")
386 (\"^To:[^\\n,]+\\\\.de[ \\t\\n,>]\" . \"deutsch8\"))"
387 :type
'(repeat (cons regexp string
))
391 (defcustom ispell-message-fcc-skip
50000
392 "*Query before saving Fcc message copy if attachment larger than this value.
393 Always stores Fcc copy of message when nil."
394 :type
'(choice integer
(const :tag
"off" nil
))
398 (defcustom ispell-grep-command
399 ;; MS-Windows/MS-DOS have `egrep' as a Unix shell script, so they
400 ;; cannot invoke it. Use "grep -E" instead (see ispell-grep-options
402 (if (memq system-type
'(windows-nt ms-dos
)) "grep" "egrep")
403 "Name of the grep command for search processes."
407 (defcustom ispell-grep-options
408 (if (memq system-type
'(windows-nt ms-dos
)) "-Ei" "-i")
409 "String of options to use when running the program in `ispell-grep-command'.
410 Should probably be \"-i\" or \"-e\".
411 Some machines (like the NeXT) don't support \"-i\"."
415 (defcustom ispell-look-command
416 (cond ((file-exists-p "/bin/look") "/bin/look")
417 ((file-exists-p "/usr/local/bin/look") "/usr/local/bin/look")
418 ((file-exists-p "/usr/bin/look") "/usr/bin/look")
420 "Name of the look command for search processes.
421 This must be an absolute file name."
425 (defcustom ispell-look-p
(file-exists-p ispell-look-command
)
426 "*Non-nil means use `look' rather than `grep'.
427 Default is based on whether `look' seems to be available."
431 (defcustom ispell-have-new-look nil
432 "*Non-nil means use the `-r' option (regexp) when running `look'."
436 (defcustom ispell-look-options
(if ispell-have-new-look
"-dfr" "-df")
437 "String of command options for `ispell-look-command'."
441 (defcustom ispell-use-ptys-p nil
442 "When non-nil, Emacs uses ptys to communicate with Ispell.
443 When nil, Emacs uses pipes."
447 (defcustom ispell-following-word nil
448 "*Non-nil means `ispell-word' checks the word around or after point.
449 Otherwise `ispell-word' checks the preceding word."
453 (defcustom ispell-help-in-bufferp nil
454 "*Non-nil means display interactive keymap help in a buffer.
455 The following values are supported:
456 nil Expand the minibuffer and display a short help message
457 there for a couple of seconds.
458 t Pop up a new buffer and display a short help message there
459 for a couple of seconds.
460 electric Pop up a new buffer and display a long help message there.
461 User can browse and then exit the help mode."
462 :type
'(choice (const electric
) (const :tag
"off" nil
) (const :tag
"on" t
))
465 (defcustom ispell-quietly nil
466 "*Non-nil means suppress messages in `ispell-word'."
470 (defcustom ispell-format-word-function
(function upcase
)
471 "*Formatting function for displaying word being spell checked.
472 The function must take one string argument and return a string."
475 (defvaralias 'ispell-format-word
'ispell-format-word-function
)
477 (defcustom ispell-use-framepop-p nil
478 "When non-nil ispell uses framepop to display choices in a dedicated frame.
479 You can set this variable to dynamically use framepop if you are in a
480 window system by evaluating the following on startup to set this variable:
481 (and window-system (condition-case () (require 'framepop) (error nil)))"
486 (defcustom ispell-personal-dictionary nil
487 "*File name of your personal spelling dictionary, or nil.
488 If nil, the default personal dictionary, (\"~/.ispell_DICTNAME\" for ispell or
489 \"~/.aspell.LANG.pws\" for aspell) is used, where DICTNAME is the name of your
490 default dictionary and LANG the two letter language code."
492 (const :tag
"default" nil
))
495 (defcustom ispell-silently-savep nil
496 "*When non-nil, save personal dictionary without asking for confirmation."
500 (defvar ispell-local-dictionary-overridden nil
501 "Non-nil means the user has explicitly set this buffer's Ispell dictionary.")
502 (make-variable-buffer-local 'ispell-local-dictionary-overridden
)
504 (defcustom ispell-local-dictionary nil
505 "If non-nil, the dictionary to be used for Ispell commands in this buffer.
506 The value must be a string dictionary name,
507 or nil, which means use the global setting in `ispell-dictionary'.
508 Dictionary names are defined in `ispell-local-dictionary-alist'
509 and `ispell-dictionary-alist'.
511 Setting `ispell-local-dictionary' to a value has the same effect as
512 calling \\[ispell-change-dictionary] with that value. This variable
513 is automatically set when defined in the file with either
514 `ispell-dictionary-keyword' or the Local Variable syntax."
515 :type
'(choice string
516 (const :tag
"default" nil
))
519 (put 'ispell-local-dictionary
'safe-local-variable
'string-or-null-p
)
521 (make-variable-buffer-local 'ispell-local-dictionary
)
523 (defcustom ispell-dictionary nil
524 "Default dictionary to use if `ispell-local-dictionary' is nil."
525 :type
'(choice string
526 (const :tag
"default" nil
))
529 (defcustom ispell-extra-args nil
530 "*If non-nil, a list of extra switches to pass to the Ispell program.
531 For example, (\"-W\" \"3\") to cause it to accept all 1-3 character
532 words as correct. See also `ispell-dictionary-alist', which may be used
533 for language-specific arguments."
534 :type
'(repeat string
)
539 (defcustom ispell-skip-html
'use-mode-name
540 "*Indicates whether ispell should skip spell checking of SGML markup.
541 If t, always skip SGML markup; if nil, never skip; if non-t and non-nil,
542 guess whether SGML markup should be skipped according to the name of the
543 buffer's major mode."
544 :type
'(choice (const :tag
"always" t
) (const :tag
"never" nil
)
545 (const :tag
"use-mode-name" use-mode-name
))
548 (make-variable-buffer-local 'ispell-skip-html
)
551 (defcustom ispell-local-dictionary-alist nil
552 "*List of local or customized dictionary definitions.
553 These can override the values in `ispell-dictionary-alist'.
555 To make permanent changes to your dictionary definitions, you
556 will need to make your changes in this variable, save, and then
558 :type
'(repeat (list (choice :tag
"Dictionary"
559 (string :tag
"Dictionary name")
560 (const :tag
"default" nil
))
561 (regexp :tag
"Case characters")
562 (regexp :tag
"Non case characters")
563 (regexp :tag
"Other characters")
564 (boolean :tag
"Many other characters")
565 (repeat :tag
"Ispell command line args"
567 (choice :tag
"Extended character mode"
568 (const "~tex") (const "~plaintex")
569 (const "~nroff") (const "~list")
570 (const "~latin1") (const "~latin3")
571 (const :tag
"default" nil
))
572 (coding-system :tag
"Coding System")))
576 (defvar ispell-dictionary-base-alist
578 ;; The default dictionary. It may be English.aff, or any other
579 ;; dictionary depending on locale and such things. We should probably
580 ;; ask ispell what dictionary it's using, but until we do that, let's
581 ;; just use an approximate regexp.
582 "[[:alpha:]]" "[^[:alpha:]]" "[']" nil
("-B") nil iso-8859-1
)
583 ("american" ; Yankee English
584 "[A-Za-z]" "[^A-Za-z]" "[']" nil
("-B") nil iso-8859-1
)
585 ("brasileiro" ; Brazilian mode
586 "[A-Z\301\311\315\323\332\300\310\314\322\331\303\325\307\334\302\312\324a-z\341\351\355\363\372\340\350\354\362\371\343\365\347\374\342\352\364]"
587 "[^A-Z\301\311\315\323\332\300\310\314\322\331\303\325\307\334\302\312\324a-z\341\351\355\363\372\340\350\354\362\371\343\365\347\374\342\352\364]"
588 "[']" nil nil nil iso-8859-1
)
589 ("british" ; British version
590 "[A-Za-z]" "[^A-Za-z]" "[']" nil
("-B") nil iso-8859-1
)
591 ("castellano" ; Spanish mode
592 "[A-Z\301\311\315\321\323\332\334a-z\341\351\355\361\363\372\374]"
593 "[^A-Z\301\311\315\321\323\332\334a-z\341\351\355\361\363\372\374]"
594 "[-]" nil
("-B") "~tex" iso-8859-1
)
595 ("castellano8" ; 8 bit Spanish mode
596 "[A-Z\301\311\315\321\323\332\334a-z\341\351\355\361\363\372\374]"
597 "[^A-Z\301\311\315\321\323\332\334a-z\341\351\355\361\363\372\374]"
598 "[-]" nil
("-B" "-d" "castellano") "~latin1" iso-8859-1
)
600 "[A-Za-z\301\311\314\315\323\332\331\335\256\251\310\330\317\253\322\341\351\354\355\363\372\371\375\276\271\350\370\357\273\362]"
601 "[^A-Za-z\301\311\314\315\323\332\331\335\256\251\310\330\317\253\322\341\351\354\355\363\372\371\375\276\271\350\370\357\273\362]"
602 "" nil
("-B") nil iso-8859-2
)
604 "[A-Z\306\330\305a-z\346\370\345]" "[^A-Z\306\330\305a-z\346\370\345]"
605 "[']" nil
("-C") nil iso-8859-1
)
606 ("deutsch" ; Deutsch.aff
607 "[a-zA-Z\"]" "[^a-zA-Z\"]" "[']" t
("-C") "~tex" iso-8859-1
)
609 "[a-zA-Z\304\326\334\344\366\337\374]"
610 "[^a-zA-Z\304\326\334\344\366\337\374]"
611 "[']" t
("-C" "-d" "deutsch") "~latin1" iso-8859-1
)
612 ("english" ; make English explicitly selectable
613 "[A-Za-z]" "[^A-Za-z]" "[']" nil
("-B") nil iso-8859-1
)
615 "[A-Za-z\246\254\266\274\306\330\335\336\346\370\375\376]"
616 "[^A-Za-z\246\254\266\274\306\330\335\336\346\370\375\376]"
617 "[-']" t
("-C") "~latin3" iso-8859-3
)
619 "[A-Za-z^\\]" "[^A-Za-z^\\]"
620 "[-'`\"]" t
("-C" "-d" "esperanto") "~tex" iso-8859-3
)
622 "[A-Za-z\345\344\366\305\304\326]"
623 "[^A-Za-z\345\344\366\305\304\326]"
624 "[:]" nil
("-C") "~list" iso-8859-1
)
626 "[A-Za-z]" "[^A-Za-z]" "[`'^-]" t nil nil iso-8859-1
)
627 ("francais" ; Francais.aff
628 "[A-Za-z\300\302\306\307\310\311\312\313\316\317\324\331\333\334\340\342\347\350\351\352\353\356\357\364\371\373\374]"
629 "[^A-Za-z\300\302\306\307\310\311\312\313\316\317\324\331\333\334\340\342\347\350\351\352\353\356\357\364\371\373\374]"
630 "[-'.@]" t nil
"~list" iso-8859-1
)
631 ("francais-tex" ; Francais.aff
632 "[A-Za-z\300\302\306\307\310\311\312\313\316\317\324\331\333\334\340\342\347\350\351\352\353\356\357\364\371\373\374\\]"
633 "[^A-Za-z\300\302\306\307\310\311\312\313\316\317\324\331\333\334\340\342\347\350\351\352\353\356\357\364\371\373\374\\]"
634 "[-'^`\".@]" t nil
"~tex" iso-8859-1
)
635 ("german" ; german.aff
636 "[a-zA-Z\"]" "[^a-zA-Z\"]" "[']" t
("-C") "~tex" iso-8859-1
)
637 ("german8" ; german.aff
638 "[a-zA-Z\304\326\334\344\366\337\374]"
639 "[^a-zA-Z\304\326\334\344\366\337\374]"
640 "[']" t
("-C" "-d" "german") "~latin1" iso-8859-1
)
641 ("italiano" ; Italian.aff
642 "[A-Z\300\301\310\311\314\315\322\323\331\332a-z\340\341\350\351\354\355\363\371\372]"
643 "[^A-Z\300\301\310\311\314\315\322\323\331\332a-z\340\341\350\351\354\355\363\371\372]"
644 "[-.]" nil
("-B" "-d" "italian") "~tex" iso-8859-1
)
645 ("nederlands" ; Nederlands.aff
646 "[A-Za-z\300\301\302\303\304\305\307\310\311\312\313\314\315\316\317\322\323\324\325\326\331\332\333\334\340\341\342\343\344\345\347\350\351\352\353\354\355\356\357\361\362\363\364\365\366\371\372\373\374]"
647 "[^A-Za-z\300\301\302\303\304\305\307\310\311\312\313\314\315\316\317\322\323\324\325\326\331\332\333\334\340\341\342\343\344\345\347\350\351\352\353\354\355\356\357\361\362\363\364\365\366\371\372\373\374]"
648 "[']" t
("-C") nil iso-8859-1
)
649 ("nederlands8" ; Dutch8.aff
650 "[A-Za-z\300\301\302\303\304\305\307\310\311\312\313\314\315\316\317\322\323\324\325\326\331\332\333\334\340\341\342\343\344\345\347\350\351\352\353\354\355\356\357\361\362\363\364\365\366\371\372\373\374]"
651 "[^A-Za-z\300\301\302\303\304\305\307\310\311\312\313\314\315\316\317\322\323\324\325\326\331\332\333\334\340\341\342\343\344\345\347\350\351\352\353\354\355\356\357\361\362\363\364\365\366\371\372\373\374]"
652 "[']" t
("-C") nil iso-8859-1
)
653 ("norsk" ; 8 bit Norwegian mode
654 "[A-Za-z\305\306\307\310\311\322\324\330\345\346\347\350\351\362\364\370]"
655 "[^A-Za-z\305\306\307\310\311\322\324\330\345\346\347\350\351\362\364\370]"
656 "[\"]" nil nil
"~list" iso-8859-1
)
657 ("norsk7-tex" ; 7 bit Norwegian TeX mode
658 "[A-Za-z{}\\'^`]" "[^A-Za-z{}\\'^`]"
659 "[\"]" nil
("-d" "norsk") "~plaintex" iso-8859-1
)
660 ("polish" ; Polish mode
661 "[A-Za-z\241\243\246\254\257\261\263\266\274\277\306\312\321\323\346\352\361\363]"
662 "[^A-Za-z\241\243\246\254\257\261\263\266\274\277\306\312\321\323\346\352\361\363]"
663 "[.]" nil nil nil iso-8859-2
)
664 ("portugues" ; Portuguese mode
665 "[a-zA-Z\301\302\307\311\323\340\341\342\351\352\355\363\343\347\372]"
666 "[^a-zA-Z\301\302\307\311\323\340\341\342\351\352\355\363\343\347\372]"
667 "[']" t
("-C") "~latin1" iso-8859-1
)
668 ("russian" ; Russian.aff (KOI8-R charset)
669 "[\341\342\367\347\344\345\263\366\372\351\352\353\354\355\356\357\360\362\363\364\365\346\350\343\376\373\375\370\371\377\374\340\361\301\302\327\307\304\305\243\326\332\311\312\313\314\315\316\317\320\322\323\324\325\306\310\303\336\333\335\330\331\337\334\300\321]"
670 "[^\341\342\367\347\344\345\263\366\372\351\352\353\354\355\356\357\360\362\363\364\365\346\350\343\376\373\375\370\371\377\374\340\361\301\302\327\307\304\305\243\326\332\311\312\313\314\315\316\317\320\322\323\324\325\306\310\303\336\333\335\330\331\337\334\300\321]"
671 "" nil nil nil koi8-r
)
672 ("russianw" ; russianw.aff (CP1251 charset)
673 "[\300\301\302\303\304\305\250\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\334\333\332\335\336\337\340\341\342\343\344\345\270\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\374\373\372\375\376\377]"
674 "[^\300\301\302\303\304\305\250\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\334\333\332\335\336\337\340\341\342\343\344\345\270\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\374\373\372\375\376\377]"
675 "" nil nil nil windows-1251
)
676 ("slovak" ; Slovakian
677 "[A-Za-z\301\304\311\315\323\332\324\300\305\245\335\256\251\310\317\253\322\341\344\351\355\363\372\364\340\345\265\375\276\271\350\357\273\362]"
678 "[^A-Za-z\301\304\311\315\323\332\324\300\305\245\335\256\251\310\317\253\322\341\344\351\355\363\372\364\340\345\265\375\276\271\350\357\273\362]"
679 "" nil
("-B") nil iso-8859-2
)
680 ("slovenian" ; Slovenian
681 "[A-Za-z\301\304\311\315\323\332\324\300\305\245\335\256\251\310\317\253\322\341\344\351\355\363\372\364\340\345\265\375\276\271\350\357\273\362]"
682 "[^A-Za-z\301\304\311\315\323\332\324\300\305\245\335\256\251\310\317\253\322\341\344\351\355\363\372\364\340\345\265\375\276\271\350\357\273\362]"
683 "" nil
("-B" "-d" "slovenian") nil iso-8859-2
)
684 ("svenska" ; Swedish mode
685 "[A-Za-z\345\344\366\351\340\374\350\346\370\347\305\304\326\311\300\334\310\306\330\307]"
686 "[^A-Za-z\345\344\366\351\340\374\350\346\370\347\305\304\326\311\300\334\310\306\330\307]"
687 "[']" nil
("-C") "~list" iso-8859-1
))
688 "Base value for `ispell-dictionary-alist'.")
690 (defvar ispell-dictionary-alist nil
691 "An alist of dictionaries and their associated parameters.
693 Each element of this list is also a list:
695 \(DICTIONARY-NAME CASECHARS NOT-CASECHARS OTHERCHARS MANY-OTHERCHARS-P
696 ISPELL-ARGS EXTENDED-CHARACTER-MODE CHARACTER-SET\)
698 DICTIONARY-NAME is a possible string value of variable `ispell-dictionary',
699 nil means the default dictionary.
701 CASECHARS is a regular expression of valid characters that comprise a word.
703 NOT-CASECHARS is the opposite regexp of CASECHARS.
705 OTHERCHARS is a regexp of characters in the NOT-CASECHARS set but which can be
706 used to construct words in some special way. If OTHERCHARS characters follow
707 and precede characters from CASECHARS, they are parsed as part of a word,
708 otherwise they become word-breaks. As an example in English, assume the
709 regular expression \"[']\" for OTHERCHARS. Then \"they're\" and
710 \"Steven's\" are parsed as single words including the \"'\" character, but
711 \"Stevens'\" does not include the quote character as part of the word.
712 If you want OTHERCHARS to be empty, use the empty string.
713 Hint: regexp syntax requires the hyphen to be declared first here.
715 CASECHARS, NOT-CASECHARS, and OTHERCHARS must be unibyte strings
716 containing bytes of CHARACTER-SET. In addition, if they contain
717 non-ASCII bytes, the regular expression must be a single
718 `character set' construct that doesn't specify a character range
721 MANY-OTHERCHARS-P is non-nil when multiple OTHERCHARS are allowed in a word.
722 Otherwise only a single OTHERCHARS character is allowed to be part of any
725 ISPELL-ARGS is a list of additional arguments passed to the ispell
728 EXTENDED-CHARACTER-MODE should be used when dictionaries are used which
729 have been configured in an Ispell affix file. (For example, umlauts
730 can be encoded as \\\"a, a\\\", \"a, ...) Defaults are ~tex and ~nroff
731 in English. This has the same effect as the command-line `-T' option.
732 The buffer Major Mode controls Ispell's parsing in tex or nroff mode,
733 but the dictionary can control the extended character mode.
734 Both defaults can be overruled in a buffer-local fashion. See
735 `ispell-parsing-keyword' for details on this.
737 CHARACTER-SET used to encode text sent to the ispell subprocess
738 when the language uses non-ASCII characters.
740 Note that with \"ispell\" as the speller, the CASECHARS and
741 OTHERCHARS slots of the alist should contain the same character
742 set as casechars and otherchars in the LANGUAGE.aff file \(e.g.,
743 english.aff\). aspell and hunspell don't have this limitation.")
745 (defvar ispell-really-aspell nil
) ; Non-nil if we can use aspell extensions.
746 (defvar ispell-really-hunspell nil
) ; Non-nil if we can use hunspell extensions.
747 (defvar ispell-encoding8-command nil
748 "Command line option prefix to select encoding if supported, nil otherwise.
749 If setting the encoding is supported by spellchecker and is selectable from
750 the command line, this variable will contain \"--encoding=\" for aspell
751 and \"-i \" for hunspell, so the appropriate mime charset can be selected.
752 That will be set in `ispell-check-version' for hunspell >= 1.1.6 and
755 For aspell, non-nil also means to try to automatically find its dictionaries.
757 Earlier aspell versions do not consistently support charset encoding. Handling
758 this would require some extra guessing in `ispell-aspell-find-dictionary'.")
760 (defvar ispell-aspell-supports-utf8 nil
761 "Non-nil if aspell has consistent command line UTF-8 support. Obsolete.
762 ispell.el and flyspell.el will use for this purpose the more generic
763 variable `ispell-encoding8-command' for both aspell and hunspell. Is left
764 here just for backwards compatibility.")
766 (make-obsolete-variable 'ispell-aspell-supports-utf8
767 'ispell-encoding8-command
"23.1")
770 ;;; **********************************************************************
771 ;;; The following are used by ispell, and should not be changed.
772 ;;; **********************************************************************
776 ;; The version must be 3.1 or greater for this version of ispell.el
777 ;; There is an incompatibility between version 3.1.12 and lower versions.
778 (defconst ispell-required-version
'(3 1 12)
779 "Ispell versions with which this version of ispell.el is known to work.")
780 (defvar ispell-offset -
1
781 "Offset that maps protocol differences between ispell 3.1 versions.")
783 (defconst ispell-version
"ispell.el 3.6 - 7-Jan-2003")
786 (defun ispell-check-version (&optional interactivep
)
787 "Ensure that `ispell-program-name' is valid and has the correct version.
788 Returns version number if called interactively.
789 Otherwise returns the library directory name, if that is defined."
790 ;; This is a little wasteful as we actually launch ispell twice: once
791 ;; to make sure it's the right version, and once for real. But people
792 ;; get confused by version mismatches *all* the time (and I've got the
793 ;; email to prove it) so I think this is worthwhile. And the -v[ersion]
794 ;; option is the only way I can think of to do this that works with
795 ;; all versions, since versions earlier than 3.0.09 didn't identify
796 ;; themselves on startup.
798 (let ((default-directory (or (and (boundp 'temporary-file-directory
)
799 temporary-file-directory
)
801 result status ispell-program-version
)
804 (setq status
(ispell-call-process
805 ispell-program-name nil t nil
806 ;; aspell doesn't accept the -vv switch.
807 (let ((case-fold-search
808 (memq system-type
'(ms-dos windows-nt
)))
810 (file-name-nondirectory ispell-program-name
)))
811 ;; Assume anything that isn't `aspell' is Ispell.
812 (if (string-match "\\`aspell" speller
) "-v" "-vv"))))
813 (goto-char (point-min))
815 ;; report version information of ispell and ispell.el
818 (setq result
(concat (buffer-substring-no-properties (point-min)
822 (message "%s" result
))
823 ;; return library directory.
824 (if (re-search-forward "LIBDIR = \\\"\\([^ \t\n]*\\)\\\"" nil t
)
825 (setq result
(match-string 1))))
826 (goto-char (point-min))
827 (if (not (memq status
'(0 nil
)))
828 (error "%s exited with %s %s" ispell-program-name
829 (if (stringp status
) "signal" "code") status
))
831 ;; Get relevant version strings. Only xx.yy.... format works well
832 (let (case-fold-search)
833 (setq ispell-program-version
834 (and (search-forward-regexp "\\([0-9]+\\.[0-9\\.]+\\)" nil t
)
837 ;; Make sure these variables are (re-)initialized to the default value
838 (setq ispell-really-aspell nil
839 ispell-aspell-supports-utf8 nil
840 ispell-really-hunspell nil
841 ispell-encoding8-command nil
)
843 (goto-char (point-min))
844 (or (setq ispell-really-aspell
845 (and (search-forward-regexp
846 "(but really Aspell \\([0-9]+\\.[0-9\\.-]+\\)?)" nil t
)
848 (setq ispell-really-hunspell
849 (and (search-forward-regexp
850 "(but really Hunspell \\([0-9]+\\.[0-9\\.-]+\\)?)"
854 (let ((aspell-minver "0.50")
855 (aspell8-minver "0.60")
856 (ispell0-minver "3.1.0")
857 (ispell-minver "3.1.12")
858 (hunspell8-minver "1.1.6"))
860 (if (ispell-check-minver ispell0-minver ispell-program-version
)
861 (or (ispell-check-minver ispell-minver ispell-program-version
)
862 (setq ispell-offset
0))
863 (error "%s release %s or greater is required"
868 (ispell-really-aspell
869 (if (ispell-check-minver aspell-minver ispell-really-aspell
)
870 (if (ispell-check-minver aspell8-minver ispell-really-aspell
)
872 (setq ispell-aspell-supports-utf8 t
)
873 (setq ispell-encoding8-command
"--encoding=")))
874 (setq ispell-really-aspell nil
)))
875 (ispell-really-hunspell
876 (if (ispell-check-minver hunspell8-minver ispell-really-hunspell
)
877 (setq ispell-encoding8-command
"-i")
878 (setq ispell-really-hunspell nil
))))))
881 (defun ispell-call-process (&rest args
)
882 "Like `call-process' but defend against bad `default-directory'."
883 (let ((default-directory default-directory
))
884 (unless (and (file-directory-p default-directory
)
885 (file-readable-p default-directory
))
886 (setq default-directory
(expand-file-name "~/")))
887 (apply 'call-process args
)))
889 (defun ispell-call-process-region (&rest args
)
890 "Like `call-process-region' but defend against bad `default-directory'."
891 (let ((default-directory default-directory
))
892 (unless (and (file-directory-p default-directory
)
893 (file-readable-p default-directory
))
894 (setq default-directory
(expand-file-name "~/")))
895 (apply 'call-process-region args
)))
899 ;; The preparation of the menu bar menu must be autoloaded
900 ;; because otherwise this file gets autoloaded every time Emacs starts
901 ;; so that it can set up the menus and determine keyboard equivalents.
904 (defvar ispell-menu-map nil
"Key map for ispell menu.")
905 ;;; redo menu when loading ispell to get dictionary modifications
906 (setq ispell-menu-map nil
)
909 (defvar ispell-menu-xemacs nil
910 "Spelling menu for XEmacs.
911 If nil when package is loaded, a standard menu will be set,
912 and added as a submenu of the \"Edit\" menu.")
914 ;; Break out XEmacs menu and split into several calls to avoid having
915 ;; long lines in loaddefs.el. Detect need off following constant.
917 ;;; Set up dictionary
919 (defvar ispell-menu-map-needed
920 ;; only needed when not version 18 and not XEmacs.
921 (and (not ispell-menu-map
)
922 (not (featurep 'xemacs
))
925 (defvar ispell-library-directory
(condition-case ()
926 (ispell-check-version)
928 "Directory where ispell dictionaries reside.")
930 (defvar ispell-process nil
931 "The process object for Ispell.")
933 (defvar ispell-async-processp
(and (fboundp 'delete-process
)
934 (fboundp 'process-send-string
)
935 (fboundp 'accept-process-output
)
936 ;;(fboundp 'start-process)
937 ;;(fboundp 'set-process-filter)
938 ;;(fboundp 'process-kill-without-query)
940 "Non-nil means that the OS supports asynchronous processes.")
942 ;; Make ispell.el work better with aspell.
944 (defvar ispell-aspell-dictionary-alist nil
945 "An alist of parsed aspell dicts and associated parameters.
948 (defun ispell-find-aspell-dictionaries ()
949 "Find Aspell's dictionaries, and record in `ispell-dictionary-alist'."
950 (unless (and ispell-really-aspell ispell-encoding8-command
)
951 (error "This function only works with aspell >= 0.60"))
955 (ispell-call-process ispell-program-name nil t nil
"dicts")
957 ;; Search for the named dictionaries.
960 (mapcar #'ispell-aspell-find-dictionary dictionaries
))))
961 ;; Ensure aspell's alias dictionary will override standard
963 (setq found
(ispell-aspell-add-aliases found
))
964 ;; Merge into FOUND any elements from the standard ispell-dictionary-alist
965 ;; which have no element in FOUND at all.
966 (dolist (dict ispell-dictionary-alist
)
967 (unless (assoc (car dict
) found
)
968 (setq found
(nconc found
(list dict
)))))
969 (setq ispell-aspell-dictionary-alist found
)
970 ;; Add a default entry
972 '(nil "[[:alpha:]]" "[^[:alpha:]]" "[']" nil
("-B") nil utf-8
)))
973 (push default-dict ispell-aspell-dictionary-alist
))))
975 (defvar ispell-aspell-data-dir nil
976 "Data directory of Aspell.")
978 (defvar ispell-aspell-dict-dir nil
979 "Dictionary directory of Aspell.")
981 (defun ispell-get-aspell-config-value (key)
982 "Return value of Aspell configuration option KEY.
983 Assumes that value contains no whitespace."
985 (ispell-call-process ispell-program-name nil t nil
"config" key
)
986 (car (split-string (buffer-string)))))
988 (defun ispell-aspell-find-dictionary (dict-name)
989 "For aspell dictionary DICT-NAME, return a list of parameters if an
990 associated data file is found or nil otherwise. List format is that
991 of `ispell-dictionary-base-alist' elements."
992 ;; Make sure `ispell-aspell-data-dir' is defined
993 (or ispell-aspell-data-dir
994 (setq ispell-aspell-data-dir
995 (ispell-get-aspell-config-value "data-dir")))
996 ;; Try finding associated datafile
998 (concat ispell-aspell-data-dir
"/"
999 ;; Strip out variant, country code, etc.
1000 (and (string-match "^[[:alpha:]]+" dict-name
)
1001 (match-string 0 dict-name
)) ".dat"))
1003 (concat ispell-aspell-data-dir
"/"
1004 ;; Strip out anything but xx_YY.
1005 (and (string-match "^[[:alpha:]_]+" dict-name
)
1006 (match-string 0 dict-name
)) ".dat"))
1008 (if (file-readable-p datafile1
)
1010 (if (file-readable-p datafile2
)
1016 (insert-file-contents data-file
)
1017 ;; There is zero or one line with special characters declarations.
1018 (when (search-forward-regexp "^special" nil t
)
1019 (let ((specials (split-string
1020 (buffer-substring (point)
1021 (progn (end-of-line) (point))))))
1022 ;; The line looks like: special ' -** - -** . -** : -*-
1023 ;; -** means that this character
1024 ;; - doesn't appear at word start
1025 ;; * may appear in the middle of a word
1026 ;; * may appear at word end
1027 ;; `otherchars' is about the middle case.
1029 (when (eq (aref (cadr specials
) 1) ?
*)
1030 (push (car specials
) otherchars
))
1031 (setq specials
(cddr specials
)))))
1035 (regexp-opt otherchars
)
1036 t
; We can't tell, so set this to t
1037 (list "-d" dict-name
)
1038 nil
; aspell doesn't support this
1039 ;; Here we specify the encoding to use while communicating with
1040 ;; aspell. This doesn't apply to command line arguments, so
1041 ;; just don't pass words to spellcheck as arguments...
1044 (defun ispell-aspell-add-aliases (alist)
1045 "Find aspell's dictionary aliases and add them to dictionary ALIST.
1046 Return the new dictionary alist."
1048 (file-expand-wildcards
1049 (concat (or ispell-aspell-dict-dir
1050 (setq ispell-aspell-dict-dir
1051 (ispell-get-aspell-config-value "dict-dir")))
1053 (dolist (alias-file aliases
)
1055 (insert-file-contents alias-file
)
1056 ;; Look for a line "add FOO.multi", extract FOO
1057 (when (search-forward-regexp "^add \\([^.]+\\)\\.multi" nil t
)
1058 (let* ((aliasname (file-name-sans-extension
1059 (file-name-nondirectory alias-file
)))
1060 (already-exists-p (assoc aliasname alist
))
1061 (realname (match-string 1))
1062 (realdict (assoc realname alist
)))
1063 (when (and realdict
(not already-exists-p
))
1064 (push (cons aliasname
(cdr realdict
)) alist
))))))
1067 ;; Set params according to the selected spellchecker
1069 (defvar ispell-last-program-name nil
1070 "Last value of `ispell-program-name'. Internal use.")
1072 (defvar ispell-initialize-spellchecker-hook nil
1073 "Normal hook run on spellchecker initialization.
1074 This hook is run when a spellchecker is used for the first
1075 time, before `ispell-dictionary-alist' is set. It is intended for
1076 sysadmins to override entries in `ispell-dictionary-base-alist'
1077 by putting those overrides in `ispell-base-dicts-override-alist', which is
1078 a dynamically scoped var with same format as `ispell-dictionary-alist'.
1079 This alist will not override the auto-detected values (e.g. if a recent
1080 aspell is used along with Emacs).")
1082 (defun ispell-set-spellchecker-params ()
1083 "Initialize some spellchecker parameters when changed or first used."
1084 (unless (eq ispell-last-program-name ispell-program-name
)
1085 (setq ispell-last-program-name ispell-program-name
)
1086 (ispell-kill-ispell t
)
1087 (if (and (condition-case ()
1089 (setq ispell-library-directory
(ispell-check-version))
1092 ispell-really-aspell
1093 ispell-encoding8-command
1094 ;; XEmacs does not like [:alpha:] regexps.
1095 (string-match "^[[:alpha:]]+$" "abcde"))
1096 (unless ispell-aspell-dictionary-alist
1097 (ispell-find-aspell-dictionaries)))
1099 ;; Substitute ispell-dictionary-alist with the list of dictionaries
1100 ;; corresponding to the given spellchecker. If a recent aspell, use
1101 ;; the list of really installed dictionaries and add to it elements
1102 ;; of the original list that are not present there. Allow distro info.
1103 (let ((found-dicts-alist
1104 (if (and ispell-really-aspell
1105 ispell-encoding8-command
)
1106 ispell-aspell-dictionary-alist
1108 ispell-base-dicts-override-alist
; Override only base-dicts-alist
1111 (run-hooks 'ispell-initialize-spellchecker-hook
)
1113 ;; Add dicts to ``ispell-dictionary-alist'' unless already present.
1114 (dolist (dict (append found-dicts-alist
1115 ispell-base-dicts-override-alist
1116 ispell-dictionary-base-alist
))
1117 (unless (assoc (car dict
) all-dicts-alist
)
1118 (add-to-list 'all-dicts-alist dict
)))
1119 (setq ispell-dictionary-alist all-dicts-alist
))))
1122 (defun ispell-valid-dictionary-list ()
1123 "Return a list of valid dictionaries.
1124 The variable `ispell-library-directory' defines their location."
1125 ;; Initialize variables and dictionaries alists for desired spellchecker.
1126 ;; Make sure ispell.el is loaded to avoid some autoload loops in XEmacs
1127 ;; (and may be others)
1128 (if (featurep 'ispell
)
1129 (ispell-set-spellchecker-params))
1131 (let ((dicts (append ispell-local-dictionary-alist ispell-dictionary-alist
))
1132 (dict-list (cons "default" nil
))
1134 (dolist (dict dicts
)
1135 (setq name
(car dict
)
1136 dict-bname
(or (car (cdr (member "-d" (nth 5 dict
))))
1138 ;; Include if the dictionary is in the library, or dir not defined.
1141 ;; For Aspell, we already know which dictionaries exist.
1142 (or ispell-really-aspell
1143 ;; Include all dictionaries if lib directory not known.
1144 ;; Same for Hunspell, where ispell-library-directory is nil.
1145 (not ispell-library-directory
)
1146 (file-exists-p (concat ispell-library-directory
1147 "/" dict-bname
".hash"))
1148 (file-exists-p (concat ispell-library-directory
1149 "/" dict-bname
".has"))))
1150 (push name dict-list
)))
1153 ;;; define commands in menu in opposite order you want them to appear.
1155 (if ispell-menu-map-needed
1157 (setq ispell-menu-map
(make-sparse-keymap "Spell"))
1158 (define-key ispell-menu-map
[ispell-change-dictionary
]
1159 `(menu-item ,(purecopy "Change Dictionary...") ispell-change-dictionary
1160 :help
,(purecopy "Supply explicit dictionary file name")))
1161 (define-key ispell-menu-map
[ispell-kill-ispell
]
1162 `(menu-item ,(purecopy "Kill Process") ispell-kill-ispell
1163 :enable
(and (boundp 'ispell-process
) ispell-process
1164 (eq (ispell-process-status) 'run
))
1165 :help
,(purecopy "Terminate Ispell subprocess")))
1166 (define-key ispell-menu-map
[ispell-pdict-save
]
1167 `(menu-item ,(purecopy "Save Dictionary")
1168 (lambda () (interactive) (ispell-pdict-save t t
))
1169 :help
,(purecopy "Save personal dictionary")))
1170 (define-key ispell-menu-map
[ispell-customize
]
1171 `(menu-item ,(purecopy "Customize...")
1172 (lambda () (interactive) (customize-group 'ispell
))
1173 :help
,(purecopy "Customize spell checking options")))
1174 (define-key ispell-menu-map
[ispell-help
]
1175 ;; use (x-popup-menu last-nonmenu-event(list "" ispell-help-list)) ?
1176 `(menu-item ,(purecopy "Help")
1177 (lambda () (interactive) (describe-function 'ispell-help
))
1178 :help
,(purecopy "Show standard Ispell keybindings and commands")))
1179 (define-key ispell-menu-map
[flyspell-mode
]
1180 `(menu-item ,(purecopy "Automatic spell checking (Flyspell)")
1182 :help
,(purecopy "Check spelling while you edit the text")
1183 :button
(:toggle .
(bound-and-true-p flyspell-mode
))))
1184 (define-key ispell-menu-map
[ispell-complete-word
]
1185 `(menu-item ,(purecopy "Complete Word") ispell-complete-word
1186 :help
,(purecopy "Complete word at cursor using dictionary")))
1187 (define-key ispell-menu-map
[ispell-complete-word-interior-frag
]
1188 `(menu-item ,(purecopy "Complete Word Fragment")
1189 ispell-complete-word-interior-frag
1190 :help
,(purecopy "Complete word fragment at cursor")))))
1193 (if ispell-menu-map-needed
1195 (define-key ispell-menu-map
[ispell-continue
]
1196 `(menu-item ,(purecopy "Continue Spell-Checking") ispell-continue
1197 :enable
(and (boundp 'ispell-region-end
)
1198 (marker-position ispell-region-end
)
1199 (equal (marker-buffer ispell-region-end
)
1201 :help
,(purecopy "Continue spell checking last region")))
1202 (define-key ispell-menu-map
[ispell-word
]
1203 `(menu-item ,(purecopy "Spell-Check Word") ispell-word
1204 :help
,(purecopy "Spell-check word at cursor")))
1205 (define-key ispell-menu-map
[ispell-comments-and-strings
]
1206 `(menu-item ,(purecopy "Spell-Check Comments")
1207 ispell-comments-and-strings
1208 :help
,(purecopy "Spell-check only comments and strings")))))
1211 (if ispell-menu-map-needed
1213 (define-key ispell-menu-map
[ispell-region
]
1214 `(menu-item ,(purecopy "Spell-Check Region") ispell-region
1216 :help
,(purecopy "Spell-check text in marked region")))
1217 (define-key ispell-menu-map
[ispell-message
]
1218 `(menu-item ,(purecopy "Spell-Check Message") ispell-message
1219 :visible
(eq major-mode
'mail-mode
)
1220 :help
,(purecopy "Skip headers and included message text")))
1221 (define-key ispell-menu-map
[ispell-buffer
]
1222 `(menu-item ,(purecopy "Spell-Check Buffer") ispell-buffer
1223 :help
,(purecopy "Check spelling of selected buffer")))
1224 ;;(put 'ispell-region 'menu-enable 'mark-active)
1225 (fset 'ispell-menu-map
(symbol-value 'ispell-menu-map
))))
1227 ;;; XEmacs versions 19 & 20
1228 (if (and (featurep 'xemacs
)
1230 ;;(null ispell-menu-xemacs)
1231 (not (and (boundp 'infodock-version
) infodock-version
)))
1232 (let ((dicts (if (fboundp 'ispell-valid-dictionary-list
)
1233 (reverse (ispell-valid-dictionary-list))))
1234 (current-menubar (or current-menubar default-menubar
))
1236 '(["Help" (describe-function 'ispell-help
) t
]
1237 ;;["Help" (popup-menu ispell-help-list) t]
1238 ["Check Message" ispell-message t
]
1239 ["Check Buffer" ispell-buffer t
]
1240 ["Check Comments" ispell-comments-and-strings t
]
1241 ["Check Word" ispell-word t
]
1242 ["Check Region" ispell-region
(or (not zmacs-regions
) (mark))]
1243 ["Continue Check" ispell-continue t
]
1244 ["Complete Word Frag"ispell-complete-word-interior-frag t
]
1245 ["Complete Word" ispell-complete-word t
]
1246 ["Kill Process" ispell-kill-ispell t
]
1247 ["Customize..." (customize-group 'ispell
) t
]
1248 ;; flyspell-mode may not be bound...
1249 ;;["flyspell" flyspell-mode
1250 ;; :style toggle :selected flyspell-mode ]
1252 ["Save Personal Dict"(ispell-pdict-save t t
) t
]
1253 ["Change Dictionary" ispell-change-dictionary t
])))
1255 (setq dicts
(cons "default" nil
)))
1256 (dolist (name dicts
)
1257 (setq menu
(append menu
1260 (concat "Select " (capitalize name
))
1261 (list 'ispell-change-dictionary name
)
1263 (setq ispell-menu-xemacs menu
)
1266 (if (car (find-menu-item current-menubar
'("Cmds")))
1269 (delete-menu-item '("Cmds" "Spell-Check"))
1270 (add-menu '("Cmds") "Spell-Check" ispell-menu-xemacs
))
1272 (delete-menu-item '("Edit" "Spell")) ; in case already defined
1273 (add-menu '("Edit") "Spell" ispell-menu-xemacs
))))))
1275 (defalias 'ispell-int-char
1276 ;; Allow incrementing characters as integers in XEmacs 20
1277 (if (and (featurep 'xemacs
)
1278 (fboundp 'int-char
))
1280 ;; Emacs and XEmacs 19 or earlier
1284 ;;; **********************************************************************
1286 (defvar ispell-current-dictionary nil
1287 "The name of the current dictionary, or nil for the default.
1288 This is passed to the ispell process using the `-d' switch and is
1289 used as key in `ispell-local-dictionary-alist' and `ispell-dictionary-alist'.")
1291 (defvar ispell-current-personal-dictionary nil
1292 "The name of the current personal dictionary, or nil for the default.
1293 This is passed to the ispell process using the `-p' switch.")
1295 (defun ispell-decode-string (str)
1296 "Decodes multibyte character strings.
1297 Protects against bogus binding of `enable-multibyte-characters' in XEmacs."
1298 ;; FIXME: enable-multibyte-characters is read-only, so bogus bindings are
1299 ;; really nasty (they signal an error in Emacs): Who does that? --Stef
1300 (if (and (or (featurep 'xemacs
)
1301 (and (boundp 'enable-multibyte-characters
)
1302 enable-multibyte-characters
))
1303 (fboundp 'decode-coding-string
)
1304 (ispell-get-coding-system))
1305 (decode-coding-string str
(ispell-get-coding-system))
1308 ;; Return a string decoded from Nth element of the current dictionary.
1309 (defun ispell-get-decoded-string (n)
1310 "Get the decoded string in slot N of the descriptor of the current dict."
1312 (assoc ispell-current-dictionary ispell-local-dictionary-alist
)
1313 (assoc ispell-current-dictionary ispell-dictionary-alist
)
1314 (error "No data for dictionary \"%s\", neither in `ispell-local-dictionary-alist' nor in `ispell-dictionary-alist'"
1315 ispell-current-dictionary
)))
1317 (when (and (> (length str
) 0)
1318 (not (multibyte-string-p str
)))
1319 (setq str
(ispell-decode-string str
))
1320 (or (multibyte-string-p str
)
1321 (setq str
(string-to-multibyte str
))))
1324 (defun ispell-get-casechars ()
1325 (ispell-get-decoded-string 1))
1326 (defun ispell-get-not-casechars ()
1327 (ispell-get-decoded-string 2))
1328 (defun ispell-get-otherchars ()
1329 (ispell-get-decoded-string 3))
1330 (defun ispell-get-many-otherchars-p ()
1331 (nth 4 (or (assoc ispell-current-dictionary ispell-local-dictionary-alist
)
1332 (assoc ispell-current-dictionary ispell-dictionary-alist
))))
1333 (defun ispell-get-ispell-args ()
1334 (nth 5 (or (assoc ispell-current-dictionary ispell-local-dictionary-alist
)
1335 (assoc ispell-current-dictionary ispell-dictionary-alist
))))
1336 (defun ispell-get-extended-character-mode ()
1337 (if ispell-really-hunspell
;; hunspell treats ~word as ordinary words
1338 nil
;; in pipe mode. Disable extended-char-mode
1339 (nth 6 (or (assoc ispell-current-dictionary ispell-local-dictionary-alist
)
1340 (assoc ispell-current-dictionary ispell-dictionary-alist
)))))
1341 (defun ispell-get-coding-system ()
1342 (nth 7 (or (assoc ispell-current-dictionary ispell-local-dictionary-alist
)
1343 (assoc ispell-current-dictionary ispell-dictionary-alist
))))
1346 (defvar ispell-pdict-modified-p nil
1347 "Non-nil means personal dictionary has modifications to be saved.")
1349 ;;; If you want to save the dictionary when quitting, must do so explicitly.
1350 ;;; When non-nil, the spell session is terminated.
1351 ;;; When numeric, contains cursor location in buffer, and cursor remains there.
1352 (defvar ispell-quit nil
)
1354 (defvar ispell-process-directory nil
1355 "The directory where `ispell-process' was started.")
1357 (defvar ispell-filter nil
1358 "Output filter from piped calls to Ispell.")
1360 (defvar ispell-filter-continue nil
1361 "Control variable for Ispell filter function.")
1363 (defvar ispell-output-buffer nil
1364 "Buffer used for reading output of a synchronous Ispell subprocess.")
1366 (defvar ispell-session-buffer nil
1367 "Buffer used for passing input to a synchronous Ispell subprocess.")
1369 (defvar ispell-cmd-args nil
1370 "Command-line arguments to pass to a synchronous Ispell subprocess.")
1372 (defvar ispell-query-replace-marker
(make-marker)
1373 "Marker for `query-replace' processing.")
1375 (defvar ispell-recursive-edit-marker
(make-marker)
1376 "Marker for return point from recursive edit.")
1378 (defvar ispell-checking-message nil
1379 "Non-nil when we're checking a mail message.
1380 Set to the MIME boundary locations when checking messages.")
1382 (defconst ispell-choices-buffer
"*Choices*")
1384 (defvar ispell-overlay nil
"Overlay variable for Ispell highlighting.")
1386 ;;; *** Buffer Local Definitions ***
1388 (defconst ispell-words-keyword
"LocalWords: "
1389 "The keyword for local oddly-spelled words to accept.
1390 The keyword will be followed by any number of local word spellings.
1391 There can be multiple instances of this keyword in the file.")
1393 (defconst ispell-dictionary-keyword
"Local IspellDict: "
1394 "The keyword for a local dictionary to use.
1395 The keyword must be followed by a valid dictionary name, defined in
1396 `ispell-local-dictionary-alist' or `ispell-dictionary-alist'.
1397 When multiple occurrences exist, the last keyword
1398 definition is used.")
1400 (defconst ispell-pdict-keyword
"Local IspellPersDict: "
1401 "The keyword for defining buffer local dictionaries.
1402 Keyword must be followed by the filename of a personal dictionary.
1403 The last occurring definition in the buffer will be used.")
1405 (defconst ispell-parsing-keyword
"Local IspellParsing: "
1406 "The keyword for overriding default Ispell parsing.
1407 The above keyword string should be followed by `latex-mode' or
1408 `nroff-mode' to put the current buffer into the desired parsing mode.
1410 Extended character mode can be changed for this buffer by placing
1411 a `~' followed by an extended-character mode -- such as `~.tex'.
1412 The last occurring definition in the buffer will be used.")
1415 (defvar ispell-skip-region-alist
1416 `((ispell-words-keyword forward-line
)
1417 (ispell-dictionary-keyword forward-line
)
1418 (ispell-pdict-keyword forward-line
)
1419 (ispell-parsing-keyword forward-line
)
1420 (,(purecopy "^---*BEGIN PGP [A-Z ]*--*")
1421 .
,(purecopy "^---*END PGP [A-Z ]*--*"))
1422 ;; assume multiline uuencoded file? "\nM.*$"?
1423 (,(purecopy "^begin [0-9][0-9][0-9] [^ \t]+$") .
,(purecopy "\nend\n"))
1424 (,(purecopy "^%!PS-Adobe-[123].0") .
,(purecopy "\n%%EOF\n"))
1425 (,(purecopy "^---* \\(Start of \\)?[Ff]orwarded [Mm]essage")
1426 .
,(purecopy "^---* End of [Ff]orwarded [Mm]essage"))
1427 ;; Matches e-mail addresses, file names, http addresses, etc. The
1428 ;; `-+' `_+' patterns are necessary for performance reasons when
1429 ;; `-' or `_' part of word syntax.
1430 (,(purecopy "\\(--+\\|_+\\|\\(/\\w\\|\\(\\(\\w\\|[-_]\\)+[.:@]\\)\\)\\(\\w\\|[-_]\\)*\\([.:/@]+\\(\\w\\|[-_~=?&]\\)+\\)+\\)"))
1431 ;; above checks /.\w sequences
1432 ;;("\\(--+\\|\\(/\\|\\(\\(\\w\\|[-_]\\)+[.:@]\\)\\)\\(\\w\\|[-_]\\)*\\([.:/@]+\\(\\w\\|[-_~=?&]\\)+\\)+\\)")
1433 ;; This is a pretty complex regexp. It can be simplified to the following:
1434 ;; "\\(\\w\\|[-_]\\)*\\([.:/@]+\\(\\w\\|[-_]\\|~\\)+\\)+"
1435 ;; but some valid text will be skipped, e.g. "his/her". This could be
1436 ;; fixed up (at the expense of a moderately more complex regexp)
1437 ;; by not allowing "/" to be the character which triggers the
1438 ;; identification of the computer name, e.g.:
1439 ;; "\\(\\w\\|[-_]\\)+[.:@]\\(\\w\\|[-_]\\)*\\([.:/@]+\\(\\w\\|[-_]\\|~\\)+\\)+"
1441 "Alist expressing beginning and end of regions not to spell check.
1442 The alist key must be a regular expression.
1443 Valid forms include:
1444 (KEY) - just skip the key.
1445 (KEY . REGEXP) - skip to the end of REGEXP. REGEXP may be string or symbol.
1446 (KEY REGEXP) - skip to end of REGEXP. REGEXP must be a string.
1447 (KEY FUNCTION ARGS) - FUNCTION called with ARGS returns end of region.")
1448 (put 'ispell-skip-region-alist
'risky-local-variable t
)
1452 (defvar ispell-tex-skip-alists
1454 '((;;("%\\[" . "%\\]") ; AMStex block comment...
1455 ;; All the standard LaTeX keywords from L. Lamport's guide:
1456 ;; \cite, \hspace, \hspace*, \hyphenation, \include, \includeonly, \input,
1457 ;; \label, \nocite, \rule (in ispell - rest included here)
1458 ("\\\\addcontentsline" ispell-tex-arg-end
2)
1459 ("\\\\add\\(tocontents\\|vspace\\)" ispell-tex-arg-end
)
1460 ("\\\\\\([aA]lph\\|arabic\\)" ispell-tex-arg-end
)
1461 ;;("\\\\author" ispell-tex-arg-end)
1462 ("\\\\bibliographystyle" ispell-tex-arg-end
)
1463 ("\\\\makebox" ispell-tex-arg-end
0)
1464 ("\\\\e?psfig" ispell-tex-arg-end
)
1465 ("\\\\document\\(class\\|style\\)" .
1466 "\\\\begin[ \t\n]*{[ \t\n]*document[ \t\n]*}"))
1467 (;; delimited with \begin. In ispell: displaymath, eqnarray, eqnarray*,
1468 ;; equation, minipage, picture, tabular, tabular* (ispell)
1469 ("\\(figure\\|table\\)\\*?" ispell-tex-arg-end
0)
1470 ("list" ispell-tex-arg-end
2)
1471 ("program" .
"\\\\end[ \t\n]*{[ \t\n]*program[ \t\n]*}")
1472 ("verbatim\\*?" .
"\\\\end[ \t\n]*{[ \t\n]*verbatim\\*?[ \t\n]*}"))))
1473 "*Lists of regions to be skipped in TeX mode.
1474 First list is used raw.
1475 Second list has key placed inside \\begin{}.
1477 Delete or add any regions you want to be automatically selected
1478 for skipping in latex mode.")
1479 (put 'ispell-tex-skip-alist
'risky-local-variable t
)
1483 (defconst ispell-html-skip-alists
1484 '(("<[cC][oO][dD][eE]\\>[^>]*>" "</[cC][oO][dD][eE]*>")
1485 ("<[sS][cC][rR][iI][pP][tT]\\>[^>]*>" "</[sS][cC][rR][iI][pP][tT]>")
1486 ("<[aA][pP][pP][lL][eE][tT]\\>[^>]*>" "</[aA][pP][pP][lL][eE][tT]>")
1487 ("<[vV][eE][rR][bB]\\>[^>]*>" "<[vV][eE][rR][bB]\\>[^>]*>")
1488 ;;("<[tT][tT]\\>[^>]*>" "<[tT][tT]\\>[^>]*>")
1491 ("&[^ \t\n;]" "[; \t\n]"))
1492 "*Lists of start and end keys to skip in HTML buffers.
1493 Same format as `ispell-skip-region-alist'.
1494 Note - substrings of other matches must come last
1495 (e.g. \"<[tT][tT]/\" and \"<[^ \\t\\n>]\").")
1496 (put 'ispell-html-skip-alists
'risky-local-variable t
)
1498 (defvar ispell-local-pdict ispell-personal-dictionary
1499 "A buffer local variable containing the current personal dictionary.
1500 If non-nil, the value must be a string, which is a file name.
1502 If you specify a personal dictionary for the current buffer which is
1503 different from the current personal dictionary, the effect is similar
1504 to calling \\[ispell-change-dictionary]. This variable is automatically
1505 set when defined in the file with either `ispell-pdict-keyword' or the
1506 local variable syntax.")
1508 (make-variable-buffer-local 'ispell-local-pdict
)
1509 ;;;###autoload(put 'ispell-local-pdict 'safe-local-variable 'stringp)
1511 (defvar ispell-buffer-local-name nil
1512 "Contains the buffer name if local word definitions were used.
1513 Ispell is then restarted because the local words could conflict.")
1515 (defvar ispell-parser
'use-mode-name
1516 "*Indicates whether ispell should parse the current buffer as TeX Code.
1517 Special value `use-mode-name' tries to guess using the name of `major-mode'.
1518 Default parser is `nroff'.
1519 Currently the only other valid parser is `tex'.
1521 You can set this variable in hooks in your init file -- eg:
1523 \(add-hook 'tex-mode-hook (lambda () (setq ispell-parser 'tex)))")
1525 (defvar ispell-region-end
(make-marker)
1526 "Marker that allows spelling continuations.")
1528 (defvar ispell-check-only nil
1529 "If non-nil, `ispell-word' does not try to correct the word.")
1532 ;;; **********************************************************************
1533 ;;; **********************************************************************
1537 ;;;###autoload (define-key esc-map "$" 'ispell-word)
1540 (defun ispell-accept-output (&optional timeout-secs timeout-msecs
)
1541 "Wait for output from ispell process, or TIMEOUT-SECS and TIMEOUT-MSECS.
1542 If asynchronous subprocesses are not supported, call `ispell-filter' and
1543 pass it the output of the last ispell invocation."
1544 (if ispell-async-processp
1545 (accept-process-output ispell-process timeout-secs timeout-msecs
)
1546 (if (null ispell-process
)
1547 (error "No Ispell process to read output from!")
1548 (let ((buf ispell-output-buffer
)
1550 (if (not (bufferp buf
))
1551 (setq ispell-filter nil
)
1552 (with-current-buffer buf
1553 (setq ispell-output
(buffer-substring-no-properties
1554 (point-min) (point-max))))
1555 (ispell-filter t ispell-output
)
1556 (with-current-buffer buf
1557 (erase-buffer)))))))
1559 (defun ispell-send-replacement (misspelled replacement
)
1560 "Notify aspell that MISSPELLED should be spelled REPLACEMENT.
1561 This allows it to improve the suggestion list based on actual misspellings."
1562 (and ispell-really-aspell
1563 (ispell-send-string (concat "$$ra " misspelled
"," replacement
"\n"))))
1566 (defun ispell-send-string (string)
1567 "Send the string STRING to the Ispell process."
1568 (if ispell-async-processp
1569 (process-send-string ispell-process string
)
1570 ;; Asynchronous subprocesses aren't supported on this losing system.
1571 ;; We keep all the directives passed to Ispell during the entire
1572 ;; session in a buffer, and pass them anew each time we invoke
1573 ;; Ispell to process another chunk of text. (Yes, I know this is a
1574 ;; terrible kludge, and it's a bit slow, but it does get the work done.)
1575 (let ((cmd (aref string
0))
1576 ;; The following commands are not passed to Ispell until
1577 ;; we have a *real* reason to invoke it.
1578 (cmds-to-defer '(?
* ?
@ ?~ ?
+ ?- ?
! ?%
))
1579 (session-buf ispell-session-buffer
)
1580 (output-buf ispell-output-buffer
)
1581 (ispell-args ispell-cmd-args
)
1582 (defdir ispell-process-directory
)
1584 (with-current-buffer session-buf
1585 (setq prev-pos
(point))
1586 (setq default-directory defdir
)
1588 (if (not (memq cmd cmds-to-defer
))
1589 (let (coding-system-for-read coding-system-for-write status
)
1590 (if (and (boundp 'enable-multibyte-characters
)
1591 enable-multibyte-characters
)
1592 (setq coding-system-for-read
(ispell-get-coding-system)
1593 coding-system-for-write
(ispell-get-coding-system)))
1594 (set-buffer output-buf
)
1596 (set-buffer session-buf
)
1598 (apply 'ispell-call-process-region
1599 (point-min) (point-max)
1600 ispell-program-name nil
1603 ;; hunspell -m option means something different
1604 (if ispell-really-hunspell
"" "-m")
1606 (set-buffer output-buf
)
1607 (goto-char (point-min))
1609 (if (not (looking-at "@(#) "))
1610 (error "Ispell error: %s"
1611 (buffer-substring-no-properties
1612 (point) (progn (end-of-line) (point)))))
1613 ;; If STRING is "^Z\n", we just started Ispell and need
1614 ;; to retain its version ID line in the output buffer.
1615 ;; Otherwise, remove the ID line, as it will confuse
1617 (or (string= string
"\032\n")
1620 (delete-region (point-min) (point))))
1621 ;; If STRING begins with ^ or any normal character, we need
1622 ;; to remove the last line from the session buffer, since it
1623 ;; was just spell-checked, and we don't want to check it again.
1624 ;; The same goes for the # command, since Ispell already saved
1625 ;; the personal dictionary.
1626 (set-buffer session-buf
)
1627 (delete-region prev-pos
(point))
1628 ;; Ispell run synchronously saves the personal dictionary
1629 ;; after each successful command. So we can remove any
1630 ;; lines in the session buffer that insert words into the
1632 (if (memq status
'(0 nil
))
1633 (let ((more-lines t
))
1634 (goto-char (point-min))
1636 (if (looking-at "^\\*")
1637 (let ((start (point)))
1639 (delete-region start
(point)))
1640 (setq more-lines
(= 0 (forward-line))))))))))))))
1643 ;; Insert WORD while possibly translating characters by
1644 ;; translation-table-for-input.
1645 (defun ispell-insert-word (word)
1646 (let ((pos (point)))
1648 ;; Avoid "obsolete" warnings for translation-table-for-input.
1650 (if (char-table-p translation-table-for-input
)
1651 (translate-region pos
(point) translation-table-for-input
)))))
1654 (defun ispell-word (&optional following quietly continue region
)
1655 "Check spelling of word under or before the cursor.
1656 If the word is not found in dictionary, display possible corrections
1657 in a window allowing you to choose one.
1659 If optional argument FOLLOWING is non-nil or if `ispell-following-word'
1660 is non-nil when called interactively, then the following word
1661 \(rather than preceding\) is checked when the cursor is not over a word.
1662 When the optional argument QUIETLY is non-nil or `ispell-quietly' is non-nil
1663 when called interactively, non-corrective messages are suppressed.
1665 With a prefix argument (or if CONTINUE is non-nil),
1666 resume interrupted spell-checking of a buffer or region.
1668 Interactively, in Transient Mark mode when the mark is active, call
1669 `ispell-region' to check the active region for spelling errors.
1671 Word syntax is controlled by the definition of the chosen dictionary,
1672 which is in `ispell-local-dictionary-alist' or `ispell-dictionary-alist'.
1674 This will check or reload the dictionary. Use \\[ispell-change-dictionary]
1675 or \\[ispell-region] to update the Ispell process.
1678 nil word is correct or spelling is accepted.
1679 0 word is inserted into buffer-local definitions.
1680 \"word\" word corrected from word list.
1681 \(\"word\" arg\) word is hand entered.
1682 quit spell session exited."
1683 (interactive (list ispell-following-word ispell-quietly current-prefix-arg t
))
1685 ((and region
(use-region-p))
1686 (ispell-region (region-beginning) (region-end)))
1687 (continue (ispell-continue))
1689 (ispell-set-spellchecker-params) ; Initialize variables and dicts alists
1690 (ispell-accept-buffer-local-defs) ; use the correct dictionary
1691 (let ((cursor-location (point)) ; retain cursor location
1692 (word (ispell-get-word following
))
1693 start end poss new-word replace
)
1694 ;; De-structure return word info list.
1695 (setq start
(car (cdr word
))
1696 end
(car (cdr (cdr word
)))
1699 ;; At this point it used to ignore 2-letter words.
1700 ;; But that is silly; if the user asks for it, we should do it. - rms.
1702 (message "Checking spelling of %s..."
1703 (funcall ispell-format-word-function word
)))
1704 (ispell-send-string "%\n") ; put in verbose mode
1705 (ispell-send-string (concat "^" word
"\n"))
1706 ;; wait until ispell has processed word
1708 (ispell-accept-output)
1709 (not (string= "" (car ispell-filter
)))))
1710 ;;(ispell-send-string "!\n") ;back to terse mode.
1711 (setq ispell-filter
(cdr ispell-filter
)) ; remove extra \n
1712 (if (and ispell-filter
(listp ispell-filter
))
1713 (if (> (length ispell-filter
) 1)
1714 (error "Ispell and its process have different character maps")
1715 (setq poss
(ispell-parse-output (car ispell-filter
)))))
1718 (message "%s is correct"
1719 (funcall ispell-format-word-function word
)))
1720 (and (featurep 'xemacs
)
1722 (and (fboundp 'delete-extent
)
1723 (delete-extent (extent-at start
)))))
1726 (message "%s is correct because of root %s"
1727 (funcall ispell-format-word-function word
)
1728 (funcall ispell-format-word-function poss
)))
1729 (and (featurep 'xemacs
)
1731 (and (fboundp 'delete-extent
)
1732 (delete-extent (extent-at start
)))))
1734 (message "Error checking word %s using %s with %s dictionary"
1735 (funcall ispell-format-word-function word
)
1736 (file-name-nondirectory ispell-program-name
)
1737 (or ispell-current-dictionary
"default")))
1738 (ispell-check-only ; called from ispell minor mode.
1739 (if (fboundp 'make-extent
)
1740 (if (fboundp 'set-extent-property
)
1741 (let ((ext (make-extent start end
)))
1742 (set-extent-property ext
'face ispell-highlight-face
)
1743 (set-extent-property ext
'priority
2000)))
1745 (message "%s is incorrect"
1746 (funcall ispell-format-word-function word
))))
1747 (t ; prompt for correct word.
1748 (save-window-excursion
1749 (setq replace
(ispell-command-loop
1750 (car (cdr (cdr poss
)))
1751 (car (cdr (cdr (cdr poss
))))
1752 (car poss
) start end
)))
1753 (cond ((equal 0 replace
)
1754 (ispell-add-per-file-word-list (car poss
)))
1756 (setq new-word
(if (atom replace
) replace
(car replace
))
1757 cursor-location
(+ (- (length word
) (- end start
))
1759 (if (not (equal new-word
(car poss
)))
1762 ;; Insert first and then delete,
1763 ;; to avoid collapsing markers before and after
1764 ;; into a single place.
1765 (ispell-insert-word new-word
)
1766 (delete-region (point) end
)
1767 ;; It is meaningless to preserve the cursor position
1768 ;; inside a word that has changed.
1769 (setq cursor-location
(point))
1770 (setq end
(point))))
1771 (if (not (atom replace
)) ;recheck spelling of replacement
1773 (if (car (cdr replace
)) ; query replace requested
1774 (save-window-excursion
1775 (query-replace word new-word t
)))
1777 ;; single word could be split into multiple words
1778 (setq ispell-quit
(not (ispell-region start end
)))
1780 ;; keep if rechecking word and we keep choices win.
1781 (if (get-buffer ispell-choices-buffer
)
1782 (kill-buffer ispell-choices-buffer
))))
1783 (ispell-pdict-save ispell-silently-savep
)
1784 ;; NB: Cancels ispell-quit incorrectly if called from ispell-region
1785 (if ispell-quit
(setq ispell-quit nil replace
'quit
))
1786 (goto-char cursor-location
) ; return to original location
1790 (defun ispell-get-word (following &optional extra-otherchars
)
1791 "Return the word for spell-checking according to ispell syntax.
1792 If optional argument FOLLOWING is non-nil or if `ispell-following-word'
1793 is non-nil when called interactively, then the following word
1794 \(rather than preceding\) is checked when the cursor is not over a word.
1795 Optional second argument contains otherchars that can be included in word
1796 many times (see the doc string of `ispell-dictionary-alist' for details
1799 Word syntax is controlled by the definition of the chosen dictionary,
1800 which is in `ispell-local-dictionary-alist' or `ispell-dictionary-alist'."
1801 (ispell-set-spellchecker-params) ; Initialize variables and dicts alists
1802 (let* ((ispell-casechars (ispell-get-casechars))
1803 (ispell-not-casechars (ispell-get-not-casechars))
1804 (ispell-otherchars (ispell-get-otherchars))
1805 (ispell-many-otherchars-p (ispell-get-many-otherchars-p))
1806 (word-regexp (concat ispell-casechars
1808 (if (not (string= "" ispell-otherchars
))
1809 (concat ispell-otherchars
"?"))
1810 (if extra-otherchars
1811 (concat extra-otherchars
"?"))
1814 (if (or ispell-many-otherchars-p
1820 (if (not (looking-at ispell-casechars
))
1822 (re-search-forward ispell-casechars
(point-max) t
)
1823 (re-search-backward ispell-casechars
(point-min) t
)))
1824 ;; move to front of word
1825 (re-search-backward ispell-not-casechars
(point-min) 'start
)
1826 (while (and (or (and (not (string= "" ispell-otherchars
))
1827 (looking-at ispell-otherchars
))
1828 (and extra-otherchars
(looking-at extra-otherchars
)))
1830 (or (not did-it-once
)
1831 ispell-many-otherchars-p
)
1832 (not (eq prevpt
(point))))
1833 (if (and extra-otherchars
(looking-at extra-otherchars
))
1836 (if (looking-at ispell-casechars
)
1837 (re-search-backward ispell-not-casechars
(point-min) 'move
)))
1841 (if (looking-at ispell-casechars
)
1842 (re-search-backward ispell-not-casechars
(point-min) 'move
)
1843 (backward-char -
1))))
1844 ;; Now mark the word and save to string.
1845 (if (not (re-search-forward word-regexp
(point-max) t
))
1846 (if ispell-check-only
1847 ;; return dummy word when just flagging misspellings
1848 (list "" (point) (point))
1849 (error "No word found to check!"))
1850 (setq start
(copy-marker (match-beginning 0))
1852 word
(buffer-substring-no-properties start end
))
1853 (list word start end
))))
1856 ;;; Global ispell-pdict-modified-p is set by ispell-command-loop and
1857 ;;; tracks changes in the dictionary. The global may either be
1858 ;;; a value or a list, whose value is the state of whether the
1859 ;;; dictionary needs to be saved.
1862 (defun ispell-pdict-save (&optional no-query force-save
)
1863 "Check to see if the personal dictionary has been modified.
1864 If so, ask if it needs to be saved."
1865 (interactive (list ispell-silently-savep t
))
1866 (if (and ispell-pdict-modified-p
(listp ispell-pdict-modified-p
))
1867 (setq ispell-pdict-modified-p
(car ispell-pdict-modified-p
)))
1868 (if (or ispell-pdict-modified-p force-save
)
1869 (if (or no-query
(y-or-n-p "Personal dictionary modified. Save? "))
1871 (ispell-send-string "#\n") ; save dictionary
1872 (message "Personal dictionary saved."))))
1873 ;; unassert variable, even if not saved to avoid questioning.
1874 (setq ispell-pdict-modified-p nil
))
1877 (defun ispell-command-loop (miss guess word start end
)
1878 "Display possible corrections from list MISS.
1879 GUESS lists possibly valid affix construction of WORD.
1880 Returns nil to keep word.
1881 Returns 0 to insert locally into buffer-local dictionary.
1882 Returns string for new chosen word.
1883 Returns list for new replacement word (will be rechecked).
1884 Query-replace when list length is 2.
1885 Automatic query-replace when second element is `query-replace'.
1886 Highlights the word, which is assumed to run from START to END.
1887 Global `ispell-pdict-modified-p' becomes a list where the only value
1888 indicates whether the dictionary has been modified when option `a'
1890 Global `ispell-quit' set to start location to continue spell session."
1892 (line ispell-choices-win-default-height
)
1893 ;; ensure 4 context lines.
1894 (max-lines (- (ispell-adjusted-window-height) 4))
1896 (window-min-height (min window-min-height
1897 ispell-choices-win-default-height
))
1898 (command-characters '( ? ?i ?a ?A ?r ?R ?? ?x ?X ?q ?l ?u ?m
))
1899 (dedicated (window-dedicated-p (selected-window)))
1901 char num result textwin dedicated-win
)
1903 ;; setup the *Choices* buffer with valid data.
1904 (with-current-buffer (get-buffer-create ispell-choices-buffer
)
1905 (setq mode-line-format
1907 "-- %b -- word: " word
1908 " -- dict: " (or ispell-current-dictionary
"default")
1909 " -- prog: " (file-name-nondirectory ispell-program-name
)))
1910 ;; XEmacs: no need for horizontal scrollbar in choices window
1912 (and (fboundp 'set-specifier
)
1913 (boundp 'horizontal-scrollbar-visible-p
)
1914 (set-specifier horizontal-scrollbar-visible-p nil
1915 (cons (current-buffer) nil
))))
1919 (insert "Affix rules generate and capitalize "
1920 "this word as shown below:\n\t")
1922 (if (> (+ 4 (current-column) (length (car guess
)))
1926 (setq line
(1+ line
))))
1927 (insert (car guess
) " ")
1928 (setq guess
(cdr guess
)))
1929 (insert "\nUse option `i' to accept this spelling and put it in your private dictionary.\n")
1930 (setq line
(+ line
(if choices
3 2)))))
1932 (< (if (> (+ 7 (current-column) (length (car choices
))
1933 (if (> count ?~
) 3 0))
1937 (setq line
(1+ line
)))
1940 ;; not so good if there are over 20 or 30 options, but then, if
1941 ;; there are that many you don't want to scan them all anyway...
1942 (while (memq count command-characters
) ; skip command characters.
1943 (setq count
(ispell-int-char (1+ count
))
1944 skipped
(1+ skipped
)))
1945 (insert "(" count
") " (car choices
) " ")
1946 (setq choices
(cdr choices
)
1947 count
(ispell-int-char (1+ count
))))
1948 (setq count
(ispell-int-char (- count ?
0 skipped
))))
1950 ;; ensure word is visible
1951 (if (not (pos-visible-in-window-p end
))
1954 ;; allow temporary split of dedicated windows...
1957 (setq dedicated-win
(selected-window))
1958 (set-window-dedicated-p dedicated-win nil
)))
1960 ;; Display choices for misspelled word.
1961 (ispell-show-choices line end
)
1962 (select-window (setq textwin
(next-window)))
1964 ;; highlight word, protecting current buffer status
1967 (and ispell-highlight-p
1968 (ispell-highlight-spelling-error start end t
))
1969 ;; Loop until a valid choice is made.
1977 (let (message-log-max)
1978 (message (concat "C-h or ? for more options; SPC to leave "
1979 "unchanged, Character to replace word")))
1980 (let ((inhibit-quit t
)
1982 (setq char nil skipped
0)
1983 ;; If the user types C-g, or generates some other
1984 ;; non-character event (such as a frame switch
1985 ;; event), stop ispell. As a special exception,
1986 ;; ignore mouse events occurring in the same frame.
1987 (while (and input-valid
(not (characterp char
)))
1988 (setq char
(read-key))
1990 (or (characterp char
)
1991 (and (mouse-event-p char
)
1992 (eq (selected-frame)
1994 (posn-window (event-start char
))))))))
1995 (when (or quit-flag
(not input-valid
) (= char ?\C-g
))
1996 (setq char ?X quit-flag nil
)))
1997 ;; Adjust num to array offset skipping command characters.
1998 (let ((com-chars command-characters
))
2000 (if (and (> (car com-chars
) ?
0) (< (car com-chars
) char
))
2001 (setq skipped
(1+ skipped
)))
2002 (setq com-chars
(cdr com-chars
)))
2003 (setq num
(- char ?
0 skipped
)))
2006 ((= char ?
) nil
) ; accept word this time only
2007 ((= char ?i
) ; accept and insert word into pers dict
2008 (ispell-send-string (concat "*" word
"\n"))
2009 (setq ispell-pdict-modified-p
'(t)) ; dictionary modified!
2011 ((or (= char ?a
) (= char ?A
)) ; accept word without insert
2012 (ispell-send-string (concat "@" word
"\n"))
2013 (if (null ispell-pdict-modified-p
)
2014 (setq ispell-pdict-modified-p
2015 (list ispell-pdict-modified-p
)))
2016 (if (= char ?A
) 0)) ; return 0 for ispell-add buffer-local
2017 ((or (= char ?r
) (= char ?R
)) ; type in replacement
2018 (and (eq 'block ispell-highlight-p
) ; refresh tty's
2019 (ispell-highlight-spelling-error start end nil t
))
2021 (if (or (= char ?R
) ispell-query-replace-choices
)
2023 (format "Query-replacement for %s: "word
)
2026 (cons (read-string "Replacement for: " word
)
2028 (and (eq 'block ispell-highlight-p
)
2029 (ispell-highlight-spelling-error start end nil
2032 ((or (= char ??
) (= char help-char
) (= char ?\C-h
))
2033 (and (eq 'block ispell-highlight-p
)
2034 (ispell-highlight-spelling-error start end nil t
))
2036 (and (eq 'block ispell-highlight-p
)
2037 (ispell-highlight-spelling-error start end nil
2040 ;; Quit and move point back.
2042 (ispell-pdict-save ispell-silently-savep
)
2043 (message "Exited spell-checking")
2044 (setq ispell-quit t
)
2046 ;; Quit and preserve point.
2048 (ispell-pdict-save ispell-silently-savep
)
2050 (substitute-command-keys
2051 (concat "Spell-checking suspended;"
2052 " use C-u \\[ispell-word] to resume")))
2053 (setq ispell-quit start
)
2056 (if (y-or-n-p "Really kill Ispell process? ")
2058 (ispell-kill-ispell t
) ; terminate process.
2059 (setq ispell-quit
(or (not ispell-checking-message
)
2061 ispell-pdict-modified-p nil
))
2062 t
)) ; continue if they don't quit.
2064 (and (eq 'block ispell-highlight-p
) ; refresh tty displays
2065 (ispell-highlight-spelling-error start end nil t
))
2066 (let ((new-word (read-string
2067 "Lookup string (`*' is wildcard): "
2071 (with-current-buffer (get-buffer-create
2072 ispell-choices-buffer
)
2076 mode-line-format
;; setup the *Choices* buffer with valid data.
2077 (concat "-- %b -- word: " new-word
2079 (or ispell-complete-word-dict
2080 ispell-alternate-dictionary
))
2081 miss
(lookup-words new-word
)
2083 line ispell-choices-win-default-height
)
2084 (while (and choices
; adjust choices window.
2085 (< (if (> (+ 7 (current-column)
2086 (length (car choices
))
2087 (if (> count ?~
) 3 0))
2091 (setq line
(1+ line
)))
2094 (while (memq count command-characters
)
2095 (setq count
(ispell-int-char (1+ count
))
2096 skipped
(1+ skipped
)))
2097 (insert "(" count
") " (car choices
) " ")
2098 (setq choices
(cdr choices
)
2099 count
(ispell-int-char (1+ count
))))
2100 (setq count
(ispell-int-char
2101 (- count ?
0 skipped
))))
2102 (ispell-show-choices line end
)
2103 (select-window (next-window)))))
2104 (and (eq 'block ispell-highlight-p
)
2105 (ispell-highlight-spelling-error start end nil
2107 t
) ; reselect from new choices
2108 ((= char ?u
) ; insert lowercase into dictionary
2109 (ispell-send-string (concat "*" (downcase word
) "\n"))
2110 (setq ispell-pdict-modified-p
'(t)) ; dictionary modified!
2112 ((= char ?m
) ; type in what to insert
2114 (concat "*" (read-string "Insert: " word
) "\n"))
2115 (setq ispell-pdict-modified-p
'(t))
2117 ((and (>= num
0) (< num count
))
2118 (if ispell-query-replace-choices
; Query replace flag
2119 (list (nth num miss
) 'query-replace
)
2124 ;; This may have alignment errors if current line is edited
2125 (if (marker-position ispell-recursive-edit-marker
)
2127 (message "Only one recursive edit session supported")
2130 (set-marker ispell-recursive-edit-marker start
)
2131 ;;(set-marker ispell-region-end reg-end)
2132 (and ispell-highlight-p
; unhighlight
2133 (ispell-highlight-spelling-error start end
))
2138 (substitute-command-keys
2139 (concat "Exit recursive edit with"
2140 " \\[exit-recursive-edit]")))
2141 (save-window-excursion (save-excursion
2144 (goto-char ispell-recursive-edit-marker
)
2145 (if (not (equal (marker-buffer
2146 ispell-recursive-edit-marker
)
2149 (set-marker ispell-recursive-edit-marker nil
)
2151 "Cannot continue ispell from this buffer.")))
2152 (set-marker ispell-recursive-edit-marker nil
)))
2153 (list word nil
)) ; recheck starting at this word.
2155 (funcall (key-binding "\C-z"))
2160 (and ispell-highlight-p
; unhighlight
2161 (save-window-excursion
2162 (select-window textwin
)
2163 (ispell-highlight-spelling-error start end
)))
2165 (set-window-dedicated-p dedicated-win t
)))))
2169 (defun ispell-show-choices (line end
)
2170 "Show the choices in another buffer or frame."
2171 (if (and ispell-use-framepop-p
(fboundp 'framepop-display-buffer
))
2173 (framepop-display-buffer (get-buffer ispell-choices-buffer
))
2174 ;; (get-buffer-window ispell-choices-buffer t)
2175 (select-window (previous-window))) ; *Choices* window
2176 ;; standard selection by splitting a small buffer out of this window.
2177 (let ((choices-window (get-buffer-window ispell-choices-buffer
)))
2179 (if (= line
(ispell-adjusted-window-height choices-window
))
2180 (select-window choices-window
)
2181 ;; *Choices* window changed size. Adjust the choices window
2182 ;; without scrolling the spelled window when possible
2184 (- line
(ispell-adjusted-window-height choices-window
)))
2185 (visible (progn (vertical-motion -
1) (point))))
2186 (if (< line ispell-choices-win-default-height
)
2187 (setq window-line
(+ window-line
2188 (- ispell-choices-win-default-height
2190 (move-to-window-line 0)
2191 (vertical-motion window-line
)
2192 (set-window-start (selected-window)
2193 (if (> (point) visible
) visible
(point)))
2195 (select-window choices-window
)
2196 (enlarge-window window-line
)))
2197 ;; Overlay *Choices* window when it isn't showing
2198 (ispell-overlay-window (max line ispell-choices-win-default-height
)))
2199 (switch-to-buffer ispell-choices-buffer
)
2200 (goto-char (point-min)))))
2204 (defun ispell-help ()
2205 "Display a list of the options available when a misspelling is encountered.
2209 DIGIT: Replace the word with a digit offered in the *Choices* buffer.
2210 SPC: Accept word this time.
2211 `i': Accept word and insert into private dictionary.
2212 `a': Accept word for this session.
2213 `A': Accept word and place in `buffer-local dictionary'.
2214 `r': Replace word with typed-in value. Rechecked.
2215 `R': Replace word with typed-in value. Query-replaced in buffer. Rechecked.
2216 `?': Show these commands.
2217 `x': Exit spelling buffer. Move cursor to original point.
2218 `X': Exit spelling buffer. Leaves cursor at the current point, and permits
2219 the aborted check to be completed later.
2220 `q': Quit spelling session (Kills ispell process).
2221 `l': Look up typed-in replacement in alternate dictionary. Wildcards okay.
2222 `u': Like `i', but the word is lower-cased first.
2223 `m': Place typed-in value in personal dictionary, then recheck current word.
2224 `C-l': Redraw screen.
2225 `C-r': Recursive edit.
2226 `C-z': Suspend Emacs or iconify frame."
2228 (if (equal ispell-help-in-bufferp
'electric
)
2232 (function (lambda ()
2233 ;;This shouldn't be necessary: with-electric-help needs
2234 ;; an optional argument telling it about the smallest
2235 ;; acceptable window-height of the help buffer.
2236 ;;(if (< (window-height) 15)
2238 ;; (- 15 (ispell-adjusted-window-height))))
2239 (princ "Selections are:
2241 DIGIT: Replace the word with a digit offered in the *Choices* buffer.
2242 SPC: Accept word this time.
2243 `i': Accept word and insert into private dictionary.
2244 `a': Accept word for this session.
2245 `A': Accept word and place in `buffer-local dictionary'.
2246 `r': Replace word with typed-in value. Rechecked.
2247 `R': Replace word with typed-in value. Query-replaced in buffer. Rechecked.
2248 `?': Show these commands.
2249 `x': Exit spelling buffer. Move cursor to original point.
2250 `X': Exit spelling buffer. Leaves cursor at the current point, and permits
2251 the aborted check to be completed later.
2252 `q': Quit spelling session (Kills ispell process).
2253 `l': Look up typed-in replacement in alternate dictionary. Wildcards okay.
2254 `u': Like `i', but the word is lower-cased first.
2255 `m': Place typed-in value in personal dictionary, then recheck current word.
2256 `C-l': Redraw screen.
2257 `C-r': Recursive edit.
2258 `C-z': Suspend Emacs or iconify frame.")
2262 (let ((help-1 (concat "[r/R]eplace word; [a/A]ccept for this session; "
2263 "[i]nsert into private dictionary"))
2264 (help-2 (concat "[l]ook a word up in alternate dictionary; "
2265 "e[x/X]it; [q]uit session"))
2266 (help-3 (concat "[u]ncapitalized insert into dict. "
2267 "Type 'x C-h f ispell-help' for more help")))
2268 (save-window-excursion
2269 (if ispell-help-in-bufferp
2271 (ispell-overlay-window 4)
2272 (switch-to-buffer (get-buffer-create "*Ispell Help*"))
2273 (insert (concat help-1
"\n" help-2
"\n" help-3
))
2275 (kill-buffer "*Ispell Help*"))
2277 (let ((resize-mini-windows 'grow-only
))
2278 (select-window (minibuffer-window))
2281 ;;(set-minibuffer-window (selected-window))
2283 (insert (concat help-1
"\n" help-2
"\n" help-3
))
2285 (erase-buffer)))))))
2288 (defun lookup-words (word &optional lookup-dict
)
2289 "Look up WORD in optional word-list dictionary LOOKUP-DICT.
2290 A `*' serves as a wild card. If no wild cards, `look' is used if it exists.
2291 Otherwise the variable `ispell-grep-command' contains the command used to
2292 search for the words (usually egrep).
2294 Optional second argument contains the dictionary to use; the default is
2295 `ispell-alternate-dictionary', overridden by `ispell-complete-word-dict'
2297 ;; We don't use the filter for this function, rather the result is written
2298 ;; into a buffer. Hence there is no need to save the filter values.
2299 (if (null lookup-dict
)
2300 (setq lookup-dict
(or ispell-complete-word-dict
2301 ispell-alternate-dictionary
)))
2304 (unless (file-readable-p lookup-dict
)
2305 (error "lookup-words error: Unreadable or missing plain word-list %s."
2307 (error (concat "lookup-words error: No plain word-list found at system"
2308 "default locations. "
2309 "Customize `ispell-alternate-dictionary' to set yours.")))
2311 (let* ((process-connection-type ispell-use-ptys-p
)
2312 (wild-p (string-match "\\*" word
))
2313 (look-p (and ispell-look-p
; Only use look for an exact match.
2314 (or ispell-have-new-look
(not wild-p
))))
2315 (prog (if look-p ispell-look-command ispell-grep-command
))
2316 (args (if look-p ispell-look-options ispell-grep-options
))
2319 (message "Starting \"%s\" process..." (file-name-nondirectory prog
))
2323 (insert "^" word
"$")
2324 (while (search-backward "*" nil t
) (insert "."))
2325 (setq word
(buffer-string))
2327 (setq status
(apply 'ispell-call-process prog nil t nil
2328 (nconc (if (and args
(> (length args
) 0))
2333 (if lookup-dict
(list lookup-dict
)))))
2334 ;; `grep' returns status 1 and no output when word not found, which
2335 ;; is a perfectly normal thing.
2336 (if (stringp status
)
2337 (error "error: %s exited with signal %s"
2338 (file-name-nondirectory prog
) status
)
2339 ;; Else collect words into `results' in FIFO order.
2340 (goto-char (point-max))
2341 ;; Assure we've ended with \n.
2342 (or (bobp) (= (preceding-char) ?
\n) (insert ?
\n))
2346 (push (buffer-substring-no-properties (point)
2349 (if (and results
(string-match ".+: " (car results
)))
2350 (error "%s error: %s" ispell-grep-command
(car results
)))
2354 ;; "ispell-filter" is a list of output lines from the generating function.
2355 ;; Each full line (ending with \n) is a separate item on the list.
2356 ;; "output" can contain multiple lines, part of a line, or both.
2357 ;; "start" and "end" are used to keep bounds on lines when "output" contains
2359 ;; "ispell-filter-continue" is true when we have received only part of a
2360 ;; line as output from a generating function ("output" did not end with \n)
2361 ;; THIS FUNCTION WILL FAIL IF THE PROCESS OUTPUT DOESN'T END WITH \n!
2362 ;; This is the case when a process dies or fails. The default behavior
2363 ;; in this case treats the next input received as fresh input.
2365 (defun ispell-filter (process output
)
2366 "Output filter function for ispell, grep, and look."
2371 (setq end
(string-match "\n" output start
)) ; get text up to the newline.
2372 ;; If we get out of sync and ispell-filter-continue is asserted when we
2373 ;; are not continuing, treat the next item as a separate list. When
2374 ;; ispell-filter-continue is asserted, ispell-filter *should* always be a
2377 ;; Continue with same line (item)?
2378 (if (and ispell-filter-continue ispell-filter
(listp ispell-filter
))
2379 ;; Yes. Add it to the prev item
2380 (setcar ispell-filter
2381 (concat (car ispell-filter
) (substring output start end
)))
2382 ;; No. This is a new line and item.
2384 (cons (substring output start end
) ispell-filter
)))
2386 ;; We've completed reading the output, but didn't finish the line.
2387 (setq ispell-filter-continue t continue nil
)
2388 ;; skip over newline, this line complete.
2389 (setq ispell-filter-continue nil end
(1+ end
))
2390 (if (= end
(length output
)) ; No more lines in output
2391 (setq continue nil
) ; so we can exit the filter.
2392 (setq start end
)))))) ; else move start to next line of input
2395 ;;; This function destroys the mark location if it is in the word being
2397 (defun ispell-highlight-spelling-error-generic (start end
&optional highlight
2399 "Highlight the word from START to END with a kludge using `inverse-video'.
2400 When the optional third arg HIGHLIGHT is set, the word is highlighted;
2401 otherwise it is displayed normally.
2402 Uses block cursor to highlight one character.
2403 Optional REFRESH will unhighlighted then highlight, using block cursor
2404 highlighting when REFRESH is equal to `block'."
2405 (and (eq 'block ispell-highlight-p
)
2406 (or (eq 'block refresh
)
2407 (setq start
(1+ start
)))) ; On block non-refresh, inc start.
2408 (let ((modified (buffer-modified-p)) ; don't allow this fn to modify buffer
2409 (buffer-read-only nil
) ; Allow highlighting read-only buffers.
2410 (text (buffer-substring-no-properties start end
))
2411 ; Save highlight region.
2412 (inhibit-quit t
) ; inhibit interrupt processing here.
2413 (buffer-undo-list t
)) ; don't clutter the undo list.
2415 (delete-region start end
)
2416 (insert-char ?
(- end start
)) ; minimize amount of redisplay
2417 (sit-for 0) ; update display
2418 (if highlight
(setq inverse-video
(not inverse-video
))) ; toggle video
2419 (delete-region start end
) ; delete whitespace
2420 (insert text
) ; insert text in inverse video.
2421 (sit-for 0) ; update display showing inverse video.
2424 (setq inverse-video
(not inverse-video
)) ; toggle video
2425 (and (eq 'block ispell-highlight-p
)
2426 (goto-char (1- start
)))) ; use block cursor to "highlight" char
2427 (set-buffer-modified-p modified
) ; don't modify if flag not set.
2428 (and refresh
; re-highlight
2429 (ispell-highlight-spelling-error-generic
2430 (if (eq 'block refresh
) start
(- start
2)) end t
))))
2433 (defun ispell-highlight-spelling-error-xemacs (start end
&optional highlight
)
2434 "Highlight the word from START to END using `isearch-highlight'.
2435 When the optional third arg HIGHLIGHT is set, the word is highlighted,
2436 otherwise it is displayed normally."
2438 (isearch-highlight start end
)
2439 (isearch-dehighlight))
2444 (defun ispell-highlight-spelling-error-overlay (start end
&optional highlight
)
2445 "Highlight the word from START to END using overlays.
2446 When the optional third arg HIGHLIGHT is set, the word is highlighted
2447 otherwise it is displayed normally.
2449 The variable `ispell-highlight-face' selects the face to use for highlighting."
2452 (move-overlay ispell-overlay start end
(current-buffer))
2453 (setq ispell-overlay
(make-overlay start end
))
2454 (overlay-put ispell-overlay
'priority
1001) ;higher than lazy overlays
2455 (overlay-put ispell-overlay
'face ispell-highlight-face
))
2457 (delete-overlay ispell-overlay
)))
2458 (if (and ispell-lazy-highlight
(boundp 'lazy-highlight-cleanup
))
2460 (let ((isearch-string
2463 (regexp-quote (buffer-substring-no-properties start end
))
2466 (isearch-case-fold-search nil
))
2467 (isearch-lazy-highlight-new-loop
2468 (if (boundp 'reg-start
) reg-start
)
2469 (if (boundp 'reg-end
) reg-end
)))
2470 (lazy-highlight-cleanup lazy-highlight-cleanup
)
2471 (setq isearch-lazy-highlight-last-string nil
))))
2474 (defun ispell-highlight-spelling-error (start end
&optional highlight refresh
)
2477 (ispell-highlight-spelling-error-xemacs start end highlight
))
2478 ((and (featurep 'faces
)
2479 (or (and (fboundp 'display-color-p
) (display-color-p))
2481 (ispell-highlight-spelling-error-overlay start end highlight
))
2482 (t (ispell-highlight-spelling-error-generic start end highlight refresh
))))
2484 (defun ispell-adjusted-window-height (&optional window
)
2485 "Like `window-height', adjusted to correct for the effect of tall mode-lines.
2486 The value returned is actually the nominal number of text-lines in the
2487 window plus 1. On a terminal, this is the same value returned by
2488 `window-height', but if the window has a mode-line is taller than a normal
2489 text line, the returned value may be smaller than that from
2491 (cond ((fboundp 'window-text-height
)
2492 (1+ (window-text-height window
)))
2493 ((or (and (fboundp 'display-graphic-p
) (display-graphic-p))
2494 (and (featurep 'xemacs
) window-system
))
2495 (1- (window-height window
)))
2497 (window-height window
))))
2499 (defun ispell-overlay-window (height)
2500 "Create a window covering the top HEIGHT lines of the current window.
2501 Ensure that the line above point is still visible but otherwise avoid
2502 scrolling the current window. Leave the new window selected."
2504 (let ((oldot (save-excursion (vertical-motion -
1) (point)))
2505 (top (save-excursion (move-to-window-line height
) (point))))
2506 ;; If line above old point (line starting at oldot) would be
2507 ;; hidden by new window, scroll it to just below new win
2508 ;; otherwise set top line of other win so it doesn't scroll.
2509 (if (< oldot top
) (setq top oldot
))
2510 ;; if frame is unsplittable, temporarily disable that...
2511 (if (cdr (assq 'unsplittable
(frame-parameters (selected-frame))))
2512 (let ((frame (selected-frame)))
2513 (modify-frame-parameters frame
'((unsplittable . nil
)))
2514 (split-window nil height
)
2515 (modify-frame-parameters frame
'((unsplittable . t
))))
2516 (split-window nil height
))
2517 (let ((deficit (- height
(ispell-adjusted-window-height))))
2519 ;; Number of lines the window is still too short. We ensure that
2520 ;; there are at least (1- HEIGHT) lines visible in the window.
2521 (enlarge-window deficit
)
2523 (vertical-motion deficit
)
2524 (setq top
(min (point) oldot
))))
2525 (set-window-start (next-window) top
))))
2528 ;;; Should we add a compound word match return value?
2529 (defun ispell-parse-output (output &optional accept-list shift
)
2530 "Parse the OUTPUT string from Ispell process and return:
2531 1: t for an exact match.
2532 2: A string containing the root word matched via suffix removal.
2533 3: A list of possible correct spellings of the format:
2534 (\"ORIGINAL-WORD\" OFFSET MISS-LIST GUESS-LIST)
2535 ORIGINAL-WORD is a string of the possibly misspelled word.
2536 OFFSET is an integer giving the line offset of the word.
2537 MISS-LIST and GUESS-LIST are possibly null lists of guesses and misses.
2538 4: nil when an error has occurred.
2540 Optional second arg ACCEPT-LIST is list of words already accepted.
2541 Optional third arg SHIFT is an offset to apply based on previous corrections."
2543 ((string= output
"") t
) ; for startup with pipes...
2544 ((string= output
"*") t
) ; exact match
2545 ((string= output
"-") t
) ; compound word match
2546 ((eq (aref output
0) ?
+) ; found because of root word
2547 (substring output
2)) ; return root word
2548 ((equal 0 (string-match "[\ra-zA-Z]" output
))
2549 (ding) ; error message from ispell!
2550 (message "Ispell error: %s" output
)
2553 (t ; need to process &, ?, and #'s
2554 (let ((type (aref output
0)) ; &, ?, or #
2555 (original-word (substring output
2 (string-match " " output
2)))
2556 (cur-count 0) ; contains number of misses + guesses
2557 count miss-list guess-list offset
)
2558 (setq output
(substring output
(match-end 0))) ; skip over misspelling
2560 (setq count
0) ; no misses for type #
2561 (setq count
(string-to-number output
) ; get number of misses.
2562 output
(substring output
(1+ (string-match " " output
1)))))
2563 (setq offset
(string-to-number output
))
2564 (setq output
(if (eq type ?
#) ; No miss or guess list.
2566 (substring output
(1+ (string-match " " output
1)))))
2568 (let ((end (string-match ", \\|\\($\\)" output
))) ; end of miss/guess.
2569 (setq cur-count
(1+ cur-count
))
2570 (if (> cur-count count
)
2571 (push (substring output
0 end
) guess-list
)
2572 (push (substring output
0 end
) miss-list
))
2573 (setq output
(if (match-end 1) ; True only when at end of line.
2574 nil
; No more misses or guesses.
2575 (substring output
(+ end
2))))))
2576 ;; return results. Accept word if it was already accepted.
2578 (if (member original-word accept-list
)
2581 (if (numberp shift
) (+ shift offset
) offset
)
2582 (nreverse miss-list
) (nreverse guess-list
)))))))
2585 (defun ispell-process-status ()
2586 "Return the status of the Ispell process.
2587 When asynchronous processes are not supported, `run' is always returned."
2588 (if ispell-async-processp
2589 (process-status ispell-process
)
2590 (and ispell-process
'run
)))
2593 (defun ispell-start-process ()
2594 "Start the ispell process, with support for no asynchronous processes.
2595 Keeps argument list for future ispell invocations for no async support."
2596 ;; Local dictionary becomes the global dictionary in use.
2597 (setq ispell-current-dictionary
2598 (or ispell-local-dictionary ispell-dictionary
))
2599 (setq ispell-current-personal-dictionary
2600 (or ispell-local-pdict ispell-personal-dictionary
))
2601 (let* ((default-directory
2602 (if (and (file-directory-p default-directory
)
2603 (file-readable-p default-directory
))
2605 ;; Defend against bad `default-directory'.
2606 (expand-file-name "~/")))
2607 (orig-args (ispell-get-ispell-args))
2610 (if (and ispell-current-dictionary
; Not for default dict (nil)
2611 (not (member "-d" orig-args
))) ; Only define if not overridden.
2612 (list "-d" ispell-current-dictionary
))
2614 (if ispell-current-personal-dictionary
; Use specified pers dict.
2616 (expand-file-name ispell-current-personal-dictionary
)))
2617 ;; If we are using recent aspell or hunspell, make sure we use the
2618 ;; right encoding for communication. ispell or older aspell/hunspell
2619 ;; does not support this.
2620 (if ispell-encoding8-command
2621 (if ispell-really-hunspell
2622 (list ispell-encoding8-command
2623 (upcase (symbol-name (ispell-get-coding-system))))
2625 (concat ispell-encoding8-command
2626 (symbol-name (ispell-get-coding-system))))))
2627 ispell-extra-args
)))
2629 ;; Initially we don't know any buffer's local words.
2630 (setq ispell-buffer-local-name nil
)
2632 (if ispell-async-processp
2633 (let ((process-connection-type ispell-use-ptys-p
))
2634 (apply 'start-process
2635 "ispell" nil ispell-program-name
2636 "-a" ; Accept single input lines.
2637 ;; Make root/affix combos not in dict.
2638 ;; hunspell -m option means different.
2639 (if ispell-really-hunspell
"" "-m")
2641 (setq ispell-cmd-args args
2642 ispell-output-buffer
(generate-new-buffer " *ispell-output*")
2643 ispell-session-buffer
(generate-new-buffer " *ispell-session*"))
2644 (ispell-send-string "\032\n") ; so Ispell prints version and exits
2648 (defun ispell-init-process ()
2649 "Check status of Ispell process and start if necessary."
2650 (let* (;; Basename of dictionary used by the spell-checker
2651 (dict-bname (or (car (cdr (member "-d" (ispell-get-ispell-args))))
2652 ispell-current-dictionary
))
2653 ;; Use "~/" as default-directory unless using Ispell with per-dir
2654 ;; personal dictionaries and not in a minibuffer under XEmacs
2656 (if (or ispell-really-aspell
2657 ispell-really-hunspell
2658 ;; Protect against bad default-directory
2659 (not (and (file-directory-p default-directory
)
2660 (file-readable-p default-directory
)))
2661 ;; Ispell and per-dir personal dicts available
2662 (not (or (file-readable-p (concat default-directory
2664 (file-readable-p (concat default-directory
2668 ;; Ispell, in a minibuffer, and XEmacs
2669 (and (window-minibuffer-p)
2670 (not (fboundp 'minibuffer-selected-window
))))
2671 (expand-file-name "~/")
2672 (expand-file-name default-directory
))))
2673 ;; Check if process needs restart
2674 (if (and ispell-process
2675 (eq (ispell-process-status) 'run
)
2676 ;; Unless we are using an explicit personal dictionary, ensure
2677 ;; we're in the same default directory! Restart check for
2678 ;; personal dictionary is done in
2679 ;; `ispell-internal-change-dictionary', called from
2680 ;; `ispell-buffer-local-dict'
2681 (or (or ispell-local-pdict ispell-personal-dictionary
)
2682 (equal ispell-process-directory default-directory
)))
2683 (setq ispell-filter nil ispell-filter-continue nil
)
2684 ;; may need to restart to select new personal dictionary.
2685 (ispell-kill-ispell t
)
2686 (message "Starting new Ispell process [%s] ..."
2687 (or ispell-local-dictionary ispell-dictionary
"default"))
2689 (setq ispell-library-directory
(ispell-check-version)
2690 ispell-process
(ispell-start-process)
2692 ispell-filter-continue nil
2693 ispell-process-directory default-directory
)
2695 (unless (equal ispell-process-directory
(expand-file-name "~/"))
2696 ;; At this point, `ispell-process-directory' will be "~/" unless using
2697 ;; Ispell with directory-specific dicts and not in XEmacs minibuffer.
2698 ;; If not, kill ispell process when killing buffer. It may be in a
2699 ;; removable device that would otherwise become un-mountable.
2700 (with-current-buffer
2701 (if (and (window-minibuffer-p) ;; In minibuffer
2702 (fboundp 'minibuffer-selected-window
)) ;; Not XEmacs.
2703 ;; In this case kill ispell only when parent buffer is killed
2704 ;; to avoid over and over ispell kill.
2705 (window-buffer (minibuffer-selected-window))
2707 ;; 'local does not automatically make hook buffer-local in XEmacs.
2708 (if (featurep 'xemacs
)
2709 (make-local-hook 'kill-buffer-hook
))
2710 (add-hook 'kill-buffer-hook
2711 (lambda () (ispell-kill-ispell t
)) nil
'local
)))
2713 (if ispell-async-processp
2714 (set-process-filter ispell-process
'ispell-filter
))
2715 ;; Protect against XEmacs bogus binding of `enable-multibyte-characters'.
2716 (if (and (or (featurep 'xemacs
)
2717 (and (boundp 'enable-multibyte-characters
)
2718 enable-multibyte-characters
))
2719 (fboundp 'set-process-coding-system
))
2720 (set-process-coding-system ispell-process
(ispell-get-coding-system)
2721 (ispell-get-coding-system)))
2722 ;; Get version ID line
2723 (ispell-accept-output 3)
2724 ;; get more output if filter empty?
2725 (if (null ispell-filter
) (ispell-accept-output 3))
2726 (cond ((null ispell-filter
)
2727 (error "%s did not output version line" ispell-program-name
))
2729 (stringp (car ispell-filter
))
2730 (if (string-match "warning: " (car ispell-filter
))
2732 (ispell-accept-output 3) ; was warn msg.
2733 (stringp (car ispell-filter
)))
2734 (null (cdr ispell-filter
)))
2735 (string-match "^@(#) " (car ispell-filter
)))
2736 ;; got the version line as expected (we already know it's the right
2737 ;; version, so don't bother checking again.)
2740 ;; Otherwise, it must be an error message. Show the user.
2741 ;; But first wait to see if some more output is going to arrive.
2742 ;; Otherwise we get cool errors like "Can't open ".
2744 (ispell-accept-output 3)
2745 (error "%s" (mapconcat 'identity ispell-filter
"\n"))))
2746 (setq ispell-filter nil
) ; Discard version ID line
2747 (let ((extended-char-mode (ispell-get-extended-character-mode)))
2748 (if extended-char-mode
; ~ extended character mode
2749 (ispell-send-string (concat extended-char-mode
"\n"))))
2750 (if ispell-async-processp
2751 (if (featurep 'emacs
)
2752 (set-process-query-on-exit-flag ispell-process nil
)
2753 (if (fboundp 'set-process-query-on-exit-flag
)
2754 (set-process-query-on-exit-flag ispell-process nil
)
2755 (process-kill-without-query ispell-process
)))))))
2758 (defun ispell-kill-ispell (&optional no-error
)
2759 "Kill current Ispell process (so that you may start a fresh one).
2760 With NO-ERROR, just return non-nil if there was no Ispell running."
2762 ;; This hook is typically used by flyspell to flush some variables used
2763 ;; to optimize the common cases.
2764 (run-hooks 'ispell-kill-ispell-hook
)
2765 (if (not (and ispell-process
2766 (eq (ispell-process-status) 'run
)))
2768 (error "There is no ispell process running!"))
2769 (if ispell-async-processp
2770 (delete-process ispell-process
)
2771 ;; synchronous processes
2772 (ispell-send-string "\n") ; make sure side effects occurred.
2773 (kill-buffer ispell-output-buffer
)
2774 (kill-buffer ispell-session-buffer
)
2775 (setq ispell-output-buffer nil
2776 ispell-session-buffer nil
))
2777 (setq ispell-process nil
)
2778 (message "Ispell process killed")
2781 ;;; ispell-change-dictionary is set in some people's hooks. Maybe this should
2782 ;;; call ispell-init-process rather than wait for a spell checking command?
2785 (defun ispell-change-dictionary (dict &optional arg
)
2786 "Change to dictionary DICT for Ispell.
2787 With a prefix arg, set it \"globally\", for all buffers.
2788 Without a prefix arg, set it \"locally\", just for this buffer.
2790 By just answering RET you can find out what the current dictionary is."
2792 (list (completing-read
2793 "Use new dictionary (RET for current, SPC to complete): "
2794 (and (fboundp 'ispell-valid-dictionary-list
)
2795 (mapcar 'list
(ispell-valid-dictionary-list)))
2797 current-prefix-arg
))
2798 (ispell-set-spellchecker-params) ; Initialize variables and dicts alists
2799 (unless arg
(ispell-buffer-local-dict 'no-reload
))
2800 (if (equal dict
"default") (setq dict nil
))
2801 ;; This relies on completing-read's bug of returning "" for no match
2802 (cond ((equal dict
"")
2803 (ispell-internal-change-dictionary)
2804 (message "Using %s dictionary"
2805 (or (and (not arg
) ispell-local-dictionary
)
2806 ispell-dictionary
"default")))
2807 ((equal dict
(or (and (not arg
) ispell-local-dictionary
)
2808 ispell-dictionary
"default"))
2809 ;; Specified dictionary is the default already. Could reload
2810 ;; the dictionaries if needed.
2811 (ispell-internal-change-dictionary)
2812 (and (interactive-p)
2813 (message "No change, using %s dictionary" dict
)))
2814 (t ; reset dictionary!
2815 (if (or (assoc dict ispell-local-dictionary-alist
)
2816 (assoc dict ispell-dictionary-alist
))
2818 ;; set default dictionary
2819 (setq ispell-dictionary dict
)
2820 ;; set local dictionary
2821 (setq ispell-local-dictionary dict
)
2822 (setq ispell-local-dictionary-overridden t
))
2823 (error "Undefined dictionary: %s" dict
))
2824 (ispell-internal-change-dictionary)
2825 (message "%s Ispell dictionary set to %s"
2826 (if arg
"Global" "Local")
2829 (defun ispell-internal-change-dictionary ()
2830 "Update the dictionary and the personal dictionary used by Ispell.
2831 This may kill the Ispell process; if so, a new one will be started
2833 (let ((dict (or ispell-local-dictionary ispell-dictionary
))
2834 (pdict (or ispell-local-pdict ispell-personal-dictionary
)))
2835 (unless (and (equal ispell-current-dictionary dict
)
2836 (equal ispell-current-personal-dictionary pdict
))
2837 (ispell-kill-ispell t
)
2838 (setq ispell-current-dictionary dict
2839 ispell-current-personal-dictionary pdict
))))
2841 ;; Avoid error messages when compiling for these dynamic variables.
2842 (defvar ispell-start
)
2845 ;; Spelling of comments are checked when ispell-check-comments is non-nil.
2848 (defun ispell-region (reg-start reg-end
&optional recheckp shift
)
2849 "Interactively check a region for spelling errors.
2850 Return nil if spell session was terminated, otherwise returns shift offset
2851 amount for last line processed."
2852 (interactive "r") ; Don't flag errors on read-only bufs.
2853 (ispell-set-spellchecker-params) ; Initialize variables and dicts alists
2855 (ispell-accept-buffer-local-defs)) ; set up dictionary, local words, etc.
2856 (let ((skip-region-start (make-marker))
2857 (rstart (make-marker)))
2860 (message "Spell-checking %s using %s with %s dictionary..."
2861 (if (and (= reg-start
(point-min)) (= reg-end
(point-max)))
2862 (buffer-name) "region")
2863 (file-name-nondirectory ispell-program-name
)
2864 (or ispell-current-dictionary
"default"))
2865 ;; Returns cursor to original location.
2866 (save-window-excursion
2867 (goto-char reg-start
)
2868 (let ((transient-mark-mode)
2869 (case-fold-search case-fold-search
)
2872 (let (message-log-max)
2873 (message "searching for regions to skip"))
2874 (if (re-search-forward (ispell-begin-skip-region-regexp) reg-end t
)
2876 (setq key
(match-string-no-properties 0))
2877 (set-marker skip-region-start
(- (point) (length key
)))
2878 (goto-char reg-start
)))
2879 (let (message-log-max)
2881 "Continuing spelling check using %s with %s dictionary..."
2882 (file-name-nondirectory ispell-program-name
)
2883 (or ispell-current-dictionary
"default")))
2884 (set-marker rstart reg-start
)
2885 (set-marker ispell-region-end reg-end
)
2886 (while (and (not ispell-quit
)
2887 (< (point) ispell-region-end
))
2888 ;; spell-check region with skipping
2889 (if (and (marker-position skip-region-start
)
2890 (<= skip-region-start
(point)))
2892 ;; If region inside line comment, must keep comment start.
2893 (setq in-comment
(point)
2896 (or (null comment-end
) (string= "" comment-end
))
2899 (re-search-forward comment-start in-comment t
))
2901 ;; Can change skip-regexps (in ispell-message)
2902 (ispell-skip-region key
) ; moves pt past region.
2903 (set-marker rstart
(point))
2904 ;; check for saving large attachments...
2905 (setq query-fcc
(and query-fcc
2906 (ispell-ignore-fcc skip-region-start
2908 (if (and (< rstart ispell-region-end
)
2910 (ispell-begin-skip-region-regexp)
2911 ispell-region-end t
))
2913 (setq key
(match-string-no-properties 0))
2914 (set-marker skip-region-start
2915 (- (point) (length key
)))
2917 (set-marker skip-region-start nil
))))
2918 (setq reg-end
(max (point)
2919 (if (marker-position skip-region-start
)
2920 (min skip-region-start ispell-region-end
)
2921 (marker-position ispell-region-end
))))
2922 (let* ((ispell-start (point))
2923 (ispell-end (min (point-at-eol) reg-end
))
2924 (string (ispell-get-line
2925 ispell-start ispell-end in-comment
)))
2926 (if in-comment
; account for comment chars added
2927 (setq ispell-start
(- ispell-start
(length in-comment
))
2929 (setq ispell-end
(point)) ; "end" tracks region retrieved.
2930 (if string
; there is something to spell check!
2931 ;; (special start end)
2932 (setq shift
(ispell-process-line string
2933 (and recheckp shift
))))
2934 (goto-char ispell-end
)))))
2939 (if (and (not (and recheckp ispell-keep-choices-win
))
2940 (get-buffer ispell-choices-buffer
))
2941 (kill-buffer ispell-choices-buffer
))
2942 (set-marker skip-region-start nil
)
2943 (set-marker rstart nil
)
2946 ;; preserve or clear the region for ispell-continue.
2947 (if (not (numberp ispell-quit
))
2948 (set-marker ispell-region-end nil
)
2949 ;; Ispell-continue enabled - ispell-region-end is set.
2950 (goto-char ispell-quit
))
2951 ;; Check for aborting
2952 (if (and ispell-checking-message
(numberp ispell-quit
))
2954 (setq ispell-quit nil
)
2955 (error "Message send aborted")))
2956 (if (not recheckp
) (setq ispell-quit nil
)))
2957 (if (not recheckp
) (set-marker ispell-region-end nil
))
2958 ;; Only save if successful exit.
2959 (ispell-pdict-save ispell-silently-savep
)
2960 (message "Spell-checking %s using %s with %s dictionary...done"
2961 (if (and (= reg-start
(point-min)) (= reg-end
(point-max)))
2962 (buffer-name) "region")
2963 (file-name-nondirectory ispell-program-name
)
2964 (or ispell-current-dictionary
"default"))))))
2967 (defun ispell-begin-skip-region-regexp ()
2968 "Return a regexp of the search keys for region skipping.
2969 Includes `ispell-skip-region-alist' plus tex, tib, html, and comment keys.
2970 Must be called after `ispell-buffer-local-parsing' due to dependence on mode."
2976 (if (and ispell-checking-message
2977 (not (eq t ispell-checking-message
)))
2978 (mapconcat #'car ispell-checking-message
"\\|"))
2980 (if (eq ispell-parser
'tex
)
2981 (ispell-begin-tex-skip-regexp))
2983 (if ispell-skip-html
2984 (ispell-begin-skip-region ispell-html-skip-alists
))
2986 (if ispell-skip-tib ispell-tib-ref-beginning
)
2988 (if (and (eq 'exclusive ispell-check-comments
) comment-start
)
2989 ;; search from end of current comment to start of next comment.
2990 (if (string= "" comment-end
) "^" (regexp-quote comment-end
)))
2991 (if (and (null ispell-check-comments
) comment-start
)
2992 (regexp-quote comment-start
))
2993 (ispell-begin-skip-region ispell-skip-region-alist
)))
2997 (defun ispell-begin-skip-region (skip-alist)
2998 "Regular expression for start of regions to skip generated from SKIP-ALIST.
2999 Each selection should be a key of SKIP-ALIST;
3000 otherwise, the current line is skipped."
3001 (mapconcat (lambda (lst) (if (stringp (car lst
)) (car lst
) (eval (car lst
))))
3006 (defun ispell-begin-tex-skip-regexp ()
3007 "Regular expression of tex commands to skip.
3008 Generated from `ispell-tex-skip-alists'."
3011 (mapconcat (function (lambda (lst) (car lst
)))
3012 (car ispell-tex-skip-alists
)
3015 ;; keys wrapped in begin{}
3016 (mapconcat (function (lambda (lst)
3017 (concat "\\\\begin[ \t\n]*{[ \t\n]*"
3020 (car (cdr ispell-tex-skip-alists
))
3024 (defun ispell-skip-region-list ()
3025 "Return a list describing key and body regions to skip for this buffer.
3026 Includes regions defined by `ispell-skip-region-alist', tex mode,
3027 `ispell-html-skip-alists', and `ispell-checking-message'.
3028 Manual checking must include comments and tib references.
3029 The list is of the form described by variable `ispell-skip-region-alist'.
3030 Must be called after `ispell-buffer-local-parsing' due to dependence on mode."
3031 (let ((skip-alist ispell-skip-region-alist
))
3032 ;; only additional explicit region definition is tex.
3033 (if (eq ispell-parser
'tex
)
3034 (setq case-fold-search nil
3035 skip-alist
(append (car ispell-tex-skip-alists
)
3036 (car (cdr ispell-tex-skip-alists
))
3038 (if ispell-skip-html
3039 (setq skip-alist
(append ispell-html-skip-alists skip-alist
)))
3040 (if (and ispell-checking-message
3041 (not (eq t ispell-checking-message
)))
3042 (setq skip-alist
(append ispell-checking-message skip-alist
)))
3046 (defun ispell-tex-arg-end (&optional arg
)
3047 "Skip across ARG number of braces."
3050 (while (looking-at "[ \t\n]*\\[") (forward-sexp))
3051 (forward-sexp (or arg
1)))
3053 (message "Error skipping s-expressions at point %d." (point))
3058 (defun ispell-ignore-fcc (start end
)
3059 "Delete the Fcc: message header when large attachments are included.
3060 Return value `nil' if file with large attachments is saved.
3061 This can be used to avoid multiple questions for multiple large attachments.
3062 Returns point to starting location afterwards."
3064 (if (and ispell-checking-message ispell-message-fcc-skip
)
3065 (if (< ispell-message-fcc-skip
(- end start
))
3066 (let (case-fold-search head-end
)
3067 (goto-char (point-min))
3069 (or (re-search-forward
3070 (concat "^" (regexp-quote mail-header-separator
) "$")
3072 (re-search-forward "^$" nil t
)
3074 (goto-char (point-min))
3075 (if (re-search-forward "^Fcc:" head-end t
)
3077 "Save copy of this message with large attachments? ")
3085 (defun ispell-skip-region (key)
3086 "Skip across KEY and then to end of region.
3087 Key lookup determines region to skip.
3088 Point is placed at end of skipped region."
3089 ;; move over key to begin checking.
3090 (forward-char (length key
))
3091 (let ((start (point))
3092 ;; Regenerate each call... This function can change region definition.
3093 (alist (ispell-skip-region-list))
3094 alist-key null-skip
)
3096 ;; what about quoted comment, or comment inside strings?
3097 ((and (null ispell-check-comments
) comment-start
3098 (string= key comment-start
))
3099 (if (string= "" comment-end
)
3101 (search-forward comment-end ispell-region-end t
)))
3102 ((and (eq 'exclusive ispell-check-comments
) comment-start
3103 (string= key comment-end
))
3104 (search-forward comment-start ispell-region-end
:end
))
3105 ((and ispell-skip-tib
(string-match ispell-tib-ref-beginning key
))
3106 (re-search-forward ispell-tib-ref-end ispell-region-end t
))
3107 ;; markings from alist
3110 (setq alist-key
(eval (car (car alist
))))
3111 (if (string-match alist-key key
)
3113 (setq alist
(cdr (car alist
)))
3115 ((null alist
) (setq null-skip t
)) ; done! Just skip key.
3116 ((not (consp alist
))
3117 ;; Search past end of spell region to find this region end.
3118 (re-search-forward (eval alist
) (point-max) t
))
3119 ((and (= 1 (length alist
))
3120 (stringp (car alist
)))
3121 (re-search-forward (car alist
) (point-max) t
))
3123 (setq null-skip t
) ; error handling in functions!
3124 (if (consp (cdr alist
))
3125 (apply (car alist
) (cdr alist
))
3126 (funcall (car alist
)))))
3128 (setq alist
(cdr alist
))))))
3129 (if (and (= start
(point)) (null null-skip
))
3131 (message "Matching region end for `%s' point %d not found"
3137 (defun ispell-get-line (start end in-comment
)
3138 "Grab the next line of data.
3139 Returns a string with the line data."
3140 (let ((ispell-casechars (ispell-get-casechars))
3142 (cond ; LOOK AT THIS LINE AND SKIP OR PROCESS
3143 ((eolp) ; END OF LINE, just go to next line.
3145 ;;((looking-at "[-#@*+!%~^]") ; SKIP SPECIAL ISPELL CHARACTERS
3146 ;; (forward-char 1)) ; not needed as quoted below.
3147 ((or (re-search-forward ispell-casechars end t
) ; TEXT EXISTS
3148 (re-search-forward "[][()${}]" end t
)) ; or MATH COMMANDS
3149 (setq string
(concat "^" in-comment
3150 (buffer-substring-no-properties start end
)
3153 (t (goto-char end
))) ; EMPTY LINE, skip it.
3157 (defun ispell-looking-at (string)
3158 (let ((coding (ispell-get-coding-system))
3159 (len (length string
)))
3160 (and (<= (+ (point) len
) (point-max))
3161 (equal (encode-coding-string string coding
)
3162 (encode-coding-string (buffer-substring-no-properties
3163 (point) (+ (point) len
))
3166 (defun ispell-process-line (string shift
)
3167 "Send STRING, a line of text, to ispell and process the result.
3168 This will modify the buffer for spelling errors.
3169 Requires variables ISPELL-START and ISPELL-END to be defined in its
3171 Returns the sum SHIFT due to changes in word replacements."
3172 ;;(declare special ispell-start ispell-end)
3173 (let (poss accept-list
)
3174 (if (not (numberp shift
))
3176 ;; send string to spell process and get input.
3177 (ispell-send-string string
)
3179 (ispell-accept-output)
3180 ;; Last item of output contains a blank line.
3181 (not (string= "" (car ispell-filter
)))))
3182 ;; parse all inputs from the stream one word at a time.
3183 ;; Place in FIFO order and remove the blank item.
3184 (setq ispell-filter
(nreverse (cdr ispell-filter
)))
3185 (while (and (not ispell-quit
) ispell-filter
)
3186 ;; get next word, accounting for accepted words and start shifts
3187 (setq poss
(ispell-parse-output (car ispell-filter
)
3189 (if (and poss
(listp poss
)) ; spelling error occurred.
3190 ;; Whenever we have misspellings, we can change
3191 ;; the buffer. Keep boundaries as markers.
3192 ;; Markers can move with highlighting! This destroys
3193 ;; end of region markers line-end and ispell-region-end
3195 (copy-marker (+ ispell-start ispell-offset
(car (cdr poss
)))))
3196 (word-len (length (car poss
)))
3197 (line-end (copy-marker ispell-end
))
3198 (line-start (copy-marker ispell-start
))
3199 recheck-region replace
)
3200 (goto-char word-start
)
3201 ;; Adjust the horizontal scroll & point
3202 (ispell-horiz-scroll)
3203 (goto-char (+ word-len word-start
))
3204 (ispell-horiz-scroll)
3205 (goto-char word-start
)
3206 (ispell-horiz-scroll)
3208 ;; Alignment cannot be tracked and this error will occur when
3209 ;; `query-replace' makes multiple corrections on the starting line.
3210 (or (ispell-looking-at (car poss
))
3211 ;; This occurs due to filter pipe problems
3212 (error (concat "Ispell misalignment: word "
3213 "`%s' point %d; probably incompatible versions")
3214 (car poss
) (marker-position word-start
)))
3215 ;; ispell-cmd-loop can go recursive & change buffer
3216 (if ispell-keep-choices-win
3217 (setq replace
(ispell-command-loop
3218 (car (cdr (cdr poss
)))
3219 (car (cdr (cdr (cdr poss
))))
3220 (car poss
) (marker-position word-start
)
3221 (+ word-len
(marker-position word-start
))))
3222 (save-window-excursion
3223 (setq replace
(ispell-command-loop
3224 (car (cdr (cdr poss
)))
3225 (car (cdr (cdr (cdr poss
))))
3226 (car poss
) (marker-position word-start
)
3227 (+ word-len
(marker-position word-start
))))))
3229 (goto-char word-start
)
3230 ;; Recheck when query replace edit changes misspelled word.
3231 ;; Error in tex mode when a potential math mode change exists.
3232 (if (and replace
(listp replace
) (= 2 (length replace
)))
3233 (if (and (eq ispell-parser
'tex
)
3234 (string-match "[\\\\][]()[]\\|\\\\begin\\|\\$"
3235 (regexp-quote string
)))
3237 "Don't start query replace on a line with math characters"
3239 (set-marker line-end
(point))
3240 (setq ispell-filter nil
3243 ;; insert correction if needed
3246 (equal 0 replace
)) ; ACCEPT/INSERT
3247 (if (equal 0 replace
) ; BUFFER-LOCAL DICT ADD
3248 (ispell-add-per-file-word-list (car poss
)))
3249 ;; do not recheck accepted word on this line
3250 (setq accept-list
(cons (car poss
) accept-list
)))
3251 (t ; replacement word selected or entered
3252 (delete-region (point) (+ word-len
(point)))
3253 (if (not (listp replace
))
3255 (ispell-insert-word replace
) ; insert dictionary word
3256 (ispell-send-replacement (car poss
) replace
)
3257 (setq accept-list
(cons replace accept-list
)))
3258 (let ((replace-word (car replace
)))
3259 ;; Recheck hand entered replacement word
3260 (insert replace-word
)
3261 (ispell-send-replacement (car poss
) replace-word
)
3262 (if (car (cdr replace
))
3263 (save-window-excursion
3264 (delete-other-windows) ; to correctly show help.
3265 ;; Assume case-replace &
3266 ;; case-fold-search correct?
3267 (query-replace (car poss
) (car replace
) t
)))
3268 (goto-char word-start
)
3269 ;; do not recheck if already accepted
3270 (if (member replace-word accept-list
)
3271 (setq accept-list
(cons replace-word accept-list
)
3272 replace replace-word
)
3273 (let ((region-end (copy-marker ispell-region-end
)))
3274 (setq recheck-region ispell-filter
3275 ispell-filter nil
; save filter
3276 shift
0 ; already accounted
3277 shift
(ispell-region
3279 (+ word-start
(length replace-word
))
3281 (if (null shift
) ; quitting check.
3283 (set-marker ispell-region-end region-end
)
3284 (set-marker region-end nil
)
3285 (setq ispell-filter recheck-region
3287 replace replace-word
)))))
3289 (setq shift
(+ shift
(- (length replace
) word-len
)))
3291 ;; Move line-start across word...
3292 ;; new shift function does this now...
3293 ;;(set-marker line-start (+ line-start
3294 ;; (- (length replace)
3295 ;; (length (car poss)))))
3297 (if (not ispell-quit
)
3298 ;; FIXME: remove redundancy with identical code above.
3299 (let (message-log-max)
3301 "Continuing spelling check using %s with %s dictionary..."
3302 (file-name-nondirectory ispell-program-name
)
3303 (or ispell-current-dictionary
"default"))))
3305 (setq ispell-start
(marker-position line-start
)
3306 ispell-end
(marker-position line-end
))
3307 ;; Adjust markers when end of region lost from highlighting.
3308 (if (and (not recheck-region
)
3309 (< ispell-end
(+ word-start word-len
)))
3310 (setq ispell-end
(+ word-start word-len
)))
3311 (if (= word-start ispell-region-end
)
3312 (set-marker ispell-region-end
(+ word-start word-len
)))
3313 ;; going out of scope - unneeded
3314 (set-marker line-start nil
)
3315 (set-marker word-start nil
)
3316 (set-marker line-end nil
)))
3317 ;; finished with misspelling!
3318 (setq ispell-filter
(cdr ispell-filter
)))
3323 (defun ispell-comments-and-strings ()
3324 "Check comments and strings in the current buffer for spelling errors."
3326 (goto-char (point-min))
3330 (setq state
(parse-partial-sexp (point) (point-max)
3331 nil nil state
'syntax-table
))
3332 (if (or (nth 3 state
) (nth 4 state
))
3333 (let ((start (point)))
3334 (setq state
(parse-partial-sexp start
(point-max)
3335 nil nil state
'syntax-table
))
3336 (if (or (nth 3 state
) (nth 4 state
))
3337 (error "Unterminated string or comment"))
3339 (setq done
(not (ispell-region start
(point))))))))))
3343 (defun ispell-buffer ()
3344 "Check the current buffer for spelling errors interactively."
3346 (ispell-region (point-min) (point-max)))
3350 (defun ispell-continue ()
3351 "Continue a halted spelling session beginning with the current word."
3353 (if (not (marker-position ispell-region-end
))
3354 (message "No session to continue. Use 'X' command when checking!")
3355 (if (not (equal (marker-buffer ispell-region-end
) (current-buffer)))
3356 (message "Must continue ispell from buffer %s"
3357 (buffer-name (marker-buffer ispell-region-end
)))
3359 ;; find beginning of current word:
3360 (car (cdr (ispell-get-word t
)))
3361 (marker-position ispell-region-end
)))))
3364 ;;; Horizontal scrolling
3365 (defun ispell-horiz-scroll ()
3366 "Place point within the horizontal visibility of its window area."
3367 (if truncate-lines
; display truncating lines?
3368 ;; See if display needs to be scrolled.
3369 (let ((column (- (current-column) (max (window-hscroll) 1))))
3370 (if (and (< column
0) (> (window-hscroll) 0))
3371 (scroll-right (max (- column
) 10))
3372 (if (>= column
(- (window-width) 2))
3373 (scroll-left (max (- column
(window-width) -
3) 10)))))))
3376 ;;; Interactive word completion.
3377 ;; Forces "previous-word" processing. Do we want to make this selectable?
3380 (defun ispell-complete-word (&optional interior-frag
)
3381 "Try to complete the word before or under point (see `lookup-words').
3382 If optional INTERIOR-FRAG is non-nil then the word may be a character
3383 sequence inside of a word.
3385 Standard ispell choices are then available."
3387 (let ((cursor-location (point))
3388 (case-fold-search-val case-fold-search
)
3389 (word (ispell-get-word nil
"\\*")) ; force "previous-word" processing.
3390 start end possibilities replacement
)
3391 (setq start
(car (cdr word
))
3392 end
(car (cdr (cdr word
)))
3395 (or (string= word
"") ; Will give you every word
3396 (lookup-words (concat (and interior-frag
"*") word
3397 (if (or interior-frag
(null ispell-look-p
))
3399 (or ispell-complete-word-dict
3400 ispell-alternate-dictionary
))))
3401 (cond ((eq possibilities t
)
3402 (message "No word to complete"))
3403 ((null possibilities
)
3404 (message "No match for \"%s\"" word
))
3405 (t ; There is a modification...
3406 (setq case-fold-search nil
) ; Try and respect case of word.
3408 ((string-equal (upcase word
) word
)
3409 (setq possibilities
(mapcar 'upcase possibilities
)))
3410 ((eq (upcase (aref word
0)) (aref word
0))
3411 (setq possibilities
(mapcar (function
3413 (if (eq (aref word
0) (aref pos
0))
3417 (setq case-fold-search case-fold-search-val
)
3418 (save-window-excursion
3420 (ispell-command-loop possibilities nil word start end
)))
3422 ((equal 0 replacement
) ; BUFFER-LOCAL ADDITION
3423 (ispell-add-per-file-word-list word
))
3424 (replacement ; REPLACEMENT WORD
3425 (delete-region start end
)
3426 (setq word
(if (atom replacement
) replacement
(car replacement
))
3427 cursor-location
(+ (- (length word
) (- end start
))
3429 (ispell-insert-word word
)
3430 (if (not (atom replacement
)) ; recheck spelling of replacement.
3432 (goto-char cursor-location
)
3433 (ispell-word nil t
)))))
3434 (if (get-buffer ispell-choices-buffer
)
3435 (kill-buffer ispell-choices-buffer
))))
3436 (ispell-pdict-save ispell-silently-savep
)
3437 (goto-char cursor-location
)))
3441 (defun ispell-complete-word-interior-frag ()
3442 "Completes word matching character sequence inside a word."
3444 (ispell-complete-word t
))
3449 "Interactively check a region or buffer for spelling errors.
3450 If `transient-mark-mode' is on, and a region is active, spell-check
3451 that region. Otherwise spell-check the buffer.
3453 Ispell dictionaries are not distributed with Emacs. If you are
3454 looking for a dictionary, please see the distribution of the GNU ispell
3455 program, or do an Internet search; there are various dictionaries
3456 available on the net."
3458 (if (and (boundp 'transient-mark-mode
) transient-mark-mode
3459 (boundp 'mark-active
) mark-active
)
3460 (ispell-region (region-beginning) (region-end))
3464 ;;; **********************************************************************
3465 ;;; Ispell Minor Mode
3466 ;;; **********************************************************************
3468 (defvar ispell-minor-keymap
3469 (let ((map (make-sparse-keymap)))
3470 (define-key map
" " 'ispell-minor-check
)
3471 (define-key map
"\r" 'ispell-minor-check
)
3473 "Keymap used for Ispell minor mode.")
3476 (define-minor-mode ispell-minor-mode
3477 "Toggle last-word spell checking (Ispell minor mode).
3478 With a prefix argument ARG, enable Ispell minor mode if ARG is
3479 positive, and disable it otherwise. If called from Lisp, enable
3480 the mode if ARG is omitted or nil.
3482 Ispell minor mode is a buffer-local minor mode. When enabled,
3483 typing SPC or RET warns you if the previous word is incorrectly
3486 All the buffer-local variables and dictionaries are ignored. To
3487 read them into the running ispell process, type \\[ispell-word]
3490 For spell-checking \"on the fly\", not just after typing SPC or
3491 RET, use `flyspell-mode'."
3492 nil
" Spell" ispell-minor-keymap
)
3494 (defun ispell-minor-check ()
3495 "Check previous word, then continue with the normal binding of this key.
3496 Don't check previous word when character before point is a space or newline.
3497 Don't read buffer-local settings or word lists."
3499 (let ((ispell-minor-mode nil
)
3500 (ispell-check-only t
)
3501 (last-char (char-after (1- (point)))))
3502 (command-execute (key-binding (this-command-keys)))
3503 (if (not (or (eq last-char ?\
) (eq last-char ?
\n)
3504 (and ispell-skip-html
(eq last-char ?
>))
3505 (and ispell-skip-html
(eq last-char ?\
;))))
3506 (ispell-word nil t
))))
3509 ;;; **********************************************************************
3511 ;;; **********************************************************************
3513 (defvar ispell-message-text-end
3514 (mapconcat (function identity
)
3516 ;; Don't spell check signatures
3518 ;; Matches PostScript files.
3519 ;;"^%!PS-Adobe-[123].0"
3520 ;; Matches uuencoded text
3521 ;;"^begin [0-9][0-9][0-9] .*\nM.*\nM.*\nM"
3522 ;; Matches shell files (especially auto-decoding)
3524 ;; Matches context difference listing
3525 "\\(\\(^cd .*\n\\)?diff -c .*\\)?\n\\*\\*\\* .*\n--- .*\n\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*"
3526 ;; Matches unidiff difference listing
3527 "\\(diff -u .*\\)?\n--- .*\n\\+\\+\\+ .*\n@@ [-+][0-9]+,[0-9]+ [-+][0-9]+,[0-9]+ @@"
3528 ;; Matches reporter.el bug report
3529 "^current state:\n==============\n"
3530 ;; Matches commonly used "cut" boundaries
3531 "^\\(- \\)?[-=_]+\\s ?\\(cut here\\|Environment Follows\\)")
3533 "*Text beyond which `ispell-message' will not spell-check.
3534 If it is a string, limit is the first occurrence of that regular expression.
3535 Otherwise, it must be a function which is called to get the limit.")
3536 (put 'ispell-message-text-end
'risky-local-variable t
)
3539 (defun ispell-mime-multipartp (&optional limit
)
3540 "Return multipart message start boundary or nil if none."
3541 ;; caller must ensure `case-fold-search' is set to `t'
3544 "Content-Type: *multipart/\\([^ \t\n]*;[ \t]*[\n]?[ \t]*\\)+boundary="
3547 (if (looking-at "\"")
3550 (setq start
(point))
3551 (while (not (looking-at "\""))
3553 (setq boundary
(buffer-substring-no-properties start
(point))))
3554 (let ((start (point)))
3555 (while (looking-at "[-0-9a-zA-Z'()+_,./:=?]")
3557 (setq boundary
(buffer-substring-no-properties start
(point)))))
3558 (if (< (length boundary
) 1)
3560 (concat "--" boundary
)))))
3563 (defun ispell-mime-skip-part (boundary)
3564 "Move point across header, or entire MIME part if message is encoded.
3565 All specified types except `7bit' `8bit' and `quoted-printable' are considered
3566 encoded and therefore skipped. See rfc 1521, 2183, ...
3567 If no boundary is given, then entire message is skipped.
3569 This starts one line ABOVE the MIME content messages, on the boundary marker,
3570 for operation with the generic region-skipping code.
3571 This places new MIME boundaries into variable `ispell-checking-message'."
3572 (forward-line) ; skip over boundary to headers
3573 (let ((save-case-fold-search case-fold-search
)
3576 (setq case-fold-search t
3577 ispell-skip-html nil
)
3579 (setq continuep nil
)
3580 (if (looking-at "Content-Type: *text/")
3582 (goto-char (match-end 0))
3583 (if (looking-at "html")
3584 (setq ispell-skip-html t
))
3587 (re-search-forward "\\(.*;[ \t]*[\n]\\)*.*$" nil t
)
3589 (if (looking-at "Content-Transfer-Encoding: *\\([^ \t\n]*\\)")
3590 (let ((match (buffer-substring (match-beginning 1) (match-end 1))))
3591 (setq textp
(member (upcase match
)
3592 ;; only spell check the following encodings:
3593 '("7BIT" "8BIT" "QUOTED-PRINTABLE" "BINARY"))
3595 (goto-char (match-end 0))
3596 (re-search-forward "\\(.*;[ \t]*[\n]\\)*.*$" nil t
)
3598 ;; hierarchical boundary definition
3599 (if (looking-at "Content-Type: *multipart/")
3600 (let ((new-boundary (ispell-mime-multipartp)))
3601 (if (string-match new-boundary boundary
)
3603 ;; first pass redefine skip function to include new boundary
3604 ;;(re-search-backward boundary nil t)
3606 (setq ispell-checking-message
3608 (list new-boundary
'ispell-mime-skip-part new-boundary
)
3609 (if (eq t ispell-checking-message
) nil
3610 ispell-checking-message
))
3613 ;; Skip all MIME headers that don't affect spelling
3614 (if (looking-at "Content-[^ \t]*: *\\(.*;[ \t]*[\n]\\)*.*$")
3617 (goto-char (match-end 0))
3620 (setq case-fold-search save-case-fold-search
)
3623 ;; encoded message. Skip to boundary, or entire message.
3625 (goto-char (point-max))
3626 (re-search-forward boundary nil t
)
3632 (defun ispell-message ()
3633 "Check the spelling of a mail message or news post.
3634 Don't check spelling of message headers except the Subject field.
3635 Don't check included messages.
3637 To abort spell checking of a message region and send the message anyway,
3638 use the `x' command. (Any subsequent regions will be checked.)
3639 The `X' command aborts sending the message so that you can edit the buffer.
3641 To spell-check whenever a message is sent, include the appropriate lines
3642 in your .emacs file:
3643 (add-hook 'message-send-hook 'ispell-message) ;; GNUS 5
3644 (add-hook 'news-inews-hook 'ispell-message) ;; GNUS 4
3645 (add-hook 'mail-send-hook 'ispell-message)
3646 (add-hook 'mh-before-send-letter-hook 'ispell-message)
3648 You can bind this to the key C-c i in GNUS or mail by adding to
3649 `news-reply-mode-hook' or `mail-mode-hook' the following lambda expression:
3650 (function (lambda () (local-set-key \"\\C-ci\" 'ispell-message)))"
3653 (goto-char (point-min))
3654 (let* (boundary mimep
3655 (ispell-skip-region-alist-save ispell-skip-region-alist
)
3656 ;; Nil when message came from outside (eg calling Emacs as editor)
3657 ;; Non-nil marker of end of headers.
3660 (concat "^" (regexp-quote mail-header-separator
) "$") nil t
))
3661 (end-of-headers ; Start of body.
3663 (or internal-messagep
3664 (re-search-forward "^$" nil t
)
3666 (limit (copy-marker ; End of region we will spell check.
3668 ((not ispell-message-text-end
) (point-max))
3669 ((char-or-string-p ispell-message-text-end
)
3670 (if (re-search-forward ispell-message-text-end nil t
)
3673 (t (min (point-max) (funcall ispell-message-text-end
))))))
3674 (default-prefix ; Vanilla cite prefix (just used for cite-regexp)
3675 (if (and (boundp 'mail-yank-prefix
) mail-yank-prefix
)
3676 (ispell-non-empty-string mail-yank-prefix
)
3678 (cite-regexp ;Prefix of quoted text
3680 ((functionp 'sc-cite-regexp
) ; sc 3.0
3682 (concat "\\(" (sc-cite-regexp) "\\)" "\\|"
3683 (ispell-non-empty-string sc-reference-tag-string
))))
3684 ((boundp 'sc-cite-regexp
) ; sc 2.3
3685 (concat "\\(" sc-cite-regexp
"\\)" "\\|"
3687 (ispell-non-empty-string sc-reference-tag-string
))))
3688 ((or (equal major-mode
'news-reply-mode
) ;GNUS 4 & below
3689 (equal major-mode
'message-mode
)) ;GNUS 5
3690 (concat "In article <" "\\|"
3691 "[^,;&+=\n]+ <[^,;&+=]+> writes:" "\\|"
3692 (with-no-warnings message-cite-prefix-regexp
)
3695 ((equal major-mode
'mh-letter-mode
) ; mh mail message
3696 (concat "[^,;&+=\n]+ writes:" "\\|"
3698 (ispell-non-empty-string mh-ins-buf-prefix
))))
3699 ((not internal-messagep
) ; Assume nn sent us this message.
3700 (concat "In [a-zA-Z.]+ you write:" "\\|"
3701 "In <[^,;&+=]+> [^,;&+=]+ writes:" "\\|"
3703 ((boundp 'vm-included-text-prefix
) ; VM mail message
3704 (concat "[^,;&+=\n]+ writes:" "\\|"
3705 (ispell-non-empty-string vm-included-text-prefix
)))
3706 (t default-prefix
)))
3707 (ispell-skip-region-alist
3708 (cons (list (concat "^\\(" cite-regexp
"\\)")
3709 (function forward-line
))
3710 ispell-skip-region-alist
))
3711 (old-case-fold-search case-fold-search
)
3712 (dictionary-alist ispell-message-dictionary-alist
)
3713 (ispell-checking-message t
))
3715 ;; Select dictionary for message
3716 (or (local-variable-p 'ispell-local-dictionary
(current-buffer))
3717 (while dictionary-alist
3718 (goto-char (point-min))
3719 (if (re-search-forward (car (car dictionary-alist
))
3721 (setq ispell-local-dictionary
(cdr (car dictionary-alist
))
3722 dictionary-alist nil
)
3723 (setq dictionary-alist
(cdr dictionary-alist
)))))
3727 ;; Spell check any original Subject:
3728 (goto-char (point-min))
3729 (setq case-fold-search t
3730 mimep
(re-search-forward "MIME-Version:" end-of-headers t
))
3731 (goto-char (point-min))
3732 (if (re-search-forward "^Subject: *" end-of-headers t
)
3734 (goto-char (match-end 0))
3735 (if (and (not (looking-at ".*Re\\>"))
3736 (not (looking-at "\\[")))
3738 (setq case-fold-search old-case-fold-search
)
3739 (ispell-region (point)
3740 (progn ;Tab-initiated continuation lns.
3742 (while (looking-at "\n[ \t]")
3747 (goto-char (point-min))
3748 (setq boundary
(ispell-mime-multipartp end-of-headers
))))
3749 ;; Adjust message limit to MIME message if necessary.
3751 (re-search-forward (concat boundary
"--") nil t
)
3752 (re-search-backward boundary nil t
)
3753 (< (point) (marker-position limit
))
3754 (set-marker limit
(point)))
3755 (goto-char (point-min))
3756 ;; Select type or skip checking if this is a non-multipart message
3757 ;; Point moved to end of buffer if region is encoded.
3758 (when (and mimep
(not boundary
))
3759 (goto-char (point-min))
3760 (re-search-forward "Content-[^ \t]*:" end-of-headers t
)
3761 (forward-line -
1) ; following fn starts one line above
3762 (ispell-mime-skip-part nil
)
3763 ;; if message-text-end region, limit may be less than point.
3764 (if (> (point) limit
)
3765 (set-marker limit
(point))))
3766 (goto-char (max end-of-headers
(point)))
3768 (setq case-fold-search old-case-fold-search
)
3769 ;; Define MIME regions to skip.
3771 (setq ispell-checking-message
3772 (list (list boundary
'ispell-mime-skip-part boundary
))))
3773 (ispell-region (point) limit
))
3774 (set-marker end-of-headers nil
)
3775 (set-marker limit nil
)
3776 (setq ispell-skip-region-alist ispell-skip-region-alist-save
3777 ispell-skip-html nil
3778 case-fold-search old-case-fold-search
)))))
3781 (defun ispell-non-empty-string (string)
3782 (if (or (not string
) (string-equal string
""))
3783 "\\'\\`" ; An unmatchable string if string is null.
3784 (regexp-quote string
)))
3787 ;;; **********************************************************************
3788 ;;; Buffer Local Functions
3789 ;;; **********************************************************************
3792 (defun ispell-accept-buffer-local-defs ()
3793 "Load all buffer-local information, restarting Ispell when necessary."
3794 (ispell-buffer-local-dict) ; May kill ispell-process.
3795 (ispell-buffer-local-words) ; Will initialize ispell-process.
3796 (ispell-buffer-local-parsing))
3799 (defun ispell-buffer-local-parsing ()
3800 "Place Ispell into parsing mode for this buffer.
3801 Overrides the default parsing mode.
3802 Includes LaTeX/Nroff modes and extended character mode."
3803 ;; (ispell-init-process) must already be called.
3804 (ispell-send-string "!\n") ; Put process in terse mode.
3805 ;; We assume all major modes with "tex-mode" in them should use latex parsing
3806 ;; When exclusively checking comments, set to raw text mode (nroff).
3807 (if (and (not (eq 'exclusive ispell-check-comments
))
3808 (or (and (eq ispell-parser
'use-mode-name
)
3809 (string-match "[Tt][Ee][Xx]-mode"
3810 (symbol-name major-mode
)))
3811 (eq ispell-parser
'tex
)))
3813 (ispell-send-string "+\n") ; set ispell mode to tex
3814 (if (not (eq ispell-parser
'tex
))
3815 (set (make-local-variable 'ispell-parser
) 'tex
)))
3816 (ispell-send-string "-\n")) ; set mode to normal (nroff)
3817 ;; If needed, test for SGML & HTML modes and set a buffer local nil/t value.
3818 (if (and ispell-skip-html
(not (eq ispell-skip-html t
)))
3819 (setq ispell-skip-html
3820 (not (null (string-match "sgml\\|html\\|xml"
3821 (downcase (symbol-name major-mode
)))))))
3822 ;; Set default extended character mode for given buffer, if any.
3823 (let ((extended-char-mode (ispell-get-extended-character-mode)))
3824 (if extended-char-mode
3825 (ispell-send-string (concat extended-char-mode
"\n"))))
3826 ;; Set buffer-local parsing mode and extended character mode, if specified.
3828 (goto-char (point-max))
3829 ;; Uses last occurrence of ispell-parsing-keyword
3830 (if (search-backward ispell-parsing-keyword nil t
)
3831 (let ((end (point-at-eol))
3833 (search-forward ispell-parsing-keyword
)
3834 (while (re-search-forward " *\\([^ \"]+\\)" end t
)
3835 ;; space separated definitions.
3836 (setq string
(downcase (match-string-no-properties 1)))
3837 (cond ((and (string-match "latex-mode" string
)
3838 (not (eq 'exclusive ispell-check-comments
)))
3839 (ispell-send-string "+\n~tex\n"))
3840 ((string-match "nroff-mode" string
)
3841 (ispell-send-string "-\n~nroff\n"))
3842 ((string-match "~" string
) ; Set extended character mode.
3843 (ispell-send-string (concat string
"\n")))
3844 (t (message "Invalid Ispell Parsing argument!")
3848 ;; Can kill the current ispell process
3850 (defun ispell-buffer-local-dict (&optional no-reload
)
3851 "Initializes local dictionary and local personal dictionary.
3852 If optional NO-RELOAD is non-nil, do not reload any dictionary.
3853 When a dictionary is defined in the buffer (see variable
3854 `ispell-dictionary-keyword'), it will override the local setting
3855 from \\[ispell-change-dictionary].
3856 Both should not be used to define a buffer-local dictionary."
3858 (goto-char (point-min))
3860 ;; Override the local variable definition.
3861 ;; Uses last occurrence of ispell-dictionary-keyword.
3862 (goto-char (point-max))
3863 (unless ispell-local-dictionary-overridden
3864 (if (search-backward ispell-dictionary-keyword nil t
)
3866 (search-forward ispell-dictionary-keyword
)
3867 (setq end
(point-at-eol))
3868 (if (re-search-forward " *\\([^ \"]+\\)" end t
)
3869 (setq ispell-local-dictionary
3870 (match-string-no-properties 1))))))
3871 (goto-char (point-max))
3872 (if (search-backward ispell-pdict-keyword nil t
)
3874 (search-forward ispell-pdict-keyword
)
3875 (setq end
(point-at-eol))
3876 (if (re-search-forward " *\\([^ \"]+\\)" end t
)
3877 (setq ispell-local-pdict
3878 (match-string-no-properties 1)))))))
3880 ;; Reload if new dictionary (maybe the personal one) defined.
3881 (ispell-internal-change-dictionary)))
3884 (defun ispell-buffer-local-words ()
3885 "Load the buffer-local dictionary in the current buffer."
3886 ;; If there's an existing ispell process that's wrong for this use,
3888 (if (and ispell-buffer-local-name
3889 (not (equal ispell-buffer-local-name
(buffer-name))))
3890 (ispell-kill-ispell t
))
3891 ;; Actually start a new ispell process, because we need
3892 ;; to send commands now to specify the local words to it.
3893 (ispell-init-process)
3895 (goto-char (point-min))
3896 (while (search-forward ispell-words-keyword nil t
)
3897 (or ispell-buffer-local-name
3898 (setq ispell-buffer-local-name
(buffer-name)))
3899 (let ((end (point-at-eol))
3900 (ispell-casechars (ispell-get-casechars))
3902 ;; buffer-local words separated by a space, and can contain
3903 ;; any character other than a space. Not rigorous enough.
3904 (while (re-search-forward " *\\([^ ]+\\)" end t
)
3905 (setq string
(match-string-no-properties 1))
3906 ;; This can fail when string contains a word with invalid chars.
3907 ;; Error handling needs to be added between ispell and Emacs.
3908 (if (and (< 1 (length string
))
3909 (equal 0 (string-match ispell-casechars string
)))
3910 (ispell-send-string (concat "@" string
"\n"))))))))
3913 ;;; returns optionally adjusted region-end-point.
3915 ;; If comment-padright is defined, newcomment must be loaded.
3916 (declare-function comment-add
"newcomment" (arg))
3918 (defun ispell-add-per-file-word-list (word)
3919 "Add WORD to the per-file word list."
3920 (or ispell-buffer-local-name
3921 (setq ispell-buffer-local-name
(buffer-name)))
3923 (goto-char (point-min))
3924 (let (line-okay search done found
)
3926 (let ((case-fold-search nil
))
3927 (setq search
(search-forward ispell-words-keyword nil
'move
)
3928 found
(or found search
)
3929 line-okay
(< (+ (length word
) 1 ; 1 for space after word..
3930 (progn (end-of-line) (current-column)))
3932 (if (or (and search line-okay
)
3939 (unless found
(newline))
3940 (insert (if comment-start
3942 (if (fboundp 'comment-padright
)
3943 ;; Try and use the proper comment marker,
3944 ;; e.g. ";;" rather than ";".
3945 (comment-padright comment-start
3950 ispell-words-keyword
)
3951 (if (and comment-end
(> (length comment-end
) 0))
3954 (insert comment-end
)))))
3955 (insert (concat " " word
))))))))
3957 (add-to-list 'debug-ignored-errors
"^No word found to check!$")
3962 ;;; LOCAL VARIABLES AND BUFFER-LOCAL VALUE EXAMPLES.
3964 ;; Local Variable options:
3965 ;; mode: name(-mode)
3967 ;; local-variable: value
3969 ;; The following sets the buffer local dictionary to `american' English
3970 ;; and spell checks only comments.
3974 ;; comment-column: 40
3975 ;; ispell-check-comments: exclusive
3976 ;; ispell-local-dictionary: "american"
3980 ;;; MORE EXAMPLES OF ISPELL BUFFER-LOCAL VALUES
3982 ;; The following places this file in nroff parsing and extended char modes.
3983 ;; Local IspellParsing: nroff-mode ~nroff
3984 ;; Change IspellPersDict to IspellPersDict: to enable the following line.
3985 ;; Local IspellPersDict ~/.ispell_lisp
3986 ;; The following were automatically generated by ispell using the 'A' command:
3987 ; LocalWords: settable alist inews mh frag pdict Wildcards iconify arg tex kss
3988 ; LocalWords: alists minibuffer bufferp autoload loaddefs aff Dansk KOI SPC op
3989 ; LocalWords: Francais Nederlands charset autoloaded popup nonmenu regexp num
3990 ; LocalWords: AMStex hspace includeonly nocite epsfig displaymath eqnarray reg
3991 ; LocalWords: minipage modeline pers dict unhighlight buf grep sync prev inc
3992 ; LocalWords: fn oldot NB AIX msg init read's bufs pt cmd Quinlan eg
3993 ; LocalWords: uuencoded unidiff sc nn VM SGML eval IspellPersDict
3994 ; LocalWords: lns XEmacs HTML casechars Multibyte
3996 ;;; ispell.el ends here