do not open editor in dumb terminal
PATCH 1/1 do not open editor in dumb terminal
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.
---
git-commit.sh | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
c0ee93460521c1cbf9d3fe86a08b41295a79ebb1
git-commit.sh +6 -0
@@ -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
Signature · 1 line
1.1.6.g46dc-dirty
Dear diary, on Fri, Feb 03, 2006 at 12:41:33PM CET, I got a letter where Amos Waterland <[email protected]> said that...
Quoted 8 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 <[email protected]>Cc Dave C Boutcher <[email protected]>
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.)
Signature · 5 lines
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
Quoted 7 lines · Petr Baudis
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 tmpfileQuoted 5 lines · Amos Waterland
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.
Quoted 11 lines · Junio C Hamano
Quoted 5 lines · Amos Waterland
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.
Quoted 6 lines · Amos Waterland
If your TERM is set to
emacs' then that is fine. If it is set todumb' 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.
Quoted 6 lines
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
Quoted 4 lines · Amos Waterland
If your TERM is set to
emacs' then that is fine. If it is set todumb' 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.
Quoted 4 lines
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.
---
git-commit.sh +4 -0
@@ -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
Quoted 7 lines · Junio C Hamano
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*
Quoted 5 lines · Daniel Barkalow
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).