Function: ansi-term
ansi-term is an autoloaded, interactive and byte-compiled function
defined in term.el.gz.
Signature
(ansi-term PROGRAM &optional NEW-BUFFER-NAME)
Documentation
Start a terminal-emulator in a new buffer.
This is almost the same as term apart from always creating a new buffer,
and \C-x being marked as a term-escape-char.
Probably introduced at or before Emacs version 28.1.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/term.el.gz
;;;###autoload
(defun ansi-term (program &optional new-buffer-name)
"Start a terminal-emulator in a new buffer.
This is almost the same as `term' apart from always creating a new buffer,
and \\`C-x' being marked as a `term-escape-char'."
(interactive (list (read-from-minibuffer "Run program: "
(or explicit-shell-file-name
(getenv "ESHELL")
shell-file-name))))
;; Pick the name of the new buffer.
(setq term-ansi-buffer-name
(if new-buffer-name
new-buffer-name
(if term-ansi-buffer-base-name
(if (eq term-ansi-buffer-base-name t)
(file-name-nondirectory program)
term-ansi-buffer-base-name)
"ansi-term")))
(setq term-ansi-buffer-name (concat "*" term-ansi-buffer-name "*"))
;; In order to have more than one term active at a time
;; I'd like to have the term names have the *term-ansi-term<?>* form,
;; for now they have the *term-ansi-term*<?> form but we'll see...
(setq term-ansi-buffer-name (generate-new-buffer-name term-ansi-buffer-name))
(let ((prog (split-string-shell-command program)))
(setq term-ansi-buffer-name
(apply #'term-ansi-make-term term-ansi-buffer-name (car prog)
nil (cdr prog))))
(set-buffer term-ansi-buffer-name)
(term-mode)
(term-char-mode)
;; Historical baggage. A call to term-set-escape-char used to not
;; undo any previous call to t-s-e-c. Because of this, ansi-term
;; ended up with both C-x and C-c as escape chars. Who knows what
;; the original intention was, but people could have become used to
;; either. (Bug#12842)
(let (term-escape-char)
;; I wanna have find-file on C-x C-f -mm
;; your mileage may definitely vary, maybe it's better to put this in your
;; .emacs ...
(term-set-escape-char ?\C-x))
(switch-to-buffer term-ansi-buffer-name))