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