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

From: Junio C Hamano <junkio@cox.net>
Date: 2006-02-05 13:54:59
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.

---
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


-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Received on Sun Feb 05 13:55:48 2006

This archive was generated by hypermail 2.1.8 : 2006-02-05 13:55:58 EST