Mercurial > emacs
annotate lisp/textmodes/=ispell4.el @ 2980:654eebe93c27
* keyboard.c (make_lispy_movement): Deal properly with mouse
motion outside of all windows.
author | Jim Blandy <jimb@redhat.com> |
---|---|
date | Sun, 23 May 1993 19:52:07 +0000 |
parents | e931a98b2f36 |
children | 6b8a9fb0537c |
rev | line source |
---|---|
660
08eb386dd0f3
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
317
diff
changeset
|
1 ;;; ispell.el --- this is the GNU EMACS interface to GNU ISPELL version 3. |
08eb386dd0f3
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
317
diff
changeset
|
2 |
845 | 3 ;;Copyright (C) 1990, 1991 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 |
31 "T if default 'look' program has the -r flag.") | |
32 | |
33 (defvar ispell-enable-tex-parser nil | |
34 "T to enable experimental tex parser in ispell for tex buffers.") | |
35 | |
36 (defvar ispell-process nil "The process running ISPELL") | |
37 (defvar ispell-next-message nil | |
38 "An integer telling where in the *ispell* buffer where | |
39 to look for the next message from the ISPELL program.") | |
40 | |
41 ;Each marker in this list points to the start of a word that | |
42 ;ispell thought was bad last time it did the :file command. | |
43 ;Notice that if the user accepts or inserts a word into his | |
44 ;private dictionary, then some "good" words will be on the list. | |
45 ;We would like to deal with this by looking up the words again just before | |
46 ;presenting them to the user, but that is too slow on machines | |
47 ;without the select system call. Therefore, see the variable | |
48 ;ispell-recently-accepted. | |
49 (defvar ispell-bad-words nil | |
50 "A list of markers corresponding to the output of the ISPELL :file command.") | |
51 | |
52 ;list of words that the user has accepted, but that might still | |
53 ;be on the bad-words list | |
54 (defvar ispell-recently-accepted nil) | |
55 | |
2837
00f822101e49
(ispell): Deactivate mark before the Ispell run.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
56 ;; 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
|
57 ;; This is the window config from before then. |
00f822101e49
(ispell): Deactivate mark before the Ispell run.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
58 (defvar ispell-window-configuration) |
00f822101e49
(ispell): Deactivate mark before the Ispell run.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
59 |
55 | 60 ;t when :dump command needed |
61 (defvar ispell-dump-needed nil) | |
62 | |
63 (defun ispell-flush-bad-words () | |
64 (while ispell-bad-words | |
65 (if (markerp (car ispell-bad-words)) | |
66 (set-marker (car ispell-bad-words) nil)) | |
67 (setq ispell-bad-words (cdr ispell-bad-words))) | |
68 (setq ispell-recently-accepted nil)) | |
69 | |
70 (defun kill-ispell () | |
71 "Kill the ispell process. | |
72 Any changes the your private dictionay | |
73 that have not already been dumped will be lost." | |
74 (interactive) | |
75 (if ispell-process | |
76 (delete-process ispell-process)) | |
77 (setq ispell-process nil) | |
78 (ispell-flush-bad-words)) | |
79 | |
80 (put 'ispell-startup-error 'error-conditions | |
81 '(ispell-startup-error error)) | |
82 (put 'ispell-startup-error 'error-message | |
83 "Problem starting ispell - see buffer *ispell*") | |
84 | |
85 (defun start-ispell () | |
86 "Start an ispell subprocess; check the version; and display the greeting." | |
87 (message "Starting ispell ...") | |
88 (let ((buf (get-buffer "*ispell*"))) | |
89 (if buf | |
90 (kill-buffer buf))) | |
91 (condition-case err | |
92 (setq ispell-process (start-process "ispell" "*ispell*" "ispell" "-S")) | |
93 (file-error (signal 'ispell-startup-error nil))) | |
94 (process-kill-without-query ispell-process) | |
95 (buffer-disable-undo (process-buffer ispell-process)) | |
96 (accept-process-output ispell-process) | |
97 (let (last-char) | |
98 (save-excursion | |
99 (set-buffer (process-buffer ispell-process)) | |
100 (bury-buffer (current-buffer)) | |
101 (setq last-char (- (point-max) 1)) | |
102 (while (not (eq (char-after last-char) ?=)) | |
103 (cond ((not (eq (process-status ispell-process) 'run)) | |
104 (kill-ispell) | |
105 (signal 'ispell-startup-error nil))) | |
106 (accept-process-output ispell-process) | |
107 (setq last-char (- (point-max) 1))) | |
108 (goto-char (point-min)) | |
109 (let ((greeting (read (current-buffer)))) | |
110 (if (not (= (car greeting) 1)) | |
111 (error "Bad ispell version: wanted 1, got %d" (car greeting))) | |
112 (message (car (cdr greeting)))) | |
113 (delete-region (point-min) last-char)))) | |
114 | |
115 ;leaves buffer set to *ispell*, point at '=' | |
116 (defun ispell-sync (intr) | |
117 "Make sure ispell is ready for a command." | |
118 (if (or (null ispell-process) | |
119 (not (eq (process-status ispell-process) 'run))) | |
120 (start-ispell)) | |
121 (if intr | |
122 (interrupt-process ispell-process)) | |
123 (let (last-char) | |
124 (set-buffer (process-buffer ispell-process)) | |
125 (bury-buffer (current-buffer)) | |
126 (setq last-char (- (point-max) 1)) | |
127 (while (not (eq (char-after last-char) ?=)) | |
128 (accept-process-output ispell-process) | |
129 (setq last-char (- (point-max) 1))) | |
130 (goto-char last-char))) | |
131 | |
132 (defun ispell-cmd (&rest strings) | |
133 "Send a command to ispell. Choices are: | |
134 | |
671
21d23fa6fa2a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
135 WORD Check spelling of WORD. Result is |
55 | 136 |
671
21d23fa6fa2a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
137 nil not found |
21d23fa6fa2a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
138 t spelled ok |
21d23fa6fa2a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
139 list of strings near misses |
55 | 140 |
671
21d23fa6fa2a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
141 :file FILENAME scan the named file, and print the file offsets of |
55 | 142 any misspelled words |
143 | |
671
21d23fa6fa2a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
144 :insert WORD put word in private dictonary |
55 | 145 |
671
21d23fa6fa2a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
146 :accept WORD don't complain about word any more this session |
55 | 147 |
148 :dump write out the current private dictionary, if necessary. | |
149 | |
671
21d23fa6fa2a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
150 :reload reread `~/ispell.words' |
55 | 151 |
152 :tex | |
153 :troff | |
154 :generic set type of parser to use when scanning whole files | |
155 " | |
156 (save-excursion | |
157 (ispell-sync t) | |
158 (set-buffer (process-buffer ispell-process)) | |
159 (bury-buffer (current-buffer)) | |
160 (erase-buffer) | |
161 (setq ispell-next-message (point-min)) | |
162 (while strings | |
163 (process-send-string ispell-process (car strings)) | |
164 (setq strings (cdr strings))) | |
165 (process-send-string ispell-process "\n") | |
166 (accept-process-output ispell-process) | |
167 (ispell-sync nil))) | |
168 | |
169 (defun ispell-dump () | |
170 (cond (ispell-dump-needed | |
171 (setq ispell-dump-needed nil) | |
172 (ispell-cmd ":dump")))) | |
173 | |
174 (defun ispell-insert (word) | |
175 (ispell-cmd ":insert " word) | |
176 (if ispell-bad-words | |
177 (setq ispell-recently-accepted (cons word ispell-recently-accepted))) | |
178 (setq ispell-dump-needed t)) | |
179 | |
180 (defun ispell-accept (word) | |
181 (ispell-cmd ":accept " word) | |
182 (if ispell-bad-words | |
183 (setq ispell-recently-accepted (cons word ispell-recently-accepted)))) | |
184 | |
185 | |
186 (defun ispell-next-message () | |
187 "Return the next message sent by the ispell subprocess." | |
188 (save-excursion | |
189 (set-buffer (process-buffer ispell-process)) | |
190 (bury-buffer (current-buffer)) | |
191 (save-restriction | |
192 (goto-char ispell-next-message) | |
193 (narrow-to-region (point) | |
194 (progn (forward-sexp 1) (point))) | |
195 (setq ispell-next-message (point)) | |
196 (goto-char (point-min)) | |
197 (read (current-buffer))))) | |
198 | |
199 (defun ispell-tex-buffer-p () | |
200 (memq major-mode '(plain-TeX-mode LaTeX-mode))) | |
201 | |
256 | 202 ;;;###autoload |
55 | 203 (defun ispell (&optional buf start end) |
671
21d23fa6fa2a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
204 "Run Ispell over current buffer's visited file. |
21d23fa6fa2a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
205 First the file is scanned for misspelled words, then Ispell |
55 | 206 enters a loop with the following commands for every misspelled word: |
207 | |
208 DIGIT Near miss selector. If the misspelled word is close to | |
209 some words in the dictionary, they are offered as near misses. | |
210 r Replace. Replace the word with a string you type. Each word | |
211 of your new string is also checked. | |
212 i Insert. Insert this word in your private dictonary (kept in | |
213 `$HOME/ispell.words'). | |
214 a Accept. Accept this word for the rest of this editing session, | |
215 but don't put it in your private dictonary. | |
216 l Lookup. Look for a word in the dictionary by fast binary | |
217 search, or search for a regular expression in the dictionary | |
218 using grep. | |
219 SPACE Accept the word this time, but complain if it is seen again. | |
214 | 220 q, \\[keyboard-quit] Leave the command loop. You can come back later with \\[ispell-next]." |
55 | 221 (interactive) |
222 (if (null start) | |
223 (setq start 0)) | |
224 (if (null end) | |
225 (setq end 0)) | |
226 | |
227 (if (null buf) | |
228 (setq buf (current-buffer))) | |
229 (setq buf (get-buffer buf)) | |
230 (if (null buf) | |
231 (error "Can't find buffer")) | |
2837
00f822101e49
(ispell): Deactivate mark before the Ispell run.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
232 ;; 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
|
233 ;; and a region highlight while in the Ispell loop is distracting. |
00f822101e49
(ispell): Deactivate mark before the Ispell run.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
234 (if transient-mark-mode |
00f822101e49
(ispell): Deactivate mark before the Ispell run.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
235 (progn |
00f822101e49
(ispell): Deactivate mark before the Ispell run.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
236 (setq mark-active nil) |
00f822101e49
(ispell): Deactivate mark before the Ispell run.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
237 (run-hooks 'deactivate-mark-hook))) |
55 | 238 (save-excursion |
239 (set-buffer buf) | |
240 (let ((filename buffer-file-name) | |
2837
00f822101e49
(ispell): Deactivate mark before the Ispell run.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
241 (delete-temp nil)) |
55 | 242 (unwind-protect |
243 (progn | |
244 (cond ((null filename) | |
245 (setq filename (make-temp-name "/usr/tmp/ispell")) | |
246 (setq delete-temp t) | |
247 (write-region (point-min) (point-max) filename)) | |
248 ((and (buffer-modified-p buf) | |
249 (y-or-n-p (format "Save file %s? " filename))) | |
250 (save-buffer))) | |
251 (message "Ispell scanning file...") | |
252 (if (and ispell-enable-tex-parser | |
253 (ispell-tex-buffer-p)) | |
254 (ispell-cmd ":tex") | |
255 (ispell-cmd ":generic")) | |
256 (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
|
257 (if delete-temp |
00f822101e49
(ispell): Deactivate mark before the Ispell run.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
258 (condition-case () |
00f822101e49
(ispell): Deactivate mark before the Ispell run.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
259 (delete-file filename) |
00f822101e49
(ispell): Deactivate mark before the Ispell run.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
260 (file-error nil))))) |
55 | 261 (message "Parsing ispell output ...") |
262 (ispell-flush-bad-words) | |
263 (let (pos bad-words) | |
264 (while (numberp (setq pos (ispell-next-message))) | |
265 ;;ispell may check the words on the line following the end | |
266 ;;of the region - therefore, don't record anything out of range | |
267 (if (or (= end 0) | |
268 (< pos end)) | |
269 (setq bad-words (cons (set-marker (make-marker) (+ pos 1)) | |
270 bad-words)))) | |
271 (setq bad-words (cons pos bad-words)) | |
272 (setq ispell-bad-words (nreverse bad-words)))) | |
273 (cond ((not (markerp (car ispell-bad-words))) | |
274 (setq ispell-bad-words nil) | |
275 (message "No misspellings.")) | |
276 (t | |
277 (message "Ispell parsing done.") | |
278 (ispell-next)))) | |
279 | |
316 | 280 ;;;###autoload |
2571
b65cf676a09b
All fsets changed to defaliases.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2307
diff
changeset
|
281 (defalias 'ispell-buffer 'ispell) |
316 | 282 |
55 | 283 (defun ispell-next () |
284 "Resume command loop for most recent ispell command." | |
285 (interactive) | |
2837
00f822101e49
(ispell): Deactivate mark before the Ispell run.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
286 (setq ispell-window-configuration nil) |
55 | 287 (unwind-protect |
288 (catch 'quit | |
2837
00f822101e49
(ispell): Deactivate mark before the Ispell run.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
289 ;; 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
|
290 ;; 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
|
291 ;; when you type q. |
00f822101e49
(ispell): Deactivate mark before the Ispell run.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
292 (let (next) |
00f822101e49
(ispell): Deactivate mark before the Ispell run.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
293 (while (markerp (setq next (car ispell-bad-words))) |
00f822101e49
(ispell): Deactivate mark before the Ispell run.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
294 (switch-to-buffer (marker-buffer next)) |
00f822101e49
(ispell): Deactivate mark before the Ispell run.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
295 (push-mark) |
00f822101e49
(ispell): Deactivate mark before the Ispell run.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
296 (ispell-point next "at saved position.") |
00f822101e49
(ispell): Deactivate mark before the Ispell run.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
297 (setq ispell-bad-words (cdr ispell-bad-words)) |
00f822101e49
(ispell): Deactivate mark before the Ispell run.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
298 (set-marker next nil)))) |
00f822101e49
(ispell): Deactivate mark before the Ispell run.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
299 (if ispell-window-configuration |
00f822101e49
(ispell): Deactivate mark before the Ispell run.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
300 (set-window-configuration ispell-window-configuration)) |
55 | 301 (cond ((null ispell-bad-words) |
302 (error "Ispell has not yet been run.")) | |
303 ((markerp (car ispell-bad-words)) | |
304 (message (substitute-command-keys | |
305 "Type \\[ispell-next] to continue."))) | |
306 ((eq (car ispell-bad-words) nil) | |
307 (setq ispell-bad-words nil) | |
308 (message "No more misspellings (but checker was interrupted.)")) | |
309 ((eq (car ispell-bad-words) t) | |
310 (setq ispell-bad-words nil) | |
311 (message "Ispell done.")) | |
312 (t | |
313 (setq ispell-bad-words nil) | |
314 (message "Bad ispell internal list")))) | |
315 (ispell-dump)) | |
316 | |
256 | 317 ;;;###autoload |
671
21d23fa6fa2a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
318 (defun ispell-word (&optional resume) |
55 | 319 "Check the spelling of the word under the cursor. |
671
21d23fa6fa2a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
320 See `ispell' for more information. |
21d23fa6fa2a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
321 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
|
322 (interactive "P") |
21d23fa6fa2a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
323 (if resume |
21d23fa6fa2a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
324 (ispell-next) |
21d23fa6fa2a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
325 (condition-case err |
21d23fa6fa2a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
326 (catch 'quit |
21d23fa6fa2a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
327 (save-window-excursion |
21d23fa6fa2a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
328 (ispell-point (point) "at point.")) |
21d23fa6fa2a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
329 (ispell-dump)) |
21d23fa6fa2a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
330 (ispell-startup-error |
21d23fa6fa2a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
331 (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
|
332 (load-library "spell") |
21d23fa6fa2a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
333 (define-key esc-map "$" 'spell-word) |
21d23fa6fa2a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
334 (spell-word))))))) |
316 | 335 ;;;###autoload |
336 (define-key esc-map "$" 'ispell-word) | |
55 | 337 |
256 | 338 ;;;###autoload |
55 | 339 (defun ispell-region (start &optional end) |
340 "Check the spelling for all of the words in the region." | |
341 (interactive "r") | |
342 (ispell (current-buffer) start end)) | |
343 | |
344 (defun ispell-letterp (c) | |
345 (and c | |
346 (or (and (>= c ?A) (<= c ?Z)) | |
347 (and (>= c ?a) (<= c ?z)) | |
348 (>= c 128)))) | |
349 | |
350 (defun ispell-letter-or-quotep (c) | |
351 (and c | |
352 (or (and (>= c ?A) (<= c ?Z)) | |
353 (and (>= c ?a) (<= c ?z)) | |
354 (= c ?') | |
355 (>= c 128)))) | |
356 | |
357 (defun ispell-find-word-start () | |
358 ;;backward to a letter | |
359 (if (not (ispell-letterp (char-after (point)))) | |
360 (while (and (not (bobp)) | |
361 (not (ispell-letterp (char-after (- (point) 1))))) | |
362 (backward-char))) | |
363 ;;backward to beginning of word | |
364 (while (ispell-letter-or-quotep (char-after (- (point) 1))) | |
365 (backward-char)) | |
366 (skip-chars-forward "'")) | |
367 | |
368 (defun ispell-find-word-end () | |
369 (while (ispell-letter-or-quotep (char-after (point))) | |
370 (forward-char)) | |
371 (skip-chars-backward "'")) | |
372 | |
373 (defun ispell-next-word () | |
374 (while (and (not (eobp)) | |
375 (not (ispell-letterp (char-after (point))))) | |
376 (forward-char))) | |
377 | |
378 ;if end is nil, then do one word at start | |
379 ;otherwise, do all words from the beginning of the word where | |
380 ;start points, to the end of the word where end points | |
381 (defun ispell-point (start message) | |
382 (let ((wend (make-marker)) | |
383 rescan | |
384 end) | |
2837
00f822101e49
(ispell): Deactivate mark before the Ispell run.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
385 ;; 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
|
386 ;; 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
|
387 ;; when you type q. |
55 | 388 (goto-char start) |
389 (ispell-find-word-start) ;find correct word start | |
390 (setq start (point-marker)) | |
391 (ispell-find-word-end) ;now find correct end | |
392 (setq end (point-marker)) | |
393 (if (>= start end) | |
394 (error "No word %s" message)) | |
395 (while (< start end) | |
396 (goto-char start) | |
397 (ispell-find-word-end) ;find end of current word | |
398 ;could be before 'end' if | |
399 ;user typed replacement | |
400 ;that is more than one word | |
401 (set-marker wend (point)) | |
402 (setq rescan nil) | |
403 (setq word (buffer-substring start wend)) | |
404 (cond ((ispell-still-bad word) | |
2837
00f822101e49
(ispell): Deactivate mark before the Ispell run.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
405 ;;; This just causes confusion. -- rms. |
00f822101e49
(ispell): Deactivate mark before the Ispell run.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
406 ;;; (goto-char start) |
00f822101e49
(ispell): Deactivate mark before the Ispell run.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
407 ;;; (sit-for 0) |
55 | 408 (message (format "Ispell checking %s" word)) |
409 (ispell-cmd word) | |
410 (let ((message (ispell-next-message))) | |
411 (cond ((eq message t) | |
412 (message "%s: ok" word)) | |
413 ((or (null message) | |
414 (consp message)) | |
415 (setq rescan | |
416 (ispell-command-loop word start wend message))) | |
417 (t | |
418 (error "unknown ispell response %s" message)))))) | |
419 (cond ((null rescan) | |
420 (goto-char wend) | |
421 (ispell-next-word) | |
422 (set-marker start (point))))) | |
423 ;;clear the choices buffer; otherwise it's hard for the user to tell | |
424 ;;when we get back to the command loop | |
425 (let ((buf (get-buffer "*ispell choices*"))) | |
426 (cond (buf | |
427 (set-buffer buf) | |
428 (erase-buffer)))) | |
429 (set-marker start nil) | |
430 (set-marker end nil) | |
2837
00f822101e49
(ispell): Deactivate mark before the Ispell run.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
431 (set-marker wend nil))) |
55 | 432 |
433 (defun ispell-still-bad (word) | |
434 (let ((words ispell-recently-accepted) | |
435 (ret t) | |
436 (case-fold-search t)) | |
437 (while words | |
438 (cond ((eq (string-match (car words) word) 0) | |
439 (setq ret nil) | |
440 (setq words nil))) | |
441 (setq words (cdr words))) | |
442 ret)) | |
443 | |
444 (defun ispell-show-choices (word message first-line) | |
778 | 445 ;;if there is only one window on the frame, make the ispell |
55 | 446 ;;messages winow be small. otherwise just use the other window |
447 (let* ((selwin (selected-window)) | |
448 (resize (eq selwin (next-window))) | |
449 (buf (get-buffer-create "*ispell choices*")) | |
450 w) | |
2837
00f822101e49
(ispell): Deactivate mark before the Ispell run.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
451 (or ispell-window-configuration |
00f822101e49
(ispell): Deactivate mark before the Ispell run.
Richard M. Stallman <rms@gnu.org>
parents:
2571
diff
changeset
|
452 (setq ispell-window-configuration (current-window-configuration))) |
55 | 453 (setq w (display-buffer buf)) |
454 (buffer-disable-undo buf) | |
455 (if resize | |
456 (unwind-protect | |
457 (progn | |
458 (select-window w) | |
459 (enlarge-window (- 6 (window-height w)))) | |
460 (select-window selwin))) | |
461 (save-excursion | |
462 (set-buffer buf) | |
463 (bury-buffer buf) | |
464 (set-window-point w (point-min)) | |
465 (set-window-start w (point-min)) | |
466 (erase-buffer) | |
467 (insert first-line "\n") | |
468 (insert | |
469 "SPC skip; A accept; I insert; DIGIT select; R replace; \ | |
470 L lookup; Q quit\n") | |
471 (cond ((not (null message)) | |
472 (let ((i 0)) | |
473 (while (< i 3) | |
474 (let ((j 0)) | |
475 (while (< j 3) | |
476 (let* ((n (+ (* j 3) i)) | |
477 (choice (nth n message))) | |
478 (cond (choice | |
479 (let ((str (format "%d %s" n choice))) | |
480 (insert str) | |
481 (insert-char ? (- 20 (length str))))))) | |
482 (setq j (+ j 1)))) | |
483 (insert "\n") | |
484 (setq i (+ i 1))))))))) | |
485 | |
486 (defun ispell-command-loop (word start end message) | |
487 (let ((flag t) | |
488 (rescan nil) | |
489 first-line) | |
490 (if (null message) | |
491 (setq first-line (concat "No near misses for '" word "'")) | |
492 (setq first-line (concat "Near misses for '" word "'"))) | |
493 (while flag | |
494 (ispell-show-choices word message first-line) | |
495 (message "Ispell command: ") | |
2888
e931a98b2f36
(ispell-command-loop): Make an undo boundary.
Richard M. Stallman <rms@gnu.org>
parents:
2837
diff
changeset
|
496 (undo-boundary) |
55 | 497 (let ((c (downcase (read-char))) |
498 replacement) | |
499 (cond ((and (>= c ?0) | |
500 (<= c ?9) | |
501 (setq replacement (nth (- c ?0) message))) | |
502 (ispell-replace start end replacement) | |
503 (setq flag nil)) | |
504 ((= c ?q) | |
505 (throw 'quit nil)) | |
506 ((= c ? ) | |
507 (setq flag nil)) | |
508 ((= c ?r) | |
509 (ispell-replace start end (read-string "Replacement: ")) | |
510 (setq rescan t) | |
511 (setq flag nil)) | |
512 ((= c ?i) | |
513 (ispell-insert word) | |
514 (setq flag nil)) | |
515 ((= c ?a) | |
516 (ispell-accept word) | |
517 (setq flag nil)) | |
518 ((= c ?l) | |
519 (let ((val (ispell-do-look word))) | |
520 (setq first-line (car val)) | |
521 (setq message (cdr val)))) | |
522 ((= c ??) | |
523 (message | |
524 "Type 'C-h d ispell' to the emacs main loop for more help") | |
525 (sit-for 2)) | |
526 (t | |
527 (message "Bad ispell command") | |
528 (sit-for 2))))) | |
529 rescan)) | |
530 | |
531 (defun ispell-do-look (bad-word) | |
532 (let (regex buf words) | |
533 (cond ((null ispell-have-new-look) | |
534 (setq regex (read-string "Lookup: "))) | |
535 (t | |
536 (setq regex (read-string "Lookup (regex): " "^")))) | |
537 (setq buf (get-buffer-create "*ispell look*")) | |
538 (save-excursion | |
539 (set-buffer buf) | |
540 (delete-region (point-min) (point-max)) | |
541 (if ispell-have-new-look | |
542 (call-process "look" nil buf nil "-r" regex) | |
543 (call-process "look" nil buf nil regex)) | |
544 (goto-char (point-min)) | |
545 (forward-line 10) | |
546 (delete-region (point) (point-max)) | |
547 (goto-char (point-min)) | |
548 (while (not (= (point-min) (point-max))) | |
549 (end-of-line) | |
550 (setq words (cons (buffer-substring (point-min) (point)) words)) | |
551 (forward-line) | |
552 (delete-region (point-min) (point))) | |
553 (kill-buffer buf) | |
554 (cons (format "Lookup '%s'" regex) | |
555 (reverse words))))) | |
556 | |
557 (defun ispell-replace (start end new) | |
558 (goto-char start) | |
559 (insert new) | |
560 (delete-region (point) end)) | |
561 | |
562 (defun reload-ispell () | |
563 "Tell ispell to re-read your private dictionary." | |
564 (interactive) | |
565 (ispell-cmd ":reload")) | |
566 | |
567 (defun batch-make-ispell () | |
568 (byte-compile-file "ispell.el") | |
569 (find-file "ispell.texinfo") | |
570 (let ((old-dir default-directory) | |
571 (default-directory "/tmp")) | |
572 (texinfo-format-buffer)) | |
573 (Info-validate) | |
574 (if (get-buffer " *problems in info file*") | |
575 (kill-emacs 1)) | |
576 (write-region (point-min) (point-max) "ispell.info")) | |
577 | |
660
08eb386dd0f3
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
317
diff
changeset
|
578 ;;; ispell.el ends here |