aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/comint.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/comint.el')
-rw-r--r--lisp/comint.el257
1 files changed, 120 insertions, 137 deletions
diff --git a/lisp/comint.el b/lisp/comint.el
index 8b5a107c7d7..8b2c779ecd3 100644
--- a/lisp/comint.el
+++ b/lisp/comint.el
@@ -1,7 +1,7 @@
1;;; comint.el --- general command interpreter in a window stuff 1;;; comint.el --- general command interpreter in a window stuff
2 2
3;; Copyright (C) 1988,90,92,93,94,95,96,97,98,99,2000,01,02,03,2004 3;; Copyright (C) 1988, 1990, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4;; Free Software Foundation, Inc. 4;; 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
5 5
6;; Author: Olin Shivers <shivers@cs.cmu.edu> 6;; Author: Olin Shivers <shivers@cs.cmu.edu>
7;; Simon Marshall <simon@gnu.org> 7;; Simon Marshall <simon@gnu.org>
@@ -185,10 +185,10 @@ the remaining prompts will be accidentally messed up. You may
185wish to put something like the following in your `.emacs' file: 185wish to put something like the following in your `.emacs' file:
186 186
187\(add-hook 'comint-mode-hook 187\(add-hook 'comint-mode-hook
188 '(lambda () 188 (lambda ()
189 (define-key comint-mode-map \"\C-w\" 'comint-kill-region) 189 (define-key comint-mode-map \"\C-w\" 'comint-kill-region)
190 (define-key comint-mode-map [C-S-backspace] 190 (define-key comint-mode-map [C-S-backspace]
191 'comint-kill-whole-line))) 191 'comint-kill-whole-line)))
192 192
193If you sometimes use comint-mode on text-only terminals or with `emacs-nw', 193If you sometimes use comint-mode on text-only terminals or with `emacs-nw',
194you might wish to use another binding for `comint-kill-whole-line'." 194you might wish to use another binding for `comint-kill-whole-line'."
@@ -369,11 +369,8 @@ Takes one argument, the input. If non-nil, the input may be saved on the input
369history list. Default is to save anything that isn't all whitespace.") 369history list. Default is to save anything that isn't all whitespace.")
370 370
371(defvar comint-input-filter-functions '() 371(defvar comint-input-filter-functions '()
372 "Functions to call before input is sent to the process. 372 "Special hook run before input is sent to the process.
373These functions get one argument, a string containing the text to send. 373These functions get one argument, a string containing the text to send.")
374
375You can use `add-hook' to add functions to this list
376either globally or locally.")
377 374
378(defvar comint-output-filter-functions '(comint-postoutput-scroll-to-bottom) 375(defvar comint-output-filter-functions '(comint-postoutput-scroll-to-bottom)
379 "Functions to call after output is inserted into the buffer. 376 "Functions to call after output is inserted into the buffer.
@@ -411,7 +408,7 @@ See `comint-send-input'."
411(defcustom comint-use-prompt-regexp-instead-of-fields nil 408(defcustom comint-use-prompt-regexp-instead-of-fields nil
412 "*If non-nil, use `comint-prompt-regexp' to distinguish prompts from user-input. 409 "*If non-nil, use `comint-prompt-regexp' to distinguish prompts from user-input.
413If nil, then program output and user-input are given different `field' 410If nil, then program output and user-input are given different `field'
414properties, which emacs commands can use to distinguish them (in 411properties, which Emacs commands can use to distinguish them (in
415particular, common movement commands such as begining-of-line respect 412particular, common movement commands such as begining-of-line respect
416field boundaries in a natural way)." 413field boundaries in a natural way)."
417 :type 'boolean 414 :type 'boolean
@@ -432,7 +429,106 @@ executed once when the buffer is created."
432 :type 'hook 429 :type 'hook
433 :group 'comint) 430 :group 'comint)
434 431
435(defvar comint-mode-map nil) 432(defvar comint-mode-map
433 (let ((map (make-sparse-keymap)))
434 ;; Keys:
435 (define-key map "\ep" 'comint-previous-input)
436 (define-key map "\en" 'comint-next-input)
437 (define-key map [C-up] 'comint-previous-input)
438 (define-key map [C-down] 'comint-next-input)
439 (define-key map "\er" 'comint-previous-matching-input)
440 (define-key map "\es" 'comint-next-matching-input)
441 (define-key map [?\C-c ?\M-r] 'comint-previous-matching-input-from-input)
442 (define-key map [?\C-c ?\M-s] 'comint-next-matching-input-from-input)
443 (define-key map "\e\C-l" 'comint-show-output)
444 (define-key map "\C-m" 'comint-send-input)
445 (define-key map "\C-d" 'comint-delchar-or-maybe-eof)
446 (define-key map "\C-c " 'comint-accumulate)
447 (define-key map "\C-c\C-x" 'comint-get-next-from-history)
448 (define-key map "\C-c\C-a" 'comint-bol-or-process-mark)
449 (define-key map "\C-c\C-u" 'comint-kill-input)
450 (define-key map "\C-c\C-w" 'backward-kill-word)
451 (define-key map "\C-c\C-c" 'comint-interrupt-subjob)
452 (define-key map "\C-c\C-z" 'comint-stop-subjob)
453 (define-key map "\C-c\C-\\" 'comint-quit-subjob)
454 (define-key map "\C-c\C-m" 'comint-insert-input)
455 (define-key map "\C-c\C-o" 'comint-delete-output)
456 (define-key map "\C-c\C-r" 'comint-show-output)
457 (define-key map "\C-c\C-e" 'comint-show-maximum-output)
458 (define-key map "\C-c\C-l" 'comint-dynamic-list-input-ring)
459 (define-key map "\C-c\C-n" 'comint-next-prompt)
460 (define-key map "\C-c\C-p" 'comint-previous-prompt)
461 (define-key map "\C-c\C-d" 'comint-send-eof)
462 (define-key map "\C-c\C-s" 'comint-write-output)
463 (define-key map "\C-c." 'comint-insert-previous-argument)
464 ;; Mouse Buttons:
465 (define-key map [mouse-2] 'comint-insert-input)
466 ;; Menu bars:
467 ;; completion:
468 (define-key map [menu-bar completion]
469 (cons "Complete" (make-sparse-keymap "Complete")))
470 (define-key map [menu-bar completion complete-expand]
471 '("Expand File Name" . comint-replace-by-expanded-filename))
472 (define-key map [menu-bar completion complete-listing]
473 '("File Completion Listing" . comint-dynamic-list-filename-completions))
474 (define-key map [menu-bar completion complete-file]
475 '("Complete File Name" . comint-dynamic-complete-filename))
476 (define-key map [menu-bar completion complete]
477 '("Complete Before Point" . comint-dynamic-complete))
478 ;; Input history:
479 (define-key map [menu-bar inout]
480 (cons "In/Out" (make-sparse-keymap "In/Out")))
481 (define-key map [menu-bar inout delete-output]
482 '("Delete Current Output Group" . comint-delete-output))
483 (define-key map [menu-bar inout append-output-to-file]
484 '("Append Current Output Group to File" . comint-append-output-to-file))
485 (define-key map [menu-bar inout write-output]
486 '("Write Current Output Group to File" . comint-write-output))
487 (define-key map [menu-bar inout next-prompt]
488 '("Forward Output Group" . comint-next-prompt))
489 (define-key map [menu-bar inout previous-prompt]
490 '("Backward Output Group" . comint-previous-prompt))
491 (define-key map [menu-bar inout show-maximum-output]
492 '("Show Maximum Output" . comint-show-maximum-output))
493 (define-key map [menu-bar inout show-output]
494 '("Show Current Output Group" . comint-show-output))
495 (define-key map [menu-bar inout kill-input]
496 '("Kill Current Input" . comint-kill-input))
497 (define-key map [menu-bar inout copy-input]
498 '("Copy Old Input" . comint-insert-input))
499 (define-key map [menu-bar inout forward-matching-history]
500 '("Forward Matching Input..." . comint-forward-matching-input))
501 (define-key map [menu-bar inout backward-matching-history]
502 '("Backward Matching Input..." . comint-backward-matching-input))
503 (define-key map [menu-bar inout next-matching-history]
504 '("Next Matching Input..." . comint-next-matching-input))
505 (define-key map [menu-bar inout previous-matching-history]
506 '("Previous Matching Input..." . comint-previous-matching-input))
507 (define-key map [menu-bar inout next-matching-history-from-input]
508 '("Next Matching Current Input" . comint-next-matching-input-from-input))
509 (define-key map [menu-bar inout previous-matching-history-from-input]
510 '("Previous Matching Current Input" . comint-previous-matching-input-from-input))
511 (define-key map [menu-bar inout next-history]
512 '("Next Input" . comint-next-input))
513 (define-key map [menu-bar inout previous-history]
514 '("Previous Input" . comint-previous-input))
515 (define-key map [menu-bar inout list-history]
516 '("List Input History" . comint-dynamic-list-input-ring))
517 (define-key map [menu-bar inout expand-history]
518 '("Expand History Before Point" . comint-replace-by-expanded-history))
519 ;; Signals
520 (let ((signals-map (make-sparse-keymap "Signals")))
521 (define-key map [menu-bar signals] (cons "Signals" signals-map))
522 (define-key signals-map [eof] '("EOF" . comint-send-eof))
523 (define-key signals-map [kill] '("KILL" . comint-kill-subjob))
524 (define-key signals-map [quit] '("QUIT" . comint-quit-subjob))
525 (define-key signals-map [cont] '("CONT" . comint-continue-subjob))
526 (define-key signals-map [stop] '("STOP" . comint-stop-subjob))
527 (define-key signals-map [break] '("BREAK" . comint-interrupt-subjob)))
528 ;; Put them in the menu bar:
529 (setq menu-bar-final-items (append '(completion inout signals)
530 menu-bar-final-items))
531 map))
436 532
437;; Fixme: Is this still relevant? 533;; Fixme: Is this still relevant?
438(defvar comint-ptyp t 534(defvar comint-ptyp t
@@ -548,114 +644,6 @@ Entry to this mode runs the hooks on `comint-mode-hook'."
548 ;; This behavior is not useful in comint buffers, and is annoying 644 ;; This behavior is not useful in comint buffers, and is annoying
549 (set (make-local-variable 'next-line-add-newlines) nil)) 645 (set (make-local-variable 'next-line-add-newlines) nil))
550 646
551(if comint-mode-map
552 nil
553 ;; Keys:
554 (setq comint-mode-map (make-sparse-keymap))
555 (define-key comint-mode-map "\ep" 'comint-previous-input)
556 (define-key comint-mode-map "\en" 'comint-next-input)
557 (define-key comint-mode-map [C-up] 'comint-previous-input)
558 (define-key comint-mode-map [C-down] 'comint-next-input)
559 (define-key comint-mode-map "\er" 'comint-previous-matching-input)
560 (define-key comint-mode-map "\es" 'comint-next-matching-input)
561 (define-key comint-mode-map [?\C-c ?\M-r] 'comint-previous-matching-input-from-input)
562 (define-key comint-mode-map [?\C-c ?\M-s] 'comint-next-matching-input-from-input)
563 (define-key comint-mode-map "\e\C-l" 'comint-show-output)
564 (define-key comint-mode-map "\C-m" 'comint-send-input)
565 (define-key comint-mode-map "\C-d" 'comint-delchar-or-maybe-eof)
566 (define-key comint-mode-map "\C-c " 'comint-accumulate)
567 (define-key comint-mode-map "\C-c\C-x" 'comint-get-next-from-history)
568 (define-key comint-mode-map "\C-c\C-a" 'comint-bol-or-process-mark)
569 (define-key comint-mode-map "\C-c\C-u" 'comint-kill-input)
570 (define-key comint-mode-map "\C-c\C-w" 'backward-kill-word)
571 (define-key comint-mode-map "\C-c\C-c" 'comint-interrupt-subjob)
572 (define-key comint-mode-map "\C-c\C-z" 'comint-stop-subjob)
573 (define-key comint-mode-map "\C-c\C-\\" 'comint-quit-subjob)
574 (define-key comint-mode-map "\C-c\C-m" 'comint-insert-input)
575 (define-key comint-mode-map "\C-c\C-o" 'comint-delete-output)
576 (define-key comint-mode-map "\C-c\C-r" 'comint-show-output)
577 (define-key comint-mode-map "\C-c\C-e" 'comint-show-maximum-output)
578 (define-key comint-mode-map "\C-c\C-l" 'comint-dynamic-list-input-ring)
579 (define-key comint-mode-map "\C-c\C-n" 'comint-next-prompt)
580 (define-key comint-mode-map "\C-c\C-p" 'comint-previous-prompt)
581 (define-key comint-mode-map "\C-c\C-d" 'comint-send-eof)
582 (define-key comint-mode-map "\C-c\C-s" 'comint-write-output)
583 (define-key comint-mode-map "\C-c." 'comint-insert-previous-argument)
584 ;; Mouse Buttons:
585 (define-key comint-mode-map [mouse-2] 'comint-mouse-insert-input)
586 ;; Menu bars:
587 ;; completion:
588 (define-key comint-mode-map [menu-bar completion]
589 (cons "Complete" (make-sparse-keymap "Complete")))
590 (define-key comint-mode-map [menu-bar completion complete-expand]
591 '("Expand File Name" . comint-replace-by-expanded-filename))
592 (define-key comint-mode-map [menu-bar completion complete-listing]
593 '("File Completion Listing" . comint-dynamic-list-filename-completions))
594 (define-key comint-mode-map [menu-bar completion complete-file]
595 '("Complete File Name" . comint-dynamic-complete-filename))
596 (define-key comint-mode-map [menu-bar completion complete]
597 '("Complete Before Point" . comint-dynamic-complete))
598 ;; Input history:
599 (define-key comint-mode-map [menu-bar inout]
600 (cons "In/Out" (make-sparse-keymap "In/Out")))
601 (define-key comint-mode-map [menu-bar inout delete-output]
602 '("Delete Current Output Group" . comint-delete-output))
603 (define-key comint-mode-map [menu-bar inout append-output-to-file]
604 '("Append Current Output Group to File" . comint-append-output-to-file))
605 (define-key comint-mode-map [menu-bar inout write-output]
606 '("Write Current Output Group to File" . comint-write-output))
607 (define-key comint-mode-map [menu-bar inout next-prompt]
608 '("Forward Output Group" . comint-next-prompt))
609 (define-key comint-mode-map [menu-bar inout previous-prompt]
610 '("Backward Output Group" . comint-previous-prompt))
611 (define-key comint-mode-map [menu-bar inout show-maximum-output]
612 '("Show Maximum Output" . comint-show-maximum-output))
613 (define-key comint-mode-map [menu-bar inout show-output]
614 '("Show Current Output Group" . comint-show-output))
615 (define-key comint-mode-map [menu-bar inout kill-input]
616 '("Kill Current Input" . comint-kill-input))
617 (define-key comint-mode-map [menu-bar inout copy-input]
618 '("Copy Old Input" . comint-insert-input))
619 (define-key comint-mode-map [menu-bar inout forward-matching-history]
620 '("Forward Matching Input..." . comint-forward-matching-input))
621 (define-key comint-mode-map [menu-bar inout backward-matching-history]
622 '("Backward Matching Input..." . comint-backward-matching-input))
623 (define-key comint-mode-map [menu-bar inout next-matching-history]
624 '("Next Matching Input..." . comint-next-matching-input))
625 (define-key comint-mode-map [menu-bar inout previous-matching-history]
626 '("Previous Matching Input..." . comint-previous-matching-input))
627 (define-key comint-mode-map [menu-bar inout next-matching-history-from-input]
628 '("Next Matching Current Input" . comint-next-matching-input-from-input))
629 (define-key comint-mode-map [menu-bar inout previous-matching-history-from-input]
630 '("Previous Matching Current Input" . comint-previous-matching-input-from-input))
631 (define-key comint-mode-map [menu-bar inout next-history]
632 '("Next Input" . comint-next-input))
633 (define-key comint-mode-map [menu-bar inout previous-history]
634 '("Previous Input" . comint-previous-input))
635 (define-key comint-mode-map [menu-bar inout list-history]
636 '("List Input History" . comint-dynamic-list-input-ring))
637 (define-key comint-mode-map [menu-bar inout expand-history]
638 '("Expand History Before Point" . comint-replace-by-expanded-history))
639 ;; Signals
640 (define-key comint-mode-map [menu-bar signals]
641 (cons "Signals" (make-sparse-keymap "Signals")))
642 (define-key comint-mode-map [menu-bar signals eof]
643 '("EOF" . comint-send-eof))
644 (define-key comint-mode-map [menu-bar signals kill]
645 '("KILL" . comint-kill-subjob))
646 (define-key comint-mode-map [menu-bar signals quit]
647 '("QUIT" . comint-quit-subjob))
648 (define-key comint-mode-map [menu-bar signals cont]
649 '("CONT" . comint-continue-subjob))
650 (define-key comint-mode-map [menu-bar signals stop]
651 '("STOP" . comint-stop-subjob))
652 (define-key comint-mode-map [menu-bar signals break]
653 '("BREAK" . comint-interrupt-subjob))
654 ;; Put them in the menu bar:
655 (setq menu-bar-final-items (append '(completion inout signals)
656 menu-bar-final-items))
657 )
658
659(defun comint-check-proc (buffer) 647(defun comint-check-proc (buffer)
660 "Return t if there is a living process associated w/buffer BUFFER. 648 "Return t if there is a living process associated w/buffer BUFFER.
661Living means the status is `open', `run', or `stop'. 649Living means the status is `open', `run', or `stop'.
@@ -798,9 +786,10 @@ buffer. The hook `comint-exec-hook' is run after each exec."
798 (set-process-coding-system proc decoding encoding)) 786 (set-process-coding-system proc decoding encoding))
799 proc)) 787 proc))
800 788
801(defun comint-insert-input () 789(defun comint-insert-input (&optional event)
802 "In a Comint buffer, set the current input to the previous input at point." 790 "In a Comint buffer, set the current input to the previous input at point."
803 (interactive) 791 (interactive (list last-input-event))
792 (if event (mouse-set-point event))
804 (let ((pos (point))) 793 (let ((pos (point)))
805 (if (not (eq (get-char-property pos 'field) 'input)) 794 (if (not (eq (get-char-property pos 'field) 'input))
806 ;; No input at POS, fall back to the global definition. 795 ;; No input at POS, fall back to the global definition.
@@ -818,13 +807,7 @@ buffer. The hook `comint-exec-hook' is run after each exec."
818 ;; Insert the input at point 807 ;; Insert the input at point
819 (insert (buffer-substring-no-properties 808 (insert (buffer-substring-no-properties
820 (previous-single-char-property-change (1+ pos) 'field) 809 (previous-single-char-property-change (1+ pos) 'field)
821 (next-single-char-property-change pos 'field)))))) 810 (next-single-char-property-change pos 'field))))))
822
823(defun comint-mouse-insert-input (event)
824 "In a Comint buffer, set the current input to the previous input you click on."
825 (interactive "e")
826 (mouse-set-point event)
827 (comint-insert-input))
828 811
829 812
830;; Input history processing in a buffer 813;; Input history processing in a buffer
@@ -1734,7 +1717,7 @@ Make backspaces delete the previous character."
1734 (1- prompt-start) prompt-start 'read-only 'fence)) 1717 (1- prompt-start) prompt-start 'read-only 'fence))
1735 (add-text-properties 1718 (add-text-properties
1736 prompt-start (point) 1719 prompt-start (point)
1737 '(read-only t rear-non-sticky t front-sticky (read-only)))) 1720 '(read-only t rear-nonsticky t front-sticky (read-only))))
1738 (unless (and (bolp) (null comint-last-prompt-overlay)) 1721 (unless (and (bolp) (null comint-last-prompt-overlay))
1739 ;; Need to create or move the prompt overlay (in the case 1722 ;; Need to create or move the prompt overlay (in the case
1740 ;; where there is no prompt ((bolp) == t), we still do 1723 ;; where there is no prompt ((bolp) == t), we still do
@@ -2136,8 +2119,8 @@ This command also kills the pending input
2136between the process mark and point. 2119between the process mark and point.
2137 2120
2138WARNING: if there is no current subjob, you can end up suspending 2121WARNING: if there is no current subjob, you can end up suspending
2139the top-level process running in the buffer. If you accidentally do 2122the top-level process running in the buffer. If you accidentally do
2140this, use \\[comint-continue-subjob] to resume the process. (This 2123this, use \\[comint-continue-subjob] to resume the process. (This
2141is not a problem with most shells, since they ignore this signal.)" 2124is not a problem with most shells, since they ignore this signal.)"
2142 (interactive) 2125 (interactive)
2143 (comint-skip-input) 2126 (comint-skip-input)
@@ -2357,9 +2340,9 @@ preceding newline is removed."
2357 2340
2358(defun comint-kill-whole-line (&optional arg) 2341(defun comint-kill-whole-line (&optional arg)
2359 "Kill current line, ignoring read-only and field properties. 2342 "Kill current line, ignoring read-only and field properties.
2360With prefix arg, kill that many lines starting from the current line. 2343With prefix ARG, kill that many lines starting from the current line.
2361If arg is negative, kill backward. Also kill the preceding newline, 2344If arg is negative, kill backward. Also kill the preceding newline,
2362instead of the trailing one. \(This is meant to make C-x z work well 2345instead of the trailing one. \(This is meant to make \\[repeat] work well
2363with negative arguments.) 2346with negative arguments.)
2364If arg is zero, kill current line but exclude the trailing newline. 2347If arg is zero, kill current line but exclude the trailing newline.
2365The read-only status of newlines is updated with `comint-update-fence', 2348The read-only status of newlines is updated with `comint-update-fence',
@@ -2505,7 +2488,7 @@ Provides a default, if there is one, and returns the result filename.
2505 2488
2506See `comint-source-default' for more on determining defaults. 2489See `comint-source-default' for more on determining defaults.
2507 2490
2508PROMPT is the prompt string. PREV-DIR/FILE is the (directory . file) pair 2491PROMPT is the prompt string. PREV-DIR/FILE is the (directory . file) pair
2509from the last source processing command. SOURCE-MODES is a list of major 2492from the last source processing command. SOURCE-MODES is a list of major
2510modes used to determine what file buffers contain source files. (These 2493modes used to determine what file buffers contain source files. (These
2511two arguments are used for determining defaults). If MUSTMATCH-P is true, 2494two arguments are used for determining defaults). If MUSTMATCH-P is true,
@@ -3503,5 +3486,5 @@ REGEXP-GROUP is the regular expression group in REGEXP to use."
3503 3486
3504(provide 'comint) 3487(provide 'comint)
3505 3488
3506;;; arch-tag: 1793314c-09db-40be-9549-9aeae3e75164 3489;; arch-tag: 1793314c-09db-40be-9549-9aeae3e75164
3507;;; comint.el ends here 3490;;; comint.el ends here