Function: term-mode
term-mode is an interactive and byte-compiled function defined in
term.el.gz.
Signature
(term-mode)
Documentation
Major mode for interacting with an inferior interpreter.
The interpreter name is same as buffer name, sans the asterisks.
There are two submodes: line mode and char mode. By default, you are
in char mode. In char sub-mode, each character (except
term-escape-char) is sent immediately to the subprocess.
The escape character is equivalent to the usual meaning of C-x.
In line mode, you send a line of input at a time; use
M-x term-send-input (term-send-input) to send.
In line mode, this maintains an input history of size
term-input-ring-size, and you can access it with the commands
M-x term-next-input (term-next-input), M-x term-previous-input (term-previous-input), and
M-x term-dynamic-list-input-ring (term-dynamic-list-input-ring). Input ring history expansion can be
achieved with the commands M-x term-replace-by-expanded-history (term-replace-by-expanded-history) or
M-x term-magic-space (term-magic-space). Input ring expansion is controlled by the
variable term-input-autoexpand, and addition is controlled by the
variable term-input-ignoredups.
Input to, and output from, the subprocess can cause the window to scroll to
the end of the buffer. See variables term-scroll-to-bottom-on-input,
and term-scroll-to-bottom-on-output.
If you accidentally suspend your process, use M-x term-continue-subjob (term-continue-subjob)
to continue it.
This mode can be customized to create specific modes for running
particular subprocesses. This can be done by setting the hooks
term-input-filter-functions, term-input-filter,
term-input-sender and term-get-old-input to appropriate functions,
and the variable term-prompt-regexp to the appropriate regular
expression.
Commands in raw mode:
<backspace> term-send-backspace
<delete> term-send-del
<deletechar> term-send-del
<down> term-send-down
<end> term-send-end
<home> term-send-home
<insert> term-send-insert
<left> term-send-left
<mouse-2> term-mouse-paste
<next> term-send-next
<prior> term-send-prior
<right> term-send-right
<up> term-send-up
<xterm-paste> term--xterm-paste
C-/ term-send-C-_
C-<down> term-send-ctrl-down
C-<left> term-send-ctrl-left
C-<right> term-send-ctrl-right
C-<up> term-send-ctrl-up
C-c # server-edit
C-c $ set-selective-display
C-c ' expand-abbrev
C-c ( kmacro-start-macro
C-c ) kmacro-end-macro
C-c * calc-dispatch
C-c + balance-windows
C-c - shrink-window-if-larger-than-buffer
C-c . set-fill-prefix
C-c 0 delete-window
C-c 1 delete-other-windows
C-c 2 split-window-below
C-c 3 split-window-right
C-c 4 . xref-find-definitions-other-window
C-c 4 0 kill-buffer-and-window
C-c 4 1 same-window-prefix
C-c 4 4 other-window-prefix
C-c 4 C-f find-file-other-window
C-c 4 C-j dired-jump-other-window
C-c 4 C-o display-buffer
C-c 4 a add-change-log-entry-other-window
C-c 4 b switch-to-buffer-other-window
C-c 4 c clone-indirect-buffer-other-window
C-c 4 d dired-other-window
C-c 4 f find-file-other-window
C-c 4 m compose-mail-other-window
C-c 4 p project-other-window-command
C-c 4 r find-file-read-only-other-window
C-c 5 . xref-find-definitions-other-frame
C-c 5 0 delete-frame
C-c 5 1 delete-other-frames
C-c 5 2 make-frame-command
C-c 5 5 other-frame-prefix
C-c 5 C-f find-file-other-frame
C-c 5 C-o display-buffer-other-frame
C-c 5 b switch-to-buffer-other-frame
C-c 5 c clone-frame
C-c 5 d dired-other-frame
C-c 5 f find-file-other-frame
C-c 5 m compose-mail-other-frame
C-c 5 o other-frame
C-c 5 p project-other-frame-command
C-c 5 r find-file-read-only-other-frame
C-c 6 2 2C-two-columns
C-c 6 <f2> 2C-two-columns
C-c 6 b 2C-associate-buffer
C-c 6 s 2C-split
C-c 8 RET insert-char
C-c ; comment-set-column
C-c < scroll-left
C-c <left> previous-buffer
C-c <right> next-buffer
C-c = what-cursor-position
C-c > scroll-right
C-c C-+ text-scale-adjust
C-c C-- text-scale-adjust
C-c C-0 text-scale-adjust
C-c C-; comment-line
C-c C-<left> previous-buffer
C-c C-<right> next-buffer
C-c C-= text-scale-adjust
C-c C-@ pop-global-mark
C-c C-SPC pop-global-mark
C-c C-a C-l gud-refresh
C-c C-a C-w gud-watch
C-c C-b list-buffers
C-c C-c save-buffers-kill-terminal
C-c C-c term-send-raw
C-c C-d list-directory
C-c C-e eval-last-sexp
C-c C-f find-file
C-c C-j dired-jump
C-c C-j term-line-mode
C-c C-k term-char-mode
C-c C-k C-a kmacro-add-counter
C-c C-k C-c kmacro-set-counter
C-c C-k C-d kmacro-delete-ring-head
C-c C-k C-e kmacro-edit-macro-repeat
C-c C-k C-f kmacro-set-format
C-c C-k C-k kmacro-end-or-call-macro-repeat
C-c C-k C-l kmacro-call-ring-2nd-repeat
C-c C-k C-n kmacro-cycle-ring-next
C-c C-k C-p kmacro-cycle-ring-previous
C-c C-k C-s kmacro-start-macro
C-c C-k C-t kmacro-swap-ring
C-c C-k C-v kmacro-view-macro-repeat
C-c C-k RET kmacro-edit-macro
C-c C-k SPC kmacro-step-edit-macro
C-c C-k TAB kmacro-insert-counter
C-c C-k b kmacro-bind-to-key
C-c C-k d kmacro-redisplay
C-c C-k e edit-kbd-macro
C-c C-k l kmacro-edit-lossage
C-c C-k n kmacro-name-last-macro
C-c C-k q kbd-macro-query
C-c C-k r apply-macro-to-region-lines
C-c C-k s kmacro-start-macro
C-c C-k x kmacro-to-register
C-c C-l downcase-region
C-c C-n set-goal-column
C-c C-o delete-blank-lines
C-c C-p C-a pages-add-new-page
C-c C-p C-d pages-directory
C-c C-p C-l pages-set-delimiter
C-c C-p C-n pages-next-page
C-c C-p C-p pages-previous-page
C-c C-p C-s pages-search
C-c C-p RET mark-page
C-c C-p d pages-directory-for-addresses
C-c C-p s pages-sort-buffer
C-c C-q read-only-mode
C-c C-q term-pager-toggle
C-c C-r find-file-read-only
C-c C-s save-buffer
C-c C-t transpose-lines
C-c C-u universal-argument
C-c C-u upcase-region
C-c C-v find-alternate-file
C-c C-v scroll-up-command
C-c C-w write-file
C-c C-x exchange-point-and-mark
C-c C-z suspend-frame
C-c DEL backward-kill-sentence
C-c ESC ESC repeat-complex-command
C-c M-: repeat-complex-command
C-c M-g magit-dispatch
C-c M-x execute-extended-command
C-c RET C-\ set-input-method
C-c RET F set-file-name-coding-system
C-c RET X set-next-selection-coding-system
C-c RET c universal-coding-system-argument
C-c RET f set-buffer-file-coding-system
C-c RET k set-keyboard-coding-system
C-c RET l set-language-environment
C-c RET p set-buffer-process-coding-system
C-c RET r revert-buffer-with-coding-system
C-c RET t set-terminal-coding-system
C-c RET x set-selection-coding-system
C-c SPC rectangle-mark-mode(var)/rectangle-mark-mode(fun)
C-c TAB indent-rigidly
C-c X = edebug-display-freq-count
C-c X C edebug-Continue-fast-mode
C-c X D edebug-toggle-disable-breakpoint
C-c X G edebug-Go-nonstop-mode
C-c X Q edebug-top-level-nonstop
C-c X SPC edebug-step-mode
C-c X T edebug-Trace-fast-mode
C-c X U edebug-unset-breakpoints
C-c X W edebug-toggle-save-windows
C-c X X edebug-set-global-break-condition
C-c X a abort-recursive-edit
C-c X b edebug-set-breakpoint
C-c X c edebug-continue-mode
C-c X g edebug-go-mode
C-c X q top-level(var)/top-level(fun)
C-c X t edebug-trace-mode
C-c X u edebug-unset-breakpoint
C-c X w edebug-where
C-c X x edebug-set-conditional-breakpoint
C-c [ backward-page
C-c \ activate-transient-input-method
C-c ] forward-page
C-c ^ enlarge-window
C-c ` next-error
C-c a ' expand-abbrev
C-c a + add-mode-abbrev
C-c a - inverse-add-global-abbrev
C-c a C-a add-mode-abbrev
C-c a e expand-abbrev
C-c a g add-global-abbrev
C-c a i g inverse-add-global-abbrev
C-c a i l inverse-add-mode-abbrev
C-c a l add-mode-abbrev
C-c a n expand-jump-to-next-slot
C-c a p expand-jump-to-previous-slot
C-c b switch-to-buffer
C-c d dired
C-c e kmacro-end-and-call-macro
C-c f set-fill-column
C-c g magit-status
C-c h mark-whole-buffer
C-c i insert-file
C-c k kill-buffer
C-c l count-lines-page
C-c m compose-mail
C-c n d narrow-to-defun
C-c n g goto-line-relative
C-c n n narrow-to-region
C-c n p narrow-to-page
C-c n w widen
C-c o other-window
C-c p ! project-shell-command
C-c p & project-async-shell-command
C-c p D project-dired
C-c p F project-or-external-find-file
C-c p G project-or-external-find-regexp
C-c p b project-switch-to-buffer
C-c p c project-compile
C-c p d project-find-dir
C-c p e project-eshell
C-c p f project-find-file
C-c p g project-find-regexp
C-c p k project-kill-buffers
C-c p m magit-project-status
C-c p p project-switch-project
C-c p r project-query-replace-regexp
C-c p s project-shell
C-c p v project-vc-dir
C-c p x project-execute-extended-command
C-c q kbd-macro-query
C-c r + increment-register
C-c r C-@ point-to-register
C-c r C-SPC point-to-register
C-c r M bookmark-set-no-overwrite
C-c r M-w copy-rectangle-as-kill
C-c r N rectangle-number-lines
C-c r SPC point-to-register
C-c r b bookmark-jump
C-c r c clear-rectangle
C-c r d delete-rectangle
C-c r f frameset-to-register
C-c r g insert-register
C-c r i insert-register
C-c r j jump-to-register
C-c r k kill-rectangle
C-c r l bookmark-bmenu-list
C-c r m bookmark-set
C-c r n number-to-register
C-c r o open-rectangle
C-c r r copy-rectangle-to-register
C-c r s copy-to-register
C-c r t string-rectangle
C-c r w window-configuration-to-register
C-c r x copy-to-register
C-c r y yank-rectangle
C-c s save-some-buffers
C-c t 0 tab-close
C-c t 1 tab-close-other
C-c t 2 tab-new
C-c t C-f find-file-other-tab
C-c t C-r find-file-read-only-other-tab
C-c t G tab-group
C-c t M tab-move-to
C-c t N tab-new-to
C-c t O tab-previous
C-c t RET tab-switch
C-c t b switch-to-buffer-other-tab
C-c t d dired-other-tab
C-c t f find-file-other-tab
C-c t m tab-move
C-c t n tab-duplicate
C-c t o tab-next
C-c t p project-other-tab-command
C-c t r tab-rename
C-c t t other-tab-prefix
C-c t u tab-undo
C-c u undo
C-c v + vc-update
C-c v = vc-diff
C-c v D vc-root-diff
C-c v G vc-ignore
C-c v I vc-log-incoming
C-c v L vc-print-root-log
C-c v M D vc-diff-mergebase
C-c v M L vc-log-mergebase
C-c v O vc-log-outgoing
C-c v P vc-push
C-c v a vc-update-change-log
C-c v b vc-switch-backend
C-c v d vc-dir
C-c v g vc-annotate
C-c v h vc-region-history
C-c v i vc-register
C-c v l vc-print-log
C-c v m vc-merge
C-c v r vc-retrieve-tag
C-c v s vc-create-tag
C-c v u vc-revert
C-c v v vc-next-action
C-c v x vc-delete-file
C-c v ~ vc-revision-other-window
C-c x f font-lock-update
C-c x g revert-buffer-quick
C-c x i insert-buffer
C-c x n clone-buffer
C-c x r rename-buffer
C-c x t toggle-truncate-lines
C-c x u rename-uniquely
C-c z repeat
C-c { shrink-window-horizontally
C-c } enlarge-window-horizontally
C-c ~ vi-switch-mode
ESC ..\x3FFFFF term-send-raw-meta
ESC ..\x3FFFFF term-send-raw-meta
ESC ..\x3FFFFF term-send-raw-meta
S-<insert> term-paste
S-<next> scroll-up
S-<prior> scroll-down
SPC..~ term-send-raw
..\x3FFFFF term-send-raw
..\x3FFFFF term-send-raw
..\x3FFFFF term-send-raw
Commands in line mode:
A-M-r term-previous-matching-input-from-input
A-M-s term-next-matching-input-from-input
C-M-l term-show-output
C-c C-\ term-quit-subjob
C-c C-a term-bol
C-c C-c term-interrupt-subjob
C-c C-d term-send-eof
C-c C-e term-show-maximum-output
C-c C-j term-line-mode
C-c C-k term-char-mode
C-c C-l term-dynamic-list-input-ring
C-c C-n term-next-prompt
C-c C-o term-kill-output
C-c C-p term-previous-prompt
C-c C-q term-pager-toggle
C-c C-r term-show-output
C-c C-u term-kill-input
C-c C-w backward-kill-word
C-c C-z term-stop-subjob
C-c RET term-copy-old-input
C-d term-delchar-or-maybe-eof
M-n term-next-input
M-p term-previous-input
M-r term-previous-matching-input
M-s term-next-matching-input
RET term-send-input
Entry to this mode runs the hooks on term-mode-hook.
Probably introduced at or before Emacs version 28.1.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/term.el.gz
(define-derived-mode term-mode fundamental-mode "Term"
"Major mode for interacting with an inferior interpreter.
The interpreter name is same as buffer name, sans the asterisks.
There are two submodes: line mode and char mode. By default, you are
in char mode. In char sub-mode, each character (except
`term-escape-char') is sent immediately to the subprocess.
The escape character is equivalent to the usual meaning of C-x.
In line mode, you send a line of input at a time; use
\\[term-send-input] to send.
In line mode, this maintains an input history of size
`term-input-ring-size', and you can access it with the commands
\\[term-next-input], \\[term-previous-input], and
\\[term-dynamic-list-input-ring]. Input ring history expansion can be
achieved with the commands \\[term-replace-by-expanded-history] or
\\[term-magic-space]. Input ring expansion is controlled by the
variable `term-input-autoexpand', and addition is controlled by the
variable `term-input-ignoredups'.
Input to, and output from, the subprocess can cause the window to scroll to
the end of the buffer. See variables `term-scroll-to-bottom-on-input',
and `term-scroll-to-bottom-on-output'.
If you accidentally suspend your process, use \\[term-continue-subjob]
to continue it.
This mode can be customized to create specific modes for running
particular subprocesses. This can be done by setting the hooks
`term-input-filter-functions', `term-input-filter',
`term-input-sender' and `term-get-old-input' to appropriate functions,
and the variable `term-prompt-regexp' to the appropriate regular
expression.
Commands in raw mode:
\\{term-raw-map}
Commands in line mode:
\\{term-mode-map}
Entry to this mode runs the hooks on `term-mode-hook'."
;; we do not want indent to sneak in any tabs
(setq indent-tabs-mode nil)
(setq buffer-display-table term-display-table)
(setq-local term-home-marker (copy-marker 0))
(setq-local term-height (floor (window-screen-lines)))
(setq-local term-width (window-max-chars-per-line))
(setq-local term-last-input-start (make-marker))
(setq-local term-last-input-end (make-marker))
(setq-local term-last-input-match "")
;; These local variables are set to their local values:
(make-local-variable 'term-saved-home-marker)
(make-local-variable 'term-saved-cursor)
(make-local-variable 'term-prompt-regexp)
(make-local-variable 'term-input-ring-size)
(make-local-variable 'term-input-ring)
(make-local-variable 'term-input-ring-file-name)
(make-local-variable 'term-input-ring-index)
(unless term-input-ring
(setq term-input-ring (make-ring term-input-ring-size)))
;; I'm not sure these saves are necessary but, since I
;; haven't tested the whole thing on a net connected machine with
;; a properly configured ange-ftp, I've decided to be conservative
;; and put them in. -mm
(setq-local term-ansi-at-host (system-name))
(setq-local term-ansi-at-dir default-directory)
(setq-local term-ansi-at-message nil)
;; For user tracking purposes -mm
(make-local-variable 'ange-ftp-default-user)
(make-local-variable 'ange-ftp-default-password)
(make-local-variable 'ange-ftp-generate-anonymous-password)
;; You may want to have different scroll-back sizes -mm
(make-local-variable 'term-buffer-maximum-size)
;; Of course these have to be buffer-local -mm
(make-local-variable 'term-ansi-current-bold)
(make-local-variable 'term-ansi-current-color)
(make-local-variable 'term-ansi-face-already-done)
(make-local-variable 'term-ansi-current-bg-color)
(make-local-variable 'term-ansi-current-underline)
(make-local-variable 'term-ansi-current-reverse)
(make-local-variable 'term-ansi-current-invisible)
(make-local-variable 'term-terminal-undecoded-bytes)
(make-local-variable 'term-do-line-wrapping)
(make-local-variable 'term-kill-echo-list)
(make-local-variable 'term-start-line-column)
(make-local-variable 'term-current-column)
(make-local-variable 'term-current-row)
(make-local-variable 'term-log-buffer)
(make-local-variable 'term-pager-count)
(make-local-variable 'term-pager-old-local-map)
(make-local-variable 'term-old-mode-map)
(make-local-variable 'term-insert-mode)
(make-local-variable 'term-completion-fignore)
(make-local-variable 'term-get-old-input)
(make-local-variable 'term-matching-input-from-input-string)
(make-local-variable 'term-input-autoexpand)
(make-local-variable 'term-input-ignoredups)
(make-local-variable 'term-delimiter-argument-list)
(make-local-variable 'term-input-filter)
(make-local-variable 'term-input-sender)
(make-local-variable 'term-eol-on-send)
(make-local-variable 'term-scroll-to-bottom-on-output)
(make-local-variable 'term-scroll-show-maximum-output)
(make-local-variable 'term-ptyp)
(setq-local term-vertical-motion 'vertical-motion)
(setq-local term-pending-delete-marker (make-marker))
(make-local-variable 'term-current-face)
(term-ansi-reset)
(add-hook 'menu-bar-update-hook 'term--update-term-menu)
(setq-local term-pending-frame nil)
;; Cua-mode's keybindings interfere with the term keybindings, disable it.
(setq-local cua-mode nil)
(setq-local font-lock-defaults '(nil t))
(add-function :filter-return
(local 'filter-buffer-substring-function)
#'term--filter-buffer-substring)
(add-function :filter-return
(local 'window-adjust-process-window-size-function)
(lambda (size)
(when size
(term-reset-size (cdr size) (car size)))
size)
'((name . term-maybe-reset-size)))
(add-hook 'read-only-mode-hook #'term-line-mode-buffer-read-only-update nil t)
(term--reset-scroll-region)
(or term-input-ring
(setq term-input-ring (make-ring term-input-ring-size)))
(term-update-mode-line))