annotate lisp/textmodes/=ispell4.el @ 2980:654eebe93c27

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