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