1 ;;;;;;;;;;;;;;;;;;;;;;;;;;; -*- Mode: emacs-lisp -*- ;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ;;; GNU EMACS interface for International Ispell Version 3.1 by Geoff Kuenning.
5 ;;; Copyright (C) 1994 Free Software Foundation, Inc.
8 ;;; Authors : Ken Stevens et. al.
9 ;;; Last Modified By: Ken Stevens <k.stevens@ieee.org>
10 ;;; Last Modified On: Tue Feb 15 16:11:14 MST 1994
11 ;;; Update Revision : 2.26
12 ;;; Syntax : emacs-lisp
13 ;;; Status : Release with 3.1.03 ispell.
14 ;;; Version : International Ispell Version 3.1 by Geoff Kuenning.
16 ;;; This file is part of GNU Emacs.
18 ;;; GNU Emacs is free software; you can redistribute it and/or modify
19 ;;; it under the terms of the GNU General Public License as published by
20 ;;; the Free Software Foundation; either version 2, or (at your option)
21 ;;; any later version.
23 ;;; GNU Emacs is distributed in the hope that it will be useful,
24 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
25 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 ;;; GNU General Public License for more details.
28 ;;; You should have received a copy of the GNU General Public License
29 ;;; along with GNU Emacs; see the file COPYING. If not, write to
30 ;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
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
41 ;;; You particularly may want to change the default dictionary for your
42 ;;; country and language.
45 ;;; To fully install this, add this file to your GNU lisp directory and
46 ;;; compile it with M-X byte-compile-file. Then add the following to the
47 ;;; appropriate init file:
49 ;;; (autoload 'ispell-word "ispell"
50 ;;; "Check the spelling of word in buffer." t)
51 ;;; (global-set-key "\e$" 'ispell-word)
52 ;;; (autoload 'ispell-region "ispell"
53 ;;; "Check the spelling of region." t)
54 ;;; (autoload 'ispell-buffer "ispell"
55 ;;; "Check the spelling of buffer." t)
56 ;;; (autoload 'ispell-complete-word "ispell"
57 ;;; "Look up current word in dictionary and try to complete it." t)
58 ;;; (autoload 'ispell-change-dictionary "ispell"
59 ;;; "Change ispell dictionary." t)
60 ;;; (autoload 'ispell-message "ispell"
61 ;;; "Check spelling of mail message or news post.")
63 ;;; Depending on the mail system you use, you may want to include these:
65 ;;; (add-hook 'news-inews-hook 'ispell-message)
66 ;;; (add-hook 'mail-send-hook 'ispell-message)
67 ;;; (add-hook 'mh-before-send-letter-hook 'ispell-message)
70 ;;; Ispell has a TeX parser and a nroff parser (the default).
71 ;;; The parsing is controlled by the variable ispell-parser. Currently
72 ;;; it is just a "toggle" between TeX and nroff, but if more parsers are
73 ;;; added it will be updated. See the variable description for more info.
83 ;;; ispell-complete-word
84 ;;; ispell-complete-word-interior-frag
85 ;;; ispell-change-dictionary
86 ;;; ispell-kill-ispell
90 ;;; Commands in ispell-region:
91 ;;; Character replacement: Replace word with choice. May query-replace.
92 ;;; ' ': Accept word this time.
93 ;;; 'i': Accept word and insert into private dictionary.
94 ;;; 'a': Accept word for this session.
95 ;;; 'A': Accept word and place in buffer-local dictionary.
96 ;;; 'r': Replace word with typed-in value. Rechecked.
97 ;;; 'R': Replace word with typed-in value. Query-replaced in buffer. Rechecked.
98 ;;; '?': Show these commands
99 ;;; 'x': Exit spelling buffer. Move cursor to original point.
100 ;;; 'X': Exit spelling buffer. Leave cursor at the current point.
101 ;;; 'q': Quit spelling session (Kills ispell process).
102 ;;; 'l': Look up typed-in replacement in alternate dictionary. Wildcards okay.
103 ;;; 'u': Like 'i', but the word is lower-cased first.
104 ;;; 'm': Like 'i', but allows one to include dictionary completion info.
105 ;;; 'C-l': redraws screen
106 ;;; 'C-r': recursive edit
107 ;;; 'C-z': suspend emacs
109 ;;; Buffer-Local features:
110 ;;; There are a number of buffer-local features that can be used to customize
111 ;;; ispell for the current buffer. This includes language dictionaries,
112 ;;; personal dictionaries, parsing, and local word spellings. Each of these
113 ;;; local customizations are done either through local variables, or by
114 ;;; including the keyword and argument(s) at the end of the buffer (usually
115 ;;; prefixed by the comment characters). See the end of this file for
116 ;;; examples. The local keywords and variables are:
118 ;;; ispell-dictionary-keyword language-dictionary
119 ;;; uses local variable ispell-local-dictionary
120 ;;; ispell-pdict-keyword personal-dictionary
121 ;;; uses local variable ispell-local-pdict
122 ;;; ispell-parsing-keyword mode-arg extended-char-arg
123 ;;; ispell-words-keyword any number of local word spellings
127 ;;; Highlighting in version 19 still doesn't work on tty's.
128 ;;; On some versions of emacs, growing the minibuffer fails.
133 ;;; name changes for copyright assignment. Added word-frags in complete-word.
134 ;;; Horizontal scroll (John Conover) Query-replace matches words now. bugs.
137 ;;; minor mods, upgraded ispell-message
140 ;;; query-replace more robust, messages, defaults, ispell-change-dict.
142 ;;; Revision 2.23 1993/11/22 23:47:03 stevens
143 ;;; ispell-message, Fixed highlighting, added menu-bar, fixed ispell-help, ...
146 ;;; Added 'u' command. Fixed default in ispell-local-dictionary.
147 ;;; fixed affix rules display. Tib skipping more robust. Contributions by
148 ;;; Per Abraham (parser selection), Denis Howe, and Eberhard Mattes.
150 ;;; Revision 2.21 1993/06/30 14:09:04 stevens
151 ;;; minor bugs. (nroff word skipping fixed)
153 ;;; Revision 2.20 1993/06/30 14:09:04 stevens
155 ;;; Debugging and contributions by: Boris Aronov, Rik Faith, Chris Moore,
156 ;;; Kevin Rodgers, Malcolm Davis.
157 ;;; Particular thanks to Michael Lipp, Jamie Zawinski, Phil Queinnec
158 ;;; and John Heidemann for suggestions and code.
159 ;;; Major update including many tweaks.
160 ;;; Many changes were integrations of suggestions.
161 ;;; lookup-words rehacked to use call-process (Jamie).
162 ;;; ispell-complete-word rehacked to be compatible with the rest of the
163 ;;; system for word searching and to include multiple wildcards,
164 ;;; and it's own dictionary.
165 ;;; query-replace capability added. New options 'X', 'R', and 'A'.
166 ;;; buffer-local modes for dictionary, word-spelling, and formatter-parsing.
167 ;;; Many random bugs, like commented comments being skipped, fix to
168 ;;; keep-choices-win, fix for math mode, added pipe mode choice,
169 ;;; fixed 'q' command, ispell-word checks previous word and leave cursor
170 ;;; in same location. Fixed tib code which could drop spelling regions.
171 ;;; Cleaned up setq calls for efficiency. Gave more context on window overlays.
172 ;;; Assure context on ispell-command-loop. Window lossage in look cmd fixed.
173 ;;; Due to pervasive opinion, common-lisp package syntax removed. Display
174 ;;; problem when not highlighting.
176 ;;; Revision 2.19 1992/01/10 10:54:08 geoff
177 ;;; Make another attempt at fixing the "Bogus, dude" problem. This one is
178 ;;; less elegant, but has the advantage of working.
180 ;;; Revision 2.18 1992/01/07 10:04:52 geoff
181 ;;; Fix the "Bogus, Dude" problem in ispell-word.
183 ;;; Revision 2.17 1991/09/12 00:01:42 geoff
184 ;;; Add some changes to make ispell-complete-word work better, though
185 ;;; still not perfectly.
187 ;;; Revision 2.16 91/09/04 18:00:52 geoff
188 ;;; More updates from Sebastian, to make the multiple-dictionary support
191 ;;; Revision 2.15 91/09/04 17:30:02 geoff
192 ;;; Sebastian Kremer's tib support
194 ;;; Revision 2.14 91/09/04 16:19:37 geoff
195 ;;; Don't do set-window-start if the move-to-window-line moved us
196 ;;; downward, rather than upward. This prevents getting the buffer all
197 ;;; confused. Also, don't use the "not-modified" function to clear the
198 ;;; modification flag; instead use set-buffer-modified-p. This prevents
199 ;;; extra messages from flashing.
201 ;;; Revision 2.13 91/09/04 14:35:41 geoff
202 ;;; Fix a spelling error in a comment. Add code to handshake with the
203 ;;; ispell process before sending anything to it.
205 ;;; Revision 2.12 91/09/03 20:14:21 geoff
206 ;;; Add Sebastian Kremer's multiple-language support.
210 ;;; Texas Instruments - Computer Science Center
211 ;;; ARPA: Buehring%TI-CSL@CSNet-Relay
212 ;;; UUCP: {smu, texsun, im4u, rice} ! ti-csl ! buehring
214 ;;; ispell-region and associated routines added by
217 ;;; Tue Jan 13 20:18:02 CST 1987
219 ;;; extensively modified by Mark Davies and Andrew Vignaux
220 ;;; {mark,andrew}@vuwcomp
221 ;;; Sun May 10 11:45:04 NZST 1987
223 ;;; Ken Stevens ARPA: k.stevens@ieee.org
224 ;;; Tue Jan 3 16:59:07 PST 1989
225 ;;; This file has overgone a major overhaul to be compatible with ispell
226 ;;; version 2.1. Most of the functions have been totally rewritten, and
227 ;;; many user-accessible variables have been added. The syntax table has
228 ;;; been removed since it didn't work properly anyway, and a filter is
229 ;;; used rather than a buffer. Regular expressions are used based on
230 ;;; ispell's internal definition of characters (see ispell(4)).
231 ;;; Some new updates:
232 ;;; - Updated to version 3.0 to include terse processing.
233 ;;; - Added a variable for the look command.
234 ;;; - Fixed a bug in ispell-word when cursor is far away from the word
235 ;;; that is to be checked.
236 ;;; - Ispell places the incorrect word or guess in the minibuffer now.
237 ;;; - fixed a bug with 'l' option when multiple windows are on the screen.
238 ;;; - lookup-words just didn't work with the process filter. Fixed.
239 ;;; - Rewrote the process filter to make it cleaner and more robust
240 ;;; in the event of a continued line not being completed.
241 ;;; - Made ispell-init-process more robust in handling errors.
242 ;;; - Fixed bug in continuation location after a region has been modified by
243 ;;; correcting a misspelling.
246 ;;; Sebastian Kremer <sk@thp.uni-koeln.de>
247 ;;; Wed Aug 7 14:02:17 MET DST 1991
248 ;;; - Ported ispell-complete-word from Ispell 2 to Ispell 3.
249 ;;; - Added ispell-kill-ispell command.
250 ;;; - Added ispell-dictionary and ispell-dictionary-alist variables to
251 ;;; support other than default language. See their docstrings and
252 ;;; command ispell-change-dictionary.
253 ;;; - (ispelled it :-)
254 ;;; - Added ispell-skip-tib variable to support the tib bibliography
258 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
262 ;;; **********************************************************************
263 ;;; The following variables should be set according to personal preference
264 ;;; and location of binaries:
265 ;;; **********************************************************************
268 ;;; ******* THIS FILE IS WRITTEN FOR ISPELL VERSION 3.1
271 (defvar ispell-highlight-p t
272 "*When not nil, spelling errors will be highlighted.")
274 (defvar ispell-highlight-face
'highlight
275 "*The face used for ispell highlighting. For Emacses with overlays.
276 Common values for GNU emacs are highlight, modeline, secondary-selection,
277 region, and underline.
278 This variable can be set by the user to whatever face they desire.
279 It's most convenient if the cursor color and highlight color are
280 slightly different.")
282 (defvar ispell-check-comments nil
283 "*When true, the spelling of comments in region is checked.")
285 (defvar ispell-query-replace-choices nil
286 "*When true and spell checking a region, the correction will be made
287 throughout the buffer using \\[query-replace].")
289 (defvar ispell-skip-tib nil
290 "*If non-nil, the spelling of references for the tib(1) bibliography
291 program are skipped. Otherwise any text between strings matching the regexps
292 ispell-tib-ref-beginning and ispell-tib-ref-end is ignored.
294 TeX users beware: Any field starting with [. will skip until a .] -- even
295 your whole buffer -- unless you set ispell-skip-tib to nil. That includes
296 a [.5mm] type of number....")
298 (defvar ispell-tib-ref-beginning
"[[<]\\."
299 "Regexp matching the beginning of a Tib reference.")
301 (defvar ispell-tib-ref-end
"\\.[]>]"
302 "Regexp matching the end of a Tib reference.")
304 (defvar ispell-keep-choices-win t
305 "*When not nil, the *Choices* window remains for spelling session.
306 This minimizes redisplay thrashing.")
308 (defvar ispell-choices-win-default-height
2
309 "*The default size of the *Choices*, including status line.
310 Must be greater than 1.")
312 (defvar ispell-program-name
"ispell"
313 "Program invoked by \\[ispell-word] and \\[ispell-region] commands.")
315 (defvar ispell-alternate-dictionary
316 (cond ((file-exists-p "/usr/dict/web2") "/usr/dict/web2")
317 ((file-exists-p "/usr/dict/words") "/usr/dict/words")
318 ((file-exists-p "/usr/lib/dict/words") "/usr/lib/dict/words")
319 ((file-exists-p "/sys/dict") "/sys/dict")
320 (t "/usr/dict/words"))
321 "*Alternate dictionary for spelling help.")
323 (defvar ispell-complete-word-dict ispell-alternate-dictionary
324 "*Dictionary used for word completion.")
326 (defvar ispell-grep-command
"/usr/bin/egrep"
327 "Name of the grep command for search processes.")
329 (defvar ispell-grep-options
"-i"
330 "Options for ispell-grep-command.
331 Should probably be \"-i\" or \"-e\".
332 Some machines (like the NeXT) don't support \"-i\"")
334 (defvar ispell-look-command
"/usr/bin/look"
335 "Name of the look command for search processes.
336 Must contain complete path!")
338 (defvar ispell-look-p
(file-exists-p ispell-look-command
)
339 "*Use look. Should be nil if your UNIX doesn't have this program.
340 Attempts to automatically reset if look not available")
342 (defvar ispell-have-new-look nil
343 "*Non-nil means use the `-r' option (regexp) when running `look'.")
345 (defvar ispell-look-options
(if ispell-have-new-look
"-dfr" "-df")
346 "Options for ispell-look-command")
348 (defvar ispell-use-ptys-p nil
349 "When t, emacs will use pty's to communicate with ispell.
350 When nil, emacs will use pipes.")
352 (defvar ispell-following-word nil
353 "*If non-nil the \\[ispell-word] command will check the spelling
354 of the word under or following \(rather than preceding\) the cursor
355 when called interactively.")
357 (defvar ispell-help-in-bufferp t
358 "*If non-nil, the \\[ispell-help] command will display its
359 message in a buffer. Otherwise the minibuffer will be used.")
361 (defvar ispell-quietly nil
362 "*If non-nil, the \\[ispell-word] command will suppress all
363 non-corrective messages when called interactively.")
365 (defvar ispell-format-word
(function upcase
)
366 "*The function called to format the word whose spelling is being checked,
367 in diagnostic messages to the user. The function must take one string
368 argument and return a string.")
370 (defvar ispell-personal-dictionary nil
371 "*A string or nil. If nil, the default directory, ~/.ispell_words is used.")
373 (defvar ispell-silently-savep nil
374 "*When non-nil, save the personal dictionary without user verification.")
376 ;;; This variable contains the current dictionary being used if the ispell
377 ;;; process is running. Otherwise it contains the global default.
378 (defvar ispell-dictionary nil
379 "If non-nil, a dictionary to use instead of the default one.
380 This is passed to the ispell process using the \"-d\" switch and is
381 used as key in ispell-dictionary-alist (which see).
383 You should set this variable before your first call to ispell (e.g. in
384 your .emacs), or use the \\[ispell-change-dictionary] command to
385 change it, as changing this variable only takes effect in a newly
386 started ispell process.")
389 (defvar ispell-dictionary-alist
; sk 9-Aug-1991 18:28
390 '((nil ; default (english.aff)
391 "[A-Za-z]" "[^A-Za-z]" "[-']" nil
("-B") nil
)
392 ("english" ; make english explicitly selectable
393 "[A-Za-z]" "[^A-Za-z]" "[-']" nil
("-B") nil
)
394 ("deutsch" ; deutsch.aff
395 "[a-zA-Z\"]" "[^a-zA-Z\"]" "[-']" t
("-C") nil
)
397 "[a-zA-Z\304\326\334\344\366\337\374]"
398 "[^a-zA-Z\304\326\334\344\366\337\374]"
399 "[-']" t
("-C" "-d" "deutsch") "~latin1")
400 ("nederlands8" ; dutch8.aff
401 "[A-Za-z\300-\305\307\310-\317\322-\326\331-\334\340-\345\347\350-\357\361\362-\366\371-\374]"
402 "[^A-Za-z\300-\305\307\310-\317\322-\326\331-\334\340-\345\347\350-\357\361\362-\366\371-\374]"
404 ("svenska" ;7 bit swedish mode
405 "[A-Za-z}{|\\133\\135\\\\]" "[^A-Za-z}{|\\133\\135\\\\]"
406 "[-']" nil
("-C") nil
)
407 ("svenska8" ;8 bit swedish mode
408 "[A-Za-z\345\344\366\305\304\366]" "[^A-Za-z\345\344\366\305\304\366]"
409 "[-']" nil
("-C" "-d" "svenska") "~list") ; Add `"-T" "list"' instead?
411 "[A-Za-z]" "[^A-Za-z]" "[-`'\^]" nil nil nil
)
413 "[A-Z\306\330\305a-z\346\370\345]" "[^A-Z\306\330\305a-z\346\370\345]"
414 "[-]" nil
("-C") nil
)
416 "An alist of dictionaries and their associated parameters.
418 Each element of this list is also a list:
421 CASECHARS NOT-CASECHARS OTHERCHARS MANY-OTHERCHARS-P
422 ISPELL-ARGS EXTENDED-CHARACTER-MODE\)
424 DICTIONARY-NAME is a possible value of variable ispell-dictionary, nil
425 means the default dictionary.
427 CASECHARS is a regular expression of valid characters that comprise a
430 NOT-CASECHARS is the opposite regexp of CASECHARS.
432 OTHERCHARS is a regular expression of other characters that are valid
433 in word constructs. Otherchars cannot be adjacent to each other in a
434 word, nor can they begin or end a word. This implies we can't check
435 \"Stevens'\" as a correct possessive and other correct formations.
437 Hint: regexp syntax requires the hyphen to be declared first here.
439 MANY-OTHERCHARS-P is non-nil if many otherchars are to be allowed in a
440 word instead of only one.
442 ISPELL-ARGS is a list of additional arguments passed to the ispell
445 EXTENDED-CHARACTER-MODE should be used when dictionaries are used which
446 have been configured in ispell's parse.y. (For example, umlauts
447 can be encoded as \\\"a, a\\\", \"a, ...) Defaults are ~tex and ~nroff
448 in english. This has the same effect as the command-line `-T' option.
449 The buffer Major Mode controls ispell's parsing in tex or nroff mode,
450 but the dictionary can control the extended character mode.
451 Both defaults can be overruled in a buffer-local fashion. See
452 ispell-parsing-keyword for details on this.
454 Note that the CASECHARS and OTHERCHARS slots of the alist should
455 contain the same character set as casechars and otherchars in the
456 language.aff file \(e.g., english.aff\).")
459 ;;; ispell-menu-map from menu-bar.el
462 (defvar ispell-menu-map nil
)
464 (if (null ispell-menu-map
)
465 (let ((dicts (reverse (cons (cons "default" nil
) ispell-dictionary-alist
)))
467 (setq ispell-menu-map
(make-sparse-keymap "Spell"))
469 (setq name
(car (car dicts
))
472 (define-key ispell-menu-map
(vector (intern name
))
473 (cons (concat "Select " (capitalize name
))
474 (list 'lambda
() '(interactive)
475 (list 'ispell-change-dictionary name
))))))
476 ;; Why do we need an alias here?
477 (defalias 'ispell-menu-map ispell-menu-map
)
478 ;; Define commands in opposite order you want them to appear in menu.
479 (define-key ispell-menu-map
[ispell-change-dictionary
]
480 '("Change Dictionary" . ispell-change-dictionary
))
481 (define-key ispell-menu-map
[ispell-kill-ispell
]
482 '("Kill Process" . ispell-kill-ispell
))
483 (define-key ispell-menu-map
[ispell-pdict-save
]
484 '("Save Dictionary" .
(lambda () (interactive) (ispell-pdict-save t
))))
485 (define-key ispell-menu-map
[ispell-complete-word
]
486 '("Complete Word" . ispell-complete-word
))
487 (define-key ispell-menu-map
[ispell-complete-word-interior-frag
]
488 '("Complete Word Frag" . ispell-complete-word-interior-frag
))
489 (define-key ispell-menu-map
[ispell-continue
]
490 '("Continue Check" . ispell-continue
))
491 (define-key ispell-menu-map
[ispell-region
]
492 '("Check Region" . ispell-region
))
493 (define-key ispell-menu-map
[ispell-word
]
494 '("Check Word" . ispell-word
))
495 (define-key ispell-menu-map
[ispell-buffer
]
496 '("Check Buffer" . ispell-buffer
))
497 (define-key ispell-menu-map
[ispell-message
]
498 '("Check Message" . ispell-message
))
499 (define-key ispell-menu-map
[ispell-help
]
500 '("Help" .
(lambda () (interactive) (describe-function 'ispell-help
))))
505 ;;; **********************************************************************
506 ;;; The following are used by ispell, and should not be changed.
507 ;;; **********************************************************************
510 ;;; This doesn't match the LAST patch number -- this is for 3.1 or 3.0.09
511 (defconst ispell-required-versions
'("3.1." "3.0.09")
512 "Ispell versions with which this version of ispell.el is known to work.")
514 (defun ispell-get-casechars ()
515 (nth 1 (assoc ispell-dictionary ispell-dictionary-alist
)))
516 (defun ispell-get-not-casechars ()
517 (nth 2 (assoc ispell-dictionary ispell-dictionary-alist
)))
518 (defun ispell-get-otherchars ()
519 (nth 3 (assoc ispell-dictionary ispell-dictionary-alist
)))
520 (defun ispell-get-many-otherchars-p ()
521 (nth 4 (assoc ispell-dictionary ispell-dictionary-alist
)))
522 (defun ispell-get-ispell-args ()
523 (nth 5 (assoc ispell-dictionary ispell-dictionary-alist
)))
524 (defun ispell-get-extended-character-mode ()
525 (nth 6 (assoc ispell-dictionary ispell-dictionary-alist
)))
527 (defvar ispell-process nil
528 "Holds the process object for 'ispell'")
530 (defvar ispell-pdict-modified-p nil
531 "T when the personal dictionary has modifications that need to be written.")
533 ;;; If you want to save the dictionary when quitting, must do so explicitly.
534 (defvar ispell-quit nil
535 "Set to t or point when user wants to abort ispell session.")
537 (defvar ispell-filter nil
538 "Output filter from piped calls to ispell.")
540 (defvar ispell-filter-continue nil
541 "Control variable for ispell filter function.")
543 (defvar ispell-process-directory nil
544 "The directory where ispell-process was started.")
546 (defvar ispell-query-replace-marker
(make-marker)
547 "Marker for query-replace processing.")
549 (defvar ispell-checking-message nil
550 "Non-nil when we're checking a mail message")
552 (defconst ispell-choices-buffer
"*Choices*")
554 (defvar ispell-overlay nil
"overlay variable for ispell")
556 ;;; *** Buffer Local Definitions ***
558 ;;; This is the local dictionary to use. When nil the default dictionary will
559 ;;; be used. Do not redefine default value or it will override the global!
560 (defvar ispell-local-dictionary nil
561 "A buffer local variable. If non-nil, a dictionary to be used when running
562 an ispell-command in this buffer. Setting ispell-local-dictionary to a value
563 has the same effect as calling \\[ispell-change-dictionary] with that value.
564 This variable is automatically set when defined in the file with either
565 ispell-dictionary-keyword or the Local Variable syntax.
566 If using Local Variable syntax, the dictionary must be a string.")
568 (make-variable-buffer-local 'ispell-local-dictionary
)
570 ;; Use default directory, unless locally set.
571 (set-default 'ispell-local-dictionary nil
)
573 (defconst ispell-words-keyword
"LocalWords: "
574 "The keyword for local oddly-spelled words to accept.
575 The keyword will be followed by any number of local word spellings.
576 There can be multiple of these keywords in the file.")
578 (defconst ispell-dictionary-keyword
"Local IspellDict: "
579 "The keyword for local dictionary definitions.
580 There should be only one dictionary keyword definition per file, and it
581 should be followed by a correct dictionary name in ispell-dictionary-alist.")
583 (defconst ispell-parsing-keyword
"Local IspellParsing: "
584 "The keyword for overriding default ispell parsing as determined by
585 the buffer's major mode and extended-character mode as determined by the
588 The above keyword string should be followed by `latex-mode' or
589 `nroff-mode' to put the current buffer into the desired parsing mode.
591 Extended character mode can be changed for this buffer by placing
592 a `~' followed by an extended-character mode -- such as `~.tex'.")
594 (defvar ispell-local-pdict ispell-personal-dictionary
595 "A buffer local variable. If a personal dictionary is specified for
596 the current buffer which is different from the current personal dictionary,
597 the effect will be similar to calling \\[ispell-change-dictionary].
598 This variable is automatically set when defined in the file with either
599 ispell-pdict-keyword or the local variable syntax.
600 If using Local variable syntax, the dictionary must be nil or a string.")
602 (make-variable-buffer-local 'ispell-local-pdict
)
604 (defconst ispell-pdict-keyword
"Local IspellPersDict: "
605 "The keyword for defining buffer local dictionaries.")
607 (defvar ispell-buffer-local-name nil
608 "Contains the buffer name if local word definitions were used.
609 Ispell is then restarted because the local words could conflict.")
611 (defvar ispell-parser
'use-mode-name
612 "*Indicates whether ispell should parse the current buffer as TeX Code.
613 Special value 'use-mode-name tries to guess using the name of major-mode.
614 Default parser is 'nroff.
615 Currently the only other valid parser is 'tex.
617 You can set this variable in hooks in your init file -- eg:
619 (add-hook 'tex-mode-hook (function (lambda () (setq ispell-parser 'tex))))")
621 (defvar ispell-region-end
(make-marker)
622 "Marker that allows spelling continuations.")
625 ;;; **********************************************************************
626 ;;; **********************************************************************
630 (defun ispell-word (&optional following quietly
)
631 "Check spelling of word under or before the cursor.
632 If word not found in dictionary, display possible corrections in a window
634 If optional argument FOLLOWING is non-nil or if ispell-following-word
635 is non-nil when called interactively, then the following word
636 \(rather than preceding\) will be checked when the cursor is not over a word.
637 When the optional argument QUIETLY is non-nil or ispell-quietly is non-nil
638 when called interactively, non-corrective messages are suppressed.
640 Word syntax described by ispell-dictionary-alist (which see).
642 This will check or reload the dictionary. Use \\[ispell-change-dictionary]
643 or \\[ispell-region] to update the ispell process."
646 (setq following ispell-following-word
647 quietly ispell-quietly
))
648 (ispell-buffer-local-dict) ; use the correct dictionary
649 (let ((cursor-location (point)) ; retain cursor location
650 ispell-keep-choices-win
; override global to force creation
651 (word (ispell-get-word following
))
652 start end poss replace
)
653 ;; destructure return word info list.
654 (setq start
(car (cdr word
))
655 end
(car (cdr (cdr word
)))
658 ;; now check spelling of word.
660 (message "Checking spelling of %s..."
661 (funcall ispell-format-word word
)))
662 (ispell-init-process) ; erases ispell output buffer
663 (process-send-string ispell-process
"%\n") ;put in verbose mode
664 (process-send-string ispell-process
(concat "^" word
"\n"))
665 ;; wait until ispell has processed word
667 (accept-process-output ispell-process
)
668 (not (string= "" (car ispell-filter
)))))
669 ;;(process-send-string ispell-process "!\n") ;back to terse mode.
670 (setq ispell-filter
(cdr ispell-filter
))
671 (if (listp ispell-filter
)
672 (setq poss
(ispell-parse-output (car ispell-filter
))))
675 (message "%s is correct." (funcall ispell-format-word word
))))
678 (message "%s is correct because of root %s"
679 (funcall ispell-format-word word
)
680 (funcall ispell-format-word poss
))))
681 ((null poss
) (message "Error in ispell process"))
682 (t ; prompt for correct word.
685 (if ispell-highlight-p
686 (highlight-spelling-error start end t
)) ; highlight word
687 (setq replace
(ispell-command-loop
688 (car (cdr (cdr poss
)))
689 (car (cdr (cdr (cdr poss
))))
692 (if ispell-highlight-p
; clear highlight
693 (highlight-spelling-error start end
)))
694 (cond ((equal 0 replace
)
695 (ispell-add-per-file-word-list (car poss
)))
697 (delete-region start end
)
698 (setq word
(if (atom replace
) replace
(car replace
))
699 cursor-location
(+ (- (length word
) (- end start
))
702 (if (not (atom replace
)) ; recheck spelling of replacement
704 (goto-char cursor-location
)
705 (ispell-word following quietly
)))))
706 (if (get-buffer ispell-choices-buffer
)
707 (kill-buffer ispell-choices-buffer
))))
708 (goto-char cursor-location
) ; return to original location
709 (ispell-pdict-save ispell-silently-savep
)
710 (if ispell-quit
(setq ispell-quit nil
))))
713 (defun ispell-get-word (following &optional extra-otherchars
)
714 "Return the word for spell-checking according to ispell syntax.
715 If optional argument FOLLOWING is non-nil or if ispell-following-word
716 is non-nil when called interactively, then the following word
717 \(rather than preceeding\) will be checked when the cursor is not over a word.
718 Optional second argument contains otherchars that can be included in word
721 Word syntax described by ispell-dictionary-alist (which see)."
722 (let* ((ispell-casechars (ispell-get-casechars))
723 (ispell-not-casechars (ispell-get-not-casechars))
724 (ispell-otherchars (ispell-get-otherchars))
725 (ispell-many-otherchars-p (ispell-get-many-otherchars-p))
726 (word-regexp (concat ispell-casechars
731 (concat extra-otherchars
"?"))
734 (if (or ispell-many-otherchars-p
740 (if (not (looking-at ispell-casechars
))
742 (re-search-forward ispell-casechars
(point-max) t
)
743 (re-search-backward ispell-casechars
(point-min) t
)))
744 ;; move to front of word
745 (re-search-backward ispell-not-casechars
(point-min) 'start
)
746 (while (and (or (looking-at ispell-otherchars
)
747 (and extra-otherchars
(looking-at extra-otherchars
)))
749 (or (not did-it-once
)
750 ispell-many-otherchars-p
))
751 (if (and extra-otherchars
(looking-at extra-otherchars
))
754 (if (looking-at ispell-casechars
)
755 (re-search-backward ispell-not-casechars
(point-min) 'move
)))
758 (if (looking-at ispell-casechars
)
759 (re-search-backward ispell-not-casechars
(point-min) 'move
)
760 (backward-char -
1))))
761 ;; Now mark the word and save to string.
762 (or (re-search-forward word-regexp
(point-max) t
)
763 (error "No word found to check!"))
764 (setq start
(match-beginning 0)
766 word
(buffer-substring start end
))
767 (list word start end
)))
770 ;;; Global ispell-pdict-modified-p is set by ispell-command-loop and
771 ;;; tracks changes in the dictionary. The global may either be
772 ;;; a value or a list, whose value is the state of whether the
773 ;;; dictionary needs to be saved.
776 (defun ispell-pdict-save (&optional no-query force-save
)
777 "Check to see if the personal dictionary has been modified.
778 If so, ask if it needs to be saved."
779 (interactive (list ispell-silently-savep t
))
780 (if (and ispell-pdict-modified-p
(listp ispell-pdict-modified-p
))
781 (setq ispell-pdict-modified-p
(car ispell-pdict-modified-p
)))
782 (if (or ispell-pdict-modified-p force-save
)
783 (if (or no-query
(y-or-n-p "Personal dictionary modified. Save? "))
784 (process-send-string ispell-process
"#\n")))
785 ;; unassert variable, even if not saved to avoid questioning.
786 (setq ispell-pdict-modified-p nil
))
789 (defun ispell-command-loop (miss guess word
)
790 "Display possible corrections from list MISS.
791 GUESS lists possibly valid affix construction of WORD.
792 Returns nil to keep word.
793 0 to insert locally into buffer-local dictionary.
794 string for new chosen word.
795 list for new replacement word (will be rechecked).
796 Optional second argument means replace misspelling in
797 the rest of the region.
798 Global ispell-pdict-modified-p becomes a list where the only value
799 indicates whether the dictionary has been modified when option a or i is
802 (save-window-excursion
805 (max-lines (- (window-height) 4)) ; assure 4 context lines.
807 (window-min-height (min window-min-height
808 ispell-choices-win-default-height
))
809 (command-characters '( ? ?i ?a ?A ?r ?R ?? ?x ?X ?q ?l ?u ?m
))
813 (if ispell-keep-choices-win
814 (select-window (previous-window))
815 (set-buffer (get-buffer-create ispell-choices-buffer
))
816 (setq mode-line-format
"-- %b --"))
817 (if (equal (get-buffer ispell-choices-buffer
) (current-buffer))
819 (error "Bogus, dude! I should be in the *Choices* buffer, but I'm not!"))
823 "Affix rules generate and capitalize this word as shown below:\n\t")
825 (if (> (+ 4 (current-column) (length (car guess
)))
829 (setq line
(1+ line
))))
830 (insert (car guess
) " ")
831 (setq guess
(cdr guess
)))
832 (insert "\nUse option \"i\" if this is a correct composition from the derivative root.\n")
833 (setq line
(+ line
(if choices
3 2)))))
835 (< (if (> (+ 7 (current-column) (length (car choices
))
836 (if (> count ?~
) 3 0))
840 (setq line
(1+ line
)))
843 ;; not so good if there are over 20 or 30 options, but then, if
844 ;; there are that many you don't want to have to scan them all anyway...
845 (while (memq count command-characters
) ; skip command characters.
846 (setq count
(1+ count
)
847 skipped
(1+ skipped
)))
848 (insert "(" count
") " (car choices
) " ")
849 (setq choices
(cdr choices
)
851 (setq count
(- count ?
0 skipped
)))
853 (if ispell-keep-choices-win
854 (if (> line ispell-keep-choices-win
)
856 (switch-to-buffer ispell-choices-buffer
)
857 (select-window (next-window))
859 (let ((cur-point (point)))
860 (move-to-window-line (- line ispell-keep-choices-win
))
861 (if (<= (point) cur-point
)
862 (set-window-start (selected-window) (point)))))
863 (select-window (previous-window))
864 (enlarge-window (- line ispell-keep-choices-win
))
865 (goto-char (point-min))))
866 (ispell-overlay-window (max line ispell-choices-win-default-height
)))
867 (switch-to-buffer ispell-choices-buffer
)
868 (goto-char (point-min))
869 (select-window (next-window))
877 (message "C-h or ? for more options; SPC to leave unchanged, Character to replace word")
878 (setq char
(read-char)
880 ;; Adjust num to array offset skipping command characters.
881 (let ((com-chars command-characters
))
883 (if (and (> (car com-chars
) ?
0) (< (car com-chars
) char
))
884 (setq skipped
(1+ skipped
)))
885 (setq com-chars
(cdr com-chars
)))
886 (setq num
(- char ?
0 skipped
)))
889 ((= char ?
) nil
) ; accept word this time only
890 ((= char ?i
) ; accept and insert word into pers dict
891 (process-send-string ispell-process
(concat "*" word
"\n"))
892 (setq ispell-pdict-modified-p
'(t)) ; dictionary was modified!
894 ((or (= char ?a
) (= char ?A
)) ; accept word, don't insert in dict
895 (process-send-string ispell-process
(concat "@" word
"\n"))
896 (if (null ispell-pdict-modified-p
)
897 (setq ispell-pdict-modified-p
898 (list ispell-pdict-modified-p
)))
899 (if (= char ?A
) 0)) ; return 0 for ispell-add buffer-local
900 ((or (= char ?r
) (= char ?R
)) ; type in replacement
901 (if (or (= char ?R
) ispell-query-replace-choices
)
902 (list (read-string "Query-replacement for: " word
) t
)
903 (cons (read-string "Replacement for: " word
) nil
)))
904 ((or (= char ??
) (= char help-char
) (= char ?\C-h
))
907 ;; quit or quit and stay at this point.
908 ((or (= char ?x
) (= char ?X
)) ; quit.
909 (ispell-pdict-save ispell-silently-savep
)
910 (message "exited ispell")
911 (setq ispell-quit
(if (= char ?X
) (point) t
))
914 (= char
(nth 3 (current-input-mode)))) ; C-g
915 (if (y-or-n-p "Really quit ignoring changes? ")
917 (ispell-kill-ispell t
) ; terminate process.
919 ispell-pdict-modified-p nil
))
920 t
)) ; continue if they don't quit.
922 (let ((new-word (read-string "Lookup string ('*' is wildcard): "
928 (set-buffer (get-buffer-create ispell-choices-buffer
))
932 mode-line-format
"-- %b --"
933 miss
(lookup-words new-word
)
935 (while (and choices
; adjust choices window.
936 (< (if (> (+ 7 (current-column)
937 (length (car choices
))
938 (if (> count ?~
) 3 0))
942 (setq new-line
(1+ new-line
)))
945 (while (memq count command-characters
)
946 (setq count
(1+ count
)
947 skipped
(1+ skipped
)))
948 (insert "(" count
") " (car choices
) " ")
949 (setq choices
(cdr choices
)
951 (setq count
(- count ?
0 skipped
)))
952 (select-window (previous-window))
953 (if (/= new-line line
)
955 (if (> new-line line
)
956 (enlarge-window (- new-line line
))
957 (shrink-window (- line new-line
)))
958 (setq line new-line
)))
959 (select-window (next-window)))))
960 t
) ; reselect from new choices
962 (process-send-string ispell-process
963 (concat "*" (downcase word
) "\n"))
964 (setq ispell-pdict-modified-p
'(t)) ; dictionary was modified!
966 ((= char ?m
) ; type in what to insert
968 ispell-process
(concat "*" (read-string "Insert: " word
) "\n"))
969 (setq ispell-pdict-modified-p
'(t))
971 ((and (>= num
0) (< num count
))
972 (if ispell-query-replace-choices
; Query replace when flag set.
973 (list (nth num miss
) 'query-replace
)
978 (save-window-excursion (recursive-edit)) t
)
983 (if (not ispell-keep-choices-win
) (bury-buffer ispell-choices-buffer
))))
987 (defun ispell-help ()
988 "This gives a list of the options available when a misspelling is encountered.
992 DIGIT: Replace the word with a digit offered in the *Choices* buffer.
993 ' ': Accept word this time.
994 'i': Accept word and insert into private dictionary.
995 'a': Accept word for this session.
996 'A': Accept word and place in `buffer-local dictionary'.
997 'r': Replace word with typed-in value. Rechecked.
998 'R': Replace word with typed-in value. Query-replaced in buffer. Rechecked.
999 '?': Show these commands.
1000 'x': Exit spelling buffer. Move cursor to original point.
1001 'X': Exit spelling buffer. Leaves cursor at the current point, and permits
1002 the aborted check to be completed later.
1003 'q': Quit spelling session (Kills ispell process).
1004 'l': Look up typed-in replacement in alternate dictionary. Wildcards okay.
1005 'u': Like 'i', but the word is lower-cased first.
1006 'm': Like 'i', but allows one to include dictionary completion information.
1007 'C-l': redraws screen
1008 'C-r': recursive edit
1009 'C-z': suspend emacs"
1011 (let ((help-1 "[r/R]eplace word; [a/A]ccept for this session; [i]nsert into private dictionary")
1012 (help-2 "[l]ook a word up in alternate dictionary; e[x/X]it; [q]uit session")
1013 (help-3 "[u]ncapitalized insert into dictionary. Type 'C-h d ispell-help' for more help"))
1014 (save-window-excursion
1015 (if ispell-help-in-bufferp
1017 (ispell-overlay-window 4)
1018 (switch-to-buffer (get-buffer-create "*Ispell Help*"))
1019 (insert (concat help-1
"\n" help-2
"\n" help-3
))
1021 (kill-buffer "*Ispell Help*"))
1022 (select-window (minibuffer-window))
1025 (cond ((string-match "Lucid" emacs-version
)
1032 (if (string-match "^19\\." emacs-version
)
1035 (insert (concat help-1
"\n" help-2
"\n" help-3
))))
1040 (defun lookup-words (word &optional lookup-dict
)
1041 "Look up word in word-list dictionary.
1042 A '*' is used for wild cards. If no wild cards, 'look' is used if it exists.
1043 Otherwise the variable ispell-grep-command contains the command used to
1044 search for the words (usually egrep).
1045 Optional second argument contains the dictionary to use, the default is
1046 ispell-alternate-dictionary."
1047 ;; We don't use the filter for this function, rather the result is written
1048 ;; into a buffer. Hence there is no need to save the filter values.
1049 (if (null lookup-dict
)
1050 (setq lookup-dict ispell-alternate-dictionary
))
1052 (let* ((process-connection-type ispell-use-ptys-p
)
1053 (wild-p (string-match "\\*" word
))
1054 (look-p (and ispell-look-p
; Only use look for an exact match.
1055 (or ispell-have-new-look
(not wild-p
))))
1056 (ispell-grep-buffer (get-buffer-create "*Ispell-Temp*")) ; result buf
1057 (prog (if look-p ispell-look-command ispell-grep-command
))
1058 (args (if look-p ispell-look-options ispell-grep-options
))
1061 (save-window-excursion
1062 (message "Starting \"%s\" process..." (file-name-nondirectory prog
))
1063 (set-buffer ispell-grep-buffer
)
1067 (insert "^" word
"$")
1068 (while (search-backward "*" nil t
) (insert "."))
1069 (setq word
(buffer-string))
1071 (setq status
(call-process prog nil t nil args word lookup-dict
))
1072 ;; grep returns status 1 and no output when word not found, which
1073 ;; is a perfectly normal thing.
1074 (if (stringp status
)
1075 (setq results
(cons (format "error: %s exited with signal %s"
1076 (file-name-nondirectory prog
) status
)
1078 ;; else collect words into `results' in FIFO order
1079 (goto-char (point-max))
1080 ;; assure we've ended with \n
1081 (or (bobp) (= (preceding-char) ?
\n) (insert ?
\n))
1085 (setq results
(cons (buffer-substring (point) (1- loc
))
1088 (kill-buffer ispell-grep-buffer
)
1089 (if (and results
(string-match ".+: " (car results
)))
1090 (error "%s error: %s" ispell-grep-command
(car results
))))
1094 ;;; "ispell-filter" is a list of output lines from the generating function.
1095 ;;; Each full line (ending with \n) is a separate item on the list.
1096 ;;; "output" can contain multiple lines, part of a line, or both.
1097 ;;; "start" and "end" are used to keep bounds on lines when "output" contains
1099 ;;; "ispell-filter-continue" is true when we have received only part of a
1100 ;;; line as output from a generating function ("output" did not end with \n)
1101 ;;; NOTE THAT THIS FUNCTION WILL FAIL IF THE PROCESS OUTPUT DOESNT END WITH \n!
1102 ;;; This is the case when a process dies or fails. The default behavior
1103 ;;; in this case treats the next input received as fresh input.
1105 (defun ispell-filter (process output
)
1106 "Output filter function for ispell, grep, and look."
1111 (setq end
(string-match "\n" output start
)) ; get text up to the newline.
1112 ;; If we get out of sync and ispell-filter-continue is asserted when we
1113 ;; are not continuing, treat the next item as a separate list. When
1114 ;; ispell-filter-continue is asserted, ispell-filter *should* always be a
1117 ;; Continue with same line (item)?
1118 (if (and ispell-filter-continue ispell-filter
(listp ispell-filter
))
1119 ;; Yes. Add it to the prev item
1120 (setcar ispell-filter
1121 (concat (car ispell-filter
) (substring output start end
)))
1122 ;; No. This is a new line and item.
1124 (cons (substring output start end
) ispell-filter
)))
1126 ;; We've completed reading the output, but didn't finish the line.
1127 (setq ispell-filter-continue t continue nil
)
1128 ;; skip over newline, this line complete.
1129 (setq ispell-filter-continue nil end
(1+ end
))
1130 (if (= end
(length output
)) ; No more lines in output
1131 (setq continue nil
) ; so we can exit the filter.
1132 (setq start end
)))))) ; else move start to next line of input
1135 ;;; This function destroys the mark location if it is in the word being
1137 (defun highlight-spelling-error-generic (start end
&optional highlight
)
1138 "Highlight the word from START to END by deleting and reinserting it
1139 while toggling the variable \"inverse-video\". When the optional
1140 third arg HIGHLIGHT is set, the word is highlighted otherwise it is
1141 displayed normally."
1142 (let ((modified (buffer-modified-p)) ; don't allow this fn to modify buffer
1143 (buffer-read-only nil
) ; Allow highlighting read-only buffers.
1144 (text (buffer-substring start end
)) ; Save highlight region
1145 (inhibit-quit t
) ; inhibit interrupt processing here.
1146 (buffer-undo-list nil
)) ; don't clutter the undo list.
1147 (delete-region start end
)
1148 (insert-char ?
(- end start
)) ; mimimize amount of redisplay
1149 (sit-for 0) ; update display
1150 (if highlight
(setq inverse-video
(not inverse-video
))) ; toggle video
1151 (delete-region start end
) ; delete whitespace
1152 (insert text
) ; insert text in inverse video.
1153 (sit-for 0) ; update display showing inverse video.
1154 (if highlight
(setq inverse-video
(not inverse-video
))) ; toggle video
1155 (set-buffer-modified-p modified
))) ; don't modify if flag not set.
1158 (defun highlight-spelling-error-lucid (start end
&optional highlight
)
1159 "Highlight the word from START to END using isearch-highlight. When
1160 the optional third arg HIGHLIGHT is set, the word is highlighted
1161 otherwise it is displayed normally."
1163 (isearch-highlight start end
)
1164 (isearch-dehighlight t
))
1169 (defun highlight-spelling-error-overlay (start end
&optional highlight
)
1170 "Highlight the word from START to END using overlays. When the
1171 optional third arg HIGHLIGHT is set, the word is highlighted otherwise
1172 it is displayed normally.
1173 The variable ispell-highlight-face selects the face that will be used
1177 (setq ispell-overlay
(make-overlay start end
))
1178 (overlay-put ispell-overlay
'face ispell-highlight-face
))
1179 (delete-overlay ispell-overlay
)))
1182 ;;; Choose a highlight function at load time.
1183 (fset 'highlight-spelling-error
1186 ((string-match "Lucid" emacs-version
) 'highlight-spelling-error-lucid
)
1187 ((and (string-match "^19\\." emacs-version
)
1188 (featurep 'faces
)) 'highlight-spelling-error-overlay
)
1189 (t 'highlight-spelling-error-generic
))))
1192 (defun ispell-overlay-window (height)
1193 "Create a (usually small) window covering the top HEIGHT lines of the
1194 current window. Ensure that the line above point is still visible but
1195 otherwise avoid scrolling the current window. Should leave the old
1198 (let ((oldot (save-excursion (forward-line -
1) (point)))
1199 (top (save-excursion (move-to-window-line height
) (point))))
1200 ;; If line above old point (line starting at olddot) would be
1201 ;; hidden by new window, scroll it to just below new win
1202 ;; otherwise set top line of other win so it doesn't scroll.
1203 (if (< oldot top
) (setq top oldot
))
1204 (split-window nil height
)
1205 (set-window-start (next-window) top
))))
1208 ;;; Should we add a compound word match return value?
1209 (defun ispell-parse-output (output)
1210 "Parse the OUTPUT string of 'ispell' and return:
1211 1: T for an exact match.
1212 2: A string containing the root word for a match via suffix removal.
1213 3: A list of possible correct spellings of the format:
1214 '(\"original-word\" offset miss-list guess-list)
1215 original-word is a string of the possibly misspelled word.
1216 offset is an integer giving the line offset of the word.
1217 miss-list and guess-list are possibly null lists of guesses and misses."
1219 ((string= output
"") t
) ; for startup with pipes...
1220 ((string= output
"*") t
) ; exact match
1221 ((string= output
"-") t
) ; compound word match
1222 ((string= (substring output
0 1) "+") ; found cuz of root word
1223 (substring output
2)) ; return root word
1224 (t ; need to process &, ?, and #'s
1225 (let ((type (substring output
0 1)) ; &, ?, or #
1226 (original-word (substring output
2 (string-match " " output
2)))
1227 (cur-count 0) ; contains number of misses + guesses
1228 count miss-list guess-list offset
)
1229 (setq output
(substring output
(match-end 0))) ; skip over misspelling
1230 (if (string= type
"#")
1231 (setq count
0) ; no misses for type #
1232 (setq count
(string-to-int output
) ; get number of misses.
1233 output
(substring output
(1+ (string-match " " output
1)))))
1234 (setq offset
(string-to-int output
))
1235 (if (string= type
"#") ; No miss or guess list.
1237 (setq output
(substring output
(1+ (string-match " " output
1)))))
1239 (let ((end (string-match ", \\|\\($\\)" output
))) ; end of miss/guess.
1240 (setq cur-count
(1+ cur-count
))
1241 (if (> cur-count count
)
1242 (setq guess-list
(cons (substring output
0 end
) guess-list
))
1243 (setq miss-list
(cons (substring output
0 end
) miss-list
)))
1244 (if (match-end 1) ; True only when at end of line.
1245 (setq output nil
) ; no more misses or guesses
1246 (setq output
(substring output
(+ end
2))))))
1247 (list original-word offset miss-list guess-list
)))))
1250 (defun check-ispell-version ()
1251 ;; This is a little wasteful as we actually launch ispell twice: once
1252 ;; to make sure it's the right version, and once for real. But people
1253 ;; get confused by version mismatches *all* the time (and I've got the
1254 ;; email to prove it) so I think this is worthwhile. And the -v[ersion]
1255 ;; option is the only way I can think of to do this that works with
1256 ;; all versions, since versions earlier than 3.0.09 didn't identify
1257 ;; themselves on startup.
1259 ;; If the ispell.el file ever supports more than one version of the
1260 ;; external ispell program, then this should be reworked to accept more
1261 ;; than one version, but until that happens, doing so would be false
1265 (set-buffer (get-buffer-create " *ispell-tmp*"))
1267 (let ((status (call-process ispell-program-name nil t nil
"-v"))
1268 (case-fold-search t
))
1269 (goto-char (point-min))
1270 (cond ((not (memq status
'(0 nil
)))
1271 (error "%s exited with %s %s" ispell-program-name
1272 (if (stringp status
) "signal" "code") status
))
1273 ((not (re-search-forward
1275 (mapconcat 'regexp-quote
1276 ispell-required-versions
1280 (error "version mismatch: ispell.el is for %s, %s is %s"
1281 (car ispell-required-versions
)
1283 (if (re-search-forward "version \\([0-9][0-9.]+\\)\\b"
1285 (buffer-substring (match-beginning 1) (match-end 1))
1286 "an unknown version"))))
1287 (kill-buffer (current-buffer)))))
1290 (defun ispell-init-process ()
1291 "Check status of 'ispell' process and start if necessary."
1292 (if (and ispell-process
1293 (eq (process-status ispell-process
) 'run
)
1294 ;; If we're using a personal dictionary, assure
1295 ;; we're in the same default directory!
1296 (or (not ispell-personal-dictionary
)
1297 (equal ispell-process-directory default-directory
)))
1298 (setq ispell-filter nil ispell-filter-continue nil
)
1299 ;; may need to restart to select new personal dictionary.
1300 (ispell-kill-ispell t
)
1301 (message "Starting new ispell process...")
1303 (check-ispell-version)
1304 (setq ispell-process
1305 (let ((process-connection-type ispell-use-ptys-p
))
1306 (apply 'start-process
1307 "ispell" nil ispell-program-name
1308 "-a" ; accept single input lines
1309 "-m" ; make root/affix combos not in dict
1311 ;; Local dictionary becomes the global dictionary in use.
1312 (if ispell-local-dictionary
1313 (setq ispell-dictionary ispell-local-dictionary
))
1314 (setq args
(ispell-get-ispell-args))
1315 (if ispell-dictionary
; use specified dictionary
1317 (append (list "-d" ispell-dictionary
) args
)))
1318 (if ispell-personal-dictionary
; use specified pers dict
1323 ispell-personal-dictionary
)))))
1326 ispell-filter-continue nil
1327 ispell-process-directory default-directory
)
1328 (set-process-filter ispell-process
'ispell-filter
)
1329 (accept-process-output ispell-process
) ; Get version ID line
1330 (cond ((null ispell-filter
)
1331 (error "%s did not output version line"))
1332 ((and (null (cdr ispell-filter
))
1333 (stringp (car ispell-filter
))
1334 (string-match "^@(#) " (car ispell-filter
)))
1335 ;; got the version line as expected (we already know it's the right
1336 ;; version, so don't bother checking again.)
1339 ;; Otherwise, it must be an error message. Show the user.
1340 ;; But first wait to see if some more output is going to arrive.
1341 ;; Otherwise we get cool errors like "Can't open ".
1343 (accept-process-output)
1344 (error "%s" (mapconcat 'identity ispell-filter
"\n"))))
1345 (setq ispell-filter nil
) ; Discard version ID line
1346 (let ((extended-char-mode (ispell-get-extended-character-mode)))
1347 (if extended-char-mode
1348 (process-send-string ispell-process
1349 (concat extended-char-mode
"\n"))))
1350 (process-kill-without-query ispell-process
)))
1354 (defun ispell-kill-ispell (&optional no-error
)
1355 "Kill current ispell process (so that you may start a fresh one).
1356 With NO-ERROR, just return non-nil if there was no ispell running."
1358 (if (not (and ispell-process
1359 (eq (process-status ispell-process
) 'run
)))
1361 (error "There is no ispell process running!"))
1362 (kill-process ispell-process
)
1363 (setq ispell-process nil
)
1364 (message "Killed ispell process.")
1369 (defun ispell-change-dictionary (dict &optional arg
)
1370 "Change ispell-dictionary (q.v.) and kill old ispell process.
1371 A new one will be started as soon as necessary.
1373 By just answering RET you can find out what the current dictionary is.
1375 With prefix argument, set the default directory."
1377 (list (completing-read
1378 "Use new dictionary (RET for current, SPC to complete): "
1379 (cons (cons "default" nil
) ispell-dictionary-alist
) nil t
)
1380 current-prefix-arg
))
1381 (if (equal dict
"default") (setq dict nil
))
1382 ;; This relies on completing-read's bug of returning "" for no match
1383 (cond ((equal dict
"")
1384 (message "Using %s dictionary"
1385 (or ispell-local-dictionary ispell-dictionary
"default")))
1386 ((and (equal dict ispell-dictionary
)
1387 (equal dict ispell-local-dictionary
))
1388 ;; Specified dictionary is the default already. No-op
1389 (message "No change, using %s dictionary" (or dict
"default")))
1390 (t ; reset dictionary!
1391 (if (assoc dict ispell-dictionary-alist
)
1393 (if (or arg
(null dict
)) ; set default dictionary
1394 (setq ispell-dictionary dict
))
1395 (if (null arg
) ; set local dictionary
1396 (setq ispell-local-dictionary dict
)))
1397 (error "Illegal dictionary: %s" dict
))
1398 (ispell-kill-ispell t
)
1399 (message "(Next %sispell command will use %s dictionary)"
1400 (cond ((equal ispell-local-dictionary ispell-dictionary
)
1404 (or (if (or (equal ispell-local-dictionary ispell-dictionary
)
1406 ispell-local-dictionary
1411 ;;; Spelling of comments are checked when ispell-check-comments is non-nil.
1414 (defun ispell-region (reg-start reg-end
)
1415 "Interactively check a region for spelling errors."
1416 (interactive "r") ; Don't flag errors on read-only bufs.
1417 (ispell-accept-buffer-local-defs) ; set up dictionary, local words, etc.
1420 (message "Spelling %s..."
1421 (if (and (= reg-start
(point-min)) (= reg-end
(point-max)))
1422 (buffer-name) "region"))
1424 ;; must be top level now, not inside ispell-command-loop for keeping window.
1425 (save-window-excursion
1426 (if ispell-keep-choices-win
1427 (let ((window-min-height ispell-choices-win-default-height
))
1428 ;; This keeps the default window size when choices window saved.
1429 (setq ispell-keep-choices-win ispell-choices-win-default-height
)
1430 (ispell-overlay-window ispell-choices-win-default-height
)
1431 (switch-to-buffer (get-buffer-create ispell-choices-buffer
))
1432 (setq mode-line-format
"-- %b --")
1434 (select-window (next-window))
1436 (goto-char reg-start
)
1437 (let ((transient-mark-mode nil
))
1438 (while (and (not ispell-quit
) (< (point) reg-end
))
1439 (let ((start (point))
1441 (end (save-excursion (end-of-line) (min (point) reg-end
)))
1442 (ispell-casechars (ispell-get-casechars))
1444 (cond ; LOOK AT THIS LINE AND SKIP OR PROCESS
1445 ((eolp) ; END OF LINE, just go to next line.
1447 ((and (null ispell-check-comments
) ; SKIPING COMMENTS
1448 comment-start
; skip comments that start on the line.
1449 (search-forward comment-start end t
)) ; a comment is on this line.
1450 (if (= (- (point) start
) (length comment-start
))
1451 ;; comment starts the line. We can skip the entire line or region
1452 (if (string= "" comment-end
) ; skip to next line over comment
1453 (beginning-of-line 2)
1454 (search-forward comment-end reg-end
'limit
)) ; jmp to comment end
1455 ;; Comment starts later on line. Check for spelling before comment.
1456 (let ((limit (- (point) (length comment-start
))))
1457 (goto-char (1- limit
))
1458 (if (looking-at "\\\\") ; "quoted" comment, don't skip
1459 ;; quoted comment. Skip over comment-start and continue.
1460 (if (= start
(1- limit
))
1461 (setq limit
(+ limit
(length comment-start
)))
1462 (setq limit
(1- limit
))))
1464 ;; Only check if there are "casechars" or math chars before comment
1465 (if (or (re-search-forward ispell-casechars limit t
)
1466 (re-search-forward "[][()$]" limit t
))
1467 (setq string
(concat "^" (buffer-substring start limit
) "\n")))
1468 (goto-char limit
))))
1469 ((and ispell-skip-tib
; SKIP TIB REFERENCES!
1470 (re-search-forward ispell-tib-ref-beginning end t
))
1471 (if (= (- (point) 2) start
) ; tib ref is 2 chars.
1472 ;; Skip to end of tib ref, not necessarily on this line.
1473 ;; Return an error if tib ref not found
1474 (if (not (re-search-forward ispell-tib-ref-end reg-end t
))
1476 (ispell-pdict-save ispell-silently-savep
)
1478 (message "Open tib reference. Set ispell-skip-tib to nil to avoid this error.")
1479 (setq ispell-quit
(- (point) 2)))) ; leave dot at error loc.
1480 ;; tib ref starts later on line. Check spelling before tib.
1481 (let ((limit (- (point) 2)))
1483 (if (or (re-search-forward ispell-casechars limit t
)
1484 (re-search-forward "[][()$]" limit t
))
1485 (setq string
(concat "^" (buffer-substring start limit
) "\n")))
1486 (goto-char limit
))))
1487 ((looking-at "[-#@*+!%~^]") ; SKIP SPECIAL ISPELL CHARACTERS
1489 ((or (re-search-forward ispell-casechars end t
) ; TEXT EXISTS...
1490 (re-search-forward "[][()$]" end t
)) ; or MATH COMMANDS...
1491 (setq string
(concat "^" (buffer-substring start end
) "\n"))
1493 (t (beginning-of-line 2))) ; EMPTY LINE, skip it.
1495 (setq end
(point)) ; "end" tracks end of region to check.
1497 (if string
; there is something to spell!
1499 ;; send string to spell process and get input.
1500 (process-send-string ispell-process string
)
1502 (accept-process-output ispell-process
)
1503 ;; Last item of output contains a blank line.
1504 (not (string= "" (car ispell-filter
)))))
1505 ;; parse all inputs from the stream one word at a time.
1506 ;; Place in FIFO order and remove the blank item.
1507 (setq ispell-filter
(nreverse (cdr ispell-filter
)))
1508 (while (and (not ispell-quit
) ispell-filter
)
1509 (setq poss
(ispell-parse-output (car ispell-filter
)))
1510 (if (listp poss
) ; spelling error occurred.
1511 (let* ((word-start (+ start offset-change
(car (cdr poss
))))
1512 (word-end (+ word-start
(length (car poss
))))
1514 (goto-char word-start
)
1515 ;; The following lines adjust the horizontal scroll & point
1517 (goto-char word-end
)
1519 (goto-char word-start
)
1521 (if (/= word-end
(progn
1522 (search-forward (car poss
) word-end t
)
1524 ;; This usually occurs due to filter pipe problems
1525 (error "***ispell misalignment: word \"%s\" point %d; please retry."
1526 (car poss
) word-start
))
1529 (if ispell-highlight-p
1530 (highlight-spelling-error word-start word-end t
))
1531 (sit-for 0) ; update screen display
1532 (setq replace
(ispell-command-loop
1533 (car (cdr (cdr poss
)))
1534 (car (cdr (cdr (cdr poss
))))
1537 (if ispell-highlight-p
1538 (highlight-spelling-error word-start word-end
)))
1540 ((and replace
(listp replace
))
1541 ;; REPLACEMENT WORD entered. Recheck line starting with
1542 ;; the replacement word.
1543 (setq ispell-filter nil
1544 string
(buffer-substring word-start word-end
))
1545 (let ((change (- (length (car replace
)) ; adjust
1546 (length (car poss
))))) ; regions
1547 (setq reg-end
(+ reg-end change
)
1548 offset-change
(+ offset-change change
)))
1549 (delete-region word-start word-end
)
1550 (insert (car replace
))
1551 ;; I only need to recheck typed-in replacements.
1552 (if (not (eq 'query-replace
(car (cdr replace
))))
1553 (backward-char (length (car replace
))))
1554 (setq end
(point)) ; reposition in region to recheck
1555 ;; when second arg exists, query-replace, saving regions
1556 (if (car (cdr replace
))
1558 (save-window-excursion ; save if help is called.
1559 (set-marker ispell-query-replace-marker reg-end
)
1560 ;; Assume case-replace & case-fold-search correct?
1561 (query-replace string
(car replace
) t
))
1563 (setq reg-end
(marker-position
1564 ispell-query-replace-marker
))
1565 (set-marker ispell-query-replace-marker nil
))))
1566 ((or (null replace
) (equal 0 replace
)) ; ACCEPT/INSERT
1567 (if (equal 0 replace
) ; BUFFER-LOCAL DICTIONARY ADD
1568 (setq reg-end
(ispell-add-per-file-word-list
1569 (car poss
) reg-end
)))
1570 ;; This prevents us from pointing out the word that was
1571 ;; just accepted (via 'i' or 'a') if it follows on the
1572 ;; same line. (The drawback of processing entire lines.)
1573 ;; Redo check following the accepted word.
1574 (if (and ispell-pdict-modified-p
1575 (listp ispell-pdict-modified-p
))
1576 ;; We have accepted or inserted a word. Re-check line
1577 (setq ispell-pdict-modified-p
; fix update flag
1578 (car ispell-pdict-modified-p
)
1579 ispell-filter nil
; don't continue check.
1580 end word-start
))) ; reposition continue loc
1581 (replace ; STRING REPLACEMENT for this word.
1582 (delete-region word-start word-end
)
1584 (let ((change (- (length replace
) (length (car poss
)))))
1585 (setq reg-end
(+ reg-end change
)
1586 offset-change
(+ offset-change change
)
1587 end
(+ end change
)))))
1588 (if (not ispell-quit
)
1589 (message "continuing spelling check..."))
1591 (setq ispell-filter
(cdr ispell-filter
))))) ; finished with line
1595 (if (get-buffer ispell-choices-buffer
)
1596 (kill-buffer ispell-choices-buffer
))
1599 ;; preserve or clear the region for ispell-continue.
1600 (if (not (numberp ispell-quit
))
1601 (set-marker ispell-region-end nil
)
1602 ;; Enable ispell-continue.
1603 (set-marker ispell-region-end reg-end
)
1604 (goto-char ispell-quit
))
1605 ;; Check for aborting
1606 (if (and ispell-checking-message
(numberp ispell-quit
))
1608 (setq ispell-quit nil
)
1609 (error "Message send aborted.")))
1610 (setq ispell-quit nil
))
1611 (set-marker ispell-region-end nil
)
1612 ;; Only save if successful exit.
1613 (ispell-pdict-save ispell-silently-savep
)
1614 (message "Spell done."))))
1619 (defun ispell-buffer ()
1620 "Check the current buffer for spelling errors interactively."
1622 (ispell-region (point-min) (point-max)))
1625 (defun ispell-continue ()
1627 "Continue a spelling session after making some changes."
1628 (if (not (marker-position ispell-region-end
))
1629 (message "No session to continue. Use 'X' command when checking!")
1630 (if (not (equal (marker-buffer ispell-region-end
) (current-buffer)))
1631 (message "Must continue ispell from buffer %s"
1632 (buffer-name (marker-buffer ispell-region-end
)))
1633 (ispell-region (point) (marker-position ispell-region-end
)))))
1636 ;;; Horizontal scrolling
1637 (defun horiz-scroll ()
1638 "This function checks if the point is within the horizontal
1639 visibility of its window area."
1640 (if truncate-lines
; display truncating lines?
1641 ;; See if display needs to be scrolled.
1642 (let ((column (- (current-column) (max (window-hscroll) 1))))
1643 (if (and (< column
0) (> (window-hscroll) 0))
1644 (scroll-right (max (- column
) 10))
1645 (if (>= column
(- (window-width) 2))
1646 (scroll-left (max (- column
(window-width) -
3) 10)))))))
1649 ;;; Interactive word completion.
1650 ;;; Forces "previous-word" processing. Do we want to make this selectable?
1653 (defun ispell-complete-word (&optional interior-frag
)
1654 "Look up word before or under point in dictionary (see lookup-words command)
1655 and try to complete it. If optional INTERIOR-FRAG is non-nil then the word
1656 may be a character sequence inside of a word.
1658 Standard ispell choices are then available."
1660 (let ((cursor-location (point))
1661 ispell-keep-choices-win
1662 (word (ispell-get-word nil
"\\*")) ; force "previous-word" processing.
1663 start end possibilities replacement
)
1664 (setq start
(car (cdr word
))
1665 end
(car (cdr (cdr word
)))
1668 (or (string= word
"") ; Will give you every word
1669 (lookup-words (concat (if interior-frag
"*") word
"*")
1670 ispell-complete-word-dict
)))
1671 (cond ((eq possibilities t
)
1672 (message "No word to complete"))
1673 ((null possibilities
)
1674 (message "No match for \"%s\"" word
))
1675 (t ; There is a modification...
1678 (if ispell-highlight-p
1679 (highlight-spelling-error start end t
)) ; highlight word
1680 (setq replacement
(ispell-command-loop possibilities nil word
)))
1682 (if ispell-highlight-p
1683 (highlight-spelling-error start end
))) ; un-highlight
1685 ((equal 0 replacement
) ; BUFFER-LOCAL ADDITION
1686 (ispell-add-per-file-word-list word
))
1687 (replacement ; REPLACEMENT WORD
1688 (delete-region start end
)
1689 (setq word
(if (atom replacement
) replacement
(car replacement
))
1690 cursor-location
(+ (- (length word
) (- end start
))
1693 (if (not (atom replacement
)) ; recheck spelling of replacement.
1695 (goto-char cursor-location
)
1696 (ispell-word nil t
)))))
1697 (if (get-buffer ispell-choices-buffer
)
1698 (kill-buffer ispell-choices-buffer
))))
1699 (ispell-pdict-save ispell-silently-savep
)
1700 (goto-char cursor-location
)))
1704 (defun ispell-complete-word-interior-frag ()
1705 "Runs `ispell-complete-word' assuming that the word is a character sequence
1708 (ispell-complete-word t
))
1711 ;;; **********************************************************************
1713 ;;; **********************************************************************
1714 ;;; Original from D. Quinlan, E. Bradford, A. Albert, and M. Ernst
1717 (defvar ispell-message-text-end
1718 (mapconcat (function identity
)
1720 ;; Matches postscript files.
1722 ;; Matches uuencoded text
1723 "^begin [0-9][0-9][0-9] .*\nM.*\nM.*\nM"
1724 ;; Matches shell files (esp. auto-decoding)
1726 ;; Matches difference listing
1727 "diff -c .*\n\\*\\*\\* .*\n--- "
1728 ;; Matches "----------------- cut here"
1729 "^[-=]+\\s cut here")
1731 "*End of text which will be checked in ispell-message.
1732 If it is a string, limit at first occurence of that regular expression.
1733 Otherwise, it must be a function which is called to get the limit.")
1736 (defun ispell-message ()
1737 "Check the spelling of a mail message or news post.
1738 Don't check spelling of message headers except the Subject field.
1739 Don't check included messages.
1741 To abort spell checking of a message REGION and send the message anyway,
1742 use the 'x' or 'q' command. (Any subsequent regions will be checked.)
1743 The 'X' command aborts the message send so that you can edit the buffer.
1745 To spell-check whenever a message is sent, include the appropriate lines
1746 in your .emacs file:
1747 (add-hook 'news-inews-hook 'ispell-message)
1748 (add-hook 'mail-send-hook 'ispell-message)
1749 (add-hook 'mh-before-send-letter-hook 'ispell-message)
1751 Or you can bind the function C-c i in gnus or mail by setting
1752 news-reply-mode-hook or mail-mode-hook to the following lambda expression:
1753 (function (lambda () (local-set-key \"\\C-ci\" 'ispell-message)))"
1756 (beginning-of-buffer)
1757 (let* ((internal-messagep
1758 (search-forward mail-header-separator nil t
))
1761 ((not ispell-message-text-end
) (point-max))
1762 ((char-or-string-p ispell-message-text-end
)
1763 (if (re-search-forward ispell-message-text-end nil t
)
1766 (t (min (point-max) (funcall ispell-message-text-end
)))))
1767 (cite-regexp ;Prefix of inserted text
1769 ((featurep 'supercite
) ; sc 3.0
1770 (concat "\\(" (sc-cite-regexp) "\\)" "\\|"
1771 (ispell-non-empty-string sc-reference-tag-string
)))
1772 ((featurep 'sc
) ; sc 2.3
1773 (concat "\\(" sc-cite-regexp
"\\)" "\\|"
1774 (ispell-non-empty-string sc-reference-tag-string
)))
1775 ((equal major-mode
'news-reply-mode
) ;Gnus
1776 (concat "In article <" "\\|"
1777 (if mail-yank-prefix
1778 (ispell-non-empty-string mail-yank-prefix
)
1780 ((equal major-mode
'mh-letter-mode
) ; mh mail message
1781 (ispell-non-empty-string mh-ins-buf-prefix
))
1782 ((not internal-messagep
) ; Assume nn sent us this message.
1783 (concat "In [a-zA-Z.]+ you write:" "\\|"
1784 "In <[^,;&+=]+> [^,;&+=]+ writes:" "\\|"
1786 ((boundp 'vm-included-text-prefix
) ; VM mail message
1787 (concat "[^,;&+=]+ writes:" "\\|"
1788 (ispell-non-empty-string vm-included-text-prefix
)))
1789 (mail-yank-prefix ; vanilla mail message.
1790 (ispell-non-empty-string mail-yank-prefix
))
1792 (cite-regexp-start (concat "^[ \t]*$\\|" cite-regexp
))
1793 (cite-regexp-end (concat "^\\(" cite-regexp
"\\)"))
1794 (old-case-fold-search case-fold-search
)
1795 (case-fold-search t
)
1796 (ispell-checking-message t
))
1798 (beginning-of-buffer)
1799 ;; Skip header fields except Subject: without Re:'s
1800 ;;(search-forward mail-header-separator nil t)
1801 (while (if internal-messagep
1802 (< (point) internal-messagep
)
1803 (and (looking-at "[-a-zA-Z]+:\\|\t\\| ")
1806 ;; spell check Subject: field without Re:'s.
1807 (if (looking-at "Subject: *")
1809 (goto-char (match-end 0))
1810 (if (and (not (looking-at ".*Re\\>"))
1811 (not (looking-at "\\[")))
1812 (let ((case-fold-search old-case-fold-search
))
1813 (ispell-region (point)
1816 (while (looking-at "\n[ \t]")
1820 (setq case-fold-search nil
)
1821 ;; Skip mail header, particularly for non-english languages.
1822 (if (looking-at mail-header-separator
)
1824 (while (< (point) limit
)
1825 ;; Skip across text cited from other messages.
1826 (while (and (looking-at cite-regexp-start
)
1829 (if (< (point) limit
)
1830 ;; Check the next batch of lines that *aren't* cited.
1831 (let ((end (save-excursion
1832 (if (re-search-forward cite-regexp-end limit
'end
)
1835 (ispell-region (point) end
)
1836 (goto-char end
))))))))
1838 (defun ispell-non-empty-string (string)
1839 (if (or (not string
) (string-equal string
""))
1840 "\\'\\`" ; An unmatchable string if string is null.
1841 (regexp-quote string
)))
1844 ;;; **********************************************************************
1845 ;;; Buffer Local Functions
1846 ;;; **********************************************************************
1849 (defun ispell-accept-buffer-local-defs ()
1850 "Loads all buffer-local information, restarting ispell when necessary."
1851 (ispell-buffer-local-dict) ; May kill ispell-process.
1852 (ispell-buffer-local-words) ; Will initialize ispell-process.
1853 (ispell-buffer-local-parsing))
1856 ;;; Currently ispell version 3.0.09 (beta) doesn't fully support the "~"
1857 ;;; pipe mode command. Should be fixed in the next release.
1859 (defun ispell-buffer-local-parsing ()
1860 "Places ispell into parsing mode for this buffer.
1861 This overrides the default parsing mode.
1862 This includes latex/nroff modes and extended character mode."
1863 ;; (ispell-init-process) must already be called.
1864 (process-send-string ispell-process
"!\n") ; Put process in terse mode.
1865 ;; We assume all major modes with "tex-mode" in them should use latex parsing
1866 (if (or (and (eq ispell-parser
'use-mode-name
)
1867 (string-match "[Tt][Ee][Xx]-mode" (symbol-name major-mode
)))
1868 (eq ispell-parser
'tex
))
1869 (process-send-string ispell-process
"+\n") ; set ispell mode to tex
1870 (process-send-string ispell-process
"-\n")) ; set mode to normal (nroff)
1871 ;; Set default extended character mode for given buffer, if any.
1872 (let ((extended-char-mode (ispell-get-extended-character-mode)))
1873 (if extended-char-mode
1874 (process-send-string ispell-process
(concat extended-char-mode
"\n"))))
1875 ;; Set buffer-local parsing mode and extended charater mode, if specified.
1877 (goto-char (point-min))
1878 ;; Uses last valid definition
1879 (while (search-forward ispell-parsing-keyword nil t
)
1880 (let ((end (save-excursion (end-of-line) (point)))
1881 (case-fold-search t
)
1883 (while (re-search-forward " *\\([^ \"]+\\)" end t
)
1884 ;; space separated definitions.
1885 (setq string
(buffer-substring (match-beginning 1) (match-end 1)))
1886 (cond ((string-match "latex-mode" string
)
1887 (process-send-string ispell-process
"+\n"))
1888 ((string-match "nroff-mode" string
)
1889 (process-send-string ispell-process
"-\n"))
1890 ((string-match "~" string
) ; Set extended character mode.
1891 (process-send-string ispell-process
(concat string
"\n")))
1892 (t (message "Illegal Ispell Parsing argument!")
1896 ;;; Can kill the current ispell process
1898 (defun ispell-buffer-local-dict ()
1899 "Does necessary local dictionary initialization.
1900 When a dictionary is defined in the buffer (see variable
1901 ispell-dictionary-keyword), it will override the local setting
1902 from \\[ispell-change-dictionary].
1903 Both should not be used to define a buffer-local dictionary."
1905 (goto-char (point-min))
1907 ;; Override the local variable definition.
1908 ;; Uses last valid definition.
1909 (while (search-forward ispell-dictionary-keyword nil t
)
1910 (setq end
(save-excursion (end-of-line) (point)))
1911 (if (re-search-forward " *\\([^ \"]+\\)" end t
)
1912 (setq ispell-local-dictionary
1913 (buffer-substring (match-beginning 1) (match-end 1)))))
1914 (goto-char (point-min))
1915 (while (search-forward ispell-pdict-keyword nil t
)
1916 (setq end
(save-excursion (end-of-line) (point)))
1917 (if (re-search-forward " *\\([^ \"]+\\)" end t
)
1918 (setq ispell-local-pdict
1919 (buffer-substring (match-beginning 1) (match-end 1)))))))
1920 ;; Reload if new personal dictionary defined.
1921 (if (and ispell-local-pdict
1922 (not (equal ispell-local-pdict ispell-personal-dictionary
)))
1924 (ispell-kill-ispell t
)
1925 (setq ispell-personal-dictionary ispell-local-pdict
)))
1926 ;; Reload if new dictionary defined.
1927 (if (and ispell-local-dictionary
1928 (not (equal ispell-local-dictionary ispell-dictionary
)))
1929 (ispell-change-dictionary ispell-local-dictionary
)))
1932 (defun ispell-buffer-local-words ()
1933 "Loads the buffer-local \"dictionary\" in the current buffer."
1934 (if (and ispell-buffer-local-name
1935 (not (equal ispell-buffer-local-name
(buffer-name))))
1937 (ispell-kill-ispell t
)
1938 (setq ispell-buffer-local-name nil
)))
1939 (ispell-init-process)
1941 (goto-char (point-min))
1942 (while (search-forward ispell-words-keyword nil t
)
1943 (or ispell-buffer-local-name
1944 (setq ispell-buffer-local-name
(buffer-name)))
1945 (let ((end (save-excursion (end-of-line) (point)))
1947 (while (re-search-forward " *\\([^ \"]+\\)" end t
)
1948 (setq string
(buffer-substring (match-beginning 1) (match-end 1)))
1949 (process-send-string
1950 ispell-process
(concat "@" (buffer-substring (match-beginning 1)
1955 ;;; returns optionally adjusted region-end-point.
1957 (defun ispell-add-per-file-word-list (word &optional reg-end
)
1958 "Adds new word to the per-file word list."
1959 (or ispell-buffer-local-name
1960 (setq ispell-buffer-local-name
(buffer-name)))
1964 (goto-char (point-min))
1965 (let ((case-fold-search nil
)
1966 line-okay search done string
)
1968 (setq search
(search-forward ispell-words-keyword nil
'move
)
1969 line-okay
(< (+ (length word
) 1 ; 1 for space after word..
1970 (progn (end-of-line) (current-column)))
1972 (if (or (and search line-okay
)
1979 (setq string
(concat comment-start
" "
1980 ispell-words-keyword
))
1981 ;; in case the keyword is in the middle of the file....
1982 (if (> reg-end
(point))
1983 (setq reg-end
(+ reg-end
(length string
))))
1985 (if (and comment-end
(not (equal "" comment-end
)))
1989 (insert comment-end
)))))
1990 (if (> reg-end
(point))
1991 (setq reg-end
(+ 1 reg-end
(length word
))))
1992 (insert (concat " " word
)))))))
1996 (defconst ispell-version
"2.26 Tue Feb 15 16:11:14 MST 1994")
2001 ;;; LOCAL VARIABLES AND BUFFER-LOCAL VALUE EXAMPLES.
2003 ;;; Local Variable options:
2004 ;;; mode: name(-mode)
2005 ;;; eval: expression
2006 ;;; local-variable: value
2008 ;;; The following sets the buffer local dictionary to english!
2010 ;;; Local Variables:
2011 ;;; mode: emacs-lisp
2012 ;;; comment-column: 40
2013 ;;; ispell-local-dictionary: "english"
2017 ;;; MORE EXAMPLES OF ISPELL BUFFER-LOCAL VALUES
2019 ;;; The following places this file in nroff parsing and extended char modes.
2020 ;;; Local IspellParsing: nroff-mode ~nroff
2021 ;;; Change IspellDict to IspellDict: to enable the following line.
2022 ;;; Local IspellDict english
2023 ;;; Change IspellPersDict to IspellPersDict: to enable the following line.
2024 ;;; Local IspellPersDict ~/.ispell_lisp
2025 ;;; The following were automatically generated by ispell using the 'A' command:
2026 ; LocalWords: ispell ispell-highlight-p ispell-check-comments query-replace
2027 ; LocalWords: ispell-query-replace-choices ispell-skip-tib non-nil tib
2028 ; LocalWords: regexps ispell-tib-ref-beginning ispell-tib-ref-end
2030 ;; ispell.el ends here