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