1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>A summary of Emacs' bundled shell and terminal modes — Luke Shumaker</title>
<link rel="stylesheet" type="text/css" href="assets/style.css">
</head>
<body>
<header><a href="/">Luke Shumaker</a> » <a href=/blog>blog</a> » emacs-shells</header>
<article>
<h1 id="a-summary-of-emacs-bundled-shell-and-terminal-modes">A summary of Emacs' bundled shell and terminal modes</h1>
<p>This is based on a post on <a href="http://www.reddit.com/r/emacs/comments/1bzl8b/how_can_i_get_a_dumbersimpler_shell_in_emacs/c9blzyb">reddit</a>, published on 2013-04-09.</p>
<p>Emacs comes bundled with a few different shell and terminal modes. It can be hard to keep them straight. What's the difference between <code>M-x term</code> and <code>M-x ansi-term</code>?</p>
<p>Here's a good breakdown of the different bundled shells and terminals for Emacs, from dumbest to most Emacs-y.</p>
<h2 id="term-mode">term-mode</h2>
<p>Your VT100-esque terminal emulator; it does what most terminal programs do. Ncurses-things work OK, but dumping large amounts of text can be slow. By default it asks you which shell to run, defaulting to the environmental variable <code>$SHELL</code> (<code>/bin/bash</code> for me). There are two modes of operation:</p>
<ul>
<li>char mode: Keys are sent immediately to the shell (including keys that are normally Emacs keystrokes), with the following exceptions:</li>
<li><code>(term-escape-char) (term-escape-char)</code> sends <code>(term-escape-char)</code> to the shell (see above for what the default value is).</li>
<li><code>(term-escape-char) <anything-else></code> is like doing equates to <code>C-x <anything-else></code> in normal Emacs.</li>
<li><code>(term-escape-char) C-j</code> switches to line mode.</li>
<li>line mode: Editing is done like in a normal Emacs buffer, <code><enter></code> sends the current line to the shell. This is useful for working with a program's output.</li>
<li><code>C-c C-k</code> switches to char mode.</li>
</ul>
<p>This mode is activated with</p>
<pre><code>; Creates or switches to an existing "*terminal*" buffer.
; The default 'term-escape-char' is "C-c"
M-x term</code></pre>
<p>or</p>
<pre><code>; Creates a new "*ansi-term*" or "*ansi-term*<n>" buffer.
; The default 'term-escape-char' is "C-c" and "C-x"
M-x ansi-term</code></pre>
<h2 id="shell-mode">shell-mode</h2>
<p>The name is a misnomer; shell-mode is a terminal emulator, not a shell; it's called that because it is used for running a shell (bash, zsh, …). The idea of this mode is to use an external shell, but make it Emacs-y. History is not handled by the shell, but by Emacs; <code>M-p</code> and <code>M-n</code> access the history, while arrows/<code>C-p</code>/<code>C-n</code> move the point (which is is consistent with other Emacs REPL-type interfaces). It ignores VT100-type terminal colors, and colorizes things itself (it inspects words to see if they are directories, in the case of <code>ls</code>). This has the benefit that it does syntax highlighting on the currently being typed command. Ncurses programs will of course not work. This mode is activated with:</p>
<pre><code>M-x shell</code></pre>
<h2 id="eshell-mode">eshell-mode</h2>
<p>This is a shell+terminal, entirely written in Emacs lisp. (Interestingly, it doesn't set <code>$SHELL</code>, so that will be whatever it was when you launched Emacs). This won't even be running zsh or bash, it will be running "esh", part of Emacs.</p>
</article>
<footer>
<p>The content of this page is Copyright © 2013 <a href="mailto:lukeshu@sbcglobal.net">Luke Shumaker</a>.</p>
<p>This page is licensed under the <a href="https://creativecommons.org/licenses/by-sa/3.0/">CC BY-SA-3.0</a> license.</p>
</footer>
</body>
</html>
|