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