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