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