diff options
| author | Richard M. Stallman | 1998-05-27 21:06:56 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1998-05-27 21:06:56 +0000 |
| commit | 361ecbf2ee0246033ffe9ebf0f4b30d0b150c891 (patch) | |
| tree | f3a3c33c51f7c55978a8b4c5103871d225376ca3 | |
| parent | 77fb89636c5edaafa99a3cda6757b05dc2bb4541 (diff) | |
| download | emacs-361ecbf2ee0246033ffe9ebf0f4b30d0b150c891.tar.gz emacs-361ecbf2ee0246033ffe9ebf0f4b30d0b150c891.zip | |
(comint-get-next-from-history): New command.
(comint-accumulate, comint-goto-process-mark): Likewise.
(comint-set-process-mark, comint-bol-or-process-mark): Likewise.
(comint-save-input-ring-index): New permanent local var.
(comint-accum-marker): Likewise.
(comint-send-input): Clear comint-input-ring-index
and comint-accum-marker.
(comint-previous-matching-input-from-input):
Use comint-accum-marker if set.
(comint-previous-matching-input): Likewise.
(comint-mode): Make those vars buffer-local and initialize.
(comint-mode-map): Make C-c C-a run comint-bol-or-process-mark.
Bind C-c SPC to comint-accumulate. Bind C-c C-q to
comint-get-next-from-history.
| -rw-r--r-- | lisp/comint.el | 106 |
1 files changed, 98 insertions, 8 deletions
diff --git a/lisp/comint.el b/lisp/comint.el index 3da9fd1d8a9..f486c7c29ae 100644 --- a/lisp/comint.el +++ b/lisp/comint.el | |||
| @@ -65,14 +65,15 @@ | |||
| 65 | ;; Comint Mode Commands: (common to all derived modes, like shell & cmulisp | 65 | ;; Comint Mode Commands: (common to all derived modes, like shell & cmulisp |
| 66 | ;; mode) | 66 | ;; mode) |
| 67 | ;; | 67 | ;; |
| 68 | ;; m-p comint-previous-input Cycle backwards in input history | 68 | ;; m-p comint-previous-input Cycle backwards in input history |
| 69 | ;; m-n comint-next-input Cycle forwards | 69 | ;; m-n comint-next-input Cycle forwards |
| 70 | ;; m-r comint-previous-matching-input Previous input matching a regexp | 70 | ;; m-r comint-previous-matching-input Previous input matching a regexp |
| 71 | ;; m-s comint-next-matching-input Next input that matches | 71 | ;; m-s comint-next-matching-input Next input that matches |
| 72 | ;; m-c-l comint-show-output Show last batch of process output | 72 | ;; m-c-l comint-show-output Show last batch of process output |
| 73 | ;; return comint-send-input | 73 | ;; return comint-send-input |
| 74 | ;; c-d comint-delchar-or-maybe-eof Delete char unless at end of buff | 74 | ;; c-d comint-delchar-or-maybe-eof Delete char unless at end of buff |
| 75 | ;; c-c c-a comint-bol Beginning of line; skip prompt | 75 | ;; c-c c-a comint-bol-or-process-mark First time, move point to bol; |
| 76 | ;; second time, move to process-mark. | ||
| 76 | ;; c-c c-u comint-kill-input ^u | 77 | ;; c-c c-u comint-kill-input ^u |
| 77 | ;; c-c c-w backward-kill-word ^w | 78 | ;; c-c c-w backward-kill-word ^w |
| 78 | ;; c-c c-c comint-interrupt-subjob ^c | 79 | ;; c-c c-c comint-interrupt-subjob ^c |
| @@ -98,6 +99,11 @@ | |||
| 98 | ;; comint-continue-subjob Send CONT signal to buffer's process | 99 | ;; comint-continue-subjob Send CONT signal to buffer's process |
| 99 | ;; group. Useful if you accidentally | 100 | ;; group. Useful if you accidentally |
| 100 | ;; suspend your process (with C-c C-z). | 101 | ;; suspend your process (with C-c C-z). |
| 102 | ;; comint-get-next-from-history Fetch successive input history lines | ||
| 103 | ;; comint-accumulate Combine lines to send them together | ||
| 104 | ;; as input. | ||
| 105 | ;; comint-goto-process-mark Move point to where process-mark is. | ||
| 106 | ;; comint-set-process-mark Set process-mark to point. | ||
| 101 | 107 | ||
| 102 | ;; comint-mode-hook is the comint mode hook. Basically for your keybindings. | 108 | ;; comint-mode-hook is the comint mode hook. Basically for your keybindings. |
| 103 | 109 | ||
| @@ -115,6 +121,7 @@ | |||
| 115 | ;; comint-input-ring-size integer For the input history | 121 | ;; comint-input-ring-size integer For the input history |
| 116 | ;; comint-input-ring ring mechanism | 122 | ;; comint-input-ring ring mechanism |
| 117 | ;; comint-input-ring-index number ... | 123 | ;; comint-input-ring-index number ... |
| 124 | ;; comint-save-input-ring-index number ... | ||
| 118 | ;; comint-input-autoexpand symbol ... | 125 | ;; comint-input-autoexpand symbol ... |
| 119 | ;; comint-input-ignoredups boolean ... | 126 | ;; comint-input-ignoredups boolean ... |
| 120 | ;; comint-last-input-match string ... | 127 | ;; comint-last-input-match string ... |
| @@ -133,6 +140,7 @@ | |||
| 133 | ;; comint-scroll-to-bottom-on-input symbol For scroll behavior | 140 | ;; comint-scroll-to-bottom-on-input symbol For scroll behavior |
| 134 | ;; comint-scroll-to-bottom-on-output symbol ... | 141 | ;; comint-scroll-to-bottom-on-output symbol ... |
| 135 | ;; comint-scroll-show-maximum-output boolean ... | 142 | ;; comint-scroll-show-maximum-output boolean ... |
| 143 | ;; comint-accum-marker maker For comint-accumulate | ||
| 136 | ;; | 144 | ;; |
| 137 | ;; Comint mode non-buffer local variables: | 145 | ;; Comint mode non-buffer local variables: |
| 138 | ;; comint-completion-addsuffix boolean/cons For file name | 146 | ;; comint-completion-addsuffix boolean/cons For file name |
| @@ -359,10 +367,18 @@ This is to work around a bug in Emacs process signaling.") | |||
| 359 | "Index of last matched history element.") | 367 | "Index of last matched history element.") |
| 360 | (defvar comint-matching-input-from-input-string "" | 368 | (defvar comint-matching-input-from-input-string "" |
| 361 | "Input previously used to match input history.") | 369 | "Input previously used to match input history.") |
| 370 | (defvar comint-save-input-ring-index | ||
| 371 | "Last input ring index which you copied. | ||
| 372 | This is to support the command \\[comint-get-next-from-history].") | ||
| 373 | |||
| 374 | (defvar comint-accum-marker nil | ||
| 375 | "Non-nil if you are accumulating input lines to send as input together. | ||
| 376 | The command \\[comint-accumulate] sets this.") | ||
| 362 | 377 | ||
| 363 | (put 'comint-replace-by-expanded-history 'menu-enable 'comint-input-autoexpand) | 378 | (put 'comint-replace-by-expanded-history 'menu-enable 'comint-input-autoexpand) |
| 364 | (put 'comint-input-ring 'permanent-local t) | 379 | (put 'comint-input-ring 'permanent-local t) |
| 365 | (put 'comint-input-ring-index 'permanent-local t) | 380 | (put 'comint-input-ring-index 'permanent-local t) |
| 381 | (put 'comint-save-input-ring-index 'permanent-local t) | ||
| 366 | (put 'comint-input-autoexpand 'permanent-local t) | 382 | (put 'comint-input-autoexpand 'permanent-local t) |
| 367 | (put 'comint-input-filter-functions 'permanent-local t) | 383 | (put 'comint-input-filter-functions 'permanent-local t) |
| 368 | (put 'comint-output-filter-functions 'permanent-local t) | 384 | (put 'comint-output-filter-functions 'permanent-local t) |
| @@ -432,8 +448,11 @@ Entry to this mode runs the hooks on `comint-mode-hook'." | |||
| 432 | (or (and (boundp 'comint-input-ring) comint-input-ring) | 448 | (or (and (boundp 'comint-input-ring) comint-input-ring) |
| 433 | (setq comint-input-ring (make-ring comint-input-ring-size))) | 449 | (setq comint-input-ring (make-ring comint-input-ring-size))) |
| 434 | (make-local-variable 'comint-input-ring-index) | 450 | (make-local-variable 'comint-input-ring-index) |
| 451 | (make-local-variable 'comint-save-input-ring-index) | ||
| 435 | (or (and (boundp 'comint-input-ring-index) comint-input-ring-index) | 452 | (or (and (boundp 'comint-input-ring-index) comint-input-ring-index) |
| 436 | (setq comint-input-ring-index nil)) | 453 | (setq comint-input-ring-index nil)) |
| 454 | (or (and (boundp 'comint-save-input-ring-index) comint-save-input-ring-index) | ||
| 455 | (setq comint-save-input-ring-index nil)) | ||
| 437 | (make-local-variable 'comint-matching-input-from-input-string) | 456 | (make-local-variable 'comint-matching-input-from-input-string) |
| 438 | (make-local-variable 'comint-input-autoexpand) | 457 | (make-local-variable 'comint-input-autoexpand) |
| 439 | (make-local-variable 'comint-input-ignoredups) | 458 | (make-local-variable 'comint-input-ignoredups) |
| @@ -456,6 +475,9 @@ Entry to this mode runs the hooks on `comint-mode-hook'." | |||
| 456 | (make-local-variable 'comint-process-echoes) | 475 | (make-local-variable 'comint-process-echoes) |
| 457 | (make-local-variable 'comint-file-name-chars) | 476 | (make-local-variable 'comint-file-name-chars) |
| 458 | (make-local-variable 'comint-file-name-quote-list) | 477 | (make-local-variable 'comint-file-name-quote-list) |
| 478 | (make-local-variable 'comint-accum-marker) | ||
| 479 | (setq comint-accum-marker (make-marker)) | ||
| 480 | (set-marker comint-accum-marker nil) | ||
| 459 | (run-hooks 'comint-mode-hook)) | 481 | (run-hooks 'comint-mode-hook)) |
| 460 | 482 | ||
| 461 | (if comint-mode-map | 483 | (if comint-mode-map |
| @@ -473,7 +495,9 @@ Entry to this mode runs the hooks on `comint-mode-hook'." | |||
| 473 | (define-key comint-mode-map "\e\C-l" 'comint-show-output) | 495 | (define-key comint-mode-map "\e\C-l" 'comint-show-output) |
| 474 | (define-key comint-mode-map "\C-m" 'comint-send-input) | 496 | (define-key comint-mode-map "\C-m" 'comint-send-input) |
| 475 | (define-key comint-mode-map "\C-d" 'comint-delchar-or-maybe-eof) | 497 | (define-key comint-mode-map "\C-d" 'comint-delchar-or-maybe-eof) |
| 476 | (define-key comint-mode-map "\C-c\C-a" 'comint-bol) | 498 | (define-key comint-mode-map "\C-c " 'comint-accumulate) |
| 499 | (define-key comint-mode-map "\C-c\C-q" 'comint-get-next-from-history) | ||
| 500 | (define-key comint-mode-map "\C-c\C-a" 'comint-bol-or-process-mark) | ||
| 477 | (define-key comint-mode-map "\C-c\C-u" 'comint-kill-input) | 501 | (define-key comint-mode-map "\C-c\C-u" 'comint-kill-input) |
| 478 | (define-key comint-mode-map "\C-c\C-w" 'backward-kill-word) | 502 | (define-key comint-mode-map "\C-c\C-w" 'backward-kill-word) |
| 479 | (define-key comint-mode-map "\C-c\C-c" 'comint-interrupt-subjob) | 503 | (define-key comint-mode-map "\C-c\C-c" 'comint-interrupt-subjob) |
| @@ -897,7 +921,9 @@ If N is negative, find the next or Nth next match." | |||
| 897 | (message "History item: %d" (1+ pos)) | 921 | (message "History item: %d" (1+ pos)) |
| 898 | (delete-region | 922 | (delete-region |
| 899 | ;; Can't use kill-region as it sets this-command | 923 | ;; Can't use kill-region as it sets this-command |
| 900 | (process-mark (get-buffer-process (current-buffer))) (point)) | 924 | (or (marker-position comint-accum-marker) |
| 925 | (process-mark (get-buffer-process (current-buffer)))) | ||
| 926 | (point)) | ||
| 901 | (insert (ring-ref comint-input-ring pos))))) | 927 | (insert (ring-ref comint-input-ring pos))))) |
| 902 | 928 | ||
| 903 | (defun comint-next-matching-input (regexp arg) | 929 | (defun comint-next-matching-input (regexp arg) |
| @@ -919,7 +945,8 @@ If N is negative, search forwards for the -Nth following match." | |||
| 919 | ;; Starting a new search | 945 | ;; Starting a new search |
| 920 | (setq comint-matching-input-from-input-string | 946 | (setq comint-matching-input-from-input-string |
| 921 | (buffer-substring | 947 | (buffer-substring |
| 922 | (process-mark (get-buffer-process (current-buffer))) | 948 | (or (marker-position comint-accum-marker) |
| 949 | (process-mark (get-buffer-process (current-buffer)))) | ||
| 923 | (point)) | 950 | (point)) |
| 924 | comint-input-ring-index nil)) | 951 | comint-input-ring-index nil)) |
| 925 | (comint-previous-matching-input | 952 | (comint-previous-matching-input |
| @@ -1255,12 +1282,15 @@ Similarly for Soar, Scheme, etc." | |||
| 1255 | (ring-insert comint-input-ring history)) | 1282 | (ring-insert comint-input-ring history)) |
| 1256 | (run-hook-with-args 'comint-input-filter-functions | 1283 | (run-hook-with-args 'comint-input-filter-functions |
| 1257 | (concat input "\n")) | 1284 | (concat input "\n")) |
| 1285 | (setq comint-save-input-ring-index comint-input-ring-index) | ||
| 1258 | (setq comint-input-ring-index nil) | 1286 | (setq comint-input-ring-index nil) |
| 1259 | ;; Update the markers before we send the input | 1287 | ;; Update the markers before we send the input |
| 1260 | ;; in case we get output amidst sending the input. | 1288 | ;; in case we get output amidst sending the input. |
| 1261 | (set-marker comint-last-input-start pmark) | 1289 | (set-marker comint-last-input-start pmark) |
| 1262 | (set-marker comint-last-input-end (point)) | 1290 | (set-marker comint-last-input-end (point)) |
| 1263 | (set-marker (process-mark proc) (point)) | 1291 | (set-marker (process-mark proc) (point)) |
| 1292 | ;; clear the "accumulation" marker | ||
| 1293 | (set-marker comint-accum-marker nil) | ||
| 1264 | (funcall comint-input-sender proc input) | 1294 | (funcall comint-input-sender proc input) |
| 1265 | ;; This used to call comint-output-filter-functions, | 1295 | ;; This used to call comint-output-filter-functions, |
| 1266 | ;; but that scrolled the buffer in undesirable ways. | 1296 | ;; but that scrolled the buffer in undesirable ways. |
| @@ -2241,6 +2271,66 @@ Typing SPC flushes the help buffer." | |||
| 2241 | (set-window-configuration conf) | 2271 | (set-window-configuration conf) |
| 2242 | (setq unread-command-events (listify-key-sequence key))))))) | 2272 | (setq unread-command-events (listify-key-sequence key))))))) |
| 2243 | 2273 | ||
| 2274 | (defun comint-get-next-from-history () | ||
| 2275 | "After fetching a line from input history, this fetches the following line. | ||
| 2276 | In other words, this recalls the input line after the line you recalled last. | ||
| 2277 | You can use this to repeat a sequence of input lines." | ||
| 2278 | (interactive) | ||
| 2279 | (if comint-save-input-ring-index | ||
| 2280 | (progn | ||
| 2281 | (setq comint-input-ring-index (1+ comint-save-input-ring-index)) | ||
| 2282 | (comint-next-input 1)) | ||
| 2283 | (message "No previous history command"))) | ||
| 2284 | |||
| 2285 | (defun comint-accumulate () | ||
| 2286 | "Accumulate a line to send as input along with more lines. | ||
| 2287 | This inserts a newline so that you can enter more text | ||
| 2288 | to be sent along with this line. Use \\[comint-send-input] | ||
| 2289 | to send all the accumulated input, at once. | ||
| 2290 | The entire accumulated text becomes one item in the input history | ||
| 2291 | when you send it." | ||
| 2292 | (interactive) | ||
| 2293 | (insert "\n") | ||
| 2294 | (set-marker comint-accum-marker (point)) | ||
| 2295 | (if comint-input-ring-index | ||
| 2296 | (setq comint-save-input-ring-index | ||
| 2297 | (- comint-input-ring-index 1)))) | ||
| 2298 | |||
| 2299 | (defun comint-goto-process-mark () | ||
| 2300 | "Move point to the process mark. | ||
| 2301 | The process mark separates output, and input already sent, | ||
| 2302 | from input that has not yet been sent." | ||
| 2303 | (interactive) | ||
| 2304 | (let ((proc (or (get-buffer-process (current-buffer)) | ||
| 2305 | (error "Current buffer has no process")))) | ||
| 2306 | (goto-char (process-mark proc)) | ||
| 2307 | (message "Point is now at the process mark"))) | ||
| 2308 | |||
| 2309 | (defun comint-bol-or-process-mark () | ||
| 2310 | "Move point beginning of line (after prompt) or to the process mark. | ||
| 2311 | The first time you use this command, it moves to the beginning of the line | ||
| 2312 | \(but after the prompt, if any). If you repeat it again immediately, | ||
| 2313 | it moves point to the process mark. | ||
| 2314 | |||
| 2315 | The process mark separates the process output, along with input already sent, | ||
| 2316 | from input that has not yet been sent. Ordinarily, the process mark | ||
| 2317 | is at the beginning of the current input line; but if you have | ||
| 2318 | used \\[comint-accumulate] to send multiple lines at once, | ||
| 2319 | the process mark is at the beginning of the accumulated input." | ||
| 2320 | (interactive) | ||
| 2321 | (if (not (eq last-command 'comint-bol-or-mark)) | ||
| 2322 | (comint-bol nil) | ||
| 2323 | (comint-goto-process-mark))) | ||
| 2324 | |||
| 2325 | (defun comint-set-process-mark () | ||
| 2326 | "Set the process mark at point." | ||
| 2327 | (interactive) | ||
| 2328 | (let ((proc (or (get-buffer-process (current-buffer)) | ||
| 2329 | (error "Current buffer has no process")))) | ||
| 2330 | (set-marker (process-mark proc) (point)) | ||
| 2331 | (message "Process mark set"))) | ||
| 2332 | |||
| 2333 | |||
| 2244 | ;; Converting process modes to use comint mode | 2334 | ;; Converting process modes to use comint mode |
| 2245 | ;; =========================================================================== | 2335 | ;; =========================================================================== |
| 2246 | ;; The code in the Emacs 19 distribution has all been modified to use comint | 2336 | ;; The code in the Emacs 19 distribution has all been modified to use comint |