aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1993-12-23 03:39:27 +0000
committerRichard M. Stallman1993-12-23 03:39:27 +0000
commitd637fa567905eb4aa550c611af2aefee7215a567 (patch)
tree944676491e8680e379e5608a686e111b970c7326
parente9681c45f9ffd2819410b763338ba58b0b892b78 (diff)
downloademacs-d637fa567905eb4aa550c611af2aefee7215a567.tar.gz
emacs-d637fa567905eb4aa550c611af2aefee7215a567.zip
(comint-read-input-ring): New arg SILENT.
(comint-replace-by-expanded-history): New arg SILENT. (comint-send-input): Pass t as new arg. (comint-mode-map): Put comint-show-output on C-M-l. (comint-preinput-scroll-to-bottom): Removed calls to window-minibuffer-p and 'not-minibuf arg to walk-windows. Removed mouse-yank-at-click from command list and doc string. Removed duplicate test for comint-scroll-to-bottom-on-input (scroll). Removed test for 'this within walk-windows code. (comint-postoutput-scroll-to-bottom): Don't select a different buffer permanently. (comint-prompt-regexp): Fixed documentation. (comint-replace-by-expanded-history): Use skip-chars-forward to advance in main loop.
-rw-r--r--lisp/comint.el119
1 files changed, 67 insertions, 52 deletions
diff --git a/lisp/comint.el b/lisp/comint.el
index 8d8c0623a76..fff0f077246 100644
--- a/lisp/comint.el
+++ b/lisp/comint.el
@@ -67,7 +67,7 @@
67;;; m-n comint-next-input Cycle forwards 67;;; m-n comint-next-input Cycle forwards
68;;; m-r comint-previous-matching-input Previous input matching a regexp 68;;; m-r comint-previous-matching-input Previous input matching a regexp
69;;; m-s comint-next-matching-input Next input that matches 69;;; m-s comint-next-matching-input Next input that matches
70;;; m-c-r comint-previous-input-matching Search backwards in input history 70;;; m-c-l comint-show-output Show last batch of process output
71;;; return comint-send-input 71;;; return comint-send-input
72;;; c-a comint-bol Beginning of line; skip prompt 72;;; c-a comint-bol Beginning of line; skip prompt
73;;; c-d comint-delchar-or-maybe-eof Delete char unless at end of buff 73;;; c-d comint-delchar-or-maybe-eof Delete char unless at end of buff
@@ -138,11 +138,11 @@
138Defaults to \"^\", the null string at BOL. 138Defaults to \"^\", the null string at BOL.
139 139
140Good choices: 140Good choices:
141 Canonical Lisp: \"^[^> ]*>+:? *\" (Lucid, franz, kcl, T, cscheme, oaklisp) 141 Canonical Lisp: \"^[^> \\n]*>+:? *\" (Lucid, franz, kcl, T, cscheme, oaklisp)
142 Lucid Common Lisp: \"^\\\\(>\\\\|\\\\(->\\\\)+\\\\) *\" 142 Lucid Common Lisp: \"^\\\\(>\\\\|\\\\(->\\\\)+\\\\) *\"
143 franz: \"^\\\\(->\\\\|<[0-9]*>:\\\\) *\" 143 franz: \"^\\\\(->\\\\|<[0-9]*>:\\\\) *\"
144 kcl: \"^>+ *\" 144 kcl: \"^>+ *\"
145 shell: \"^[^#$%>]*[#$%>] *\" 145 shell: \"^[^#$%>\\n]*[#$%>] *\"
146 T: \"^>+ *\" 146 T: \"^>+ *\"
147 147
148This is a good thing to set in mode hooks.") 148This is a good thing to set in mode hooks.")
@@ -406,6 +406,7 @@ Entry to this mode runs the hooks on `comint-mode-hook'."
406 (define-key comint-mode-map "\es" 'comint-next-matching-input) 406 (define-key comint-mode-map "\es" 'comint-next-matching-input)
407 (define-key comint-mode-map [?\A-\M-r] 'comint-previous-matching-input-from-input) 407 (define-key comint-mode-map [?\A-\M-r] 'comint-previous-matching-input-from-input)
408 (define-key comint-mode-map [?\A-\M-s] 'comint-next-matching-input-from-input) 408 (define-key comint-mode-map [?\A-\M-s] 'comint-next-matching-input-from-input)
409 (define-key comint-mode-map "\e\C-l" 'comint-show-output)
409 (define-key comint-mode-map "\C-m" 'comint-send-input) 410 (define-key comint-mode-map "\C-m" 'comint-send-input)
410 (define-key comint-mode-map "\C-d" 'comint-delchar-or-maybe-eof) 411 (define-key comint-mode-map "\C-d" 'comint-delchar-or-maybe-eof)
411 (define-key comint-mode-map "\C-a" 'comint-bol) 412 (define-key comint-mode-map "\C-a" 'comint-bol)
@@ -600,22 +601,27 @@ buffer. The hook `comint-exec-hook' is run after each exec."
600;;; comint-read-input-ring Read into comint-input-ring... 601;;; comint-read-input-ring Read into comint-input-ring...
601;;; comint-write-input-ring Write to comint-input-ring-file-name. 602;;; comint-write-input-ring Write to comint-input-ring-file-name.
602 603
603(defun comint-read-input-ring () 604(defun comint-read-input-ring (&optional silent)
604 "Sets the buffer's `comint-input-ring' from a history file. 605 "Sets the buffer's `comint-input-ring' from a history file.
605The name of the file is given by the variable `comint-input-ring-file-name'. 606The name of the file is given by the variable `comint-input-ring-file-name'.
606The history ring is of size `comint-input-ring-size', regardless of file size. 607The history ring is of size `comint-input-ring-size', regardless of file size.
607If `comint-input-ring-file-name' is nil this function does nothing. 608If `comint-input-ring-file-name' is nil this function does nothing.
608 609
609Useful within mode or mode hooks. 610If the optional argument SILENT is non-nil, we say nothing about a
611failure to read the history file.
610 612
611The structure of the history file should be one input command per line, and 613This function is useful for major mode commands and mode hooks.
612most recent command last. 614
615The structure of the history file should be one input command per line,
616with the most recent command last.
613See also `comint-input-ignoredups' and `comint-write-input-ring'." 617See also `comint-input-ignoredups' and `comint-write-input-ring'."
614 (cond ((or (null comint-input-ring-file-name) 618 (cond ((or (null comint-input-ring-file-name)
615 (equal comint-input-ring-file-name "")) 619 (equal comint-input-ring-file-name ""))
616 nil) 620 nil)
617 ((not (file-readable-p comint-input-ring-file-name)) 621 ((not (file-readable-p comint-input-ring-file-name))
618 (message "Cannot read history file %s" comint-input-ring-file-name)) 622 (or silent
623 (message "Cannot read history file %s"
624 comint-input-ring-file-name)))
619 (t 625 (t
620 (let ((history-buf (get-file-buffer comint-input-ring-file-name)) 626 (let ((history-buf (get-file-buffer comint-input-ring-file-name))
621 (ring (make-ring comint-input-ring-size))) 627 (ring (make-ring comint-input-ring-size)))
@@ -845,7 +851,7 @@ If N is negative, find the next or Nth next match."
845 (comint-previous-matching-input-from-input (- arg))) 851 (comint-previous-matching-input-from-input (- arg)))
846 852
847 853
848(defun comint-replace-by-expanded-history () 854(defun comint-replace-by-expanded-history (&optional silent)
849 "Expand input command history references before point. 855 "Expand input command history references before point.
850This function depends on the buffer's idea of the input history, which may not 856This function depends on the buffer's idea of the input history, which may not
851match the command interpreter's idea, assuming it has one. 857match the command interpreter's idea, assuming it has one.
@@ -854,13 +860,21 @@ Assumes history syntax is like typical Un*x shells'. However, since emacs
854cannot know the interpreter's idea of input line numbers, assuming it has one, 860cannot know the interpreter's idea of input line numbers, assuming it has one,
855it cannot expand absolute input line number references. 861it cannot expand absolute input line number references.
856 862
863If the optional argument SILENT is non-nil, never complain
864even if history reference seems erroneous.
865
857See also `comint-magic-space'." 866See also `comint-magic-space'."
858 (interactive) 867 (interactive)
859 (save-excursion 868 (save-excursion
860 (let ((toend (- (save-excursion (end-of-line nil) (point)) (point))) 869 (let ((toend (- (save-excursion (end-of-line nil) (point)) (point)))
861 (start (progn (comint-bol nil) (point)))) 870 (start (progn (comint-bol nil) (point))))
862 (while (re-search-forward 871 (while (progn
863 "[!^]" (save-excursion (end-of-line nil) (- (point) toend)) t) 872 (skip-chars-forward "^!^"
873 (save-excursion
874 (end-of-line nil) (- (point) toend)))
875 (< (point)
876 (save-excursion
877 (end-of-line nil) (- (point) toend))))
864 ;; This seems a bit complex. We look for references such as !!, !-num, 878 ;; This seems a bit complex. We look for references such as !!, !-num,
865 ;; !foo, !?foo, !{bar}, !?{bar}, ^oh, ^my^, ^god^it, ^never^ends^. 879 ;; !foo, !?foo, !{bar}, !?{bar}, ^oh, ^my^, ^god^it, ^never^ends^.
866 ;; If that wasn't enough, the plings can be suffixed with argument 880 ;; If that wasn't enough, the plings can be suffixed with argument
@@ -868,11 +882,10 @@ See also `comint-magic-space'."
868 ;; Argument ranges are complex too, so we hive off the input line, 882 ;; Argument ranges are complex too, so we hive off the input line,
869 ;; referenced with plings, with the range string to `comint-args'. 883 ;; referenced with plings, with the range string to `comint-args'.
870 (setq comint-input-ring-index nil) 884 (setq comint-input-ring-index nil)
871 (goto-char (match-beginning 0))
872 (cond ((or (= (preceding-char) ?\\) 885 (cond ((or (= (preceding-char) ?\\)
873 (comint-within-quotes start (point))) 886 (comint-within-quotes start (point)))
874 ;; The history is quoted, or we're in quotes. 887 ;; The history is quoted, or we're in quotes.
875 (goto-char (match-end 0))) 888 (goto-char (1+ (point))))
876 ((looking-at "![0-9]+\\($\\|[^-]\\)") 889 ((looking-at "![0-9]+\\($\\|[^-]\\)")
877 ;; We cannot know the interpreter's idea of input line numbers. 890 ;; We cannot know the interpreter's idea of input line numbers.
878 (goto-char (match-end 0)) 891 (goto-char (match-end 0))
@@ -908,9 +921,10 @@ See also `comint-magic-space'."
908 (comint-previous-matching-input-string-position 921 (comint-previous-matching-input-string-position
909 (concat pref (regexp-quote exp)) 1)))) 922 (concat pref (regexp-quote exp)) 1))))
910 (if (null pos) 923 (if (null pos)
911 (progn (message "Not found") 924 (or silent
912 (goto-char (match-end 0)) 925 (progn (message "Not found")
913 (ding)) 926 (goto-char (match-end 0))
927 (ding)))
914 (setq comint-input-ring-index pos) 928 (setq comint-input-ring-index pos)
915 (message "History item: %d" (1+ pos)) 929 (message "History item: %d" (1+ pos))
916 (replace-match 930 (replace-match
@@ -927,8 +941,10 @@ See also `comint-magic-space'."
927 (goto-char (match-beginning 0)) 941 (goto-char (match-beginning 0))
928 (if (search-forward old pos t) 942 (if (search-forward old pos t)
929 (replace-match new t t) 943 (replace-match new t t)
930 (message "Not found") 944 (or silent
931 (ding)))) 945 (progn
946 (message "Not found")
947 (ding))))))
932 (t 948 (t
933 (goto-char (match-end 0)))))))) 949 (goto-char (match-end 0))))))))
934 950
@@ -1078,14 +1094,14 @@ Similarly for Soar, Scheme, etc."
1078 ;; Just whatever's already there 1094 ;; Just whatever's already there
1079 intxt 1095 intxt
1080 ;; Expand and leave it visible in buffer 1096 ;; Expand and leave it visible in buffer
1081 (comint-replace-by-expanded-history) 1097 (comint-replace-by-expanded-history t)
1082 (buffer-substring pmark (point)))) 1098 (buffer-substring pmark (point))))
1083 (history (if (not (eq comint-input-autoexpand 'history)) 1099 (history (if (not (eq comint-input-autoexpand 'history))
1084 input 1100 input
1085 ;; This is messy 'cos ultimately the original 1101 ;; This is messy 'cos ultimately the original
1086 ;; functions used do insertion, rather than return 1102 ;; functions used do insertion, rather than return
1087 ;; strings. We have to expand, then insert back. 1103 ;; strings. We have to expand, then insert back.
1088 (comint-replace-by-expanded-history) 1104 (comint-replace-by-expanded-history t)
1089 (let ((copy (buffer-substring pmark (point)))) 1105 (let ((copy (buffer-substring pmark (point))))
1090 (delete-region pmark (point)) 1106 (delete-region pmark (point))
1091 (insert input) 1107 (insert input)
@@ -1164,32 +1180,29 @@ Similarly for Soar, Scheme, etc."
1164 "Go to the end of buffer in all windows showing it. 1180 "Go to the end of buffer in all windows showing it.
1165Movement occurs if point in the selected window is not after the process mark, 1181Movement occurs if point in the selected window is not after the process mark,
1166and `this-command' is an insertion command. Insertion commands recognised 1182and `this-command' is an insertion command. Insertion commands recognised
1167are `self-insert-command', `comint-magic-space', `yank', `mouse-yank-at-click', 1183are `self-insert-command', `comint-magic-space', `yank', and `hilit-yank'.
1168and `hilit-yank'.
1169Depends on the value of `comint-scroll-to-bottom-on-input'. 1184Depends on the value of `comint-scroll-to-bottom-on-input'.
1170 1185
1171This function should be a pre-command hook." 1186This function should be a pre-command hook."
1172 (if (and comint-scroll-to-bottom-on-input 1187 (if (and comint-scroll-to-bottom-on-input
1173 (memq this-command '(self-insert-command comint-magic-space yank 1188 (memq this-command '(self-insert-command comint-magic-space yank
1174 mouse-yank-at-click hilit-yank))) 1189 hilit-yank)))
1175 (let* ((selected (selected-window)) 1190 (let* ((selected (selected-window))
1176 (current (current-buffer)) 1191 (current (current-buffer))
1177 (process (get-buffer-process current)) 1192 (process (get-buffer-process current))
1178 (scroll comint-scroll-to-bottom-on-input)) 1193 (scroll comint-scroll-to-bottom-on-input))
1179 (if (and process (< (point) (process-mark process)) 1194 (if (and process (< (point) (process-mark process)))
1180 scroll (not (window-minibuffer-p selected)))
1181 (if (eq scroll 'this) 1195 (if (eq scroll 'this)
1182 (goto-char (point-max)) 1196 (goto-char (point-max))
1183 (walk-windows 1197 (walk-windows
1184 (function (lambda (window) 1198 (function (lambda (window)
1185 (if (and (eq (window-buffer window) current) 1199 (if (and (eq (window-buffer window) current)
1186 (or (eq scroll t) (eq scroll 'all) 1200 (or (eq scroll t) (eq scroll 'all)))
1187 (and (eq scroll 'this) (eq selected window))))
1188 (progn 1201 (progn
1189 (select-window window) 1202 (select-window window)
1190 (goto-char (point-max)) 1203 (goto-char (point-max))
1191 (select-window selected))))) 1204 (select-window selected)))))
1192 'not-minibuf t)))))) 1205 nil t))))))
1193 1206
1194(defun comint-postoutput-scroll-to-bottom (string) 1207(defun comint-postoutput-scroll-to-bottom (string)
1195 "Go to the end of buffer in all windows showing it. 1208 "Go to the end of buffer in all windows showing it.
@@ -1202,30 +1215,32 @@ This function should be in the list `comint-output-filter-functions'."
1202 (current (current-buffer)) 1215 (current (current-buffer))
1203 (process (get-buffer-process current)) 1216 (process (get-buffer-process current))
1204 (scroll comint-scroll-to-bottom-on-output)) 1217 (scroll comint-scroll-to-bottom-on-output))
1205 (if process 1218 (unwind-protect
1206 (walk-windows 1219 (if process
1207 (function (lambda (window) 1220 (walk-windows
1208 (if (eq (window-buffer window) current) 1221 (function (lambda (window)
1209 (progn 1222 (if (eq (window-buffer window) current)
1210 (select-window window) 1223 (progn
1211 (if (and (< (point) (process-mark process)) 1224 (select-window window)
1212 (or (eq scroll t) (eq scroll 'all) 1225 (if (and (< (point) (process-mark process))
1213 ;; Maybe user wants point to jump to the end. 1226 (or (eq scroll t) (eq scroll 'all)
1214 (and (eq scroll 'this) (eq selected window)) 1227 ;; Maybe user wants point to jump to the end.
1215 (and (eq scroll 'others) (not (eq selected window))) 1228 (and (eq scroll 'this) (eq selected window))
1216 ;; If point was at the end, keep it at the end. 1229 (and (eq scroll 'others) (not (eq selected window)))
1217 (>= (point) 1230 ;; If point was at the end, keep it at the end.
1218 (- (process-mark process) (length string))))) 1231 (>= (point)
1219 (goto-char (process-mark process))) 1232 (- (process-mark process) (length string)))))
1220 ;; Optionally scroll so that the text 1233 (goto-char (process-mark process)))
1221 ;; ends at the bottom of the window. 1234 ;; Optionally scroll so that the text
1222 (if (and comint-scroll-show-maximum-output 1235 ;; ends at the bottom of the window.
1223 (>= (point) (process-mark process))) 1236 (if (and comint-scroll-show-maximum-output
1224 (save-excursion 1237 (>= (point) (process-mark process)))
1225 (goto-char (point-max)) 1238 (save-excursion
1226 (recenter -1))) 1239 (goto-char (point-max))
1227 (select-window selected))))) 1240 (recenter -1)))
1228 nil t)))) 1241 (select-window selected)))))
1242 nil t))
1243 (set-buffer current))))
1229 1244
1230(defun comint-show-maximum-output () 1245(defun comint-show-maximum-output ()
1231 "Put the end of the buffer at the bottom of the window." 1246 "Put the end of the buffer at the bottom of the window."