All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Chris Torek <chris.torek@gmail.com>, Carlo Arenas <carenas@gmail.com>
Cc: phillip.wood@dunelm.org.uk, Git List <git@vger.kernel.org>,
	thomas.wolf@paranor.ch, Alexander Veit <alexander.veit@gmx.net>
Subject: Re: [PATCH] editor: only save (and restore) the terminal if using a tty
Date: Wed, 01 Dec 2021 16:38:59 -0800	[thread overview]
Message-ID: <xmqq7dcnyh5o.fsf@gitster.g> (raw)
In-Reply-To: <xmqq35nc15nr.fsf@gitster.g> (Junio C. Hamano's message of "Wed, 01 Dec 2021 11:33:44 -0800")

Junio C Hamano <gitster@pobox.com> writes:

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

That's an overkill.

A single configuration variable as an escape hatch, that enables the
save/restore around editor invocation, whose default value is
determined by the name of the editor, is probably the right degree
of flexibility.

Something along this line, perhaps?

 editor.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git c/editor.c w/editor.c
index fdd3eeafa9..70d3f80966 100644
--- c/editor.c
+++ w/editor.c
@@ -3,6 +3,7 @@
 #include "strbuf.h"
 #include "run-command.h"
 #include "sigchain.h"
+#include "compat/terminal.h"
 
 #ifndef DEFAULT_EDITOR
 #define DEFAULT_EDITOR "vi"
@@ -47,6 +48,16 @@ const char *git_sequence_editor(void)
 	return editor;
 }
 
+static int prepare_term(const char *editor)
+{
+	int need_saverestore = !strcmp(editor, "vi");
+
+	git_config_get_bool("editor.stty", &need_saverestore);
+	if (need_saverestore)
+		return save_term(1);
+	return 0;
+}
+
 static int launch_specified_editor(const char *editor, const char *path,
 				   struct strbuf *buffer, const char *const *env)
 {
@@ -57,7 +68,7 @@ static int launch_specified_editor(const char *editor, const char *path,
 		struct strbuf realpath = STRBUF_INIT;
 		const char *args[] = { editor, NULL, NULL };
 		struct child_process p = CHILD_PROCESS_INIT;
-		int ret, sig;
+		int ret, sig, need_restore = 0;
 		int print_waiting_for_editor = advice_enabled(ADVICE_WAITING_FOR_EDITOR) && isatty(2);
 
 		if (print_waiting_for_editor) {
@@ -83,7 +94,10 @@ static int launch_specified_editor(const char *editor, const char *path,
 		p.env = env;
 		p.use_shell = 1;
 		p.trace2_child_class = "editor";
+		need_restore = prepare_term(editor);
 		if (start_command(&p) < 0) {
+			if (need_restore)
+				restore_term();
 			strbuf_release(&realpath);
 			return error("unable to start editor '%s'", editor);
 		}
@@ -91,6 +105,8 @@ static int launch_specified_editor(const char *editor, const char *path,
 		sigchain_push(SIGINT, SIG_IGN);
 		sigchain_push(SIGQUIT, SIG_IGN);
 		ret = finish_command(&p);
+		if (need_restore)
+			restore_term();
 		strbuf_release(&realpath);
 		sig = ret - 128;
 		sigchain_pop(SIGINT);

  reply	other threads:[~2021-12-02  0:39 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-22  8:42 Update to Git 2.34.0 breaks application Alexander Veit
2021-11-22 21:43 ` Phillip Wood
2021-11-22 22:28   ` [PATCH] editor: only save (and restore) the terminal if using a tty Carlo Marcelo Arenas Belón
2021-11-22 22:47     ` Junio C Hamano
2021-11-22 23:03     ` Junio C Hamano
2021-11-22 23:08       ` Junio C Hamano
2021-11-23  8:52         ` Alexander Veit
2021-11-23  9:08           ` Carlo Arenas
2021-11-22 23:39       ` Carlo Arenas
2021-11-23 17:35         ` Junio C Hamano
2021-11-24 13:29           ` Johannes Schindelin
2021-11-24 18:25             ` Carlo Arenas
2021-11-24 19:34             ` Junio C Hamano
2021-11-24 20:04               ` Carlo Arenas
2021-11-24 20:51                 ` Junio C Hamano
2021-11-29 21:12               ` Johannes Schindelin
2021-11-23 11:05     ` Phillip Wood
2021-11-23 17:27       ` Junio C Hamano
2021-11-23 17:31       ` Carlo Arenas
2021-11-30 11:07         ` Phillip Wood
2021-12-01  5:12           ` Chris Torek
2021-12-01 19:33             ` Junio C Hamano
2021-12-02  0:38               ` Junio C Hamano [this message]
2021-12-02  1:51                 ` Carlo Arenas
2021-12-02 14:48             ` Johannes Schindelin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqq7dcnyh5o.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=alexander.veit@gmx.net \
    --cc=carenas@gmail.com \
    --cc=chris.torek@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=phillip.wood@dunelm.org.uk \
    --cc=thomas.wolf@paranor.ch \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.