]> code.delx.au - gnu-emacs/blob - lisp/textmodes/flyspell.el
(make-flyspell-overlay): fix front stickiness.
[gnu-emacs] / lisp / textmodes / flyspell.el
1 ;;; flyspell.el --- On-the-fly spell checker
2
3 ;; Copyright (C) 1998 Free Software Foundation, Inc.
4
5 ;; Author: Manuel Serrano <Manuel.Serrano@unice.fr>
6 ;; Keywords: convenience
7
8 ;;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; commentary:
26 ;;
27 ;; Flyspell is a minor Emacs mode performing on-the-fly spelling
28 ;; checking.
29 ;;
30 ;; To enable Flyspell minor mode, type Meta-x flyspell-mode.
31 ;; This applies only to the current buffer.
32 ;;
33 ;; Note: consider setting the variable ispell-parser to `tex' to
34 ;; avoid TeX command checking; use `(setq ispell-parser 'tex)'
35 ;; _before_ entering flyspell.
36 ;;
37 ;; Some user variables control the behavior of flyspell. They are
38 ;; those defined under the `User variables' comment.
39 ;;
40 ;; Note: as suggested by Yaron M. Minsky, if you use flyspell when
41 ;; sending mails, you should add the following:
42 ;; (add-hook 'mail-send-hook 'flyspell-mode-off)
43
44 ;;; Code:
45 (require 'ispell)
46
47 ;*---------------------------------------------------------------------*/
48 ;* Group ... */
49 ;*---------------------------------------------------------------------*/
50 (defgroup flyspell nil
51 "Spellchecking on the fly."
52 :tag "FlySpell"
53 :prefix "flyspell-"
54 :group 'processes
55 :version "20.3")
56
57 ;*---------------------------------------------------------------------*/
58 ;* User variables ... */
59 ;*---------------------------------------------------------------------*/
60 (defcustom flyspell-highlight-flag t
61 "*How Flyspell should indicate misspelled words.
62 Non-nil means use highlight, nil means use minibuffer messages."
63 :group 'flyspell
64 :type 'boolean)
65
66 (defcustom flyspell-mark-duplications-flag t
67 "*Non-nil means Flyspell reports a repeated word as an error."
68 :group 'flyspell
69 :type 'boolean)
70
71 (defcustom flyspell-sort-corrections t
72 "*Non-nil means, sort the corrections alphabetically before popping them."
73 :group 'flyspell
74 :type 'boolean)
75
76 (defcustom flyspell-duplicate-distance 10000
77 "*The maximum distance for finding duplicates of unrecognized words.
78 This applies to the feature that when a word is not found in the dictionary,
79 if the same spelling occurs elsewhere in the buffer,
80 Flyspell uses a different face (`flyspell-duplicate-face') to highlight it.
81 This variable specifies how far to search to find such a duplicate.
82 -1 means no limit (search the whole buffer).
83 0 means do not search for duplicate unrecognized spellings."
84 :group 'flyspell
85 :type 'number)
86
87 (defcustom flyspell-delay 3
88 "*The number of seconds to wait before checking, after a \"delayed\" command."
89 :group 'flyspell
90 :type 'number)
91
92 (defcustom flyspell-persistent-highlight t
93 "*Non-nil means misspelled words remain highlighted until corrected.
94 If this variable is nil, only the most recently detected misspelled word
95 is highlighted."
96 :group 'flyspell
97 :type 'boolean)
98
99 (defcustom flyspell-highlight-properties t
100 "*Non-nil means highlight incorrect words even if a property exists for this word."
101 :group 'flyspell
102 :type 'boolean)
103
104 (defcustom flyspell-default-delayed-commands
105 '(self-insert-command
106 delete-backward-char
107 delete-char)
108 "The standard list of delayed commands for Flyspell.
109 See `flyspell-delayed-commands'."
110 :group 'flyspell
111 :type '(repeat (symbol)))
112
113 (defcustom flyspell-delayed-commands nil
114 "List of commands that are \"delayed\" for Flyspell mode.
115 After these commands, Flyspell checking is delayed for a short time,
116 whose length is specified by `flyspell-delay'."
117 :group 'flyspell
118 :type '(repeat (symbol)))
119
120 (defcustom flyspell-issue-welcome-flag t
121 "*Non-nil means that Flyspell should display a welcome message when started."
122 :group 'flyspell
123 :type 'boolean)
124
125 (defcustom flyspell-consider-dash-as-word-delimiter-flag nil
126 "*Non-nil means that the `-' char is considered as a word delimiter."
127 :group 'flyspell
128 :type 'boolean)
129
130 (defcustom flyspell-incorrect-hook nil
131 "*List of functions to be called when incorrect words are encountered.
132 Each function is given two arguments: the beginning and the end
133 of the incorrect region."
134 :group 'flyspell)
135
136 (defcustom flyspell-multi-language-p nil
137 "*Non-nil means that Flyspell can be used with multiple languages.
138 This mode works by starting a separate Ispell process for each buffer,
139 so that each buffer can use its own language."
140 :group 'flyspell
141 :type 'boolean)
142
143 ;*---------------------------------------------------------------------*/
144 ;* Mode specific options */
145 ;* ------------------------------------------------------------- */
146 ;* Mode specific options enable users to disable flyspell on */
147 ;* certain word depending of the emacs mode. For instance, when */
148 ;* using flyspell with mail-mode add the following expression */
149 ;* in your .emacs file: */
150 ;* (add-hook 'mail-mode */
151 ;* '(lambda () (setq flyspell-generic-check-word-p */
152 ;* 'mail-mode-flyspell-verify))) */
153 ;*---------------------------------------------------------------------*/
154 (defvar flyspell-generic-check-word-p nil
155 "Function providing per-mode customization over which words are flyspelled.
156 Returns t to continue checking, nil otherwise.
157 Flyspell mode sets this variable to whatever is the `flyspell-mode-predicate'
158 property of the major mode name.")
159 (make-variable-buffer-local 'flyspell-generic-check-word-p)
160
161 (put 'mail-mode 'flyspell-mode-predicate 'mail-mode-flyspell-verify)
162 (put 'message-mode 'flyspell-mode-predicate 'mail-mode-flyspell-verify)
163 (defun mail-mode-flyspell-verify ()
164 "This function is used for `flyspell-generic-check-word-p' in Mail mode."
165 (save-excursion
166 (or (progn
167 (beginning-of-line)
168 (looking-at "Subject:"))
169 (not (or (re-search-forward mail-header-separator nil t)
170 (re-search-backward message-signature-separator nil t)
171 (progn
172 (beginning-of-line)
173 (looking-at "[>}|]")))))))
174
175 (put 'texinfo-mode 'flyspell-mode-predicate 'texinfo-mode-flyspell-verify)
176 (defun texinfo-mode-flyspell-verify ()
177 "This function is used for `flyspell-generic-check-word-p' in Texinfo mode."
178 (save-excursion
179 (forward-word -1)
180 (not (looking-at "@"))))
181
182 ;*---------------------------------------------------------------------*/
183 ;* Overlay compatibility */
184 ;*---------------------------------------------------------------------*/
185 (autoload 'make-overlay "overlay" "" t)
186 (autoload 'move-overlay "overlay" "" t)
187 (autoload 'overlayp "overlay" "" t)
188 (autoload 'overlay-properties "overlay" "" t)
189 (autoload 'overlays-in "overlay" "" t)
190 (autoload 'delete-overlay "overlay" "" t)
191 (autoload 'overlays-at "overlay" "" t)
192 (autoload 'overlay-put "overlay" "" t)
193 (autoload 'overlay-get "overlay" "" t)
194
195 ;*---------------------------------------------------------------------*/
196 ;* Which emacs are we currently running */
197 ;*---------------------------------------------------------------------*/
198 (defvar flyspell-emacs
199 (cond
200 ((string-match "XEmacs" emacs-version)
201 'xemacs)
202 (t
203 'emacs))
204 "The type of Emacs we are currently running.")
205
206 (defvar flyspell-use-local-map
207 (or (eq flyspell-emacs 'xemacs)
208 (not (string< emacs-version "20"))))
209
210 ;*---------------------------------------------------------------------*/
211 ;* The minor mode declaration. */
212 ;*---------------------------------------------------------------------*/
213 (defvar flyspell-mode nil)
214 (make-variable-buffer-local 'flyspell-mode)
215
216 (defvar flyspell-mode-map (make-sparse-keymap))
217 (defvar flyspell-mouse-map (make-sparse-keymap))
218
219 (or (assoc 'flyspell-mode minor-mode-alist)
220 (setq minor-mode-alist
221 (cons '(flyspell-mode " Fly") minor-mode-alist)))
222
223 ;; mouse or local-map bindings
224 (cond
225 ((eq flyspell-emacs 'xemacs)
226 (define-key flyspell-mouse-map [(button2)]
227 (function flyspell-correct-word/mouse-keymap))
228 (define-key flyspell-mouse-map "\M-\t" 'flyspell-auto-correct-word))
229 (flyspell-use-local-map
230 (define-key flyspell-mouse-map [(mouse-2)]
231 (function flyspell-correct-word/mouse-keymap))
232 (define-key flyspell-mouse-map "\M-\t" 'flyspell-auto-correct-word))
233 (t
234 (or (assoc 'flyspell-mode minor-mode-map-alist)
235 (setq minor-mode-map-alist
236 (cons (cons 'flyspell-mode flyspell-mode-map)
237 minor-mode-map-alist)))
238 (define-key flyspell-mode-map "\M-\t" 'flyspell-auto-correct-word)
239 (define-key flyspell-mode-map [(mouse-2)]
240 (function flyspell-correct-word/local-keymap))))
241
242 ;; the name of the overlay property that defines the keymap
243 (defvar flyspell-overlay-keymap-property-name
244 (if (string-match "19.*XEmacs" emacs-version)
245 'keymap
246 'local-map))
247
248 ;*---------------------------------------------------------------------*/
249 ;* Highlighting */
250 ;*---------------------------------------------------------------------*/
251 (defface flyspell-incorrect-face
252 '((((class color)) (:foreground "OrangeRed" :bold t :underline t))
253 (t (:bold t)))
254 "Face used for marking a misspelled word in Flyspell."
255 :group 'flyspell)
256
257 (defface flyspell-duplicate-face
258 '((((class color)) (:foreground "Gold3" :bold t :underline t))
259 (t (:bold t)))
260 "Face used for marking a misspelled word that appears twice in the buffer.
261 See also `flyspell-duplicate-distance'."
262 :group 'flyspell)
263
264 (defvar flyspell-overlay nil)
265
266 ;*---------------------------------------------------------------------*/
267 ;* flyspell-mode ... */
268 ;*---------------------------------------------------------------------*/
269 ;;;###autoload
270 (defun flyspell-mode (&optional arg)
271 "Minor mode performing on-the-fly spelling checking.
272 Ispell is automatically spawned on background for each entered words.
273 The default flyspell behavior is to highlight incorrect words.
274 With no argument, this command toggles Flyspell mode.
275 With a prefix argument ARG, turn Flyspell minor mode on iff ARG is positive.
276
277 Bindings:
278 \\[ispell-word]: correct words (using Ispell).
279 \\[flyspell-auto-correct-word]: automatically correct word.
280 \\[flyspell-correct-word] (or mouse-2): popup correct words.
281
282 Hooks:
283 flyspell-mode-hook is run after flyspell is entered.
284
285 Remark:
286 `flyspell-mode' uses `ispell-mode'. Thus all Ispell options are
287 valid. For instance, a personal dictionary can be used by
288 invoking `ispell-change-dictionary'.
289
290 Consider using the `ispell-parser' to check your text. For instance
291 consider adding:
292 \(add-hook 'tex-mode-hook (function (lambda () (setq ispell-parser 'tex))))
293 in your .emacs file.
294
295 flyspell-region checks all words inside a region.
296
297 flyspell-buffer checks the whole buffer."
298 (interactive "P")
299 (let ((old-flyspell-mode flyspell-mode))
300 ;; Mark the mode as on or off.
301 (setq flyspell-mode (not (or (and (null arg) flyspell-mode)
302 (<= (prefix-numeric-value arg) 0))))
303 ;; Do the real work.
304 (unless (eq flyspell-mode old-flyspell-mode)
305 (if flyspell-mode
306 (flyspell-mode-on)
307 (flyspell-mode-off))
308 ;; Force modeline redisplay.
309 (set-buffer-modified-p (buffer-modified-p)))))
310
311 ;*---------------------------------------------------------------------*/
312 ;* flyspell-mode-on ... */
313 ;*---------------------------------------------------------------------*/
314 (defun flyspell-mode-on ()
315 "Turn Flyspell mode on. Do not use this; use `flyspell-mode' instead."
316 (setq ispell-highlight-face 'flyspell-incorrect-face)
317 ;; ispell initialization
318 (if flyspell-multi-language-p
319 (progn
320 (make-variable-buffer-local 'ispell-dictionary)
321 (make-variable-buffer-local 'ispell-process)
322 (make-variable-buffer-local 'ispell-filter)
323 (make-variable-buffer-local 'ispell-filter-continue)
324 (make-variable-buffer-local 'ispell-process-directory)
325 (make-variable-buffer-local 'ispell-parser)
326 (put 'ispell-dictionary 'permanent-local t)
327 (put 'ispell-process 'permanent-local t)
328 (put 'ispell-filter 'permanent-local t)
329 (put 'ispell-filter-continue 'permanent-local t)
330 (put 'ispell-process-directory 'permanent-local t)
331 (put 'ispell-parser 'permanent-local t)))
332 ;; We put the `flyspell-delayed' property on some commands.
333 (flyspell-delay-commands)
334 ;; we bound flyspell action to post-command hook
335 (make-local-hook 'post-command-hook)
336 (add-hook 'post-command-hook (function flyspell-post-command-hook) t t)
337 ;; we bound flyspell action to pre-command hook
338 (make-local-hook 'pre-command-hook)
339 (add-hook 'pre-command-hook (function flyspell-pre-command-hook) t t)
340
341 ;; Set flyspell-generic-check-word-p based on the major mode.
342 (let ((mode-predicate (get major-mode 'flyspell-mode-predicate)))
343 (if mode-predicate
344 (setq flyspell-generic-check-word-p mode-predicate)))
345
346 ;; the welcome message
347 (if flyspell-issue-welcome-flag
348 (let ((binding (where-is-internal 'flyspell-auto-correct-word
349 nil 'non-ascii)))
350 (message
351 (if binding
352 (format "Welcome to flyspell. Use %s or Mouse-2 to correct words."
353 (key-description binding))
354 "Welcome to flyspell. Use Mouse-2 to correct words."))))
355 ;; we have to kill the flyspell process when the buffer is deleted.
356 ;; (thanks to Jeff Miller and Roland Rosenfeld who sent me this
357 ;; improvement).
358 (add-hook 'kill-buffer-hook
359 '(lambda ()
360 (if (and flyspell-multi-language-p ispell-process)
361 (ispell-kill-ispell t))))
362 ;; we end with the flyspell hooks
363 (run-hooks 'flyspell-mode-hook))
364
365 ;*---------------------------------------------------------------------*/
366 ;* flyspell-delay-commands ... */
367 ;*---------------------------------------------------------------------*/
368 (defun flyspell-delay-commands ()
369 "Install the standard set of Flyspell delayed commands."
370 (mapcar 'flyspell-delay-command flyspell-default-delayed-commands)
371 (mapcar 'flyspell-delay-command flyspell-delayed-commands))
372
373 ;*---------------------------------------------------------------------*/
374 ;* flyspell-delay-command ... */
375 ;*---------------------------------------------------------------------*/
376 (defun flyspell-delay-command (command)
377 "Set COMMAND to be delayed, for Flyspell.
378 When flyspell `post-command-hook' is invoked because a delayed command
379 as been used the current word is not immediatly checked.
380 It will be checked only after `flyspell-delay' seconds."
381 (interactive "SDelay Flyspell after Command: ")
382 (put command 'flyspell-delayed t))
383
384 ;*---------------------------------------------------------------------*/
385 ;* flyspell-ignore-commands ... */
386 ;*---------------------------------------------------------------------*/
387 (defun flyspell-ignore-commands ()
388 "This is an obsolete function, use `flyspell-delay-commands' instead."
389 (flyspell-delay-commands))
390
391 ;*---------------------------------------------------------------------*/
392 ;* flyspell-ignore-command ... */
393 ;*---------------------------------------------------------------------*/
394 (defun flyspell-ignore-command (command)
395 "This is an obsolete function, use `flyspell-delay-command' instead.
396 COMMAND is the name of the command to be delayed."
397 (flyspell-delay-command command))
398
399 (make-obsolete 'flyspell-ignore-commands 'flyspell-delay-commands)
400 (make-obsolete 'flyspell-ignore-command 'flyspell-delay-command)
401
402 ;*---------------------------------------------------------------------*/
403 ;* flyspell-word-cache ... */
404 ;*---------------------------------------------------------------------*/
405 (defvar flyspell-word-cache-start nil)
406 (defvar flyspell-word-cache-end nil)
407 (defvar flyspell-word-cache-word nil)
408 (make-variable-buffer-local 'flyspell-word-cache-start)
409 (make-variable-buffer-local 'flyspell-word-cache-end)
410 (make-variable-buffer-local 'flyspell-word-cache-word)
411
412 ;*---------------------------------------------------------------------*/
413 ;* The flyspell pre-hook, store the current position. In the */
414 ;* post command hook, we will check, if the word at this position */
415 ;* has to be spell checked. */
416 ;*---------------------------------------------------------------------*/
417 (defvar flyspell-pre-buffer nil)
418 (defvar flyspell-pre-point nil)
419
420 ;*---------------------------------------------------------------------*/
421 ;* flyspell-pre-command-hook ... */
422 ;*---------------------------------------------------------------------*/
423 (defun flyspell-pre-command-hook ()
424 "Save the current buffer and point for Flyspell's post-command hook."
425 (interactive)
426 (setq flyspell-pre-buffer (current-buffer))
427 (setq flyspell-pre-point (point)))
428
429 ;*---------------------------------------------------------------------*/
430 ;* flyspell-mode-off ... */
431 ;*---------------------------------------------------------------------*/
432 ;;;###autoload
433 (defun flyspell-mode-off ()
434 "Turn Flyspell mode off."
435 ;; If we have an Ispell process for each buffer,
436 ;; kill the one for this buffer.
437 (if flyspell-multi-language-p
438 (ispell-kill-ispell t))
439 ;; we remove the hooks
440 (remove-hook 'post-command-hook (function flyspell-post-command-hook) t)
441 (remove-hook 'pre-command-hook (function flyspell-pre-command-hook) t)
442 ;; we remove all the flyspell hilightings
443 (flyspell-delete-all-overlays)
444 ;; we have to erase pre cache variables
445 (setq flyspell-pre-buffer nil)
446 (setq flyspell-pre-point nil)
447 ;; we mark the mode as killed
448 (setq flyspell-mode nil))
449
450 ;*---------------------------------------------------------------------*/
451 ;* flyspell-check-word-p ... */
452 ;*---------------------------------------------------------------------*/
453 (defun flyspell-check-word-p ()
454 "Return t when the word at `point' has to be checked.
455 The answer depends of several criteria.
456 Mostly we check word delimiters."
457 (cond
458 ((<= (- (point-max) 1) (point-min))
459 ;; the buffer is not filled enough
460 nil)
461 ((not (and (symbolp this-command) (get this-command 'flyspell-delayed)))
462 ;; the current command is not delayed, that
463 ;; is that we must check the word now
464 t)
465 ((and (> (point) (point-min))
466 (save-excursion
467 (backward-char 1)
468 (and (looking-at (flyspell-get-not-casechars))
469 (or flyspell-consider-dash-as-word-delimiter-flag
470 (not (looking-at "\\-"))))))
471 ;; yes because we have reached or typed a word delimiter.
472 t)
473 ((not (integerp flyspell-delay))
474 ;; yes because the user had set up a no-delay configuration.
475 t)
476 (executing-kbd-macro
477 ;; Don't delay inside a keyboard macro.
478 t)
479 (t
480 (if (fboundp 'about-xemacs)
481 (sit-for flyspell-delay nil)
482 (sit-for flyspell-delay 0 nil)))))
483
484 ;*---------------------------------------------------------------------*/
485 ;* flyspell-check-pre-word-p ... */
486 ;*---------------------------------------------------------------------*/
487 (defun flyspell-check-pre-word-p ()
488 "Return non-nil if we should to check the word before point.
489 More precisely, it applies to the word that was before point
490 before the current command."
491 (cond
492 ((or (not (numberp flyspell-pre-point))
493 (not (bufferp flyspell-pre-buffer))
494 (not (buffer-live-p flyspell-pre-buffer)))
495 nil)
496 ((or (and (= flyspell-pre-point (- (point) 1))
497 (eq (char-syntax (char-after flyspell-pre-point)) ?w))
498 (= flyspell-pre-point (point))
499 (= flyspell-pre-point (+ (point) 1)))
500 nil)
501 ((not (eq (current-buffer) flyspell-pre-buffer))
502 t)
503 ((not (and (numberp flyspell-word-cache-start)
504 (numberp flyspell-word-cache-end)))
505 t)
506 (t
507 (or (< flyspell-pre-point flyspell-word-cache-start)
508 (> flyspell-pre-point flyspell-word-cache-end)))))
509
510 ;*---------------------------------------------------------------------*/
511 ;* flyspell-post-command-hook ... */
512 ;*---------------------------------------------------------------------*/
513 (defun flyspell-post-command-hook ()
514 "The `post-command-hook' used by flyspell to check a word in-the-fly."
515 (interactive)
516 (if (flyspell-check-word-p)
517 (flyspell-word))
518 (if (flyspell-check-pre-word-p)
519 (save-excursion
520 (set-buffer flyspell-pre-buffer)
521 (save-excursion
522 (goto-char flyspell-pre-point)
523 (flyspell-word)))))
524
525 ;*---------------------------------------------------------------------*/
526 ;* flyspell-word ... */
527 ;*---------------------------------------------------------------------*/
528 (defun flyspell-word (&optional following)
529 "Spell check a word."
530 (interactive (list current-prefix-arg))
531 (if (interactive-p)
532 (setq following ispell-following-word))
533 (save-excursion
534 (ispell-accept-buffer-local-defs) ; use the correct dictionary
535 (let ((cursor-location (point)) ; retain cursor location
536 (word (flyspell-get-word following))
537 start end poss)
538 (if (or (eq word nil)
539 (and (fboundp flyspell-generic-check-word-p)
540 (not (funcall flyspell-generic-check-word-p))))
541 t
542 (progn
543 ;; destructure return word info list.
544 (setq start (car (cdr word))
545 end (car (cdr (cdr word)))
546 word (car word))
547 ;; before checking in the directory, we check for doublons.
548 (cond
549 ((and flyspell-mark-duplications-flag
550 (save-excursion
551 (goto-char start)
552 (word-search-backward word
553 (- start
554 (+ 1 (- end start)))
555 t)))
556 ;; yes, this is a doublon
557 (flyspell-highlight-incorrect-region start end))
558 ((and (eq flyspell-word-cache-start start)
559 (eq flyspell-word-cache-end end)
560 (string-equal flyspell-word-cache-word word))
561 ;; this word had been already checked, we skip
562 nil)
563 ((and (eq ispell-parser 'tex)
564 (flyspell-tex-command-p word))
565 ;; this is a correct word (because a tex command)
566 (flyspell-unhighlight-at start)
567 (if (> end start)
568 (flyspell-unhighlight-at (- end 1)))
569 t)
570 (t
571 ;; we setup the cache
572 (setq flyspell-word-cache-start start)
573 (setq flyspell-word-cache-end end)
574 (setq flyspell-word-cache-word word)
575 ;; now check spelling of word.
576 (process-send-string ispell-process "%\n")
577 ;; put in verbose mode
578 (process-send-string ispell-process
579 (concat "^" word "\n"))
580 ;; we mark the ispell process so it can be killed
581 ;; when emacs is exited without query
582 (if (fboundp 'process-kill-without-query)
583 (process-kill-without-query ispell-process))
584 ;; wait until ispell has processed word
585 (while (progn
586 (accept-process-output ispell-process)
587 (not (string= "" (car ispell-filter)))))
588 ;; (process-send-string ispell-process "!\n")
589 ;; back to terse mode.
590 (setq ispell-filter (cdr ispell-filter))
591 (if (listp ispell-filter)
592 (setq poss (ispell-parse-output (car ispell-filter))))
593 (cond ((eq poss t)
594 ;; correct
595 (flyspell-unhighlight-at start)
596 (if (> end start)
597 (flyspell-unhighlight-at (- end 1)))
598 t)
599 ((and (stringp poss) flyspell-highlight-flag)
600 ;; correct
601 (flyspell-unhighlight-at start)
602 (if (> end start)
603 (flyspell-unhighlight-at (- end 1)))
604 t)
605 ((null poss)
606 (flyspell-unhighlight-at start)
607 (if (> end start)
608 (flyspell-unhighlight-at (- end 1)))
609 (message "Error in ispell process"))
610 ((or (and (< flyspell-duplicate-distance 0)
611 (or (save-excursion
612 (goto-char start)
613 (word-search-backward word
614 (point-min)
615 t))
616 (save-excursion
617 (goto-char end)
618 (word-search-forward word
619 (point-max)
620 t))))
621 (and (> flyspell-duplicate-distance 0)
622 (or (save-excursion
623 (goto-char start)
624 (word-search-backward
625 word
626 (- start
627 flyspell-duplicate-distance)
628 t))
629 (save-excursion
630 (goto-char end)
631 (word-search-forward
632 word
633 (+ end
634 flyspell-duplicate-distance)
635 t)))))
636 (if flyspell-highlight-flag
637 (flyspell-highlight-duplicate-region start end)
638 (message (format "duplicate `%s'" word))))
639 (t
640 ;; incorrect highlight the location
641 (if flyspell-highlight-flag
642 (flyspell-highlight-incorrect-region start end)
643 (message (format "mispelling `%s'" word)))))
644 (goto-char cursor-location) ; return to original location
645 (if ispell-quit (setq ispell-quit nil)))))))))
646
647 ;*---------------------------------------------------------------------*/
648 ;* flyspell-tex-command-p ... */
649 ;*---------------------------------------------------------------------*/
650 (defun flyspell-tex-command-p (word)
651 "Return t if WORD is a TeX command."
652 (eq (aref word 0) ?\\))
653
654 ;*---------------------------------------------------------------------*/
655 ;* flyspell-casechars-cache ... */
656 ;*---------------------------------------------------------------------*/
657 (defvar flyspell-casechars-cache nil)
658 (defvar flyspell-ispell-casechars-cache nil)
659 (make-variable-buffer-local 'flyspell-casechars-cache)
660 (make-variable-buffer-local 'flyspell-ispell-casechars-cache)
661
662 ;*---------------------------------------------------------------------*/
663 ;* flyspell-get-casechars ... */
664 ;*---------------------------------------------------------------------*/
665 (defun flyspell-get-casechars ()
666 "This function builds a string that is the regexp of word chars.
667 In order to avoid one useless string construction,
668 this function changes the last char of the `ispell-casechars' string."
669 (let ((ispell-casechars (ispell-get-casechars)))
670 (cond
671 ((eq ispell-casechars flyspell-ispell-casechars-cache)
672 flyspell-casechars-cache)
673 ((not (eq ispell-parser 'tex))
674 (setq flyspell-ispell-casechars-cache ispell-casechars)
675 (setq flyspell-casechars-cache
676 (concat (substring ispell-casechars
677 0
678 (- (length ispell-casechars) 1))
679 "{}]"))
680 flyspell-casechars-cache)
681 (t
682 (setq flyspell-ispell-casechars-cache ispell-casechars)
683 (setq flyspell-casechars-cache ispell-casechars)
684 flyspell-casechars-cache))))
685
686 ;*---------------------------------------------------------------------*/
687 ;* flyspell-get-not-casechars-cache ... */
688 ;*---------------------------------------------------------------------*/
689 (defvar flyspell-not-casechars-cache nil)
690 (defvar flyspell-ispell-not-casechars-cache nil)
691 (make-variable-buffer-local 'flyspell-not-casechars-cache)
692 (make-variable-buffer-local 'flyspell-ispell-not-casechars-cache)
693
694 ;*---------------------------------------------------------------------*/
695 ;* flyspell-get-not-casechars ... */
696 ;*---------------------------------------------------------------------*/
697 (defun flyspell-get-not-casechars ()
698 "This function builds a string that is the regexp of non-word chars."
699 (let ((ispell-not-casechars (ispell-get-not-casechars)))
700 (cond
701 ((eq ispell-not-casechars flyspell-ispell-not-casechars-cache)
702 flyspell-not-casechars-cache)
703 ((not (eq ispell-parser 'tex))
704 (setq flyspell-ispell-not-casechars-cache ispell-not-casechars)
705 (setq flyspell-not-casechars-cache
706 (concat (substring ispell-not-casechars
707 0
708 (- (length ispell-not-casechars) 1))
709 "{}]"))
710 flyspell-not-casechars-cache)
711 (t
712 (setq flyspell-ispell-not-casechars-cache ispell-not-casechars)
713 (setq flyspell-not-casechars-cache ispell-not-casechars)
714 flyspell-not-casechars-cache))))
715
716 ;*---------------------------------------------------------------------*/
717 ;* flyspell-get-word ... */
718 ;*---------------------------------------------------------------------*/
719 (defun flyspell-get-word (following)
720 "Return the word for spell-checking according to Ispell syntax.
721 If optional argument FOLLOWING is non-nil or if `ispell-following-word'
722 is non-nil when called interactively, then the following word
723 \(rather than preceding\) is checked when the cursor is not over a word.
724 Optional second argument contains otherchars that can be included in word
725 many times.
726
727 Word syntax described by `ispell-dictionary-alist' (which see)."
728 (let* ((flyspell-casechars (flyspell-get-casechars))
729 (flyspell-not-casechars (flyspell-get-not-casechars))
730 (ispell-otherchars (ispell-get-otherchars))
731 (ispell-many-otherchars-p (ispell-get-many-otherchars-p))
732 (word-regexp (concat flyspell-casechars
733 "+\\("
734 ispell-otherchars
735 "?"
736 flyspell-casechars
737 "+\\)"
738 (if ispell-many-otherchars-p
739 "*" "?")))
740 (tex-prelude "[\\\\{]")
741 (tex-regexp (if (eq ispell-parser 'tex)
742 (concat tex-prelude "?" word-regexp "}?")
743 word-regexp))
744
745 did-it-once
746 start end word)
747 ;; find the word
748 (if (not (or (looking-at flyspell-casechars)
749 (and (eq ispell-parser 'tex)
750 (looking-at tex-prelude))))
751 (if following
752 (re-search-forward flyspell-casechars (point-max) t)
753 (re-search-backward flyspell-casechars (point-min) t)))
754 ;; move to front of word
755 (re-search-backward flyspell-not-casechars (point-min) 'start)
756 (let ((pos nil))
757 (while (and (looking-at ispell-otherchars)
758 (not (bobp))
759 (or (not did-it-once)
760 ispell-many-otherchars-p)
761 (not (eq pos (point))))
762 (setq pos (point))
763 (setq did-it-once t)
764 (backward-char 1)
765 (if (looking-at flyspell-casechars)
766 (re-search-backward flyspell-not-casechars (point-min) 'move)
767 (backward-char -1))))
768 ;; Now mark the word and save to string.
769 (if (eq (re-search-forward tex-regexp (point-max) t) nil)
770 nil
771 (progn
772 (setq start (match-beginning 0)
773 end (point)
774 word (buffer-substring start end))
775 (list word start end)))))
776
777 ;*---------------------------------------------------------------------*/
778 ;* flyspell-region ... */
779 ;*---------------------------------------------------------------------*/
780 (defun flyspell-region (beg end)
781 "Flyspell text between BEG and END."
782 (interactive "r")
783 (save-excursion
784 (if (> beg end)
785 (let ((old beg))
786 (setq beg end)
787 (setq end old)))
788 (goto-char beg)
789 (let ((count 0))
790 (while (< (point) end)
791 (if (= count 100)
792 (progn
793 (message "Spell Checking...%d%%"
794 (* 100 (/ (float (- (point) beg)) (- end beg))))
795 (setq count 0))
796 (setq count (+ 1 count)))
797 (flyspell-word)
798 (let ((cur (point)))
799 (forward-word 1)
800 (if (and (< (point) end) (> (point) (+ cur 1)))
801 (backward-char 1)))))
802 (backward-char 1)
803 (message "Spell Checking...done")
804 (flyspell-word)))
805
806 ;*---------------------------------------------------------------------*/
807 ;* flyspell-buffer ... */
808 ;*---------------------------------------------------------------------*/
809 (defun flyspell-buffer ()
810 "Flyspell whole buffer."
811 (interactive)
812 (flyspell-region (point-min) (point-max)))
813
814 ;*---------------------------------------------------------------------*/
815 ;* flyspell-overlay-p ... */
816 ;*---------------------------------------------------------------------*/
817 (defun flyspell-overlay-p (o)
818 "A predicate that return true iff O is an overlay used by flyspell."
819 (and (overlayp o) (overlay-get o 'flyspell-overlay)))
820
821 ;*---------------------------------------------------------------------*/
822 ;* flyspell-delete-all-overlays ... */
823 ;* ------------------------------------------------------------- */
824 ;* Remove all the overlays introduced by flyspell. */
825 ;*---------------------------------------------------------------------*/
826 (defun flyspell-delete-all-overlays ()
827 "Delete all the overlays used by flyspell."
828 (let ((l (overlays-in (point-min) (point-max))))
829 (while (consp l)
830 (progn
831 (if (flyspell-overlay-p (car l))
832 (delete-overlay (car l)))
833 (setq l (cdr l))))))
834
835 ;*---------------------------------------------------------------------*/
836 ;* flyspell-unhighlight-at ... */
837 ;*---------------------------------------------------------------------*/
838 (defun flyspell-unhighlight-at (pos)
839 "Remove the flyspell overlay that are located at POS."
840 (if flyspell-persistent-highlight
841 (let ((overlays (overlays-at pos)))
842 (while (consp overlays)
843 (if (flyspell-overlay-p (car overlays))
844 (delete-overlay (car overlays)))
845 (setq overlays (cdr overlays))))
846 (delete-overlay flyspell-overlay)))
847
848 ;*---------------------------------------------------------------------*/
849 ;* flyspell-properties-at-p ... */
850 ;* ------------------------------------------------------------- */
851 ;* Is there an highlight properties at position pos? */
852 ;*---------------------------------------------------------------------*/
853 (defun flyspell-properties-at-p (pos)
854 "Return t if there is a text property at POS, not counting `local-map'.
855 If variable `flyspell-highlight-properties' is set to nil,
856 text with properties are not checked. This function is used to discover
857 if the character at POS has any other property."
858 (let ((prop (text-properties-at pos))
859 (keep t))
860 (while (and keep (consp prop))
861 (if (and (eq (car prop) 'local-map) (consp (cdr prop)))
862 (setq prop (cdr (cdr prop)))
863 (setq keep nil)))
864 (consp prop)))
865
866 ;*---------------------------------------------------------------------*/
867 ;* make-flyspell-overlay ... */
868 ;*---------------------------------------------------------------------*/
869 (defun make-flyspell-overlay (beg end face mouse-face)
870 "Allocate an overlay to highlight an incorrect word.
871 BEG and END specify the range in the buffer of that word.
872 FACE and MOUSE-FACE specify the `face' and `mouse-face' properties
873 for the overlay."
874 (let ((flyspell-overlay (make-overlay beg end nil t nil)))
875 (overlay-put flyspell-overlay 'face face)
876 (overlay-put flyspell-overlay 'mouse-face mouse-face)
877 (overlay-put flyspell-overlay 'flyspell-overlay t)
878 (if flyspell-use-local-map
879 (overlay-put flyspell-overlay
880 flyspell-overlay-keymap-property-name
881 flyspell-mouse-map))))
882
883 ;*---------------------------------------------------------------------*/
884 ;* flyspell-highlight-incorrect-region ... */
885 ;*---------------------------------------------------------------------*/
886 (defun flyspell-highlight-incorrect-region (beg end)
887 "Set up an overlay on a misspelled word, in the buffer from BEG to END."
888 (run-hook-with-args 'flyspell-incorrect-hook beg end)
889 (if (or flyspell-highlight-properties (not (flyspell-properties-at-p beg)))
890 (progn
891 ;; we cleanup current overlay at the same position
892 (if (and (not flyspell-persistent-highlight)
893 (overlayp flyspell-overlay))
894 (delete-overlay flyspell-overlay)
895 (let ((overlays (overlays-at beg)))
896 (while (consp overlays)
897 (if (flyspell-overlay-p (car overlays))
898 (delete-overlay (car overlays)))
899 (setq overlays (cdr overlays)))))
900 ;; now we can use a new overlay
901 (setq flyspell-overlay
902 (make-flyspell-overlay beg end
903 'flyspell-incorrect-face 'highlight)))))
904
905 ;*---------------------------------------------------------------------*/
906 ;* flyspell-highlight-duplicate-region ... */
907 ;*---------------------------------------------------------------------*/
908 (defun flyspell-highlight-duplicate-region (beg end)
909 "Set up an overlay on a duplicated word, in the buffer from BEG to END."
910 (if (or flyspell-highlight-properties (not (flyspell-properties-at-p beg)))
911 (progn
912 ;; we cleanup current overlay at the same position
913 (if (and (not flyspell-persistent-highlight)
914 (overlayp flyspell-overlay))
915 (delete-overlay flyspell-overlay)
916 (let ((overlays (overlays-at beg)))
917 (while (consp overlays)
918 (if (flyspell-overlay-p (car overlays))
919 (delete-overlay (car overlays)))
920 (setq overlays (cdr overlays)))))
921 ;; now we can use a new overlay
922 (setq flyspell-overlay
923 (make-flyspell-overlay beg end
924 'flyspell-duplicate-face 'highlight)))))
925
926 ;*---------------------------------------------------------------------*/
927 ;* flyspell-auto-correct-cache ... */
928 ;*---------------------------------------------------------------------*/
929 (defvar flyspell-auto-correct-pos nil)
930 (defvar flyspell-auto-correct-region nil)
931 (defvar flyspell-auto-correct-ring nil)
932
933 ;*---------------------------------------------------------------------*/
934 ;* flyspell-auto-correct-word ... */
935 ;*---------------------------------------------------------------------*/
936 (defun flyspell-auto-correct-word (pos)
937 "Correct the word at POS.
938 This command proposes various successive corrections for the word at POS.
939 The variable `flyspell-auto-correct-binding' specifies the key to bind
940 to this command."
941 (interactive "d")
942 ;; use the correct dictionary
943 (ispell-accept-buffer-local-defs)
944 (if (eq flyspell-auto-correct-pos pos)
945 ;; we have already been using the function at the same location
946 (progn
947 (save-excursion
948 (let ((start (car flyspell-auto-correct-region))
949 (len (cdr flyspell-auto-correct-region)))
950 (delete-region start (+ start len))
951 (setq flyspell-auto-correct-ring (cdr flyspell-auto-correct-ring))
952 (let* ((word (car flyspell-auto-correct-ring))
953 (len (length word)))
954 (rplacd flyspell-auto-correct-region len)
955 (goto-char start)
956 (insert word))))
957 (setq flyspell-auto-correct-pos (point)))
958 ;; retain cursor location
959 (let ((cursor-location pos)
960 (word (flyspell-get-word nil))
961 start end poss)
962 ;; destructure return word info list.
963 (setq start (car (cdr word))
964 end (car (cdr (cdr word)))
965 word (car word))
966 ;; now check spelling of word.
967 (process-send-string ispell-process "%\n") ;put in verbose mode
968 (process-send-string ispell-process (concat "^" word "\n"))
969 ;; wait until ispell has processed word
970 (while (progn
971 (accept-process-output ispell-process)
972 (not (string= "" (car ispell-filter)))))
973 (setq ispell-filter (cdr ispell-filter))
974 (if (listp ispell-filter)
975 (setq poss (ispell-parse-output (car ispell-filter))))
976 (cond ((or (eq poss t) (stringp poss))
977 ;; don't correct word
978 t)
979 ((null poss)
980 ;; ispell error
981 (error "Ispell: error in Ispell process"))
982 (t
983 ;; the word is incorrect, we have to propose a replacement
984 (let ((replacements (if flyspell-sort-corrections
985 (sort (car (cdr (cdr poss))) 'string<)
986 (car (cdr (cdr poss))))))
987 (if (consp replacements)
988 (progn
989 (let ((replace (car replacements)))
990 (setq word replace)
991 (setq cursor-location (+ (- (length word) (- end start))
992 cursor-location))
993 (if (not (equal word (car poss)))
994 (progn
995 ;; the save the current replacements
996 (setq flyspell-auto-correct-pos cursor-location)
997 (setq flyspell-auto-correct-region
998 (cons start (length word)))
999 (let ((l replacements))
1000 (while (consp (cdr l))
1001 (setq l (cdr l)))
1002 (rplacd l (cons (car poss) replacements)))
1003 (setq flyspell-auto-correct-ring
1004 (cdr replacements))
1005 (delete-region start end)
1006 (insert word)))))))))
1007 ;; return to original location
1008 (goto-char cursor-location)
1009 (ispell-pdict-save t))))
1010
1011 ;*---------------------------------------------------------------------*/
1012 ;* flyspell-correct-word ... */
1013 ;*---------------------------------------------------------------------*/
1014 (defun flyspell-correct-word (event)
1015 "Check spelling of word under or before the cursor.
1016 If the word is not found in dictionary, display possible corrections
1017 in a popup menu allowing you to choose one.
1018
1019 Word syntax described by `ispell-dictionary-alist' (which see).
1020
1021 This will check or reload the dictionary. Use \\[ispell-change-dictionary]
1022 or \\[ispell-region] to update the Ispell process."
1023 (interactive "e")
1024 (if flyspell-use-local-map
1025 (flyspell-correct-word/mouse-keymap event)
1026 (flyspell-correct-word/local-keymap event)))
1027
1028 ;*---------------------------------------------------------------------*/
1029 ;* flyspell-correct-word/local-keymap ... */
1030 ;*---------------------------------------------------------------------*/
1031 (defun flyspell-correct-word/local-keymap (event)
1032 "emacs 19.xx seems to be buggous. Overlay keymap does not seems
1033 to work correctly with local map. That is, if a key is not
1034 defined for the overlay keymap, the current local map, is not
1035 checked. The binding is resolved with the global map. The
1036 consequence is that we can not use overlay map with flyspell."
1037 (interactive "e")
1038 (save-window-excursion
1039 (let ((save (point)))
1040 (mouse-set-point event)
1041 ;; we look for a flyspell overlay here
1042 (let ((overlays (overlays-at (point)))
1043 (overlay nil))
1044 (while (consp overlays)
1045 (if (flyspell-overlay-p (car overlays))
1046 (progn
1047 (setq overlay (car overlays))
1048 (setq overlays nil))
1049 (setq overlays (cdr overlays))))
1050 ;; we return to the correct location
1051 (goto-char save)
1052 ;; we check to see if button2 has been used overlay a
1053 ;; flyspell overlay
1054 (if overlay
1055 ;; yes, so we use the flyspell function
1056 (flyspell-correct-word/mouse-keymap event)
1057 ;; no so we have to use the non flyspell binding
1058 (let ((flyspell-mode nil))
1059 (if (key-binding (this-command-keys))
1060 (command-execute (key-binding (this-command-keys))))))))))
1061
1062 ;*---------------------------------------------------------------------*/
1063 ;* flyspell-correct-word ... */
1064 ;*---------------------------------------------------------------------*/
1065 (defun flyspell-correct-word/mouse-keymap (event)
1066 "Pop up a menu of possible corrections for a misspelled word.
1067 The word checked is the word at the mouse position."
1068 (interactive "e")
1069 ;; use the correct dictionary
1070 (ispell-accept-buffer-local-defs)
1071 ;; retain cursor location (I don't know why but save-excursion here fails).
1072 (let ((save (point)))
1073 (mouse-set-point event)
1074 (let ((cursor-location (point))
1075 (word (flyspell-get-word nil))
1076 start end poss replace)
1077 ;; destructure return word info list.
1078 (setq start (car (cdr word))
1079 end (car (cdr (cdr word)))
1080 word (car word))
1081 ;; now check spelling of word.
1082 (process-send-string ispell-process "%\n") ;put in verbose mode
1083 (process-send-string ispell-process (concat "^" word "\n"))
1084 ;; wait until ispell has processed word
1085 (while (progn
1086 (accept-process-output ispell-process)
1087 (not (string= "" (car ispell-filter)))))
1088 (setq ispell-filter (cdr ispell-filter))
1089 (if (listp ispell-filter)
1090 (setq poss (ispell-parse-output (car ispell-filter))))
1091 (cond ((or (eq poss t) (stringp poss))
1092 ;; don't correct word
1093 t)
1094 ((null poss)
1095 ;; ispell error
1096 (error "Ispell: error in Ispell process"))
1097 ((string-match "GNU" (emacs-version))
1098 ;; the word is incorrect, we have to propose a replacement
1099 (setq replace (flyspell-emacs-popup event poss word))
1100 (cond ((eq replace 'ignore)
1101 nil)
1102 ((eq replace 'save)
1103 (process-send-string ispell-process (concat "*" word "\n"))
1104 (flyspell-unhighlight-at cursor-location)
1105 (setq ispell-pdict-modified-p '(t)))
1106 ((or (eq replace 'buffer) (eq replace 'session))
1107 (process-send-string ispell-process (concat "@" word "\n"))
1108 (if (null ispell-pdict-modified-p)
1109 (setq ispell-pdict-modified-p
1110 (list ispell-pdict-modified-p)))
1111 (flyspell-unhighlight-at cursor-location)
1112 (if (eq replace 'buffer)
1113 (ispell-add-per-file-word-list word)))
1114 (replace
1115 (setq word (if (atom replace) replace (car replace))
1116 cursor-location (+ (- (length word) (- end start))
1117 cursor-location))
1118 (if (not (equal word (car poss)))
1119 (progn
1120 (delete-region start end)
1121 (insert word))))))
1122 ((string-match "XEmacs" (emacs-version))
1123 (flyspell-xemacs-popup
1124 event poss word cursor-location start end)))
1125 (ispell-pdict-save t))
1126 (if (< save (point-max))
1127 (goto-char save)
1128 (goto-char (point-max)))))
1129
1130 ;*---------------------------------------------------------------------*/
1131 ;* flyspell-xemacs-correct ... */
1132 ;*---------------------------------------------------------------------*/
1133 (defun flyspell-xemacs-correct (replace poss word cursor-location start end)
1134 "The xemacs popup menu callback."
1135 (cond ((eq replace 'ignore)
1136 nil)
1137 ((eq replace 'save)
1138 (process-send-string ispell-process (concat "*" word "\n"))
1139 (flyspell-unhighlight-at cursor-location)
1140 (setq ispell-pdict-modified-p '(t)))
1141 ((or (eq replace 'buffer) (eq replace 'session))
1142 (process-send-string ispell-process (concat "@" word "\n"))
1143 (flyspell-unhighlight-at cursor-location)
1144 (if (null ispell-pdict-modified-p)
1145 (setq ispell-pdict-modified-p
1146 (list ispell-pdict-modified-p)))
1147 (if (eq replace 'buffer)
1148 (ispell-add-per-file-word-list word)))
1149 (replace
1150 (setq word (if (atom replace) replace (car replace))
1151 cursor-location (+ (- (length word) (- end start))
1152 cursor-location))
1153 (if (not (equal word (car poss)))
1154 (save-excursion
1155 (delete-region start end)
1156 (goto-char start)
1157 (insert word))))))
1158
1159 ;*---------------------------------------------------------------------*/
1160 ;* flyspell-emacs-popup ... */
1161 ;*---------------------------------------------------------------------*/
1162 (defun flyspell-emacs-popup (event poss word)
1163 "The Emacs popup menu."
1164 (if (not event)
1165 (let* ((mouse-pos (mouse-position))
1166 (mouse-pos (if (nth 1 mouse-pos)
1167 mouse-pos
1168 (set-mouse-position (car mouse-pos)
1169 (/ (frame-width) 2) 2)
1170 (unfocus-frame)
1171 (mouse-position))))
1172 (setq event (list (list (car (cdr mouse-pos))
1173 (1+ (cdr (cdr mouse-pos))))
1174 (car mouse-pos)))))
1175 (let* ((corrects (if flyspell-sort-corrections
1176 (sort (car (cdr (cdr poss))) 'string<)
1177 (car (cdr (cdr poss)))))
1178 (cor-menu (if (consp corrects)
1179 (mapcar (lambda (correct)
1180 (list correct correct))
1181 corrects)
1182 '()))
1183 (affix (car (cdr (cdr (cdr poss)))))
1184 (base-menu (let ((save (if (consp affix)
1185 (list
1186 (list (concat "Save affix: " (car affix))
1187 'save)
1188 '("Accept (session)" accept)
1189 '("Accept (buffer)" buffer))
1190 '(("Save word" save)
1191 ("Accept (session)" session)
1192 ("Accept (buffer)" buffer)))))
1193 (if (consp cor-menu)
1194 (append cor-menu (cons "" save))
1195 save)))
1196 (menu (cons "flyspell correction menu" base-menu)))
1197 (car (x-popup-menu event
1198 (list (format "%s [%s]" word (or ispell-local-dictionary
1199 ispell-dictionary))
1200 menu)))))
1201
1202 ;*---------------------------------------------------------------------*/
1203 ;* flyspell-xemacs-popup ... */
1204 ;*---------------------------------------------------------------------*/
1205 (defun flyspell-xemacs-popup (event poss word cursor-location start end)
1206 "The xemacs popup menu."
1207 (let* ((corrects (if flyspell-sort-corrections
1208 (sort (car (cdr (cdr poss))) 'string<)
1209 (car (cdr (cdr poss)))))
1210 (cor-menu (if (consp corrects)
1211 (mapcar (lambda (correct)
1212 (vector correct
1213 (list 'flyspell-xemacs-correct
1214 correct
1215 (list 'quote poss)
1216 word
1217 cursor-location
1218 start
1219 end)
1220 t))
1221 corrects)
1222 '()))
1223 (affix (car (cdr (cdr (cdr poss)))))
1224 (menu (let ((save (if (consp affix)
1225 (vector
1226 (concat "Save affix: " (car affix))
1227 (list 'flyspell-xemacs-correct
1228 ''save
1229 (list 'quote poss)
1230 word
1231 cursor-location
1232 start
1233 end)
1234 t)
1235 (vector
1236 "Save word"
1237 (list 'flyspell-xemacs-correct
1238 ''save
1239 (list 'quote poss)
1240 word
1241 cursor-location
1242 start
1243 end)
1244 t)))
1245 (session (vector "Accept (session)"
1246 (list 'flyspell-xemacs-correct
1247 ''session
1248 (list 'quote poss)
1249 word
1250 cursor-location
1251 start
1252 end)
1253 t))
1254 (buffer (vector "Accept (buffer)"
1255 (list 'flyspell-xemacs-correct
1256 ''buffer
1257 (list 'quote poss)
1258 word
1259 cursor-location
1260 start
1261 end)
1262 t)))
1263 (if (consp cor-menu)
1264 (append cor-menu (list "-" save session buffer))
1265 (list save session buffer)))))
1266 (popup-menu (cons (format "%s [%s]" word (or ispell-local-dictionary
1267 ispell-dictionary))
1268 menu))))
1269
1270 (provide 'flyspell)
1271
1272 ;;; flyspell.el ends here