Mercurial > emacs
annotate lisp/textmodes/=ispell4.el @ 5315:55a8d59088c1
Add side-effect-free props for many functions.
(byte-boolean-vars): Add highlight-nonselected-windows.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Thu, 23 Dec 1993 05:00:49 +0000 |
parents | 346d921eaf3b |
children | ec02e2f72eae |
rev | line source |
---|---|
3722 | 1 ;;; ispell.el --- this is the GNU EMACS interface to GNU ISPELL version 4. |
660
08eb386dd0f3
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
317
diff
changeset
|
2 |
4043
6228decc1353
(ispell): Call deactivate-mark instead of setting mark-active directly. Do
Roland McGrath <roland@gnu.org>
parents:
3722
diff
changeset
|
3 ;;Copyright (C) 1990, 1991, 1993 Free Software Foundation, Inc. |
792
45d748a65f24
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
778
diff
changeset
|
4 |
2247
2c7997f249eb
Add or correct keywords
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
845
diff
changeset
|
5 ;; Keywords: wp |
2c7997f249eb
Add or correct keywords
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
845
diff
changeset
|
6 |
671
21d23fa6fa2a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
7 ;;This file is part of GNU Emacs. |
55 | 8 ;; |
671
21d23fa6fa2a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
9 ;;GNU Emacs is free software; you can redistribute it and/or modify |
55 | 10 ;;it under the terms of the GNU General Public License as published by |
317 | 11 ;;the Free Software Foundation; either version 2, or (at your option) |
55 | 12 ;;any later version. |
13 ;; | |
671
21d23fa6fa2a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
14 ;;GNU Emacs is distributed in the hope that it will be useful, |
55 | 15 ;;but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 ;;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 ;;GNU General Public License for more details. | |
18 ;; | |
19 ;;You should have received a copy of the GNU General Public License | |
671
21d23fa6fa2a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
20 ;;along with GNU Emacs; see the file COPYING. If not, write to |
55 | 21 ;;the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
22 | |
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
23 ;;; Commentary: |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
24 |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
25 ;; This package provides a graceful interface to ispell, the GNU |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
26 ;; spelling checker. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
27 |
792
45d748a65f24
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
778
diff
changeset
|
28 ;;; Code: |
45d748a65f24
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
778
diff
changeset
|
29 |
55 | 30 (defvar ispell-have-new-look t |
3623 | 31 "Non-nil means use the `-r' option when running `look'.") |
55 | 32 |
33 (defvar ispell-enable-tex-parser nil | |
3623 | 34 "Non-nil enables experimental TeX parser in Ispell for TeX-mode buffers.") |
35 | |
36 (defvar ispell-process nil "The process running Ispell") | |
37 (defvar ispell-next-message nil | |
38 "An integer: where in `*ispell*' buffer to find next message from Ispell.") | |
55 | 39 |
3623 | 40 (defvar ispell-command "ispell" |
41 "Command for running Ispell.") | |
42 (defvar ispell-command-options nil | |
43 "*String (or list of strings) to pass to Ispell as command arguments. | |
5293
346d921eaf3b
Don't imply private dictionary is always ispell.words.
Richard M. Stallman <rms@gnu.org>
parents:
4933
diff
changeset
|
44 You can specify your private dictionary via the -p <filename> option. |
3623 | 45 The -S option is always passed to Ispell as the last parameter, |
46 and need not be mentioned here.") | |
55 | 47 |
4895
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
48 (defvar ispell-look-command "look" |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
49 "*Command for running look.") |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
50 |
55 | 51 ;Each marker in this list points to the start of a word that |
52 ;ispell thought was bad last time it did the :file command. | |
53 ;Notice that if the user accepts or inserts a word into his | |
54 ;private dictionary, then some "good" words will be on the list. | |
55 ;We would like to deal with this by looking up the words again just before | |
56 ;presenting them to the user, but that is too slow on machines | |
57 ;without the select system call. Therefore, see the variable | |
58 ;ispell-recently-accepted. | |
59 (defvar ispell-bad-words nil | |
3623 | 60 "A list of markers reflecting the output of the Ispell `:file' command.") |
55 | 61 |
62 ;list of words that the user has accepted, but that might still | |
63 ;be on the bad-words list | |
64 (defvar ispell-recently-accepted nil) | |
65 | |
2837
00f822101e49
(ispell): Deactivate mark before the Ispell run.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
66 ;; Non-nil means we have started showing an alternatives window. |
00f822101e49
(ispell): Deactivate mark before the Ispell run.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
67 ;; This is the window config from before then. |
4105
230eede21566
(ispell-menu-map): Add missing quote in defalias.
Richard M. Stallman <rms@gnu.org>
parents:
4062
diff
changeset
|
68 (defvar ispell-window-configuration nil) |
2837
00f822101e49
(ispell): Deactivate mark before the Ispell run.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
69 |
55 | 70 ;t when :dump command needed |
71 (defvar ispell-dump-needed nil) | |
72 | |
73 (defun ispell-flush-bad-words () | |
74 (while ispell-bad-words | |
75 (if (markerp (car ispell-bad-words)) | |
76 (set-marker (car ispell-bad-words) nil)) | |
77 (setq ispell-bad-words (cdr ispell-bad-words))) | |
78 (setq ispell-recently-accepted nil)) | |
79 | |
80 (defun kill-ispell () | |
3623 | 81 "Kill the Ispell process. |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3112
diff
changeset
|
82 Any changes in your private dictionary |
55 | 83 that have not already been dumped will be lost." |
84 (interactive) | |
85 (if ispell-process | |
86 (delete-process ispell-process)) | |
87 (setq ispell-process nil) | |
88 (ispell-flush-bad-words)) | |
89 | |
90 (put 'ispell-startup-error 'error-conditions | |
91 '(ispell-startup-error error)) | |
92 (put 'ispell-startup-error 'error-message | |
93 "Problem starting ispell - see buffer *ispell*") | |
94 | |
3623 | 95 ;; Start an ispell subprocess; check the version; and display the greeting. |
96 | |
55 | 97 (defun start-ispell () |
98 (message "Starting ispell ...") | |
99 (let ((buf (get-buffer "*ispell*"))) | |
100 (if buf | |
101 (kill-buffer buf))) | |
102 (condition-case err | |
3623 | 103 (setq ispell-process |
104 (apply 'start-process "ispell" "*ispell*" ispell-command | |
105 (append (if (listp ispell-command-options) | |
106 ispell-command-options | |
107 (list ispell-command-options)) | |
108 '("-S")))) | |
55 | 109 (file-error (signal 'ispell-startup-error nil))) |
110 (process-kill-without-query ispell-process) | |
111 (buffer-disable-undo (process-buffer ispell-process)) | |
112 (accept-process-output ispell-process) | |
113 (let (last-char) | |
114 (save-excursion | |
115 (set-buffer (process-buffer ispell-process)) | |
116 (bury-buffer (current-buffer)) | |
117 (setq last-char (- (point-max) 1)) | |
118 (while (not (eq (char-after last-char) ?=)) | |
119 (cond ((not (eq (process-status ispell-process) 'run)) | |
120 (kill-ispell) | |
121 (signal 'ispell-startup-error nil))) | |
122 (accept-process-output ispell-process) | |
123 (setq last-char (- (point-max) 1))) | |
124 (goto-char (point-min)) | |
125 (let ((greeting (read (current-buffer)))) | |
126 (if (not (= (car greeting) 1)) | |
127 (error "Bad ispell version: wanted 1, got %d" (car greeting))) | |
128 (message (car (cdr greeting)))) | |
129 (delete-region (point-min) last-char)))) | |
130 | |
3623 | 131 ;; Make sure ispell is ready for a command. |
132 ;; Leaves buffer set to *ispell*, point at '='. | |
133 | |
55 | 134 (defun ispell-sync (intr) |
135 (if (or (null ispell-process) | |
136 (not (eq (process-status ispell-process) 'run))) | |
137 (start-ispell)) | |
138 (if intr | |
139 (interrupt-process ispell-process)) | |
140 (let (last-char) | |
141 (set-buffer (process-buffer ispell-process)) | |
142 (bury-buffer (current-buffer)) | |
143 (setq last-char (- (point-max) 1)) | |
144 (while (not (eq (char-after last-char) ?=)) | |
145 (accept-process-output ispell-process) | |
146 (setq last-char (- (point-max) 1))) | |
147 (goto-char last-char))) | |
148 | |
3623 | 149 ;; Send a command to ispell. Choices are: |
150 ;; | |
151 ;; WORD Check spelling of WORD. Result is | |
152 ;; | |
153 ;; nil not found | |
154 ;; t spelled ok | |
155 ;; list of strings near misses | |
156 ;; | |
157 ;; :file FILENAME scan the named file, and print the file offsets of | |
158 ;; any misspelled words | |
159 ;; | |
160 ;; :insert WORD put word in private dictionary | |
161 ;; | |
162 ;; :accept WORD don't complain about word any more this session | |
163 ;; | |
164 ;; :dump write out the current private dictionary, if necessary. | |
165 ;; | |
5293
346d921eaf3b
Don't imply private dictionary is always ispell.words.
Richard M. Stallman <rms@gnu.org>
parents:
4933
diff
changeset
|
166 ;; :reload reread private dictionary (default: `~/ispell.words') |
3623 | 167 ;; |
168 ;; :tex | |
169 ;; :troff | |
170 ;; :generic set type of parser to use when scanning whole files | |
55 | 171 |
3623 | 172 (defun ispell-cmd (&rest strings) |
55 | 173 (save-excursion |
174 (ispell-sync t) | |
175 (set-buffer (process-buffer ispell-process)) | |
176 (bury-buffer (current-buffer)) | |
177 (erase-buffer) | |
178 (setq ispell-next-message (point-min)) | |
179 (while strings | |
180 (process-send-string ispell-process (car strings)) | |
181 (setq strings (cdr strings))) | |
182 (process-send-string ispell-process "\n") | |
183 (accept-process-output ispell-process) | |
184 (ispell-sync nil))) | |
185 | |
186 (defun ispell-dump () | |
187 (cond (ispell-dump-needed | |
188 (setq ispell-dump-needed nil) | |
189 (ispell-cmd ":dump")))) | |
190 | |
191 (defun ispell-insert (word) | |
192 (ispell-cmd ":insert " word) | |
193 (if ispell-bad-words | |
194 (setq ispell-recently-accepted (cons word ispell-recently-accepted))) | |
195 (setq ispell-dump-needed t)) | |
196 | |
197 (defun ispell-accept (word) | |
198 (ispell-cmd ":accept " word) | |
199 (if ispell-bad-words | |
200 (setq ispell-recently-accepted (cons word ispell-recently-accepted)))) | |
201 | |
3623 | 202 ;; Return the next message sent by the Ispell subprocess. |
55 | 203 |
204 (defun ispell-next-message () | |
205 (save-excursion | |
206 (set-buffer (process-buffer ispell-process)) | |
207 (bury-buffer (current-buffer)) | |
208 (save-restriction | |
209 (goto-char ispell-next-message) | |
210 (narrow-to-region (point) | |
211 (progn (forward-sexp 1) (point))) | |
212 (setq ispell-next-message (point)) | |
213 (goto-char (point-min)) | |
214 (read (current-buffer))))) | |
215 | |
216 (defun ispell-tex-buffer-p () | |
217 (memq major-mode '(plain-TeX-mode LaTeX-mode))) | |
218 | |
4062
d7f5f18ddbc5
(ispell-menu-map): New keymap--both fn and var.
Richard M. Stallman <rms@gnu.org>
parents:
4043
diff
changeset
|
219 (defvar ispell-menu-map (make-sparse-keymap "Spell")) |
4105
230eede21566
(ispell-menu-map): Add missing quote in defalias.
Richard M. Stallman <rms@gnu.org>
parents:
4062
diff
changeset
|
220 (defalias 'ispell-menu-map ispell-menu-map) |
4062
d7f5f18ddbc5
(ispell-menu-map): New keymap--both fn and var.
Richard M. Stallman <rms@gnu.org>
parents:
4043
diff
changeset
|
221 |
4895
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
222 (define-key ispell-menu-map [ispell-complete-word-interior-frag] |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
223 '("Complete Interior Fragment" . ispell-complete-word-interior-frag)) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
224 |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
225 (define-key ispell-menu-map [ispell-complete-word] |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
226 '("Complete Word" . ispell-complete-word)) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
227 |
4062
d7f5f18ddbc5
(ispell-menu-map): New keymap--both fn and var.
Richard M. Stallman <rms@gnu.org>
parents:
4043
diff
changeset
|
228 (define-key ispell-menu-map [reload-ispell] |
d7f5f18ddbc5
(ispell-menu-map): New keymap--both fn and var.
Richard M. Stallman <rms@gnu.org>
parents:
4043
diff
changeset
|
229 '("Reload Dictionary" . reload-ispell)) |
d7f5f18ddbc5
(ispell-menu-map): New keymap--both fn and var.
Richard M. Stallman <rms@gnu.org>
parents:
4043
diff
changeset
|
230 |
d7f5f18ddbc5
(ispell-menu-map): New keymap--both fn and var.
Richard M. Stallman <rms@gnu.org>
parents:
4043
diff
changeset
|
231 (define-key ispell-menu-map [ispell-next] |
d7f5f18ddbc5
(ispell-menu-map): New keymap--both fn and var.
Richard M. Stallman <rms@gnu.org>
parents:
4043
diff
changeset
|
232 '("Continue Check" . ispell-next)) |
d7f5f18ddbc5
(ispell-menu-map): New keymap--both fn and var.
Richard M. Stallman <rms@gnu.org>
parents:
4043
diff
changeset
|
233 |
4749
fe223c0faf71
(ispell-message): New command, with menu bar item.
Richard M. Stallman <rms@gnu.org>
parents:
4256
diff
changeset
|
234 (define-key ispell-menu-map [ispell-message] |
fe223c0faf71
(ispell-message): New command, with menu bar item.
Richard M. Stallman <rms@gnu.org>
parents:
4256
diff
changeset
|
235 '("Check Message" . ispell-message)) |
fe223c0faf71
(ispell-message): New command, with menu bar item.
Richard M. Stallman <rms@gnu.org>
parents:
4256
diff
changeset
|
236 |
4062
d7f5f18ddbc5
(ispell-menu-map): New keymap--both fn and var.
Richard M. Stallman <rms@gnu.org>
parents:
4043
diff
changeset
|
237 (define-key ispell-menu-map [ispell-region] |
d7f5f18ddbc5
(ispell-menu-map): New keymap--both fn and var.
Richard M. Stallman <rms@gnu.org>
parents:
4043
diff
changeset
|
238 '("Check Region" . ispell-region)) |
d7f5f18ddbc5
(ispell-menu-map): New keymap--both fn and var.
Richard M. Stallman <rms@gnu.org>
parents:
4043
diff
changeset
|
239 |
d7f5f18ddbc5
(ispell-menu-map): New keymap--both fn and var.
Richard M. Stallman <rms@gnu.org>
parents:
4043
diff
changeset
|
240 (define-key ispell-menu-map [ispell-buffer] |
d7f5f18ddbc5
(ispell-menu-map): New keymap--both fn and var.
Richard M. Stallman <rms@gnu.org>
parents:
4043
diff
changeset
|
241 '("Check Buffer" . ispell)) |
d7f5f18ddbc5
(ispell-menu-map): New keymap--both fn and var.
Richard M. Stallman <rms@gnu.org>
parents:
4043
diff
changeset
|
242 |
d7f5f18ddbc5
(ispell-menu-map): New keymap--both fn and var.
Richard M. Stallman <rms@gnu.org>
parents:
4043
diff
changeset
|
243 (define-key ispell-menu-map [ispell-word] |
d7f5f18ddbc5
(ispell-menu-map): New keymap--both fn and var.
Richard M. Stallman <rms@gnu.org>
parents:
4043
diff
changeset
|
244 '("Check Word" . ispell-word)) |
d7f5f18ddbc5
(ispell-menu-map): New keymap--both fn and var.
Richard M. Stallman <rms@gnu.org>
parents:
4043
diff
changeset
|
245 |
256 | 246 ;;;###autoload |
55 | 247 (defun ispell (&optional buf start end) |
671
21d23fa6fa2a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
248 "Run Ispell over current buffer's visited file. |
21d23fa6fa2a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
249 First the file is scanned for misspelled words, then Ispell |
55 | 250 enters a loop with the following commands for every misspelled word: |
251 | |
252 DIGIT Near miss selector. If the misspelled word is close to | |
253 some words in the dictionary, they are offered as near misses. | |
254 r Replace. Replace the word with a string you type. Each word | |
255 of your new string is also checked. | |
5293
346d921eaf3b
Don't imply private dictionary is always ispell.words.
Richard M. Stallman <rms@gnu.org>
parents:
4933
diff
changeset
|
256 i Insert. Insert this word in your private dictionary (by default, |
55 | 257 `$HOME/ispell.words'). |
258 a Accept. Accept this word for the rest of this editing session, | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3112
diff
changeset
|
259 but don't put it in your private dictionary. |
55 | 260 l Lookup. Look for a word in the dictionary by fast binary |
261 search, or search for a regular expression in the dictionary | |
262 using grep. | |
263 SPACE Accept the word this time, but complain if it is seen again. | |
214 | 264 q, \\[keyboard-quit] Leave the command loop. You can come back later with \\[ispell-next]." |
55 | 265 (interactive) |
266 (if (null start) | |
267 (setq start 0)) | |
268 (if (null end) | |
269 (setq end 0)) | |
270 | |
271 (if (null buf) | |
272 (setq buf (current-buffer))) | |
273 (setq buf (get-buffer buf)) | |
274 (if (null buf) | |
275 (error "Can't find buffer")) | |
2837
00f822101e49
(ispell): Deactivate mark before the Ispell run.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
276 ;; Deactivate the mark, because we'll do it anyway if we change something, |
00f822101e49
(ispell): Deactivate mark before the Ispell run.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
277 ;; and a region highlight while in the Ispell loop is distracting. |
4043
6228decc1353
(ispell): Call deactivate-mark instead of setting mark-active directly. Do
Roland McGrath <roland@gnu.org>
parents:
3722
diff
changeset
|
278 (deactivate-mark) |
55 | 279 (save-excursion |
280 (set-buffer buf) | |
281 (let ((filename buffer-file-name) | |
2837
00f822101e49
(ispell): Deactivate mark before the Ispell run.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
282 (delete-temp nil)) |
55 | 283 (unwind-protect |
284 (progn | |
4889
8b896067d6fb
(ispell): If the buffer to spell has no associated file, or, the
Brian Fox <bfox@gnu.org>
parents:
4842
diff
changeset
|
285 (cond ((or (null filename) |
8b896067d6fb
(ispell): If the buffer to spell has no associated file, or, the
Brian Fox <bfox@gnu.org>
parents:
4842
diff
changeset
|
286 (find-file-name-handler buffer-file-name)) |
55 | 287 (setq filename (make-temp-name "/usr/tmp/ispell")) |
288 (setq delete-temp t) | |
289 (write-region (point-min) (point-max) filename)) | |
290 ((and (buffer-modified-p buf) | |
291 (y-or-n-p (format "Save file %s? " filename))) | |
292 (save-buffer))) | |
293 (message "Ispell scanning file...") | |
294 (if (and ispell-enable-tex-parser | |
295 (ispell-tex-buffer-p)) | |
296 (ispell-cmd ":tex") | |
297 (ispell-cmd ":generic")) | |
298 (ispell-cmd (format ":file %s %d %d" filename start end))) | |
2837
00f822101e49
(ispell): Deactivate mark before the Ispell run.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
299 (if delete-temp |
00f822101e49
(ispell): Deactivate mark before the Ispell run.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
300 (condition-case () |
00f822101e49
(ispell): Deactivate mark before the Ispell run.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
301 (delete-file filename) |
00f822101e49
(ispell): Deactivate mark before the Ispell run.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
302 (file-error nil))))) |
55 | 303 (message "Parsing ispell output ...") |
304 (ispell-flush-bad-words) | |
305 (let (pos bad-words) | |
306 (while (numberp (setq pos (ispell-next-message))) | |
307 ;;ispell may check the words on the line following the end | |
308 ;;of the region - therefore, don't record anything out of range | |
309 (if (or (= end 0) | |
310 (< pos end)) | |
311 (setq bad-words (cons (set-marker (make-marker) (+ pos 1)) | |
312 bad-words)))) | |
313 (setq bad-words (cons pos bad-words)) | |
314 (setq ispell-bad-words (nreverse bad-words)))) | |
315 (cond ((not (markerp (car ispell-bad-words))) | |
316 (setq ispell-bad-words nil) | |
4926
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
317 (message "No misspellings.") |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
318 t) |
55 | 319 (t |
320 (message "Ispell parsing done.") | |
321 (ispell-next)))) | |
322 | |
316 | 323 ;;;###autoload |
2571
b65cf676a09b
All fsets changed to defaliases.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2307
diff
changeset
|
324 (defalias 'ispell-buffer 'ispell) |
316 | 325 |
55 | 326 (defun ispell-next () |
4926
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
327 "Resume command loop for most recent Ispell command. |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
328 Return value is t unless exit is due to typing `q'." |
55 | 329 (interactive) |
2837
00f822101e49
(ispell): Deactivate mark before the Ispell run.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
330 (setq ispell-window-configuration nil) |
4927 | 331 (prog1 |
332 (unwind-protect | |
333 (catch 'ispell-quit | |
334 ;; There used to be a save-excursion here, | |
335 ;; but that was annoying: it's better if point doesn't move | |
336 ;; when you type q. | |
337 (let (next) | |
338 (while (markerp (setq next (car ispell-bad-words))) | |
339 (switch-to-buffer (marker-buffer next)) | |
340 (push-mark) | |
341 (ispell-point next "at saved position.") | |
342 (setq ispell-bad-words (cdr ispell-bad-words)) | |
343 (set-marker next nil))) | |
344 t) | |
345 (if ispell-window-configuration | |
346 (set-window-configuration ispell-window-configuration)) | |
347 (cond ((null ispell-bad-words) | |
348 (error "Ispell has not yet been run.")) | |
349 ((markerp (car ispell-bad-words)) | |
350 (message (substitute-command-keys | |
351 "Type \\[ispell-next] to continue."))) | |
352 ((eq (car ispell-bad-words) nil) | |
353 (setq ispell-bad-words nil) | |
354 (message "No more misspellings (but checker was interrupted.)")) | |
355 ((eq (car ispell-bad-words) t) | |
356 (setq ispell-bad-words nil) | |
357 (message "Ispell done.")) | |
358 (t | |
359 (setq ispell-bad-words nil) | |
360 (message "Bad ispell internal list")))) | |
361 (ispell-dump))) | |
55 | 362 |
256 | 363 ;;;###autoload |
671
21d23fa6fa2a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
364 (defun ispell-word (&optional resume) |
55 | 365 "Check the spelling of the word under the cursor. |
3623 | 366 See the command `ispell' for more information. |
671
21d23fa6fa2a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
367 With a prefix argument, resume handling of the previous Ispell command." |
21d23fa6fa2a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
368 (interactive "P") |
21d23fa6fa2a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
369 (if resume |
21d23fa6fa2a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
370 (ispell-next) |
21d23fa6fa2a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
371 (condition-case err |
4926
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
372 (catch 'ispell-quit |
671
21d23fa6fa2a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
373 (save-window-excursion |
21d23fa6fa2a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
374 (ispell-point (point) "at point.")) |
21d23fa6fa2a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
375 (ispell-dump)) |
21d23fa6fa2a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
376 (ispell-startup-error |
21d23fa6fa2a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
377 (cond ((y-or-n-p "Problem starting ispell, use old-style spell instead? ") |
21d23fa6fa2a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
378 (load-library "spell") |
21d23fa6fa2a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
379 (define-key esc-map "$" 'spell-word) |
21d23fa6fa2a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
380 (spell-word))))))) |
5293
346d921eaf3b
Don't imply private dictionary is always ispell.words.
Richard M. Stallman <rms@gnu.org>
parents:
4933
diff
changeset
|
381 |
346d921eaf3b
Don't imply private dictionary is always ispell.words.
Richard M. Stallman <rms@gnu.org>
parents:
4933
diff
changeset
|
382 ;;;###autoload (define-key esc-map "$" 'ispell-word) |
55 | 383 |
256 | 384 ;;;###autoload |
55 | 385 (defun ispell-region (start &optional end) |
386 "Check the spelling for all of the words in the region." | |
387 (interactive "r") | |
388 (ispell (current-buffer) start end)) | |
389 | |
390 (defun ispell-letterp (c) | |
391 (and c | |
392 (or (and (>= c ?A) (<= c ?Z)) | |
393 (and (>= c ?a) (<= c ?z)) | |
394 (>= c 128)))) | |
395 | |
396 (defun ispell-letter-or-quotep (c) | |
397 (and c | |
398 (or (and (>= c ?A) (<= c ?Z)) | |
399 (and (>= c ?a) (<= c ?z)) | |
400 (= c ?') | |
401 (>= c 128)))) | |
402 | |
403 (defun ispell-find-word-start () | |
404 ;;backward to a letter | |
405 (if (not (ispell-letterp (char-after (point)))) | |
406 (while (and (not (bobp)) | |
407 (not (ispell-letterp (char-after (- (point) 1))))) | |
408 (backward-char))) | |
409 ;;backward to beginning of word | |
410 (while (ispell-letter-or-quotep (char-after (- (point) 1))) | |
411 (backward-char)) | |
412 (skip-chars-forward "'")) | |
413 | |
414 (defun ispell-find-word-end () | |
415 (while (ispell-letter-or-quotep (char-after (point))) | |
416 (forward-char)) | |
417 (skip-chars-backward "'")) | |
418 | |
419 (defun ispell-next-word () | |
420 (while (and (not (eobp)) | |
421 (not (ispell-letterp (char-after (point))))) | |
422 (forward-char))) | |
423 | |
424 ;if end is nil, then do one word at start | |
425 ;otherwise, do all words from the beginning of the word where | |
426 ;start points, to the end of the word where end points | |
427 (defun ispell-point (start message) | |
428 (let ((wend (make-marker)) | |
429 rescan | |
430 end) | |
2837
00f822101e49
(ispell): Deactivate mark before the Ispell run.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
431 ;; There used to be a save-excursion here, |
00f822101e49
(ispell): Deactivate mark before the Ispell run.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
432 ;; but that was annoying: it's better if point doesn't move |
00f822101e49
(ispell): Deactivate mark before the Ispell run.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
433 ;; when you type q. |
55 | 434 (goto-char start) |
435 (ispell-find-word-start) ;find correct word start | |
436 (setq start (point-marker)) | |
437 (ispell-find-word-end) ;now find correct end | |
438 (setq end (point-marker)) | |
4256
aaf846efe4cb
(ispell-point): Do nothing if there's no word at START.
Richard M. Stallman <rms@gnu.org>
parents:
4105
diff
changeset
|
439 ;; Do nothing if we don't find a word. |
aaf846efe4cb
(ispell-point): Do nothing if there's no word at START.
Richard M. Stallman <rms@gnu.org>
parents:
4105
diff
changeset
|
440 (if (< start end) |
aaf846efe4cb
(ispell-point): Do nothing if there's no word at START.
Richard M. Stallman <rms@gnu.org>
parents:
4105
diff
changeset
|
441 (while (< start end) |
aaf846efe4cb
(ispell-point): Do nothing if there's no word at START.
Richard M. Stallman <rms@gnu.org>
parents:
4105
diff
changeset
|
442 (goto-char start) |
aaf846efe4cb
(ispell-point): Do nothing if there's no word at START.
Richard M. Stallman <rms@gnu.org>
parents:
4105
diff
changeset
|
443 (ispell-find-word-end) ;find end of current word |
55 | 444 ;could be before 'end' if |
445 ;user typed replacement | |
446 ;that is more than one word | |
4256
aaf846efe4cb
(ispell-point): Do nothing if there's no word at START.
Richard M. Stallman <rms@gnu.org>
parents:
4105
diff
changeset
|
447 (set-marker wend (point)) |
aaf846efe4cb
(ispell-point): Do nothing if there's no word at START.
Richard M. Stallman <rms@gnu.org>
parents:
4105
diff
changeset
|
448 (setq rescan nil) |
aaf846efe4cb
(ispell-point): Do nothing if there's no word at START.
Richard M. Stallman <rms@gnu.org>
parents:
4105
diff
changeset
|
449 (setq word (buffer-substring start wend)) |
aaf846efe4cb
(ispell-point): Do nothing if there's no word at START.
Richard M. Stallman <rms@gnu.org>
parents:
4105
diff
changeset
|
450 (cond ((ispell-still-bad word) |
2837
00f822101e49
(ispell): Deactivate mark before the Ispell run.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
451 ;;; This just causes confusion. -- rms. |
00f822101e49
(ispell): Deactivate mark before the Ispell run.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
452 ;;; (goto-char start) |
00f822101e49
(ispell): Deactivate mark before the Ispell run.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
453 ;;; (sit-for 0) |
4256
aaf846efe4cb
(ispell-point): Do nothing if there's no word at START.
Richard M. Stallman <rms@gnu.org>
parents:
4105
diff
changeset
|
454 (message (format "Ispell checking %s" word)) |
aaf846efe4cb
(ispell-point): Do nothing if there's no word at START.
Richard M. Stallman <rms@gnu.org>
parents:
4105
diff
changeset
|
455 (ispell-cmd word) |
aaf846efe4cb
(ispell-point): Do nothing if there's no word at START.
Richard M. Stallman <rms@gnu.org>
parents:
4105
diff
changeset
|
456 (let ((message (ispell-next-message))) |
aaf846efe4cb
(ispell-point): Do nothing if there's no word at START.
Richard M. Stallman <rms@gnu.org>
parents:
4105
diff
changeset
|
457 (cond ((eq message t) |
aaf846efe4cb
(ispell-point): Do nothing if there's no word at START.
Richard M. Stallman <rms@gnu.org>
parents:
4105
diff
changeset
|
458 (message "%s: ok" word)) |
aaf846efe4cb
(ispell-point): Do nothing if there's no word at START.
Richard M. Stallman <rms@gnu.org>
parents:
4105
diff
changeset
|
459 ((or (null message) |
aaf846efe4cb
(ispell-point): Do nothing if there's no word at START.
Richard M. Stallman <rms@gnu.org>
parents:
4105
diff
changeset
|
460 (consp message)) |
aaf846efe4cb
(ispell-point): Do nothing if there's no word at START.
Richard M. Stallman <rms@gnu.org>
parents:
4105
diff
changeset
|
461 (setq rescan |
aaf846efe4cb
(ispell-point): Do nothing if there's no word at START.
Richard M. Stallman <rms@gnu.org>
parents:
4105
diff
changeset
|
462 (ispell-command-loop word start wend message))) |
aaf846efe4cb
(ispell-point): Do nothing if there's no word at START.
Richard M. Stallman <rms@gnu.org>
parents:
4105
diff
changeset
|
463 (t |
aaf846efe4cb
(ispell-point): Do nothing if there's no word at START.
Richard M. Stallman <rms@gnu.org>
parents:
4105
diff
changeset
|
464 (error "unknown ispell response %s" message)))))) |
aaf846efe4cb
(ispell-point): Do nothing if there's no word at START.
Richard M. Stallman <rms@gnu.org>
parents:
4105
diff
changeset
|
465 (cond ((null rescan) |
aaf846efe4cb
(ispell-point): Do nothing if there's no word at START.
Richard M. Stallman <rms@gnu.org>
parents:
4105
diff
changeset
|
466 (goto-char wend) |
aaf846efe4cb
(ispell-point): Do nothing if there's no word at START.
Richard M. Stallman <rms@gnu.org>
parents:
4105
diff
changeset
|
467 (ispell-next-word) |
aaf846efe4cb
(ispell-point): Do nothing if there's no word at START.
Richard M. Stallman <rms@gnu.org>
parents:
4105
diff
changeset
|
468 (set-marker start (point)))))) |
55 | 469 ;;clear the choices buffer; otherwise it's hard for the user to tell |
470 ;;when we get back to the command loop | |
471 (let ((buf (get-buffer "*ispell choices*"))) | |
472 (cond (buf | |
473 (set-buffer buf) | |
474 (erase-buffer)))) | |
475 (set-marker start nil) | |
476 (set-marker end nil) | |
2837
00f822101e49
(ispell): Deactivate mark before the Ispell run.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
477 (set-marker wend nil))) |
55 | 478 |
479 (defun ispell-still-bad (word) | |
480 (let ((words ispell-recently-accepted) | |
481 (ret t) | |
482 (case-fold-search t)) | |
483 (while words | |
484 (cond ((eq (string-match (car words) word) 0) | |
485 (setq ret nil) | |
486 (setq words nil))) | |
487 (setq words (cdr words))) | |
488 ret)) | |
489 | |
490 (defun ispell-show-choices (word message first-line) | |
778 | 491 ;;if there is only one window on the frame, make the ispell |
55 | 492 ;;messages winow be small. otherwise just use the other window |
493 (let* ((selwin (selected-window)) | |
494 (resize (eq selwin (next-window))) | |
495 (buf (get-buffer-create "*ispell choices*")) | |
496 w) | |
2837
00f822101e49
(ispell): Deactivate mark before the Ispell run.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
497 (or ispell-window-configuration |
00f822101e49
(ispell): Deactivate mark before the Ispell run.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
498 (setq ispell-window-configuration (current-window-configuration))) |
55 | 499 (setq w (display-buffer buf)) |
500 (buffer-disable-undo buf) | |
501 (if resize | |
502 (unwind-protect | |
503 (progn | |
504 (select-window w) | |
505 (enlarge-window (- 6 (window-height w)))) | |
506 (select-window selwin))) | |
507 (save-excursion | |
508 (set-buffer buf) | |
509 (bury-buffer buf) | |
510 (set-window-point w (point-min)) | |
511 (set-window-start w (point-min)) | |
512 (erase-buffer) | |
513 (insert first-line "\n") | |
514 (insert | |
515 "SPC skip; A accept; I insert; DIGIT select; R replace; \ | |
516 L lookup; Q quit\n") | |
517 (cond ((not (null message)) | |
518 (let ((i 0)) | |
519 (while (< i 3) | |
520 (let ((j 0)) | |
521 (while (< j 3) | |
522 (let* ((n (+ (* j 3) i)) | |
523 (choice (nth n message))) | |
524 (cond (choice | |
525 (let ((str (format "%d %s" n choice))) | |
526 (insert str) | |
527 (insert-char ? (- 20 (length str))))))) | |
528 (setq j (+ j 1)))) | |
529 (insert "\n") | |
530 (setq i (+ i 1))))))))) | |
531 | |
532 (defun ispell-command-loop (word start end message) | |
533 (let ((flag t) | |
534 (rescan nil) | |
535 first-line) | |
536 (if (null message) | |
537 (setq first-line (concat "No near misses for '" word "'")) | |
538 (setq first-line (concat "Near misses for '" word "'"))) | |
539 (while flag | |
540 (ispell-show-choices word message first-line) | |
541 (message "Ispell command: ") | |
2888
e931a98b2f36
(ispell-command-loop): Make an undo boundary.
Richard M. Stallman <rms@gnu.org>
parents:
2837
diff
changeset
|
542 (undo-boundary) |
55 | 543 (let ((c (downcase (read-char))) |
544 replacement) | |
545 (cond ((and (>= c ?0) | |
546 (<= c ?9) | |
547 (setq replacement (nth (- c ?0) message))) | |
548 (ispell-replace start end replacement) | |
549 (setq flag nil)) | |
550 ((= c ?q) | |
4926
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
551 (throw 'ispell-quit nil)) |
4927 | 552 ((= c (nth 3 (current-input-mode))) |
4926
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
553 (keyboard-quit)) |
55 | 554 ((= c ? ) |
555 (setq flag nil)) | |
556 ((= c ?r) | |
557 (ispell-replace start end (read-string "Replacement: ")) | |
558 (setq rescan t) | |
559 (setq flag nil)) | |
560 ((= c ?i) | |
561 (ispell-insert word) | |
562 (setq flag nil)) | |
563 ((= c ?a) | |
564 (ispell-accept word) | |
565 (setq flag nil)) | |
566 ((= c ?l) | |
567 (let ((val (ispell-do-look word))) | |
568 (setq first-line (car val)) | |
569 (setq message (cdr val)))) | |
570 ((= c ??) | |
571 (message | |
572 "Type 'C-h d ispell' to the emacs main loop for more help") | |
573 (sit-for 2)) | |
574 (t | |
575 (message "Bad ispell command") | |
576 (sit-for 2))))) | |
577 rescan)) | |
578 | |
579 (defun ispell-do-look (bad-word) | |
580 (let (regex buf words) | |
581 (cond ((null ispell-have-new-look) | |
582 (setq regex (read-string "Lookup: "))) | |
583 (t | |
584 (setq regex (read-string "Lookup (regex): " "^")))) | |
585 (setq buf (get-buffer-create "*ispell look*")) | |
586 (save-excursion | |
587 (set-buffer buf) | |
588 (delete-region (point-min) (point-max)) | |
589 (if ispell-have-new-look | |
4895
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
590 (call-process ispell-look-command nil buf nil "-r" regex) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
591 (call-process ispell-look-command nil buf nil regex)) |
55 | 592 (goto-char (point-min)) |
593 (forward-line 10) | |
594 (delete-region (point) (point-max)) | |
595 (goto-char (point-min)) | |
596 (while (not (= (point-min) (point-max))) | |
597 (end-of-line) | |
598 (setq words (cons (buffer-substring (point-min) (point)) words)) | |
599 (forward-line) | |
600 (delete-region (point-min) (point))) | |
601 (kill-buffer buf) | |
602 (cons (format "Lookup '%s'" regex) | |
603 (reverse words))))) | |
604 | |
605 (defun ispell-replace (start end new) | |
606 (goto-char start) | |
607 (insert new) | |
608 (delete-region (point) end)) | |
609 | |
610 (defun reload-ispell () | |
3623 | 611 "Tell Ispell to re-read your private dictionary." |
55 | 612 (interactive) |
613 (ispell-cmd ":reload")) | |
614 | |
615 (defun batch-make-ispell () | |
616 (byte-compile-file "ispell.el") | |
617 (find-file "ispell.texinfo") | |
618 (let ((old-dir default-directory) | |
619 (default-directory "/tmp")) | |
620 (texinfo-format-buffer)) | |
621 (Info-validate) | |
622 (if (get-buffer " *problems in info file*") | |
623 (kill-emacs 1)) | |
624 (write-region (point-min) (point-max) "ispell.info")) | |
625 | |
4895
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
626 ;;;; ispell-complete-word |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
627 |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
628 ;;; Brief Description: |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
629 ;;; Complete word fragment at point using dictionary and replace with full |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
630 ;;; word. Expansion done in current buffer like lisp-complete-symbol. |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
631 ;;; Completion of interior word fragments possible with prefix argument. |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
632 |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
633 ;;; Known Problem: |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
634 ;;; Does not use private dictionary because GNU `look' does not use it. It |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
635 ;;; would be nice if GNU `look' took standard input; this would allow gzip'ed |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
636 ;;; dictionaries to be used. GNU `look' also has a bug, see |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
637 ;;; `ispell-gnu-look-still-broken-p'. |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
638 |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
639 ;;; Motivation: |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
640 ;;; The `l', "regular expression look up", keymap option of ispell-word |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
641 ;;; (ispell-do-look) can only be run after finding a misspelled word. So |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
642 ;;; ispell-do-look can not be used to look for words starting with `cat' to |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
643 ;;; find `catechetical' since `cat' is a correctly spelled word. Furthermore, |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
644 ;;; ispell-do-look does not return the entire list returned by `look'. |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
645 ;;; |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
646 ;;; ispell-complete-word allows you to get a completion list from the system |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
647 ;;; dictionary and expand a word fragment at the current position in a buffer. |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
648 ;;; These examples assume ispell-complete-word is bound to M-TAB as it is in |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
649 ;;; text-mode; the `Complete Word' and `Complete Interior Fragment' entries of |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
650 ;;; the "Spell" submenu under the "Edit" menu may also be used instead of |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
651 ;;; M-TAB and C-u M-TAB, respectively. |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
652 ;;; |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
653 ;;; EXAMPLE 1: The word `Saskatchewan' needs to be spelled. The user may |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
654 ;;; type `Sas' and hit M-TAB and a completion list will be built using the |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
655 ;;; shell command `look' and displayed in the *Completions* buffer: |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
656 ;;; |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
657 ;;; Possible completions are: |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
658 ;;; sash sashay |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
659 ;;; sashayed sashed |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
660 ;;; sashes sashimi |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
661 ;;; Saskatchewan Saskatoon |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
662 ;;; sass sassafras |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
663 ;;; sassier sassing |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
664 ;;; sasswood sassy |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
665 ;;; |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
666 ;;; By viewing this list the user will hopefully be motivated to insert the |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
667 ;;; letter `k' after the `sas'. When M-TAB is hit again the word `Saskat' |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
668 ;;; will be inserted in place of `sas' (note case) since this is a unique |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
669 ;;; substring completion. The narrowed completion list can be viewed with |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
670 ;;; another M-TAB |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
671 ;;; |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
672 ;;; Possible completions are: |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
673 ;;; Saskatchewan Saskatoon |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
674 ;;; |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
675 ;;; Inserting the letter `c' and hitting M-TAB will narrow the completion |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
676 ;;; possibilities to just `Saskatchewan' and this will be inserted in the |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
677 ;;; buffer. At any point the user may click the mouse on a completion to |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
678 ;;; select it. |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
679 ;;; |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
680 ;;; EXAMPLE 2: The user has typed `Sasaquane' and M-$ (ispell-word) gives no |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
681 ;;; "near-misses" in which case you back up to `Sas' and hit M-TAB and find |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
682 ;;; the correct word as above. The `Sas' will be replaced by `Saskatchewan' |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
683 ;;; and the remaining word fragment `aquane' can be deleted. |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
684 ;;; |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
685 ;;; EXAMPLE 3: If a version of `look' is used that supports regular |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
686 ;;; expressions, then `ispell-have-new-look' should be t (its default) and |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
687 ;;; interior word fragments may also be used for the search. The word |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
688 ;;; `pneumonia' needs to be spelled. The user can only remember the |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
689 ;;; interior fragment `mon' in which case `C-u M-TAB' on `mon' gives a list |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
690 ;;; of all words containing the interior word fragment `mon'. Typing `p' |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
691 ;;; and M-TAB will narrow this list to all the words starting with `p' and |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
692 ;;; containing `mon' from which `pneumonia' can be found as above. |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
693 |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
694 ;;; The user-defined variables are: |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
695 ;;; |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
696 ;;; ispell-look-command |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
697 ;;; ispell-look-dictionary |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
698 ;;; ispell-gnu-look-still-broken-p |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
699 |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
700 ;;; Algorithm (some similarity to lisp-complete-symbol): |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
701 ;;; |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
702 ;;; * call-process on command ispell-look-command (default: "look") to find |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
703 ;;; words in ispell-look-dictionary matching `string' (or `regexp' if |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
704 ;;; ispell-have-new-look is t). Parse output and store results in |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
705 ;;; ispell-lookup-completions-alist. |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
706 ;;; |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
707 ;;; * Build completion list using try-completion and `string' |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
708 ;;; |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
709 ;;; * Replace `string' in buffer with matched common substring completion. |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
710 ;;; |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
711 ;;; * Display completion list only if there is no matched common substring. |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
712 ;;; |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
713 ;;; * Rebuild ispell-lookup-completions-alist, on a next call, only when |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
714 ;;; beginning of word fragment has changed. |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
715 ;;; |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
716 ;;; * Interior fragments searches are performed similarly with the exception |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
717 ;;; that the entire fragment at point is initially removed from the buffer, |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
718 ;;; the STRING passed to try-completion and all-completions is just "" and |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
719 ;;; not the interior fragment; this allows all completions containing the |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
720 ;;; interior fragment to be shown. The location in the buffer is stored to |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
721 ;;; decide whether future completion narrowing of the current list should be |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
722 ;;; done or if a new list should be built. See interior fragment example |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
723 ;;; above. |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
724 ;;; |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
725 ;;; * Robust searches are done using a `look' with -r (regular expression) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
726 ;;; switch if ispell-have-new-look is t. |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
727 |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
728 ;;;; User-defined variables. |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
729 |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
730 (defvar ispell-look-dictionary nil |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
731 "*If non-nil then spelling dictionary as string for `ispell-complete-word'. |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
732 Overrides default dictionary file such as \"/usr/dict/words\" or GNU look's |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
733 \"${prefix}/lib/ispell/ispell.words\"") |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
734 |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
735 (defvar ispell-gnu-look-still-broken-p nil |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
736 "*t if GNU look -r can give different results with and without trialing `.*'. |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
737 Example: `look -dfr \"^ya\" foo' returns nothing, while `look -dfr \"^ya.*\" foo' |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
738 returns `yacc', where `foo' is a dictionary file containing the three lines |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
739 |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
740 y |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
741 y's |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
742 yacc |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
743 |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
744 Both commands should return `yacc'. If `ispell-complete-word' erroneously |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
745 states that no completions exist for a string, then setting this variable to t |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
746 will help find those completions.") |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
747 |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
748 ;;;; Internal variables. |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
749 |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
750 ;;; Possible completions for last word fragment. |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
751 (defvar ispell-lookup-completions-alist nil) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
752 |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
753 ;;; Last word fragment processed by `ispell-complete-word'. |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
754 (defvar ispell-lookup-last-word nil) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
755 |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
756 ;;; Buffer local variables. |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
757 |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
758 ;;; Value of interior-frag in last call to `ispell-complete-word'. |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
759 (defvar ispell-lookup-last-interior-p nil) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
760 (make-variable-buffer-local 'ispell-lookup-last-interior-p) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
761 (put 'ispell-lookup-last-interior-p 'permanent-local t) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
762 |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
763 ;;; Buffer position in last call to `ispell-complete-word'. |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
764 (defvar ispell-lookup-last-bow nil) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
765 (make-variable-buffer-local 'ispell-lookup-last-bow) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
766 (put 'ispell-lookup-last-bow 'permanent-local t) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
767 |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
768 ;;;; Interactive functions. |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
769 ;;;###autoload |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
770 (defun ispell-complete-word (&optional interior-frag) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
771 "Complete word using letters at point to word beginning using `look'. |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
772 With optional argument INTERIOR-FRAG, word fragment at point is assumed to be |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
773 an interior word fragment in which case `ispell-have-new-look' should be t. |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
774 See also `ispell-look-dictionary' and `ispell-gnu-look-still-broken-p'." |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
775 |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
776 (interactive "P") |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
777 |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
778 ;; `look' must support regexp expressions in order to perform an interior |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
779 ;; fragment search. |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
780 (if (and interior-frag (not ispell-have-new-look)) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
781 (error (concat "Sorry `ispell-have-new-look' is nil. " |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
782 "You also will need GNU Ispell's `look'."))) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
783 |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
784 (let* ((completion-ignore-case t) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
785 |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
786 ;; Get location of beginning of word fragment. |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
787 (bow (save-excursion (skip-chars-backward "a-zA-Z'") (point))) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
788 |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
789 ;; Get the string to look up. |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
790 (string (buffer-substring bow (point))) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
791 |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
792 ;; Get regexp for which we search and, if necessary, an interior word |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
793 ;; fragment. |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
794 (regexp (if interior-frag |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
795 (concat "^.*" string ".*") |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
796 ;; If possible use fast binary search: no trailing `.*'. |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
797 (concat "^" string |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
798 (if ispell-gnu-look-still-broken-p ".*")))) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
799 |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
800 ;; We want all completions for case of interior fragments so set |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
801 ;; prefix to an empty string. |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
802 (prefix (if interior-frag "" string)) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
803 |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
804 ;; Are we continuing from a previous interior fragment search? |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
805 ;; Check last value of interior-word and if the point has moved. |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
806 (continuing-an-interior-frag-p |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
807 (and ispell-lookup-last-interior-p |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
808 (equal ispell-lookup-last-bow bow))) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
809 |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
810 ;; Are we starting a unique word fragment search? Always t for |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
811 ;; interior word fragment search. |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
812 (new-unique-string-p |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
813 (or interior-frag (null ispell-lookup-last-word) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
814 (let ((case-fold-search t)) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
815 ;; Can we locate last word fragment as a substring of current |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
816 ;; word fragment? If the last word fragment is larger than |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
817 ;; the current string then we will have to rebuild the list |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
818 ;; later. |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
819 (not (string-match |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
820 (concat "^" ispell-lookup-last-word) string))))) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
821 |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
822 completion) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
823 |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
824 ;; Check for perfect completion already. That is, maybe the user has hit |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
825 ;; M-x ispell-complete-word one too many times? |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
826 (if (string-equal string "") |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
827 (if (string-equal (concat ispell-lookup-last-word " ") |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
828 (buffer-substring |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
829 (save-excursion (forward-word -1) (point)) (point))) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
830 (error "Perfect match...still. Please move on.") |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
831 (error "No word fragment at point."))) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
832 |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
833 ;; Create list of words from system dictionary starting with `string' if |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
834 ;; new string and not continuing from a previous interior fragment search. |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
835 (if (and (not continuing-an-interior-frag-p) new-unique-string-p) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
836 (setq ispell-lookup-completions-alist |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
837 (ispell-lookup-build-list string regexp))) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
838 |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
839 ;; Check for a completion of `string' in the list and store `string' and |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
840 ;; other variables for the next call. |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
841 (setq completion (try-completion prefix ispell-lookup-completions-alist) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
842 ispell-lookup-last-word string |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
843 ispell-lookup-last-interior-p interior-frag |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
844 ispell-lookup-last-bow bow) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
845 |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
846 ;; Test the completion status. |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
847 (cond |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
848 |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
849 ;; * Guess is a perfect match. |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
850 ((eq completion t) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
851 (insert " ") |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
852 (message "Perfect match.")) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
853 |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
854 ;; * No possibilities. |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
855 ((null completion) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
856 (message "Can't find completion for \"%s\"" string) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
857 (beep)) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
858 |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
859 ;; * Replace string fragment with matched common substring completion. |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
860 ((and (not (string-equal completion "")) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
861 ;; Fold case so a completion list is built when `string' and common |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
862 ;; substring differ only in case. |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
863 (let ((case-fold-search t)) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
864 (not (string-match (concat "^" completion "$") string)))) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
865 (search-backward string bow) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
866 (replace-match completion nil t) ; FIXEDCASE doesn't work? or LITERAL? |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
867 (message "Proposed unique substring. Repeat for completions list.")) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
868 |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
869 ;; * String is a common substring completion already. Make list. |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
870 (t |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
871 (message "Making completion list...") |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
872 (if (string-equal completion "") (delete-region bow (point))) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
873 (let ((list (all-completions prefix ispell-lookup-completions-alist))) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
874 (with-output-to-temp-buffer " *Completions*" |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
875 (display-completion-list list))) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
876 (message "Making completion list...done"))))) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
877 |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
878 ;;;###autoload |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
879 (defun ispell-complete-word-interior-frag () |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
880 "Runs `ispell-complete-word' with a non-nil INTERIOR-FRAG. |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
881 A completion list is built for word fragment at point which is assumed to be |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
882 an interior word fragment. `ispell-have-new-look' should be t." |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
883 (interactive) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
884 (ispell-complete-word t)) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
885 |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
886 ;;;; Internal Function. |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
887 |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
888 ;;; Build list of words using ispell-look-command from dictionary |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
889 ;;; ispell-look-dictionary (if this is a non-nil string). Look for words |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
890 ;;; starting with STRING if ispell-have-new-look is nil or look for REGEXP if |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
891 ;;; ispell-have-new-look is t. Returns result as an alist suitable for use by |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
892 ;;; try-completion, all-completions, and completing-read. |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
893 (defun ispell-lookup-build-list (string regexp) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
894 (save-excursion |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
895 (message "Building list...") |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
896 (set-buffer (get-buffer-create " *ispell look*")) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
897 (erase-buffer) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
898 |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
899 (if (stringp ispell-look-dictionary) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
900 (if ispell-have-new-look |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
901 (call-process ispell-look-command nil t nil "-fr" regexp |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
902 ispell-look-dictionary) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
903 (call-process ispell-look-command nil t nil "-f" string |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
904 ispell-look-dictionary)) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
905 (if ispell-have-new-look |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
906 (call-process ispell-look-command nil t nil "-fr" regexp) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
907 (call-process ispell-look-command nil t nil "-f" string))) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
908 |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
909 ;; Build list for try-completion and all-completions by storing each line |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
910 ;; of output starting from bottom of buffer and deleting upwards. |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
911 (let (list) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
912 (goto-char (point-min)) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
913 (while (not (= (point-min) (point-max))) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
914 (end-of-line) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
915 (setq list (cons (buffer-substring (point-min) (point)) list)) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
916 (forward-line) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
917 (delete-region (point-min) (point))) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
918 |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
919 ;; Clean. |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
920 (erase-buffer) |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
921 (message "Building list...done") |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
922 |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
923 ;; Make the list into an alist and return. |
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
924 (mapcar 'list (nreverse list))))) |
4926
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
925 |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
926 ;; Return regexp-quote of STRING if STRING is non-empty. |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
927 ;; Otherwise return an unmatchable regexp. |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
928 (defun ispell-non-empty-string (string) |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
929 (if (or (not string) (string-equal string "")) |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
930 "\\'\\`" ; An unmatchable string if string is null. |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
931 (regexp-quote string))) |
4895
7c2d90ff5849
(ispell-look-command): New user variable.
Richard M. Stallman <rms@gnu.org>
parents:
4889
diff
changeset
|
932 |
4926
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
933 (defvar ispell-message-cite-regexp "^ \\|^\t" |
4842
ef5f87232112
(ispell-message-cite-regexp): Add definition.
Richard M. Stallman <rms@gnu.org>
parents:
4786
diff
changeset
|
934 "*Regular expression to match lines cited from one message into another.") |
ef5f87232112
(ispell-message-cite-regexp): Add definition.
Richard M. Stallman <rms@gnu.org>
parents:
4786
diff
changeset
|
935 |
4926
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
936 ;;;###autoload |
4749
fe223c0faf71
(ispell-message): New command, with menu bar item.
Richard M. Stallman <rms@gnu.org>
parents:
4256
diff
changeset
|
937 (defun ispell-message () |
4926
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
938 "Check the spelling of a mail message or news post. |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
939 Don't check spelling of message headers or included messages. |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
940 |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
941 To spell-check whenever a message is sent, include this line in .emacs: |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
942 (setq news-inews-hook (setq mail-send-hook 'ispell-message)) |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
943 |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
944 Or you can bind the function to C-c i in gnus or mail with: |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
945 (setq mail-mode-hook (setq news-reply-mode-hook |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
946 (function (lambda () (local-set-key \"\\C-ci\" 'ispell-message)))))" |
4749
fe223c0faf71
(ispell-message): New command, with menu bar item.
Richard M. Stallman <rms@gnu.org>
parents:
4256
diff
changeset
|
947 (interactive) |
fe223c0faf71
(ispell-message): New command, with menu bar item.
Richard M. Stallman <rms@gnu.org>
parents:
4256
diff
changeset
|
948 (save-excursion |
4929
2b5e416494d1
(ispell-message): If gnus, but no mail-yank-prefix,
Richard M. Stallman <rms@gnu.org>
parents:
4927
diff
changeset
|
949 (let (non-internal-message |
2b5e416494d1
(ispell-message): If gnus, but no mail-yank-prefix,
Richard M. Stallman <rms@gnu.org>
parents:
4927
diff
changeset
|
950 (old-case-fold-search case-fold-search) |
2b5e416494d1
(ispell-message): If gnus, but no mail-yank-prefix,
Richard M. Stallman <rms@gnu.org>
parents:
4927
diff
changeset
|
951 (case-fold-search nil)) |
4926
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
952 (goto-char (point-min)) |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
953 ;; Don't spell-check the headers. |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
954 (if (search-forward mail-header-separator nil t) |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
955 ;; Move to first body line. |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
956 (forward-line 1) |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
957 (while (and (looking-at "[a-zA-Z-]+:\\|\t\\| ") |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
958 (not (eobp))) |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
959 (forward-line 1)) |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
960 (setq non-internal-message t) |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
961 ) |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
962 (let ((cite-regexp ;Prefix of inserted text |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
963 (cond |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
964 ((featurep 'supercite) ; sc 3.0 |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
965 (concat "\\(" (sc-cite-regexp) "\\)" "\\|" |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
966 (ispell-non-empty-string sc-reference-tag-string))) |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
967 ((featurep 'sc) ; sc 2.3 |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
968 (concat "\\(" sc-cite-regexp "\\)" "\\|" |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
969 (ispell-non-empty-string sc-reference-tag-string))) |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
970 (non-internal-message ; Assume nn sent us this message. |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
971 (concat "In [a-zA-Z.]+ you write:" "\\|" |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
972 "In <[^,;&+=]+> [^,;&+=]+ writes:" "\\|" |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
973 " *> *")) |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
974 ((equal major-mode 'news-reply-mode) ;Gnus |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
975 (concat "In article <" "\\|" |
4929
2b5e416494d1
(ispell-message): If gnus, but no mail-yank-prefix,
Richard M. Stallman <rms@gnu.org>
parents:
4927
diff
changeset
|
976 (if mail-yank-prefix |
2b5e416494d1
(ispell-message): If gnus, but no mail-yank-prefix,
Richard M. Stallman <rms@gnu.org>
parents:
4927
diff
changeset
|
977 (ispell-non-empty-string mail-yank-prefix) |
2b5e416494d1
(ispell-message): If gnus, but no mail-yank-prefix,
Richard M. Stallman <rms@gnu.org>
parents:
4927
diff
changeset
|
978 ispell-message-cite-regexp))) |
4926
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
979 ((boundp 'vm-included-text-prefix) ; VM mail message |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
980 (concat "[^,;&+=]+ writes:" "\\|" |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
981 (ispell-non-empty-string vm-included-text-prefix) |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
982 )) |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
983 ((boundp 'mh-ins-buf-prefix) ; mh mail message |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
984 (ispell-non-empty-string mh-ins-buf-prefix)) |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
985 (mail-yank-prefix ; vanilla mail message. |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
986 (ispell-non-empty-string mail-yank-prefix)) |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
987 (t ispell-message-cite-regexp))) |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
988 (continue t)) |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
989 |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
990 (while (and (not (eobp)) continue) |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
991 ;; Skip across text cited from other messages. |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
992 (while (and (looking-at (concat "^[ \t]*$\\|" cite-regexp)) |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
993 (not (eobp))) |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
994 (forward-line 1)) |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
995 (if (not (eobp)) |
4929
2b5e416494d1
(ispell-message): If gnus, but no mail-yank-prefix,
Richard M. Stallman <rms@gnu.org>
parents:
4927
diff
changeset
|
996 ;; Check the next batch of lines that *aren't* cited. |
4926
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
997 (let ((start (point))) |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
998 (if (re-search-forward |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
999 (concat "^\\(" cite-regexp "\\)") nil 'end) |
c639a86ac9f1
(ispell-message): Stop if ispell-region returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
4895
diff
changeset
|
1000 (beginning-of-line)) |
4929
2b5e416494d1
(ispell-message): If gnus, but no mail-yank-prefix,
Richard M. Stallman <rms@gnu.org>
parents:
4927
diff
changeset
|
1001 (let ((case-fold-search old-case-fold-search)) |
2b5e416494d1
(ispell-message): If gnus, but no mail-yank-prefix,
Richard M. Stallman <rms@gnu.org>
parents:
4927
diff
changeset
|
1002 (save-excursion |
2b5e416494d1
(ispell-message): If gnus, but no mail-yank-prefix,
Richard M. Stallman <rms@gnu.org>
parents:
4927
diff
changeset
|
1003 (setq continue (ispell-region (- start 1) (point)))))))))))) |
4749
fe223c0faf71
(ispell-message): New command, with menu bar item.
Richard M. Stallman <rms@gnu.org>
parents:
4256
diff
changeset
|
1004 |
3112 | 1005 (provide 'ispell) |
1006 | |
660
08eb386dd0f3
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
317
diff
changeset
|
1007 ;;; ispell.el ends here |