• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /macosx-10.10/emacs-93/emacs/lisp/

Lines Matching defs:comint

0 ;;; comint.el --- general command interpreter in a window stuff
31 ;; (comint mode). The idea is that you can build specific process-in-a-buffer
32 ;; modes on top of comint mode -- e.g., Lisp, shell, scheme, T, soar, ....
37 ;; Several packages are already defined using comint mode:
55 ;; background, dbx, gdb, kermit, prolog, telnet) to use comint-mode
65 ;; M-p comint-previous-input Cycle backwards in input history
66 ;; M-n comint-next-input Cycle forwards
67 ;; M-r comint-previous-matching-input Previous input matching a regexp
68 ;; M-s comint-next-matching-input Next input that matches
69 ;; M-C-l comint-show-output Show last batch of process output
70 ;; RET comint-send-input
71 ;; C-d comint-delchar-or-maybe-eof Delete char unless at end of buff
72 ;; C-c C-a comint-bol-or-process-mark First time, move point to bol;
74 ;; C-c C-u comint-kill-input ^u
76 ;; C-c C-c comint-interrupt-subjob ^c
77 ;; C-c C-z comint-stop-subjob ^z
78 ;; C-c C-\ comint-quit-subjob ^\
79 ;; C-c C-o comint-delete-output Delete last batch of process output
80 ;; C-c C-r comint-show-output Show last batch of process output
81 ;; C-c C-l comint-dynamic-list-input-ring List input history
83 ;; Not bound by default in comint-mode (some are in shell mode)
84 ;; comint-run Run a program under comint-mode
86 ;; comint-dynamic-complete-filename Complete filename at point.
87 ;; comint-dynamic-list-filename-completions List completions in help buffer.
88 ;; comint-replace-by-expanded-filename Expand and complete filename at point;
90 ;; comint-replace-by-expanded-history Expand history at point;
92 ;; comint-magic-space Expand history and add (a) space(s).
93 ;; comint-kill-subjob No mercy.
94 ;; comint-show-maximum-output Show as much output as possible.
95 ;; comint-continue-subjob Send CONT signal to buffer's process
98 ;; comint-get-next-from-history Fetch successive input history lines
99 ;; comint-accumulate Combine lines to send them together
101 ;; comint-goto-process-mark Move point to where process-mark is.
102 ;; comint-set-process-mark Set process-mark to point.
104 ;; comint-mode-hook is the Comint mode hook. Basically for your keybindings.
114 ;; comint-prompt-regexp string comint-bol uses to match prompt
115 ;; comint-delimiter-argument-list list For delimiters and arguments
116 ;; comint-last-input-start marker Handy if inferior always echoes
117 ;; comint-last-input-end marker For comint-delete-output command
118 ;; comint-input-ring-size integer For the input history
119 ;; comint-input-ring ring mechanism
120 ;; comint-input-ring-index number ...
121 ;; comint-save-input-ring-index number ...
122 ;; comint-input-autoexpand symbol ...
123 ;; comint-input-ignoredups boolean ...
124 ;; comint-dynamic-complete-functions hook For the completion mechanism
125 ;; comint-completion-fignore list ...
126 ;; comint-file-name-chars string ...
127 ;; comint-file-name-quote-list list ...
128 ;; comint-get-old-input function Hooks for specific
129 ;; comint-input-filter-functions hook process-in-a-buffer
130 ;; comint-output-filter-functions hook function modes.
131 ;; comint-preoutput-filter-functions hook
132 ;; comint-input-filter function ...
133 ;; comint-input-sender function ...
134 ;; comint-eol-on-send boolean ...
135 ;; comint-process-echoes boolean ...
136 ;; comint-scroll-to-bottom-on-input symbol For scroll behavior
137 ;; comint-move-point-for-output symbol ...
138 ;; comint-scroll-show-maximum-output boolean ...
139 ;; comint-accum-marker maker For comint-accumulate
142 ;; comint-completion-addsuffix boolean/cons For file name
143 ;; comint-completion-autolist boolean completion behavior
144 ;; comint-completion-recexact boolean ...
146 (defgroup comint nil
150 (defgroup comint-completion nil
151 "Completion facilities in comint."
152 :group 'comint)
154 (defgroup comint-source nil
155 "Source finding facilities in comint."
156 :prefix "comint-"
157 :group 'comint)
159 (defvar comint-prompt-regexp "^"
164 `comint-use-prompt-regexp' is non-nil.
176 (defcustom comint-prompt-read-only nil
177 "If non-nil, the comint prompt is read only.
183 override the read-only-ness of comint prompts is to call
184 `comint-kill-whole-line' or `comint-kill-region' with no
189 \(add-hook 'comint-mode-hook
191 (define-key comint-mode-map \"\\C-w\" 'comint-kill-region)
192 (define-key comint-mode-map [C-S-backspace]
193 'comint-kill-whole-line)))
195 If you sometimes use comint-mode on text-only terminals or with `emacs -nw',
196 you might wish to use another binding for `comint-kill-whole-line'."
198 :group 'comint
201 (defvar comint-delimiter-argument-list ()
205 whitespace). See `comint-arguments'.
212 (defcustom comint-input-autoexpand nil
218 into the buffer's input ring. See also `comint-magic-space' and
219 `comint-dynamic-complete'.
226 :group 'comint)
228 (defface comint-highlight-input '((t (:weight bold)))
230 :group 'comint)
232 (defface comint-highlight-prompt
237 :group 'comint)
239 (defcustom comint-input-ignoredups nil
245 :group 'comint)
247 (defcustom comint-input-ring-file-name nil
249 See also `comint-read-input-ring' and `comint-write-input-ring'.
254 :group 'comint)
256 (defcustom comint-scroll-to-bottom-on-input nil
263 See `comint-preinput-scroll-to-bottom'. This variable is buffer-local."
268 :group 'comint)
270 (defcustom comint-move-point-for-output nil
280 See the variable `comint-scroll-show-maximum-output' and the function
281 `comint-postoutput-scroll-to-bottom'.
288 :group 'comint)
290 (defvaralias 'comint-scroll-to-bottom-on-output 'comint-move-point-for-output)
292 (defcustom comint-scroll-show-maximum-output t
296 `comint-move-point-for-output' said to move it there)
303 See also the variable `comint-move-point-for-output' and the function
304 `comint-postoutput-scroll-to-bottom'.
307 :group 'comint)
309 (defcustom comint-buffer-maximum-size 1024
312 the function `comint-truncate-buffer' is on `comint-output-filter-functions'."
314 :group 'comint)
316 (defvar comint-input-ring-size 150
319 (defvar comint-input-ring-separator "\n"
322 (defvar comint-input-history-ignore "^#"
325 (defcustom comint-process-echoes nil
332 :group 'comint)
339 (defcustom comint-password-prompt-regexp
346 This is used by `comint-watch-for-password-prompt'."
348 :group 'comint)
351 (defvar comint-get-old-input (function comint-get-old-input-default)
355 default is `comint-get-old-input-default', which either grabs the
357 text matching `comint-prompt-regexp', depending on the value of
358 `comint-use-prompt-regexp'.")
360 (defvar comint-dynamic-complete-functions
361 '(comint-replace-by-expanded-history comint-dynamic-complete-filename)
364 See also `comint-dynamic-complete'.
368 (defvar comint-input-filter
374 (defvar comint-input-filter-functions '()
379 (defvar comint-output-filter-functions '(comint-postoutput-scroll-to-bottom comint-watch-for-password-prompt)
381 One possible function is `comint-postoutput-scroll-to-bottom'.
384 `comint-last-output-start' and the buffer's `process-mark', if other filter
387 See also `comint-preoutput-filter-functions'.
392 (defvar comint-input-sender-no-newline nil
393 "Non-nil directs the `comint-input-sender' function not to send a newline.")
395 (defvar comint-input-sender (function comint-simple-send)
397 Usually this is just `comint-simple-send', but if your mode needs to
399 `comint-simple-send' just sends the string plus a newline.
400 \(If `comint-input-sender-no-newline' is non-nil, it omits the newline.)
401 This is called from the user command `comint-send-input'.")
403 (defcustom comint-eol-on-send t
405 See `comint-send-input'."
407 :group 'comint)
409 ;; Note: If it is decided to purge comint-prompt-regexp from the source
412 (defcustom comint-use-prompt-regexp nil
413 "*If non-nil, use `comint-prompt-regexp' to recognize prompts.
419 :group 'comint)
423 (define-obsolete-variable-alias 'comint-use-prompt-regexp-instead-of-fields
424 'comint-use-prompt-regexp "22.1")
426 (defcustom comint-mode-hook nil
427 "Hook run upon entry to `comint-mode'.
430 :group 'comint)
432 (defcustom comint-exec-hook '()
433 "Hook run each time a process is exec'd by `comint-exec'.
436 `(process-kill-without-query)'). In contrast, the `comint-mode-hook' is only
439 :group 'comint)
441 (defvar comint-mode-map
444 (define-key map "\ep" 'comint-previous-input)
445 (define-key map "\en" 'comint-next-input)
446 (define-key map [C-up] 'comint-previous-input)
447 (define-key map [C-down] 'comint-next-input)
448 (define-key map "\er" 'comint-previous-matching-input)
449 (define-key map "\es" 'comint-next-matching-input)
450 (define-key map [?\C-c ?\M-r] 'comint-previous-matching-input-from-input)
451 (define-key map [?\C-c ?\M-s] 'comint-next-matching-input-from-input)
452 (define-key map "\e\C-l" 'comint-show-output)
453 (define-key map "\C-m" 'comint-send-input)
454 (define-key map "\C-d" 'comint-delchar-or-maybe-eof)
455 (define-key map "\C-c " 'comint-accumulate)
456 (define-key map "\C-c\C-x" 'comint-get-next-from-history)
457 (define-key map "\C-c\C-a" 'comint-bol-or-process-mark)
458 (define-key map "\C-c\C-u" 'comint-kill-input)
460 (define-key map "\C-c\C-c" 'comint-interrupt-subjob)
461 (define-key map "\C-c\C-z" 'comint-stop-subjob)
462 (define-key map "\C-c\C-\\" 'comint-quit-subjob)
463 (define-key map "\C-c\C-m" 'comint-copy-old-input)
464 (define-key map "\C-c\C-o" 'comint-delete-output)
465 (define-key map "\C-c\C-r" 'comint-show-output)
466 (define-key map "\C-c\C-e" 'comint-show-maximum-output)
467 (define-key map "\C-c\C-l" 'comint-dynamic-list-input-ring)
468 (define-key map "\C-c\C-n" 'comint-next-prompt)
469 (define-key map "\C-c\C-p" 'comint-previous-prompt)
470 (define-key map "\C-c\C-d" 'comint-send-eof)
471 (define-key map "\C-c\C-s" 'comint-write-output)
472 (define-key map "\C-c." 'comint-insert-previous-argument)
474 (define-key map [mouse-2] 'comint-insert-input)
480 '("Expand File Name" . comint-replace-by-expanded-filename))
482 '("File Completion Listing" . comint-dynamic-list-filename-completions))
484 '("Complete File Name" . comint-dynamic-complete-filename))
486 '("Complete Before Point" . comint-dynamic-complete))
491 '("Delete Current Output Group" . comint-delete-output))
493 '("Append Current Output Group to File" . comint-append-output-to-file))
495 '("Write Current Output Group to File" . comint-write-output))
497 '("Forward Output Group" . comint-next-prompt))
499 '("Backward Output Group" . comint-previous-prompt))
501 '("Show Maximum Output" . comint-show-maximum-output))
503 '("Show Current Output Group" . comint-show-output))
505 '("Kill Current Input" . comint-kill-input))
507 '("Copy Old Input" . comint-copy-old-input))
509 '("Forward Matching Input..." . comint-forward-matching-input))
511 '("Backward Matching Input..." . comint-backward-matching-input))
513 '("Next Matching Input..." . comint-next-matching-input))
515 '("Previous Matching Input..." . comint-previous-matching-input))
517 '("Next Matching Current Input" . comint-next-matching-input-from-input))
519 '("Previous Matching Current Input" . comint-previous-matching-input-from-input))
521 '("Next Input" . comint-next-input))
523 '("Previous Input" . comint-previous-input))
525 '("List Input History" . comint-dynamic-list-input-ring))
527 '("Expand History Before Point" . comint-replace-by-expanded-history))
531 (define-key signals-map [eof] '("EOF" . comint-send-eof))
532 (define-key signals-map [kill] '("KILL" . comint-kill-subjob))
533 (define-key signals-map [quit] '("QUIT" . comint-quit-subjob))
534 (define-key signals-map [cont] '("CONT" . comint-continue-subjob))
535 (define-key signals-map [stop] '("STOP" . comint-stop-subjob))
536 (define-key signals-map [break] '("BREAK" . comint-interrupt-subjob)))
543 (defvar comint-ptyp t
547 (defvar comint-input-ring nil)
548 (defvar comint-last-input-start nil)
549 (defvar comint-last-input-end nil)
550 (defvar comint-last-output-start nil)
551 (defvar comint-input-ring-index nil
553 (defvar comint-matching-input-from-input-string ""
555 (defvar comint-save-input-ring-index
557 This is to support the command \\[comint-get-next-from-history].")
559 (defvar comint-accum-marker nil
561 The command \\[comint-accumulate] sets this.")
563 (defvar comint-stored-incomplete-input nil
566 (put 'comint-replace-by-expanded-history 'menu-enable 'comint-input-autoexpand)
567 (put 'comint-input-ring 'permanent-local t)
568 (put 'comint-input-ring-index 'permanent-local t)
569 (put 'comint-save-input-ring-index 'permanent-local t)
570 (put 'comint-input-autoexpand 'permanent-local t)
571 (put 'comint-input-filter-functions 'permanent-local t)
572 (put 'comint-output-filter-functions 'permanent-local t)
573 (put 'comint-preoutput-filter-functions 'permanent-local t)
574 (put 'comint-scroll-to-bottom-on-input 'permanent-local t)
575 (put 'comint-move-point-for-output 'permanent-local t)
576 (put 'comint-scroll-show-maximum-output 'permanent-local t)
577 (put 'comint-ptyp 'permanent-local t)
579 (put 'comint-mode 'mode-class 'special)
581 (define-derived-mode comint-mode fundamental-mode "Comint"
586 Setting variable `comint-eol-on-send' means jump to the end of the line
591 `comint-input-filter-functions', `comint-input-filter', `comint-input-sender'
592 and `comint-get-old-input' to appropriate functions, and the variable
593 `comint-prompt-regexp' to the appropriate regular expression.
595 An input history is maintained of size `comint-input-ring-size', and
596 can be accessed with the commands \\[comint-next-input], \\[comint-previous-input], and \\[comint-dynamic-list-input-ring].
598 \\[comint-replace-by-expanded-history] or \\[comint-magic-space].
599 Input ring expansion is controlled by the variable `comint-input-autoexpand',
600 and addition is controlled by the variable `comint-input-ignoredups'.
603 `comint-dynamic-complete', `comint-dynamic-list-filename-completions', and
604 `comint-magic-space'.
607 the end of the buffer. See variables `comint-output-filter-functions',
608 `comint-preoutput-filter-functions', `comint-scroll-to-bottom-on-input',
609 and `comint-move-point-for-output'.
611 If you accidentally suspend your process, use \\[comint-continue-subjob]
614 \\{comint-mode-map}
616 Entry to this mode runs the hooks on `comint-mode-hook'."
618 (set (make-local-variable 'comint-last-input-start) (point-min-marker))
619 (set (make-local-variable 'comint-last-input-end) (point-min-marker))
620 (set (make-local-variable 'comint-last-output-start) (make-marker))
621 (make-local-variable 'comint-last-prompt-overlay)
622 (make-local-variable 'comint-prompt-regexp) ; Don't set; default
623 (make-local-variable 'comint-input-ring-size) ; ...to global val.
624 (make-local-variable 'comint-input-ring)
625 (make-local-variable 'comint-input-ring-file-name)
626 (or (and (boundp 'comint-input-ring) comint-input-ring)
627 (setq comint-input-ring (make-ring comint-input-ring-size)))
628 (make-local-variable 'comint-input-ring-index)
629 (make-local-variable 'comint-save-input-ring-index)
630 (or (and (boundp 'comint-input-ring-index) comint-input-ring-index)
631 (setq comint-input-ring-index nil))
632 (or (and (boundp 'comint-save-input-ring-index) comint-save-input-ring-index)
633 (setq comint-save-input-ring-index nil))
634 (make-local-variable 'comint-matching-input-from-input-string)
635 (make-local-variable 'comint-input-autoexpand)
636 (make-local-variable 'comint-input-ignoredups)
637 (make-local-variable 'comint-delimiter-argument-list)
638 (make-local-variable 'comint-completion-fignore)
639 (make-local-variable 'comint-get-old-input)
640 (make-local-variable 'comint-input-filter)
641 (make-local-variable 'comint-input-sender)
642 (make-local-variable 'comint-eol-on-send)
643 (make-local-variable 'comint-scroll-to-bottom-on-input)
644 (make-local-variable 'comint-move-point-for-output)
645 (make-local-variable 'comint-scroll-show-maximum-output)
646 (make-local-variable 'comint-stored-incomplete-input)
650 (add-hook 'pre-command-hook 'comint-preinput-scroll-to-bottom t t)
651 (make-local-variable 'comint-ptyp)
652 (make-local-variable 'comint-process-echoes)
653 (make-local-variable 'comint-file-name-chars)
654 (make-local-variable 'comint-file-name-quote-list)
655 (make-local-variable 'comint-accum-marker)
656 (setq comint-accum-marker (make-marker))
660 ;; This behavior is not useful in comint buffers, and is annoying
663 (defun comint-check-proc (buffer)
671 (defun make-comint-in-buffer (name buffer program &optional startfile &rest switches)
685 ;; comint mode. Otherwise, leave buffer and existing process alone.
686 (unless (comint-check-proc buffer)
688 (unless (derived-mode-p 'comint-mode)
689 (comint-mode))) ; Install local vars, mode, keymap, ...
690 (comint-exec buffer name program startfile switches))
694 (defun make-comint (name program &optional startfile &rest switches)
704 (apply #'make-comint-in-buffer name nil program startfile switches))
707 (defun comint-run (program)
710 The file name is used to make a symbol name, such as `comint-sh-hook', and any
712 See `make-comint' and `comint-exec'."
715 (switch-to-buffer (make-comint name program))
716 (run-hooks (intern-soft (concat "comint-" name "-hook")))))
718 (defun comint-exec (buffer name command startfile switches)
723 buffer. The hook `comint-exec-hook' is run after each exec."
731 (comint-exec-1 name buffer command switches))))
732 (set-process-filter proc 'comint-output-filter)
733 (make-local-variable 'comint-ptyp)
734 (setq comint-ptyp process-connection-type) ; t if pty, nil if pipe.
741 ;;but has bad results if the comint does not prompt at all
750 (comint-send-string proc startfile)))
751 (run-hooks 'comint-exec-hook)
754 ;; This auxiliary function cranks up the process for comint-exec in
757 (defun comint-exec-1 (name buffer command switches)
775 (list (format "INSIDE_EMACS=%s,comint" emacs-version))
807 (defun comint-insert-input (event)
817 (if (or (null comint-accum-marker)
820 ;; buffer is not a comint buffer (which can happen if a
821 ;; non-comint window was selected and we clicked in a comint
826 (and fun (not (eq fun 'comint-insert-input))
832 (or (marker-position comint-accum-marker)
844 ;; comint-dynamic-list-input-ring List history in help buffer.
845 ;; comint-previous-input Previous input...
846 ;; comint-previous-matching-input ...matching a string.
847 ;; comint-previous-matching-input-from-input ... matching the current input.
848 ;; comint-next-input Next input...
849 ;; comint-next-matching-input ...matching a string.
850 ;; comint-next-matching-input-from-input ... matching the current input.
851 ;; comint-backward-matching-input Backwards input...
852 ;; comint-forward-matching-input ...matching a string.
853 ;; comint-replace-by-expanded-history Expand history at point;
855 ;; comint-magic-space Expand history and insert space.
858 ;; comint-read-input-ring Read into comint-input-ring...
859 ;; comint-write-input-ring Write to comint-input-ring-file-name.
860 ;; comint-replace-by-expanded-history-before-point Workhorse function.
862 (defun comint-read-input-ring (&optional silent)
863 "Set the buffer's `comint-input-ring' from a history file.
864 The name of the file is given by the variable `comint-input-ring-file-name'.
865 The history ring is of size `comint-input-ring-size', regardless of file size.
866 If `comint-input-ring-file-name' is nil this function does nothing.
874 `comint-input-ring-separator', and entries that match
875 `comint-input-history-ignore' are ignored. The most recent command
878 See also `comint-input-ignoredups' and `comint-write-input-ring'."
879 (cond ((or (null comint-input-ring-file-name)
880 (equal comint-input-ring-file-name ""))
882 ((not (file-readable-p comint-input-ring-file-name))
885 comint-input-ring-file-name)))
888 (file comint-input-ring-file-name)
890 (size comint-input-ring-size)
903 (re-search-backward comint-input-ring-separator nil t)
905 (if (re-search-backward comint-input-ring-separator nil t)
910 (if (and (not (string-match comint-input-history-ignore history))
911 (or (null comint-input-ignoredups)
918 (setq comint-input-ring ring
919 comint-input-ring-index nil)))))
921 (defun comint-write-input-ring ()
922 "Writes the buffer's `comint-input-ring' to a history file.
923 The name of the file is given by the variable `comint-input-ring-file-name'.
924 The original contents of the file are lost if `comint-input-ring' is not empty.
925 If `comint-input-ring-file-name' is nil this function does nothing.
929 See also `comint-read-input-ring'."
930 (cond ((or (null comint-input-ring-file-name)
931 (equal comint-input-ring-file-name "")
932 (null comint-input-ring) (ring-empty-p comint-input-ring))
934 ((not (file-writable-p comint-input-ring-file-name))
935 (message "Cannot write history file %s" comint-input-ring-file-name))
938 (ring comint-input-ring)
939 (file comint-input-ring-file-name)
948 (insert (ring-ref ring index) comint-input-ring-separator))
953 (defvar comint-dynamic-list-input-ring-window-conf)
955 (defun comint-dynamic-list-input-ring-select ()
969 (set-window-configuration comint-dynamic-list-input-ring-window-conf)
972 (defun comint-dynamic-list-input-ring ()
975 (if (or (not (ring-p comint-input-ring))
976 (ring-empty-p comint-input-ring))
980 (index (1- (ring-length comint-input-ring)))
984 (setq history (cons (ring-ref comint-input-ring index) history)
993 (define-key keymap "\C-m" 'comint-dynamic-list-input-ring-select)
1000 (setq comint-dynamic-list-input-ring-window-conf conf)
1007 (defun comint-regexp-arg (prompt)
1019 (defun comint-search-arg (arg)
1021 (cond ((not (comint-after-pmark-p))
1023 ((or (null comint-input-ring)
1024 (ring-empty-p comint-input-ring))
1028 (setq comint-input-ring-index nil)
1033 (defun comint-restore-input ()
1036 (when comint-input-ring-index
1037 (comint-delete-input)
1038 (when (> (length comint-stored-incomplete-input) 0)
1039 (insert comint-stored-incomplete-input)
1041 (setq comint-input-ring-index nil)))
1043 (defun comint-search-start (arg)
1044 "Index to start a directional search, starting at `comint-input-ring-index'."
1045 (if comint-input-ring-index
1047 (mod (+ comint-input-ring-index (if (> arg 0) 1 -1))
1048 (ring-length comint-input-ring))
1052 (1- (ring-length comint-input-ring))))) ; Last elt for backward search
1054 (defun comint-previous-input-string (arg)
1056 Moves relative to `comint-input-ring-index'."
1057 (ring-ref comint-input-ring (if comint-input-ring-index
1058 (mod (+ arg comint-input-ring-index)
1059 (ring-length comint-input-ring))
1062 (defun comint-previous-input (arg)
1065 (if (and comint-input-ring-index
1068 (eq comint-input-ring-index 0))
1070 (eq comint-input-ring-index
1071 (1- (ring-length comint-input-ring)))))
1072 comint-stored-incomplete-input)
1073 (comint-restore-input)
1074 (comint-previous-matching-input "." arg)))
1076 (defun comint-next-input (arg)
1079 (comint-previous-input (- arg)))
1081 (defun comint-previous-matching-input-string (regexp arg)
1083 Moves relative to `comint-input-ring-index'."
1084 (let* ((pos (comint-previous-matching-input-string-position regexp arg)))
1085 (if pos (ring-ref comint-input-ring pos))))
1087 (defun comint-previous-matching-input-string-position (regexp arg &optional start)
1089 Moves relative to START, or `comint-input-ring-index'."
1090 (if (or (not (ring-p comint-input-ring))
1091 (ring-empty-p comint-input-ring))
1093 (let* ((len (ring-length comint-input-ring))
1095 (n (mod (- (or start (comint-search-start arg)) motion) len))
1105 (not (string-match regexp (ring-ref comint-input-ring n))))
1111 (if (string-match regexp (ring-ref comint-input-ring n))
1114 (defun comint-delete-input ()
1118 (or (marker-position comint-accum-marker)
1122 (defun comint-previous-matching-input (regexp n)
1127 (interactive (comint-regexp-arg "Previous input matching (regexp): "))
1128 (setq n (comint-search-arg n))
1129 (let ((pos (comint-previous-matching-input-string-position regexp n)))
1134 (if (null comint-input-ring-index) ;not yet on ring
1135 (setq comint-stored-incomplete-input
1136 (funcall comint-get-old-input)))
1137 (setq comint-input-ring-index pos)
1139 (comint-delete-input)
1140 (insert (ring-ref comint-input-ring pos)))))
1142 (defun comint-next-matching-input (regexp n)
1147 (interactive (comint-regexp-arg "Next input matching (regexp): "))
1148 (comint-previous-matching-input regexp (- n)))
1150 (defun comint-previous-matching-input-from-input (n)
1156 (if (not (memq last-command '(comint-previous-matching-input-from-input
1157 comint-next-matching-input-from-input)))
1159 (setq comint-matching-input-from-input-string
1161 (or (marker-position comint-accum-marker)
1164 comint-input-ring-index nil))
1165 (comint-previous-matching-input
1166 (concat "^" (regexp-quote comint-matching-input-from-input-string))
1169 (defun comint-next-matching-input-from-input (n)
1175 (comint-previous-matching-input-from-input (- n)))
1178 (defun comint-replace-by-expanded-history (&optional silent start)
1180 Expansion is dependent on the value of `comint-input-autoexpand'.
1196 See `comint-magic-space' and `comint-replace-by-expanded-history-before-point'.
1200 (if (and comint-input-autoexpand
1201 (if comint-use-prompt-regexp
1202 ;; Use comint-prompt-regexp
1205 (looking-at (concat comint-prompt-regexp "!\\|\\^")))
1212 (comint-replace-by-expanded-history-before-point silent start)
1216 (defun comint-replace-by-expanded-history-before-point (silent &optional start)
1218 See `comint-replace-by-expanded-history'. Returns t if successful.
1225 (start (or start (comint-line-beginning-position))))
1235 ;; referenced with plings, with the range string to `comint-args'.
1236 (setq comint-input-ring-index nil)
1238 (comint-within-quotes start (point)))
1250 (if (<= number (ring-length comint-input-ring))
1253 (comint-args (comint-previous-input-string number)
1256 (setq comint-input-ring-index number)
1263 (comint-args (comint-previous-input-string 0)
1276 (comint-previous-matching-input-string-position
1284 (setq comint-input-ring-index pos)
1286 (comint-args (ring-ref comint-input-ring pos)
1295 (replace-match (comint-previous-input-string 0) t t)
1307 (defun comint-magic-space (arg)
1309 A useful command to bind to SPC. See `comint-replace-by-expanded-history'."
1311 (comint-replace-by-expanded-history)
1315 (defun comint-within-quotes (beg end)
1318 (let ((countsq (comint-how-many-region "\\(^\\|[^\\\\]\\)\'" beg end))
1319 (countdq (comint-how-many-region "\\(^\\|[^\\\\]\\)\"" beg end)))
1322 (defun comint-how-many-region (regexp beg end)
1332 (defun comint-args (string begin end)
1338 (comint-arguments string 0 nil)
1349 (comint-arguments string nth mth)))))
1351 (defun comint-delim-arg (arg)
1353 Break it up at the delimiters in `comint-delimiter-argument-list'.
1359 (if (null comint-delimiter-argument-list)
1367 (if (and (memq char comint-delimiter-argument-list)
1374 comint-delimiter-argument-list)
1381 (defun comint-arguments (string nth mth)
1388 in `comint-delimiter-argument-list' is a separate argument.
1413 ;; characters, so that `comint-delim-arg' won't break them up.
1427 (nconc (comint-delim-arg str) args))))
1435 (nconc (comint-delim-arg str) args))))
1446 (defun comint-add-to-input-history (cmd)
1448 Ignore duplicates if `comint-input-ignoredups' is non-nil."
1449 (if (and (funcall comint-input-filter cmd)
1450 (or (null comint-input-ignoredups)
1451 (not (ring-p comint-input-ring))
1452 (ring-empty-p comint-input-ring)
1453 (not (string-equal (ring-ref comint-input-ring 0)
1455 (ring-insert comint-input-ring cmd)))
1457 (defun comint-send-input (&optional no-newline artificial)
1461 value of variable `comint-get-old-input' to retrieve old input, copies
1468 `comint-input-autoexpand'. The list of function names contained in the value
1469 of `comint-input-filter-functions' is called on the input before sending it.
1471 `comint-input-filter' returns non-nil when called on the input.
1473 If variable `comint-eol-on-send' is non-nil, then point is moved to the
1476 After the input has been sent, if `comint-process-echoes' is non-nil,
1477 then `comint-send-input' waits to see if the process outputs a string
1482 The values of `comint-get-old-input', `comint-input-filter-functions', and
1483 `comint-input-filter' are chosen according to the command interpreter running
1487 `comint-get-old-input' is the default:
1488 If `comint-use-prompt-regexp' is nil, then
1491 If `comint-use-prompt-regexp' is non-nil, then
1493 regexp `comint-prompt-regexp' removed.
1494 `comint-input-filter-functions' monitors input for \"cd\", \"pushd\", and
1496 `comint-input-filter' is the default: returns t if the input isn't all white
1500 `comint-get-old-input' snarfs the sexp ending at point.
1501 `comint-input-filter-functions' does nothing.
1502 `comint-input-filter' returns nil if the input matches input-filter-regexp,
1513 (progn (if comint-eol-on-send (end-of-line))
1515 (let ((copy (funcall comint-get-old-input)))
1519 (input (if (not (eq comint-input-autoexpand 'input))
1523 (comint-replace-by-expanded-history t pmark)
1525 (history (if (not (eq comint-input-autoexpand 'history))
1530 (comint-replace-by-expanded-history t pmark)
1540 (comint-add-to-input-history history)
1542 (run-hook-with-args 'comint-input-filter-functions
1552 font-lock-face comint-highlight-input))
1553 (unless comint-use-prompt-regexp
1564 (unless (or no-newline comint-use-prompt-regexp)
1571 (comint-snapshot-last-prompt)
1573 (setq comint-save-input-ring-index comint-input-ring-index)
1574 (setq comint-input-ring-index nil)
1577 (set-marker comint-last-input-start pmark)
1578 (set-marker comint-last-input-end (point))
1581 (set-marker comint-accum-marker nil)
1582 (let ((comint-input-sender-no-newline no-newline))
1583 (funcall comint-input-sender proc input))
1586 (when (and comint-process-echoes (not artificial))
1587 (let ((echo-len (- comint-last-input-end
1588 comint-last-input-start)))
1591 (> (+ comint-last-input-end echo-len)
1595 nil comint-last-input-start
1598 ;; (+ comint-last-input-start
1599 ;; (- (point-max) comint-last-input-end))
1600 nil comint-last-input-end (point-max)))))
1602 (<= (+ comint-last-input-end echo-len)
1606 nil comint-last-input-start comint-last-input-end
1607 nil comint-last-input-end
1608 (+ comint-last-input-end echo-len))))
1611 ;; problems when `comint-prompt-read-only' is non-nil.
1613 (delete-region comint-last-input-end
1614 (+ comint-last-input-end echo-len))
1615 (when comint-prompt-read-only
1617 (goto-char comint-last-input-end)
1618 (comint-update-fence)))))))
1620 ;; This used to call comint-output-filter-functions,
1622 (run-hook-with-args 'comint-output-filter-functions "")))))
1624 (defvar comint-preoutput-filter-functions nil
1639 (defvar comint-inhibit-carriage-motion nil
1641 See `comint-carriage-motion' for details.")
1645 (defvar comint-last-prompt-overlay nil)
1647 (defun comint-snapshot-last-prompt ()
1648 "`snapshot' any current `comint-last-prompt-overlay'.
1651 (when comint-last-prompt-overlay
1654 (add-text-properties (overlay-start comint-last-prompt-overlay)
1655 (overlay-end comint-last-prompt-overlay)
1656 (overlay-properties comint-last-prompt-overlay)))))
1658 (defun comint-carriage-motion (start end)
1692 ;; The purpose of using this filter for comint processes
1693 ;; is to keep comint-last-input-end from moving forward
1695 (defun comint-output-filter (process string)
1701 (let ((functions comint-preoutput-filter-functions))
1704 (let ((functions (default-value 'comint-preoutput-filter-functions)))
1726 (set-marker comint-last-output-start (point))
1741 ;; variable). In comint buffers, this variable would be set
1747 ;; comint-last-output-start
1748 (set-marker comint-last-output-start old-point)
1749 ;; comint-last-input-end
1750 (when (and comint-last-input-end
1751 (equal (marker-position comint-last-input-end)
1753 (set-marker comint-last-input-end old-point))
1775 (unless comint-inhibit-carriage-motion
1777 (comint-carriage-motion comint-last-output-start (point)))
1781 (run-hook-with-args 'comint-output-filter-functions string)
1786 (unless comint-use-prompt-regexp
1789 (add-text-properties comint-last-output-start (point)
1799 (when comint-prompt-read-only
1807 (unless (and (bolp) (null comint-last-prompt-overlay))
1811 (if comint-last-prompt-overlay
1813 (move-overlay comint-last-prompt-overlay
1816 (setq comint-last-prompt-overlay
1818 (overlay-put comint-last-prompt-overlay
1819 'font-lock-face 'comint-highlight-prompt))))
1823 (defun comint-preinput-scroll-to-bottom ()
1827 are `self-insert-command', `comint-magic-space', `yank', and `hilit-yank'.
1828 Depends on the value of `comint-scroll-to-bottom-on-input'.
1831 (if (and comint-scroll-to-bottom-on-input
1832 (memq this-command '(self-insert-command comint-magic-space yank
1837 (scroll comint-scroll-to-bottom-on-input))
1851 (defun comint-postoutput-scroll-to-bottom (string)
1854 Depends on the value of `comint-move-point-for-output' and
1855 `comint-scroll-show-maximum-output'.
1857 This function should be in the list `comint-output-filter-functions'."
1861 (scroll comint-move-point-for-output))
1875 (and (marker-position comint-last-output-start)
1876 (>= (point) comint-last-output-start))))
1880 (if (and comint-scroll-show-maximum-output
1889 (defun comint-truncate-buffer (&optional string)
1890 "Truncate the buffer to `comint-buffer-maximum-size'.
1891 This function could be on `comint-output-filter-functions' or bound to a key."
1895 (forward-line (- comint-buffer-maximum-size))
1900 (defun comint-strip-ctrl-m (&optional string)
1902 This function could be on `comint-output-filter-functions' or bound to a key."
1908 (if (interactive-p) comint-last-input-end comint-last-output-start))
1912 (defalias 'shell-strip-ctrl-m 'comint-strip-ctrl-m)
1914 (defun comint-show-maximum-output ()
1920 (defun comint-get-old-input-default ()
1921 "Default for `comint-get-old-input'.
1922 If `comint-use-prompt-regexp' is nil, then either
1925 If `comint-use-prompt-regexp' is non-nil, then return
1927 `comint-prompt-regexp' removed."
1931 (comint-bol)
1934 (defun comint-copy-old-input ()
1936 Calls `comint-get-old-input' to get old input."
1938 (let ((input (funcall comint-get-old-input))
1945 (defun comint-skip-prompt ()
1946 "Skip past the text matching regexp `comint-prompt-regexp'.
1948 (if (and (looking-at comint-prompt-regexp)
1952 (defun comint-after-pmark-p ()
1957 (defun comint-simple-send (proc string)
1960 set the hook `comint-input-sender'."
1961 (comint-send-string proc string)
1962 (if comint-input-sender-no-newline
1965 (comint-send-string proc "\n")))
1967 (defun comint-line-beginning-position ()
1969 If `comint-use-prompt-regexp' is non-nil, then the prompt skip is done by
1970 skipping text matching the regular expression `comint-prompt-regexp',
1972 (if comint-use-prompt-regexp
1973 ;; Use comint-prompt-regexp
1976 (comint-skip-prompt)
1987 (defun comint-bol (&optional arg)
1990 If `comint-use-prompt-regexp' is non-nil, then the prompt skip is done
1991 by skipping text matching the regular expression `comint-prompt-regexp',
1997 (goto-char (comint-line-beginning-position))))
2000 (defun comint-read-noecho (prompt &optional ignore)
2010 The string is sent using `comint-input-sender'.
2025 (comint-snapshot-last-prompt)
2026 (funcall comint-input-sender proc str))
2030 (defun comint-watch-for-password-prompt (string)
2034 `comint-password-prompt-regexp'.
2036 This function could be in the list `comint-output-filter-functions'."
2037 (when (string-match comint-password-prompt-regexp string)
2045 (defun comint-send-string (process string)
2051 (comint-snapshot-last-prompt))
2052 (comint-snapshot-last-prompt))
2055 (defun comint-send-region (process start end)
2061 (comint-snapshot-last-prompt))
2062 (comint-snapshot-last-prompt))
2069 (defun comint-delete-output ()
2080 (delete-region comint-last-input-end pmark)
2086 (comint-output-filter proc replacement)))
2087 (define-obsolete-function-alias 'comint-kill-output
2088 'comint-delete-output "21.1")
2090 (defun comint-write-output (filename &optional append mustbenew)
2114 (write-region comint-last-input-end (point) filename
2118 ;; users can just use `comint-write-output' with a prefix arg.
2119 (defun comint-append-output-to-file (filename)
2123 (comint-write-output filename t))
2125 (defun comint-show-output ()
2130 (let ((pos (or (marker-position comint-last-input-end) (point-max))))
2131 (cond (comint-use-prompt-regexp
2135 (comint-skip-prompt))
2145 (defun comint-interrupt-subjob ()
2150 (comint-skip-input)
2151 (interrupt-process nil comint-ptyp)
2155 (defun comint-kill-subjob ()
2160 (comint-skip-input)
2161 (kill-process nil comint-ptyp))
2163 (defun comint-quit-subjob ()
2168 (comint-skip-input)
2169 (quit-process nil comint-ptyp))
2171 (defun comint-stop-subjob ()
2178 this, use \\[comint-continue-subjob] to resume the process. (This
2181 (comint-skip-input)
2182 (stop-process nil comint-ptyp))
2184 (defun comint-continue-subjob ()
2188 (continue-process nil comint-ptyp))
2190 (defun comint-skip-input ()
2193 (let ((comint-input-sender 'ignore)
2194 (comint-input-filter-functions nil))
2195 (comint-send-input t t))
2203 (defun comint-kill-input ()
2210 (defun comint-delchar-or-maybe-eof (arg)
2216 (comint-send-eof)
2219 (defun comint-send-eof ()
2222 (comint-send-input t t)
2226 (defun comint-backward-matching-input (regexp n)
2228 If `comint-use-prompt-regexp' is non-nil, then input fields are identified
2229 by lines that match `comint-prompt-regexp'.
2233 (interactive (comint-regexp-arg "Backward input matching (regexp): "))
2234 (if comint-use-prompt-regexp
2235 ;; Use comint-prompt-regexp
2236 (let* ((re (concat comint-prompt-regexp ".*" regexp))
2244 (comint-bol nil)))
2258 (defun comint-forward-matching-input (regexp n)
2260 If `comint-use-prompt-regexp' is non-nil, then input fields are identified
2261 by lines that match `comint-prompt-regexp'.
2265 (interactive (comint-regexp-arg "Forward input matching (regexp): "))
2266 (comint-backward-matching-input regexp (- n)))
2269 (defun comint-next-prompt (n)
2271 If `comint-use-prompt-regexp' is nil, then this means the beginning of
2273 text matching `comint-prompt-regexp'."
2275 (if comint-use-prompt-regexp
2276 ;; Use comint-prompt-regexp
2277 (let ((paragraph-start comint-prompt-regexp))
2280 (comint-skip-prompt))
2306 (defun comint-previous-prompt (n)
2308 If `comint-use-prompt-regexp' is nil, then this means the beginning of
2310 text matching `comint-prompt-regexp'."
2312 (comint-next-prompt (- n)))
2314 ;; State used by `comint-insert-previous-argument' when cycling.
2315 (defvar comint-insert-previous-argument-last-start-pos nil)
2316 (make-variable-buffer-local 'comint-insert-previous-argument-last-start-pos)
2317 (defvar comint-insert-previous-argument-last-index nil)
2318 (make-variable-buffer-local 'comint-insert-previous-argument-last-index)
2321 ;; make comint-arguments understand negative indices as bash does
2322 (defun comint-insert-previous-argument (index)
2336 (delete-region comint-insert-previous-argument-last-start-pos (point))
2337 (setq index comint-insert-previous-argument-last-index))
2340 (setq comint-input-ring-index nil)
2341 (setq comint-insert-previous-argument-last-index index)
2342 (when (null comint-insert-previous-argument-last-start-pos)
2344 (setq comint-insert-previous-argument-last-start-pos
2347 (if (<= (point) (comint-line-beginning-position))
2348 (comint-bol)
2352 (set-marker comint-insert-previous-argument-last-start-pos (point))
2354 (let ((input-string (comint-previous-input-string 0)))
2358 (insert (comint-arguments input-string index index)))
2360 (setq comint-input-ring-index (1+ (or comint-input-ring-index 0)))
2367 ;; Support editing with `comint-prompt-read-only' set to t.
2369 (defun comint-update-fence ()
2374 implement comint read-only prompts. If the text after a newline
2397 (defun comint-kill-whole-line (&optional count)
2404 The read-only status of newlines is updated with `comint-update-fence',
2409 (when (>= count 0) (comint-update-fence))))
2411 (defun comint-kill-region (beg end &optional yank-handler)
2417 comint prompts if `comint-prompt-read-only' is non-nil. This
2424 updated using `comint-update-fence', if necessary."
2442 (comint-update-fence))))))
2476 (defun comint-source-default (previous-dir/file source-modes)
2513 (defun comint-check-source (fname)
2530 (defun comint-extract-string ()
2541 (defun comint-get-source (prompt prev-dir/file source-modes mustmatch-p)
2546 See `comint-source-default' for more on determining defaults.
2555 (interactive (comint-get-source \"Compile file: \" prev-lisp-dir/file
2557 (let* ((def (comint-source-default prev-dir/file source-modes))
2558 (stringfile (comint-extract-string))
2599 (defun comint-proc-query (proc str)
2609 (comint-send-string proc str) ; send the query
2629 ;; comint-dynamic-complete Complete or expand command, filename,
2631 ;; comint-dynamic-complete-filename Complete filename at point.
2632 ;; comint-dynamic-list-filename-completions List completions in help buffer.
2633 ;; comint-replace-by-expanded-filename Expand and complete filename at point;
2635 ;; comint-dynamic-simple-complete Complete stub given candidates.
2637 ;; These are not installed in the comint-mode keymap. But they are
2639 ;; (define-key shell-mode-map "\t" 'comint-dynamic-complete)
2641 ;; 'comint-dynamic-list-filename-completions)))
2646 (defcustom comint-completion-autolist nil
2650 :group 'comint-completion)
2652 (defcustom comint-completion-addsuffix t
2662 :group 'comint-completion)
2664 (defcustom comint-completion-recexact nil
2668 A non-nil value is useful if `comint-completion-autolist' is non-nil too."
2670 :group 'comint-completion)
2672 (defcustom comint-completion-fignore nil
2676 Note that this applies to `comint-dynamic-complete-filename' only."
2678 :group 'comint-completion)
2681 (defvar comint-file-name-prefix ""
2686 (defvar comint-file-name-chars
2696 (defvar comint-file-name-quote-list nil
2702 (defun comint-directory (directory)
2703 "Return expanded DIRECTORY, with `comint-file-name-prefix' if absolute."
2705 (concat comint-file-name-prefix directory)
2709 (defun comint-word (word-chars)
2734 (defun comint-substitute-in-file-name (filename)
2752 (defun comint-match-partial-filename ()
2754 Environment variables are substituted. See `comint-word'."
2755 (let ((filename (comint-word comint-file-name-chars)))
2756 (and filename (comint-substitute-in-file-name
2757 (comint-unquote-filename filename)))))
2760 (defun comint-quote-filename (filename)
2762 Magic characters are those in `comint-file-name-quote-list'."
2763 (if (null comint-file-name-quote-list)
2767 (mapconcat 'char-to-string comint-file-name-quote-list ""))))
2775 (defun comint-unquote-filename (filename)
2777 (if (null comint-file-name-quote-list)
2787 (defun comint-dynamic-complete ()
2789 Calls the functions in `comint-dynamic-complete-functions' to perform
2793 (run-hook-with-args-until-success 'comint-dynamic-complete-functions))
2796 (defun comint-dynamic-complete-filename ()
2798 Completes if after a filename. See `comint-match-partial-filename' and
2799 `comint-dynamic-complete-as-filename'.
2800 This function is similar to `comint-replace-by-expanded-filename', except that
2805 Completion is dependent on the value of `comint-completion-addsuffix',
2806 `comint-completion-recexact' and `comint-completion-fignore', and the timing of
2807 completions listing is dependent on the value of `comint-completion-autolist'.
2811 (when (comint-match-partial-filename)
2814 (comint-dynamic-complete-as-filename)))
2816 (defun comint-dynamic-complete-as-filename ()
2818 See `comint-dynamic-complete-filename'. Returns t if successful."
2820 (completion-ignored-extensions comint-completion-fignore)
2827 (dirsuffix (cond ((not comint-completion-addsuffix)
2829 ((not (consp comint-completion-addsuffix))
2832 (car comint-completion-addsuffix))))
2833 (filesuffix (cond ((not comint-completion-addsuffix)
2835 ((not (consp comint-completion-addsuffix))
2838 (cdr comint-completion-addsuffix))))
2839 (filename (or (comint-match-partial-filename) ""))
2842 (directory (if filedir (comint-directory filedir) default-directory))
2852 (comint-dynamic-list-filename-completions))
2855 (insert (comint-quote-filename
2863 ((and comint-completion-recexact comint-completion-addsuffix
2870 ((or comint-completion-autolist
2873 (comint-dynamic-list-filename-completions))
2880 (defun comint-replace-by-expanded-filename ()
2887 `comint-dynamic-complete-filename'."
2889 (let ((filename (comint-match-partial-filename)))
2892 (comint-dynamic-complete-filename))))
2895 (defun comint-dynamic-simple-complete (stub candidates)
2907 See also `comint-dynamic-complete-filename'."
2909 (suffix (cond ((not comint-completion-addsuffix) "")
2910 ((not (consp comint-completion-addsuffix)) " ")
2911 (t (cdr comint-completion-addsuffix))))
2928 (cond ((and comint-completion-recexact comint-completion-addsuffix
2935 ((or comint-completion-autolist
2938 (comint-dynamic-list-completions completions)
2945 (defun comint-dynamic-list-filename-completions ()
2953 (filename (or (comint-match-partial-filename) ""))
2956 (directory (if filedir (comint-directory filedir) default-directory))
2960 (comint-dynamic-list-completions
2961 (mapcar 'comint-quote-filename completions)))))
2967 (defvar comint-displayed-dynamic-completions nil)
2969 (defvar comint-dynamic-list-completions-config nil)
2971 (defun comint-dynamic-list-completions (completions)
2988 (buffer-local-value 'comint-displayed-dynamic-completions
3001 (setq comint-dynamic-list-completions-config
3010 (set (make-local-variable 'comint-displayed-dynamic-completions)
3022 (set-window-configuration comint-dynamic-list-completions-config))
3024 (set-window-configuration comint-dynamic-list-completions-config)
3029 (defun comint-get-next-from-history ()
3034 (if comint-save-input-ring-index
3036 (setq comint-input-ring-index (1+ comint-save-input-ring-index))
3037 (comint-next-input 1))
3040 (defun comint-accumulate ()
3043 to be sent along with this line. Use \\[comint-send-input]
3049 (set-marker comint-accum-marker (point))
3050 (if comint-input-ring-index
3051 (setq comint-save-input-ring-index
3052 (- comint-input-ring-index 1))))
3054 (defun comint-goto-process-mark ()
3065 (defun comint-bol-or-process-mark ()
3074 used \\[comint-accumulate] to send multiple lines at once,
3077 (if (not (eq last-command 'comint-bol-or-process-mark))
3078 (comint-bol nil)
3079 (comint-goto-process-mark)))
3081 (defun comint-set-process-mark ()
3093 ;; This little add-on for comint is intended to make it easy to get
3094 ;; output from currently active comint buffers into another buffer,
3095 ;; or buffers, and then go back to using the comint shell.
3098 ;; query using the process associated with a comint-buffer, and save that
3105 ;; The basic implementation is as follows: comint-redirect changes the
3106 ;; preoutput filter functions (`comint-preoutput-filter-functions') to use
3109 ;; this is the prompt for the interpreter, `comint-prompt-regexp'). When it
3111 ;; `comint-redirect-hook'.
3113 ;; Each comint buffer may only use one redirection at a time, but any number
3114 ;; of different comint buffers may be simultaneously redirected.
3116 ;; NOTE: It is EXTREMELY important that `comint-prompt-regexp' be set to the
3120 ;; a prompt in the comint buffer; however, it is still important to ensure that
3123 ;; XXX: This doesn't work so well unless `comint-prompt-regexp' is set;
3128 ;; `comint-use-prompt-regexp' is true.
3134 (defcustom comint-redirect-verbose nil
3137 :group 'comint
3140 ;; Directly analagous to comint-preoutput-filter-functions
3141 (defvar comint-redirect-filter-functions nil
3157 (defvar comint-redirect-output-buffer nil
3160 (defvar comint-redirect-finished-regexp nil
3165 (defvar comint-redirect-insert-matching-regexp nil
3167 More precisely, the text that matches `comint-redirect-finished-regexp'
3171 (defvar comint-redirect-echo-input nil
3174 (defvar comint-redirect-completed nil
3177 (defvar comint-redirect-original-mode-line-process nil
3180 (defvar comint-redirect-perform-sanity-check t
3183 regular expression `comint-redirect-finished-regexp' that controls
3189 (defvar comint-redirect-original-filter-function nil
3194 (defvar comint-redirect-subvert-readonly nil
3195 "Non-nil means `comint-redirect' can insert into read-only buffers.
3204 (defun comint-redirect-setup (output-buffer
3205 comint-buffer
3209 This function sets local variables that are used by `comint-redirect-filter'
3218 This function is called by `comint-redirect-send-command-to-process',
3220 (with-current-buffer comint-buffer
3222 (make-local-variable 'comint-redirect-original-mode-line-process)
3223 (setq comint-redirect-original-mode-line-process mode-line-process)
3225 (make-local-variable 'comint-redirect-output-buffer)
3226 (setq comint-redirect-output-buffer output-buffer)
3228 (make-local-variable 'comint-redirect-finished-regexp)
3229 (setq comint-redirect-finished-regexp finished-regexp)
3231 (make-local-variable 'comint-redirect-echo-input)
3232 (setq comint-redirect-echo-input echo-input)
3234 (make-local-variable 'comint-redirect-completed)
3235 (setq comint-redirect-completed nil)
3242 (defun comint-redirect-cleanup ()
3243 "End a Comint redirection. See `comint-redirect-send-command'."
3247 comint-redirect-original-filter-function)
3249 (setq mode-line-process comint-redirect-original-mode-line-process)
3251 (setq comint-redirect-completed t))
3255 (defalias 'comint-redirect-remove-redirection 'comint-redirect-cleanup)
3257 (defun comint-redirect-filter (process input-string)
3259 The variable `comint-redirect-output-buffer' says which buffer(s) to
3268 (comint-redirect-preoutput-filter input-string)
3270 (and comint-redirect-echo-input
3271 comint-redirect-original-filter-function
3272 (funcall comint-redirect-original-filter-function
3276 (defun comint-redirect-preoutput-filter (input-string)
3278 The variable `comint-redirect-output-buffer' says which buffer(s) to
3285 (if (listp comint-redirect-output-buffer)
3286 comint-redirect-output-buffer
3287 (list comint-redirect-output-buffer)))
3291 (let ((functions comint-redirect-filter-functions))
3296 (let ((functions (default-value 'comint-redirect-filter-functions)))
3305 ;; Clobber `comint-redirect-finished-regexp'
3306 (or comint-redirect-insert-matching-regexp
3307 (and (string-match comint-redirect-finished-regexp filtered-input-string)
3319 (let ((inhibit-read-only comint-redirect-subvert-readonly))
3323 (and comint-redirect-verbose
3330 (and (string-match comint-redirect-finished-regexp input-string)
3332 (and comint-redirect-verbose
3334 (comint-redirect-cleanup)
3335 (run-hooks 'comint-redirect-hook)))
3337 (if comint-redirect-echo-input
3342 (defun comint-redirect-send-command (command output-buffer echo &optional no-display)
3350 (comint-redirect-send-command-to-process
3355 (defun comint-redirect-send-command-to-process
3371 (and comint-redirect-perform-sanity-check
3374 (or (re-search-backward comint-prompt-regexp nil t)
3375 (error "No prompt found or `comint-prompt-regexp' not set properly"))))
3380 (comint-redirect-setup
3386 comint-prompt-regexp
3394 (setq comint-redirect-original-filter-function
3396 (set-process-filter proc 'comint-redirect-filter)
3416 (defun comint-redirect-results-list (command regexp regexp-group)
3420 (comint-redirect-results-list-from-process
3425 (defun comint-redirect-results-list-from-process (process command regexp regexp-group)
3434 (comint-redirect-send-command-to-process command
3438 (while (null comint-redirect-completed)
3464 ;; Converting process modes to use comint mode
3466 ;; The code in the Emacs 19 distribution has all been modified to use comint
3474 ;; last-input-start comint-last-input-start
3475 ;; last-input-end comint-last-input-end
3476 ;; shell-prompt-pattern comint-prompt-regexp
3480 ;; shell-mode-map comint-mode-map
3482 ;; shell-send-input comint-send-input
3483 ;; shell-send-eof comint-delchar-or-maybe-eof
3484 ;; kill-shell-input comint-kill-input
3485 ;; interrupt-shell-subjob comint-interrupt-subjob
3486 ;; stop-shell-subjob comint-stop-subjob
3487 ;; quit-shell-subjob comint-quit-subjob
3488 ;; kill-shell-subjob comint-kill-subjob
3489 ;; kill-output-from-shell comint-delete-output
3490 ;; show-output-from-shell comint-show-output
3491 ;; copy-last-shell-input Use comint-previous-input/comint-next-input
3494 ;; SHELL-DIRECTORY-TRACKER, the shell mode's comint-input-filter-functions.
3498 ;; comint-last-input-start is provided for modes which want to munge
3502 ;; but you should think twice before using comint-last-input-start
3506 ;; *not* create the comint-mode local variables in your foo-mode function.
3507 ;; This is not modular. Instead, call comint-mode, and let *it* create the
3508 ;; necessary comint-specific local variables. Then create the
3510 ;; be foo-mode-map, and its mode to be foo-mode. Set the comint-mode hooks
3511 ;; (comint-{prompt-regexp, input-filter, input-filter-functions,
3513 ;; foo-mode-hook, and you're done. Don't run the comint-mode hook yourself;
3514 ;; comint-mode will take care of it. The following example, from shell.el,
3519 ;; (setq shell-mode-map (copy-keymap comint-mode-map))
3522 ;; (define-key shell-mode-map "\t" 'comint-dynamic-complete)
3524 ;; 'comint-dynamic-list-filename-completions)))
3528 ;; (comint-mode)
3529 ;; (setq comint-prompt-regexp shell-prompt-pattern)
3535 ;; (add-hook 'comint-input-filter-functions 'shell-directory-tracker)
3539 ;; Completion for comint-mode users
3541 ;; For modes that use comint-mode, comint-dynamic-complete-functions is the
3544 ;; You could use comint-dynamic-simple-complete to do the bulk of the
3549 (provide 'comint)
3552 ;;; comint.el ends here