threads / patch / 3228

patchdo not open editor in dumb terminal

Subject: [PATCH] do not open editor in dumb terminal

## tl;dr

9 messages between Feb 3, 2006 and Feb 6, 2006. Diffs are folded; open one to read it.

replies: 8people: 5as markdown or json

Amos Waterland· Feb 3, 2006, 11:41 UTC · lore

Many people run git from a shell in emacs (obtained by M-x shell). When they try to do a commit without specifying a log message on the command line with -m, git opens vi inside emacs, with unpleasant results. I think the right answer is to just refuse to open an editor in any dumb terminal.

Signed-off-by: Amos Waterland <apw@us.ibm.com>
Cc: Dave C Boutcher <boutcher@cs.umn.edu>
---
 git-commit.sh |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
c0ee93460521c1cbf9d3fe86a08b41295a79ebb1
Show changes to git-commit.sh +6 −0
diff --git a/git-commit.sh b/git-commit.sh
index 193feeb..fef8f96 100755
--- a/git-commit.sh
+++ b/git-commit.sh
@@ -207,6 +207,12 @@ then
 fi
 case "$no_edit" in
 '')
+	if [ "$TERM" = "dumb" ]; then
+		printf "%s: %s: %s\n" "git-commit" \
+			"cannot open editor in a dumb terminal" \
+			"use -m to supply message" >&2
+		exit 1
+	fi
 	${VISUAL:-${EDITOR:-vi}} "$GIT_DIR/COMMIT_EDITMSG"
 	;;
 esac
-- 
1.1.6.g46dc-dirty
Junio C Hamano· Feb 3, 2006, 19:56 UTC · re: Amos Waterland · lore

Re: [PATCH] do not open editor in dumb terminal

Amos Waterland <apw@us.ibm.com> writes:
Show 5 quoted lines
> Many people run git from a shell in emacs (obtained by M-x shell).  When
> they try to do a commit without specifying a log message on the command
> line with -m, git opens vi inside emacs, with unpleasant results.  I
> think the right answer is to just refuse to open an editor in any dumb
> terminal.
No, please don't.

I run 'git commit' from M-x shell or M-x compile. My EDITOR is set to 'emacsclient' while inside Emacs.

As a matter of fact, I do almost all my work inside Emacs and this setting works rather well for not only git but for other people's commands (like 'cvs commit').

It might be an option not to fall back on vi and instead to fall back on ed/ex when neither EDITOR nor VISUAL is specified and the terminal is dumb. But the patch as-is is unacceptable.

Amos Waterland· Feb 5, 2006, 00:37 UTC · re: Junio C Hamano · lore

Re: [PATCH] do not open editor in dumb terminal

On Fri, Feb 03, 2006 at 11:56:54AM -0800, Junio C Hamano wrote:
Show 11 quoted lines
> Amos Waterland <apw@us.ibm.com> writes:
> > Many people run git from a shell in emacs (obtained by M-x shell).  When
> > they try to do a commit without specifying a log message on the command
> > line with -m, git opens vi inside emacs, with unpleasant results.  I
> > think the right answer is to just refuse to open an editor in any dumb
> > terminal.
> 
> No, please don't.
> 
> I run 'git commit' from M-x shell or M-x compile.  My EDITOR is
> set to 'emacsclient' while inside Emacs.

If your TERM is set to `emacs' then that is fine. If it is set to `dumb' however, that seems a bit strange. A dumb terminal is usually understood to be one that does not have the ability to interpret control sequences.

The reason I sent the patch is that people get a rather unpleasant introduction to git when vi splatters control characters all over their emacs session when they do their first commit. I agree that people probably should have their EDITOR set to emacsclient though, so if you want to just leave the code as is that's cool with me.

H. Peter Anvin· Feb 5, 2006, 01:58 UTC · re: Amos Waterland · lore

Re: [PATCH] do not open editor in dumb terminal

Amos Waterland wrote:
Show 12 quoted lines
> 
> If your TERM is set to `emacs' then that is fine.  If it is set to
> `dumb' however, that seems a bit strange.  A dumb terminal is usually
> understood to be one that does not have the ability to interpret control
> sequences.
> 
> The reason I sent the patch is that people get a rather unpleasant
> introduction to git when vi splatters control characters all over their
> emacs session when they do their first commit.  I agree that people
> probably should have their EDITOR set to emacsclient though, so if you
> want to just leave the code as is that's cool with me.
> 
Sounds more like an unpleasant introduction to emacs.
	-hpa
Junio C Hamano· Feb 5, 2006, 02:54 UTC · re: Amos Waterland · lore

Re: [PATCH] do not open editor in dumb terminal

Amos Waterland <apw@us.ibm.com> writes:
> If your TERM is set to `emacs' then that is fine.  If it is set to
> `dumb' however, that seems a bit strange.  A dumb terminal is usually
> understood to be one that does not have the ability to interpret control
> sequences.

I am not talking about M-x terminal that uses TERM=emacs-*. I am talking about M-x shell and M-x compile. In those modes, the default TERM is "dumb".

I could live with something like this (untested) patch, though. Instead of falling back on ed (or ex), you could error out and give the error message if you want.

I know of an editor that works fine even when invoked with TERM=dumb, and I explicitly told programs to use it by exporting EDITOR environment variable with the name of that editor. I am entitled to expect that programs honor that wish, instead of insulting me by saying "Hey dummy, you cannot run any editor on a dumb terminal". Be the editor "emacsclient" or "ed", they both work fine for me, thank you ;-).

The user, at least the ones who understand what your program does, always knows a lot better about his enviornment and his needs than your program will ever do. You can try to be helpful (e.g. refuse to spawn the editor when you feel it is not appropriate), but you can never be perfect. Just in case your helpfulness turns out to be misguided inconvenience, you should leave a way for the user to override it. I was unhappy about your patch because it errored out only after checking TERM without checking EDITOR or VISUAL.

Although you did not bring this up, there is a same issue for ${PAGER:-less} elsewhere. Inside Emacs I usually set it to "cat". I do not want the program to be helpful by just checking TERM=dumb to error that out, either.

> The reason I sent the patch is that people get a rather
> unpleasant introduction to git when vi splatters control
> characters all over their emacs session when they do their
> first commit.

It's been quite a while since I used the real "vi" the last time, but I think the real vi was not _that_ dumb as you described. If the termcap said that the $TERM cannot do a reasonable visual mode, it sensibly fell back to a line editor mode ex, if I recall correctly. Maybe popular vi clones these days are poorly emulated in that respect. I dunno.

---
Show changes to git-commit.sh +4 −0
diff --git a/git-commit.sh b/git-commit.sh
index 193feeb..c4a9dc3 100755
--- a/git-commit.sh
+++ b/git-commit.sh
@@ -207,6 +207,10 @@ then
 fi
 case "$no_edit" in
 '')
+	case "$VISUAL$EDITOR,$TERM" in
+	',dumb')
+		EDITOR=ed ;;
+	esac
 	${VISUAL:-${EDITOR:-vi}} "$GIT_DIR/COMMIT_EDITMSG"
 	;;
 esac
Daniel Barkalow· Feb 5, 2006, 05:04 UTC · re: Junio C Hamano · lore

Re: [PATCH] do not open editor in dumb terminal

On Sat, 4 Feb 2006, Junio C Hamano wrote:
Show 7 quoted lines
> I know of an editor that works fine even when invoked with
> TERM=dumb, and I explicitly told programs to use it by exporting
> EDITOR environment variable with the name of that editor.  I am
> entitled to expect that programs honor that wish, instead of
> insulting me by saying "Hey dummy, you cannot run any editor on
> a dumb terminal".  Be the editor "emacsclient" or "ed", they
> both work fine for me, thank you ;-).

I think that "ed" is a bit too obscure as something for people to use interactively, and emacsclient is obviously not a sane default (since people might not be using emacs in server mode). Probably the right thing is to have it supply a default if the terminal isn't dumb, and abort with an error if there is no editor set after defaults are supplied.

(I think the only editors people use in dumb terminals these days are ones that do the editing somewhere else, although I'm not sure of that.)

	-Daniel
*This .sig left intentionally blank*
Junio C Hamano· Feb 5, 2006, 05:48 UTC · re: Daniel Barkalow · lore

Re: [PATCH] do not open editor in dumb terminal

Daniel Barkalow <barkalow@iabervon.org> writes:
Show 5 quoted lines
> I think that "ed" is a bit too obscure as something for people to use 
> interactively, and emacsclient is obviously not a sane default (since 
> people might not be using emacs in server mode). Probably the right thing 
> is to have it supply a default if the terminal isn't dumb, and abort with 
> an error if there is no editor set after defaults are supplied.

I tend to agree (I am a minority who used ed for a long time, but I am well aware that I _am_ a minority). If somebody wants to send in a tested patch to be applied, I would suggest to replace EDITOR=ed in the one I sent out with an error message and exit(1).

Petr Baudis· Feb 5, 2006, 17:44 UTC · re: Amos Waterland · lore

Re: [PATCH] do not open editor in dumb terminal

Dear diary, on Fri, Feb 03, 2006 at 12:41:33PM CET, I got a letter where Amos Waterland <apw@us.ibm.com> said that...

Show 8 quoted lines
> Many people run git from a shell in emacs (obtained by M-x shell).  When
> they try to do a commit without specifying a log message on the command
> line with -m, git opens vi inside emacs, with unpleasant results.  I
> think the right answer is to just refuse to open an editor in any dumb
> terminal.
> 
> Signed-off-by: Amos Waterland <apw@us.ibm.com>
> Cc: Dave C Boutcher <boutcher@cs.umn.edu>

Cogito solves this by [ -t ] and just doing cat instead of $EDITOR if the input is not a terminal. Couldn't Junio just do

	emacsclient | cg^H^Hgit commit

in that case? (Note that I'm totally clueless about what emacsclient's usage actually is.)

-- 
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
Of the 3 great composers Mozart tells us what it's like to be human,
Beethoven tells us what it's like to be Beethoven and Bach tells us
what it's like to be the universe.  -- Douglas Adams
Junio C Hamano· Feb 6, 2006, 00:56 UTC · re: Petr Baudis · lore

Re: [PATCH] do not open editor in dumb terminal

Petr Baudis <pasky@suse.cz> writes:
Show 7 quoted lines
> Cogito solves this by [ -t ] and just doing cat instead of $EDITOR if
> the input is not a terminal. Couldn't Junio just do
>
> 	emacsclient | cg^H^Hgit commit
>
> in that case? (Note that I'm totally clueless about what emacsclient's
> usage actually is.)

It works just like other editors you can sanely use as EDITOR or VISUAL. Takes list of files to edit on the command line, lets the user interact with it and modify the files, writes out the results to the files and exits.

So you could have suggested something like this:
	$ ( $EDITOR tmpfile && cat tmpfile ) | cg commit

I think "git commit -F -" reads from stdin so an equilvalent can be done with "git commit", but I suspect a sane user would rather do this instead if he uses a temporary file:

	$ $EDITOR tmpfile
        $ git commit -F tmpfile

← back to recent threads