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