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