Function: comint-mode

comint-mode is an interactive and byte-compiled function defined in comint.el.gz.

Signature

(comint-mode)

Documentation

Major mode for interacting with an inferior interpreter.

Interpreter name is same as buffer name, sans the asterisks. Return at end of buffer sends line as input. Return not at end copies rest of line to end and sends it. Setting variable comint-eol-on-send means jump to the end of the line before submitting new input.

This mode is customized to create major modes such as Inferior Lisp mode, Shell mode, etc. This can be done by setting the hooks comint-input-filter-functions, comint-input-filter, comint-input-sender and comint-get-old-input to appropriate functions, and the variable comint-prompt-regexp to the appropriate regular expression.

The mode maintains an input history of size comint-input-ring-size. You can access this with the commands M-x comint-next-input (comint-next-input), M-x comint-previous-input (comint-previous-input), and M-x comint-dynamic-list-input-ring (comint-dynamic-list-input-ring). Input ring history expansion can be achieved with the commands M-x comint-replace-by-expanded-history (comint-replace-by-expanded-history) or M-x comint-magic-space (comint-magic-space). Input ring expansion is controlled by the variable comint-input-autoexpand, and addition is controlled by the variable comint-input-ignoredups.

Commands with no default key bindings include comint-send-invisible, completion-at-point, comint-dynamic-list-filename-completions, and comint-magic-space.

Input to, and output from, the subprocess can cause the window to scroll to the end of the buffer. See variables comint-output-filter-functions, comint-preoutput-filter-functions, comint-scroll-to-bottom-on-input, and comint-move-point-for-output.

If you accidentally suspend your process, use M-x comint-continue-subjob (comint-continue-subjob) to continue it.

<delete> delete-forward-char
<kp-delete> delete-forward-char
<mouse-2> comint-insert-input
C-<down> comint-next-input
C-<up> comint-previous-input
C-M-l comint-show-output
C-c . comint-insert-previous-argument
C-c C-\ comint-quit-subjob
C-c C-a comint-bol-or-process-mark
C-c C-c comint-interrupt-subjob
C-c C-d comint-send-eof
C-c C-e comint-show-maximum-output
C-c C-l comint-dynamic-list-input-ring
C-c C-n comint-next-prompt
C-c C-o comint-delete-output
C-c C-p comint-previous-prompt
C-c C-r comint-show-output
C-c C-s comint-write-output
C-c C-u comint-kill-input
C-c C-w backward-kill-word
C-c C-x comint-get-next-from-history
C-c C-z comint-stop-subjob
C-c M-o comint-clear-buffer
C-c M-r comint-previous-matching-input-from-input
C-c M-s comint-next-matching-input-from-input
C-c RET comint-copy-old-input
C-c SPC comint-accumulate
C-d comint-delchar-or-maybe-eof
M-n comint-next-input
M-p comint-previous-input
M-r comint-history-isearch-backward-regexp
RET comint-send-input

Entry to this mode runs the hooks on comint-mode-hook.

Probably introduced at or before Emacs version 19.20.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/comint.el.gz
(define-derived-mode comint-mode fundamental-mode "Comint"
  "Major mode for interacting with an inferior interpreter.
Interpreter name is same as buffer name, sans the asterisks.
Return at end of buffer sends line as input.
Return not at end copies rest of line to end and sends it.
Setting variable `comint-eol-on-send' means jump to the end of the line
before submitting new input.

This mode is customized to create major modes such as Inferior Lisp
mode, Shell mode, etc.  This can be done by setting the hooks
`comint-input-filter-functions', `comint-input-filter', `comint-input-sender'
and `comint-get-old-input' to appropriate functions, and the variable
`comint-prompt-regexp' to the appropriate regular expression.

The mode maintains an input history of size `comint-input-ring-size'.
You can access this with the commands \\[comint-next-input],
\\[comint-previous-input], and \\[comint-dynamic-list-input-ring].
Input ring history expansion can be achieved with the commands
\\[comint-replace-by-expanded-history] or \\[comint-magic-space].
Input ring expansion is controlled by the variable `comint-input-autoexpand',
and addition is controlled by the variable `comint-input-ignoredups'.

Commands with no default key bindings include `comint-send-invisible',
`completion-at-point', `comint-dynamic-list-filename-completions', and
`comint-magic-space'.

Input to, and output from, the subprocess can cause the window to scroll to
the end of the buffer.  See variables `comint-output-filter-functions',
`comint-preoutput-filter-functions', `comint-scroll-to-bottom-on-input',
and `comint-move-point-for-output'.

If you accidentally suspend your process, use \\[comint-continue-subjob]
to continue it.

\\{comint-mode-map}

Entry to this mode runs the hooks on `comint-mode-hook'."
  (setq mode-line-process
        (list (propertize ":%s" 'help-echo "Process status")))
  (setq-local window-point-insertion-type t)
  (setq-local comint-last-input-start (point-min-marker))
  (setq-local comint-last-input-end (point-min-marker))
  (setq-local comint-last-output-start (make-marker))
  (make-local-variable 'comint-last-prompt)
  (make-local-variable 'comint-prompt-regexp)        ; Don't set; default
  (make-local-variable 'comint-input-ring-size)      ; ...to global val.
  (make-local-variable 'comint-input-ring)
  (make-local-variable 'comint-input-ring-file-name)
  (or (and (boundp 'comint-input-ring) comint-input-ring)
      (setq comint-input-ring (make-ring comint-input-ring-size)))
  (make-local-variable 'comint-input-ring-index)
  (make-local-variable 'comint-save-input-ring-index)
  (or (and (boundp 'comint-input-ring-index) comint-input-ring-index)
      (setq comint-input-ring-index nil))
  (or (and (boundp 'comint-save-input-ring-index) comint-save-input-ring-index)
      (setq comint-save-input-ring-index nil))
  (make-local-variable 'comint-matching-input-from-input-string)
  (make-local-variable 'comint-input-autoexpand)
  (make-local-variable 'comint-input-ignoredups)
  (make-local-variable 'comint-delimiter-argument-list)
  (make-local-variable 'comint-completion-fignore)
  (make-local-variable 'comint-get-old-input)
  (make-local-variable 'comint-input-filter)
  (make-local-variable 'comint-input-sender)
  (make-local-variable 'comint-eol-on-send)
  (make-local-variable 'comint-scroll-to-bottom-on-input)
  (make-local-variable 'comint-move-point-for-output)
  (make-local-variable 'comint-scroll-show-maximum-output)
  (make-local-variable 'comint-stored-incomplete-input)
  ;; Following disabled because it seems to break the case when
  ;; comint-scroll-show-maximum-output is nil, and no-one can remember
  ;; what the original problem was.  If there are problems with point
  ;; not going to the end, consider re-enabling this.
  ;; https://lists.gnu.org/r/emacs-devel/2007-08/msg00827.html
  ;;
  ;; This makes it really work to keep point at the bottom.
  ;; (setq-local scroll-conservatively 10000)
  (add-hook 'pre-command-hook 'comint-preinput-scroll-to-bottom t t)
  (make-local-variable 'comint-ptyp)
  (make-local-variable 'comint-process-echoes)
  (make-local-variable 'comint-file-name-chars)
  (make-local-variable 'comint-file-name-quote-list)
  ;; dir tracking on remote files
  (setq-local comint-file-name-prefix
              (or (file-remote-p default-directory) ""))
  (setq-local comint-accum-marker (make-marker))
  (setq-local font-lock-defaults '(nil t))
  (add-hook 'change-major-mode-hook 'font-lock-defontify nil t)
  (add-hook 'isearch-mode-hook 'comint-history-isearch-setup nil t)
  (add-hook 'completion-at-point-functions 'comint-completion-at-point nil t)
  ;; This behavior is not useful in comint buffers, and is annoying
  (setq-local next-line-add-newlines nil))