[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why do we need a number of different terminal modes in Emacs?

From: Robert Thorpe
Subject: Re: Why do we need a number of different terminal modes in Emacs?
Date: Sun, 01 Feb 2015 13:37:11 +0000

Andrey Lisin <address@hidden> writes:

> Hi everyone,
> could anyone explain me why do we need several of terminal
> implementations inside Emacs? Shell, eshell, term, ansi-term... And as
> far as I noticed they all suck one way or another. For example, shell
> cannot complete commands when you ssh to remote server inside it. Eshell
> tragically cannot do a very simple thing - source a bash script. Really,
> try to run `.' or `source' inside eshell.
> So, am I right and we need them all just because one solves restrictions
> of the others and others do the same thing for the one? Why then not
> just to write some standard terminal implementation, that will just
> works? Does it have something with cross-platform nature of Emacs? Or,
> maybe I'm doing something wrong and all this stuff makes sense? Thank
> you.

I'll explain the trickiness.  Shell-mode works in an Emacs-like manner.
It hooks to an external shell, such as bash, ksh or tcsh.  It transfers
*lines* to the shell.  It has to work this way, since the line is edited by
Emacs editing commands.  Emacs editing commands work exactly as they do
elsewhere in Emacs.  For example, if you do C-a in tcsh or sh it will
bring you to the beginning of the line, that's not a feature of those
shells.  You can define keymaps for any key you like.

The shell-mode system can only work for programs with line-orientated
input.  A program that responds to keys one at a time can't be handled
this way.  Shell modes doesn't even try to do this, or to deal with
programs that have text-based GUIs, like "top" or curses programs.  Type
"top" in shell and see what happens.  Notice you have to type "q RET" to
exit, not just "q".

So, we have the terminal modes: ansi-term and term.  These emulate
*terminals* imperfectly, and a shell runs under that terminal.  These
have two modes, line mode and character mode.  In line-mode they behave
like shell mode as I described above.  In character mode they relay
characters one-at-a-time to the inferior program.  You switch between
the two modes with C-c C-j and C-c C-k.  Emacs only catches a few keys,
C-x, C-c, C-num and a few other without passing them through (see C-h m
in term-mode).  You can run programs with text-based GUIs like "top" and
"emacs -nw" in terms.

For example.  Go into term mode using bash.  Type some stuff in and
press M-b & M-f to move across words.  This works in either character
mode (C-c C-k) or line mode (C-c C-k).  It works in line mode because
those are Emacs keybindings and it works in character mode because
they're bash keybindings.  Now, run another shell like dash.  Try M-b &
M-f there.  They will work in line mode but fail in character mode.

There is little difference between term and ansi-term.  In the past only
ansi-term had colours, now both do.  The prefix key is C-c in term and
C-x in ansi-term.

Eshell is a completely different thing.  It's a shell written in Emacs
Lisp.  The idea of it is that you can write lisp at the command prompt
as well as calling shell programs.  For example you can write (+ 2 3) at
the eshell prompt and it will return 5.  Eshell can't source bash scripts
because bash is nowhere in sight here.  Like shell-mode it doesn't
emulate a terminal or have a character mode, so you can't use it with
the programs that need that.

For your use I think term in line-mode would be best, switching to
character mode when necessary.

Robert Thorpe

reply via email to

[Prev in Thread] Current Thread [Next in Thread]