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