Doc fixes.
[bpt/emacs.git] / lisp / textmodes / ispell.el
CommitLineData
f5136913 1;;; ispell.el --- Interface to International Ispell Version 3.1
be010748 2
f5136913 3;; Copyright (C) 1994, 1995, 1997, 1998 Free Software Foundation, Inc.
be010748 4
b578f267 5;; Authors : Ken Stevens <k.stevens@ieee.org>
f5136913
RS
6;; Stevens Mod Date: Tue Apr 28 14:40:01 PDT 1998
7;; Stevens Revision: 3.0
8;; Status : Release with 3.1.12+ ispell.
9;; Bug Reports : ispell-el-bugs@itcorp.com
10;; Web Site : http://kdstevens.com/~stevens/ispell-page.html
be010748 11
b578f267
EN
12;; This file is part of GNU Emacs.
13
14;; GNU Emacs is free software; you can redistribute it and/or modify
15;; it under the terms of the GNU General Public License as published by
16;; the Free Software Foundation; either version 2, or (at your option)
17;; any later version.
18
19;; GNU Emacs is distributed in the hope that it will be useful,
20;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22;; GNU General Public License for more details.
23
24;; You should have received a copy of the GNU General Public License
25;; along with GNU Emacs; see the file COPYING. If not, write to the
26;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
27;; Boston, MA 02111-1307, USA.
28
29;; Note: version numbers and time stamp are not updated
f5136913 30;; when this file is edited for release with GNU emacs.
be010748 31
007852e0 32;;; Commentary:
007852e0 33
b578f267 34;; INSTRUCTIONS
f5136913 35
b578f267
EN
36;; This code contains a section of user-settable variables that you should
37;; inspect prior to installation. Look past the end of the history list.
38;; Set them up for your locale and the preferences of the majority of the
39;; users. Otherwise the users may need to set a number of variables
40;; themselves.
41;; You particularly may want to change the default dictionary for your
42;; country and language.
f5136913 43
b578f267 44;; Depending on the mail system you use, you may want to include these:
f5136913 45
b578f267
EN
46;; (add-hook 'news-inews-hook 'ispell-message)
47;; (add-hook 'mail-send-hook 'ispell-message)
48;; (add-hook 'mh-before-send-letter-hook 'ispell-message)
f5136913
RS
49
50
b578f267
EN
51;; Ispell has a TeX parser and a nroff parser (the default).
52;; The parsing is controlled by the variable ispell-parser. Currently
53;; it is just a "toggle" between TeX and nroff, but if more parsers are
54;; added it will be updated. See the variable description for more info.
f5136913
RS
55
56
b578f267 57;; TABLE OF CONTENTS
f5136913 58
b578f267
EN
59;; ispell-word
60;; ispell-region
61;; ispell-buffer
62;; ispell-message
bc7d6816 63;; ispell-comments-and-strings
b578f267
EN
64;; ispell-continue
65;; ispell-complete-word
66;; ispell-complete-word-interior-frag
67;; ispell-change-dictionary
68;; ispell-kill-ispell
69;; ispell-pdict-save
f5136913
RS
70;; ispell-skip-region-alist
71
b578f267
EN
72;; Commands in ispell-region:
73;; Character replacement: Replace word with choice. May query-replace.
f5136913
RS
74;; ` ': Accept word this time.
75;; `i': Accept word and insert into private dictionary.
76;; `a': Accept word for this session.
77;; `A': Accept word and place in buffer-local dictionary.
78;; `r': Replace word with typed-in value. Rechecked.
79;; `R': Replace word with typed-in value. Query-replaced in buffer. Rechecked.
80;; `?': Show these commands
81;; `x': Exit spelling buffer. Move cursor to original point.
82;; `X': Exit spelling buffer. Leaves cursor at the current point, and permits
83;; the check to be completed later.
84;; `q': Quit spelling session (Kills ispell process).
85;; `l': Look up typed-in replacement in alternate dictionary. Wildcards okay.
86;; `u': Like `i', but the word is lower-cased first.
87;; `m': Place entered value in personal dictionary, then recheck current word.
88;; `C-l': redraws screen
89;; `C-r': recursive edit
90;; `C-z': suspend emacs or iconify frame
91
b578f267
EN
92;; Buffer-Local features:
93;; There are a number of buffer-local features that can be used to customize
94;; ispell for the current buffer. This includes language dictionaries,
95;; personal dictionaries, parsing, and local word spellings. Each of these
96;; local customizations are done either through local variables, or by
97;; including the keyword and argument(s) at the end of the buffer (usually
98;; prefixed by the comment characters). See the end of this file for
99;; examples. The local keywords and variables are:
f5136913 100
b578f267
EN
101;; ispell-dictionary-keyword language-dictionary
102;; uses local variable ispell-local-dictionary
103;; ispell-pdict-keyword personal-dictionary
104;; uses local variable ispell-local-pdict
105;; ispell-parsing-keyword mode-arg extended-char-arg
106;; ispell-words-keyword any number of local word spellings
f5136913
RS
107
108;; Region skipping:
109;; Place new regular expression definitions of regions you prefer not to
110;; spell check in `ispell-skip-region-alist'. Mode-dependent features can
111;; be added to latex by modifying `ispell-tex-skip-alists'.
112;; `ispell-message' contains some custom skipping code for e-mail messages.
113
b578f267
EN
114;; BUGS:
115;; Highlighting in version 19 still doesn't work on tty's.
116;; On some versions of emacs, growing the minibuffer fails.
f5136913
RS
117;; Autoloading ispell can result in problems if you need to use a local or
118;; modified dictionary. Place the following in your .emacs file to
119;; override the autoload definitions:
120;; (setq ispell-dictionary-alist (cons '(dictionary ...)
121;; ispell-dictionary-alist))
122;; (setq ispell-menu-map nil)
123;; (load-library "ispell")
007852e0 124
007852e0
RS
125;;; Code:
126
f5136913
RS
127;;; Custom.el macros require recompiling this when they are not present.
128;;; Add in backward compatible custom support.
129(eval-when-compile
130 (if (not (fboundp 'defcustom))
131 (defmacro defcustom (symbol value doc &rest args)
132 "Empty replacement for defcustom when not supplied."
133 `(defvar ,symbol ,value ,doc))))
007852e0 134
f5136913
RS
135(eval-when-compile
136 (if (fboundp 'defgroup)
137 (defgroup ispell nil
138 "User variables for emacs ispell interface."
139 :group 'applications)))
f2b7eb26 140
f5136913
RS
141
142;;; **********************************************************************
143;;; The following variables should be set according to personal preference
144;;; and location of binaries:
145;;; **********************************************************************
146
147
148;;; ******* THIS FILE IS WRITTEN FOR ISPELL VERSION 3.1
149;;; Code:
150
151(defcustom ispell-highlight-p 'block
152 "*Highlight spelling errors when non-nil.
153When set to `block', assumes a block cursor with TTY displays."
154 :type '(choice (const block) (const t) (const nil))
f2b7eb26
RS
155 :group 'ispell)
156
157(defcustom ispell-highlight-face 'highlight
a9210a53
RS
158 "*The face used for Ispell highlighting. For Emacses with overlays.
159Possible values are `highlight', `modeline', `secondary-selection',
160`region', and `underline'.
007852e0
RS
161This variable can be set by the user to whatever face they desire.
162It's most convenient if the cursor color and highlight color are
f2b7eb26
RS
163slightly different."
164 :type 'face
165 :group 'ispell)
007852e0 166
f2b7eb26 167(defcustom ispell-check-comments t
f5136913
RS
168 "*Spelling of comments checked when non-nil.
169When set to `exclusive', ONLY comments are checked. (For code comments).
170Warning! Not checking comments, when a comment start is embedded in strings,
171may produce undesired results."
172 :type '(choice (const exclusive) (const t) (const nil))
f2b7eb26 173 :group 'ispell)
007852e0 174
f2b7eb26 175(defcustom ispell-query-replace-choices nil
4b03da72 176 "*Corrections made throughout region when non-nil.
f2b7eb26
RS
177Uses `query-replace' (\\[query-replace]) for corrections."
178 :type 'boolean
179 :group 'ispell)
007852e0 180
f2b7eb26 181(defcustom ispell-skip-tib nil
a9210a53 182 "*Does not spell check `tib' bibliography references when non-nil.
4b03da72 183Skips any text between strings matching regular expressions
a9210a53 184`ispell-tib-ref-beginning' and `ispell-tib-ref-end'.
007852e0
RS
185
186TeX users beware: Any field starting with [. will skip until a .] -- even
a9210a53 187your whole buffer -- unless you set `ispell-skip-tib' to nil. That includes
f2b7eb26
RS
188a [.5mm] type of number...."
189 :type 'boolean
190 :group 'ispell)
007852e0
RS
191
192(defvar ispell-tib-ref-beginning "[[<]\\."
193 "Regexp matching the beginning of a Tib reference.")
194
195(defvar ispell-tib-ref-end "\\.[]>]"
196 "Regexp matching the end of a Tib reference.")
197
f2b7eb26 198(defcustom ispell-keep-choices-win t
a9210a53 199 "*When not nil, the `*Choices*' window remains for spelling session.
f2b7eb26
RS
200This minimizes redisplay thrashing."
201 :type 'boolean
202 :group 'ispell)
007852e0 203
f2b7eb26 204(defcustom ispell-choices-win-default-height 2
a9210a53 205 "*The default size of the `*Choices*' window, including status line.
f2b7eb26
RS
206Must be greater than 1."
207 :type 'integer
208 :group 'ispell)
007852e0 209
f2b7eb26
RS
210(defcustom ispell-program-name "ispell"
211 "Program invoked by \\[ispell-word] and \\[ispell-region] commands."
212 :type 'string
213 :group 'ispell)
007852e0 214
f2b7eb26 215(defcustom ispell-alternate-dictionary
007852e0 216 (cond ((file-exists-p "/usr/dict/web2") "/usr/dict/web2")
e29702dd 217 ((file-exists-p "/usr/share/dict/web2") "/usr/share/dict/web2")
007852e0
RS
218 ((file-exists-p "/usr/dict/words") "/usr/dict/words")
219 ((file-exists-p "/usr/lib/dict/words") "/usr/lib/dict/words")
e29702dd 220 ((file-exists-p "/usr/share/dict/words") "/usr/share/dict/words")
007852e0
RS
221 ((file-exists-p "/sys/dict") "/sys/dict")
222 (t "/usr/dict/words"))
f2b7eb26
RS
223 "*Alternate dictionary for spelling help."
224 :type 'file
225 :group 'ispell)
007852e0 226
f2b7eb26
RS
227(defcustom ispell-complete-word-dict ispell-alternate-dictionary
228 "*Dictionary used for word completion."
229 :type 'file
230 :group 'ispell)
007852e0 231
f5136913
RS
232(defcustom ispell-message-dictionary-alist nil
233 "*List used by `ispell-message' to select a new dictionary.
234It consists of pairs (REGEXP . DICTIONARY). If REGEXP is found
235in the message headers, `ispell-local-dictionary' will be set to
236DICTIONARY if `ispell-local-dictionary' is not buffer-local.
237E.g. you may use the following value:
238 '((\"^Newsgroups:[ \\t]*de\\\\.\" . \"deutsch8\")
239 (\"^To:[^\\n,]+\\\\.de[ \\t\\n,>]\" . \"deutsch8\"))"
240 :type '(repeat (cons regexp string))
241 :group 'ispell)
007852e0 242
f5136913
RS
243
244(defcustom ispell-grep-command "egrep"
245 "Name of the grep command for search processes."
246 :type 'string
247 :group 'ispell)
248
249(defcustom ispell-grep-options "-i"
a9210a53 250 "String of options to use when running the program in `ispell-grep-command'.
007852e0 251Should probably be \"-i\" or \"-e\".
f5136913
RS
252Some machines (like the NeXT) don't support \"-i\""
253 :type 'string
254 :group 'ispell)
007852e0 255
f5136913
RS
256(defcustom ispell-look-command
257 (cond ((file-exists-p "/bin/look") "/bin/look")
258 ((file-exists-p "/usr/local/bin/look") "/usr/local/bin/look")
259 ((file-exists-p "/usr/bin/look") "/usr/bin/look")
260 (t "look"))
007852e0 261 "Name of the look command for search processes.
f5136913
RS
262This must be an absolute file name."
263 :type 'file
264 :group 'ispell)
007852e0 265
f2b7eb26 266(defcustom ispell-look-p (file-exists-p ispell-look-command)
e29702dd 267 "*Non-nil means use `look' rather than `grep'.
f2b7eb26
RS
268Default is based on whether `look' seems to be available."
269 :type 'boolean
270 :group 'ispell)
007852e0 271
f2b7eb26
RS
272(defcustom ispell-have-new-look nil
273 "*Non-nil means use the `-r' option (regexp) when running `look'."
274 :type 'boolean
275 :group 'ispell)
007852e0 276
f5136913
RS
277(defcustom ispell-look-options (if ispell-have-new-look "-dfr" "-df")
278 "String of command options for `ispell-look-command'."
279 :type 'string
280 :group 'ispell)
007852e0 281
f5136913 282(defcustom ispell-use-ptys-p nil
a9210a53 283 "When non-nil, Emacs uses ptys to communicate with Ispell.
f5136913
RS
284When nil, Emacs uses pipes."
285 :type 'boolean
286 :group 'ispell)
007852e0 287
f2b7eb26 288(defcustom ispell-following-word nil
a9210a53 289 "*Non-nil means `ispell-word' checks the word around or after point.
f2b7eb26
RS
290Otherwise `ispell-word' checks the preceding word."
291 :type 'boolean
292 :group 'ispell)
007852e0 293
f2b7eb26 294(defcustom ispell-help-in-bufferp nil
a9210a53 295 "*Non-nil means display interactive keymap help in a buffer.
f5136913
RS
296The following valued are supported:
297 nil Expand the minibuffer and display a short help message
298 there for a couple of seconds.
299 t Pop up a new buffer and display a short help message there
300 for a couple of seconds.
301 electric Pop up a new buffer and display a long help message there.
302 User can browse and then exit the help mode."
303 :type '(choice (const electric) (const t) (const nil))
304
f2b7eb26 305 :group 'ispell)
007852e0 306
f2b7eb26
RS
307(defcustom ispell-quietly nil
308 "*Non-nil means suppress messages in `ispell-word'."
309 :type 'boolean
310 :group 'ispell)
007852e0 311
f2b7eb26 312(defcustom ispell-format-word (function upcase)
4b03da72 313 "*Formatting function for displaying word being spell checked.
f2b7eb26
RS
314The function must take one string argument and return a string."
315 :type 'function
316 :group 'ispell)
007852e0 317
f5136913
RS
318(defcustom ispell-use-framepop-p nil
319 "When non-nil ispell uses framepop to display choices in a dedicated frame.
320You can set this variable to dynamically use framepop if you are in a
321window system by evaluating the following on startup to set this variable:
322 (and window-system (condition-case () (require 'framepop) (error nil)))"
323 :type 'boolean
324 :group 'ispell)
325
d38e5dbe 326;;;###autoload
f2b7eb26 327(defcustom ispell-personal-dictionary nil
e29702dd
KH
328 "*File name of your personal spelling dictionary, or nil.
329If nil, the default personal dictionary, \"~/.ispell_DICTNAME\" is used,
f2b7eb26 330where DICTNAME is the name of your default dictionary."
6c80b133
RS
331 :type '(choice file
332 (const :tag "default" nil))
f2b7eb26 333 :group 'ispell)
007852e0 334
f2b7eb26
RS
335(defcustom ispell-silently-savep nil
336 "*When non-nil, save the personal dictionary without confirmation."
337 :type 'boolean
338 :group 'ispell)
007852e0 339
f5136913
RS
340;;; This is the local dictionary to use. When nil the default dictionary will
341;;; be used. Change set-default call to use a new default dictionary.
342(defcustom ispell-local-dictionary nil
343 "If non-nil, the dictionary to be used for Ispell commands.
344The value must be a string dictionary name in `ispell-dictionary-alist'.
345This variable becomes buffer-local when set in any fashion.
346
347Setting ispell-local-dictionary to a value has the same effect as
348calling \\[ispell-change-dictionary] with that value. This variable
349is automatically set when defined in the file with either
350`ispell-dictionary-keyword' or the Local Variable syntax.
351
352To create a non-standard default dictionary (not from ispell-dictionary-alist)
353call function set-default with the new dictionary name."
354 :type '(choice string
355 (const :tag "default" nil))
356 :group 'ispell)
357
358(make-variable-buffer-local 'ispell-local-dictionary)
359
360;; Call this function set up the default dictionary if not English.
361;;(set-default 'ispell-local-dictionary nil)
007852e0 362
007852e0 363
f2b7eb26 364(defcustom ispell-extra-args nil
a9210a53 365 "*If non-nil, a list of extra switches to pass to the Ispell program.
f5136913 366For example, (\"-W\" \"3\") to cause it to accept all 1-3 character
4b03da72 367words as correct. See also `ispell-dictionary-alist', which may be used
f2b7eb26
RS
368for language-specific arguments."
369 :type '(repeat string)
370 :group 'ispell)
4b03da72 371
d38e5dbe
RS
372;;; The preparation of the menu bar menu must be autoloaded
373;;; because otherwise this file gets autoloaded every time Emacs starts
374;;; so that it can set up the menus and determine keyboard equivalents.
8ce8687e 375
f5136913
RS
376;;; split dictionary so line length is smaller in loaddefs.el
377
d38e5dbe 378;;;###autoload
f5136913
RS
379(defvar ispell-dictionary-alist-1
380 '((nil ; default (English.aff)
381 "[A-Za-z]" "[^A-Za-z]" "[']" nil ("-B") nil nil)
382 ("american" ; make English explicitly selectable
383 "[A-Za-z]" "[^A-Za-z]" "[']" nil ("-B") nil nil)
7c5a1541 384 ("british" ; British version
f5136913
RS
385 "[A-Za-z]" "[^A-Za-z]" "[']" nil ("-B" "-d" "british") nil nil)
386 ("castellano" ; Spanish mode
387 "[A-Z\301\311\315\323\332\334\321a-z\341\351\355\363\372\374\361]"
388 "[^A-Z\301\311\315\323\332\334\321a-z\341\351\355\363\372\374\361]"
389 "[---]" nil ("-B" "-d" "castellano") "~tex" iso-latin-1)
390 ("castellano8" ; 8 bit Spanish mode
391 "[A-Z\301\311\315\323\332\334\321a-z\341\351\355\363\372\374\361]"
392 "[^A-Z\301\311\315\323\332\334\321a-z\341\351\355\363\372\374\361]"
393 "[---]" nil ("-B" "-d" "castellano") "~latin1" iso-latin-1)
394 ("czech"
395 "[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]"
396 "[^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]"
397 "" nil ("-B" "-d" "czech") nil iso-latin-2)
398 ("dansk" ; Dansk.aff
399 "[A-Z\306\330\305a-z\346\370\345]" "[^A-Z\306\330\305a-z\346\370\345]"
400 "[']" nil ("-C") nil iso-latin-1)
401 ("deutsch" ; Deutsch.aff
402 "[a-zA-Z\"]" "[^a-zA-Z\"]" "[']" t ("-C") "~tex" nil)
007852e0
RS
403 ("deutsch8"
404 "[a-zA-Z\304\326\334\344\366\337\374]"
405 "[^a-zA-Z\304\326\334\344\366\337\374]"
ef128a91 406 "[']" t ("-C" "-d" "deutsch") "~latin1" iso-latin-1)
f5136913
RS
407 ("english" ; make English explicitly selectable
408 "[A-Za-z]" "[^A-Za-z]" "[']" nil ("-B") nil nil))
313aaa0c 409 "First half of dictionary, shortened for loaddefs.el")
d38e5dbe
RS
410
411;;;###autoload
412(defvar ispell-dictionary-alist-2
f5136913
RS
413 '(("esperanto"
414 "[A-Za-z\246\254\266\274\306\330\335\336\346\370\375\376]"
415 "[^A-Za-z\246\254\266\274\306\330\335\336\346\370\375\376]"
416 "[-']" t ("-C") "~latin3" nil)
417 ("esperanto-tex"
418 "[A-Za-z^\\]" "[^A-Za-z^\\]" "[-'`\"]" t ("-C" "-d" "esperanto") "~tex"
419 nil)
e29702dd 420 ("francais7"
f5136913
RS
421 "[A-Za-z]" "[^A-Za-z]" "[`'^---]" t nil nil nil)
422 ("francais" ; Francais.aff
e29702dd
KH
423 "[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]"
424 "[^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]"
ef128a91 425 "[---']" t nil "~list" iso-latin-1)
f5136913 426 ("francais-tex" ; Francais.aff
e29702dd
KH
427 "[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\\]"
428 "[^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\\]"
ef128a91 429 "[---'^`\"]" t nil "~tex" iso-latin-1)
f5136913
RS
430 ("nederlands" ; Nederlands.aff
431 "[A-Za-z\300-\305\307\310-\317\322-\326\331-\334\340-\345\347\350-\357\361\362-\366\371-\374]"
432 "[^A-Za-z\300-\305\307\310-\317\322-\326\331-\334\340-\345\347\350-\357\361\362-\366\371-\374]"
433 "[']" t ("-C") nil iso-latin-1)
434 ("nederlands8" ; Dutch8.aff
435 "[A-Za-z\300-\305\307\310-\317\322-\326\331-\334\340-\345\347\350-\357\361\362-\366\371-\374]"
436 "[^A-Za-z\300-\305\307\310-\317\322-\326\331-\334\340-\345\347\350-\357\361\362-\366\371-\374]"
437 "[']" t ("-C") nil iso-latin-1)
438 ("norsk" ;8 bit Norwegian mode
439 "[A-Za-z\351\346\370\345\350\364\362\311\306\330\305\310\324\322]"
440 "[^A-Za-z\351\346\370\345\350\364\362\311\306\330\305\310\324\322]"
441 "[']" nil ("-C" "-d" "norsk") "~list" nil)
442 ("russian" ; russian.aff (KOI8-R charset)
443 "[\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]"
444 "[^\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]"
445 "[']" t ("-C" "-d" "russian") "~latin1" iso-latin-1)
446 ("svenska" ;7 bit Swedish mode
447 "[A-Za-z}{|\\133\\135\\\\]" "[^A-Za-z}{|\\133\\135\\\\]"
448 "[']" nil ("-C") nil nil)
449 ("svenska8" ;8 bit Swedish mode
450 "[A-Za-z\345\344\366\305\304\366]" "[^A-Za-z\345\344\366\305\304\366]"
451 "[']" nil ("-C" "-d" "svenska") "~list" ; Add `"-T" "list"' instead?
452 iso-latin-1))
313aaa0c 453 "Second half of dictionary, shortened for loaddefs.el")
d38e5dbe 454
f5136913
RS
455;;; The preparation of the menu bar menu must be autoloaded
456;;; because otherwise this file gets autoloaded every time Emacs starts
457;;; so that it can set up the menus and determine keyboard equivalents.
12e53d2e 458
d38e5dbe 459;;;###autoload
f5136913 460(defcustom ispell-dictionary-alist
d38e5dbe 461 (append ispell-dictionary-alist-1 ispell-dictionary-alist-2)
007852e0
RS
462 "An alist of dictionaries and their associated parameters.
463
464Each element of this list is also a list:
465
4b03da72 466\(DICTIONARY-NAME CASECHARS NOT-CASECHARS OTHERCHARS MANY-OTHERCHARS-P
f5136913 467 ISPELL-ARGS EXTENDED-CHARACTER-MODE CHARACTER-SET\)
007852e0 468
f5136913
RS
469DICTIONARY-NAME is a possible string value of variable `ispell-dictionary',
470nil means the default dictionary.
007852e0
RS
471
472CASECHARS is a regular expression of valid characters that comprise a
473word.
474
475NOT-CASECHARS is the opposite regexp of CASECHARS.
476
f5136913
RS
477OTHERCHARS is a regexp of characters in the NOT-CASECHARS set but which can be
478used to construct words in some special way. If OTHERCHARS characters follow
479and precede characters from CASECHARS, they are parsed as part of a word,
fbbd6e46 480otherwise they become word-breaks. As an example in English, assume the
f5136913 481regular expression \"[']\" for OTHERCHARS. Then \"they're\" and
fbbd6e46
RS
482\"Steven's\" are parsed as single words including the \"'\" character, but
483\"Stevens'\" does not include the quote character as part of the word.
f5136913 484If you want OTHERCHARS to be empty, use the empty string.
007852e0
RS
485Hint: regexp syntax requires the hyphen to be declared first here.
486
fbbd6e46
RS
487MANY-OTHERCHARS-P is non-nil when multiple OTHERCHARS are allowed in a word.
488Otherwise only a single OTHERCHARS character is allowed to be part of any
489single word.
007852e0
RS
490
491ISPELL-ARGS is a list of additional arguments passed to the ispell
492subprocess.
493
494EXTENDED-CHARACTER-MODE should be used when dictionaries are used which
e29702dd 495have been configured in an Ispell affix file. (For example, umlauts
007852e0 496can be encoded as \\\"a, a\\\", \"a, ...) Defaults are ~tex and ~nroff
a9210a53
RS
497in English. This has the same effect as the command-line `-T' option.
498The buffer Major Mode controls Ispell's parsing in tex or nroff mode,
007852e0
RS
499but the dictionary can control the extended character mode.
500Both defaults can be overruled in a buffer-local fashion. See
a9210a53 501`ispell-parsing-keyword' for details on this.
007852e0 502
f5136913
RS
503CHARACTER-SET used for languages with multibyte characters.
504
007852e0
RS
505Note that the CASECHARS and OTHERCHARS slots of the alist should
506contain the same character set as casechars and otherchars in the
f5136913
RS
507LANGUAGE.aff file \(e.g., english.aff\)."
508 :type '(repeat (list (choice :tag "Dictionary"
509 (string :tag "Dictionary name")
510 (const :tag "default" nil))
511 (regexp :tag "Case characters")
512 (regexp :tag "Non case characters")
513 (regexp :tag "Other characters")
514 (boolean :tag "Many other characters")
515 (repeat :tag "Ispell command line args"
516 (string :tag "Arg"))
517 (choice :tag "Extended character mode"
518 (const "~tex") (const "~list") (const "~nroff")
519 (const "~latin3") (const "~latin1")
520 (const :tag "default" nil))
521 (choice :tag "Character set"
522 (const iso-latin-1)
523 (const iso-latin-2)
524 (const :tag "default" nil))))
525 :group 'ispell)
526
007852e0 527
d38e5dbe 528;;;###autoload
e29702dd 529(defvar ispell-menu-map nil "Key map for ispell menu")
007852e0 530
d38e5dbe 531;;;###autoload
f5136913
RS
532(defvar ispell-menu-xemacs nil
533 "Spelling menu for XEmacs.
534If nil when package is loaded, a standard menu will be set,
535and added as a submenu of the \"Edit\" menu.")
e29702dd 536
f5136913 537;;; Break out XEmacs menu and split into several calls to avoid having
e29702dd 538;;; long lines in loaddefs.el. Detect need off following constant.
12e53d2e 539
f5136913 540;;; Set up dictionary
d38e5dbe 541;;;###autoload
f5136913
RS
542(defconst ispell-menu-map-needed
543 ;; only needed when not version 18 and not XEmacs.
e29702dd 544 (and (not ispell-menu-map)
f5136913
RS
545 (not (string-match "18\\.[0-9]+\\.[0-9]+" emacs-version))
546 (not (string-match "Lucid\\|XEmacs" emacs-version))))
e29702dd 547
d38e5dbe 548;;;###autoload
12e53d2e
RS
549(if ispell-menu-map-needed
550 (let ((dicts (reverse (cons (cons "default" nil) ispell-dictionary-alist)))
551 name)
12e53d2e 552 (setq ispell-menu-map (make-sparse-keymap "Spell"))
e29702dd 553 ;; add the dictionaries to the bottom of the list.
12e53d2e
RS
554 (while dicts
555 (setq name (car (car dicts))
556 dicts (cdr dicts))
557 (if (stringp name)
558 (define-key ispell-menu-map (vector (intern name))
559 (cons (concat "Select " (capitalize name))
560 (list 'lambda () '(interactive)
561 (list 'ispell-change-dictionary name))))))))
562
e29702dd 563;;; define commands in menu in opposite order you want them to appear.
d38e5dbe 564;;;###autoload
12e53d2e
RS
565(if ispell-menu-map-needed
566 (progn
12e53d2e
RS
567 (define-key ispell-menu-map [ispell-change-dictionary]
568 '("Change Dictionary" . ispell-change-dictionary))
569 (define-key ispell-menu-map [ispell-kill-ispell]
570 '("Kill Process" . ispell-kill-ispell))
571 (define-key ispell-menu-map [ispell-pdict-save]
1335d078 572 '("Save Dictionary" . (lambda () (interactive) (ispell-pdict-save t t))))
12e53d2e
RS
573 (define-key ispell-menu-map [ispell-complete-word]
574 '("Complete Word" . ispell-complete-word))
575 (define-key ispell-menu-map [ispell-complete-word-interior-frag]
576 '("Complete Word Frag" . ispell-complete-word-interior-frag))))
577
d38e5dbe 578;;;###autoload
12e53d2e
RS
579(if ispell-menu-map-needed
580 (progn
581 (define-key ispell-menu-map [ispell-continue]
582 '("Continue Check" . ispell-continue))
12e53d2e
RS
583 (define-key ispell-menu-map [ispell-word]
584 '("Check Word" . ispell-word))
f5136913
RS
585 (define-key ispell-menu-map [ispell-comments-and-strings]
586 '("Check Comments" . ispell-comments-and-strings))
81b328e5
KH
587 (define-key ispell-menu-map [ispell-region]
588 '("Check Region" . ispell-region))
12e53d2e 589 (define-key ispell-menu-map [ispell-buffer]
60d48874
RS
590 '("Check Buffer" . ispell-buffer))))
591
d38e5dbe 592;;;###autoload
60d48874
RS
593(if ispell-menu-map-needed
594 (progn
12e53d2e
RS
595 (define-key ispell-menu-map [ispell-message]
596 '("Check Message" . ispell-message))
597 (define-key ispell-menu-map [ispell-help]
e29702dd 598 ;; use (x-popup-menu last-nonmenu-event(list "" ispell-help-list)) ?
12e53d2e 599 '("Help" . (lambda () (interactive) (describe-function 'ispell-help))))
e29702dd
KH
600 (put 'ispell-region 'menu-enable 'mark-active)
601 (fset 'ispell-menu-map (symbol-value 'ispell-menu-map))))
602
f5136913
RS
603;;; XEmacs version 19 & 20
604(if (and (not (string-match "18\\.[0-9]+\\.[0-9]+" emacs-version))
605 (string-match "Lucid\\|XEmacs" emacs-version)
606 (featurep 'menubar)
607 (null ispell-menu-xemacs)
608 (not (and (boundp 'infodock-version) infodock-version)))
e29702dd
KH
609 (let ((dicts (cons (cons "default" nil) ispell-dictionary-alist))
610 (current-menubar (or current-menubar default-menubar))
611 (menu
612 '(["Help" (describe-function 'ispell-help) t]
613 ;;["Help" (popup-menu ispell-help-list) t]
614 ["Check Message" ispell-message t]
615 ["Check Buffer" ispell-buffer t]
f5136913 616 ["Check Comments" ispell-comments-and-strings t]
e29702dd
KH
617 ["Check Word" ispell-word t]
618 ["Check Region" ispell-region (or (not zmacs-regions) (mark))]
619 ["Continue Check" ispell-continue t]
620 ["Complete Word Frag"ispell-complete-word-interior-frag t]
621 ["Complete Word" ispell-complete-word t]
622 ["Kill Process" ispell-kill-ispell t]
623 "-"
1335d078 624 ["Save Dictionary" (ispell-pdict-save t t) t]
e29702dd
KH
625 ["Change Dictionary" ispell-change-dictionary t]))
626 name)
627 (while dicts
628 (setq name (car (car dicts))
629 dicts (cdr dicts))
630 (if (stringp name)
631 (setq menu (append menu
632 (list
f5136913
RS
633 (vector (concat "Select " (capitalize name))
634 (list 'ispell-change-dictionary name)
635 t))))))
636 (setq ispell-menu-xemacs menu)
e29702dd
KH
637 (if current-menubar
638 (progn
639 (delete-menu-item '("Edit" "Spell")) ; in case already defined
f5136913
RS
640 (add-menu '("Edit") "Spell" ispell-menu-xemacs)))))
641
642;;; Allow incrementing characters as integers in XEmacs 20
643(if (and (string-match "XEmacs" emacs-version)
644 (fboundp 'int-char))
645 (fset 'ispell-int-char 'int-char)
646 ;; Emacs and XEmacs 19 or earlier
647 (fset 'ispell-int-char 'identity))
007852e0
RS
648
649
650;;; **********************************************************************
651;;; The following are used by ispell, and should not be changed.
652;;; **********************************************************************
653
654
e29702dd 655;;; The version must be 3.1 or greater for this version of ispell.el
8ce8687e 656;;; There is an incompatibility between version 3.1.12 and lower versions.
e29702dd 657(defconst ispell-required-version '("3.1." 12)
007852e0 658 "Ispell versions with which this version of ispell.el is known to work.")
f5136913 659(defvar ispell-offset -1
e29702dd 660 "Offset that maps protocol differences between ispell 3.1 versions.")
007852e0 661
f5136913
RS
662;;; This variable contains the current dictionary being used if the ispell
663;;; process is running. Otherwise it contains the global default.
664(defvar ispell-dictionary nil
665 "The name of the current dictionary, or nil for the default.
666When `ispell-local-dictionary' is nil, `ispell-dictionary' is used to select
667the dictionary for new buffers.
668
669This is passed to the ispell process using the `-d' switch and is
670used as key in `ispell-dictionary-alist' (which see).")
671
ef128a91 672(defun ispell-decode-string (str)
f5136913
RS
673 "Decodes multibyte character strings."
674 (if (and (boundp 'enable-multibyte-characters)
675 (fboundp 'decode-coding-string)
676 enable-multibyte-characters
677 (ispell-get-coding-system))
678 (decode-coding-string str (ispell-get-coding-system))
679 str))
ef128a91 680
007852e0 681(defun ispell-get-casechars ()
ef128a91
KH
682 (ispell-decode-string
683 (nth 1 (assoc ispell-dictionary ispell-dictionary-alist))))
007852e0 684(defun ispell-get-not-casechars ()
ef128a91
KH
685 (ispell-decode-string
686 (nth 2 (assoc ispell-dictionary ispell-dictionary-alist))))
007852e0 687(defun ispell-get-otherchars ()
ef128a91
KH
688 (ispell-decode-string
689 (nth 3 (assoc ispell-dictionary ispell-dictionary-alist))))
007852e0
RS
690(defun ispell-get-many-otherchars-p ()
691 (nth 4 (assoc ispell-dictionary ispell-dictionary-alist)))
692(defun ispell-get-ispell-args ()
693 (nth 5 (assoc ispell-dictionary ispell-dictionary-alist)))
694(defun ispell-get-extended-character-mode ()
695 (nth 6 (assoc ispell-dictionary ispell-dictionary-alist)))
ef128a91
KH
696(defun ispell-get-coding-system ()
697 (nth 7 (assoc ispell-dictionary ispell-dictionary-alist)))
007852e0
RS
698
699(defvar ispell-process nil
a9210a53 700 "The process object for Ispell.")
007852e0
RS
701
702(defvar ispell-pdict-modified-p nil
a9210a53 703 "Non-nil means personal dictionary has modifications to be saved.")
007852e0
RS
704
705;;; If you want to save the dictionary when quitting, must do so explicitly.
e29702dd
KH
706;;; When non-nil, the spell session is terminated.
707;;; When numeric, contains cursor location in buffer, and cursor remains there.
a9210a53 708(defvar ispell-quit nil)
007852e0
RS
709
710(defvar ispell-filter nil
a9210a53 711 "Output filter from piped calls to Ispell.")
007852e0
RS
712
713(defvar ispell-filter-continue nil
a9210a53 714 "Control variable for Ispell filter function.")
007852e0
RS
715
716(defvar ispell-process-directory nil
a9210a53 717 "The directory where `ispell-process' was started.")
007852e0
RS
718
719(defvar ispell-query-replace-marker (make-marker)
a9210a53 720 "Marker for `query-replace' processing.")
007852e0 721
f5136913
RS
722(defvar ispell-recursive-edit-marker (make-marker)
723 "Marker for return point from recursive edit.")
724
007852e0
RS
725(defvar ispell-checking-message nil
726 "Non-nil when we're checking a mail message")
727
728(defconst ispell-choices-buffer "*Choices*")
729
a9210a53 730(defvar ispell-overlay nil "Overlay variable for Ispell highlighting.")
007852e0
RS
731
732;;; *** Buffer Local Definitions ***
733
f5136913 734(defconst ispell-words-keyword "LocalWords: "
007852e0
RS
735 "The keyword for local oddly-spelled words to accept.
736The keyword will be followed by any number of local word spellings.
737There can be multiple of these keywords in the file.")
738
739(defconst ispell-dictionary-keyword "Local IspellDict: "
f5136913
RS
740 "The keyword for a local dictionary to use.
741The keyword must be followed by a correct dictionary name in
742`ispell-dictionary-alist'. When multiple occurrences exist, the last keyword
743definition is used.")
744
745(defconst ispell-pdict-keyword "Local IspellPersDict: "
746 "The keyword for defining buffer local dictionaries.
747Keyword must be followed by the filename of a personal dictionary.
748The last occurring definition in the buffer will be used.")
007852e0
RS
749
750(defconst ispell-parsing-keyword "Local IspellParsing: "
a9210a53 751 "The keyword for overriding default Ispell parsing.
007852e0
RS
752The above keyword string should be followed by `latex-mode' or
753`nroff-mode' to put the current buffer into the desired parsing mode.
754
755Extended character mode can be changed for this buffer by placing
f5136913
RS
756a `~' followed by an extended-character mode -- such as `~.tex'.
757The last occurring definition in the buffer will be used.")
758
759;;;###autoload
760(defvar ispell-skip-region-alist
761 '((ispell-words-keyword forward-line)
762 (ispell-dictionary-keyword forward-line)
763 (ispell-pdict-keyword forward-line)
764 (ispell-parsing-keyword forward-line)
765 ("^---*BEGIN PGP [A-Z ]*--*" . "^---*END PGP [A-Z ]*--*")
766 ("^---* \\(Start of \\)?[Ff]orwarded [Mm]essage" . "^---* End of [Ff]orwarded [Mm]essage")
767 ;; matches e-mail addresses, file names, http addresses, etc.
768 ("\\(/\\|\\(\\(\\w\\|-\\)+[.:@]\\)\\)\\(\\w\\|-\\)*\\([.:/@]+\\(\\w\\|-\\|~\\)+\\)+")
769 ;; This is a pretty complex regexp. It can be simplified to the following:
770 ;; "\\(\\w\\|-\\)*\\([.:/@]+\\(\\w\\|-\\|~\\)+\\)+"
771 ;; but some valid text will be skipped, e.g. "his/herr". This could be
772 ;; fixed up (at the expense of a moderately more complex regexp)
773 ;; by not allowing "/" to be the character which triggers the
774 ;; identification of the computer name, e.g.:
775 ;; "\\(\\w\\|-\\)+[.:@]\\(\\w\\|-\\)*\\([.:/@]+\\(\\w\\|-\\|~\\)+\\)+"
776 )
94487c4e 777 "Alist expressing beginning and end of regions not to spell check.
f5136913
RS
778The alist key must be a regular expression.
779Valid forms include:
780 (KEY) - just skip the key.
94487c4e 781 (KEY . REGEXP) - skip to the end of REGEXP. REGEXP may be string or symbol.
f5136913 782 (KEY REGEXP) - skip to end of REGEXP. REGEXP must be a string.
94487c4e 783 (KEY FUNCTION ARGS) - FUNCTION called with ARGS returns end of region.")
f5136913 784
007852e0 785
f5136913
RS
786
787;;;###autoload
788(defvar ispell-tex-skip-alists
789 '((("%\\[" . "%\\]")
790 ;; All the standard LaTeX keywords from L. Lamport's guide:
791 ;; \cite, \hspace, \hspace*, \hyphenation, \include, \includeonly, \input,
792 ;; \label, \nocite, \rule (in ispell - rest included here)
793 ("\\\\addcontentsline" ispell-tex-arg-end 2)
794 ("\\\\add\\(tocontents\\|vspace\\)" ispell-tex-arg-end)
795 ("\\\\\\([aA]lph\\|arabic\\)" ispell-tex-arg-end)
796 ("\\\\author" ispell-tex-arg-end)
797 ("\\\\bibliographystyle" ispell-tex-arg-end)
798 ("\\\\makebox" ispell-tex-arg-end 0)
799 ;;("\\\\epsfig" ispell-tex-arg-end)
800 ("\\\\document\\(class\\|style\\)" .
801 "\\\\begin[ \t\n]*{[ \t\n]*document[ \t\n]*}"))
802 (;; delimited with \begin. In ispell: displaymath, eqnarray, eqnarray*,
803 ;; equation, minipage, picture, tabular, tabular* (ispell)
804 ("\\(figure\\|table\\)\\*?" ispell-tex-arg-end 0)
805 ("list" ispell-tex-arg-end 2)
806 ("program" . "\\\\end[ \t\n]*{[ \t\n]*program[ \t\n]*}")
807 ("verbatim\\*?" . "\\\\end[ \t\n]*{[ \t\n]*verbatim\\*?[ \t\n]*}")))
808 "*Lists of regions to be skipped in TeX mode.
809First list is used raw.
810Second list has key placed inside \\begin{}.
811
812Delete or add any regions you want to be automatically selected
813for skipping in latex mode.")
814
815
816(defcustom ispell-skip-sgml 'use-mode-name
817 "*Indicates whether ispell should skip spell checking of SGML markup.
818If t, always skip SGML markup; if nil, never skip; if non-t and non-nil,
819guess whether SGML markup should be skipped according to the name of the
820buffer's major mode."
821 :type '(choice (const use-mode-name) (const t) (const nil))
822 :group 'ispell)
1335d078 823
007852e0 824(defvar ispell-local-pdict ispell-personal-dictionary
4b03da72 825 "A buffer local variable containing the current personal dictionary.
a9210a53 826If non-nil, the value must be a string, which is a file name.
4b03da72 827
a9210a53
RS
828If you specify a personal dictionary for the current buffer which is
829different from the current personal dictionary, the effect is similar
830to calling \\[ispell-change-dictionary]. This variable is automatically
831set when defined in the file with either `ispell-pdict-keyword' or the
832local variable syntax.")
007852e0
RS
833
834(make-variable-buffer-local 'ispell-local-pdict)
835
007852e0
RS
836(defvar ispell-buffer-local-name nil
837 "Contains the buffer name if local word definitions were used.
838Ispell is then restarted because the local words could conflict.")
839
840(defvar ispell-parser 'use-mode-name
841 "*Indicates whether ispell should parse the current buffer as TeX Code.
a9210a53 842Special value `use-mode-name' tries to guess using the name of major-mode.
f5136913
RS
843Default parser is `nroff'.
844Currently the only other valid parser is `tex'.
007852e0
RS
845
846You can set this variable in hooks in your init file -- eg:
847
e29702dd 848(add-hook 'tex-mode-hook (function (lambda () (setq ispell-parser 'tex))))")
007852e0
RS
849
850(defvar ispell-region-end (make-marker)
851 "Marker that allows spelling continuations.")
852
0349bab6
RS
853(defvar ispell-check-only nil
854 "If non-nil, `ispell-word' does not try to correct the word.")
007852e0 855
e29702dd 856
007852e0
RS
857;;; **********************************************************************
858;;; **********************************************************************
859
860
f5136913
RS
861
862(and (not (string-match "18\\.[0-9]+\\.[0-9]+" emacs-version))
1335d078
RS
863 (not (boundp 'epoch::version))
864 (defalias 'ispell 'ispell-buffer))
4b03da72 865
f5136913
RS
866(if (not (fboundp 'buffer-substring-no-properties))
867 (defun buffer-substring-no-properties (start end)
868 (buffer-substring start end)))
869
8ce8687e 870;;;###autoload
a9e5664e 871(define-key esc-map "$" 'ispell-word)
a870f917 872
007852e0 873;;;###autoload
9e7ad89a 874(defun ispell-word (&optional following quietly continue)
007852e0 875 "Check spelling of word under or before the cursor.
a9210a53 876If the word is not found in dictionary, display possible corrections
e29702dd 877in a window allowing you to choose one.
a9210a53 878
4b03da72 879With a prefix argument (or if CONTINUE is non-nil),
9e7ad89a 880resume interrupted spell-checking of a buffer or region.
a9210a53 881
4b03da72 882If optional argument FOLLOWING is non-nil or if `ispell-following-word'
007852e0 883is non-nil when called interactively, then the following word
3ee3ac77 884\(rather than preceding\) is checked when the cursor is not over a word.
4b03da72 885When the optional argument QUIETLY is non-nil or `ispell-quietly' is non-nil
007852e0
RS
886when called interactively, non-corrective messages are suppressed.
887
4b03da72 888Word syntax described by `ispell-dictionary-alist' (which see).
007852e0
RS
889
890This will check or reload the dictionary. Use \\[ispell-change-dictionary]
3ee3ac77 891or \\[ispell-region] to update the Ispell process."
9e7ad89a
RS
892 (interactive (list nil nil current-prefix-arg))
893 (if continue
894 (ispell-continue)
895 (if (interactive-p)
896 (setq following ispell-following-word
897 quietly ispell-quietly))
e29702dd 898 (ispell-accept-buffer-local-defs) ; use the correct dictionary
9e7ad89a 899 (let ((cursor-location (point)) ; retain cursor location
9e7ad89a 900 (word (ispell-get-word following))
f5136913
RS
901 start end poss new-word replace)
902 ;; De-structure return word info list.
903 (setq start (car (cdr word))
904 end (car (cdr (cdr word)))
905 word (car word))
906
907 ;; now check spelling of word if it has 3 or more characters.
908 (when (> (length word) 2)
909f0455
RS
909 (or quietly
910 (message "Checking spelling of %s..."
911 (funcall ispell-format-word word)))
912 (process-send-string ispell-process "%\n") ;put in verbose mode
913 (process-send-string ispell-process (concat "^" word "\n"))
914 ;; wait until ispell has processed word
915 (while (progn
916 (accept-process-output ispell-process)
917 (not (string= "" (car ispell-filter)))))
918 ;;(process-send-string ispell-process "!\n") ;back to terse mode.
f5136913 919 (setq ispell-filter (cdr ispell-filter)) ; remove extra \n
909f0455
RS
920 (if (listp ispell-filter)
921 (setq poss (ispell-parse-output (car ispell-filter))))
922 (cond ((eq poss t)
923 (or quietly
f5136913
RS
924 (message "%s is correct"
925 (funcall ispell-format-word word))))
909f0455
RS
926 ((stringp poss)
927 (or quietly
928 (message "%s is correct because of root %s"
929 (funcall ispell-format-word word)
930 (funcall ispell-format-word poss))))
931 ((null poss) (message "Error in ispell process"))
932 (ispell-check-only ; called from ispell minor mode.
f5136913
RS
933 (beep)
934 (message "%s is incorrect" (funcall ispell-format-word word)))
909f0455
RS
935 (t ; prompt for correct word.
936 (save-window-excursion
937 (setq replace (ispell-command-loop
938 (car (cdr (cdr poss)))
939 (car (cdr (cdr (cdr poss))))
940 (car poss) start end)))
941 (cond ((equal 0 replace)
942 (ispell-add-per-file-word-list (car poss)))
943 (replace
f5136913 944 (setq new-word (if (atom replace) replace (car replace))
909f0455
RS
945 cursor-location (+ (- (length word) (- end start))
946 cursor-location))
f5136913 947 (if (not (equal new-word (car poss)))
909f0455
RS
948 (progn
949 (delete-region start end)
f5136913
RS
950 (setq start (point))
951 (insert new-word)
952 (setq end (point))))
953 (if (not (atom replace)) ;recheck spelling of replacement
909f0455 954 (progn
f5136913
RS
955 (if (car (cdr replace)) ; query replace requested
956 (save-window-excursion
957 (query-replace word new-word t)))
958 (ispell-region start end)))))
909f0455
RS
959 (if (get-buffer ispell-choices-buffer)
960 (kill-buffer ispell-choices-buffer))))
961 (goto-char cursor-location) ; return to original location
962 (ispell-pdict-save ispell-silently-savep)
963 (if ispell-quit (setq ispell-quit nil))))))
007852e0
RS
964
965
966(defun ispell-get-word (following &optional extra-otherchars)
967 "Return the word for spell-checking according to ispell syntax.
3ee3ac77 968If optional argument FOLLOWING is non-nil or if `ispell-following-word'
007852e0 969is non-nil when called interactively, then the following word
e29702dd 970\(rather than preceding\) is checked when the cursor is not over a word.
4b03da72 971Optional second argument contains otherchars that can be included in word
007852e0
RS
972many times.
973
4b03da72 974Word syntax described by `ispell-dictionary-alist' (which see)."
007852e0
RS
975 (let* ((ispell-casechars (ispell-get-casechars))
976 (ispell-not-casechars (ispell-get-not-casechars))
977 (ispell-otherchars (ispell-get-otherchars))
978 (ispell-many-otherchars-p (ispell-get-many-otherchars-p))
979 (word-regexp (concat ispell-casechars
980 "+\\("
f5136913
RS
981 (if (not (string= "" ispell-otherchars))
982 (concat ispell-otherchars "?"))
007852e0
RS
983 (if extra-otherchars
984 (concat extra-otherchars "?"))
985 ispell-casechars
986 "+\\)"
987 (if (or ispell-many-otherchars-p
988 extra-otherchars)
989 "*" "?")))
f5136913 990 did-it-once prevpt
007852e0
RS
991 start end word)
992 ;; find the word
993 (if (not (looking-at ispell-casechars))
994 (if following
995 (re-search-forward ispell-casechars (point-max) t)
996 (re-search-backward ispell-casechars (point-min) t)))
997 ;; move to front of word
998 (re-search-backward ispell-not-casechars (point-min) 'start)
f5136913
RS
999 (while (and (or (and (not (string= "" ispell-otherchars))
1000 (looking-at ispell-otherchars))
007852e0
RS
1001 (and extra-otherchars (looking-at extra-otherchars)))
1002 (not (bobp))
1003 (or (not did-it-once)
f5136913
RS
1004 ispell-many-otherchars-p)
1005 (not (eq prevpt (point))))
007852e0
RS
1006 (if (and extra-otherchars (looking-at extra-otherchars))
1007 (progn
1008 (backward-char 1)
1009 (if (looking-at ispell-casechars)
1010 (re-search-backward ispell-not-casechars (point-min) 'move)))
f5136913
RS
1011 (setq did-it-once t
1012 prevpt (point))
007852e0
RS
1013 (backward-char 1)
1014 (if (looking-at ispell-casechars)
1015 (re-search-backward ispell-not-casechars (point-min) 'move)
1016 (backward-char -1))))
1017 ;; Now mark the word and save to string.
909f0455
RS
1018 (if (not (re-search-forward word-regexp (point-max) t))
1019 (if ispell-check-only
f5136913 1020 ;; return dummy word when just flagging misspellings
909f0455
RS
1021 (list "" (point) (point))
1022 (error "No word found to check!"))
1023 (setq start (match-beginning 0)
1024 end (point)
1025 word (buffer-substring-no-properties start end))
1026 (list word start end))))
007852e0
RS
1027
1028
1029;;; Global ispell-pdict-modified-p is set by ispell-command-loop and
1030;;; tracks changes in the dictionary. The global may either be
1031;;; a value or a list, whose value is the state of whether the
1032;;; dictionary needs to be saved.
1033
f5136913 1034;;; ###autoload
007852e0
RS
1035(defun ispell-pdict-save (&optional no-query force-save)
1036 "Check to see if the personal dictionary has been modified.
3ee3ac77 1037If so, ask if it needs to be saved."
007852e0
RS
1038 (interactive (list ispell-silently-savep t))
1039 (if (and ispell-pdict-modified-p (listp ispell-pdict-modified-p))
1040 (setq ispell-pdict-modified-p (car ispell-pdict-modified-p)))
1041 (if (or ispell-pdict-modified-p force-save)
1042 (if (or no-query (y-or-n-p "Personal dictionary modified. Save? "))
1335d078
RS
1043 (progn
1044 (process-send-string ispell-process "#\n")
1045 (message "Personal dictionary saved."))))
007852e0
RS
1046 ;; unassert variable, even if not saved to avoid questioning.
1047 (setq ispell-pdict-modified-p nil))
1048
1049
29aec366 1050(defun ispell-command-loop (miss guess word start end)
007852e0
RS
1051 "Display possible corrections from list MISS.
1052GUESS lists possibly valid affix construction of WORD.
1053Returns nil to keep word.
4b03da72
RS
1054Returns 0 to insert locally into buffer-local dictionary.
1055Returns string for new chosen word.
1056Returns list for new replacement word (will be rechecked).
f5136913
RS
1057 Query-replace when list length is 2.
1058 Automatic query-replace when second element is `query-replace'.
29aec366 1059Highlights the word, which is assumed to run from START to END.
3ee3ac77
RS
1060Global `ispell-pdict-modified-p' becomes a list where the only value
1061indicates whether the dictionary has been modified when option `a' or `i' is
f5136913
RS
1062used.
1063Global `ispell-quit' set to start location to continue spell session."
e29702dd
KH
1064 (let ((textbuf (current-buffer))
1065 (count ?0)
1066 (line 2)
1067 (max-lines (- (window-height) 4)) ; assure 4 context lines.
1068 (choices miss)
1069 (window-min-height (min window-min-height
1070 ispell-choices-win-default-height))
1071 (command-characters '( ? ?i ?a ?A ?r ?R ?? ?x ?X ?q ?l ?u ?m ))
8896f22d 1072 (dedicated (window-dedicated-p (selected-window)))
f5136913
RS
1073 (skipped 0)
1074 char num result textwin dedicated-win highlighted)
e29702dd
KH
1075
1076 ;; setup the *Choices* buffer with valid data.
1077 (save-excursion
1078 (set-buffer (get-buffer-create ispell-choices-buffer))
8ce8687e 1079 (setq mode-line-format (concat "-- %b -- word: " word))
f5136913
RS
1080 (and (fboundp 'set-specifier) ; prevent XEmacs modeline hiding
1081 (set-specifier has-modeline-p (cons (current-buffer) nil)))
e29702dd
KH
1082 (erase-buffer)
1083 (if guess
1084 (progn
1085 (insert "Affix rules generate and capitalize "
1086 "this word as shown below:\n\t")
1087 (while guess
1088 (if (> (+ 4 (current-column) (length (car guess)))
1089 (window-width))
1090 (progn
1091 (insert "\n\t")
1092 (setq line (1+ line))))
1093 (insert (car guess) " ")
1094 (setq guess (cdr guess)))
1095 (insert "\nUse option `i' if this is a correct composition"
1096 " from the derivative root.\n")
1097 (setq line (+ line (if choices 3 2)))))
1098 (while (and choices
1099 (< (if (> (+ 7 (current-column) (length (car choices))
1100 (if (> count ?~) 3 0))
1101 (window-width))
1102 (progn
1103 (insert "\n")
1104 (setq line (1+ line)))
1105 line)
1106 max-lines))
1107 ;; not so good if there are over 20 or 30 options, but then, if
1108 ;; there are that many you don't want to scan them all anyway...
1109 (while (memq count command-characters) ; skip command characters.
f5136913 1110 (setq count (ispell-int-char (1+ count))
e29702dd
KH
1111 skipped (1+ skipped)))
1112 (insert "(" count ") " (car choices) " ")
1113 (setq choices (cdr choices)
f5136913
RS
1114 count (ispell-int-char (1+ count))))
1115 (setq count (ispell-int-char (- count ?0 skipped))))
e29702dd
KH
1116
1117 ;; Assure word is visible
1118 (if (not (pos-visible-in-window-p end))
1119 (sit-for 0))
f5136913
RS
1120
1121 ;; allow temporary split of dedicated windows...
1122 (if dedicated
1123 (progn
1124 (setq dedicated-win (selected-window))
1125 (set-window-dedicated-p dedicated-win nil)))
1126
e29702dd 1127 ;; Display choices for misspelled word.
f5136913 1128 (ispell-show-choices line end)
e29702dd
KH
1129
1130 (select-window (setq textwin (next-window)))
1131
1132 ;; highlight word, protecting current buffer status
29aec366 1133 (unwind-protect
e29702dd 1134 (progn
f5136913
RS
1135 (and ispell-highlight-p
1136 (ispell-highlight-spelling-error start end t))
e29702dd 1137 ;; Loop until a valid choice is made.
29aec366
RS
1138 (while
1139 (eq
1140 t
1141 (setq
1142 result
1143 (progn
1144 (undo-boundary)
ab9d539c
KH
1145 (let (message-log-max)
1146 (message (concat "C-h or ? for more options; SPC to leave "
1147 "unchanged, Character to replace word")))
29aec366
RS
1148 (let ((inhibit-quit t))
1149 (setq char (if (fboundp 'read-char-exclusive)
1150 (read-char-exclusive)
1151 (read-char))
1152 skipped 0)
1153 (if (or quit-flag (= char ?\C-g)) ; C-g is like typing X
1154 (setq char ?X
1155 quit-flag nil)))
1156 ;; Adjust num to array offset skipping command characters.
1157 (let ((com-chars command-characters))
1158 (while com-chars
1159 (if (and (> (car com-chars) ?0) (< (car com-chars) char))
1160 (setq skipped (1+ skipped)))
1161 (setq com-chars (cdr com-chars)))
1162 (setq num (- char ?0 skipped)))
1163
1164 (cond
e29702dd 1165 ((= char ? ) nil) ; accept word this time only
29aec366
RS
1166 ((= char ?i) ; accept and insert word into pers dict
1167 (process-send-string ispell-process (concat "*" word "\n"))
1168 (setq ispell-pdict-modified-p '(t)) ; dictionary modified!
1169 nil)
1170 ((or (= char ?a) (= char ?A)) ; accept word without insert
1171 (process-send-string ispell-process (concat "@" word "\n"))
1172 (if (null ispell-pdict-modified-p)
1173 (setq ispell-pdict-modified-p
1174 (list ispell-pdict-modified-p)))
1175 (if (= char ?A) 0)) ; return 0 for ispell-add buffer-local
1176 ((or (= char ?r) (= char ?R)) ; type in replacement
f5136913
RS
1177 (and (eq 'block ispell-highlight-p) ; refresh tty's
1178 (ispell-highlight-spelling-error start end nil t))
1179 (let ((result
1180 (if (or (= char ?R) ispell-query-replace-choices)
1181 (list (read-string "Query-replacement for: "
1182 word) t)
1183 (cons (read-string "Replacement for: " word)
1184 nil))))
1185 (and (eq 'block ispell-highlight-p)
1186 (ispell-highlight-spelling-error start end nil
1187 'block))
1188 result))
29aec366 1189 ((or (= char ??) (= char help-char) (= char ?\C-h))
f5136913
RS
1190 (and (eq 'block ispell-highlight-p)
1191 (ispell-highlight-spelling-error start end nil t))
29aec366 1192 (ispell-help)
f5136913
RS
1193 (and (eq 'block ispell-highlight-p)
1194 (ispell-highlight-spelling-error start end nil
1195 'block))
29aec366
RS
1196 t)
1197 ;; Quit and move point back.
1198 ((= char ?x)
1199 (ispell-pdict-save ispell-silently-savep)
1200 (message "Exited spell-checking")
1201 (setq ispell-quit t)
1202 nil)
1203 ;; Quit and preserve point.
1204 ((= char ?X)
1205 (ispell-pdict-save ispell-silently-savep)
10ba4783 1206 (message "%s"
29aec366
RS
1207 (substitute-command-keys
1208 (concat "Spell-checking suspended;"
1209 " use C-u \\[ispell-word] to resume")))
f5136913 1210 (setq ispell-quit start)
29aec366
RS
1211 nil)
1212 ((= char ?q)
1213 (if (y-or-n-p "Really kill Ispell process? ")
1214 (progn
1215 (ispell-kill-ispell t) ; terminate process.
1216 (setq ispell-quit (or (not ispell-checking-message)
1217 (point))
1218 ispell-pdict-modified-p nil))
e29702dd 1219 t)) ; continue if they don't quit.
29aec366 1220 ((= char ?l)
f5136913
RS
1221 (and (eq 'block ispell-highlight-p) ; refresh tty displays
1222 (ispell-highlight-spelling-error start end nil t))
29aec366
RS
1223 (let ((new-word (read-string
1224 "Lookup string (`*' is wildcard): "
1225 word))
1226 (new-line 2))
1227 (if new-word
007852e0 1228 (progn
29aec366
RS
1229 (save-excursion
1230 (set-buffer (get-buffer-create
1231 ispell-choices-buffer))
1232 (erase-buffer)
1233 (setq count ?0
1234 skipped 0
8ce8687e
RS
1235 mode-line-format (concat
1236 "-- %b -- word: "
1237 new-word)
29aec366
RS
1238 miss (lookup-words new-word)
1239 choices miss)
1240 (while (and choices ; adjust choices window.
1241 (< (if (> (+ 7 (current-column)
1242 (length (car choices))
1243 (if (> count ?~) 3 0))
1244 (window-width))
1245 (progn
1246 (insert "\n")
1247 (setq new-line
1248 (1+ new-line)))
1249 new-line)
1250 max-lines))
1251 (while (memq count command-characters)
f5136913 1252 (setq count (ispell-int-char (1+ count))
29aec366
RS
1253 skipped (1+ skipped)))
1254 (insert "(" count ") " (car choices) " ")
1255 (setq choices (cdr choices)
f5136913
RS
1256 count (ispell-int-char (1+ count))))
1257 (setq count (ispell-int-char
1258 (- count ?0 skipped))))
29aec366 1259 (select-window (previous-window))
1335d078
RS
1260 (if (and (/= new-line line)
1261 (> (max line new-line)
1262 ispell-choices-win-default-height))
1263 (let* ((minh ispell-choices-win-default-height)
1264 (gr-bl (if (< line minh) ; blanks
1265 (- minh line)
1266 0))
1267 (shr-bl (if (< new-line minh) ; blanks
1268 (- minh new-line)
1269 0)))
29aec366 1270 (if (> new-line line)
1335d078
RS
1271 (enlarge-window (- new-line line gr-bl))
1272 (shrink-window (- line new-line shr-bl)))
29aec366
RS
1273 (setq line new-line)))
1274 (select-window (next-window)))))
f5136913
RS
1275 (and (eq 'block ispell-highlight-p)
1276 (ispell-highlight-spelling-error start end nil
1277 'block))
29aec366
RS
1278 t) ; reselect from new choices
1279 ((= char ?u)
1280 (process-send-string ispell-process
1281 (concat "*" (downcase word) "\n"))
1282 (setq ispell-pdict-modified-p '(t)) ; dictionary modified!
1283 nil)
1284 ((= char ?m) ; type in what to insert
1285 (process-send-string
1286 ispell-process (concat "*" (read-string "Insert: " word)
1287 "\n"))
1288 (setq ispell-pdict-modified-p '(t))
1289 (cons word nil))
1290 ((and (>= num 0) (< num count))
1291 (if ispell-query-replace-choices ; Query replace flag
1292 (list (nth num miss) 'query-replace)
1293 (nth num miss)))
1294 ((= char ?\C-l)
1295 (redraw-display) t)
1296 ((= char ?\C-r)
f5136913
RS
1297 (if (marker-position ispell-recursive-edit-marker)
1298 (progn
1299 (message "Only one recursive edit session supported")
1300 (beep))
1301 (set-marker ispell-recursive-edit-marker start)
1302 ;;(set-marker ispell-region-end reg-end)
1303 (and ispell-highlight-p ; unhighlight
1304 (ispell-highlight-spelling-error start end))
1305 (unwind-protect
1306 (progn
1307 (save-window-excursion (save-excursion
1308 (recursive-edit)) t)
1309 (if (not (equal (marker-buffer
1310 ispell-recursive-edit-marker)
1311 (current-buffer)))
1312 (error
1313 "Cannot continue ispell from this buffer."))
1314 (goto-char ispell-recursive-edit-marker))
1315 (set-marker ispell-recursive-edit-marker nil)))
1316 (cons word nil)) ; recheck starting at this word.
29aec366
RS
1317 ((= char ?\C-z)
1318 (funcall (key-binding "\C-z"))
1319 t)
1320 (t (ding) t))))))
1321 result)
e29702dd 1322 ;; protected
f5136913
RS
1323 (and ispell-highlight-p ; unhighlight
1324 (save-window-excursion
1325 (select-window textwin)
1326 (ispell-highlight-spelling-error start end)))
1327 (if dedicated
1328 (set-window-dedicated-p dedicated-win t)))))
1329
1330
1331
1332(defun ispell-show-choices (line end)
1333 "Shows the choices in another buffer or frame."
1334 (if ispell-use-framepop-p
1335 (progn
1336 (framepop-display-buffer (get-buffer ispell-choices-buffer))
1337 (get-buffer-window ispell-choices-buffer t)
1338 (select-window (previous-window))) ; *Choices* window
1339 ;; standard selection by splitting a small buffer out of this window.
1340 (let ((choices-window (get-buffer-window ispell-choices-buffer)))
1341 (if choices-window
1342 (if (= line (window-height choices-window))
1343 (select-window choices-window)
1344 ;; *Choices* window changed size. Adjust the choices window
1345 ;; without scrolling the spelled window when possible
1346 (let ((window-line (- line (window-height choices-window)))
1347 (visible (progn (vertical-motion -1) (point))))
1348 (if (< line ispell-choices-win-default-height)
1349 (setq window-line (+ window-line
1350 (- ispell-choices-win-default-height
1351 line))))
1352 (move-to-window-line 0)
1353 (vertical-motion window-line)
1354 (set-window-start (selected-window)
1355 (if (> (point) visible) visible (point)))
1356 (goto-char end)
1357 (select-window (previous-window)) ; *Choices* window
1358 (enlarge-window window-line)))
1359 ;; Overlay *Choices* window when it isn't showing
1360 (ispell-overlay-window (max line ispell-choices-win-default-height)))
1361 (switch-to-buffer ispell-choices-buffer)
1362 (goto-char (point-min)))))
007852e0
RS
1363
1364
829b9e73 1365;;;###autoload
007852e0 1366(defun ispell-help ()
3ee3ac77 1367 "Display a list of the options available when a misspelling is encountered.
007852e0
RS
1368
1369Selections are:
1370
1371DIGIT: Replace the word with a digit offered in the *Choices* buffer.
a9210a53
RS
1372SPC: Accept word this time.
1373`i': Accept word and insert into private dictionary.
1374`a': Accept word for this session.
1375`A': Accept word and place in `buffer-local dictionary'.
1376`r': Replace word with typed-in value. Rechecked.
1377`R': Replace word with typed-in value. Query-replaced in buffer. Rechecked.
1378`?': Show these commands.
1379`x': Exit spelling buffer. Move cursor to original point.
1380`X': Exit spelling buffer. Leaves cursor at the current point, and permits
007852e0 1381 the aborted check to be completed later.
a9210a53
RS
1382`q': Quit spelling session (Kills ispell process).
1383`l': Look up typed-in replacement in alternate dictionary. Wildcards okay.
1384`u': Like `i', but the word is lower-cased first.
f5136913 1385`m': Place typed-in value in personal dictionary, then recheck current word.
a9210a53
RS
1386`C-l': redraws screen
1387`C-r': recursive edit
1388`C-z': suspend emacs or iconify frame"
007852e0 1389
f5136913
RS
1390 (if (equal ispell-help-in-bufferp 'electric)
1391 (progn
1392 (require 'ehelp)
1393 (with-electric-help
1394 (function (lambda ()
1395 ;;This shouldn't be necessary: with-electric-help needs
1396 ;; an optional argument telling it about the smallest
1397 ;; acceptable window-height of the help buffer.
1398 (if (< (window-height) 15)
1399 (enlarge-window (- 15 (window-height))))
1400 (princ "Selections are:
1401
1402DIGIT: Replace the word with a digit offered in the *Choices* buffer.
1403SPC: Accept word this time.
1404`i': Accept word and insert into private dictionary.
1405`a': Accept word for this session.
1406`A': Accept word and place in `buffer-local dictionary'.
1407`r': Replace word with typed-in value. Rechecked.
1408`R': Replace word with typed-in value. Query-replaced in buffer. Rechecked.
1409`?': Show these commands.
1410`x': Exit spelling buffer. Move cursor to original point.
1411`X': Exit spelling buffer. Leaves cursor at the current point, and permits
1412 the aborted check to be completed later.
1413`q': Quit spelling session (Kills ispell process).
1414`l': Look up typed-in replacement in alternate dictionary. Wildcards okay.
1415`u': Like `i', but the word is lower-cased first.
1416`m': Place typed-in value in personal dictionary, then recheck current word.
1417`C-l': redraws screen
1418`C-r': recursive edit
1419`C-z': suspend emacs or iconify frame")
1420 nil ;undocumented requirement of with-electric-help
1421 ))))
1422
1423
1424 (let ((help-1 (concat "[r/R]eplace word; [a/A]ccept for this session; "
1425 "[i]nsert into private dictionary"))
1426 (help-2 (concat "[l]ook a word up in alternate dictionary; "
1427 "e[x/X]it; [q]uit session"))
1428 (help-3 (concat "[u]ncapitalized insert into dict. "
1429 "Type 'x C-h d ispell-help' for more help")))
1430 (save-window-excursion
1431 (if ispell-help-in-bufferp
1432 (progn
1433 (ispell-overlay-window 4)
1434 (switch-to-buffer (get-buffer-create "*Ispell Help*"))
1435 (insert (concat help-1 "\n" help-2 "\n" help-3))
1436 (sit-for 5)
1437 (kill-buffer "*Ispell Help*"))
1438 (select-window (minibuffer-window))
1439 ;;(enlarge-window 2)
1440 (erase-buffer)
1441 (cond ((string-match "Lucid\\|XEmacs" emacs-version)
1442 (message help-3)
1443 (enlarge-window 1)
1444 (message help-2)
1445 (enlarge-window 1)
1446 (message help-1)
1447 (goto-char (point-min)))
1448 (t
1449 (if (not (string-match "18\\.[0-9]+\\.[0-9]+" emacs-version))
1450 (message nil))
1451 ;;(set-minibuffer-window (selected-window))
1452 (enlarge-window 2)
1453 (insert (concat help-1 "\n" help-2 "\n" help-3))))
1454 (sit-for 5)
1455 (erase-buffer))))))
007852e0
RS
1456
1457
1458(defun lookup-words (word &optional lookup-dict)
1459 "Look up word in word-list dictionary.
4b03da72
RS
1460A `*' serves as a wild card. If no wild cards, `look' is used if it exists.
1461Otherwise the variable `ispell-grep-command' contains the command used to
1462search for the words (usually egrep).
1463
3ee3ac77 1464Optional second argument contains the dictionary to use; the default is
4b03da72 1465`ispell-alternate-dictionary'."
007852e0
RS
1466 ;; We don't use the filter for this function, rather the result is written
1467 ;; into a buffer. Hence there is no need to save the filter values.
1468 (if (null lookup-dict)
1469 (setq lookup-dict ispell-alternate-dictionary))
1470
1471 (let* ((process-connection-type ispell-use-ptys-p)
1472 (wild-p (string-match "\\*" word))
1473 (look-p (and ispell-look-p ; Only use look for an exact match.
1474 (or ispell-have-new-look (not wild-p))))
1475 (ispell-grep-buffer (get-buffer-create "*Ispell-Temp*")) ; result buf
1476 (prog (if look-p ispell-look-command ispell-grep-command))
1477 (args (if look-p ispell-look-options ispell-grep-options))
1478 status results loc)
1479 (unwind-protect
1480 (save-window-excursion
1481 (message "Starting \"%s\" process..." (file-name-nondirectory prog))
1482 (set-buffer ispell-grep-buffer)
1483 (if look-p
1484 nil
1485 ;; convert * to .*
1486 (insert "^" word "$")
1487 (while (search-backward "*" nil t) (insert "."))
1488 (setq word (buffer-string))
1489 (erase-buffer))
1490 (setq status (call-process prog nil t nil args word lookup-dict))
1491 ;; grep returns status 1 and no output when word not found, which
1492 ;; is a perfectly normal thing.
1493 (if (stringp status)
1494 (setq results (cons (format "error: %s exited with signal %s"
1495 (file-name-nondirectory prog) status)
1496 results))
1497 ;; else collect words into `results' in FIFO order
1498 (goto-char (point-max))
1499 ;; assure we've ended with \n
1500 (or (bobp) (= (preceding-char) ?\n) (insert ?\n))
1501 (while (not (bobp))
1502 (setq loc (point))
1503 (forward-line -1)
f5136913
RS
1504 (setq results (cons (buffer-substring-no-properties (point)
1505 (1- loc))
007852e0
RS
1506 results)))))
1507 ;; protected
1508 (kill-buffer ispell-grep-buffer)
1509 (if (and results (string-match ".+: " (car results)))
1510 (error "%s error: %s" ispell-grep-command (car results))))
1511 results))
1512
1513
1514;;; "ispell-filter" is a list of output lines from the generating function.
1515;;; Each full line (ending with \n) is a separate item on the list.
1516;;; "output" can contain multiple lines, part of a line, or both.
1517;;; "start" and "end" are used to keep bounds on lines when "output" contains
1518;;; multiple lines.
1519;;; "ispell-filter-continue" is true when we have received only part of a
1520;;; line as output from a generating function ("output" did not end with \n)
a7acbbe4 1521;;; THIS FUNCTION WILL FAIL IF THE PROCESS OUTPUT DOESN'T END WITH \n!
007852e0
RS
1522;;; This is the case when a process dies or fails. The default behavior
1523;;; in this case treats the next input received as fresh input.
1524
1525(defun ispell-filter (process output)
1526 "Output filter function for ispell, grep, and look."
1527 (let ((start 0)
1528 (continue t)
1529 end)
1530 (while continue
1531 (setq end (string-match "\n" output start)) ; get text up to the newline.
1532 ;; If we get out of sync and ispell-filter-continue is asserted when we
1533 ;; are not continuing, treat the next item as a separate list. When
1534 ;; ispell-filter-continue is asserted, ispell-filter *should* always be a
1535 ;; list!
1536
1537 ;; Continue with same line (item)?
1538 (if (and ispell-filter-continue ispell-filter (listp ispell-filter))
1539 ;; Yes. Add it to the prev item
1540 (setcar ispell-filter
1541 (concat (car ispell-filter) (substring output start end)))
1542 ;; No. This is a new line and item.
1543 (setq ispell-filter
1544 (cons (substring output start end) ispell-filter)))
1545 (if (null end)
1546 ;; We've completed reading the output, but didn't finish the line.
1547 (setq ispell-filter-continue t continue nil)
1548 ;; skip over newline, this line complete.
1549 (setq ispell-filter-continue nil end (1+ end))
1550 (if (= end (length output)) ; No more lines in output
1551 (setq continue nil) ; so we can exit the filter.
1552 (setq start end)))))) ; else move start to next line of input
1553
1554
1555;;; This function destroys the mark location if it is in the word being
1556;;; highlighted.
f5136913
RS
1557(defun ispell-highlight-spelling-error-generic (start end &optional highlight
1558 refresh)
3ee3ac77
RS
1559 "Highlight the word from START to END with a kludge using `inverse-video'.
1560When the optional third arg HIGHLIGHT is set, the word is highlighted;
f5136913 1561otherwise it is displayed normally.
5755be32 1562Uses block cursor to highlight one character.
f5136913
RS
1563Optional REFRESH will unhighlighted then highlight, using block cursor
1564 highlighting when REFRESH is equal to `block'."
1565 (and (eq 'block ispell-highlight-p)
1566 (or (eq 'block refresh)
1567 (setq start (1+ start)))) ; On block non-refresh, inc start.
007852e0
RS
1568 (let ((modified (buffer-modified-p)) ; don't allow this fn to modify buffer
1569 (buffer-read-only nil) ; Allow highlighting read-only buffers.
f5136913 1570 (text (buffer-substring-no-properties start end)) ; Save hilight region
007852e0 1571 (inhibit-quit t) ; inhibit interrupt processing here.
29aec366 1572 (buffer-undo-list t)) ; don't clutter the undo list.
f5136913 1573 (goto-char end)
007852e0 1574 (delete-region start end)
a7acbbe4 1575 (insert-char ? (- end start)) ; minimize amount of redisplay
007852e0
RS
1576 (sit-for 0) ; update display
1577 (if highlight (setq inverse-video (not inverse-video))) ; toggle video
1578 (delete-region start end) ; delete whitespace
1579 (insert text) ; insert text in inverse video.
1580 (sit-for 0) ; update display showing inverse video.
f5136913
RS
1581 (if (not highlight)
1582 (goto-char end)
1583 (setq inverse-video (not inverse-video)) ; toggle video
1584 (and (eq 'block ispell-highlight-p)
1585 (goto-char (1- start)))) ; use block cursor to "highlight" char
1586 (set-buffer-modified-p modified) ; don't modify if flag not set.
1587 (and refresh ; re-highlight
1588 (ispell-highlight-spelling-error-generic
1589 (if (eq 'block refresh) start (- start 2)) end t))))
1590
1591
1592(defun ispell-highlight-spelling-error-xemacs (start end &optional highlight)
3ee3ac77 1593 "Highlight the word from START to END using `isearch-highlight'.
e29702dd 1594When the optional third arg HIGHLIGHT is set, the word is highlighted,
007852e0
RS
1595otherwise it is displayed normally."
1596 (if highlight
1597 (isearch-highlight start end)
1598 (isearch-dehighlight t))
1599 ;;(sit-for 0)
1600 )
1601
1602
4b03da72 1603(defun ispell-highlight-spelling-error-overlay (start end &optional highlight)
3ee3ac77
RS
1604 "Highlight the word from START to END using overlays.
1605When the optional third arg HIGHLIGHT is set, the word is highlighted
1606otherwise it is displayed normally.
4b03da72 1607
a9210a53 1608The variable `ispell-highlight-face' selects the face to use for highlighting."
007852e0
RS
1609 (if highlight
1610 (progn
1611 (setq ispell-overlay (make-overlay start end))
1612 (overlay-put ispell-overlay 'face ispell-highlight-face))
1613 (delete-overlay ispell-overlay)))
1614
1615
f5136913 1616(defun ispell-highlight-spelling-error (start end &optional highlight refresh)
29aec366 1617 (cond
f5136913
RS
1618 ((string-match "Lucid\\|XEmacs" emacs-version)
1619 (ispell-highlight-spelling-error-xemacs start end highlight))
1620 ((and (not (string-match "18\\.[0-9]+\\.[0-9]+" emacs-version))
e29702dd 1621 (featurep 'faces) window-system)
29aec366 1622 (ispell-highlight-spelling-error-overlay start end highlight))
f5136913 1623 (t (ispell-highlight-spelling-error-generic start end highlight refresh))))
007852e0 1624
e29702dd 1625
007852e0 1626(defun ispell-overlay-window (height)
3ee3ac77
RS
1627 "Create a window covering the top HEIGHT lines of the current window.
1628Ensure that the line above point is still visible but otherwise avoid
045dbcbc 1629scrolling the current window. Leave the new window selected."
007852e0
RS
1630 (save-excursion
1631 (let ((oldot (save-excursion (forward-line -1) (point)))
1632 (top (save-excursion (move-to-window-line height) (point))))
1633 ;; If line above old point (line starting at olddot) would be
1634 ;; hidden by new window, scroll it to just below new win
1635 ;; otherwise set top line of other win so it doesn't scroll.
1636 (if (< oldot top) (setq top oldot))
f5136913 1637 ;; NB: XEmacs 19.9 bug: If a window of size N (N includes the mode
4b03da72 1638 ;; line) is demanded, the last line is not visible.
f5136913 1639 ;; At least this happens on AIX 3.2, XEmacs w/ Motif, font 9x15.
4b03da72 1640 ;; So we increment the height for this case.
f5136913
RS
1641 (if (and (string-match "Lucid\\|XEmacs" emacs-version)
1642 (string-match "19\\.9\\.[0-9]+" emacs-version))
4b03da72 1643 (setq height (1+ height)))
f5136913
RS
1644 ;; if frame is unsplitable, temporarily disable that...
1645 (if (cdr (assq 'unsplittable (frame-parameters (selected-frame))))
1646 (let ((frame (selected-frame)))
1647 (modify-frame-parameters frame '((unsplittable . nil)))
1648 (split-window nil height)
1649 (modify-frame-parameters frame '((unsplittable . t))))
1650 (split-window nil height))
007852e0
RS
1651 (set-window-start (next-window) top))))
1652
1653
1654;;; Should we add a compound word match return value?
1655(defun ispell-parse-output (output)
f5136913 1656 "Parse the OUTPUT string from Ispell process and return:
a9210a53 16571: t for an exact match.
f5136913 16582: A string containing the root word matched via suffix removal.
007852e0 16593: A list of possible correct spellings of the format:
f5136913 1660 (\"ORIGINAL-WORD\" OFFSET MISS-LIST GUESS-LIST)
3ee3ac77
RS
1661 ORIGINAL-WORD is a string of the possibly misspelled word.
1662 OFFSET is an integer giving the line offset of the word.
f5136913
RS
1663 MISS-LIST and GUESS-LIST are possibly null lists of guesses and misses.
16644: Nil when an error has occurred."
007852e0
RS
1665 (cond
1666 ((string= output "") t) ; for startup with pipes...
1667 ((string= output "*") t) ; exact match
f5136913
RS
1668 ((string= output "-") t) ; compound word match
1669 ((string= (substring output 0 1) "+") ; found because of root word
007852e0 1670 (substring output 2)) ; return root word
f5136913
RS
1671 ((equal 0 (string-match "[\\ra-zA-Z]" output))
1672 (ding) ; error message from ispell!
1673 (message (concat "Ispell error: " output))
1674 (sit-for 5)
1675 nil)
007852e0
RS
1676 (t ; need to process &, ?, and #'s
1677 (let ((type (substring output 0 1)) ; &, ?, or #
1678 (original-word (substring output 2 (string-match " " output 2)))
1679 (cur-count 0) ; contains number of misses + guesses
1680 count miss-list guess-list offset)
1681 (setq output (substring output (match-end 0))) ; skip over misspelling
1682 (if (string= type "#")
1683 (setq count 0) ; no misses for type #
1684 (setq count (string-to-int output) ; get number of misses.
1685 output (substring output (1+ (string-match " " output 1)))))
1686 (setq offset (string-to-int output))
1687 (if (string= type "#") ; No miss or guess list.
1688 (setq output nil)
1689 (setq output (substring output (1+ (string-match " " output 1)))))
1690 (while output
1691 (let ((end (string-match ", \\|\\($\\)" output))) ; end of miss/guess.
1692 (setq cur-count (1+ cur-count))
1693 (if (> cur-count count)
1694 (setq guess-list (cons (substring output 0 end) guess-list))
1695 (setq miss-list (cons (substring output 0 end) miss-list)))
1696 (if (match-end 1) ; True only when at end of line.
1697 (setq output nil) ; no more misses or guesses
1698 (setq output (substring output (+ end 2))))))
1699 (list original-word offset miss-list guess-list)))))
1700
1701
f5136913 1702(defun check-ispell-version (&optional interactivep)
007852e0
RS
1703 ;; This is a little wasteful as we actually launch ispell twice: once
1704 ;; to make sure it's the right version, and once for real. But people
1705 ;; get confused by version mismatches *all* the time (and I've got the
1706 ;; email to prove it) so I think this is worthwhile. And the -v[ersion]
1707 ;; option is the only way I can think of to do this that works with
1708 ;; all versions, since versions earlier than 3.0.09 didn't identify
1709 ;; themselves on startup.
f5136913 1710 (interactive "p")
007852e0 1711 (save-excursion
f5136913 1712 (let (case-fold-search status
1335d078
RS
1713 ;; avoid bugs when syntax of `.' changes in various default modes
1714 (default-major-mode 'fundamental-mode)
f5136913 1715 (result t))
1335d078 1716 (set-buffer (get-buffer-create " *ispell-tmp*"))
f5136913 1717 (setq case-fold-search t)
1335d078
RS
1718 (erase-buffer)
1719 (setq status (call-process ispell-program-name nil t nil "-v"))
007852e0 1720 (goto-char (point-min))
f5136913
RS
1721 (if interactivep
1722 (progn
1723 (end-of-line)
1724 (setq result (concat (buffer-substring-no-properties (point-min)
1725 (point))
1726 ", "
1727 ispell-version))
1728 (message result)
1729 (goto-char (point-min))))
e29702dd
KH
1730 (if (not (memq status '(0 nil)))
1731 (error "%s exited with %s %s" ispell-program-name
1732 (if (stringp status) "signal" "code") status))
1733 (if (not (re-search-forward
f5136913 1734 (concat "\\<\\("
e29702dd 1735 (regexp-quote (car ispell-required-version))
f5136913 1736 "\\)\\([0-9]*\\)\\>")
e29702dd 1737 nil t))
f5136913
RS
1738 (error "%s version 3 release %s%s or greater is required"
1739 ispell-program-name (car ispell-required-version)
1740 (car (cdr ispell-required-version)))
e29702dd 1741 ;; check that it is the correct version.
f5136913 1742 (if (< (car (read-from-string (buffer-substring-no-properties
e29702dd
KH
1743 (match-beginning 2) (match-end 2))))
1744 (car (cdr ispell-required-version)))
1745 (setq ispell-offset 0)))
f5136913
RS
1746 (kill-buffer (current-buffer))
1747 result)))
007852e0
RS
1748
1749
1750(defun ispell-init-process ()
3ee3ac77 1751 "Check status of Ispell process and start if necessary."
007852e0
RS
1752 (if (and ispell-process
1753 (eq (process-status ispell-process) 'run)
1754 ;; If we're using a personal dictionary, assure
1755 ;; we're in the same default directory!
1756 (or (not ispell-personal-dictionary)
1757 (equal ispell-process-directory default-directory)))
1758 (setq ispell-filter nil ispell-filter-continue nil)
1759 ;; may need to restart to select new personal dictionary.
1760 (ispell-kill-ispell t)
3ee3ac77 1761 (message "Starting new Ispell process...")
007852e0
RS
1762 (sit-for 0)
1763 (check-ispell-version)
1764 (setq ispell-process
1765 (let ((process-connection-type ispell-use-ptys-p))
1766 (apply 'start-process
1767 "ispell" nil ispell-program-name
1768 "-a" ; accept single input lines
1769 "-m" ; make root/affix combos not in dict
1770 (let (args)
1771 ;; Local dictionary becomes the global dictionary in use.
1772 (if ispell-local-dictionary
1773 (setq ispell-dictionary ispell-local-dictionary))
1774 (setq args (ispell-get-ispell-args))
1775 (if ispell-dictionary ; use specified dictionary
1776 (setq args
1777 (append (list "-d" ispell-dictionary) args)))
1778 (if ispell-personal-dictionary ; use specified pers dict
1779 (setq args
1780 (append args
1781 (list "-p"
1782 (expand-file-name
1783 ispell-personal-dictionary)))))
4b03da72 1784 (setq args (append args ispell-extra-args))
007852e0
RS
1785 args)))
1786 ispell-filter nil
1787 ispell-filter-continue nil
1788 ispell-process-directory default-directory)
1789 (set-process-filter ispell-process 'ispell-filter)
f5136913
RS
1790 (if (and (boundp 'enable-multibyte-characters)
1791 (fboundp 'set-process-coding-system)
1792 enable-multibyte-characters)
ef128a91 1793 (set-process-coding-system ispell-process (ispell-get-coding-system)))
f5136913
RS
1794 ;; Get version ID line
1795 (if (not (string-match "18\\.[0-9]+\\.[0-9]+" emacs-version))
1796 (accept-process-output ispell-process 5)
1797 (accept-process-output ispell-process))
1798 ;; get more output if filter empty?
1799 (if (null ispell-filter) (accept-process-output ispell-process 5))
007852e0 1800 (cond ((null ispell-filter)
a8928dd2 1801 (error "%s did not output version line" ispell-program-name))
01ea0e3b
RS
1802 ((and
1803 (stringp (car ispell-filter))
1804 (if (string-match "warning: " (car ispell-filter))
1805 (progn
f5136913
RS
1806 (if (not (string-match "18\\.[0-9]+\\.[0-9]+" emacs-version))
1807 (accept-process-output ispell-process 5) ; was warn msg.
1808 (accept-process-output ispell-process))
01ea0e3b
RS
1809 (stringp (car ispell-filter)))
1810 (null (cdr ispell-filter)))
1811 (string-match "^@(#) " (car ispell-filter)))
007852e0
RS
1812 ;; got the version line as expected (we already know it's the right
1813 ;; version, so don't bother checking again.)
1814 nil)
1815 (t
1816 ;; Otherwise, it must be an error message. Show the user.
1817 ;; But first wait to see if some more output is going to arrive.
1818 ;; Otherwise we get cool errors like "Can't open ".
1819 (sleep-for 1)
1820 (accept-process-output)
1821 (error "%s" (mapconcat 'identity ispell-filter "\n"))))
1822 (setq ispell-filter nil) ; Discard version ID line
1823 (let ((extended-char-mode (ispell-get-extended-character-mode)))
1824 (if extended-char-mode
1825 (process-send-string ispell-process
1826 (concat extended-char-mode "\n"))))
1827 (process-kill-without-query ispell-process)))
1828
829b9e73 1829;;;###autoload
007852e0 1830(defun ispell-kill-ispell (&optional no-error)
a9210a53
RS
1831 "Kill current Ispell process (so that you may start a fresh one).
1832With NO-ERROR, just return non-nil if there was no Ispell running."
007852e0
RS
1833 (interactive)
1834 (if (not (and ispell-process
1835 (eq (process-status ispell-process) 'run)))
1836 (or no-error
1837 (error "There is no ispell process running!"))
1838 (kill-process ispell-process)
1839 (setq ispell-process nil)
3ee3ac77 1840 (message "Ispell process killed")
007852e0
RS
1841 nil))
1842
1843
8ce8687e 1844;;; ispell-change-dictionary is set in some people's hooks. Maybe this should
1335d078
RS
1845;;; call ispell-init-process rather than wait for a spell checking command?
1846
007852e0
RS
1847;;;###autoload
1848(defun ispell-change-dictionary (dict &optional arg)
a9210a53 1849 "Change `ispell-dictionary' (q.v.) and kill old Ispell process.
007852e0
RS
1850A new one will be started as soon as necessary.
1851
1852By just answering RET you can find out what the current dictionary is.
1853
1854With prefix argument, set the default directory."
1855 (interactive
1856 (list (completing-read
1857 "Use new dictionary (RET for current, SPC to complete): "
1858 (cons (cons "default" nil) ispell-dictionary-alist) nil t)
1859 current-prefix-arg))
1860 (if (equal dict "default") (setq dict nil))
1861 ;; This relies on completing-read's bug of returning "" for no match
1862 (cond ((equal dict "")
1863 (message "Using %s dictionary"
1864 (or ispell-local-dictionary ispell-dictionary "default")))
1865 ((and (equal dict ispell-dictionary)
1335d078
RS
1866 (or (null ispell-local-dictionary)
1867 (equal dict ispell-local-dictionary)))
007852e0 1868 ;; Specified dictionary is the default already. No-op
1335d078
RS
1869 (and (interactive-p)
1870 (message "No change, using %s dictionary" (or dict "default"))))
007852e0
RS
1871 (t ; reset dictionary!
1872 (if (assoc dict ispell-dictionary-alist)
1873 (progn
1874 (if (or arg (null dict)) ; set default dictionary
1875 (setq ispell-dictionary dict))
1876 (if (null arg) ; set local dictionary
1877 (setq ispell-local-dictionary dict)))
f5136913 1878 (error "Undefined dictionary: %s" dict))
007852e0 1879 (ispell-kill-ispell t)
3ee3ac77 1880 (message "(Next %sIspell command will use %s dictionary)"
007852e0
RS
1881 (cond ((equal ispell-local-dictionary ispell-dictionary)
1882 "")
1883 (arg "global ")
1884 (t "local "))
1885 (or (if (or (equal ispell-local-dictionary ispell-dictionary)
1886 (null arg))
1887 ispell-local-dictionary
1888 ispell-dictionary)
1889 "default")))))
1890
1891
1892;;; Spelling of comments are checked when ispell-check-comments is non-nil.
1893
1894;;;###autoload
1895(defun ispell-region (reg-start reg-end)
5755be32
RS
1896 "Interactively check a region for spelling errors.
1897Return non-nil if not aborted."
007852e0
RS
1898 (interactive "r") ; Don't flag errors on read-only bufs.
1899 (ispell-accept-buffer-local-defs) ; set up dictionary, local words, etc.
1900 (unwind-protect
4b03da72 1901 (save-excursion
e29702dd 1902 (message "Spell checking %s using %s dictionary..."
4b03da72 1903 (if (and (= reg-start (point-min)) (= reg-end (point-max)))
e29702dd
KH
1904 (buffer-name) "region")
1905 (or ispell-dictionary "default"))
1906 ;; Returns cursor to original location.
4b03da72 1907 (save-window-excursion
4b03da72 1908 (goto-char reg-start)
1335d078 1909 (let ((transient-mark-mode nil)
f5136913
RS
1910 (case-fold-search case-fold-search)
1911 (skip-region-start (make-marker))
1912 (skip-regexp (ispell-begin-skip-region-regexp))
1913 (skip-alist ispell-skip-region-alist)
1914 key)
1915 (if (eq ispell-parser 'tex)
1916 (setq case-fold-search nil
1917 skip-alist
1918 (append (car ispell-tex-skip-alists)
1919 (car (cdr ispell-tex-skip-alists))
1920 skip-alist)))
1921 (let (message-log-max)
1922 (message "searching for regions to skip"))
1923 (if (re-search-forward skip-regexp reg-end t)
1924 (progn
1925 (setq key (buffer-substring-no-properties
1926 (match-beginning 0) (match-end 0)))
1927 (set-marker skip-region-start (- (point) (length key)))
1928 (goto-char reg-start)))
1929 (let (message-log-max)
1930 (message "Continuing spelling check using %s dictionary..."
1931 (or ispell-dictionary "default")))
1932 (set-marker ispell-region-end reg-end)
1933 (while (and (not ispell-quit)
1934 (< (point) ispell-region-end))
1935 ;; spell-check region with skipping
1936 (if (and (marker-position skip-region-start)
1937 (<= skip-region-start (point)))
1938 (progn
1939 (ispell-skip-region key skip-alist) ; moves pt past region.
1940 (setq reg-start (point))
1941 (if (and (< reg-start ispell-region-end)
1942 (re-search-forward skip-regexp
1943 ispell-region-end t))
1944 (progn
1945 (setq key (buffer-substring-no-properties
1946 (car (match-data))
1947 (car (cdr (match-data)))))
1948 (set-marker skip-region-start
1949 (- (point) (length key)))
1950 (goto-char reg-start))
1951 (set-marker skip-region-start nil))))
1952 (setq reg-end (if (marker-position skip-region-start)
1953 (min skip-region-start ispell-region-end)
1954 (marker-position ispell-region-end)))
1955 (let* ((start (point))
1956 (end (save-excursion (end-of-line) (min (point) reg-end)))
1957 (string (ispell-get-line start end reg-end)))
1958 (setq end (point)) ; "end" tracks region retrieved.
1959 (if string ; there is something to spell check!
1960 (ispell-process-line string)) ; (special start end)
4b03da72 1961 (goto-char end)))))
5755be32 1962 (not ispell-quit)
f5136913 1963 )
4b03da72
RS
1964 ;; protected
1965 (if (get-buffer ispell-choices-buffer)
1966 (kill-buffer ispell-choices-buffer))
1967 (if ispell-quit
1968 (progn
1969 ;; preserve or clear the region for ispell-continue.
1970 (if (not (numberp ispell-quit))
1971 (set-marker ispell-region-end nil)
f5136913 1972 ;; Ispell-continue enabled - ispell-region-end is set.
4b03da72
RS
1973 (goto-char ispell-quit))
1974 ;; Check for aborting
1975 (if (and ispell-checking-message (numberp ispell-quit))
1976 (progn
1977 (setq ispell-quit nil)
1978 (error "Message send aborted.")))
1979 (setq ispell-quit nil))
1980 (set-marker ispell-region-end nil)
1981 ;; Only save if successful exit.
1982 (ispell-pdict-save ispell-silently-savep)
1983 (message "Spell-checking done"))))
007852e0
RS
1984
1985
f5136913 1986;;; Creates the regexp for skipping a region.
94487c4e 1987;;; Makes the skip-regexp local for tex buffers adding in the
f5136913
RS
1988;;; tex expressions to skip as well.
1989;;; Call AFTER ispell-buffer-local-parsing.
1990(defun ispell-begin-skip-region-regexp ()
1991 (let ((skip-regexp (ispell-begin-skip-region)))
1992 (if (and (null ispell-check-comments) comment-start)
1993 (setq skip-regexp (concat (regexp-quote comment-start) "\\|"
1994 skip-regexp)))
1995 (if (and (eq 'exclusive ispell-check-comments) comment-start)
1996 (setq skip-regexp (concat (if (string= "" comment-end) "^"
1997 (regexp-quote comment-end))
1998 "\\|" skip-regexp)))
1999 (if ispell-skip-tib
2000 (setq skip-regexp (concat ispell-tib-ref-beginning "\\|" skip-regexp)))
2001 (if ispell-skip-sgml
2002 (setq skip-regexp (concat "[<&]\\|" skip-regexp)))
2003 (if (eq ispell-parser 'tex)
2004 (setq skip-regexp (concat (ispell-begin-tex-skip-regexp) "\\|"
2005 skip-regexp)))
2006 skip-regexp))
2007
2008
2009;;; Regular expression of tex commands to skip.
2010;;; Generated from `ispell-tex-skip-alists'
2011(defun ispell-begin-tex-skip-regexp ()
2012 (concat
2013 (mapconcat (function (lambda (lst) (car lst)))
2014 (car ispell-tex-skip-alists)
2015 "\\|")
2016 "\\|"
2017 (mapconcat (function (lambda (lst)
2018 (concat "\\\\begin[ \t\n]*{[ \t\n]*"
2019 (car lst)
2020 "[ \t\n]*}")))
2021 (car (cdr ispell-tex-skip-alists))
2022 "\\|")))
2023
2024
2025;;; Regular expression of regions to skip for all buffers.
2026;;; Each selection should be a key of `ispell-skip-region-alist'
2027;;; otherwise, the current line is skipped.
2028(defun ispell-begin-skip-region ()
2029 (mapconcat (function (lambda (lst) (if (stringp (car lst)) (car lst)
2030 (eval (car lst)))))
2031 ispell-skip-region-alist
2032 "\\|"))
2033
2034
2035(defun ispell-tex-arg-end (&optional arg)
2036 (condition-case nil
2037 (progn
2038 (while (looking-at "[ \t\n]*\\[") (forward-sexp))
2039 (forward-sexp (or arg 1)))
2040 (error
2041 (message "error skipping s-expressions at point %d." (point))
2042 (beep)
2043 (sit-for 2))))
2044
2045
2046;;; Skips to region-end from point, or a single line.
2047;;; Places point at end of region skipped.
2048(defun ispell-skip-region (key alist)
2049 ;; move over key to begin checking.
2050 (forward-char (length key))
2051 (let ((start (point))
2052 alist-key null-skip)
2053 (cond
2054 ;; what about quoted comment, or comment inside strings?
2055 ((and (null ispell-check-comments) comment-start
2056 (string= key comment-start))
2057 (if (string= "" comment-end)
2058 (forward-line)
2059 (search-forward comment-end ispell-region-end t)))
2060 ((and (eq 'exclusive ispell-check-comments) comment-start
2061 (string= key comment-end))
7a914d3e 2062 (search-forward comment-start ispell-region-end :end))
f5136913
RS
2063 ((and ispell-skip-tib (string-match ispell-tib-ref-beginning key))
2064 (re-search-forward ispell-tib-ref-end ispell-region-end t))
2065 ((and ispell-skip-sgml (string-match "<" key))
2066 (search-forward ">" ispell-region-end t))
2067 ((and ispell-skip-sgml (string-match "&" key))
2068 (search-forward ";" ispell-region-end t))
2069 ;; markings from alist
2070 (t
2071 (while alist
2072 (setq alist-key (eval (car (car alist))))
2073 (if (string-match alist-key key)
2074 (progn
2075 (setq alist (cdr (car alist)))
2076 (cond
2077 ((null alist) (setq null-skip t)) ; done! Just skip key.
2078 ((not (consp alist))
2079 ;; Search past end of spell region to find this region end.
2080 (re-search-forward (eval alist) (point-max) t))
2081 ((consp alist)
2082 (if (stringp alist)
2083 (re-search-forward alist (point-max) t)
2084 (setq null-skip t) ; error handling in functions!
2085 (if (consp (cdr alist))
2086 (apply (car alist) (cdr alist))
2087 (funcall (car alist))))))
2088 (setq alist nil))
2089 (setq alist (cdr alist))))))
2090 (if (and (= start (point)) (null null-skip))
2091 (progn
2092 (message "Matching region end for `%s' point %d not found"
2093 key (point))
2094 (beep)
2095 (sit-for 2)))))
2096
2097
2098;;; Grab the next line of data.
2099;;; Returns a string with the line data
2100(defun ispell-get-line (start end reg-end)
2101 (let ((ispell-casechars (ispell-get-casechars))
2102 string)
2103 (cond ; LOOK AT THIS LINE AND SKIP OR PROCESS
2104 ((eolp) ; END OF LINE, just go to next line.
2105 (forward-line))
2106 ((looking-at "[---#@*+!%~^]") ; SKIP SPECIAL ISPELL CHARACTERS
2107 (forward-char 1))
2108 ((or (re-search-forward ispell-casechars end t) ; TEXT EXISTS
2109 (re-search-forward "[][()${}]" end t)) ; or MATH COMMANDS
2110 (setq string (concat "^" (buffer-substring-no-properties start end)
2111 "\n"))
2112 (goto-char end))
2113 (t (goto-char end))) ; EMPTY LINE, skip it.
2114 string))
2115
2116
2117(defun ispell-process-line (string)
2118 ;;(declare special start end)
2119 (let (poss)
2120 ;; send string to spell process and get input.
2121 (process-send-string ispell-process string)
2122 (while (progn
2123 (accept-process-output ispell-process)
2124 ;; Last item of output contains a blank line.
2125 (not (string= "" (car ispell-filter)))))
2126 ;; parse all inputs from the stream one word at a time.
2127 ;; Place in FIFO order and remove the blank item.
2128 (setq ispell-filter (nreverse (cdr ispell-filter)))
2129 (while (and (not ispell-quit) ispell-filter)
2130 (setq poss (ispell-parse-output (car ispell-filter)))
2131 (if (and poss (listp poss)) ; spelling error occurred.
2132 ;; Whenever we have misspellings, we can change
2133 ;; the buffer. Keep boundaries as markers.
2134 ;; Markers can move with highlighting! This destroys
2135 ;; end of region markers line-end and ispell-region-end
2136 (let ((word-start
2137 (copy-marker
2138 (if (and (boundp 'enable-multibyte-characters)
2139 enable-multibyte-characters
2140 (ispell-get-coding-system))
2141 ;; skip over multibyte characters correctly
2142 (save-excursion
2143 (goto-char (+ start ispell-offset))
2144 (forward-char (car (cdr poss)))
2145 (point))
2146 (+ start ispell-offset (car (cdr poss))))))
2147 (word-len (length (car poss)))
2148 (line-end (copy-marker end))
2149 (line-start (copy-marker start))
2150 recheck-region replace)
2151 (goto-char word-start)
2152 ;; Adjust the horizontal scroll & point
2153 (ispell-horiz-scroll)
2154 (goto-char (+ word-len word-start))
2155 (ispell-horiz-scroll)
2156 (goto-char word-start)
2157 (ispell-horiz-scroll)
2158 (if (/= (+ word-len (point))
2159 (progn
2160 (search-forward (car poss) (+ word-len (point)) t)
2161 (point)))
2162 ;; This occurs due to filter pipe problems
2163 (error (concat "Ispell misalignment: word "
2164 "`%s' point %d; probably incompatible versions")
2165 (car poss) (marker-position word-start)))
2166
2167 ;; ispell-cmd-loop can go recursive & change buffer
2168 (if ispell-keep-choices-win
2169 (setq replace (ispell-command-loop
2170 (car (cdr (cdr poss)))
2171 (car (cdr (cdr (cdr poss))))
2172 (car poss) (marker-position word-start)
2173 (+ word-len (marker-position word-start))))
2174 (save-window-excursion
2175 (setq replace (ispell-command-loop
2176 (car (cdr (cdr poss)))
2177 (car (cdr (cdr (cdr poss))))
2178 (car poss) (marker-position word-start)
2179 (+ word-len (marker-position word-start))))))
2180
2181 ;; Recheck when recursive edit changes misspelled word
2182 (goto-char word-start)
2183 (if (not (string-equal (buffer-substring-no-properties
2184 (point) (+ word-len (point)))
2185 (car poss)))
2186 (progn
2187 (set-marker line-end (point))
2188 (setq ispell-filter nil
2189 recheck-region t)))
2190
2191 (cond
2192 ((and replace (listp replace))
2193 ;; REPLACEMENT WORD
2194 ;; Recheck line starting with the replacement word.
2195 (setq ispell-filter nil
2196 recheck-region t)
2197 (delete-region (point) (+ word-len (point)))
2198 (insert (car replace))
2199 ;; Only typed-in replacements need to be re-checked.
2200 (if (not (eq 'query-replace (car (cdr replace))))
2201 (backward-char (length (car replace))))
2202 (set-marker line-end (point)) ; continue checking from here.
2203 (if (car (cdr replace))
2204 (unwind-protect
2205 (save-window-excursion
2206 (delete-other-windows) ; to correctly show help.
2207 ;; Assume case-replace &
2208 ;; case-fold-search correct?
2209 (query-replace (car poss) (car replace) t))
2210 (goto-char word-start))))
2211 ((or (null replace)
2212 (equal 0 replace)) ; ACCEPT/INSERT
2213 (if (equal 0 replace) ; BUFFER-LOCAL DICT ADD
2214 (ispell-add-per-file-word-list (car poss)))
2215 ;; This avoids pointing out the word that was
2216 ;; just accepted (via 'i' or 'a') if it follows
2217 ;; on the same line.
2218 ;; Redo check following the accepted word.
2219 (if (and ispell-pdict-modified-p
2220 (listp ispell-pdict-modified-p))
2221 ;; Word accepted. Recheck line.
2222 (progn
2223 (setq ispell-pdict-modified-p ;update flag
2224 (car ispell-pdict-modified-p)
2225 ispell-filter nil
2226 recheck-region t)
2227 (set-marker line-end (marker-position word-start)))))
2228 (replace ; STRING REPLACEMENT for this word.
2229 (delete-region (point) (+ word-len (point)))
2230 (insert replace)
2231 (set-marker line-start (+ line-start
2232 (- (length replace)
2233 (length (car poss)))))))
2234 (if (not ispell-quit)
2235 (let (message-log-max)
2236 (message "Continuing spelling check using %s dictionary..."
2237 (or ispell-dictionary "default"))))
2238 (sit-for 0)
2239 (setq start (marker-position line-start)
2240 end (marker-position line-end))
2241 ;; Adjust markers when end of region lost from highlighting.
2242 (if (and (not recheck-region) (< end (+ word-start word-len)))
2243 (setq end (+ word-start word-len)))
2244 (if (= word-start ispell-region-end)
2245 (set-marker ispell-region-end (+ word-start word-len)))
2246 ;; going out of scope - unneeded
2247 (set-marker line-start nil)
2248 (set-marker word-start nil)
2249 (set-marker line-end nil)))
2250 ;; finished with misspelling!
2251 (setq ispell-filter (cdr ispell-filter)))))
2252
2253
bc7d6816
GM
2254;;;###autoload
2255(defun ispell-comments-and-strings ()
2256 "Check comments and strings in the current buffer for spelling errors."
2257 (interactive)
2258 (goto-char (point-min))
2259 (let (state done)
2260 (while (not done)
2261 (setq done t)
2262 (setq state (parse-partial-sexp (point) (point-max)
2263 nil nil state 'syntax-table))
2264 (when (or (nth 3 state) (nth 4 state))
2265 (let ((start (point)))
2266 (setq state (parse-partial-sexp start (point-max)
2267 nil nil state 'syntax-table))
2268 (when (or (nth 3 state) (nth 4 state))
2269 (error "Unterminated string or comment."))
2270 (save-excursion
2271 (setq done (not (ispell-region start (point))))))))))
2272
007852e0
RS
2273
2274;;;###autoload
4b03da72 2275(defun ispell-buffer ()
007852e0
RS
2276 "Check the current buffer for spelling errors interactively."
2277 (interactive)
2278 (ispell-region (point-min) (point-max)))
2279
4b03da72 2280
829b9e73 2281;;;###autoload
007852e0
RS
2282(defun ispell-continue ()
2283 (interactive)
f5136913 2284 "Continue a halted spelling session beginning with the current word."
007852e0
RS
2285 (if (not (marker-position ispell-region-end))
2286 (message "No session to continue. Use 'X' command when checking!")
2287 (if (not (equal (marker-buffer ispell-region-end) (current-buffer)))
2288 (message "Must continue ispell from buffer %s"
2289 (buffer-name (marker-buffer ispell-region-end)))
f5136913
RS
2290 (ispell-region
2291 ;; find beginning of current word:
2292 (car (cdr (ispell-get-word t)))
2293 (marker-position ispell-region-end)))))
007852e0
RS
2294
2295
2296;;; Horizontal scrolling
4b03da72
RS
2297(defun ispell-horiz-scroll ()
2298 "Places point within the horizontal visibility of its window area."
007852e0
RS
2299 (if truncate-lines ; display truncating lines?
2300 ;; See if display needs to be scrolled.
2301 (let ((column (- (current-column) (max (window-hscroll) 1))))
2302 (if (and (< column 0) (> (window-hscroll) 0))
2303 (scroll-right (max (- column) 10))
2304 (if (>= column (- (window-width) 2))
2305 (scroll-left (max (- column (window-width) -3) 10)))))))
2306
2307
2308;;; Interactive word completion.
2309;;; Forces "previous-word" processing. Do we want to make this selectable?
2310
2311;;;###autoload
2312(defun ispell-complete-word (&optional interior-frag)
2313 "Look up word before or under point in dictionary (see lookup-words command)
2314and try to complete it. If optional INTERIOR-FRAG is non-nil then the word
2315may be a character sequence inside of a word.
2316
2317Standard ispell choices are then available."
2318 (interactive "P")
2319 (let ((cursor-location (point))
4b03da72 2320 case-fold-search
007852e0
RS
2321 (word (ispell-get-word nil "\\*")) ; force "previous-word" processing.
2322 start end possibilities replacement)
2323 (setq start (car (cdr word))
2324 end (car (cdr (cdr word)))
2325 word (car word)
2326 possibilities
2327 (or (string= word "") ; Will give you every word
f5136913
RS
2328 (lookup-words (concat (and interior-frag "*") word
2329 (if (or interior-frag (null ispell-look-p))
2330 "*"))
007852e0
RS
2331 ispell-complete-word-dict)))
2332 (cond ((eq possibilities t)
2333 (message "No word to complete"))
2334 ((null possibilities)
2335 (message "No match for \"%s\"" word))
2336 (t ; There is a modification...
4b03da72
RS
2337 (cond ; Try and respect case of word.
2338 ((string-match "^[^A-Z]+$" word)
2339 (setq possibilities (mapcar 'downcase possibilities)))
2340 ((string-match "^[^a-z]+$" word)
2341 (setq possibilities (mapcar 'upcase possibilities)))
2342 ((string-match "^[A-Z]" word)
2343 (setq possibilities (mapcar 'capitalize possibilities))))
29aec366
RS
2344 (save-window-excursion
2345 (setq replacement
2346 (ispell-command-loop possibilities nil word start end)))
007852e0
RS
2347 (cond
2348 ((equal 0 replacement) ; BUFFER-LOCAL ADDITION
2349 (ispell-add-per-file-word-list word))
2350 (replacement ; REPLACEMENT WORD
2351 (delete-region start end)
2352 (setq word (if (atom replacement) replacement (car replacement))
2353 cursor-location (+ (- (length word) (- end start))
2354 cursor-location))
2355 (insert word)
2356 (if (not (atom replacement)) ; recheck spelling of replacement.
2357 (progn
2358 (goto-char cursor-location)
2359 (ispell-word nil t)))))
2360 (if (get-buffer ispell-choices-buffer)
2361 (kill-buffer ispell-choices-buffer))))
2362 (ispell-pdict-save ispell-silently-savep)
2363 (goto-char cursor-location)))
2364
2365
2366;;;###autoload
2367(defun ispell-complete-word-interior-frag ()
4b03da72 2368 "Completes word matching character sequence inside a word."
007852e0
RS
2369 (interactive)
2370 (ispell-complete-word t))
2371
e29702dd 2372
0349bab6
RS
2373;;; **********************************************************************
2374;;; Ispell Minor Mode
2375;;; **********************************************************************
2376
2377(defvar ispell-minor-mode nil
2378 "Non-nil if Ispell minor mode is enabled.")
2379;; Variable indicating that ispell minor mode is active.
2380(make-variable-buffer-local 'ispell-minor-mode)
2381
2382(or (assq 'ispell-minor-mode minor-mode-alist)
2383 (setq minor-mode-alist
2384 (cons '(ispell-minor-mode " Spell") minor-mode-alist)))
2385
2386(defvar ispell-minor-keymap
2387 (let ((map (make-sparse-keymap)))
2388 (define-key map " " 'ispell-minor-check)
2389 (define-key map "\r" 'ispell-minor-check)
2390 map)
2391 "Keymap used for Ispell minor mode.")
2392
2393(or (not (boundp 'minor-mode-map-alist))
2394 (assoc 'ispell-minor-mode minor-mode-map-alist)
2395 (setq minor-mode-map-alist
2396 (cons (cons 'ispell-minor-mode ispell-minor-keymap)
2397 minor-mode-map-alist)))
2398
2399;;;###autoload
2400(defun ispell-minor-mode (&optional arg)
2401 "Toggle Ispell minor mode.
2402With prefix arg, turn Ispell minor mode on iff arg is positive.
2403
2404In Ispell minor mode, pressing SPC or RET
f5136913
RS
2405warns you if the previous word is incorrectly spelled.
2406
2407All the buffer-local variables and dictionaries are ignored -- to read
2408them into the running ispell process, type \\[ispell-word] SPC."
0349bab6
RS
2409 (interactive "P")
2410 (setq ispell-minor-mode
2411 (not (or (and (null arg) ispell-minor-mode)
2412 (<= (prefix-numeric-value arg) 0))))
2bcf8edb 2413 (force-mode-line-update))
0349bab6
RS
2414
2415(defun ispell-minor-check ()
f5136913
RS
2416 "Check previous word then continue with the normal binding of this key.
2417Don't check previous word when character before point is a space or newline.
2418Don't read buffer-local settings or word lists."
0349bab6
RS
2419 (interactive "*")
2420 (let ((ispell-minor-mode nil)
f5136913
RS
2421 (ispell-check-only t)
2422 (last-char (char-after (1- (point)))))
2423 (if (or (eq last-char ?\ ) (eq last-char ?\n))
2424 nil
2425 (save-window-excursion
2426 (save-restriction
2427 (narrow-to-region (save-excursion (forward-line -1) (point)) (point))
2428 (ispell-word nil t))))
0349bab6 2429 (call-interactively (key-binding (this-command-keys)))))
007852e0 2430
e29702dd 2431
007852e0
RS
2432;;; **********************************************************************
2433;;; Ispell Message
2434;;; **********************************************************************
7492978d
RS
2435;;; Original from D. Quinlan, E. Bradford, A. Albert, and M. Ernst
2436
2437
2438(defvar ispell-message-text-end
2439 (mapconcat (function identity)
2440 '(
f5136913
RS
2441 ;; Don't spell check signatures
2442 "^-- $"
7492978d 2443 ;; Matches postscript files.
8ce8687e 2444 "^%!PS-Adobe-[123].0"
7492978d
RS
2445 ;; Matches uuencoded text
2446 "^begin [0-9][0-9][0-9] .*\nM.*\nM.*\nM"
2447 ;; Matches shell files (esp. auto-decoding)
e29702dd 2448 "^#! /bin/[ck]?sh"
8581f180 2449 ;; Matches context difference listing
f5136913
RS
2450 "\\(\\(^cd .*\n\\)?diff -c .*\\)?\n\\*\\*\\* .*\n--- .*\n\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*"
2451 ;; Matches unidiff difference listing
2452 "\\(diff -u .*\\)?\n--- .*\n\\+\\+\\+ .*\n@@ [-+][0-9]+,[0-9]+ [-+][0-9]+,[0-9]+ @@\n"
2453 ;; Matches reporter.el bug report
2454 "^current state:\n==============\n"
2455 ;; Matches commonly used "cut" boundaries
2456 "^\\(- \\)?[-=_]+\\s ?\\(cut here\\|Environment Follows\\)")
7492978d
RS
2457 "\\|")
2458 "*End of text which will be checked in ispell-message.
e29702dd 2459If it is a string, limit at first occurrence of that regular expression.
7492978d 2460Otherwise, it must be a function which is called to get the limit.")
007852e0 2461
4b03da72 2462
8ce8687e 2463
007852e0
RS
2464;;;###autoload
2465(defun ispell-message ()
2466 "Check the spelling of a mail message or news post.
2467Don't check spelling of message headers except the Subject field.
2468Don't check included messages.
2469
6ec7837b
RS
2470To abort spell checking of a message region and send the message anyway,
2471use the `x' command. (Any subsequent regions will be checked.)
a9210a53 2472The `X' command aborts the message send so that you can edit the buffer.
007852e0
RS
2473
2474To spell-check whenever a message is sent, include the appropriate lines
2475in your .emacs file:
f5136913
RS
2476 (add-hook 'message-send-hook 'ispell-message) ;; GNUS 5
2477 (add-hook 'news-inews-hook 'ispell-message) ;; GNUS 4
007852e0
RS
2478 (add-hook 'mail-send-hook 'ispell-message)
2479 (add-hook 'mh-before-send-letter-hook 'ispell-message)
2480
e29702dd 2481You can bind this to the key C-c i in GNUS or mail by adding to
a9210a53 2482`news-reply-mode-hook' or `mail-mode-hook' the following lambda expression:
007852e0
RS
2483 (function (lambda () (local-set-key \"\\C-ci\" 'ispell-message)))"
2484 (interactive)
7492978d 2485 (save-excursion
4b03da72 2486 (goto-char (point-min))
f5136913
RS
2487 (let* (
2488 ;; Nil when message came from outside (eg calling emacs as editor)
2489 ;; Non-nil marker of end of headers.
2490 (internal-messagep
2491 (re-search-forward
2492 (concat "^" (regexp-quote mail-header-separator) "$") nil t))
2493 (end-of-headers ; Start of body.
2494 (copy-marker
2495 (or internal-messagep
2496 (re-search-forward "^$" nil t)
2497 (point-min))))
2498 (limit (copy-marker ; End of region we will spell check.
4b03da72
RS
2499 (cond
2500 ((not ispell-message-text-end) (point-max))
2501 ((char-or-string-p ispell-message-text-end)
2502 (if (re-search-forward ispell-message-text-end nil t)
2503 (match-beginning 0)
2504 (point-max)))
2505 (t (min (point-max) (funcall ispell-message-text-end))))))
f5136913
RS
2506 (default-prefix ; Vanilla cite prefix (just used for cite-regexp)
2507 (if (and (boundp 'mail-yank-prefix) mail-yank-prefix)
2508 (ispell-non-empty-string mail-yank-prefix)
2509 " \\|\t"))
2510 (cite-regexp ;Prefix of quoted text
7492978d
RS
2511 (cond
2512 ((featurep 'supercite) ; sc 3.0
2513 (concat "\\(" (sc-cite-regexp) "\\)" "\\|"
2514 (ispell-non-empty-string sc-reference-tag-string)))
2515 ((featurep 'sc) ; sc 2.3
2516 (concat "\\(" sc-cite-regexp "\\)" "\\|"
2517 (ispell-non-empty-string sc-reference-tag-string)))
f5136913
RS
2518 ((or (equal major-mode 'news-reply-mode) ;GNUS 4 & below
2519 (equal major-mode 'message-mode)) ;GNUS 5
7492978d 2520 (concat "In article <" "\\|"
f5136913
RS
2521 "[^,;&+=]+ <[^,;&+=]+> writes:" "\\|"
2522 default-prefix))
7492978d
RS
2523 ((equal major-mode 'mh-letter-mode) ; mh mail message
2524 (ispell-non-empty-string mh-ins-buf-prefix))
f5136913 2525 ((not internal-messagep) ; Assume nn sent us this message.
7492978d
RS
2526 (concat "In [a-zA-Z.]+ you write:" "\\|"
2527 "In <[^,;&+=]+> [^,;&+=]+ writes:" "\\|"
2528 " *> *"))
2529 ((boundp 'vm-included-text-prefix) ; VM mail message
2530 (concat "[^,;&+=]+ writes:" "\\|"
2531 (ispell-non-empty-string vm-included-text-prefix)))
f5136913
RS
2532 (t default-prefix)))
2533 (ispell-skip-region-alist
2534 (cons (list (concat "^\\(" cite-regexp "\\)")
2535 (function forward-line))
2536 ispell-skip-region-alist))
4b03da72
RS
2537 (old-case-fold-search case-fold-search)
2538 (case-fold-search t)
f5136913 2539 (dictionary-alist ispell-message-dictionary-alist)
4b03da72 2540 (ispell-checking-message t))
f5136913
RS
2541
2542 ;; Select dictionary for message
2543 (or (local-variable-p 'ispell-local-dictionary (current-buffer))
2544 (while dictionary-alist
2545 (goto-char (point-min))
2546 (if (re-search-forward (car (car dictionary-alist))
2547 end-of-headers t)
2548 (setq ispell-local-dictionary (cdr (car dictionary-alist))
2549 dictionary-alist nil)
2550 (setq dictionary-alist (cdr dictionary-alist)))))
2551
2552 (unwind-protect
2553 (progn
2554 ;; Spell check any original Subject:
2555 (goto-char (point-min))
2556 (if (re-search-forward "^Subject: *" end-of-headers t)
2557 (progn
2558 (goto-char (match-end 0))
2559 (if (and (not (looking-at ".*Re\\>"))
2560 (not (looking-at "\\[")))
2561 (let ((case-fold-search old-case-fold-search))
2562 (ispell-region (point)
2563 (progn ;Tab-initiated continuation lns.
2564 (end-of-line)
2565 (while (looking-at "\n[ \t]")
2566 (end-of-line 2))
2567 (point)))))))
2568 (goto-char end-of-headers)
2569 (forward-line 1)
2570 (ispell-region (point) limit))
2571 (set-marker end-of-headers nil)
2572 (set-marker limit nil)))))
4b03da72 2573
007852e0
RS
2574
2575(defun ispell-non-empty-string (string)
2576 (if (or (not string) (string-equal string ""))
2577 "\\'\\`" ; An unmatchable string if string is null.
2578 (regexp-quote string)))
2579
2580
2581;;; **********************************************************************
2582;;; Buffer Local Functions
2583;;; **********************************************************************
2584
2585
2586(defun ispell-accept-buffer-local-defs ()
f5136913 2587 "Load all buffer-local information, restarting Ispell when necessary."
007852e0
RS
2588 (ispell-buffer-local-dict) ; May kill ispell-process.
2589 (ispell-buffer-local-words) ; Will initialize ispell-process.
2590 (ispell-buffer-local-parsing))
2591
2592
007852e0 2593(defun ispell-buffer-local-parsing ()
a9210a53 2594 "Place Ispell into parsing mode for this buffer.
4b03da72 2595Overrides the default parsing mode.
f5136913 2596Includes Latex/Nroff modes and extended character mode."
007852e0
RS
2597 ;; (ispell-init-process) must already be called.
2598 (process-send-string ispell-process "!\n") ; Put process in terse mode.
2599 ;; We assume all major modes with "tex-mode" in them should use latex parsing
2600 (if (or (and (eq ispell-parser 'use-mode-name)
2601 (string-match "[Tt][Ee][Xx]-mode" (symbol-name major-mode)))
2602 (eq ispell-parser 'tex))
f5136913
RS
2603 (progn
2604 (process-send-string ispell-process "+\n") ; set ispell mode to tex
2605 (if (not (eq ispell-parser 'tex))
2606 (set (make-local-variable 'ispell-parser) 'tex)))
007852e0 2607 (process-send-string ispell-process "-\n")) ; set mode to normal (nroff)
f5136913
RS
2608 ;; If needed, test for SGML & HTML modes and set a buffer local nil/t value.
2609 (if (and ispell-skip-sgml (not (eq ispell-skip-sgml t)))
2610 (set (make-local-variable 'ispell-skip-sgml)
2611 (not (null (let ((case-fold-search t))
2612 (string-match "sgml\\|html"
2613 (symbol-name major-mode)))))))
007852e0
RS
2614 ;; Set default extended character mode for given buffer, if any.
2615 (let ((extended-char-mode (ispell-get-extended-character-mode)))
2616 (if extended-char-mode
2617 (process-send-string ispell-process (concat extended-char-mode "\n"))))
e29702dd 2618 ;; Set buffer-local parsing mode and extended character mode, if specified.
007852e0 2619 (save-excursion
f5136913
RS
2620 (goto-char (point-max))
2621 ;; Uses last occurrence of ispell-parsing-keyword
2622 (if (search-backward ispell-parsing-keyword nil t)
2623 (let ((end (save-excursion (end-of-line) (point)))
2624 (case-fold-search t)
2625 string)
2626 (search-forward ispell-parsing-keyword)
2627 (while (re-search-forward " *\\([^ \"]+\\)" end t)
2628 ;; space separated definitions.
2629 (setq string (buffer-substring-no-properties (match-beginning 1)
2630 (match-end 1)))
2631 (cond ((string-match "latex-mode" string)
2632 (process-send-string ispell-process "+\n~tex\n"))
2633 ((string-match "nroff-mode" string)
2634 (process-send-string ispell-process "-\n~nroff"))
2635 ((string-match "~" string) ; Set extended character mode.
2636 (process-send-string ispell-process (concat string "\n")))
2637 (t (message "Invalid Ispell Parsing argument!")
2638 (sit-for 2))))))))
007852e0
RS
2639
2640
2641;;; Can kill the current ispell process
2642
2643(defun ispell-buffer-local-dict ()
f5136913 2644 "Initializes local dictionary and local personal dictionary.
007852e0 2645When a dictionary is defined in the buffer (see variable
a9210a53 2646`ispell-dictionary-keyword'), it will override the local setting
007852e0
RS
2647from \\[ispell-change-dictionary].
2648Both should not be used to define a buffer-local dictionary."
2649 (save-excursion
2650 (goto-char (point-min))
2651 (let (end)
2652 ;; Override the local variable definition.
f5136913
RS
2653 ;; Uses last occurrence of ispell-dictionary-keyword.
2654 (goto-char (point-max))
2655 (if (search-backward ispell-dictionary-keyword nil t)
2656 (progn
2657 (search-forward ispell-dictionary-keyword)
2658 (setq end (save-excursion (end-of-line) (point)))
2659 (if (re-search-forward " *\\([^ \"]+\\)" end t)
2660 (setq ispell-local-dictionary
2661 (buffer-substring-no-properties (match-beginning 1)
2662 (match-end 1))))))
2663 (goto-char (point-max))
2664 (if (search-backward ispell-pdict-keyword nil t)
2665 (progn
2666 (search-forward ispell-pdict-keyword)
2667 (setq end (save-excursion (end-of-line) (point)))
2668 (if (re-search-forward " *\\([^ \"]+\\)" end t)
2669 (setq ispell-local-pdict
2670 (buffer-substring-no-properties (match-beginning 1)
2671 (match-end 1))))))))
007852e0
RS
2672 ;; Reload if new personal dictionary defined.
2673 (if (and ispell-local-pdict
2674 (not (equal ispell-local-pdict ispell-personal-dictionary)))
2675 (progn
2676 (ispell-kill-ispell t)
2677 (setq ispell-personal-dictionary ispell-local-pdict)))
2678 ;; Reload if new dictionary defined.
2679 (if (and ispell-local-dictionary
2680 (not (equal ispell-local-dictionary ispell-dictionary)))
2681 (ispell-change-dictionary ispell-local-dictionary)))
2682
2683
2684(defun ispell-buffer-local-words ()
a9210a53 2685 "Loads the buffer-local dictionary in the current buffer."
007852e0
RS
2686 (if (and ispell-buffer-local-name
2687 (not (equal ispell-buffer-local-name (buffer-name))))
2688 (progn
2689 (ispell-kill-ispell t)
2690 (setq ispell-buffer-local-name nil)))
2691 (ispell-init-process)
2692 (save-excursion
2693 (goto-char (point-min))
2694 (while (search-forward ispell-words-keyword nil t)
2695 (or ispell-buffer-local-name
2696 (setq ispell-buffer-local-name (buffer-name)))
2697 (let ((end (save-excursion (end-of-line) (point)))
f5136913 2698 (ispell-casechars (ispell-get-casechars))
007852e0 2699 string)
e29702dd 2700 ;; buffer-local words separated by a space, and can contain
f5136913 2701 ;; any character other than a space. Not rigorous enough.
7195bb71 2702 (while (re-search-forward " *\\([^ ]+\\)" end t)
f5136913
RS
2703 (setq string (buffer-substring-no-properties (match-beginning 1)
2704 (match-end 1)))
2705 ;; This can fail when string contains a word with illegal chars.
2706 ;; Error handling needs to be added between ispell and emacs.
2707 (if (and (< 1 (length string))
2708 (equal 0 (string-match ispell-casechars string)))
2709 (process-send-string ispell-process
2710 (concat "@" string "\n"))))))))
007852e0
RS
2711
2712
2713;;; returns optionally adjusted region-end-point.
2714
f5136913 2715(defun ispell-add-per-file-word-list (word)
007852e0
RS
2716 "Adds new word to the per-file word list."
2717 (or ispell-buffer-local-name
2718 (setq ispell-buffer-local-name (buffer-name)))
007852e0
RS
2719 (save-excursion
2720 (goto-char (point-min))
4b03da72 2721 (let (case-fold-search line-okay search done string)
007852e0
RS
2722 (while (not done)
2723 (setq search (search-forward ispell-words-keyword nil 'move)
2724 line-okay (< (+ (length word) 1 ; 1 for space after word..
2725 (progn (end-of-line) (current-column)))
2726 80))
2727 (if (or (and search line-okay)
2728 (null search))
2729 (progn
2730 (setq done t)
2731 (if (null search)
2732 (progn
2733 (open-line 1)
2734 (setq string (concat comment-start " "
2735 ispell-words-keyword))
007852e0
RS
2736 (insert string)
2737 (if (and comment-end (not (equal "" comment-end)))
2738 (save-excursion
2739 (open-line 1)
2740 (forward-line 1)
2741 (insert comment-end)))))
f5136913 2742 (insert (concat " " word))))))))
007852e0
RS
2743
2744
f5136913 2745(defconst ispell-version "ispell.el 3.0 -- Tue Apr 28 14:40:01 PDT 1998")
007852e0
RS
2746
2747(provide 'ispell)
2748
2749\f
2750;;; LOCAL VARIABLES AND BUFFER-LOCAL VALUE EXAMPLES.
2751
2752;;; Local Variable options:
2753;;; mode: name(-mode)
2754;;; eval: expression
2755;;; local-variable: value
2756
f5136913
RS
2757;;; The following sets the buffer local dictionary to 'american' English
2758;;; and spell checks only comments.
007852e0
RS
2759
2760;;; Local Variables:
2761;;; mode: emacs-lisp
2762;;; comment-column: 40
f5136913
RS
2763;;; ispell-check-comments: exclusive
2764;;; Local IspellDict: "american"
007852e0
RS
2765;;; End:
2766
2767
2768;;; MORE EXAMPLES OF ISPELL BUFFER-LOCAL VALUES
2769
2770;;; The following places this file in nroff parsing and extended char modes.
2771;;; Local IspellParsing: nroff-mode ~nroff
007852e0
RS
2772;;; Change IspellPersDict to IspellPersDict: to enable the following line.
2773;;; Local IspellPersDict ~/.ispell_lisp
2774;;; The following were automatically generated by ispell using the 'A' command:
f5136913
RS
2775; LocalWords: Moellmann copyleft Dansk russian KOI charset minipage hspace mh
2776; LocalWords: unsplitable includeonly nocite epsfig displaymath eqnarray init
2777; LocalWords: settable autoload inews frag pdict alist Wildcards iconify arg
2778; LocalWords: tex alists minibuffer Autoloading setq changelog kss stevens reg
2779; LocalWords: Castellano framepop sgml modeline Wedler Dirk Froembgen fn Gerd
2780; LocalWords: pgp NZST Vignaux autoloaded loaddefs aff Francais Nederlands SPC
2781; LocalWords: popup nonmenu regexp herr num pers dict unhighlight ccept uit NB
2782; LocalWords: buf grep sync prev inc hilight olddot AIX ersion msg read's op
94487c4e 2783; LocalWords: bufs pt multibyte cmd Quinlan uuencoded esp unidiff eg sc
f5136913
RS
2784; LocalWords: VM lns HTML eval american IspellPersDict
2785
2786;;; ispell.el ends here
007852e0 2787