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