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