summaryrefslogtreecommitdiff
path: root/public/emacs-shells.html
blob: 66035f7a4ad8d1be4d55042d96ba0efd7a2a1a37 (plain)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>A summary of Emacs' bundled shell and terminal modes — Luke T. Shumaker</title>
  <link rel="stylesheet" href="assets/style.css">
  <link rel="alternate" type="application/atom+xml" href="./index.atom" name="web log entries"/>
</head>
<body>
<header><a href="/">Luke T. 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:
<ul>
<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) &lt;anything-else&gt;</code> is like doing
equates to <code>C-x   &lt;anything-else&gt;</code> in normal
Emacs.</li>
<li><code>(term-escape-char) C-j</code> switches to line mode.</li>
</ul></li>
<li>line mode: Editing is done like in a normal Emacs buffer,
<code>&lt;enter&gt;</code> sends the current line to the shell. This is
useful for working with a program’s output.
<ul>
<li><code>C-c C-k</code> switches to char mode.</li>
</ul></li>
</ul>
<p>This mode is activated with</p>
<pre><code>; Creates or switches to an existing &quot;*terminal*&quot; buffer.
; The default &#39;term-escape-char&#39; is &quot;C-c&quot;
M-x term</code></pre>
<p>or</p>
<pre><code>; Creates a new &quot;*ansi-term*&quot; or &quot;*ansi-term*&lt;n&gt;&quot; buffer.
; The default &#39;term-escape-char&#39; is &quot;C-c&quot; and &quot;C-x&quot;
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>
  <aside class="sponsor"><p>I'd love it if you <a class="em"
      href="/sponsor/">sponsored me</a>.  It will allow me to continue
      my work on the GNU/Linux ecosystem.  Thanks!</p></aside>

<p>The content of this page is Copyright © 2013 <a href="mailto:lukeshu@lukeshu.com">Luke T. Shumaker</a>.</p>
<p>This page is licensed under the <a href="https://creativecommons.org/licenses/by-sa/4.0/">CC BY-SA 4.0</a> license.</p>
</footer>
</body>
</html>