aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1994-07-20 18:26:57 +0000
committerRichard M. Stallman1994-07-20 18:26:57 +0000
commit045dbcbc1d73435e19731a61f76eb72eefe9a2c1 (patch)
tree046845b7d6996eafd0d41f373fc64c3b0ef8c275
parent229b798613bfe3eac508601a71eaf40ceb60553e (diff)
downloademacs-045dbcbc1d73435e19731a61f76eb72eefe9a2c1.tar.gz
emacs-045dbcbc1d73435e19731a61f76eb72eefe9a2c1.zip
(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.
-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."
741 quietly ispell-quietly)) 741 quietly ispell-quietly))
742 (ispell-buffer-local-dict) ; use the correct dictionary 742 (ispell-buffer-local-dict) ; use the correct dictionary
743 (let ((cursor-location (point)) ; retain cursor location 743 (let ((cursor-location (point)) ; retain cursor location
744 ispell-keep-choices-win ; override global to force creation
745 (word (ispell-get-word following)) 744 (word (ispell-get-word following))
746 start end poss replace) 745 start end poss replace)
747 ;; destructure return word info list. 746 ;; destructure return word info list.
@@ -778,10 +777,11 @@ or \\[ispell-region] to update the Ispell process."
778 (progn 777 (progn
779 (if ispell-highlight-p ;highlight word 778 (if ispell-highlight-p ;highlight word
780 (ispell-highlight-spelling-error start end t)) 779 (ispell-highlight-spelling-error start end t))
781 (setq replace (ispell-command-loop 780 (save-window-excursion
782 (car (cdr (cdr poss))) 781 (setq replace (ispell-command-loop
783 (car (cdr (cdr (cdr poss)))) 782 (car (cdr (cdr poss)))
784 (car poss)))) 783 (car (cdr (cdr (cdr poss))))
784 (car poss)))))
785 ;; protected 785 ;; protected
786 (if ispell-highlight-p ; clear highlight 786 (if ispell-highlight-p ; clear highlight
787 (ispell-highlight-spelling-error start end))) 787 (ispell-highlight-spelling-error start end)))
@@ -889,214 +889,206 @@ Returns list for new replacement word (will be rechecked).
889Global `ispell-pdict-modified-p' becomes a list where the only value 889Global `ispell-pdict-modified-p' becomes a list where the only value
890indicates whether the dictionary has been modified when option `a' or `i' is 890indicates whether the dictionary has been modified when option `a' or `i' is
891used." 891used."
892 (unwind-protect 892 (let ((count ?0)
893 (save-window-excursion 893 (line 2)
894 (let ((count ?0) 894 (max-lines (- (window-height) 4)) ; assure 4 context lines.
895 (line 2) 895 (choices miss)
896 (max-lines (- (window-height) 4)) ; assure 4 context lines. 896 (window-min-height (min window-min-height
897 (choices miss) 897 ispell-choices-win-default-height))
898 (window-min-height (min window-min-height 898 (command-characters '( ? ?i ?a ?A ?r ?R ?? ?x ?X ?q ?l ?u ?m ))
899 ispell-choices-win-default-height)) 899 (skipped 0)
900 (command-characters '( ? ?i ?a ?A ?r ?R ?? ?x ?X ?q ?l ?u ?m )) 900 char num result)
901 (skipped 0) 901 (save-excursion
902 char num result) 902 (set-buffer (get-buffer-create ispell-choices-buffer))
903 (save-excursion 903 (setq mode-line-format "-- %b --")
904 (if ispell-keep-choices-win 904 (erase-buffer)
905 (if guess
906 (progn
907 (insert "Affix rules generate and capitalize "
908 "this word as shown below:\n\t")
909 (while guess
910 (if (> (+ 4 (current-column) (length (car guess)))
911 (window-width))
912 (progn
913 (insert "\n\t")
914 (setq line (1+ line))))
915 (insert (car guess) " ")
916 (setq guess (cdr guess)))
917 (insert "\nUse option `i' if this is a correct composition"
918 " from the derivative root.\n")
919 (setq line (+ line (if choices 3 2)))))
920 (while (and choices
921 (< (if (> (+ 7 (current-column) (length (car choices))
922 (if (> count ?~) 3 0))
923 (window-width))
924 (progn
925 (insert "\n")
926 (setq line (1+ line)))
927 line)
928 max-lines))
929 ;; not so good if there are over 20 or 30 options, but then, if
930 ;; there are that many you don't want to scan them all anyway...
931 (while (memq count command-characters) ; skip command characters.
932 (setq count (1+ count)
933 skipped (1+ skipped)))
934 (insert "(" count ") " (car choices) " ")
935 (setq choices (cdr choices)
936 count (1+ count)))
937 (setq count (- count ?0 skipped)))
938
939 (let ((choices-window (get-buffer-window ispell-choices-buffer)))
940 (if choices-window
941 (if (not (equal line (window-height choices-window)))
942 (progn
943 (save-excursion
944 (let ((cur-point (point)))
945 (move-to-window-line (- line (window-height choices-window)))
946 (if (<= (point) cur-point)
947 (set-window-start (selected-window) (point)))))
905 (select-window (previous-window)) 948 (select-window (previous-window))
906 (set-buffer (get-buffer-create ispell-choices-buffer)) 949 (enlarge-window (- line (window-height choices-window))))
907 (setq mode-line-format "-- %b --")) 950 (select-window choices-window))
908 (if (equal (get-buffer ispell-choices-buffer) (current-buffer)) 951 (ispell-overlay-window (max line
909 (erase-buffer) 952 ispell-choices-win-default-height))
910 (error (concat "Bogus, dude! I should be in the *Choices*" 953 (switch-to-buffer ispell-choices-buffer)))
911 " buffer, but I'm not!"))) 954 (goto-char (point-min))
912 (if guess 955 (select-window (next-window))
913 (progn 956 (while
914 (insert "Affix rules generate and capitalize " 957 (eq
915 "this word as shown below:\n\t") 958 t
916 (while guess 959 (setq
917 (if (> (+ 4 (current-column) (length (car guess))) 960 result
918 (window-width)) 961 (progn
919 (progn 962 (undo-boundary)
920 (insert "\n\t") 963 (message (concat "C-h or ? for more options; SPC to leave "
921 (setq line (1+ line)))) 964 "unchanged, Character to replace word"))
922 (insert (car guess) " ") 965 (let ((inhibit-quit t))
923 (setq guess (cdr guess))) 966 (setq char (if (fboundp 'read-char-exclusive)
924 (insert "\nUse option `i' if this is a correct composition" 967 (read-char-exclusive)
925 " from the derivative root.\n") 968 (read-char))
926 (setq line (+ line (if choices 3 2))))) 969 skipped 0)
927 (while (and choices 970 (if (or quit-flag (= char ?\C-g)) ; C-g is like typing X
928 (< (if (> (+ 7 (current-column) (length (car choices)) 971 (setq char ?X
929 (if (> count ?~) 3 0)) 972 quit-flag nil)))
930 (window-width)) 973 ;; Adjust num to array offset skipping command characters.
931 (progn 974 (let ((com-chars command-characters))
932 (insert "\n") 975 (while com-chars
933 (setq line (1+ line))) 976 (if (and (> (car com-chars) ?0) (< (car com-chars) char))
934 line) 977 (setq skipped (1+ skipped)))
935 max-lines)) 978 (setq com-chars (cdr com-chars)))
936 ;; not so good if there are over 20 or 30 options, but then, if 979 (setq num (- char ?0 skipped)))
937 ;; there are that many you don't want to scan them all anyway... 980
938 (while (memq count command-characters) ; skip command characters. 981 (cond
939 (setq count (1+ count) 982 ((= char ? ) nil) ; accept word this time only
940 skipped (1+ skipped))) 983 ((= char ?i) ; accept and insert word into pers dict
941 (insert "(" count ") " (car choices) " ") 984 (process-send-string ispell-process (concat "*" word "\n"))
942 (setq choices (cdr choices) 985 (setq ispell-pdict-modified-p '(t)) ; dictionary modified!
943 count (1+ count))) 986 nil)
944 (setq count (- count ?0 skipped))) 987 ((or (= char ?a) (= char ?A)) ; accept word without insert
945 988 (process-send-string ispell-process (concat "@" word "\n"))
946 (if ispell-keep-choices-win 989 (if (null ispell-pdict-modified-p)
947 (if (> line ispell-keep-choices-win) 990 (setq ispell-pdict-modified-p
991 (list ispell-pdict-modified-p)))
992 (if (= char ?A) 0)) ; return 0 for ispell-add buffer-local
993 ((or (= char ?r) (= char ?R)) ; type in replacement
994 (if (or (= char ?R) ispell-query-replace-choices)
995 (list (read-string "Query-replacement for: " word) t)
996 (cons (read-string "Replacement for: " word) nil)))
997 ((or (= char ??) (= char help-char) (= char ?\C-h))
998 (ispell-help)
999 t)
1000 ;; Quit and move point back.
1001 ((= char ?x)
1002 (ispell-pdict-save ispell-silently-savep)
1003 (message "Exited spell-checking")
1004 (setq ispell-quit t)
1005 nil)
1006 ;; Quit and preserve point.
1007 ((= char ?X)
1008 (ispell-pdict-save ispell-silently-savep)
1009 (message
1010 (substitute-command-keys
1011 (concat "Spell-checking suspended;"
1012 " use C-u \\[ispell-word] to resume")))
1013 (setq ispell-quit (max (point-min)
1014 (- (point) (length word))))
1015 nil)
1016 ((= char ?q)
1017 (if (y-or-n-p "Really kill Ispell process? ")
948 (progn 1018 (progn
949 (switch-to-buffer ispell-choices-buffer) 1019 (ispell-kill-ispell t) ; terminate process.
950 (select-window (next-window)) 1020 (setq ispell-quit (or (not ispell-checking-message)
951 (save-excursion 1021 (point))
952 (let ((cur-point (point))) 1022 ispell-pdict-modified-p nil))
953 (move-to-window-line (- line ispell-keep-choices-win)) 1023 t)) ; continue if they don't quit.
954 (if (<= (point) cur-point) 1024 ((= char ?l)
955 (set-window-start (selected-window) (point))))) 1025 (let ((new-word (read-string
956 (select-window (previous-window)) 1026 "Lookup string (`*' is wildcard): "
957 (enlarge-window (- line ispell-keep-choices-win)) 1027 word))
958 (goto-char (point-min)))) 1028 (new-line 2))
959 (ispell-overlay-window (max line 1029 (if new-word
960 ispell-choices-win-default-height))) 1030 (progn
961 (switch-to-buffer ispell-choices-buffer) 1031 (save-excursion
962 (goto-char (point-min)) 1032 (set-buffer (get-buffer-create
963 (select-window (next-window)) 1033 ispell-choices-buffer))
964 (while 1034 (erase-buffer)
965 (eq 1035 (setq count ?0
966 t 1036 skipped 0
967 (setq 1037 mode-line-format "-- %b --"
968 result 1038 miss (lookup-words new-word)
969 (progn 1039 choices miss)
970 (undo-boundary) 1040 (while (and choices ; adjust choices window.
971 (message (concat "C-h or ? for more options; SPC to leave " 1041 (< (if (> (+ 7 (current-column)
972 "unchanged, Character to replace word")) 1042 (length (car choices))
973 (let ((inhibit-quit t)) 1043 (if (> count ?~) 3 0))
974 (setq char (if (fboundp 'read-char-exclusive) 1044 (window-width))
975 (read-char-exclusive) 1045 (progn
976 (read-char)) 1046 (insert "\n")
977 skipped 0) 1047 (setq new-line
978 (if (or quit-flag (= char ?\C-g)) ; C-g is like typing X 1048 (1+ new-line)))
979 (setq char ?X 1049 new-line)
980 quit-flag nil))) 1050 max-lines))
981 ;; Adjust num to array offset skipping command characters. 1051 (while (memq count command-characters)
982 (let ((com-chars command-characters)) 1052 (setq count (1+ count)
983 (while com-chars 1053 skipped (1+ skipped)))
984 (if (and (> (car com-chars) ?0) (< (car com-chars) char)) 1054 (insert "(" count ") " (car choices) " ")
985 (setq skipped (1+ skipped))) 1055 (setq choices (cdr choices)
986 (setq com-chars (cdr com-chars))) 1056 count (1+ count)))
987 (setq num (- char ?0 skipped))) 1057 (setq count (- count ?0 skipped)))
988 1058 (select-window (previous-window))
989 (cond 1059 (if (/= new-line line)
990 ((= char ? ) nil) ; accept word this time only
991 ((= char ?i) ; accept and insert word into pers dict
992 (process-send-string ispell-process (concat "*" word "\n"))
993 (setq ispell-pdict-modified-p '(t)) ; dictionary modified!
994 nil)
995 ((or (= char ?a) (= char ?A)) ; accept word without insert
996 (process-send-string ispell-process (concat "@" word "\n"))
997 (if (null ispell-pdict-modified-p)
998 (setq ispell-pdict-modified-p
999 (list ispell-pdict-modified-p)))
1000 (if (= char ?A) 0)) ; return 0 for ispell-add buffer-local
1001 ((or (= char ?r) (= char ?R)) ; type in replacement
1002 (if (or (= char ?R) ispell-query-replace-choices)
1003 (list (read-string "Query-replacement for: " word) t)
1004 (cons (read-string "Replacement for: " word) nil)))
1005 ((or (= char ??) (= char help-char) (= char ?\C-h))
1006 (ispell-help)
1007 t)
1008 ;; Quit and move point back.
1009 ((= char ?x)
1010 (ispell-pdict-save ispell-silently-savep)
1011 (message "Exited spell-checking")
1012 (setq ispell-quit t)
1013 nil)
1014 ;; Quit and preserve point.
1015 ((= char ?X)
1016 (ispell-pdict-save ispell-silently-savep)
1017 (message
1018 (substitute-command-keys
1019 (concat "Spell-checking suspended;"
1020 " use C-u \\[ispell-word] to resume")))
1021 (setq ispell-quit (max (point-min)
1022 (- (point) (length word))))
1023 nil)
1024 ((= char ?q)
1025 (if (y-or-n-p "Really kill Ispell process? ")
1026 (progn
1027 (ispell-kill-ispell t) ; terminate process.
1028 (setq ispell-quit (or (not ispell-checking-message)
1029 (point))
1030 ispell-pdict-modified-p nil))
1031 t)) ; continue if they don't quit.
1032 ((= char ?l)
1033 (let ((new-word (read-string
1034 "Lookup string (`*' is wildcard): "
1035 word))
1036 (new-line 2))
1037 (if new-word
1038 (progn 1060 (progn
1039 (save-excursion 1061 (if (> new-line line)
1040 (set-buffer (get-buffer-create 1062 (enlarge-window (- new-line line))
1041 ispell-choices-buffer)) 1063 (shrink-window (- line new-line)))
1042 (erase-buffer) 1064 (setq line new-line)))
1043 (setq count ?0 1065 (select-window (next-window)))))
1044 skipped 0 1066 t) ; reselect from new choices
1045 mode-line-format "-- %b --" 1067 ((= char ?u)
1046 miss (lookup-words new-word) 1068 (process-send-string ispell-process
1047 choices miss) 1069 (concat "*" (downcase word) "\n"))
1048 (while (and choices ; adjust choices window. 1070 (setq ispell-pdict-modified-p '(t)) ; dictionary modified!
1049 (< (if (> (+ 7 (current-column) 1071 nil)
1050 (length (car choices)) 1072 ((= char ?m) ; type in what to insert
1051 (if (> count ?~) 3 0)) 1073 (process-send-string
1052 (window-width)) 1074 ispell-process (concat "*" (read-string "Insert: " word)
1053 (progn 1075 "\n"))
1054 (insert "\n") 1076 (setq ispell-pdict-modified-p '(t))
1055 (setq new-line 1077 (cons word nil))
1056 (1+ new-line))) 1078 ((and (>= num 0) (< num count))
1057 new-line) 1079 (if ispell-query-replace-choices ; Query replace flag
1058 max-lines)) 1080 (list (nth num miss) 'query-replace)
1059 (while (memq count command-characters) 1081 (nth num miss)))
1060 (setq count (1+ count) 1082 ((= char ?\C-l)
1061 skipped (1+ skipped))) 1083 (redraw-display) t)
1062 (insert "(" count ") " (car choices) " ") 1084 ((= char ?\C-r)
1063 (setq choices (cdr choices) 1085 (save-window-excursion (recursive-edit)) t)
1064 count (1+ count))) 1086 ((= char ?\C-z)
1065 (setq count (- count ?0 skipped))) 1087 (funcall (key-binding "\C-z"))
1066 (select-window (previous-window)) 1088 t)
1067 (if (/= new-line line) 1089 (t (ding) t))))))
1068 (progn 1090 result))
1069 (if (> new-line line) 1091
1070 (enlarge-window (- new-line line))
1071 (shrink-window (- line new-line)))
1072 (setq line new-line)))
1073 (select-window (next-window)))))
1074 t) ; reselect from new choices
1075 ((= char ?u)
1076 (process-send-string ispell-process
1077 (concat "*" (downcase word) "\n"))
1078 (setq ispell-pdict-modified-p '(t)) ; dictionary modified!
1079 nil)
1080 ((= char ?m) ; type in what to insert
1081 (process-send-string
1082 ispell-process (concat "*" (read-string "Insert: " word)
1083 "\n"))
1084 (setq ispell-pdict-modified-p '(t))
1085 (cons word nil))
1086 ((and (>= num 0) (< num count))
1087 (if ispell-query-replace-choices ; Query replace flag
1088 (list (nth num miss) 'query-replace)
1089 (nth num miss)))
1090 ((= char ?\C-l)
1091 (redraw-display) t)
1092 ((= char ?\C-r)
1093 (save-window-excursion (recursive-edit)) t)
1094 ((= char ?\C-z)
1095 (funcall (key-binding "\C-z"))
1096 t)
1097 (t (ding) t))))))
1098 result))
1099 (if (not ispell-keep-choices-win) (bury-buffer ispell-choices-buffer))))
1100 1092
1101 1093
1102;;;###autoload 1094;;;###autoload
@@ -1313,7 +1305,7 @@ The variable `ispell-highlight-face' selects the face to use for highlighting."
1313(defun ispell-overlay-window (height) 1305(defun ispell-overlay-window (height)
1314 "Create a window covering the top HEIGHT lines of the current window. 1306 "Create a window covering the top HEIGHT lines of the current window.
1315Ensure that the line above point is still visible but otherwise avoid 1307Ensure that the line above point is still visible but otherwise avoid
1316scrolling the current window. Leave the old window selected." 1308scrolling the current window. Leave the new window selected."
1317 (save-excursion 1309 (save-excursion
1318 (let ((oldot (save-excursion (forward-line -1) (point))) 1310 (let ((oldot (save-excursion (forward-line -1) (point)))
1319 (top (save-excursion (move-to-window-line height) (point)))) 1311 (top (save-excursion (move-to-window-line height) (point))))
@@ -1541,27 +1533,9 @@ With prefix argument, set the default directory."
1541 (message "Spell checking %s..." 1533 (message "Spell checking %s..."
1542 (if (and (= reg-start (point-min)) (= reg-end (point-max))) 1534 (if (and (= reg-start (point-min)) (= reg-end (point-max)))
1543 (buffer-name) "region")) 1535 (buffer-name) "region"))
1544 (sit-for 0) 1536;Eliminated to keep ispell-message displaying each piece: (sit-for 0)
1545 ;; must be top level, not in ispell-command-loop for keeping window. 1537 ;; must be top level, not in ispell-command-loop for keeping window.
1546 (save-window-excursion 1538 (save-window-excursion
1547 (if ispell-keep-choices-win
1548 (let ((ocb (current-buffer))
1549 (window-min-height ispell-choices-win-default-height))
1550 (or (eq ocb (window-buffer (selected-window)))
1551 (error
1552 "current buffer is not visible in selected window: %s"
1553 ocb))
1554 ;; This keeps the default window size when choices window saved
1555 (setq ispell-keep-choices-win
1556 ispell-choices-win-default-height)
1557 (ispell-overlay-window ispell-choices-win-default-height)
1558 (switch-to-buffer (get-buffer-create ispell-choices-buffer))
1559 (setq mode-line-format "-- %b --")
1560 (erase-buffer)
1561 (select-window (next-window))
1562 (or (eq (current-buffer) ocb)
1563 (error "ispell is confused about current buffer!"))
1564 (sit-for 0)))
1565 (goto-char reg-start) 1539 (goto-char reg-start)
1566 (let ((transient-mark-mode nil)) 1540 (let ((transient-mark-mode nil))
1567 (while (and (not ispell-quit) (< (point) reg-end)) 1541 (while (and (not ispell-quit) (< (point) reg-end))
@@ -1672,10 +1646,18 @@ With prefix argument, set the default directory."
1672 (ispell-highlight-spelling-error 1646 (ispell-highlight-spelling-error
1673 word-start word-end t)) 1647 word-start word-end t))
1674 (sit-for 0) ; update screen display 1648 (sit-for 0) ; update screen display
1675 (setq replace (ispell-command-loop 1649 (if ispell-keep-choices-win
1676 (car (cdr (cdr poss))) 1650 (setq replace
1677 (car (cdr (cdr (cdr poss)))) 1651 (ispell-command-loop
1678 (car poss)))) 1652 (car (cdr (cdr poss)))
1653 (car (cdr (cdr (cdr poss))))
1654 (car poss)))
1655 (save-window-excursion
1656 (setq replace
1657 (ispell-command-loop
1658 (car (cdr (cdr poss)))
1659 (car (cdr (cdr (cdr poss))))
1660 (car poss))))))
1679 ;; protected 1661 ;; protected
1680 (if ispell-highlight-p 1662 (if ispell-highlight-p
1681 (ispell-highlight-spelling-error 1663 (ispell-highlight-spelling-error
@@ -1815,7 +1797,6 @@ Standard ispell choices are then available."
1815 (interactive "P") 1797 (interactive "P")
1816 (let ((cursor-location (point)) 1798 (let ((cursor-location (point))
1817 case-fold-search 1799 case-fold-search
1818 ispell-keep-choices-win
1819 (word (ispell-get-word nil "\\*")) ; force "previous-word" processing. 1800 (word (ispell-get-word nil "\\*")) ; force "previous-word" processing.
1820 start end possibilities replacement) 1801 start end possibilities replacement)
1821 (setq start (car (cdr word)) 1802 (setq start (car (cdr word))
@@ -1841,8 +1822,9 @@ Standard ispell choices are then available."
1841 (progn 1822 (progn
1842 (if ispell-highlight-p ; highlight word 1823 (if ispell-highlight-p ; highlight word
1843 (ispell-highlight-spelling-error start end t)) 1824 (ispell-highlight-spelling-error start end t))
1844 (setq replacement 1825 (save-window-excursion
1845 (ispell-command-loop possibilities nil word))) 1826 (setq replacement
1827 (ispell-command-loop possibilities nil word))))
1846 ;; protected 1828 ;; protected
1847 (if ispell-highlight-p 1829 (if ispell-highlight-p
1848 (ispell-highlight-spelling-error start end))) ; un-highlight 1830 (ispell-highlight-spelling-error start end))) ; un-highlight