From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Robert Thorpe Newsgroups: gmane.emacs.help Subject: Re: Why do we need a number of different terminal modes in Emacs? Date: Sun, 01 Feb 2015 13:37:11 +0000 Message-ID: <87egq9sqgo.fsf@robertthorpeconsulting.com> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1422797861 13355 80.91.229.3 (1 Feb 2015 13:37:41 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 1 Feb 2015 13:37:41 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Andrey Lisin Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Feb 01 14:37:37 2015 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1YHuiW-0000uC-6x for geh-help-gnu-emacs@m.gmane.org; Sun, 01 Feb 2015 14:37:36 +0100 Original-Received: from localhost ([::1]:50533 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YHuiV-0003sS-Es for geh-help-gnu-emacs@m.gmane.org; Sun, 01 Feb 2015 08:37:35 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:49950) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YHuiD-0003sM-Sl for help-gnu-emacs@gnu.org; Sun, 01 Feb 2015 08:37:19 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YHuiA-0001pD-Lq for help-gnu-emacs@gnu.org; Sun, 01 Feb 2015 08:37:17 -0500 Original-Received: from outbound-smtp05.blacknight.com ([81.17.249.38]:46839) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YHuiA-0001p9-Di for help-gnu-emacs@gnu.org; Sun, 01 Feb 2015 08:37:14 -0500 Original-Received: from mail.blacknight.com (pemlinmail05.blacknight.ie [81.17.254.26]) by outbound-smtp05.blacknight.com (Postfix) with ESMTPS id 10F3098E61 for ; Sun, 1 Feb 2015 13:37:13 +0000 (UTC) Original-Received: (qmail 2264 invoked from network); 1 Feb 2015 13:37:13 -0000 Original-Received: from unknown (HELO RTLaptop) (rt@robertthorpeconsulting.com@[109.78.234.58]) by 81.17.254.9 with ESMTPSA (DHE-RSA-AES128-SHA encrypted, authenticated); 1 Feb 2015 13:37:12 -0000 In-Reply-To: (message from Andrey Lisin on Sun, 01 Feb 2015 13:09:53 +0600) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 81.17.249.38 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:102420 Archived-At: Andrey Lisin 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 `. some_script.sh' or `source some_script.sh' 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. BR, Robert Thorpe