annotate lisp/textmodes/flyspell.el @ 22861:49e731d1ddb6

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