summaryrefslogtreecommitdiff
path: root/lisp/textmodes/ispell.el
diff options
context:
space:
mode:
authorRichard M. Stallman <rms@gnu.org>1994-07-20 18:26:57 +0000
committerRichard M. Stallman <rms@gnu.org>1994-07-20 18:26:57 +0000
commit045dbcbc1d73435e19731a61f76eb72eefe9a2c1 (patch)
tree046845b7d6996eafd0d41f373fc64c3b0ef8c275 /lisp/textmodes/ispell.el
parent229b798613bfe3eac508601a71eaf40ceb60553e (diff)
downloademacs-045dbcbc1d73435e19731a61f76eb72eefe9a2c1.tar.gz
(ispell-command-loop, ispell-region, ispell-word):
Only pop up the choices window if an error is found in the region. Don't change the size of the choices window except as needed. Don't (sit-for 0) at the start of ispell-region (i.e. don't force redisplay at the start of the region). (ispell-overlay-window): Small documentation fix.
Diffstat (limited to 'lisp/textmodes/ispell.el')
-rw-r--r--lisp/textmodes/ispell.el456
1 files changed, 219 insertions, 237 deletions
diff --git a/lisp/textmodes/ispell.el b/lisp/textmodes/ispell.el
index 268bd76bbd9..ca965d3d51e 100644
--- a/lisp/textmodes/ispell.el
+++ b/lisp/textmodes/ispell.el
@@ -741,7 +741,6 @@ or \\[ispell-region] to update the Ispell process."
quietly ispell-quietly))
(ispell-buffer-local-dict) ; use the correct dictionary
(let ((cursor-location (point)) ; retain cursor location
- ispell-keep-choices-win ; override global to force creation
(word (ispell-get-word following))
start end poss replace)
;; destructure return word info list.
@@ -778,10 +777,11 @@ or \\[ispell-region] to update the Ispell process."
(progn
(if ispell-highlight-p ;highlight word
(ispell-highlight-spelling-error start end t))
- (setq replace (ispell-command-loop
- (car (cdr (cdr poss)))
- (car (cdr (cdr (cdr poss))))
- (car poss))))
+ (save-window-excursion
+ (setq replace (ispell-command-loop
+ (car (cdr (cdr poss)))
+ (car (cdr (cdr (cdr poss))))
+ (car poss)))))
;; protected
(if ispell-highlight-p ; clear highlight
(ispell-highlight-spelling-error start end)))
@@ -889,214 +889,206 @@ Returns list for new replacement word (will be rechecked).
Global `ispell-pdict-modified-p' becomes a list where the only value
indicates whether the dictionary has been modified when option `a' or `i' is
used."
- (unwind-protect
- (save-window-excursion
- (let ((count ?0)
- (line 2)
- (max-lines (- (window-height) 4)) ; assure 4 context lines.
- (choices miss)
- (window-min-height (min window-min-height
- ispell-choices-win-default-height))
- (command-characters '( ? ?i ?a ?A ?r ?R ?? ?x ?X ?q ?l ?u ?m ))
- (skipped 0)
- char num result)
- (save-excursion
- (if ispell-keep-choices-win
+ (let ((count ?0)
+ (line 2)
+ (max-lines (- (window-height) 4)) ; assure 4 context lines.
+ (choices miss)
+ (window-min-height (min window-min-height
+ ispell-choices-win-default-height))
+ (command-characters '( ? ?i ?a ?A ?r ?R ?? ?x ?X ?q ?l ?u ?m ))
+ (skipped 0)
+ char num result)
+ (save-excursion
+ (set-buffer (get-buffer-create ispell-choices-buffer))
+ (setq mode-line-format "-- %b --")
+ (erase-buffer)
+ (if guess
+ (progn
+ (insert "Affix rules generate and capitalize "
+ "this word as shown below:\n\t")
+ (while guess
+ (if (> (+ 4 (current-column) (length (car guess)))
+ (window-width))
+ (progn
+ (insert "\n\t")
+ (setq line (1+ line))))
+ (insert (car guess) " ")
+ (setq guess (cdr guess)))
+ (insert "\nUse option `i' if this is a correct composition"
+ " from the derivative root.\n")
+ (setq line (+ line (if choices 3 2)))))
+ (while (and choices
+ (< (if (> (+ 7 (current-column) (length (car choices))
+ (if (> count ?~) 3 0))
+ (window-width))
+ (progn
+ (insert "\n")
+ (setq line (1+ line)))
+ line)
+ max-lines))
+ ;; not so good if there are over 20 or 30 options, but then, if
+ ;; there are that many you don't want to scan them all anyway...
+ (while (memq count command-characters) ; skip command characters.
+ (setq count (1+ count)
+ skipped (1+ skipped)))
+ (insert "(" count ") " (car choices) " ")
+ (setq choices (cdr choices)
+ count (1+ count)))
+ (setq count (- count ?0 skipped)))
+
+ (let ((choices-window (get-buffer-window ispell-choices-buffer)))
+ (if choices-window
+ (if (not (equal line (window-height choices-window)))
+ (progn
+ (save-excursion
+ (let ((cur-point (point)))
+ (move-to-window-line (- line (window-height choices-window)))
+ (if (<= (point) cur-point)
+ (set-window-start (selected-window) (point)))))
(select-window (previous-window))
- (set-buffer (get-buffer-create ispell-choices-buffer))
- (setq mode-line-format "-- %b --"))
- (if (equal (get-buffer ispell-choices-buffer) (current-buffer))
- (erase-buffer)
- (error (concat "Bogus, dude! I should be in the *Choices*"
- " buffer, but I'm not!")))
- (if guess
- (progn
- (insert "Affix rules generate and capitalize "
- "this word as shown below:\n\t")
- (while guess
- (if (> (+ 4 (current-column) (length (car guess)))
- (window-width))
- (progn
- (insert "\n\t")
- (setq line (1+ line))))
- (insert (car guess) " ")
- (setq guess (cdr guess)))
- (insert "\nUse option `i' if this is a correct composition"
- " from the derivative root.\n")
- (setq line (+ line (if choices 3 2)))))
- (while (and choices
- (< (if (> (+ 7 (current-column) (length (car choices))
- (if (> count ?~) 3 0))
- (window-width))
- (progn
- (insert "\n")
- (setq line (1+ line)))
- line)
- max-lines))
- ;; not so good if there are over 20 or 30 options, but then, if
- ;; there are that many you don't want to scan them all anyway...
- (while (memq count command-characters) ; skip command characters.
- (setq count (1+ count)
- skipped (1+ skipped)))
- (insert "(" count ") " (car choices) " ")
- (setq choices (cdr choices)
- count (1+ count)))
- (setq count (- count ?0 skipped)))
-
- (if ispell-keep-choices-win
- (if (> line ispell-keep-choices-win)
+ (enlarge-window (- line (window-height choices-window))))
+ (select-window choices-window))
+ (ispell-overlay-window (max line
+ ispell-choices-win-default-height))
+ (switch-to-buffer ispell-choices-buffer)))
+ (goto-char (point-min))
+ (select-window (next-window))
+ (while
+ (eq
+ t
+ (setq
+ result
+ (progn
+ (undo-boundary)
+ (message (concat "C-h or ? for more options; SPC to leave "
+ "unchanged, Character to replace word"))
+ (let ((inhibit-quit t))
+ (setq char (if (fboundp 'read-char-exclusive)
+ (read-char-exclusive)
+ (read-char))
+ skipped 0)
+ (if (or quit-flag (= char ?\C-g)) ; C-g is like typing X
+ (setq char ?X
+ quit-flag nil)))
+ ;; Adjust num to array offset skipping command characters.
+ (let ((com-chars command-characters))
+ (while com-chars
+ (if (and (> (car com-chars) ?0) (< (car com-chars) char))
+ (setq skipped (1+ skipped)))
+ (setq com-chars (cdr com-chars)))
+ (setq num (- char ?0 skipped)))
+
+ (cond
+ ((= char ? ) nil) ; accept word this time only
+ ((= char ?i) ; accept and insert word into pers dict
+ (process-send-string ispell-process (concat "*" word "\n"))
+ (setq ispell-pdict-modified-p '(t)) ; dictionary modified!
+ nil)
+ ((or (= char ?a) (= char ?A)) ; accept word without insert
+ (process-send-string ispell-process (concat "@" word "\n"))
+ (if (null ispell-pdict-modified-p)
+ (setq ispell-pdict-modified-p
+ (list ispell-pdict-modified-p)))
+ (if (= char ?A) 0)) ; return 0 for ispell-add buffer-local
+ ((or (= char ?r) (= char ?R)) ; type in replacement
+ (if (or (= char ?R) ispell-query-replace-choices)
+ (list (read-string "Query-replacement for: " word) t)
+ (cons (read-string "Replacement for: " word) nil)))
+ ((or (= char ??) (= char help-char) (= char ?\C-h))
+ (ispell-help)
+ t)
+ ;; Quit and move point back.
+ ((= char ?x)
+ (ispell-pdict-save ispell-silently-savep)
+ (message "Exited spell-checking")
+ (setq ispell-quit t)
+ nil)
+ ;; Quit and preserve point.
+ ((= char ?X)
+ (ispell-pdict-save ispell-silently-savep)
+ (message
+ (substitute-command-keys
+ (concat "Spell-checking suspended;"
+ " use C-u \\[ispell-word] to resume")))
+ (setq ispell-quit (max (point-min)
+ (- (point) (length word))))
+ nil)
+ ((= char ?q)
+ (if (y-or-n-p "Really kill Ispell process? ")
(progn
- (switch-to-buffer ispell-choices-buffer)
- (select-window (next-window))
- (save-excursion
- (let ((cur-point (point)))
- (move-to-window-line (- line ispell-keep-choices-win))
- (if (<= (point) cur-point)
- (set-window-start (selected-window) (point)))))
- (select-window (previous-window))
- (enlarge-window (- line ispell-keep-choices-win))
- (goto-char (point-min))))
- (ispell-overlay-window (max line
- ispell-choices-win-default-height)))
- (switch-to-buffer ispell-choices-buffer)
- (goto-char (point-min))
- (select-window (next-window))
- (while
- (eq
- t
- (setq
- result
- (progn
- (undo-boundary)
- (message (concat "C-h or ? for more options; SPC to leave "
- "unchanged, Character to replace word"))
- (let ((inhibit-quit t))
- (setq char (if (fboundp 'read-char-exclusive)
- (read-char-exclusive)
- (read-char))
- skipped 0)
- (if (or quit-flag (= char ?\C-g)) ; C-g is like typing X
- (setq char ?X
- quit-flag nil)))
- ;; Adjust num to array offset skipping command characters.
- (let ((com-chars command-characters))
- (while com-chars
- (if (and (> (car com-chars) ?0) (< (car com-chars) char))
- (setq skipped (1+ skipped)))
- (setq com-chars (cdr com-chars)))
- (setq num (- char ?0 skipped)))
-
- (cond
- ((= char ? ) nil) ; accept word this time only
- ((= char ?i) ; accept and insert word into pers dict
- (process-send-string ispell-process (concat "*" word "\n"))
- (setq ispell-pdict-modified-p '(t)) ; dictionary modified!
- nil)
- ((or (= char ?a) (= char ?A)) ; accept word without insert
- (process-send-string ispell-process (concat "@" word "\n"))
- (if (null ispell-pdict-modified-p)
- (setq ispell-pdict-modified-p
- (list ispell-pdict-modified-p)))
- (if (= char ?A) 0)) ; return 0 for ispell-add buffer-local
- ((or (= char ?r) (= char ?R)) ; type in replacement
- (if (or (= char ?R) ispell-query-replace-choices)
- (list (read-string "Query-replacement for: " word) t)
- (cons (read-string "Replacement for: " word) nil)))
- ((or (= char ??) (= char help-char) (= char ?\C-h))
- (ispell-help)
- t)
- ;; Quit and move point back.
- ((= char ?x)
- (ispell-pdict-save ispell-silently-savep)
- (message "Exited spell-checking")
- (setq ispell-quit t)
- nil)
- ;; Quit and preserve point.
- ((= char ?X)
- (ispell-pdict-save ispell-silently-savep)
- (message
- (substitute-command-keys
- (concat "Spell-checking suspended;"
- " use C-u \\[ispell-word] to resume")))
- (setq ispell-quit (max (point-min)
- (- (point) (length word))))
- nil)
- ((= char ?q)
- (if (y-or-n-p "Really kill Ispell process? ")
- (progn
- (ispell-kill-ispell t) ; terminate process.
- (setq ispell-quit (or (not ispell-checking-message)
- (point))
- ispell-pdict-modified-p nil))
- t)) ; continue if they don't quit.
- ((= char ?l)
- (let ((new-word (read-string
- "Lookup string (`*' is wildcard): "
- word))
- (new-line 2))
- (if new-word
+ (ispell-kill-ispell t) ; terminate process.
+ (setq ispell-quit (or (not ispell-checking-message)
+ (point))
+ ispell-pdict-modified-p nil))
+ t)) ; continue if they don't quit.
+ ((= char ?l)
+ (let ((new-word (read-string
+ "Lookup string (`*' is wildcard): "
+ word))
+ (new-line 2))
+ (if new-word
+ (progn
+ (save-excursion
+ (set-buffer (get-buffer-create
+ ispell-choices-buffer))
+ (erase-buffer)
+ (setq count ?0
+ skipped 0
+ mode-line-format "-- %b --"
+ miss (lookup-words new-word)
+ choices miss)
+ (while (and choices ; adjust choices window.
+ (< (if (> (+ 7 (current-column)
+ (length (car choices))
+ (if (> count ?~) 3 0))
+ (window-width))
+ (progn
+ (insert "\n")
+ (setq new-line
+ (1+ new-line)))
+ new-line)
+ max-lines))
+ (while (memq count command-characters)
+ (setq count (1+ count)
+ skipped (1+ skipped)))
+ (insert "(" count ") " (car choices) " ")
+ (setq choices (cdr choices)
+ count (1+ count)))
+ (setq count (- count ?0 skipped)))
+ (select-window (previous-window))
+ (if (/= new-line line)
(progn
- (save-excursion
- (set-buffer (get-buffer-create
- ispell-choices-buffer))
- (erase-buffer)
- (setq count ?0
- skipped 0
- mode-line-format "-- %b --"
- miss (lookup-words new-word)
- choices miss)
- (while (and choices ; adjust choices window.
- (< (if (> (+ 7 (current-column)
- (length (car choices))
- (if (> count ?~) 3 0))
- (window-width))
- (progn
- (insert "\n")
- (setq new-line
- (1+ new-line)))
- new-line)
- max-lines))
- (while (memq count command-characters)
- (setq count (1+ count)
- skipped (1+ skipped)))
- (insert "(" count ") " (car choices) " ")
- (setq choices (cdr choices)
- count (1+ count)))
- (setq count (- count ?0 skipped)))
- (select-window (previous-window))
- (if (/= new-line line)
- (progn
- (if (> new-line line)
- (enlarge-window (- new-line line))
- (shrink-window (- line new-line)))
- (setq line new-line)))
- (select-window (next-window)))))
- t) ; reselect from new choices
- ((= char ?u)
- (process-send-string ispell-process
- (concat "*" (downcase word) "\n"))
- (setq ispell-pdict-modified-p '(t)) ; dictionary modified!
- nil)
- ((= char ?m) ; type in what to insert
- (process-send-string
- ispell-process (concat "*" (read-string "Insert: " word)
- "\n"))
- (setq ispell-pdict-modified-p '(t))
- (cons word nil))
- ((and (>= num 0) (< num count))
- (if ispell-query-replace-choices ; Query replace flag
- (list (nth num miss) 'query-replace)
- (nth num miss)))
- ((= char ?\C-l)
- (redraw-display) t)
- ((= char ?\C-r)
- (save-window-excursion (recursive-edit)) t)
- ((= char ?\C-z)
- (funcall (key-binding "\C-z"))
- t)
- (t (ding) t))))))
- result))
- (if (not ispell-keep-choices-win) (bury-buffer ispell-choices-buffer))))
+ (if (> new-line line)
+ (enlarge-window (- new-line line))
+ (shrink-window (- line new-line)))
+ (setq line new-line)))
+ (select-window (next-window)))))
+ t) ; reselect from new choices
+ ((= char ?u)
+ (process-send-string ispell-process
+ (concat "*" (downcase word) "\n"))
+ (setq ispell-pdict-modified-p '(t)) ; dictionary modified!
+ nil)
+ ((= char ?m) ; type in what to insert
+ (process-send-string
+ ispell-process (concat "*" (read-string "Insert: " word)
+ "\n"))
+ (setq ispell-pdict-modified-p '(t))
+ (cons word nil))
+ ((and (>= num 0) (< num count))
+ (if ispell-query-replace-choices ; Query replace flag
+ (list (nth num miss) 'query-replace)
+ (nth num miss)))
+ ((= char ?\C-l)
+ (redraw-display) t)
+ ((= char ?\C-r)
+ (save-window-excursion (recursive-edit)) t)
+ ((= char ?\C-z)
+ (funcall (key-binding "\C-z"))
+ t)
+ (t (ding) t))))))
+ result))
+
;;;###autoload
@@ -1313,7 +1305,7 @@ The variable `ispell-highlight-face' selects the face to use for highlighting."
(defun ispell-overlay-window (height)
"Create a window covering the top HEIGHT lines of the current window.
Ensure that the line above point is still visible but otherwise avoid
-scrolling the current window. Leave the old window selected."
+scrolling the current window. Leave the new window selected."
(save-excursion
(let ((oldot (save-excursion (forward-line -1) (point)))
(top (save-excursion (move-to-window-line height) (point))))
@@ -1541,27 +1533,9 @@ With prefix argument, set the default directory."
(message "Spell checking %s..."
(if (and (= reg-start (point-min)) (= reg-end (point-max)))
(buffer-name) "region"))
- (sit-for 0)
+;Eliminated to keep ispell-message displaying each piece: (sit-for 0)
;; must be top level, not in ispell-command-loop for keeping window.
(save-window-excursion
- (if ispell-keep-choices-win
- (let ((ocb (current-buffer))
- (window-min-height ispell-choices-win-default-height))
- (or (eq ocb (window-buffer (selected-window)))
- (error
- "current buffer is not visible in selected window: %s"
- ocb))
- ;; This keeps the default window size when choices window saved
- (setq ispell-keep-choices-win
- ispell-choices-win-default-height)
- (ispell-overlay-window ispell-choices-win-default-height)
- (switch-to-buffer (get-buffer-create ispell-choices-buffer))
- (setq mode-line-format "-- %b --")
- (erase-buffer)
- (select-window (next-window))
- (or (eq (current-buffer) ocb)
- (error "ispell is confused about current buffer!"))
- (sit-for 0)))
(goto-char reg-start)
(let ((transient-mark-mode nil))
(while (and (not ispell-quit) (< (point) reg-end))
@@ -1672,10 +1646,18 @@ With prefix argument, set the default directory."
(ispell-highlight-spelling-error
word-start word-end t))
(sit-for 0) ; update screen display
- (setq replace (ispell-command-loop
- (car (cdr (cdr poss)))
- (car (cdr (cdr (cdr poss))))
- (car poss))))
+ (if ispell-keep-choices-win
+ (setq replace
+ (ispell-command-loop
+ (car (cdr (cdr poss)))
+ (car (cdr (cdr (cdr poss))))
+ (car poss)))
+ (save-window-excursion
+ (setq replace
+ (ispell-command-loop
+ (car (cdr (cdr poss)))
+ (car (cdr (cdr (cdr poss))))
+ (car poss))))))
;; protected
(if ispell-highlight-p
(ispell-highlight-spelling-error
@@ -1815,7 +1797,6 @@ Standard ispell choices are then available."
(interactive "P")
(let ((cursor-location (point))
case-fold-search
- ispell-keep-choices-win
(word (ispell-get-word nil "\\*")) ; force "previous-word" processing.
start end possibilities replacement)
(setq start (car (cdr word))
@@ -1841,8 +1822,9 @@ Standard ispell choices are then available."
(progn
(if ispell-highlight-p ; highlight word
(ispell-highlight-spelling-error start end t))
- (setq replacement
- (ispell-command-loop possibilities nil word)))
+ (save-window-excursion
+ (setq replacement
+ (ispell-command-loop possibilities nil word))))
;; protected
(if ispell-highlight-p
(ispell-highlight-spelling-error start end))) ; un-highlight