Thread (1 message) 1 message, 1 author, 2021-12-01

Re: [PATCH] editor: only save (and restore) the terminal if using a tty

From: Junio C Hamano <hidden>
Date: 2021-12-01 19:33:54

Chris Torek [off-list ref] writes:
On Tue, Nov 30, 2021 at 2:41 PM Phillip Wood [off-list ref] wrote:
quoted
On 23/11/2021 17:31, Carlo Arenas wrote:
quoted
Restricting this feature further, maybe through a configuration
property or even special casing the EDITOR is also IMHO a good idea.
I think just doing this when we run the editor may be the way to go as I
think it is only that case that can mess up the terminal.
If it only happens with certain versions of vi / vim, perhaps Git could come
with a front end program that saves the tty state, runs vim, and restores the
tty state. (Or set this up so that the program can run any editor.)  Then add
a FAQ entry if needed: "if your editor goofs up the terminal, insert this front
end program".
That might work, and because the user is in control, we have less
risk of unintended breakage.  Doing so unconditionally when the
editor's name is "vi" like Dscho suggested would make it more
convenient for the users.

Some editors like Emacs can open a new window and go graphical, even
when they are launched from a terminal.  Doing the save/restore on
them would be unnecessary.  Although I do not offhand think of a way
such an unnecessary save/restore would break the terminal, we have
already seen that things can break in an unintended way by doing
something unnecessary in this area, so perhaps the best way forward
is

 - Add a multi-valued configuration variable whose value is the name
   of an editor program that needs this save/restore; optionally, we
   may want a way to say "don't do save/restore on this editor",
   e.g. "!emacs" may countermand an earlier value that would include
   the editor in the list.

 - Around the program invocation in launch_specified_editor(), check
   the name of the editor against this list and do the save/restore
   as necessary;

 - When the variable is not defined in the configuration, pretend
   that "vi" is on that list (coming up with the list of editors is
   left as an exercise to readers).

That would give us your flexibility to apply the save/restore on an
arbitrary editor that is not "vi", Dscho's convenience to special
case "vi" out of the box when unconfigured, and an escape hatch for
"vi" users for whom it hurts to do the save/restore on their "vi".

Hmm?
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help