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