* lisp/emacs-lisp/nadvice.el (advice--interactive-form): New function.
[emacs.git] / lisp / textmodes / ispell.el
blob5cdae22cc0fc8070108bb2c158f48ce49c50517e
1 ;;; ispell.el --- interface to International Ispell Versions 3.1 and 3.2
3 ;; Copyright (C) 1994-1995, 1997-2014 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 (and (file-directory-p default-directory)
935 (file-readable-p default-directory))
936 (setq default-directory (expand-file-name "~/")))
937 (apply 'call-process args)))
939 (defun ispell-call-process-region (&rest args)
940 "Like `call-process-region' but defend against bad `default-directory'."
941 (let ((default-directory default-directory))
942 (unless (and (file-directory-p default-directory)
943 (file-readable-p default-directory))
944 (setq default-directory (expand-file-name "~/")))
945 (apply 'call-process-region args)))
947 (defun ispell-create-debug-buffer (&optional append)
948 "Create an ispell debug buffer for debugging output.
949 Use APPEND to append the info to previous buffer if exists,
950 otherwise is reset. Returns name of ispell debug buffer.
951 See `ispell-buffer-with-debug' for an example of use."
952 (let ((ispell-debug-buffer (get-buffer-create "*ispell-debug*")))
953 (with-current-buffer ispell-debug-buffer
954 (if append
955 (insert
956 (format "-----------------------------------------------\n"))
957 (erase-buffer)))
958 ispell-debug-buffer))
960 (defsubst ispell-print-if-debug (format &rest args)
961 "Print message to `ispell-debug-buffer' buffer if enabled."
962 (if (boundp 'ispell-debug-buffer)
963 (with-current-buffer ispell-debug-buffer
964 (goto-char (point-max))
965 (insert (apply #'format format args)))))
968 ;; The preparation of the menu bar menu must be autoloaded
969 ;; because otherwise this file gets autoloaded every time Emacs starts
970 ;; so that it can set up the menus and determine keyboard equivalents.
972 ;;;###autoload
973 (defvar ispell-menu-map nil "Key map for ispell menu.")
974 ;; Redo menu when loading ispell to get dictionary modifications
975 (setq ispell-menu-map nil)
977 ;;;###autoload
978 (defvar ispell-menu-xemacs nil
979 "Spelling menu for XEmacs.
980 If nil when package is loaded, a standard menu will be set,
981 and added as a submenu of the \"Edit\" menu.")
983 ;; Break out XEmacs menu and split into several calls to avoid having
984 ;; long lines in loaddefs.el. Detect need off following constant.
986 ;;; Set up dictionary
987 ;;;###autoload
988 (defvar ispell-menu-map-needed
989 ;; only needed when not version 18 and not XEmacs.
990 (and (not ispell-menu-map)
991 (not (featurep 'xemacs))
992 'reload))
994 (defvar ispell-library-directory (condition-case ()
995 (ispell-check-version)
996 (error nil))
997 "Directory where ispell dictionaries reside.")
999 (defvar ispell-process nil
1000 "The process object for Ispell.")
1002 (defvar ispell-async-processp (and (fboundp 'delete-process)
1003 (fboundp 'process-send-string)
1004 (fboundp 'accept-process-output)
1005 ;;(fboundp 'start-process)
1006 ;;(fboundp 'set-process-filter)
1007 ;;(fboundp 'process-kill-without-query)
1009 "Non-nil means that the OS supports asynchronous processes.")
1011 ;; Make ispell.el work better with aspell.
1013 (defvar ispell-aspell-dictionary-alist nil
1014 "An alist of parsed aspell dicts and associated parameters.
1015 Internal use.")
1017 (defun ispell-find-aspell-dictionaries ()
1018 "Find Aspell's dictionaries, and record in `ispell-dictionary-alist'."
1019 (unless (and ispell-really-aspell ispell-encoding8-command)
1020 (error "This function only works with aspell >= 0.60"))
1021 (let* ((dictionaries
1022 (split-string
1023 (with-temp-buffer
1024 (ispell-call-process ispell-program-name nil t nil "dicts")
1025 (buffer-string))))
1026 ;; Search for the named dictionaries.
1027 (found
1028 (delq nil
1029 (mapcar #'ispell-aspell-find-dictionary dictionaries))))
1030 ;; Ensure aspell's alias dictionary will override standard
1031 ;; definitions.
1032 (setq found (ispell-aspell-add-aliases found))
1033 ;; Merge into FOUND any elements from the standard ispell-dictionary-base-alist
1034 ;; which have no element in FOUND at all.
1035 (dolist (dict ispell-dictionary-base-alist)
1036 (unless (assoc (car dict) found)
1037 (setq found (nconc found (list dict)))))
1038 (setq ispell-aspell-dictionary-alist found)
1039 ;; Add a default entry
1040 (let ((default-dict
1041 '(nil "[[:alpha:]]" "[^[:alpha:]]" "[']" nil ("-B") nil utf-8)))
1042 (push default-dict ispell-aspell-dictionary-alist))))
1044 (defvar ispell-aspell-data-dir nil
1045 "Data directory of Aspell.")
1047 (defvar ispell-aspell-dict-dir nil
1048 "Dictionary directory of Aspell.")
1050 (defun ispell-get-aspell-config-value (key)
1051 "Return value of Aspell configuration option KEY.
1052 Assumes that value contains no whitespace."
1053 (with-temp-buffer
1054 (ispell-call-process ispell-program-name nil t nil "config" key)
1055 (car (split-string (buffer-string)))))
1057 (defun ispell-aspell-find-dictionary (dict-name)
1058 "For aspell dictionary DICT-NAME, return a list of parameters if an
1059 associated data file is found or nil otherwise. List format is that
1060 of `ispell-dictionary-base-alist' elements."
1061 ;; Make sure `ispell-aspell-data-dir' is defined
1062 (or ispell-aspell-data-dir
1063 (setq ispell-aspell-data-dir
1064 (ispell-get-aspell-config-value "data-dir")))
1065 ;; Try finding associated datafile
1066 (let* ((datafile1
1067 (concat ispell-aspell-data-dir "/"
1068 ;; Strip out variant, country code, etc.
1069 (and (string-match "^[[:alpha:]]+" dict-name)
1070 (match-string 0 dict-name)) ".dat"))
1071 (datafile2
1072 (concat ispell-aspell-data-dir "/"
1073 ;; Strip out anything but xx_YY.
1074 (and (string-match "^[[:alpha:]_]+" dict-name)
1075 (match-string 0 dict-name)) ".dat"))
1076 (data-file
1077 (if (file-readable-p datafile1)
1078 datafile1
1079 (if (file-readable-p datafile2)
1080 datafile2)))
1081 otherchars)
1083 (if data-file
1084 (with-temp-buffer
1085 (insert-file-contents data-file)
1086 ;; There is zero or one line with special characters declarations.
1087 (when (search-forward-regexp "^special" nil t)
1088 (let ((specials (split-string
1089 (buffer-substring (point)
1090 (progn (end-of-line) (point))))))
1091 ;; The line looks like: special ' -** - -** . -** : -*-
1092 ;; -** means that this character
1093 ;; - doesn't appear at word start
1094 ;; * may appear in the middle of a word
1095 ;; * may appear at word end
1096 ;; `otherchars' is about the middle case.
1097 (while specials
1098 (when (eq (aref (cadr specials) 1) ?*)
1099 (push (car specials) otherchars))
1100 (setq specials (cddr specials)))))
1101 (list dict-name
1102 "[[:alpha:]]"
1103 "[^[:alpha:]]"
1104 (regexp-opt otherchars)
1105 t ; We can't tell, so set this to t
1106 (list "-d" dict-name)
1107 nil ; aspell doesn't support this
1108 ;; Here we specify the encoding to use while communicating with
1109 ;; aspell. This doesn't apply to command line arguments, so
1110 ;; just don't pass words to spellcheck as arguments...
1111 'utf-8)))))
1113 (defun ispell-aspell-add-aliases (alist)
1114 "Find aspell's dictionary aliases and add them to dictionary ALIST.
1115 Return the new dictionary alist."
1116 (let ((aliases
1117 (file-expand-wildcards
1118 (concat (or ispell-aspell-dict-dir
1119 (setq ispell-aspell-dict-dir
1120 (ispell-get-aspell-config-value "dict-dir")))
1121 "/*.alias"))))
1122 (dolist (alias-file aliases)
1123 (with-temp-buffer
1124 (insert-file-contents alias-file)
1125 ;; Look for a line "add FOO.multi", extract FOO
1126 (when (search-forward-regexp "^add \\([^.]+\\)\\.multi" nil t)
1127 (let* ((aliasname (file-name-base alias-file))
1128 (already-exists-p (assoc aliasname alist))
1129 (realname (match-string 1))
1130 (realdict (assoc realname alist)))
1131 (when (and realdict (not already-exists-p))
1132 (push (cons aliasname (cdr realdict)) alist))))))
1133 alist))
1135 ;; Make ispell.el work better with hunspell.
1137 (defvar ispell-hunspell-dict-paths-alist nil
1138 "Alist of parsed hunspell dicts and associated affix files.
1139 Will be used to parse corresponding .aff file and create associated
1140 parameters to be inserted into `ispell-hunspell-dictionary-alist'.
1141 Internal use.")
1143 (defvar ispell-hunspell-dictionary-alist nil
1144 "Alist of parsed hunspell dicts and associated parameters.
1145 This alist will initially contain names of found dicts. Associated
1146 parameters will be added when dict is used for the first time.
1147 Internal use.")
1149 (defun ispell-hunspell-fill-dictionary-entry (dict)
1150 "Fill `ispell-dictionary-alist' uninitialized entries for `DICT' and aliases.
1151 Value will be extracted from hunspell affix file and used for
1152 all uninitialized dicts using that affix file."
1153 (if (cadr (assoc dict ispell-dictionary-alist))
1154 (message "ispell-hfde: Non void entry for %s. Skipping.\n" dict)
1155 (let ((dict-alias
1156 (cadr (assoc dict ispell-hunspell-dictionary-equivs-alist)))
1157 (use-for-dicts (list dict))
1158 (dict-args-cdr (cdr (ispell-parse-hunspell-affix-file dict)))
1159 newlist)
1160 ;; Get a list of uninitialized dicts using the same affix file.
1161 (dolist (dict-equiv-alist-entry ispell-hunspell-dictionary-equivs-alist)
1162 (let ((dict-equiv-key (car dict-equiv-alist-entry))
1163 (dict-equiv-value (cadr dict-equiv-alist-entry)))
1164 (if (or (member dict dict-equiv-alist-entry)
1165 (member dict-alias dict-equiv-alist-entry))
1166 (dolist ( tmp-dict (list dict-equiv-key dict-equiv-value))
1167 (if (cadr (assoc tmp-dict ispell-dictionary-alist))
1168 (ispell-print-if-debug
1169 "ispell-hfde: %s already expanded. Skipping.\n" tmp-dict)
1170 (add-to-list 'use-for-dicts tmp-dict))))))
1171 (ispell-print-if-debug
1172 "ispell-hfde: Filling %s entry. Use for %s.\n" dict use-for-dicts)
1173 ;; The final loop.
1174 (dolist (entry ispell-dictionary-alist)
1175 (if (member (car entry) use-for-dicts)
1176 (add-to-list 'newlist
1177 (append (list (car entry)) dict-args-cdr))
1178 (add-to-list 'newlist entry)))
1179 (setq ispell-dictionary-alist newlist))))
1181 (defun ispell-parse-hunspell-affix-file (dict-key)
1182 "Parse hunspell affix file to extract parameters for `DICT-KEY'.
1183 Return a list in `ispell-dictionary-alist' format."
1184 (let ((affix-file (cadr (assoc dict-key ispell-hunspell-dict-paths-alist))))
1185 (unless affix-file
1186 (error "ispell-phaf: No matching entry for %s.\n" dict-key))
1187 (if (not (file-exists-p affix-file))
1188 (error "ispell-phaf: File \"%s\" not found.\n" affix-file))
1189 (let ((dict-name (file-name-sans-extension
1190 (file-name-nondirectory affix-file)))
1191 otherchars-string otherchars-list)
1192 (with-temp-buffer
1193 (insert-file-contents affix-file)
1194 (setq otherchars-string
1195 (save-excursion
1196 (goto-char (point-min))
1197 (if (search-forward-regexp "^WORDCHARS +" nil t )
1198 (buffer-substring (point)
1199 (progn (end-of-line) (point))))))
1200 ;; Remove trailing whitespace and extra stuff. Make list if
1201 ;; non-nil.
1202 (setq otherchars-list
1203 (if otherchars-string
1204 (split-string
1205 (if (string-match " +.*$" otherchars-string)
1206 (replace-match "" nil nil otherchars-string)
1207 otherchars-string)
1208 "" t)))
1210 ;; Fill dict entry
1211 (list dict-key
1212 "[[:alpha:]]"
1213 "[^[:alpha:]]"
1214 (if otherchars-list
1215 (regexp-opt otherchars-list)
1217 t ; many-otherchars-p: We can't tell, set to t.
1218 (list "-d" dict-name)
1219 nil ; extended-char-mode: not supported by hunspell!
1220 'utf-8)))))
1222 (defun ispell-find-hunspell-dictionaries ()
1223 "Look for installed hunspell dictionaries.
1224 Will initialize `ispell-hunspell-dictionary-alist' and
1225 `ispell-hunspell-dictionary-alist' after values found
1226 and remove `ispell-hunspell-dictionary-equivs-alist'
1227 entries if a specific dict was found."
1228 (let ((hunspell-found-dicts
1229 (split-string
1230 (with-temp-buffer
1231 (ispell-call-process ispell-program-name
1232 null-device
1235 "-D")
1236 (buffer-string))
1237 "[\n\r]+"
1239 hunspell-default-dict
1240 hunspell-default-dict-entry)
1241 (dolist (dict hunspell-found-dicts)
1242 (let* ((full-name (file-name-nondirectory dict))
1243 (basename (file-name-sans-extension full-name))
1244 (affix-file (concat dict ".aff")))
1245 (if (string-match "\\.aff$" dict)
1246 ;; Found default dictionary
1247 (if hunspell-default-dict
1248 (error "ispell-fhd: Default dict already defined as %s. Not using %s.\n"
1249 hunspell-default-dict dict)
1250 (setq affix-file dict)
1251 (setq hunspell-default-dict (list basename affix-file)))
1252 (if (and (not (assoc basename ispell-hunspell-dict-paths-alist))
1253 (file-exists-p affix-file))
1254 ;; Entry has an associated .aff file and no previous value.
1255 (let ((affix-file (expand-file-name affix-file)))
1256 (ispell-print-if-debug
1257 "++ ispell-fhd: dict-entry:%s name:%s basename:%s affix-file:%s\n"
1258 dict full-name basename affix-file)
1259 (add-to-list 'ispell-hunspell-dict-paths-alist
1260 (list basename affix-file)))
1261 (ispell-print-if-debug
1262 "-- ispell-fhd: Skipping entry: %s\n" dict)))))
1263 ;; Remove entry from aliases alist if explicit dict was found.
1264 (let (newlist)
1265 (dolist (dict ispell-hunspell-dictionary-equivs-alist)
1266 (if (assoc (car dict) ispell-hunspell-dict-paths-alist)
1267 (ispell-print-if-debug
1268 "-- ispell-fhd: Excluding %s alias. Standalone dict found.\n"
1269 (car dict))
1270 (add-to-list 'newlist dict)))
1271 (setq ispell-hunspell-dictionary-equivs-alist newlist))
1272 ;; Add known hunspell aliases
1273 (dolist (dict-equiv ispell-hunspell-dictionary-equivs-alist)
1274 (let ((dict-equiv-key (car dict-equiv))
1275 (dict-equiv-value (cadr dict-equiv))
1276 (exclude-aliases (list ;; Exclude TeX aliases
1277 "esperanto-tex"
1278 "francais7"
1279 "francais-tex"
1280 "norsk7-tex")))
1281 (if (and (assoc dict-equiv-value ispell-hunspell-dict-paths-alist)
1282 (not (assoc dict-equiv-key ispell-hunspell-dict-paths-alist))
1283 (not (member dict-equiv-key exclude-aliases)))
1284 (let ((affix-file (cadr (assoc dict-equiv-value
1285 ispell-hunspell-dict-paths-alist))))
1286 (ispell-print-if-debug "++ ispell-fhd: Adding alias %s -> %s.\n"
1287 dict-equiv-key affix-file)
1288 (add-to-list
1289 'ispell-hunspell-dict-paths-alist
1290 (list dict-equiv-key affix-file))))))
1291 ;; Parse and set values for default dictionary.
1292 (setq hunspell-default-dict (car hunspell-default-dict))
1293 (setq hunspell-default-dict-entry
1294 (ispell-parse-hunspell-affix-file hunspell-default-dict))
1295 ;; Create an alist of found dicts with only names, except for default dict.
1296 (setq ispell-hunspell-dictionary-alist
1297 (list (append (list nil) (cdr hunspell-default-dict-entry))))
1298 (dolist (dict (mapcar 'car ispell-hunspell-dict-paths-alist))
1299 (if (string= dict hunspell-default-dict)
1300 (add-to-list 'ispell-hunspell-dictionary-alist
1301 hunspell-default-dict-entry)
1302 (add-to-list 'ispell-hunspell-dictionary-alist
1303 (list dict))))))
1305 ;; Set params according to the selected spellchecker
1307 (defvar ispell-last-program-name nil
1308 "Last value of `ispell-program-name'. Internal use.")
1310 (defvar ispell-initialize-spellchecker-hook nil
1311 "Normal hook run on spellchecker initialization.
1312 This hook is run when a spellchecker is used for the first
1313 time, before `ispell-dictionary-alist' is set. It is intended for
1314 sysadmins to override entries in `ispell-dictionary-base-alist'
1315 by putting those overrides in `ispell-base-dicts-override-alist', which is
1316 a dynamically scoped var with same format as `ispell-dictionary-alist'.
1317 This alist will not override the auto-detected values (e.g. if a recent
1318 aspell is used along with Emacs).")
1320 (defun ispell-set-spellchecker-params ()
1321 "Initialize some spellchecker parameters when changed or first used."
1322 (unless (eq ispell-last-program-name ispell-program-name)
1323 (setq ispell-last-program-name ispell-program-name)
1324 (ispell-kill-ispell t)
1325 (if (and (condition-case ()
1326 (progn
1327 (setq ispell-library-directory (ispell-check-version))
1329 (error nil))
1330 ispell-encoding8-command
1331 ispell-emacs-alpha-regexp)
1332 ;; auto-detection will only be used if spellchecker is not
1333 ;; ispell, supports a way to set communication to UTF-8 and
1334 ;; Emacs flavor supports [:alpha:]
1335 (if ispell-really-aspell
1336 (or ispell-aspell-dictionary-alist
1337 (ispell-find-aspell-dictionaries))
1338 (if ispell-really-hunspell
1339 (or ispell-hunspell-dictionary-alist
1340 (ispell-find-hunspell-dictionaries)))))
1342 ;; Substitute ispell-dictionary-alist with the list of
1343 ;; dictionaries corresponding to the given spellchecker.
1344 ;; If a recent aspell or hunspell, use the list of really
1345 ;; installed dictionaries and add to it elements of the original
1346 ;; list that are not present there. Allow distro info.
1347 (let ((found-dicts-alist
1348 (if (and ispell-encoding8-command
1349 ispell-emacs-alpha-regexp)
1350 (if ispell-really-aspell
1351 ispell-aspell-dictionary-alist
1352 (if ispell-really-hunspell
1353 ispell-hunspell-dictionary-alist))
1354 nil))
1355 (ispell-dictionary-base-alist ispell-dictionary-base-alist)
1356 ispell-base-dicts-override-alist ; Override only base-dicts-alist
1357 all-dicts-alist)
1359 ;; While ispell and aspell (through aliases) use the traditional
1360 ;; dict naming originally expected by ispell.el, hunspell
1361 ;; uses locale based names with no alias. We need to map
1362 ;; standard names to locale based names to make default dict
1363 ;; definitions available for hunspell.
1364 (if ispell-really-hunspell
1365 (let (tmp-dicts-alist)
1366 (dolist (adict ispell-dictionary-base-alist)
1367 (let* ((dict-name (nth 0 adict))
1368 (dict-equiv
1369 (cadr (assoc dict-name
1370 ispell-hunspell-dictionary-equivs-alist)))
1371 (ispell-args (nth 5 adict))
1372 (ispell-args-has-d (member "-d" ispell-args))
1373 skip-dict)
1374 ;; Remove "-d" option from `ispell-args' if present
1375 (if ispell-args-has-d
1376 (let ((ispell-args-after-d
1377 (cdr (cdr ispell-args-has-d)))
1378 (ispell-args-before-d
1379 (butlast ispell-args (length ispell-args-has-d))))
1380 (setq ispell-args
1381 (nconc ispell-args-before-d
1382 ispell-args-after-d))))
1383 ;; Unless default dict, re-add "-d" option with the mapped value
1384 (if dict-name
1385 (if dict-equiv
1386 (setq ispell-args
1387 (nconc ispell-args (list "-d" dict-equiv)))
1388 (message
1389 "ispell-set-spellchecker-params: Missing hunspell equiv for \"%s\". Skipping."
1390 dict-name)
1391 (setq skip-dict t)))
1393 (unless skip-dict
1394 (add-to-list 'tmp-dicts-alist
1395 (list
1396 dict-name ; dict name
1397 (nth 1 adict) ; casechars
1398 (nth 2 adict) ; not-casechars
1399 (nth 3 adict) ; otherchars
1400 (nth 4 adict) ; many-otherchars-p
1401 ispell-args ; ispell-args
1402 (nth 6 adict) ; extended-character-mode
1403 (nth 7 adict) ; dict encoding
1404 ))))
1405 (setq ispell-dictionary-base-alist tmp-dicts-alist))))
1407 (run-hooks 'ispell-initialize-spellchecker-hook)
1409 ;; Add dicts to ``ispell-dictionary-alist'' unless already present.
1410 (dolist (dict (append found-dicts-alist
1411 ispell-base-dicts-override-alist
1412 ispell-dictionary-base-alist))
1413 (unless (assoc (car dict) all-dicts-alist)
1414 (add-to-list 'all-dicts-alist dict)))
1415 (setq ispell-dictionary-alist all-dicts-alist))
1417 ;; If Emacs flavor supports [:alpha:] use it for global dicts. If
1418 ;; spellchecker also supports UTF-8 via command-line option use it
1419 ;; in communication. This does not affect definitions in your
1420 ;; init file.
1421 (if ispell-emacs-alpha-regexp
1422 (let (tmp-dicts-alist)
1423 (dolist (adict ispell-dictionary-alist)
1424 (if (cadr adict) ;; Do not touch hunspell uninitialized entries
1425 (add-to-list 'tmp-dicts-alist
1426 (list
1427 (nth 0 adict) ; dict name
1428 "[[:alpha:]]" ; casechars
1429 "[^[:alpha:]]" ; not-casechars
1430 (nth 3 adict) ; otherchars
1431 (nth 4 adict) ; many-otherchars-p
1432 (nth 5 adict) ; ispell-args
1433 (nth 6 adict) ; extended-character-mode
1434 (if ispell-encoding8-command
1435 'utf-8
1436 (nth 7 adict))))
1437 (add-to-list 'tmp-dicts-alist adict)))
1438 (setq ispell-dictionary-alist tmp-dicts-alist)))))
1440 (defun ispell-valid-dictionary-list ()
1441 "Return a list of valid dictionaries.
1442 The variable `ispell-library-directory' defines their location."
1443 ;; Initialize variables and dictionaries alists for desired spellchecker.
1444 ;; Make sure ispell.el is loaded to avoid some autoload loops in XEmacs
1445 ;; (and may be others)
1446 (if (featurep 'ispell)
1447 (ispell-set-spellchecker-params))
1449 (let ((dicts (append ispell-local-dictionary-alist ispell-dictionary-alist))
1450 (dict-list (cons "default" nil))
1451 name dict-bname)
1452 (dolist (dict dicts)
1453 (setq name (car dict)
1454 dict-bname (or (car (cdr (member "-d" (nth 5 dict))))
1455 name))
1456 ;; Include if the dictionary is in the library, or dir not defined.
1457 (if (and
1458 name
1459 ;; For Aspell, we already know which dictionaries exist.
1460 (or ispell-really-aspell
1461 ;; Include all dictionaries if lib directory not known.
1462 ;; Same for Hunspell, where ispell-library-directory is nil.
1463 (not ispell-library-directory)
1464 (file-exists-p (concat ispell-library-directory
1465 "/" dict-bname ".hash"))
1466 (file-exists-p (concat ispell-library-directory
1467 "/" dict-bname ".has"))))
1468 (push name dict-list)))
1469 dict-list))
1471 ;; Define commands in menu in opposite order you want them to appear.
1472 ;;;###autoload
1473 (if ispell-menu-map-needed
1474 (progn
1475 (setq ispell-menu-map (make-sparse-keymap "Spell"))
1476 (define-key ispell-menu-map [ispell-change-dictionary]
1477 `(menu-item ,(purecopy "Change Dictionary...") ispell-change-dictionary
1478 :help ,(purecopy "Supply explicit dictionary file name")))
1479 (define-key ispell-menu-map [ispell-kill-ispell]
1480 `(menu-item ,(purecopy "Kill Process")
1481 (lambda () (interactive) (ispell-kill-ispell nil 'clear))
1482 :enable (and (boundp 'ispell-process) ispell-process
1483 (eq (ispell-process-status) 'run))
1484 :help ,(purecopy "Terminate Ispell subprocess")))
1485 (define-key ispell-menu-map [ispell-pdict-save]
1486 `(menu-item ,(purecopy "Save Dictionary")
1487 (lambda () (interactive) (ispell-pdict-save t t))
1488 :help ,(purecopy "Save personal dictionary")))
1489 (define-key ispell-menu-map [ispell-customize]
1490 `(menu-item ,(purecopy "Customize...")
1491 (lambda () (interactive) (customize-group 'ispell))
1492 :help ,(purecopy "Customize spell checking options")))
1493 (define-key ispell-menu-map [ispell-help]
1494 ;; use (x-popup-menu last-nonmenu-event(list "" ispell-help-list)) ?
1495 `(menu-item ,(purecopy "Help")
1496 (lambda () (interactive) (describe-function 'ispell-help))
1497 :help ,(purecopy "Show standard Ispell keybindings and commands")))
1498 (define-key ispell-menu-map [flyspell-mode]
1499 `(menu-item ,(purecopy "Automatic spell checking (Flyspell)")
1500 flyspell-mode
1501 :help ,(purecopy "Check spelling while you edit the text")
1502 :button (:toggle . (bound-and-true-p flyspell-mode))))
1503 (define-key ispell-menu-map [ispell-complete-word]
1504 `(menu-item ,(purecopy "Complete Word") ispell-complete-word
1505 :help ,(purecopy "Complete word at cursor using dictionary")))
1506 (define-key ispell-menu-map [ispell-complete-word-interior-frag]
1507 `(menu-item ,(purecopy "Complete Word Fragment")
1508 ispell-complete-word-interior-frag
1509 :help ,(purecopy "Complete word fragment at cursor")))))
1511 ;;;###autoload
1512 (if ispell-menu-map-needed
1513 (progn
1514 (define-key ispell-menu-map [ispell-continue]
1515 `(menu-item ,(purecopy "Continue Spell-Checking") ispell-continue
1516 :enable (and (boundp 'ispell-region-end)
1517 (marker-position ispell-region-end)
1518 (equal (marker-buffer ispell-region-end)
1519 (current-buffer)))
1520 :help ,(purecopy "Continue spell checking last region")))
1521 (define-key ispell-menu-map [ispell-word]
1522 `(menu-item ,(purecopy "Spell-Check Word") ispell-word
1523 :help ,(purecopy "Spell-check word at cursor")))
1524 (define-key ispell-menu-map [ispell-comments-and-strings]
1525 `(menu-item ,(purecopy "Spell-Check Comments")
1526 ispell-comments-and-strings
1527 :help ,(purecopy "Spell-check only comments and strings")))))
1529 ;;;###autoload
1530 (if ispell-menu-map-needed
1531 (progn
1532 (define-key ispell-menu-map [ispell-region]
1533 `(menu-item ,(purecopy "Spell-Check Region") ispell-region
1534 :enable mark-active
1535 :help ,(purecopy "Spell-check text in marked region")))
1536 (define-key ispell-menu-map [ispell-message]
1537 `(menu-item ,(purecopy "Spell-Check Message") ispell-message
1538 :visible (eq major-mode 'mail-mode)
1539 :help ,(purecopy "Skip headers and included message text")))
1540 (define-key ispell-menu-map [ispell-buffer]
1541 `(menu-item ,(purecopy "Spell-Check Buffer") ispell-buffer
1542 :help ,(purecopy "Check spelling of selected buffer")))
1543 ;;(put 'ispell-region 'menu-enable 'mark-active)
1544 (fset 'ispell-menu-map (symbol-value 'ispell-menu-map))))
1546 ;;; XEmacs versions 19 & 20
1547 (if (and (featurep 'xemacs)
1548 (featurep 'menubar)
1549 ;;(null ispell-menu-xemacs)
1550 (not (and (boundp 'infodock-version) infodock-version)))
1551 (let ((dicts (if (fboundp 'ispell-valid-dictionary-list)
1552 (reverse (ispell-valid-dictionary-list))))
1553 (current-menubar (or current-menubar default-menubar))
1554 (menu
1555 '(["Help" (describe-function 'ispell-help) t]
1556 ;;["Help" (popup-menu ispell-help-list) t]
1557 ["Check Message" ispell-message t]
1558 ["Check Buffer" ispell-buffer t]
1559 ["Check Comments" ispell-comments-and-strings t]
1560 ["Check Word" ispell-word t]
1561 ["Check Region" ispell-region (or (not zmacs-regions) (mark))]
1562 ["Continue Check" ispell-continue t]
1563 ["Complete Word Frag"ispell-complete-word-interior-frag t]
1564 ["Complete Word" ispell-complete-word t]
1565 ["Kill Process" (ispell-kill-ispell nil 'clear) t]
1566 ["Customize..." (customize-group 'ispell) t]
1567 ;; flyspell-mode may not be bound...
1568 ;;["flyspell" flyspell-mode
1569 ;; :style toggle :selected flyspell-mode ]
1571 ["Save Personal Dict"(ispell-pdict-save t t) t]
1572 ["Change Dictionary" ispell-change-dictionary t])))
1573 (if (null dicts)
1574 (setq dicts (cons "default" nil)))
1575 (dolist (name dicts)
1576 (setq menu (append menu
1577 (list
1578 (vector
1579 (concat "Select " (capitalize name))
1580 (list 'ispell-change-dictionary name)
1581 t)))))
1582 (setq ispell-menu-xemacs menu)
1583 (if current-menubar
1584 (progn
1585 (if (car (find-menu-item current-menubar '("Cmds")))
1586 (progn
1587 ;; XEmacs 21.2
1588 (delete-menu-item '("Cmds" "Spell-Check"))
1589 (add-menu '("Cmds") "Spell-Check" ispell-menu-xemacs))
1590 ;; previous
1591 (delete-menu-item '("Edit" "Spell")) ; in case already defined
1592 (add-menu '("Edit") "Spell" ispell-menu-xemacs))))))
1594 (defalias 'ispell-int-char
1595 ;; Allow incrementing characters as integers in XEmacs 20
1596 (if (and (featurep 'xemacs)
1597 (fboundp 'int-char))
1598 'int-char
1599 ;; Emacs and XEmacs 19 or earlier
1600 'identity))
1603 ;;; **********************************************************************
1605 (defvar ispell-current-dictionary nil
1606 "The name of the current dictionary, or nil for the default.
1607 This is passed to the ispell process using the `-d' switch and is
1608 used as key in `ispell-local-dictionary-alist' and `ispell-dictionary-alist'.")
1610 (defvar ispell-current-personal-dictionary nil
1611 "The name of the current personal dictionary, or nil for the default.
1612 This is passed to the ispell process using the `-p' switch.")
1614 (defun ispell-decode-string (str)
1615 "Decodes multibyte character strings.
1616 Protects against bogus binding of `enable-multibyte-characters' in XEmacs."
1617 ;; FIXME: enable-multibyte-characters is read-only, so bogus bindings are
1618 ;; really nasty (they signal an error in Emacs): Who does that? --Stef
1619 (if (and (or (featurep 'xemacs)
1620 (and (boundp 'enable-multibyte-characters)
1621 enable-multibyte-characters))
1622 (fboundp 'decode-coding-string)
1623 (ispell-get-coding-system))
1624 (decode-coding-string str (ispell-get-coding-system))
1625 str))
1627 ;; Return a string decoded from Nth element of the current dictionary.
1628 (defun ispell-get-decoded-string (n)
1629 "Get the decoded string in slot N of the descriptor of the current dict."
1630 (let* ((slot (or
1631 (assoc ispell-current-dictionary ispell-local-dictionary-alist)
1632 (assoc ispell-current-dictionary ispell-dictionary-alist)
1633 (error "No data for dictionary \"%s\", neither in `ispell-local-dictionary-alist' nor in `ispell-dictionary-alist'"
1634 ispell-current-dictionary)))
1635 (str (nth n slot)))
1636 (when (and (> (length str) 0)
1637 (not (multibyte-string-p str)))
1638 (setq str (ispell-decode-string str))
1639 (or (multibyte-string-p str)
1640 (setq str (string-to-multibyte str))))
1641 str))
1643 (defun ispell-get-casechars ()
1644 (ispell-get-decoded-string 1))
1645 (defun ispell-get-not-casechars ()
1646 (ispell-get-decoded-string 2))
1647 (defun ispell-get-otherchars ()
1648 (ispell-get-decoded-string 3))
1649 (defun ispell-get-many-otherchars-p ()
1650 (nth 4 (or (assoc ispell-current-dictionary ispell-local-dictionary-alist)
1651 (assoc ispell-current-dictionary ispell-dictionary-alist))))
1652 (defun ispell-get-ispell-args ()
1653 (nth 5 (or (assoc ispell-current-dictionary ispell-local-dictionary-alist)
1654 (assoc ispell-current-dictionary ispell-dictionary-alist))))
1655 (defun ispell-get-extended-character-mode ()
1656 (if ispell-really-hunspell ;; hunspell treats ~word as ordinary words
1657 nil ;; in pipe mode. Disable extended-char-mode
1658 (nth 6 (or (assoc ispell-current-dictionary ispell-local-dictionary-alist)
1659 (assoc ispell-current-dictionary ispell-dictionary-alist)))))
1660 (defun ispell-get-coding-system ()
1661 (nth 7 (or (assoc ispell-current-dictionary ispell-local-dictionary-alist)
1662 (assoc ispell-current-dictionary ispell-dictionary-alist))))
1665 (defvar ispell-pdict-modified-p nil
1666 "Non-nil means personal dictionary has modifications to be saved.")
1668 ;; If you want to save the dictionary when quitting, must do so explicitly.
1669 ;; When non-nil, the spell session is terminated.
1670 ;; When numeric, contains cursor location in buffer, and cursor remains there.
1671 (defvar ispell-quit nil)
1673 (defvar ispell-process-directory nil
1674 "The directory where `ispell-process' was started.")
1676 (defvar ispell-filter nil
1677 "Output filter from piped calls to Ispell.")
1679 (defvar ispell-filter-continue nil
1680 "Control variable for Ispell filter function.")
1682 (defvar ispell-output-buffer nil
1683 "Buffer used for reading output of a synchronous Ispell subprocess.")
1685 (defvar ispell-session-buffer nil
1686 "Buffer used for passing input to a synchronous Ispell subprocess.")
1688 (defvar ispell-cmd-args nil
1689 "Command-line arguments to pass to a synchronous Ispell subprocess.")
1691 (defvar ispell-query-replace-marker (make-marker)
1692 "Marker for `query-replace' processing.")
1694 (defvar ispell-recursive-edit-marker (make-marker)
1695 "Marker for return point from recursive edit.")
1697 (defvar ispell-checking-message nil
1698 "Non-nil when we're checking a mail message.
1699 Set to the MIME boundary locations when checking messages.")
1701 (defconst ispell-choices-buffer "*Choices*")
1703 (defvar ispell-overlay nil "Overlay variable for Ispell highlighting.")
1705 ;;; *** Buffer Local Definitions ***
1707 (defconst ispell-words-keyword "LocalWords: "
1708 "The keyword for local oddly-spelled words to accept.
1709 The keyword will be followed by any number of local word spellings.
1710 There can be multiple instances of this keyword in the file.")
1712 (defconst ispell-dictionary-keyword "Local IspellDict: "
1713 "The keyword for a local dictionary to use.
1714 The keyword must be followed by a valid dictionary name, defined in
1715 `ispell-local-dictionary-alist' or `ispell-dictionary-alist'.
1716 When multiple occurrences exist, the last keyword
1717 definition is used.")
1719 (defconst ispell-pdict-keyword "Local IspellPersDict: "
1720 "The keyword for defining buffer local dictionaries.
1721 Keyword must be followed by the filename of a personal dictionary.
1722 The last occurring definition in the buffer will be used.")
1724 (defconst ispell-parsing-keyword "Local IspellParsing: "
1725 "The keyword for overriding default Ispell parsing.
1726 The above keyword string should be followed by `latex-mode' or
1727 `nroff-mode' to put the current buffer into the desired parsing mode.
1729 Extended character mode can be changed for this buffer by placing
1730 a `~' followed by an extended-character mode -- such as `~.tex'.
1731 The last occurring definition in the buffer will be used.")
1733 ;;;###autoload
1734 (defvar ispell-skip-region-alist
1735 `((ispell-words-keyword forward-line)
1736 (ispell-dictionary-keyword forward-line)
1737 (ispell-pdict-keyword forward-line)
1738 (ispell-parsing-keyword forward-line)
1739 (,(purecopy "^---*BEGIN PGP [A-Z ]*--*")
1740 . ,(purecopy "^---*END PGP [A-Z ]*--*"))
1741 ;; assume multiline uuencoded file? "\nM.*$"?
1742 (,(purecopy "^begin [0-9][0-9][0-9] [^ \t]+$") . ,(purecopy "\nend\n"))
1743 (,(purecopy "^%!PS-Adobe-[123].0") . ,(purecopy "\n%%EOF\n"))
1744 (,(purecopy "^---* \\(Start of \\)?[Ff]orwarded [Mm]essage")
1745 . ,(purecopy "^---* End of [Ff]orwarded [Mm]essage"))
1746 ;; Matches e-mail addresses, file names, http addresses, etc. The
1747 ;; `-+' `_+' patterns are necessary for performance reasons when
1748 ;; `-' or `_' part of word syntax.
1749 (,(purecopy "\\(--+\\|_+\\|\\(/\\w\\|\\(\\(\\w\\|[-_]\\)+[.:@]\\)\\)\\(\\w\\|[-_]\\)*\\([.:/@]+\\(\\w\\|[-_~=?&]\\)+\\)+\\)"))
1750 ;; above checks /.\w sequences
1751 ;;("\\(--+\\|\\(/\\|\\(\\(\\w\\|[-_]\\)+[.:@]\\)\\)\\(\\w\\|[-_]\\)*\\([.:/@]+\\(\\w\\|[-_~=?&]\\)+\\)+\\)")
1752 ;; This is a pretty complex regexp. It can be simplified to the following:
1753 ;; "\\(\\w\\|[-_]\\)*\\([.:/@]+\\(\\w\\|[-_]\\|~\\)+\\)+"
1754 ;; but some valid text will be skipped, e.g. "his/her". This could be
1755 ;; fixed up (at the expense of a moderately more complex regexp)
1756 ;; by not allowing "/" to be the character which triggers the
1757 ;; identification of the computer name, e.g.:
1758 ;; "\\(\\w\\|[-_]\\)+[.:@]\\(\\w\\|[-_]\\)*\\([.:/@]+\\(\\w\\|[-_]\\|~\\)+\\)+"
1760 "Alist expressing beginning and end of regions not to spell check.
1761 The alist key must be a regular expression.
1762 Valid forms include:
1763 (KEY) - just skip the key.
1764 (KEY . REGEXP) - skip to the end of REGEXP. REGEXP may be string or symbol.
1765 (KEY REGEXP) - skip to end of REGEXP. REGEXP must be a string.
1766 (KEY FUNCTION ARGS) - FUNCTION called with ARGS returns end of region.")
1767 (put 'ispell-skip-region-alist 'risky-local-variable t)
1770 ;;;###autoload
1771 (defvar ispell-tex-skip-alists
1772 (purecopy
1773 '((;;("%\\[" . "%\\]") ; AMStex block comment...
1774 ;; All the standard LaTeX keywords from L. Lamport's guide:
1775 ;; \cite, \hspace, \hspace*, \hyphenation, \include, \includeonly, \input,
1776 ;; \label, \nocite, \rule (in ispell - rest included here)
1777 ("\\\\addcontentsline" ispell-tex-arg-end 2)
1778 ("\\\\add\\(tocontents\\|vspace\\)" ispell-tex-arg-end)
1779 ("\\\\\\([aA]lph\\|arabic\\)" ispell-tex-arg-end)
1780 ;;("\\\\author" ispell-tex-arg-end)
1781 ("\\\\bibliographystyle" ispell-tex-arg-end)
1782 ("\\\\makebox" ispell-tex-arg-end 0)
1783 ("\\\\e?psfig" ispell-tex-arg-end)
1784 ("\\\\document\\(class\\|style\\)" .
1785 "\\\\begin[ \t\n]*{[ \t\n]*document[ \t\n]*}"))
1786 (;; delimited with \begin. In ispell: displaymath, eqnarray, eqnarray*,
1787 ;; equation, minipage, picture, tabular, tabular* (ispell)
1788 ("\\(figure\\|table\\)\\*?" ispell-tex-arg-end 0)
1789 ("list" ispell-tex-arg-end 2)
1790 ("program" . "\\\\end[ \t\n]*{[ \t\n]*program[ \t\n]*}")
1791 ("verbatim\\*?" . "\\\\end[ \t\n]*{[ \t\n]*verbatim\\*?[ \t\n]*}"))))
1792 "Lists of regions to be skipped in TeX mode.
1793 First list is used raw.
1794 Second list has key placed inside \\begin{}.
1796 Delete or add any regions you want to be automatically selected
1797 for skipping in latex mode.")
1798 (put 'ispell-tex-skip-alist 'risky-local-variable t)
1801 ;;;###autoload
1802 (defconst ispell-html-skip-alists
1803 '(("<[cC][oO][dD][eE]\\>[^>]*>" "</[cC][oO][dD][eE]*>")
1804 ("<[sS][cC][rR][iI][pP][tT]\\>[^>]*>" "</[sS][cC][rR][iI][pP][tT]>")
1805 ("<[aA][pP][pP][lL][eE][tT]\\>[^>]*>" "</[aA][pP][pP][lL][eE][tT]>")
1806 ("<[vV][eE][rR][bB]\\>[^>]*>" "<[vV][eE][rR][bB]\\>[^>]*>")
1807 ;;("<[tT][tT]\\>[^>]*>" "<[tT][tT]\\>[^>]*>")
1808 ("<[tT][tT]/" "/")
1809 ("<[^ \t\n>]" ">")
1810 ("&[^ \t\n;]" "[; \t\n]"))
1811 "Lists of start and end keys to skip in HTML buffers.
1812 Same format as `ispell-skip-region-alist'.
1813 Note - substrings of other matches must come last
1814 (e.g. \"<[tT][tT]/\" and \"<[^ \\t\\n>]\").")
1815 (put 'ispell-html-skip-alists 'risky-local-variable t)
1817 (defvar ispell-local-pdict ispell-personal-dictionary
1818 "A buffer local variable containing the current personal dictionary.
1819 If non-nil, the value must be a string, which is a file name.
1821 If you specify a personal dictionary for the current buffer which is
1822 different from the current personal dictionary, the effect is similar
1823 to calling \\[ispell-change-dictionary]. This variable is automatically
1824 set when defined in the file with either `ispell-pdict-keyword' or the
1825 local variable syntax.")
1827 (make-variable-buffer-local 'ispell-local-pdict)
1828 ;;;###autoload(put 'ispell-local-pdict 'safe-local-variable 'stringp)
1830 (defvar ispell-buffer-local-name nil
1831 "Contains the buffer name if local word definitions were used.
1832 Ispell is then restarted because the local words could conflict.")
1834 (defvar ispell-buffer-session-localwords nil
1835 "List of words accepted for session in this buffer.")
1837 (make-variable-buffer-local 'ispell-buffer-session-localwords)
1839 (defvar ispell-parser 'use-mode-name
1840 "Indicates whether ispell should parse the current buffer as TeX Code.
1841 Special value `use-mode-name' tries to guess using the name of `major-mode'.
1842 Default parser is `nroff'.
1843 Currently the only other valid parser is `tex'.
1845 You can set this variable in hooks in your init file -- eg:
1847 \(add-hook 'tex-mode-hook (lambda () (setq ispell-parser 'tex)))")
1849 (defvar ispell-region-end (make-marker)
1850 "Marker that allows spelling continuations.")
1852 (defvar ispell-check-only nil
1853 "If non-nil, `ispell-word' does not try to correct the word.")
1856 ;;; **********************************************************************
1857 ;;; **********************************************************************
1861 ;;;###autoload (define-key esc-map "$" 'ispell-word)
1864 (defun ispell-accept-output (&optional timeout-secs timeout-msecs)
1865 "Wait for output from ispell process, or TIMEOUT-SECS and TIMEOUT-MSECS.
1866 If asynchronous subprocesses are not supported, call function `ispell-filter'
1867 and pass it the output of the last ispell invocation."
1868 (if ispell-async-processp
1869 (accept-process-output ispell-process timeout-secs timeout-msecs)
1870 (if (null ispell-process)
1871 (error "No Ispell process to read output from!")
1872 (let ((buf ispell-output-buffer)
1873 ispell-output)
1874 (if (not (bufferp buf))
1875 (setq ispell-filter nil)
1876 (with-current-buffer buf
1877 (setq ispell-output (buffer-substring-no-properties
1878 (point-min) (point-max))))
1879 (ispell-filter t ispell-output)
1880 (with-current-buffer buf
1881 (erase-buffer)))))))
1883 (defun ispell-send-replacement (misspelled replacement)
1884 "Notify aspell that MISSPELLED should be spelled REPLACEMENT.
1885 This allows it to improve the suggestion list based on actual misspellings."
1886 (and ispell-really-aspell
1887 (ispell-send-string (concat "$$ra " misspelled "," replacement "\n"))))
1890 (defun ispell-send-string (string)
1891 "Send the string STRING to the Ispell process."
1892 (if ispell-async-processp
1893 (process-send-string ispell-process string)
1894 ;; Asynchronous subprocesses aren't supported on this losing system.
1895 ;; We keep all the directives passed to Ispell during the entire
1896 ;; session in a buffer, and pass them anew each time we invoke
1897 ;; Ispell to process another chunk of text. (Yes, I know this is a
1898 ;; terrible kludge, and it's a bit slow, but it does get the work done.)
1899 (let ((cmd (aref string 0))
1900 ;; The following commands are not passed to Ispell until
1901 ;; we have a *real* reason to invoke it.
1902 (cmds-to-defer '(?* ?@ ?~ ?+ ?- ?! ?%))
1903 (session-buf ispell-session-buffer)
1904 (output-buf ispell-output-buffer)
1905 (ispell-args ispell-cmd-args)
1906 (defdir ispell-process-directory)
1907 prev-pos)
1908 (with-current-buffer session-buf
1909 (setq prev-pos (point))
1910 (setq default-directory defdir)
1911 (insert string)
1912 (if (not (memq cmd cmds-to-defer))
1913 (let (coding-system-for-read coding-system-for-write status)
1914 (if (and (boundp 'enable-multibyte-characters)
1915 enable-multibyte-characters)
1916 (setq coding-system-for-read (ispell-get-coding-system)
1917 coding-system-for-write (ispell-get-coding-system)))
1918 (set-buffer output-buf)
1919 (erase-buffer)
1920 (set-buffer session-buf)
1921 (setq status
1922 (apply 'ispell-call-process-region
1923 (point-min) (point-max)
1924 ispell-program-name nil
1925 output-buf nil
1926 "-a"
1927 ;; hunspell -m option means something different
1928 (if ispell-really-hunspell "" "-m")
1929 ispell-args))
1930 (set-buffer output-buf)
1931 (goto-char (point-min))
1932 (save-match-data
1933 (if (not (looking-at "@(#) "))
1934 (error "Ispell error: %s"
1935 (buffer-substring-no-properties
1936 (point) (progn (end-of-line) (point)))))
1937 ;; If STRING is "^Z\n", we just started Ispell and need
1938 ;; to retain its version ID line in the output buffer.
1939 ;; Otherwise, remove the ID line, as it will confuse
1940 ;; `ispell-filter'.
1941 (or (string= string "\032\n")
1942 (progn
1943 (forward-line)
1944 (delete-region (point-min) (point))))
1945 ;; If STRING begins with ^ or any normal character, we need
1946 ;; to remove the last line from the session buffer, since it
1947 ;; was just spell-checked, and we don't want to check it again.
1948 ;; The same goes for the # command, since Ispell already saved
1949 ;; the personal dictionary.
1950 (set-buffer session-buf)
1951 (delete-region prev-pos (point))
1952 ;; Ispell run synchronously saves the personal dictionary
1953 ;; after each successful command. So we can remove any
1954 ;; lines in the session buffer that insert words into the
1955 ;; dictionary.
1956 (if (memq status '(0 nil))
1957 (let ((more-lines t))
1958 (goto-char (point-min))
1959 (while more-lines
1960 (if (looking-at "^\\*")
1961 (let ((start (point)))
1962 (forward-line)
1963 (delete-region start (point)))
1964 (setq more-lines (= 0 (forward-line))))))))))))))
1967 ;;;###autoload
1968 (defun ispell-word (&optional following quietly continue region)
1969 "Check spelling of word under or before the cursor.
1970 If the word is not found in dictionary, display possible corrections
1971 in a window allowing you to choose one.
1973 If optional argument FOLLOWING is non-nil or if `ispell-following-word'
1974 is non-nil when called interactively, then the following word
1975 \(rather than preceding\) is checked when the cursor is not over a word.
1976 When the optional argument QUIETLY is non-nil or `ispell-quietly' is non-nil
1977 when called interactively, non-corrective messages are suppressed.
1979 With a prefix argument (or if CONTINUE is non-nil),
1980 resume interrupted spell-checking of a buffer or region.
1982 Interactively, in Transient Mark mode when the mark is active, call
1983 `ispell-region' to check the active region for spelling errors.
1985 Word syntax is controlled by the definition of the chosen dictionary,
1986 which is in `ispell-local-dictionary-alist' or `ispell-dictionary-alist'.
1988 This will check or reload the dictionary. Use \\[ispell-change-dictionary]
1989 or \\[ispell-region] to update the Ispell process.
1991 Return values:
1992 nil word is correct or spelling is accepted.
1993 0 word is inserted into buffer-local definitions.
1994 \"word\" word corrected from word list.
1995 \(\"word\" arg\) word is hand entered.
1996 quit spell session exited."
1997 (interactive (list ispell-following-word ispell-quietly current-prefix-arg t))
1998 (cond
1999 ((and region
2000 (if (featurep 'emacs)
2001 (use-region-p)
2002 (and (boundp 'transient-mark-mode) transient-mark-mode
2003 (boundp 'mark-active) mark-active
2004 (not (eq (region-beginning) (region-end))))))
2005 (ispell-region (region-beginning) (region-end)))
2006 (continue (ispell-continue))
2008 (ispell-set-spellchecker-params) ; Initialize variables and dicts alists
2009 (ispell-accept-buffer-local-defs) ; use the correct dictionary
2010 (let ((cursor-location (point)) ; retain cursor location
2011 (word (ispell-get-word following))
2012 start end poss new-word replace)
2013 ;; De-structure return word info list.
2014 (setq start (car (cdr word))
2015 end (car (cdr (cdr word)))
2016 word (car word))
2018 ;; At this point it used to ignore 2-letter words.
2019 ;; But that is silly; if the user asks for it, we should do it. - rms.
2020 (or quietly
2021 (message "Checking spelling of %s..."
2022 (funcall ispell-format-word-function word)))
2023 (ispell-send-string "%\n") ; put in verbose mode
2024 (ispell-send-string (concat "^" word "\n"))
2025 ;; wait until ispell has processed word
2026 (while (progn
2027 (ispell-accept-output)
2028 (not (string= "" (car ispell-filter)))))
2029 ;;(ispell-send-string "!\n") ;back to terse mode.
2030 (setq ispell-filter (cdr ispell-filter)) ; remove extra \n
2031 (if (and ispell-filter (listp ispell-filter))
2032 (if (> (length ispell-filter) 1)
2033 (error "Ispell and its process have different character maps")
2034 (setq poss (ispell-parse-output (car ispell-filter)))))
2035 (cond ((eq poss t)
2036 (or quietly
2037 (message "%s is correct"
2038 (funcall ispell-format-word-function word)))
2039 (and (featurep 'xemacs)
2040 (extent-at start)
2041 (and (fboundp 'delete-extent)
2042 (delete-extent (extent-at start)))))
2043 ((stringp poss)
2044 (or quietly
2045 (message "%s is correct because of root %s"
2046 (funcall ispell-format-word-function word)
2047 (funcall ispell-format-word-function poss)))
2048 (and (featurep 'xemacs)
2049 (extent-at start)
2050 (and (fboundp 'delete-extent)
2051 (delete-extent (extent-at start)))))
2052 ((null poss)
2053 (message "Error checking word %s using %s with %s dictionary"
2054 (funcall ispell-format-word-function word)
2055 (file-name-nondirectory ispell-program-name)
2056 (or ispell-current-dictionary "default")))
2057 (ispell-check-only ; called from ispell minor mode.
2058 (if (fboundp 'make-extent)
2059 (if (fboundp 'set-extent-property)
2060 (let ((ext (make-extent start end)))
2061 (set-extent-property ext 'face ispell-highlight-face)
2062 (set-extent-property ext 'priority 2000)))
2063 (beep)
2064 (message "%s is incorrect"
2065 (funcall ispell-format-word-function word))))
2066 (t ; prompt for correct word.
2067 (save-window-excursion
2068 (setq replace (ispell-command-loop
2069 (car (cdr (cdr poss)))
2070 (car (cdr (cdr (cdr poss))))
2071 (car poss) start end)))
2072 (cond ((equal 0 replace)
2073 (ispell-add-per-file-word-list (car poss)))
2074 (replace
2075 (setq new-word (if (atom replace) replace (car replace))
2076 cursor-location (+ (- (length word) (- end start))
2077 cursor-location))
2078 (if (not (equal new-word (car poss)))
2079 (progn
2080 (goto-char start)
2081 ;; Insert first and then delete,
2082 ;; to avoid collapsing markers before and after
2083 ;; into a single place.
2084 (insert new-word)
2085 (delete-region (point) end)
2086 ;; It is meaningless to preserve the cursor position
2087 ;; inside a word that has changed.
2088 (setq cursor-location (point))
2089 (setq end (point))))
2090 (if (not (atom replace)) ;recheck spelling of replacement
2091 (progn
2092 (if (car (cdr replace)) ; query replace requested
2093 (save-window-excursion
2094 (query-replace word new-word t)))
2095 (goto-char start)
2096 ;; single word could be split into multiple words
2097 (setq ispell-quit (not (ispell-region start end)))
2098 ))))
2099 ;; keep if rechecking word and we keep choices win.
2100 (if (get-buffer ispell-choices-buffer)
2101 (kill-buffer ispell-choices-buffer))))
2102 (ispell-pdict-save ispell-silently-savep)
2103 ;; NB: Cancels ispell-quit incorrectly if called from ispell-region
2104 (if ispell-quit (setq ispell-quit nil replace 'quit))
2105 (goto-char cursor-location) ; return to original location
2106 replace))))
2109 (defun ispell-get-word (following &optional extra-otherchars)
2110 "Return the word for spell-checking according to ispell syntax.
2111 If optional argument FOLLOWING is non-nil or if `ispell-following-word'
2112 is non-nil when called interactively, then the following word
2113 \(rather than preceding\) is checked when the cursor is not over a word.
2114 Optional second argument contains otherchars that can be included in word
2115 many times (see the doc string of `ispell-dictionary-alist' for details
2116 about otherchars).
2118 Word syntax is controlled by the definition of the chosen dictionary,
2119 which is in `ispell-local-dictionary-alist' or `ispell-dictionary-alist'."
2120 (ispell-set-spellchecker-params) ; Initialize variables and dicts alists
2121 (let* ((ispell-casechars (ispell-get-casechars))
2122 (ispell-not-casechars (ispell-get-not-casechars))
2123 (ispell-otherchars (ispell-get-otherchars))
2124 (ispell-many-otherchars-p (ispell-get-many-otherchars-p))
2125 (word-regexp (concat ispell-casechars
2126 "+\\("
2127 (if (not (string= "" ispell-otherchars))
2128 (concat ispell-otherchars "?"))
2129 (if extra-otherchars
2130 (concat extra-otherchars "?"))
2131 ispell-casechars
2132 "+\\)"
2133 (if (or ispell-many-otherchars-p
2134 extra-otherchars)
2135 "*" "?")))
2136 did-it-once prevpt
2137 start end word)
2138 ;; find the word
2139 (if (not (looking-at ispell-casechars))
2140 (if following
2141 (re-search-forward ispell-casechars (point-max) t)
2142 (re-search-backward ispell-casechars (point-min) t)))
2143 ;; move to front of word
2144 (re-search-backward ispell-not-casechars (point-min) 'start)
2145 (while (and (or (and (not (string= "" ispell-otherchars))
2146 (looking-at ispell-otherchars))
2147 (and extra-otherchars (looking-at extra-otherchars)))
2148 (not (bobp))
2149 (or (not did-it-once)
2150 ispell-many-otherchars-p)
2151 (not (eq prevpt (point))))
2152 (if (and extra-otherchars (looking-at extra-otherchars))
2153 (progn
2154 (backward-char 1)
2155 (if (looking-at ispell-casechars)
2156 (re-search-backward ispell-not-casechars (point-min) 'move)))
2157 (setq did-it-once t
2158 prevpt (point))
2159 (backward-char 1)
2160 (if (looking-at ispell-casechars)
2161 (re-search-backward ispell-not-casechars (point-min) 'move)
2162 (backward-char -1))))
2163 ;; Now mark the word and save to string.
2164 (if (not (re-search-forward word-regexp (point-max) t))
2165 (if ispell-check-only
2166 ;; return dummy word when just flagging misspellings
2167 (list "" (point) (point))
2168 (error "No word found to check!"))
2169 (setq start (copy-marker (match-beginning 0))
2170 end (point-marker)
2171 word (buffer-substring-no-properties start end))
2172 (list word start end))))
2175 ;; Global ispell-pdict-modified-p is set by ispell-command-loop and
2176 ;; tracks changes in the dictionary. The global may either be
2177 ;; a value or a list, whose value is the state of whether the
2178 ;; dictionary needs to be saved.
2180 ;;;###autoload
2181 (defun ispell-pdict-save (&optional no-query force-save)
2182 "Check to see if the personal dictionary has been modified.
2183 If so, ask if it needs to be saved."
2184 (interactive (list ispell-silently-savep t))
2185 (if (and ispell-pdict-modified-p (listp ispell-pdict-modified-p))
2186 (setq ispell-pdict-modified-p (car ispell-pdict-modified-p)))
2187 (when (and (or ispell-pdict-modified-p force-save)
2188 (or no-query
2189 (y-or-n-p "Personal dictionary modified. Save? ")))
2190 (ispell-send-string "#\n") ; save dictionary
2191 (message "Personal dictionary saved.")
2192 (when flyspell-mode
2193 (flyspell-mode 0)
2194 (flyspell-mode 1)))
2195 ;; unassert variable, even if not saved to avoid questioning.
2196 (setq ispell-pdict-modified-p nil))
2199 (defun ispell-command-loop (miss guess word start end)
2200 "Display possible corrections from list MISS.
2201 GUESS lists possibly valid affix construction of WORD.
2202 Returns nil to keep word.
2203 Returns 0 to insert locally into buffer-local dictionary.
2204 Returns string for new chosen word.
2205 Returns list for new replacement word (will be rechecked).
2206 Query-replace when list length is 2.
2207 Automatic query-replace when second element is `query-replace'.
2208 Highlights the word, which is assumed to run from START to END.
2209 Global `ispell-pdict-modified-p' becomes a list where the only value
2210 indicates whether the dictionary has been modified when option `a'
2211 or `i' is used.
2212 Global `ispell-quit' set to start location to continue spell session."
2213 (let ((count ?0)
2214 (line ispell-choices-win-default-height)
2215 ;; ensure 4 context lines.
2216 (max-lines (- (ispell-adjusted-window-height) 4))
2217 (choices miss)
2218 (window-min-height (min window-min-height
2219 ispell-choices-win-default-height))
2220 (command-characters '( ? ?i ?a ?A ?r ?R ?? ?x ?X ?q ?l ?u ?m ))
2221 (dedicated (window-dedicated-p))
2222 (skipped 0)
2223 char num result textwin dedicated-win)
2225 ;; setup the *Choices* buffer with valid data.
2226 (with-current-buffer (get-buffer-create ispell-choices-buffer)
2227 (setq mode-line-format
2228 (concat
2229 "-- %b -- word: " word
2230 " -- dict: " (or ispell-current-dictionary "default")
2231 " -- prog: " (file-name-nondirectory ispell-program-name)))
2232 ;; XEmacs: no need for horizontal scrollbar in choices window
2233 (ispell-with-no-warnings
2234 (and (fboundp 'set-specifier)
2235 (boundp 'horizontal-scrollbar-visible-p)
2236 (set-specifier horizontal-scrollbar-visible-p nil
2237 (cons (current-buffer) nil))))
2238 (erase-buffer)
2239 (if guess
2240 (progn
2241 (insert "Affix rules generate and capitalize "
2242 "this word as shown below:\n\t")
2243 (while guess
2244 (if (> (+ 4 (current-column) (length (car guess)))
2245 (window-width))
2246 (progn
2247 (insert "\n\t")
2248 (setq line (1+ line))))
2249 (insert (car guess) " ")
2250 (setq guess (cdr guess)))
2251 (insert "\nUse option `i' to accept this spelling and put it in your private dictionary.\n")
2252 (setq line (+ line (if choices 3 2)))))
2253 (while (and choices
2254 (< (if (> (+ 7 (current-column) (length (car choices))
2255 (if (> count ?~) 3 0))
2256 (window-width))
2257 (progn
2258 (insert "\n")
2259 (setq line (1+ line)))
2260 line)
2261 max-lines))
2262 ;; not so good if there are over 20 or 30 options, but then, if
2263 ;; there are that many you don't want to scan them all anyway...
2264 (while (memq count command-characters) ; skip command characters.
2265 (setq count (ispell-int-char (1+ count))
2266 skipped (1+ skipped)))
2267 (insert "(" count ") " (car choices) " ")
2268 (setq choices (cdr choices)
2269 count (ispell-int-char (1+ count))))
2270 (setq count (ispell-int-char (- count ?0 skipped))))
2272 ;; ensure word is visible
2273 (if (not (pos-visible-in-window-p end))
2274 (sit-for 0))
2276 ;; allow temporary split of dedicated windows...
2277 (if dedicated
2278 (progn
2279 (setq dedicated-win (selected-window))
2280 (set-window-dedicated-p dedicated-win nil)))
2282 ;; Display choices for misspelled word.
2283 (ispell-show-choices line end)
2284 (select-window (setq textwin (next-window)))
2286 ;; highlight word, protecting current buffer status
2287 (unwind-protect
2288 (progn
2289 (and ispell-highlight-p
2290 (ispell-highlight-spelling-error start end t))
2291 ;; Loop until a valid choice is made.
2292 (while
2295 (setq
2296 result
2297 (progn
2298 (undo-boundary)
2299 (let (message-log-max)
2300 (message (concat "C-h or ? for more options; SPC to leave "
2301 "unchanged, Character to replace word")))
2302 (let ((inhibit-quit t)
2303 (input-valid t))
2304 (setq char nil skipped 0)
2305 ;; If the user types C-g, or generates some other
2306 ;; non-character event (such as a frame switch
2307 ;; event), stop ispell. As a special exception,
2308 ;; ignore mouse events occurring in the same frame.
2309 (while (and input-valid (not (characterp char)))
2310 (setq char (read-key))
2311 (setq input-valid
2312 (or (characterp char)
2313 (and (mouse-event-p char)
2314 (eq (selected-frame)
2315 (window-frame
2316 (posn-window (event-start char))))))))
2317 (when (or quit-flag (not input-valid) (= char ?\C-g))
2318 (setq char ?X quit-flag nil)))
2319 ;; Adjust num to array offset skipping command characters.
2320 (let ((com-chars command-characters))
2321 (while com-chars
2322 (if (and (> (car com-chars) ?0) (< (car com-chars) char))
2323 (setq skipped (1+ skipped)))
2324 (setq com-chars (cdr com-chars)))
2325 (setq num (- char ?0 skipped)))
2327 (cond
2328 ((= char ? ) nil) ; accept word this time only
2329 ((= char ?i) ; accept and insert word into pers dict
2330 (ispell-send-string (concat "*" word "\n"))
2331 (setq ispell-pdict-modified-p '(t)) ; dictionary modified!
2332 (and (fboundp 'flyspell-unhighlight-at)
2333 (flyspell-unhighlight-at start))
2334 nil)
2335 ((or (= char ?a) (= char ?A)) ; accept word without insert
2336 (ispell-send-string (concat "@" word "\n"))
2337 (add-to-list 'ispell-buffer-session-localwords word)
2338 (and (fboundp 'flyspell-unhighlight-at)
2339 (flyspell-unhighlight-at start))
2340 (or ispell-buffer-local-name ; session localwords might conflict
2341 (setq ispell-buffer-local-name (buffer-name)))
2342 (if (null ispell-pdict-modified-p)
2343 (setq ispell-pdict-modified-p
2344 (list ispell-pdict-modified-p)))
2345 (if (= char ?A) 0)) ; return 0 for ispell-add buffer-local
2346 ((or (= char ?r) (= char ?R)) ; type in replacement
2347 (and (eq 'block ispell-highlight-p) ; refresh tty's
2348 (ispell-highlight-spelling-error start end nil t))
2349 (let ((result
2350 (if (or (= char ?R) ispell-query-replace-choices)
2351 (list (read-string
2352 (format "Query-replacement for %s: "word)
2353 word)
2355 (cons (read-string "Replacement for: " word)
2356 nil))))
2357 (and (eq 'block ispell-highlight-p)
2358 (ispell-highlight-spelling-error start end nil
2359 'block))
2360 result))
2361 ((or (= char ??) (= char help-char) (= char ?\C-h))
2362 (and (eq 'block ispell-highlight-p)
2363 (ispell-highlight-spelling-error start end nil t))
2364 (ispell-help)
2365 (and (eq 'block ispell-highlight-p)
2366 (ispell-highlight-spelling-error start end nil
2367 'block))
2369 ;; Quit and move point back.
2370 ((= char ?x)
2371 (ispell-pdict-save ispell-silently-savep)
2372 (message "Exited spell-checking")
2373 (setq ispell-quit t)
2374 nil)
2375 ;; Quit and preserve point.
2376 ((= char ?X)
2377 (ispell-pdict-save ispell-silently-savep)
2378 (message "%s"
2379 (substitute-command-keys
2380 (concat "Spell-checking suspended;"
2381 " use C-u \\[ispell-word] to resume")))
2382 (setq ispell-quit start)
2383 nil)
2384 ((= char ?q)
2385 (if (y-or-n-p "Really kill Ispell process? ")
2386 (progn
2387 (ispell-kill-ispell t) ; terminate process.
2388 (setq ispell-quit (or (not ispell-checking-message)
2389 (point))
2390 ispell-pdict-modified-p nil))
2391 t)) ; continue if they don't quit.
2392 ((= char ?l)
2393 (and (eq 'block ispell-highlight-p) ; refresh tty displays
2394 (ispell-highlight-spelling-error start end nil t))
2395 (let ((new-word (read-string
2396 "Lookup string (`*' is wildcard): "
2397 word)))
2398 (if new-word
2399 (progn
2400 (with-current-buffer (get-buffer-create
2401 ispell-choices-buffer)
2402 (erase-buffer)
2403 (setq count ?0
2404 skipped 0
2405 mode-line-format ;; setup the *Choices* buffer with valid data.
2406 (concat "-- %b -- word: " new-word
2407 " -- word-list: "
2408 (or ispell-complete-word-dict
2409 ispell-alternate-dictionary))
2410 miss (ispell-lookup-words new-word)
2411 choices miss
2412 line ispell-choices-win-default-height)
2413 (while (and choices ; adjust choices window.
2414 (< (if (> (+ 7 (current-column)
2415 (length (car choices))
2416 (if (> count ?~) 3 0))
2417 (window-width))
2418 (progn
2419 (insert "\n")
2420 (setq line (1+ line)))
2421 line)
2422 max-lines))
2423 (while (memq count command-characters)
2424 (setq count (ispell-int-char (1+ count))
2425 skipped (1+ skipped)))
2426 (insert "(" count ") " (car choices) " ")
2427 (setq choices (cdr choices)
2428 count (ispell-int-char (1+ count))))
2429 (setq count (ispell-int-char
2430 (- count ?0 skipped))))
2431 (ispell-show-choices line end)
2432 (select-window (next-window)))))
2433 (and (eq 'block ispell-highlight-p)
2434 (ispell-highlight-spelling-error start end nil
2435 'block))
2436 t) ; reselect from new choices
2437 ((= char ?u) ; insert lowercase into dictionary
2438 (ispell-send-string (concat "*" (downcase word) "\n"))
2439 (setq ispell-pdict-modified-p '(t)) ; dictionary modified!
2440 nil)
2441 ((= char ?m) ; type in what to insert
2442 (ispell-send-string
2443 (concat "*" (read-string "Insert: " word) "\n"))
2444 (setq ispell-pdict-modified-p '(t))
2445 (cons word nil))
2446 ((and (>= num 0) (< num count))
2447 (if ispell-query-replace-choices ; Query replace flag
2448 (list (nth num miss) 'query-replace)
2449 (nth num miss)))
2450 ((= char ?\C-l)
2451 (redraw-display) t)
2452 ((= char ?\C-r)
2453 ;; This may have alignment errors if current line is edited
2454 (if (marker-position ispell-recursive-edit-marker)
2455 (progn
2456 (message "Only one recursive edit session supported")
2457 (beep)
2458 (sit-for 2))
2459 (set-marker ispell-recursive-edit-marker start)
2460 ;;(set-marker ispell-region-end reg-end)
2461 (and ispell-highlight-p ; unhighlight
2462 (ispell-highlight-spelling-error start end))
2463 (unwind-protect
2464 (progn
2465 (message
2466 "%s"
2467 (substitute-command-keys
2468 (concat "Exit recursive edit with"
2469 " \\[exit-recursive-edit]")))
2470 (save-window-excursion (save-excursion
2471 (recursive-edit))))
2472 ;; protected
2473 (goto-char ispell-recursive-edit-marker)
2474 (if (not (equal (marker-buffer
2475 ispell-recursive-edit-marker)
2476 (current-buffer)))
2477 (progn
2478 (set-marker ispell-recursive-edit-marker nil)
2479 (error
2480 "Cannot continue ispell from this buffer.")))
2481 (set-marker ispell-recursive-edit-marker nil)))
2482 (list word nil)) ; recheck starting at this word.
2483 ((= char ?\C-z)
2484 (funcall (key-binding "\C-z"))
2486 (t (ding) t))))))
2487 result)
2488 ;; protected
2489 (and ispell-highlight-p ; unhighlight
2490 (save-window-excursion
2491 (select-window textwin)
2492 (ispell-highlight-spelling-error start end)))
2493 (if dedicated
2494 (set-window-dedicated-p dedicated-win t)))))
2498 (defun ispell-show-choices (line end)
2499 "Show the choices in another buffer or frame."
2500 (if (and ispell-use-framepop-p (fboundp 'framepop-display-buffer))
2501 (progn
2502 (framepop-display-buffer (get-buffer ispell-choices-buffer))
2503 ;; (get-buffer-window ispell-choices-buffer t)
2504 (select-window (previous-window))) ; *Choices* window
2505 ;; standard selection by splitting a small buffer out of this window.
2506 (let ((choices-window (get-buffer-window ispell-choices-buffer)))
2507 (if choices-window
2508 (if (= line (ispell-adjusted-window-height choices-window))
2509 (select-window choices-window)
2510 ;; *Choices* window changed size. Adjust the choices window
2511 ;; without scrolling the spelled window when possible
2512 (let ((window-line
2513 (- line (ispell-adjusted-window-height choices-window)))
2514 (visible (progn (vertical-motion -1) (point))))
2515 (if (< line ispell-choices-win-default-height)
2516 (setq window-line (+ window-line
2517 (- ispell-choices-win-default-height
2518 line))))
2519 (move-to-window-line 0)
2520 (vertical-motion window-line)
2521 (set-window-start (selected-window)
2522 (if (> (point) visible) visible (point)))
2523 (goto-char end)
2524 (select-window choices-window)
2525 (enlarge-window window-line)))
2526 ;; Overlay *Choices* window when it isn't showing
2527 (ispell-overlay-window (max line ispell-choices-win-default-height)))
2528 (switch-to-buffer ispell-choices-buffer)
2529 (goto-char (point-min)))))
2532 ;;;###autoload
2533 (defun ispell-help ()
2534 "Display a list of the options available when a misspelling is encountered.
2536 Selections are:
2538 DIGIT: Replace the word with a digit offered in the *Choices* buffer.
2539 SPC: Accept word this time.
2540 `i': Accept word and insert into private dictionary.
2541 `a': Accept word for this session.
2542 `A': Accept word and place in `buffer-local dictionary'.
2543 `r': Replace word with typed-in value. Rechecked.
2544 `R': Replace word with typed-in value. Query-replaced in buffer. Rechecked.
2545 `?': Show these commands.
2546 `x': Exit spelling buffer. Move cursor to original point.
2547 `X': Exit spelling buffer. Leaves cursor at the current point, and permits
2548 the aborted check to be completed later.
2549 `q': Quit spelling session (Kills ispell process).
2550 `l': Look up typed-in replacement in alternate dictionary. Wildcards okay.
2551 `u': Like `i', but the word is lower-cased first.
2552 `m': Place typed-in value in personal dictionary, then recheck current word.
2553 `C-l': Redraw screen.
2554 `C-r': Recursive edit.
2555 `C-z': Suspend Emacs or iconify frame."
2557 (if (equal ispell-help-in-bufferp 'electric)
2558 (progn
2559 (require 'ehelp)
2560 (with-electric-help
2561 (function (lambda ()
2562 ;;This shouldn't be necessary: with-electric-help needs
2563 ;; an optional argument telling it about the smallest
2564 ;; acceptable window-height of the help buffer.
2565 ;;(if (< (window-height) 15)
2566 ;; (enlarge-window
2567 ;; (- 15 (ispell-adjusted-window-height))))
2568 (princ "Selections are:
2570 DIGIT: Replace the word with a digit offered in the *Choices* buffer.
2571 SPC: Accept word this time.
2572 `i': Accept word and insert into private dictionary.
2573 `a': Accept word for this session.
2574 `A': Accept word and place in `buffer-local dictionary'.
2575 `r': Replace word with typed-in value. Rechecked.
2576 `R': Replace word with typed-in value. Query-replaced in buffer. Rechecked.
2577 `?': Show these commands.
2578 `x': Exit spelling buffer. Move cursor to original point.
2579 `X': Exit spelling buffer. Leaves cursor at the current point, and permits
2580 the aborted check to be completed later.
2581 `q': Quit spelling session (Kills ispell process).
2582 `l': Look up typed-in replacement in alternate dictionary. Wildcards okay.
2583 `u': Like `i', but the word is lower-cased first.
2584 `m': Place typed-in value in personal dictionary, then recheck current word.
2585 `C-l': Redraw screen.
2586 `C-r': Recursive edit.
2587 `C-z': Suspend Emacs or iconify frame.")
2588 nil))))
2591 (let ((help-1 (concat "[r/R]eplace word; [a/A]ccept for this session; "
2592 "[i]nsert into private dictionary"))
2593 (help-2 (concat "[l]ook a word up in alternate dictionary; "
2594 "e[x/X]it; [q]uit session"))
2595 (help-3 (concat "[u]ncapitalized insert into dict. "
2596 "Type 'x C-h f ispell-help' for more help")))
2597 (save-window-excursion
2598 (if ispell-help-in-bufferp
2599 (progn
2600 (ispell-overlay-window 4)
2601 (switch-to-buffer (get-buffer-create "*Ispell Help*"))
2602 (insert (concat help-1 "\n" help-2 "\n" help-3))
2603 (sit-for 5)
2604 (kill-buffer "*Ispell Help*"))
2605 (unwind-protect
2606 (let ((resize-mini-windows 'grow-only))
2607 (select-window (minibuffer-window))
2608 (erase-buffer)
2609 (message nil)
2610 ;;(set-minibuffer-window (selected-window))
2611 (enlarge-window 2)
2612 (insert (concat help-1 "\n" help-2 "\n" help-3))
2613 (sit-for 5))
2614 (erase-buffer)))))))
2616 (define-obsolete-function-alias 'lookup-words 'ispell-lookup-words "24.4")
2618 (defun ispell-lookup-words (word &optional lookup-dict)
2619 "Look up WORD in optional word-list dictionary LOOKUP-DICT.
2620 A `*' serves as a wild card. If no wild cards, `look' is used if it exists.
2621 Otherwise the variable `ispell-grep-command' contains the command used to
2622 search for the words (usually egrep).
2624 Optional second argument contains the dictionary to use; the default is
2625 `ispell-alternate-dictionary', overridden by `ispell-complete-word-dict'
2626 if defined."
2627 ;; We don't use the filter for this function, rather the result is written
2628 ;; into a buffer. Hence there is no need to save the filter values.
2629 (if (null lookup-dict)
2630 (setq lookup-dict (or ispell-complete-word-dict
2631 ispell-alternate-dictionary)))
2633 (if lookup-dict
2634 (unless (file-readable-p lookup-dict)
2635 (error "lookup-words error: Unreadable or missing plain word-list %s."
2636 lookup-dict))
2637 (error (concat "lookup-words error: No plain word-list found at system"
2638 "default locations. "
2639 "Customize `ispell-alternate-dictionary' to set yours.")))
2641 (let* ((process-connection-type ispell-use-ptys-p)
2642 (wild-p (string-match "\\*" word))
2643 (look-p (and ispell-look-p ; Only use look for an exact match.
2644 (or ispell-have-new-look (not wild-p))))
2645 (prog (if look-p ispell-look-command ispell-grep-command))
2646 (args (if look-p ispell-look-options ispell-grep-options))
2647 status results loc)
2648 (with-temp-buffer
2649 (message "Starting \"%s\" process..." (file-name-nondirectory prog))
2650 (if look-p
2652 (insert "^" word)
2653 ;; When there are no wildcards, append one, for consistency
2654 ;; with `look' behavior.
2655 (unless wild-p (insert "*"))
2656 (insert "$")
2657 ;; Convert * to .*
2658 (while (search-backward "*" nil t) (insert "."))
2659 (setq word (buffer-string))
2660 (erase-buffer))
2661 (setq status (apply 'ispell-call-process prog nil t nil
2662 (nconc (if (and args (> (length args) 0))
2663 (list args)
2664 (if look-p nil
2665 (list "-e")))
2666 (list word)
2667 (if lookup-dict (list lookup-dict)))))
2668 ;; `grep' returns status 1 and no output when word not found, which
2669 ;; is a perfectly normal thing.
2670 (if (stringp status)
2671 (error "error: %s exited with signal %s"
2672 (file-name-nondirectory prog) status)
2673 ;; Else collect words into `results' in FIFO order.
2674 (goto-char (point-max))
2675 ;; Assure we've ended with \n.
2676 (or (bobp) (= (preceding-char) ?\n) (insert ?\n))
2677 (while (not (bobp))
2678 (setq loc (point))
2679 (forward-line -1)
2680 (push (buffer-substring-no-properties (point)
2681 (1- loc))
2682 results))))
2683 (if (and results (string-match ".+: " (car results)))
2684 (error "%s error: %s" ispell-grep-command (car results)))
2685 results))
2688 ;; "ispell-filter" is a list of output lines from the generating function.
2689 ;; Each full line (ending with \n) is a separate item on the list.
2690 ;; "output" can contain multiple lines, part of a line, or both.
2691 ;; "start" and "end" are used to keep bounds on lines when "output" contains
2692 ;; multiple lines.
2693 ;; "ispell-filter-continue" is true when we have received only part of a
2694 ;; line as output from a generating function ("output" did not end with \n)
2695 ;; THIS FUNCTION WILL FAIL IF THE PROCESS OUTPUT DOESN'T END WITH \n!
2696 ;; This is the case when a process dies or fails. The default behavior
2697 ;; in this case treats the next input received as fresh input.
2699 (defun ispell-filter (process output)
2700 "Output filter function for ispell, grep, and look."
2701 (let ((start 0)
2702 (continue t)
2703 end)
2704 (while continue
2705 (setq end (string-match "\n" output start)) ; get text up to the newline.
2706 ;; If we get out of sync and ispell-filter-continue is asserted when we
2707 ;; are not continuing, treat the next item as a separate list. When
2708 ;; ispell-filter-continue is asserted, ispell-filter *should* always be a
2709 ;; list!
2711 ;; Continue with same line (item)?
2712 (if (and ispell-filter-continue ispell-filter (listp ispell-filter))
2713 ;; Yes. Add it to the prev item
2714 (setcar ispell-filter
2715 (concat (car ispell-filter) (substring output start end)))
2716 ;; No. This is a new line and item.
2717 (setq ispell-filter
2718 (cons (substring output start end) ispell-filter)))
2719 (if (null end)
2720 ;; We've completed reading the output, but didn't finish the line.
2721 (setq ispell-filter-continue t continue nil)
2722 ;; skip over newline, this line complete.
2723 (setq ispell-filter-continue nil end (1+ end))
2724 (if (= end (length output)) ; No more lines in output
2725 (setq continue nil) ; so we can exit the filter.
2726 (setq start end)))))) ; else move start to next line of input
2729 ;; This function destroys the mark location if it is in the word being
2730 ;; highlighted.
2731 (defun ispell-highlight-spelling-error-generic (start end &optional highlight
2732 refresh)
2733 "Highlight the word from START to END with a kludge using `inverse-video'.
2734 When the optional third arg HIGHLIGHT is set, the word is highlighted;
2735 otherwise it is displayed normally.
2736 Uses block cursor to highlight one character.
2737 Optional REFRESH will unhighlighted then highlight, using block cursor
2738 highlighting when REFRESH is equal to `block'."
2739 (and (eq 'block ispell-highlight-p)
2740 (or (eq 'block refresh)
2741 (setq start (1+ start)))) ; On block non-refresh, inc start.
2742 (let ((modified (buffer-modified-p)) ; don't allow this fn to modify buffer
2743 (buffer-read-only nil) ; Allow highlighting read-only buffers.
2744 (text (buffer-substring-no-properties start end))
2745 ; Save highlight region.
2746 (inhibit-quit t) ; inhibit interrupt processing here.
2747 (buffer-undo-list t)) ; don't clutter the undo list.
2748 (goto-char end)
2749 (delete-region start end)
2750 (insert-char ? (- end start)) ; minimize amount of redisplay
2751 (sit-for 0) ; update display
2752 (if highlight (setq inverse-video (not inverse-video))) ; toggle video
2753 (delete-region start end) ; delete whitespace
2754 (insert text) ; insert text in inverse video.
2755 (sit-for 0) ; update display showing inverse video.
2756 (if (not highlight)
2757 (goto-char end)
2758 (setq inverse-video (not inverse-video)) ; toggle video
2759 (and (eq 'block ispell-highlight-p)
2760 (goto-char (1- start)))) ; use block cursor to "highlight" char
2761 (set-buffer-modified-p modified) ; don't modify if flag not set.
2762 (and refresh ; re-highlight
2763 (ispell-highlight-spelling-error-generic
2764 (if (eq 'block refresh) start (- start 2)) end t))))
2767 (defun ispell-highlight-spelling-error-xemacs (start end &optional highlight)
2768 "Highlight the word from START to END using `isearch-highlight'.
2769 When the optional third arg HIGHLIGHT is set, the word is highlighted,
2770 otherwise it is displayed normally."
2771 (if highlight
2772 (isearch-highlight start end)
2773 (isearch-dehighlight))
2774 ;;(sit-for 0)
2778 (defun ispell-highlight-spelling-error-overlay (start end &optional highlight)
2779 "Highlight the word from START to END using overlays.
2780 When the optional third arg HIGHLIGHT is set, the word is highlighted
2781 otherwise it is displayed normally.
2783 The variable `ispell-highlight-face' selects the face to use for highlighting."
2784 (if highlight
2785 (if ispell-overlay
2786 (move-overlay ispell-overlay start end (current-buffer))
2787 (setq ispell-overlay (make-overlay start end))
2788 (overlay-put ispell-overlay 'priority 1001) ;higher than lazy overlays
2789 (overlay-put ispell-overlay 'face ispell-highlight-face))
2790 (if ispell-overlay
2791 (delete-overlay ispell-overlay)))
2792 (if (and ispell-lazy-highlight (boundp 'lazy-highlight-cleanup))
2793 (if highlight
2794 (let ((isearch-string
2795 (concat
2796 "\\b"
2797 (regexp-quote (buffer-substring-no-properties start end))
2798 "\\b"))
2799 (isearch-regexp t)
2800 (isearch-case-fold-search nil)
2801 (isearch-forward t)
2802 (isearch-other-end start)
2803 (isearch-error nil))
2804 (isearch-lazy-highlight-new-loop
2805 (if (boundp 'reg-start) reg-start)
2806 (if (boundp 'reg-end) reg-end)))
2807 (lazy-highlight-cleanup lazy-highlight-cleanup)
2808 (setq isearch-lazy-highlight-last-string nil))))
2811 (defun ispell-highlight-spelling-error (start end &optional highlight refresh)
2812 (cond
2813 ((featurep 'xemacs)
2814 (ispell-highlight-spelling-error-xemacs start end highlight))
2815 ((and (featurep 'faces)
2816 (or (and (fboundp 'display-color-p) (display-color-p))
2817 window-system))
2818 (ispell-highlight-spelling-error-overlay start end highlight))
2819 (t (ispell-highlight-spelling-error-generic start end highlight refresh))))
2821 (defun ispell-adjusted-window-height (&optional window)
2822 "Like `window-height', adjusted to correct for the effect of tall mode-lines.
2823 The value returned is actually the nominal number of text-lines in the
2824 window plus 1. On a terminal, this is the same value returned by
2825 `window-height', but if the window has a mode-line is taller than a normal
2826 text line, the returned value may be smaller than that from
2827 `window-height'."
2828 (cond ((fboundp 'window-text-height)
2829 (1+ (window-text-height window)))
2830 ((or (and (fboundp 'display-graphic-p) (display-graphic-p))
2831 (and (featurep 'xemacs) window-system))
2832 (1- (window-height window)))
2834 (window-height window))))
2836 (defun ispell-overlay-window (height)
2837 "Create a window covering the top HEIGHT lines of the current window.
2838 Ensure that the line above point is still visible but otherwise avoid
2839 scrolling the current window. Leave the new window selected."
2840 (save-excursion
2841 (let ((oldot (save-excursion (vertical-motion -1) (point)))
2842 (top (save-excursion (move-to-window-line height) (point))))
2843 ;; If line above old point (line starting at oldot) would be
2844 ;; hidden by new window, scroll it to just below new win
2845 ;; otherwise set top line of other win so it doesn't scroll.
2846 (if (< oldot top) (setq top oldot))
2847 ;; if frame is unsplittable, temporarily disable that...
2848 (if (cdr (assq 'unsplittable (frame-parameters (selected-frame))))
2849 (let ((frame (selected-frame)))
2850 (modify-frame-parameters frame '((unsplittable . nil)))
2851 (split-window nil height)
2852 (modify-frame-parameters frame '((unsplittable . t))))
2853 (split-window nil height))
2854 (let ((deficit (- height (ispell-adjusted-window-height))))
2855 (when (> deficit 0)
2856 ;; Number of lines the window is still too short. We ensure that
2857 ;; there are at least (1- HEIGHT) lines visible in the window.
2858 (enlarge-window deficit)
2859 (goto-char top)
2860 (vertical-motion deficit)
2861 (setq top (min (point) oldot))))
2862 (set-window-start (next-window) top))))
2865 ;; Should we add a compound word match return value?
2866 (defun ispell-parse-output (output &optional accept-list shift)
2867 "Parse the OUTPUT string from Ispell process and return:
2868 1: t for an exact match.
2869 2: A string containing the root word matched via suffix removal.
2870 3: A list of possible correct spellings of the format:
2871 (\"ORIGINAL-WORD\" OFFSET MISS-LIST GUESS-LIST)
2872 ORIGINAL-WORD is a string of the possibly misspelled word.
2873 OFFSET is an integer giving the line offset of the word.
2874 MISS-LIST and GUESS-LIST are possibly null lists of guesses and misses.
2875 4: nil when an error has occurred.
2877 Optional second arg ACCEPT-LIST is list of words already accepted.
2878 Optional third arg SHIFT is an offset to apply based on previous corrections."
2879 (cond
2880 ((string= output "") t) ; for startup with pipes...
2881 ((string= output "*") t) ; exact match
2882 ((string= output "-") t) ; compound word match
2883 ((eq (aref output 0) ?+) ; found because of root word
2884 (substring output 2)) ; return root word
2885 ((equal 0 (string-match "[\ra-zA-Z]" output))
2886 (ding) ; error message from ispell!
2887 (message "Ispell error: %s" output)
2888 (sit-for 5)
2889 nil)
2890 (t ; need to process &, ?, and #'s
2891 (let ((type (aref output 0)) ; &, ?, or #
2892 (original-word (substring output 2 (string-match " " output 2)))
2893 (cur-count 0) ; contains number of misses + guesses
2894 count miss-list guess-list offset)
2895 (setq output (substring output (match-end 0))) ; skip over misspelling
2896 (if (eq type ?#)
2897 (setq count 0) ; no misses for type #
2898 (setq count (string-to-number output) ; get number of misses.
2899 output (substring output (1+ (string-match " " output 1)))))
2900 (setq offset (string-to-number output))
2901 (setq output (if (eq type ?#) ; No miss or guess list.
2903 (substring output (1+ (string-match " " output 1)))))
2904 (while output
2905 (let ((end (string-match ", \\|\\($\\)" output))) ; end of miss/guess.
2906 (setq cur-count (1+ cur-count))
2907 (if (> cur-count count)
2908 (push (substring output 0 end) guess-list)
2909 (push (substring output 0 end) miss-list))
2910 (setq output (if (match-end 1) ; True only when at end of line.
2911 nil ; No more misses or guesses.
2912 (substring output (+ end 2))))))
2913 ;; return results. Accept word if it was already accepted.
2914 ;; adjust offset.
2915 (if (member original-word accept-list)
2917 (list original-word
2918 (if (numberp shift) (+ shift offset) offset)
2919 (nreverse miss-list) (nreverse guess-list)))))))
2922 (defun ispell-process-status ()
2923 "Return the status of the Ispell process.
2924 When asynchronous processes are not supported, `run' is always returned."
2925 (if ispell-async-processp
2926 (process-status ispell-process)
2927 (and ispell-process 'run)))
2930 (defun ispell-start-process ()
2931 "Start the Ispell process, with support for no asynchronous processes.
2932 Keeps argument list for future Ispell invocations for no async support."
2933 ;; `ispell-current-dictionary' and `ispell-current-personal-dictionary'
2934 ;; are properly set in `ispell-internal-change-dictionary'.
2936 ;; Parse hunspell affix file if using hunspell and entry is uninitialized.
2937 (if ispell-really-hunspell
2938 (or (cadr (assoc ispell-current-dictionary ispell-dictionary-alist))
2939 (ispell-hunspell-fill-dictionary-entry ispell-current-dictionary)))
2941 (let* ((default-directory
2942 (if (and (file-directory-p default-directory)
2943 (file-readable-p default-directory))
2944 default-directory
2945 ;; Defend against bad `default-directory'.
2946 (expand-file-name "~/")))
2947 (orig-args (ispell-get-ispell-args))
2948 (args
2949 (append
2950 (if (and ispell-current-dictionary ; Not for default dict (nil)
2951 (not (member "-d" orig-args))) ; Only define if not overridden.
2952 (list "-d" ispell-current-dictionary))
2953 orig-args
2954 (if ispell-current-personal-dictionary ; Use specified pers dict.
2955 (list "-p" ispell-current-personal-dictionary))
2956 ;; If we are using recent aspell or hunspell, make sure we use the
2957 ;; right encoding for communication. ispell or older aspell/hunspell
2958 ;; does not support this.
2959 (if ispell-encoding8-command
2960 (if ispell-really-hunspell
2961 (list ispell-encoding8-command
2962 (upcase (symbol-name (ispell-get-coding-system))))
2963 (list
2964 (concat ispell-encoding8-command
2965 (symbol-name (ispell-get-coding-system))))))
2966 ispell-extra-args)))
2968 ;; Initially we don't know any buffer's local words.
2969 (setq ispell-buffer-local-name nil)
2971 (if ispell-async-processp
2972 (let ((process-connection-type ispell-use-ptys-p))
2973 (apply 'start-process
2974 "ispell" nil ispell-program-name
2975 "-a" ; Accept single input lines.
2976 ;; Make root/affix combos not in dict.
2977 ;; hunspell -m option means different.
2978 (if ispell-really-hunspell "" "-m")
2979 args))
2980 (setq ispell-cmd-args args
2981 ispell-output-buffer (generate-new-buffer " *ispell-output*")
2982 ispell-session-buffer (generate-new-buffer " *ispell-session*"))
2983 (ispell-send-string "\032\n") ; so Ispell prints version and exits
2984 t)))
2987 (defun ispell-init-process ()
2988 "Check status of Ispell process and start if necessary."
2989 (let* (;; Basename of dictionary used by the spell-checker
2990 (dict-bname (or (car (cdr (member "-d" (ispell-get-ispell-args))))
2991 ispell-current-dictionary))
2992 ;; The directory where process was started.
2993 (current-ispell-directory default-directory)
2994 ;; The default directory for the process.
2995 ;; Use "~/" as default-directory unless using Ispell with per-dir
2996 ;; personal dictionaries and not in a minibuffer under XEmacs
2997 (default-directory
2998 (if (or ispell-really-aspell
2999 ispell-really-hunspell
3000 ;; Protect against bad default-directory
3001 (not (and (file-directory-p default-directory)
3002 (file-readable-p default-directory)))
3003 ;; Ispell and per-dir personal dicts available
3004 (not (or (file-readable-p (concat default-directory
3005 ".ispell_words"))
3006 (file-readable-p (concat default-directory
3007 ".ispell_"
3008 (or dict-bname
3009 "default")))))
3010 ;; Ispell, in a minibuffer, and XEmacs
3011 (and (window-minibuffer-p)
3012 (not (fboundp 'minibuffer-selected-window))))
3013 (expand-file-name "~/")
3014 (expand-file-name default-directory))))
3015 ;; Check if process needs restart
3016 (if (and ispell-process
3017 (eq (ispell-process-status) 'run)
3018 ;; Unless we are using an explicit personal dictionary, ensure
3019 ;; we're in the same default directory! Restart check for
3020 ;; personal dictionary is done in
3021 ;; `ispell-internal-change-dictionary', called from
3022 ;; `ispell-buffer-local-dict'
3023 (or (or ispell-local-pdict ispell-personal-dictionary)
3024 (equal ispell-process-directory default-directory)))
3025 (setq ispell-filter nil ispell-filter-continue nil)
3026 ;; may need to restart to select new personal dictionary.
3027 (ispell-kill-ispell t)
3028 (message "Starting new Ispell process %s with %s dictionary..."
3029 ispell-program-name
3030 (or ispell-local-dictionary ispell-dictionary "default"))
3031 (sit-for 0)
3032 (setq ispell-library-directory (ispell-check-version)
3033 ispell-process (ispell-start-process)
3034 ispell-filter nil
3035 ispell-filter-continue nil
3036 ispell-process-directory default-directory)
3038 (unless (equal ispell-process-directory (expand-file-name "~/"))
3039 ;; At this point, `ispell-process-directory' will be "~/" unless using
3040 ;; Ispell with directory-specific dicts and not in XEmacs minibuffer.
3041 ;; If not, kill ispell process when killing buffer. It may be in a
3042 ;; removable device that would otherwise become un-mountable.
3043 (with-current-buffer
3044 (if (and (window-minibuffer-p) ;; In minibuffer
3045 (fboundp 'minibuffer-selected-window)) ;; Not XEmacs.
3046 ;; In this case kill ispell only when parent buffer is killed
3047 ;; to avoid over and over ispell kill.
3048 (window-buffer (minibuffer-selected-window))
3049 (current-buffer))
3050 ;; 'local does not automatically make hook buffer-local in XEmacs.
3051 (if (featurep 'xemacs)
3052 (make-local-hook 'kill-buffer-hook))
3053 (add-hook 'kill-buffer-hook
3054 (lambda () (ispell-kill-ispell t)) nil 'local)))
3056 (if ispell-async-processp
3057 (set-process-filter ispell-process 'ispell-filter))
3058 ;; Protect against XEmacs bogus binding of `enable-multibyte-characters'.
3059 (if (and (or (featurep 'xemacs)
3060 (and (boundp 'enable-multibyte-characters)
3061 enable-multibyte-characters))
3062 (fboundp 'set-process-coding-system))
3063 (set-process-coding-system ispell-process (ispell-get-coding-system)
3064 (ispell-get-coding-system)))
3065 ;; Get version ID line
3066 (ispell-accept-output 3)
3067 ;; get more output if filter empty?
3068 (if (null ispell-filter) (ispell-accept-output 3))
3069 (cond ((null ispell-filter)
3070 (error "%s did not output version line" ispell-program-name))
3071 ((and
3072 (stringp (car ispell-filter))
3073 (if (string-match "warning: " (car ispell-filter))
3074 (progn
3075 (ispell-accept-output 3) ; was warn msg.
3076 (stringp (car ispell-filter)))
3077 (null (cdr ispell-filter)))
3078 (string-match "^@(#) " (car ispell-filter)))
3079 ;; got the version line as expected (we already know it's the right
3080 ;; version, so don't bother checking again.)
3081 nil)
3083 ;; Otherwise, it must be an error message. Show the user.
3084 ;; But first wait to see if some more output is going to arrive.
3085 ;; Otherwise we get cool errors like "Can't open ".
3086 (sleep-for 1)
3087 (ispell-accept-output 3)
3088 (error "%s" (mapconcat 'identity ispell-filter "\n"))))
3089 (setq ispell-filter nil) ; Discard version ID line
3090 (let ((extended-char-mode (ispell-get-extended-character-mode)))
3091 (if extended-char-mode ; ~ extended character mode
3092 (ispell-send-string (concat extended-char-mode "\n"))))
3093 (if ispell-async-processp
3094 (if (featurep 'emacs)
3095 (set-process-query-on-exit-flag ispell-process nil)
3096 (if (fboundp 'set-process-query-on-exit-flag)
3097 (set-process-query-on-exit-flag ispell-process nil)
3098 (process-kill-without-query ispell-process)))))))
3100 ;;;###autoload
3101 (defun ispell-kill-ispell (&optional no-error clear)
3102 "Kill current Ispell process (so that you may start a fresh one).
3103 With NO-ERROR, just return non-nil if there was no Ispell running.
3104 With CLEAR, buffer session localwords are cleaned."
3105 (interactive)
3106 ;; This hook is typically used by flyspell to flush some variables used
3107 ;; to optimize the common cases.
3108 (run-hooks 'ispell-kill-ispell-hook)
3109 (if (or clear
3110 (if (featurep 'xemacs)
3111 (interactive-p)
3112 (called-interactively-p 'interactive)))
3113 (setq ispell-buffer-session-localwords nil))
3114 (if (not (and ispell-process
3115 (eq (ispell-process-status) 'run)))
3116 (or no-error
3117 (error "There is no Ispell process running!"))
3118 (if ispell-async-processp
3119 (delete-process ispell-process)
3120 ;; Synchronous processes.
3121 (ispell-send-string "\n") ; Make sure side effects occurred.
3122 (kill-buffer ispell-output-buffer)
3123 (kill-buffer ispell-session-buffer)
3124 (setq ispell-output-buffer nil
3125 ispell-session-buffer nil))
3126 (setq ispell-process nil)
3127 (message "Ispell process killed")
3128 nil))
3130 ;; ispell-change-dictionary is set in some people's hooks. Maybe this should
3131 ;; call ispell-init-process rather than wait for a spell checking command?
3133 ;;;###autoload
3134 (defun ispell-change-dictionary (dict &optional arg)
3135 "Change to dictionary DICT for Ispell.
3136 With a prefix arg, set it \"globally\", for all buffers.
3137 Without a prefix arg, set it \"locally\", just for this buffer.
3139 By just answering RET you can find out what the current dictionary is."
3140 (interactive
3141 (list (completing-read
3142 "Use new dictionary (RET for current, SPC to complete): "
3143 (and (fboundp 'ispell-valid-dictionary-list)
3144 (mapcar 'list (ispell-valid-dictionary-list)))
3145 nil t)
3146 current-prefix-arg))
3147 (ispell-set-spellchecker-params) ; Initialize variables and dicts alists
3148 (unless arg (ispell-buffer-local-dict 'no-reload))
3149 (if (equal dict "default") (setq dict nil))
3150 ;; This relies on completing-read's bug of returning "" for no match
3151 (cond ((equal dict "")
3152 (ispell-internal-change-dictionary)
3153 (message "Using %s dictionary"
3154 (or (and (not arg) ispell-local-dictionary)
3155 ispell-dictionary "default")))
3156 ((equal dict (or (and (not arg) ispell-local-dictionary)
3157 ispell-dictionary "default"))
3158 ;; Specified dictionary is the default already. Could reload
3159 ;; the dictionaries if needed.
3160 (ispell-internal-change-dictionary)
3161 (and (if (featurep 'xemacs)
3162 (interactive-p)
3163 (called-interactively-p 'interactive))
3164 (message "No change, using %s dictionary" dict)))
3165 (t ; reset dictionary!
3166 (if (or (assoc dict ispell-local-dictionary-alist)
3167 (assoc dict ispell-dictionary-alist))
3168 (if arg
3169 ;; set default dictionary
3170 (setq ispell-dictionary dict)
3171 ;; set local dictionary
3172 (setq ispell-local-dictionary dict)
3173 (setq ispell-local-dictionary-overridden t))
3174 (error "Undefined dictionary: %s" dict))
3175 (ispell-internal-change-dictionary)
3176 (setq ispell-buffer-session-localwords nil)
3177 (message "%s Ispell dictionary set to %s"
3178 (if arg "Global" "Local")
3179 dict))))
3181 (defun ispell-internal-change-dictionary ()
3182 "Update the dictionary and the personal dictionary used by Ispell.
3183 This may kill the Ispell process; if so, a new one will be started
3184 when needed."
3185 (let* ((dict (or ispell-local-dictionary ispell-dictionary))
3186 (pdict (or ispell-local-pdict ispell-personal-dictionary))
3187 (expanded-pdict (if pdict (expand-file-name pdict))))
3188 (unless (and (equal ispell-current-dictionary dict)
3189 (equal ispell-current-personal-dictionary
3190 expanded-pdict))
3191 (ispell-kill-ispell t)
3192 (setq ispell-current-dictionary dict
3193 ispell-current-personal-dictionary expanded-pdict))))
3195 ;; Avoid error messages when compiling for these dynamic variables.
3196 (defvar ispell-start)
3197 (defvar ispell-end)
3199 ;; Spelling of comments are checked when ispell-check-comments is non-nil.
3201 ;;;###autoload
3202 (defun ispell-region (reg-start reg-end &optional recheckp shift)
3203 "Interactively check a region for spelling errors.
3204 Return nil if spell session was terminated, otherwise returns shift offset
3205 amount for last line processed."
3206 (interactive "r") ; Don't flag errors on read-only bufs.
3207 (ispell-set-spellchecker-params) ; Initialize variables and dicts alists
3208 (if (not recheckp)
3209 (ispell-accept-buffer-local-defs)) ; set up dictionary, local words, etc.
3210 (let ((skip-region-start (make-marker))
3211 (rstart (make-marker))
3212 (region-type (if (and (= reg-start (point-min)) (= reg-end (point-max)))
3213 (buffer-name) "region"))
3214 (program-basename (file-name-nondirectory ispell-program-name))
3215 (dictionary (or ispell-current-dictionary "default")))
3216 (unwind-protect
3217 (save-excursion
3218 (message "Spell-checking %s using %s with %s dictionary..."
3219 region-type program-basename dictionary)
3220 ;; Returns cursor to original location.
3221 (save-window-excursion
3222 (goto-char reg-start)
3223 (let ((transient-mark-mode)
3224 (case-fold-search case-fold-search)
3225 (query-fcc t)
3226 in-comment key)
3227 (ispell-print-if-debug
3228 "ispell-region: (ispell-skip-region-list):\n%s
3229 ispell-region: (ispell-begin-skip-region-regexp):\n%s
3230 ispell-region: Search for first region to skip after (ispell-begin-skip-region-regexp)\n"
3231 (ispell-skip-region-list)
3232 (ispell-begin-skip-region-regexp))
3233 (if (re-search-forward (ispell-begin-skip-region-regexp) reg-end t)
3234 (progn
3235 (setq key (match-string-no-properties 0))
3236 (set-marker skip-region-start (- (point) (length key)))
3237 (goto-char reg-start)
3238 (ispell-print-if-debug
3239 "ispell-region: First skip: %s at (pos,line,column): (%s,%s,%s).\n"
3241 (save-excursion (goto-char skip-region-start) (point))
3242 (line-number-at-pos skip-region-start)
3243 (save-excursion (goto-char skip-region-start) (current-column)))))
3244 (ispell-print-if-debug
3245 "ispell-region: Continue spell-checking with %s and %s dictionary...\n"
3246 program-basename dictionary)
3247 (set-marker rstart reg-start)
3248 (set-marker ispell-region-end reg-end)
3249 (while (and (not ispell-quit)
3250 (< (point) ispell-region-end))
3251 ;; spell-check region with skipping
3252 (if (and (marker-position skip-region-start)
3253 (<= skip-region-start (point)))
3254 (progn
3255 ;; If region inside line comment, must keep comment start.
3256 (setq in-comment (point)
3257 in-comment
3258 (and comment-start
3259 (or (null comment-end) (string= "" comment-end))
3260 (save-excursion
3261 (beginning-of-line)
3262 (re-search-forward comment-start in-comment t))
3263 comment-start))
3264 ;; Can change skip-regexps (in ispell-message)
3265 (ispell-skip-region key) ; moves pt past region.
3266 (set-marker rstart (point))
3267 ;; check for saving large attachments...
3268 (setq query-fcc (and query-fcc
3269 (ispell-ignore-fcc skip-region-start
3270 rstart)))
3271 (if (and (< rstart ispell-region-end)
3272 (re-search-forward
3273 (ispell-begin-skip-region-regexp)
3274 ispell-region-end t))
3275 (progn
3276 (setq key (match-string-no-properties 0))
3277 (set-marker skip-region-start
3278 (- (point) (length key)))
3279 (goto-char rstart)
3280 (ispell-print-if-debug
3281 "ispell-region: Next skip: %s at (pos,line,column): (%s,%s,%s).\n"
3283 (save-excursion (goto-char skip-region-start) (point))
3284 (line-number-at-pos skip-region-start)
3285 (save-excursion (goto-char skip-region-start) (current-column))))
3286 (set-marker skip-region-start nil))))
3287 (setq reg-end (max (point)
3288 (if (marker-position skip-region-start)
3289 (min skip-region-start ispell-region-end)
3290 (marker-position ispell-region-end))))
3291 (let* ((ispell-start (point))
3292 (ispell-end (min (point-at-eol) reg-end))
3293 ;; See if line must be prefixed by comment string to let ispell know this is
3294 ;; part of a comment string. This is only supported in some modes.
3295 ;; In particular, this is not supported in autoconf mode where adding the
3296 ;; comment string messes everything up because ispell tries to spellcheck the
3297 ;; `dnl' string header causing misalignments in some cases (debbugs.gnu.org: #12768).
3298 (add-comment (and in-comment
3299 (not (string= in-comment "dnl "))
3300 in-comment))
3301 (string (ispell-get-line
3302 ispell-start ispell-end add-comment)))
3303 (ispell-print-if-debug
3304 "ispell-region: string pos (%s->%s), eol: %s, [in-comment]: [%s], [add-comment]: [%s], [string]: [%s]\n"
3305 ispell-start ispell-end (point-at-eol) in-comment add-comment string)
3306 (if add-comment ; account for comment chars added
3307 (setq ispell-start (- ispell-start (length add-comment))
3308 ;; Reset `in-comment' (and indirectly `add-comment') for new line
3309 in-comment nil))
3310 (setq ispell-end (point)) ; "end" tracks region retrieved.
3311 (if string ; there is something to spell check!
3312 ;; (special start end)
3313 (setq shift (ispell-process-line string
3314 (and recheckp shift))))
3315 (goto-char ispell-end)))))
3316 (if ispell-quit
3318 (or shift 0)))
3319 ;; protected
3320 (if (and (not (and recheckp ispell-keep-choices-win))
3321 (get-buffer ispell-choices-buffer))
3322 (kill-buffer ispell-choices-buffer))
3323 (set-marker skip-region-start nil)
3324 (set-marker rstart nil)
3325 (if ispell-quit
3326 (progn
3327 ;; preserve or clear the region for ispell-continue.
3328 (if (not (numberp ispell-quit))
3329 (set-marker ispell-region-end nil)
3330 ;; Ispell-continue enabled - ispell-region-end is set.
3331 (goto-char ispell-quit))
3332 ;; Check for aborting
3333 (if (and ispell-checking-message (numberp ispell-quit))
3334 (progn
3335 (setq ispell-quit nil)
3336 (error "Message send aborted")))
3337 (if (not recheckp) (setq ispell-quit nil)))
3338 (if (not recheckp) (set-marker ispell-region-end nil))
3339 ;; Only save if successful exit.
3340 (ispell-pdict-save ispell-silently-savep)
3341 (message "Spell-checking %s using %s with %s dictionary...done"
3342 region-type program-basename dictionary)))))
3345 (defun ispell-begin-skip-region-regexp ()
3346 "Return a regexp of the search keys for region skipping.
3347 Includes `ispell-skip-region-alist' plus tex, tib, html, and comment keys.
3348 Must be called after `ispell-buffer-local-parsing' due to dependence on mode."
3349 (mapconcat
3350 'identity
3351 (delq nil
3352 (list
3353 ;; messages
3354 (if (and ispell-checking-message
3355 (not (eq t ispell-checking-message)))
3356 (mapconcat #'car ispell-checking-message "\\|"))
3357 ;; tex
3358 (if (eq ispell-parser 'tex)
3359 (ispell-begin-tex-skip-regexp))
3360 ;; html stuff
3361 (if ispell-skip-html
3362 (ispell-begin-skip-region ispell-html-skip-alists))
3363 ;; tib
3364 (if ispell-skip-tib ispell-tib-ref-beginning)
3365 ;; Comments
3366 (if (and (eq 'exclusive ispell-check-comments) comment-start)
3367 ;; search from end of current comment to start of next comment.
3368 (if (string= "" comment-end) "^" (regexp-quote comment-end)))
3369 (if (and (null ispell-check-comments) comment-start)
3370 (regexp-quote comment-start))
3371 (ispell-begin-skip-region ispell-skip-region-alist)))
3372 "\\|"))
3375 (defun ispell-begin-skip-region (skip-alist)
3376 "Regular expression for start of regions to skip generated from SKIP-ALIST.
3377 Each selection should be a key of SKIP-ALIST;
3378 otherwise, the current line is skipped."
3379 (mapconcat (lambda (lst) (if (stringp (car lst)) (car lst) (eval (car lst))))
3380 skip-alist
3381 "\\|"))
3384 (defun ispell-begin-tex-skip-regexp ()
3385 "Regular expression of tex commands to skip.
3386 Generated from `ispell-tex-skip-alists'."
3387 (concat
3388 ;; raw tex keys
3389 (mapconcat (function (lambda (lst) (car lst)))
3390 (car ispell-tex-skip-alists)
3391 "\\|")
3392 "\\|"
3393 ;; keys wrapped in begin{}
3394 (mapconcat (function (lambda (lst)
3395 (concat "\\\\begin[ \t\n]*{[ \t\n]*"
3396 (car lst)
3397 "[ \t\n]*}")))
3398 (car (cdr ispell-tex-skip-alists))
3399 "\\|")))
3402 (defun ispell-skip-region-list ()
3403 "Return a list describing key and body regions to skip for this buffer.
3404 Includes regions defined by `ispell-skip-region-alist', tex mode,
3405 `ispell-html-skip-alists', and `ispell-checking-message'.
3406 Manual checking must include comments and tib references.
3407 The list is of the form described by variable `ispell-skip-region-alist'.
3408 Must be called after `ispell-buffer-local-parsing' due to dependence on mode."
3409 (let ((skip-alist ispell-skip-region-alist))
3410 ;; only additional explicit region definition is tex.
3411 (if (eq ispell-parser 'tex)
3412 (setq case-fold-search nil
3413 skip-alist (append (car ispell-tex-skip-alists)
3414 (car (cdr ispell-tex-skip-alists))
3415 skip-alist)))
3416 (if ispell-skip-html
3417 (setq skip-alist (append ispell-html-skip-alists skip-alist)))
3418 (if (and ispell-checking-message
3419 (not (eq t ispell-checking-message)))
3420 (setq skip-alist (append ispell-checking-message skip-alist)))
3421 skip-alist))
3424 (defun ispell-tex-arg-end (&optional arg)
3425 "Skip across ARG number of braces."
3426 (condition-case nil
3427 (progn
3428 (while (looking-at "[ \t\n]*\\[") (forward-sexp))
3429 (forward-sexp (or arg 1)))
3430 (error
3431 (message "Error skipping s-expressions at point %d." (point))
3432 (beep)
3433 (sit-for 2))))
3436 (defun ispell-ignore-fcc (start end)
3437 "Delete the Fcc: message header when large attachments are included.
3438 Return value `nil' if file with large attachments is saved.
3439 This can be used to avoid multiple questions for multiple large attachments.
3440 Returns point to starting location afterwards."
3441 (let ((result t))
3442 (if (and ispell-checking-message ispell-message-fcc-skip)
3443 (if (< ispell-message-fcc-skip (- end start))
3444 (let (case-fold-search head-end)
3445 (goto-char (point-min))
3446 (setq head-end
3447 (or (re-search-forward
3448 (concat "^" (regexp-quote mail-header-separator) "$")
3449 nil t)
3450 (re-search-forward "^$" nil t)
3451 (point-min)))
3452 (goto-char (point-min))
3453 (if (re-search-forward "^Fcc:" head-end t)
3454 (if (y-or-n-p
3455 "Save copy of this message with large attachments? ")
3456 (setq result nil)
3457 (beginning-of-line)
3458 (kill-line 1)))
3459 (goto-char end))))
3460 result))
3463 (defun ispell-skip-region (key)
3464 "Skip across KEY and then to end of region.
3465 Key lookup determines region to skip.
3466 Point is placed at end of skipped region."
3467 ;; move over key to begin checking.
3468 (forward-char (length key))
3469 (let ((start (point))
3470 ;; Regenerate each call... This function can change region definition.
3471 (alist (ispell-skip-region-list))
3472 alist-key null-skip)
3473 (cond
3474 ;; what about quoted comment, or comment inside strings?
3475 ((and (null ispell-check-comments) comment-start
3476 (string= key comment-start))
3477 (if (string= "" comment-end)
3478 (forward-line)
3479 (search-forward comment-end ispell-region-end t)))
3480 ((and (eq 'exclusive ispell-check-comments) comment-start
3481 (string= key comment-end))
3482 (search-forward comment-start ispell-region-end :end))
3483 ((and ispell-skip-tib (string-match ispell-tib-ref-beginning key))
3484 (re-search-forward ispell-tib-ref-end ispell-region-end t))
3485 ;; markings from alist
3487 (while alist
3488 (setq alist-key (eval (car (car alist))))
3489 (if (string-match alist-key key)
3490 (progn
3491 (setq alist (cdr (car alist)))
3492 (cond
3493 ((null alist) (setq null-skip t)) ; done! Just skip key.
3494 ((not (consp alist))
3495 ;; Search past end of spell region to find this region end.
3496 (re-search-forward (eval alist) (point-max) t))
3497 ((and (= 1 (length alist))
3498 (stringp (car alist)))
3499 (re-search-forward (car alist) (point-max) t))
3501 (setq null-skip t) ; error handling in functions!
3502 (if (consp (cdr alist))
3503 (apply (car alist) (cdr alist))
3504 (funcall (car alist)))))
3505 (setq alist nil))
3506 (setq alist (cdr alist))))))
3507 (if (and (= start (point)) (null null-skip))
3508 (progn
3509 (message "Matching region end for `%s' point %d not found"
3510 key (point))
3511 (beep)
3512 (sit-for 2)))))
3515 (defun ispell-get-line (start end in-comment)
3516 "Grab the next line of data.
3517 Returns a string with the line data."
3518 (let ((ispell-casechars (ispell-get-casechars))
3519 string)
3520 (cond ; LOOK AT THIS LINE AND SKIP OR PROCESS
3521 ((eolp) ; END OF LINE, just go to next line.
3522 (forward-line))
3523 ;;((looking-at "[-#@*+!%~^]") ; SKIP SPECIAL ISPELL CHARACTERS
3524 ;; (forward-char 1)) ; not needed as quoted below.
3525 ((or (re-search-forward ispell-casechars end t) ; TEXT EXISTS
3526 (re-search-forward "[][()${}]" end t)) ; or MATH COMMANDS
3527 (setq string (concat "^" in-comment
3528 (buffer-substring-no-properties start end)
3529 "\n"))
3530 (goto-char end))
3531 (t (goto-char end))) ; EMPTY LINE, skip it.
3532 string))
3535 (defun ispell-looking-at (string)
3536 (let ((coding (ispell-get-coding-system))
3537 (len (length string)))
3538 (and (<= (+ (point) len) (point-max))
3539 (equal (encode-coding-string string coding)
3540 (encode-coding-string (buffer-substring-no-properties
3541 (point) (+ (point) len))
3542 coding)))))
3544 (defun ispell-process-line (string shift)
3545 "Send STRING, a line of text, to ispell and process the result.
3546 This will modify the buffer for spelling errors.
3547 Requires variables ISPELL-START and ISPELL-END to be defined in its
3548 dynamic scope.
3549 Returns the sum SHIFT due to changes in word replacements."
3550 ;;(declare special ispell-start ispell-end)
3551 (let (poss accept-list)
3552 (if (not (numberp shift))
3553 (setq shift 0))
3554 ;; send string to spell process and get input.
3555 (ispell-send-string string)
3556 (while (progn
3557 (ispell-accept-output)
3558 ;; Last item of output contains a blank line.
3559 (not (string= "" (car ispell-filter)))))
3560 ;; parse all inputs from the stream one word at a time.
3561 ;; Place in FIFO order and remove the blank item.
3562 (setq ispell-filter (nreverse (cdr ispell-filter)))
3563 (while (and (not ispell-quit) ispell-filter)
3564 ;; get next word, accounting for accepted words and start shifts
3565 (setq poss (ispell-parse-output (car ispell-filter)
3566 accept-list shift))
3567 (if (and poss (listp poss)) ; spelling error occurred.
3568 ;; Whenever we have misspellings, we can change
3569 ;; the buffer. Keep boundaries as markers.
3570 ;; Markers can move with highlighting! This destroys
3571 ;; end of region markers line-end and ispell-region-end
3572 (let ((word-start
3573 (copy-marker (+ ispell-start ispell-offset (car (cdr poss)))))
3574 (word-len (length (car poss)))
3575 (line-end (copy-marker ispell-end))
3576 (line-start (copy-marker ispell-start))
3577 recheck-region replace)
3578 (goto-char word-start)
3579 ;; Adjust the horizontal scroll & point
3580 (ispell-horiz-scroll)
3581 (goto-char (+ word-len word-start))
3582 (ispell-horiz-scroll)
3583 (goto-char word-start)
3584 (ispell-horiz-scroll)
3586 ;; Alignment cannot be tracked and this error will occur when
3587 ;; `query-replace' makes multiple corrections on the starting line.
3588 (or (ispell-looking-at (car poss))
3589 ;; This error occurs due to filter pipe problems
3590 (let* ((ispell-pipe-word (car poss))
3591 (actual-point (marker-position word-start))
3592 (actual-line (line-number-at-pos actual-point))
3593 (actual-column (save-excursion (goto-char actual-point)
3594 (current-column))))
3595 (ispell-print-if-debug
3596 "ispell-process-line: Ispell misalignment error:
3597 [Word from ispell pipe]: [%s], actual (point,line,column): (%s,%s,%s)\n"
3598 ispell-pipe-word actual-point actual-line actual-column)
3599 (error (concat "Ispell misalignment: word "
3600 "`%s' point %d; probably incompatible versions")
3601 ispell-pipe-word actual-point)))
3602 ;; ispell-cmd-loop can go recursive & change buffer
3603 (if ispell-keep-choices-win
3604 (setq replace (ispell-command-loop
3605 (car (cdr (cdr poss)))
3606 (car (cdr (cdr (cdr poss))))
3607 (car poss) (marker-position word-start)
3608 (+ word-len (marker-position word-start))))
3609 (save-window-excursion
3610 (setq replace (ispell-command-loop
3611 (car (cdr (cdr poss)))
3612 (car (cdr (cdr (cdr poss))))
3613 (car poss) (marker-position word-start)
3614 (+ word-len (marker-position word-start))))))
3616 (goto-char word-start)
3617 ;; Recheck when query replace edit changes misspelled word.
3618 ;; Error in tex mode when a potential math mode change exists.
3619 (if (and replace (listp replace) (= 2 (length replace)))
3620 (if (and (eq ispell-parser 'tex)
3621 (string-match "[\\\\][]()[]\\|\\\\begin\\|\\$"
3622 (regexp-quote string)))
3623 (error
3624 "Don't start query replace on a line with math characters"
3626 (set-marker line-end (point))
3627 (setq ispell-filter nil
3628 recheck-region t)))
3630 ;; Insert correction if needed.
3631 (cond
3632 ((or (null replace)
3633 (equal 0 replace)) ; ACCEPT/INSERT
3634 (if (equal 0 replace) ; BUFFER-LOCAL DICT ADD
3635 (ispell-add-per-file-word-list (car poss)))
3636 ;; Do not recheck accepted word on this line.
3637 (setq accept-list (cons (car poss) accept-list)))
3638 (t ; Replacement word selected or entered.
3639 (delete-region (point) (+ word-len (point)))
3640 (if (not (listp replace))
3641 (progn
3642 (insert replace) ; Insert dictionary word.
3643 (ispell-send-replacement (car poss) replace)
3644 (setq accept-list (cons replace accept-list)))
3645 (let ((replace-word (car replace)))
3646 ;; Recheck hand entered replacement word.
3647 (insert replace-word)
3648 (ispell-send-replacement (car poss) replace-word)
3649 (if (car (cdr replace))
3650 (save-window-excursion
3651 (delete-other-windows) ; to correctly show help.
3652 ;; Assume case-replace &
3653 ;; case-fold-search correct?
3654 (query-replace (car poss) (car replace) t)))
3655 (goto-char word-start)
3656 ;; Do not recheck if already accepted.
3657 (if (member replace-word accept-list)
3658 (setq accept-list (cons replace-word accept-list)
3659 replace replace-word)
3660 (let ((region-end (copy-marker ispell-region-end)))
3661 (setq recheck-region ispell-filter
3662 ispell-filter nil ; Save filter.
3663 shift 0 ; Already accounted.
3664 shift (ispell-region
3665 word-start
3666 (+ word-start (length replace-word))
3667 t shift))
3668 (if (null shift) ; Quitting check.
3669 (setq shift 0))
3670 (set-marker ispell-region-end region-end)
3671 (set-marker region-end nil)
3672 (setq ispell-filter recheck-region
3673 recheck-region nil
3674 replace replace-word)))))
3676 (setq shift (+ shift (- (length replace) word-len)))
3678 ;; Move line-start across word...
3679 ;; new shift function does this now...
3680 ;;(set-marker line-start (+ line-start
3681 ;; (- (length replace)
3682 ;; (length (car poss)))))
3684 (if (not ispell-quit)
3685 ;; FIXME: remove redundancy with identical code above.
3686 (let (message-log-max)
3687 (message
3688 "Continuing spelling check using %s with %s dictionary..."
3689 (file-name-nondirectory ispell-program-name)
3690 (or ispell-current-dictionary "default"))))
3691 (sit-for 0)
3692 (setq ispell-start (marker-position line-start)
3693 ispell-end (marker-position line-end))
3694 ;; Adjust markers when end of region lost from highlighting.
3695 (if (and (not recheck-region)
3696 (< ispell-end (+ word-start word-len)))
3697 (setq ispell-end (+ word-start word-len)))
3698 (if (= word-start ispell-region-end)
3699 (set-marker ispell-region-end (+ word-start word-len)))
3700 ;; Going out of scope - unneeded.
3701 (set-marker line-start nil)
3702 (set-marker word-start nil)
3703 (set-marker line-end nil)))
3704 ;; Finished with misspelling!
3705 (setq ispell-filter (cdr ispell-filter)))
3706 shift))
3709 ;;;###autoload
3710 (defun ispell-comments-and-strings ()
3711 "Check comments and strings in the current buffer for spelling errors."
3712 (interactive)
3713 (goto-char (point-min))
3714 (let (state done)
3715 (while (not done)
3716 (setq done t)
3717 (setq state (parse-partial-sexp (point) (point-max)
3718 nil nil state 'syntax-table))
3719 (if (or (nth 3 state) (nth 4 state))
3720 (let ((start (point)))
3721 (setq state (parse-partial-sexp start (point-max)
3722 nil nil state 'syntax-table))
3723 (if (or (nth 3 state) (nth 4 state))
3724 (error "Unterminated string or comment"))
3725 (save-excursion
3726 (setq done (not (ispell-region start (point))))))))))
3729 ;;;###autoload
3730 (defun ispell-buffer ()
3731 "Check the current buffer for spelling errors interactively."
3732 (interactive)
3733 (ispell-region (point-min) (point-max)))
3735 ;;;###autoload
3736 (defun ispell-buffer-with-debug (&optional append)
3737 "`ispell-buffer' with some output sent to `ispell-debug-buffer' buffer.
3738 Use APPEND to append the info to previous buffer if exists."
3739 (interactive)
3740 (let ((ispell-debug-buffer (ispell-create-debug-buffer append)))
3741 (ispell-buffer)))
3743 ;;;###autoload
3744 (defun ispell-continue ()
3745 "Continue a halted spelling session beginning with the current word."
3746 (interactive)
3747 (if (not (marker-position ispell-region-end))
3748 (message "No session to continue. Use 'X' command when checking!")
3749 (if (not (equal (marker-buffer ispell-region-end) (current-buffer)))
3750 (message "Must continue ispell from buffer %s"
3751 (buffer-name (marker-buffer ispell-region-end)))
3752 (ispell-region
3753 ;; find beginning of current word:
3754 (car (cdr (ispell-get-word t)))
3755 (marker-position ispell-region-end)))))
3758 ;;; Horizontal scrolling
3759 (defun ispell-horiz-scroll ()
3760 "Place point within the horizontal visibility of its window area."
3761 (if truncate-lines ; display truncating lines?
3762 ;; See if display needs to be scrolled.
3763 (let ((column (- (current-column) (max (window-hscroll) 1))))
3764 (if (and (< column 0) (> (window-hscroll) 0))
3765 (scroll-right (max (- column) 10))
3766 (if (>= column (- (window-width) 2))
3767 (scroll-left (max (- column (window-width) -3) 10)))))))
3770 ;;; Interactive word completion.
3771 ;; Forces "previous-word" processing. Do we want to make this selectable?
3773 ;;;###autoload
3774 (defun ispell-complete-word (&optional interior-frag)
3775 "Try to complete the word before or under point.
3776 If optional INTERIOR-FRAG is non-nil then the word may be a character
3777 sequence inside of a word.
3779 Standard ispell choices are then available."
3780 ;; FIXME: completion-at-point-function.
3781 (interactive "P")
3782 (let ((cursor-location (point))
3783 (case-fold-search-val case-fold-search)
3784 (word (ispell-get-word nil "\\*")) ; force "previous-word" processing.
3785 start end possibilities replacement)
3786 (setq start (car (cdr word))
3787 end (car (cdr (cdr word)))
3788 word (car word)
3789 possibilities
3790 (or (string= word "") ; Will give you every word
3791 (ispell-lookup-words
3792 (concat (and interior-frag "*") word
3793 (and interior-frag "*"))
3794 (or ispell-complete-word-dict
3795 ispell-alternate-dictionary))))
3796 (cond ((eq possibilities t)
3797 (message "No word to complete"))
3798 ((null possibilities)
3799 (message "No match for \"%s\"" word))
3800 (t ; There is a modification...
3801 (setq case-fold-search nil) ; Try and respect case of word.
3802 (cond
3803 ((string-equal (upcase word) word)
3804 (setq possibilities (mapcar 'upcase possibilities)))
3805 ((eq (upcase (aref word 0)) (aref word 0))
3806 (setq possibilities (mapcar (function
3807 (lambda (pos)
3808 (if (eq (aref word 0) (aref pos 0))
3810 (capitalize pos))))
3811 possibilities))))
3812 (setq case-fold-search case-fold-search-val)
3813 (save-window-excursion
3814 (setq replacement
3815 (ispell-command-loop possibilities nil word start end)))
3816 (cond
3817 ((equal 0 replacement) ; BUFFER-LOCAL ADDITION
3818 (ispell-add-per-file-word-list word))
3819 (replacement ; REPLACEMENT WORD
3820 (delete-region start end)
3821 (setq word (if (atom replacement) replacement (car replacement))
3822 cursor-location (+ (- (length word) (- end start))
3823 cursor-location))
3824 (insert word)
3825 (if (not (atom replacement)) ; recheck spelling of replacement.
3826 (progn
3827 (goto-char cursor-location)
3828 (ispell-word nil t)))))
3829 (if (get-buffer ispell-choices-buffer)
3830 (kill-buffer ispell-choices-buffer))))
3831 (ispell-pdict-save ispell-silently-savep)
3832 (goto-char cursor-location)))
3835 ;;;###autoload
3836 (defun ispell-complete-word-interior-frag ()
3837 "Completes word matching character sequence inside a word."
3838 (interactive)
3839 (ispell-complete-word t))
3842 ;;;###autoload
3843 (defun ispell ()
3844 "Interactively check a region or buffer for spelling errors.
3845 If `transient-mark-mode' is on, and a region is active, spell-check
3846 that region. Otherwise spell-check the buffer.
3848 Ispell dictionaries are not distributed with Emacs. If you are
3849 looking for a dictionary, please see the distribution of the GNU ispell
3850 program, or do an Internet search; there are various dictionaries
3851 available on the net."
3852 (interactive)
3853 (if (and (boundp 'transient-mark-mode) transient-mark-mode
3854 (boundp 'mark-active) mark-active)
3855 (ispell-region (region-beginning) (region-end))
3856 (ispell-buffer)))
3859 ;;; **********************************************************************
3860 ;;; Ispell Minor Mode
3861 ;;; **********************************************************************
3863 (defvar ispell-minor-keymap
3864 (let ((map (make-sparse-keymap)))
3865 (define-key map " " 'ispell-minor-check)
3866 (define-key map "\r" 'ispell-minor-check)
3867 map)
3868 "Keymap used for Ispell minor mode.")
3870 ;;;###autoload
3871 (define-minor-mode ispell-minor-mode
3872 "Toggle last-word spell checking (Ispell minor mode).
3873 With a prefix argument ARG, enable Ispell minor mode if ARG is
3874 positive, and disable it otherwise. If called from Lisp, enable
3875 the mode if ARG is omitted or nil.
3877 Ispell minor mode is a buffer-local minor mode. When enabled,
3878 typing SPC or RET warns you if the previous word is incorrectly
3879 spelled.
3881 All the buffer-local variables and dictionaries are ignored. To
3882 read them into the running ispell process, type \\[ispell-word]
3883 SPC.
3885 For spell-checking \"on the fly\", not just after typing SPC or
3886 RET, use `flyspell-mode'."
3887 nil " Spell" ispell-minor-keymap)
3889 (defun ispell-minor-check ()
3890 "Check previous word, then continue with the normal binding of this key.
3891 Don't check previous word when character before point is a space or newline.
3892 Don't read buffer-local settings or word lists."
3893 (interactive "*")
3894 (let ((ispell-minor-mode nil)
3895 (ispell-check-only t)
3896 (last-char (char-after (1- (point)))))
3897 (command-execute (key-binding (this-command-keys)))
3898 (if (not (or (eq last-char ?\ ) (eq last-char ?\n)
3899 (and ispell-skip-html (eq last-char ?>))
3900 (and ispell-skip-html (eq last-char ?\;))))
3901 (ispell-word nil t))))
3904 ;;; **********************************************************************
3905 ;;; Ispell Message
3906 ;;; **********************************************************************
3908 (defvar ispell-message-text-end
3909 (mapconcat (function identity)
3911 ;; Don't spell check signatures
3912 "^-- $"
3913 ;; Matches PostScript files.
3914 ;;"^%!PS-Adobe-[123].0"
3915 ;; Matches uuencoded text
3916 ;;"^begin [0-9][0-9][0-9] .*\nM.*\nM.*\nM"
3917 ;; Matches shell files (especially auto-decoding)
3918 "^#! /bin/[ck]?sh"
3919 ;; Matches context difference listing
3920 "\\(\\(^cd .*\n\\)?diff -c .*\\)?\n\\*\\*\\* .*\n--- .*\n\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*"
3921 ;; Matches unidiff difference listing
3922 "\\(diff -u .*\\)?\n--- .*\n\\+\\+\\+ .*\n@@ [-+][0-9]+,[0-9]+ [-+][0-9]+,[0-9]+ @@"
3923 ;; Matches reporter.el bug report
3924 "^current state:\n==============\n"
3925 ;; Matches commonly used "cut" boundaries
3926 "^\\(- \\)?[-=_]+\\s ?\\(cut here\\|Environment Follows\\)")
3927 "\\|")
3928 "Text beyond which `ispell-message' will not spell-check.
3929 If it is a string, limit is the first occurrence of that regular expression.
3930 Otherwise, it must be a function which is called to get the limit.")
3931 (put 'ispell-message-text-end 'risky-local-variable t)
3934 (defun ispell-mime-multipartp (&optional limit)
3935 "Return multipart message start boundary or nil if none."
3936 ;; caller must ensure `case-fold-search' is set to `t'
3937 (and
3938 (re-search-forward
3939 "Content-Type: *multipart/\\([^ \t\n]*;[ \t]*[\n]?[ \t]*\\)+boundary="
3940 limit t)
3941 (let (boundary)
3942 (if (looking-at "\"")
3943 (let (start)
3944 (forward-char)
3945 (setq start (point))
3946 (while (not (looking-at "\""))
3947 (forward-char 1))
3948 (setq boundary (buffer-substring-no-properties start (point))))
3949 (let ((start (point)))
3950 (while (looking-at "[-0-9a-zA-Z'()+_,./:=?]")
3951 (forward-char))
3952 (setq boundary (buffer-substring-no-properties start (point)))))
3953 (if (< (length boundary) 1)
3954 (setq boundary nil)
3955 (concat "--" boundary)))))
3958 (defun ispell-mime-skip-part (boundary)
3959 "Move point across header, or entire MIME part if message is encoded.
3960 All specified types except `7bit' `8bit' and `quoted-printable' are considered
3961 encoded and therefore skipped. See rfc 1521, 2183, ...
3962 If no boundary is given, then entire message is skipped.
3964 This starts one line ABOVE the MIME content messages, on the boundary marker,
3965 for operation with the generic region-skipping code.
3966 This places new MIME boundaries into variable `ispell-checking-message'."
3967 (forward-line) ; skip over boundary to headers
3968 (let ((save-case-fold-search case-fold-search)
3969 (continuep t)
3970 textp)
3971 (setq case-fold-search t
3972 ispell-skip-html nil)
3973 (while continuep
3974 (setq continuep nil)
3975 (if (looking-at "Content-Type: *text/")
3976 (progn
3977 (goto-char (match-end 0))
3978 (if (looking-at "html")
3979 (setq ispell-skip-html t))
3980 (setq textp t
3981 continuep t)
3982 (re-search-forward "\\(.*;[ \t]*[\n]\\)*.*$" nil t)
3983 (forward-line)))
3984 (if (looking-at "Content-Transfer-Encoding: *\\([^ \t\n]*\\)")
3985 (let ((match (buffer-substring (match-beginning 1) (match-end 1))))
3986 (setq textp (member (upcase match)
3987 ;; only spell check the following encodings:
3988 '("7BIT" "8BIT" "QUOTED-PRINTABLE" "BINARY"))
3989 continuep t)
3990 (goto-char (match-end 0))
3991 (re-search-forward "\\(.*;[ \t]*[\n]\\)*.*$" nil t)
3992 (forward-line)))
3993 ;; hierarchical boundary definition
3994 (if (looking-at "Content-Type: *multipart/")
3995 (let ((new-boundary (ispell-mime-multipartp)))
3996 (if (string-match new-boundary boundary)
3997 (setq continuep t)
3998 ;; first pass redefine skip function to include new boundary
3999 ;;(re-search-backward boundary nil t)
4000 (forward-line)
4001 (setq ispell-checking-message
4002 (cons
4003 (list new-boundary 'ispell-mime-skip-part new-boundary)
4004 (if (eq t ispell-checking-message) nil
4005 ispell-checking-message))
4006 textp t
4007 continuep t)))
4008 ;; Skip all MIME headers that don't affect spelling
4009 (if (looking-at "Content-[^ \t]*: *\\(.*;[ \t]*[\n]\\)*.*$")
4010 (progn
4011 (setq continuep t)
4012 (goto-char (match-end 0))
4013 (forward-line)))))
4015 (setq case-fold-search save-case-fold-search)
4016 (if textp
4017 (point)
4018 ;; encoded message. Skip to boundary, or entire message.
4019 (if (not boundary)
4020 (goto-char (point-max))
4021 (re-search-forward boundary nil t)
4022 (beginning-of-line)
4023 (point)))))
4026 ;;;###autoload
4027 (defun ispell-message ()
4028 "Check the spelling of a mail message or news post.
4029 Don't check spelling of message headers except the Subject field.
4030 Don't check included messages.
4032 To abort spell checking of a message region and send the message anyway,
4033 use the `x' command. (Any subsequent regions will be checked.)
4034 The `X' command aborts sending the message so that you can edit the buffer.
4036 To spell-check whenever a message is sent, include the appropriate lines
4037 in your init file:
4038 (add-hook 'message-send-hook 'ispell-message) ;; GNUS 5
4039 (add-hook 'news-inews-hook 'ispell-message) ;; GNUS 4
4040 (add-hook 'mail-send-hook 'ispell-message)
4041 (add-hook 'mh-before-send-letter-hook 'ispell-message)
4043 You can bind this to the key C-c i in GNUS or mail by adding to
4044 `news-reply-mode-hook' or `mail-mode-hook' the following lambda expression:
4045 (function (lambda () (local-set-key \"\\C-ci\" 'ispell-message)))"
4046 (interactive)
4047 (save-excursion
4048 (goto-char (point-min))
4049 (let* (boundary mimep
4050 (ispell-skip-region-alist-save ispell-skip-region-alist)
4051 ;; Nil when message came from outside (eg calling Emacs as editor)
4052 ;; Non-nil marker of end of headers.
4053 (internal-messagep
4054 (re-search-forward
4055 (concat "^" (regexp-quote mail-header-separator) "$") nil t))
4056 (end-of-headers ; Start of body.
4057 (copy-marker
4058 (or internal-messagep
4059 (re-search-forward "^$" nil t)
4060 (point-min))))
4061 (limit (copy-marker ; End of region we will spell check.
4062 (cond
4063 ((not ispell-message-text-end) (point-max))
4064 ((char-or-string-p ispell-message-text-end)
4065 (if (re-search-forward ispell-message-text-end nil t)
4066 (match-beginning 0)
4067 (point-max)))
4068 (t (min (point-max) (funcall ispell-message-text-end))))))
4069 (default-prefix ; Vanilla cite prefix (just used for cite-regexp)
4070 (if (and (boundp 'mail-yank-prefix) mail-yank-prefix)
4071 (ispell-non-empty-string mail-yank-prefix)
4072 " \\|\t"))
4073 (cite-regexp ;Prefix of quoted text
4074 (cond
4075 ((functionp 'sc-cite-regexp) ; sc 3.0
4076 (ispell-with-no-warnings
4077 (concat "\\(" (sc-cite-regexp) "\\)" "\\|"
4078 (ispell-non-empty-string sc-reference-tag-string))))
4079 ((boundp 'sc-cite-regexp) ; sc 2.3
4080 (concat "\\(" sc-cite-regexp "\\)" "\\|"
4081 (ispell-with-no-warnings
4082 (ispell-non-empty-string sc-reference-tag-string))))
4083 ((or (equal major-mode 'news-reply-mode) ;GNUS 4 & below
4084 (equal major-mode 'message-mode)) ;GNUS 5
4085 (concat "In article <" "\\|"
4086 "[^,;&+=\n]+ <[^,;&+=]+> writes:" "\\|"
4087 (ispell-with-no-warnings message-cite-prefix-regexp)
4088 "\\|"
4089 default-prefix))
4090 ((equal major-mode 'mh-letter-mode) ; mh mail message
4091 (concat "[^,;&+=\n]+ writes:" "\\|"
4092 (ispell-with-no-warnings
4093 (ispell-non-empty-string mh-ins-buf-prefix))))
4094 ((not internal-messagep) ; Assume nn sent us this message.
4095 (concat "In [a-zA-Z.]+ you write:" "\\|"
4096 "In <[^,;&+=]+> [^,;&+=]+ writes:" "\\|"
4097 " *> *"))
4098 ((boundp 'vm-included-text-prefix) ; VM mail message
4099 (concat "[^,;&+=\n]+ writes:" "\\|"
4100 (ispell-non-empty-string vm-included-text-prefix)))
4101 (t default-prefix)))
4102 (ispell-skip-region-alist
4103 (cons (list (concat "^\\(" cite-regexp "\\)")
4104 (function forward-line))
4105 ispell-skip-region-alist))
4106 (old-case-fold-search case-fold-search)
4107 (dictionary-alist ispell-message-dictionary-alist)
4108 (ispell-checking-message t))
4110 ;; Select dictionary for message
4111 (or (local-variable-p 'ispell-local-dictionary (current-buffer))
4112 (while dictionary-alist
4113 (goto-char (point-min))
4114 (if (re-search-forward (car (car dictionary-alist))
4115 end-of-headers t)
4116 (setq ispell-local-dictionary (cdr (car dictionary-alist))
4117 dictionary-alist nil)
4118 (setq dictionary-alist (cdr dictionary-alist)))))
4120 (unwind-protect
4121 (progn
4122 ;; Spell check any original Subject:
4123 (goto-char (point-min))
4124 (setq case-fold-search t
4125 mimep (re-search-forward "MIME-Version:" end-of-headers t))
4126 (goto-char (point-min))
4127 (if (re-search-forward "^Subject: *" end-of-headers t)
4128 (progn
4129 (goto-char (match-end 0))
4130 (if (and (not (looking-at ".*Re\\>"))
4131 (not (looking-at "\\[")))
4132 (progn
4133 (setq case-fold-search old-case-fold-search)
4134 (ispell-region (point)
4135 (progn ;Tab-initiated continuation lns.
4136 (end-of-line)
4137 (while (looking-at "\n[ \t]")
4138 (end-of-line 2))
4139 (point)))))))
4140 (if mimep
4141 (progn
4142 (goto-char (point-min))
4143 (setq boundary (ispell-mime-multipartp end-of-headers))))
4144 ;; Adjust message limit to MIME message if necessary.
4145 (and boundary
4146 (re-search-forward (concat boundary "--") nil t)
4147 (re-search-backward boundary nil t)
4148 (< (point) (marker-position limit))
4149 (set-marker limit (point)))
4150 (goto-char (point-min))
4151 ;; Select type or skip checking if this is a non-multipart message
4152 ;; Point moved to end of buffer if region is encoded.
4153 (when (and mimep (not boundary))
4154 (goto-char (point-min))
4155 (re-search-forward "Content-[^ \t]*:" end-of-headers t)
4156 (forward-line -1) ; following fn starts one line above
4157 (ispell-mime-skip-part nil)
4158 ;; if message-text-end region, limit may be less than point.
4159 (if (> (point) limit)
4160 (set-marker limit (point))))
4161 (goto-char (max end-of-headers (point)))
4162 (forward-line 1)
4163 (setq case-fold-search old-case-fold-search)
4164 ;; Define MIME regions to skip.
4165 (if boundary
4166 (setq ispell-checking-message
4167 (list (list boundary 'ispell-mime-skip-part boundary))))
4168 (ispell-region (point) limit))
4169 (set-marker end-of-headers nil)
4170 (set-marker limit nil)
4171 (setq ispell-skip-region-alist ispell-skip-region-alist-save
4172 ispell-skip-html nil
4173 case-fold-search old-case-fold-search)))))
4176 (defun ispell-non-empty-string (string)
4177 (if (or (not string) (string-equal string ""))
4178 "\\'\\`" ; An unmatchable string if string is null.
4179 (regexp-quote string)))
4182 ;;; **********************************************************************
4183 ;;; Buffer Local Functions
4184 ;;; **********************************************************************
4187 (defun ispell-accept-buffer-local-defs ()
4188 "Load all buffer-local information, restarting Ispell when necessary."
4189 (ispell-buffer-local-dict) ; May kill ispell-process.
4190 (ispell-buffer-local-words) ; Will initialize ispell-process.
4191 (ispell-buffer-local-parsing))
4194 (defun ispell-buffer-local-parsing ()
4195 "Place Ispell into parsing mode for this buffer.
4196 Overrides the default parsing mode.
4197 Includes LaTeX/Nroff modes and extended character mode."
4198 ;; (ispell-init-process) must already be called.
4199 (ispell-send-string "!\n") ; Put process in terse mode.
4200 ;; We assume all major modes with "tex-mode" in them should use latex parsing
4201 ;; When exclusively checking comments, set to raw text mode (nroff).
4202 (if (and (not (eq 'exclusive ispell-check-comments))
4203 (or (and (eq ispell-parser 'use-mode-name)
4204 (string-match "[Tt][Ee][Xx]-mode"
4205 (symbol-name major-mode)))
4206 (eq ispell-parser 'tex)))
4207 (progn
4208 (ispell-send-string "+\n") ; set ispell mode to tex
4209 (if (not (eq ispell-parser 'tex))
4210 (set (make-local-variable 'ispell-parser) 'tex)))
4211 (ispell-send-string "-\n")) ; set mode to normal (nroff)
4212 ;; If needed, test for SGML & HTML modes and set a buffer local nil/t value.
4213 (if (and ispell-skip-html (not (eq ispell-skip-html t)))
4214 (setq ispell-skip-html
4215 (not (null (string-match "sgml\\|html\\|xml"
4216 (downcase (symbol-name major-mode)))))))
4217 ;; Set default extended character mode for given buffer, if any.
4218 (let ((extended-char-mode (ispell-get-extended-character-mode)))
4219 (if extended-char-mode
4220 (ispell-send-string (concat extended-char-mode "\n"))))
4221 ;; Set buffer-local parsing mode and extended character mode, if specified.
4222 (save-excursion
4223 (goto-char (point-max))
4224 ;; Uses last occurrence of ispell-parsing-keyword
4225 (if (search-backward ispell-parsing-keyword nil t)
4226 (let ((end (point-at-eol))
4227 string)
4228 (search-forward ispell-parsing-keyword)
4229 (while (re-search-forward " *\\([^ \"]+\\)" end t)
4230 ;; space separated definitions.
4231 (setq string (downcase (match-string-no-properties 1)))
4232 (cond ((and (string-match "latex-mode" string)
4233 (not (eq 'exclusive ispell-check-comments)))
4234 (ispell-send-string "+\n~tex\n"))
4235 ((string-match "nroff-mode" string)
4236 (ispell-send-string "-\n~nroff\n"))
4237 ((string-match "~" string) ; Set extended character mode.
4238 (ispell-send-string (concat string "\n")))
4239 (t (message "Invalid Ispell Parsing argument!")
4240 (sit-for 2))))))))
4243 ;; Can kill the current ispell process
4245 (defun ispell-buffer-local-dict (&optional no-reload)
4246 "Initializes local dictionary and local personal dictionary.
4247 If optional NO-RELOAD is non-nil, do not reload any dictionary.
4248 When a dictionary is defined in the buffer (see variable
4249 `ispell-dictionary-keyword'), it will override the local setting
4250 from \\[ispell-change-dictionary].
4251 Both should not be used to define a buffer-local dictionary."
4252 (save-excursion
4253 (goto-char (point-min))
4254 (let (end)
4255 ;; Override the local variable definition.
4256 ;; Uses last occurrence of ispell-dictionary-keyword.
4257 (goto-char (point-max))
4258 (unless ispell-local-dictionary-overridden
4259 (if (search-backward ispell-dictionary-keyword nil t)
4260 (progn
4261 (search-forward ispell-dictionary-keyword)
4262 (setq end (point-at-eol))
4263 (if (re-search-forward " *\\([^ \"]+\\)" end t)
4264 (setq ispell-local-dictionary
4265 (match-string-no-properties 1))))))
4266 (goto-char (point-max))
4267 (if (search-backward ispell-pdict-keyword nil t)
4268 (progn
4269 (search-forward ispell-pdict-keyword)
4270 (setq end (point-at-eol))
4271 (if (re-search-forward " *\\([^ \"]+\\)" end t)
4272 (setq ispell-local-pdict
4273 (match-string-no-properties 1)))))))
4274 (unless no-reload
4275 ;; Reload if new dictionary (maybe the personal one) defined.
4276 (ispell-internal-change-dictionary)))
4279 (defun ispell-buffer-local-words ()
4280 "Load the buffer-local dictionary in the current buffer."
4281 ;; If there's an existing ispell process that's wrong for this use,
4282 ;; kill it.
4283 (if (and ispell-buffer-local-name
4284 (not (equal ispell-buffer-local-name (buffer-name))))
4285 (ispell-kill-ispell t))
4286 ;; Actually start a new ispell process, because we need
4287 ;; to send commands now to specify the local words to it.
4288 (ispell-init-process)
4289 (dolist (session-localword ispell-buffer-session-localwords)
4290 (ispell-send-string (concat "@" session-localword "\n")))
4291 (or ispell-buffer-local-name
4292 (if ispell-buffer-session-localwords
4293 (setq ispell-buffer-local-name (buffer-name))))
4294 (save-excursion
4295 (goto-char (point-min))
4296 (while (search-forward ispell-words-keyword nil t)
4297 (or ispell-buffer-local-name
4298 (setq ispell-buffer-local-name (buffer-name)))
4299 (let ((end (point-at-eol))
4300 (ispell-casechars (ispell-get-casechars))
4301 string)
4302 ;; buffer-local words separated by a space, and can contain
4303 ;; any character other than a space. Not rigorous enough.
4304 (while (re-search-forward " *\\([^ ]+\\)" end t)
4305 (setq string (match-string-no-properties 1))
4306 ;; This can fail when string contains a word with invalid chars.
4307 ;; Error handling needs to be added between ispell and Emacs.
4308 (if (and (< 1 (length string))
4309 (equal 0 (string-match ispell-casechars string)))
4310 (ispell-send-string (concat "@" string "\n"))))))))
4313 ;; Returns optionally adjusted region-end-point.
4315 ;; If comment-padright is defined, newcomment must be loaded.
4316 (declare-function comment-add "newcomment" (arg))
4318 (defun ispell-add-per-file-word-list (word)
4319 "Add WORD to the per-file word list."
4320 (or ispell-buffer-local-name
4321 (setq ispell-buffer-local-name (buffer-name)))
4322 (save-excursion
4323 (goto-char (point-min))
4324 (let (line-okay search done found)
4325 (while (not done)
4326 (let ((case-fold-search nil))
4327 (setq search (search-forward ispell-words-keyword nil 'move)
4328 found (or found search)
4329 line-okay (< (+ (length word) 1 ; 1 for space after word..
4330 (progn (end-of-line) (current-column)))
4331 fill-column)))
4332 (if (or (and search line-okay)
4333 (null search))
4334 (progn
4335 (setq done t)
4336 (if (null search)
4337 (progn
4338 (open-line 1)
4339 (unless found (newline))
4340 (insert (if comment-start
4341 (concat
4342 (if (fboundp 'comment-padright)
4343 ;; Try and use the proper comment marker,
4344 ;; e.g. ";;" rather than ";".
4345 (progn
4346 ;; XEmacs: comment-normalize-vars
4347 ;; (newcomment.el) only in >= 21.5
4348 (and (fboundp 'comment-normalize-vars)
4349 (comment-normalize-vars))
4350 (comment-padright comment-start
4351 (comment-add nil)))
4352 comment-start)
4353 " ")
4355 ispell-words-keyword)
4356 (if (and comment-end (> (length comment-end) 0))
4357 (save-excursion
4358 (newline)
4359 (insert comment-end)))))
4360 (insert (concat " " word))))))))
4362 (add-to-list 'debug-ignored-errors "^No word found to check!$")
4364 (provide 'ispell)
4367 ;;; LOCAL VARIABLES AND BUFFER-LOCAL VALUE EXAMPLES.
4369 ;; Local Variable options:
4370 ;; mode: name(-mode)
4371 ;; eval: expression
4372 ;; local-variable: value
4374 ;; The following sets the buffer local dictionary to `american' English
4375 ;; and spell checks only comments.
4377 ;; Local Variables:
4378 ;; mode: emacs-lisp
4379 ;; comment-column: 40
4380 ;; ispell-check-comments: exclusive
4381 ;; ispell-local-dictionary: "american"
4382 ;; End:
4385 ;;; MORE EXAMPLES OF ISPELL BUFFER-LOCAL VALUES
4387 ;; The following places this file in nroff parsing and extended char modes.
4388 ;; Local IspellParsing: nroff-mode ~nroff
4389 ;; Change IspellPersDict to IspellPersDict: to enable the following line.
4390 ;; Local IspellPersDict ~/.ispell_lisp
4391 ;; The following were automatically generated by ispell using the 'A' command:
4392 ; LocalWords: settable alist inews mh frag pdict Wildcards iconify arg tex kss
4393 ; LocalWords: alists minibuffer bufferp autoload loaddefs aff Dansk KOI SPC op
4394 ; LocalWords: Francais Nederlands charset autoloaded popup nonmenu regexp num
4395 ; LocalWords: AMStex hspace includeonly nocite epsfig displaymath eqnarray reg
4396 ; LocalWords: minipage pers dict unhighlight buf grep sync prev inc
4397 ; LocalWords: fn oldot NB AIX msg init read's bufs pt cmd Quinlan eg
4398 ; LocalWords: uuencoded unidiff sc nn VM SGML eval IspellPersDict
4399 ; LocalWords: lns XEmacs HTML casechars Multibyte
4401 ;;; ispell.el ends here