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