All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: Yoichi Nakayama via GitGitGadget <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, Jeff King <peff@peff.net>,
	Yoichi Nakayama <yoichi.nakayama@gmail.com>
Subject: Re: [PATCH v7 3/3] git-jump: invoke emacs/emacsclient
Date: Fri, 25 Nov 2022 09:55:13 +0100	[thread overview]
Message-ID: <221125.8635a7o123.gmgdl@evledraar.gmail.com> (raw)
In-Reply-To: <d8233f9617563d7c7168afc6e1abfaba57e54038.1669347422.git.gitgitgadget@gmail.com>


On Fri, Nov 25 2022, Yoichi Nakayama via GitGitGadget wrote:

> From: Yoichi Nakayama <yoichi.nakayama@gmail.com>
>
> It works with GIT_EDITOR="emacs", "emacsclient" or "emacsclient -t"
>
> Signed-off-by: Yoichi Nakayama <yoichi.nakayama@gmail.com>
> ---
>  contrib/git-jump/git-jump | 17 ++++++++++++++++-
>  1 file changed, 16 insertions(+), 1 deletion(-)
>
> diff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump
> index cc97b0dcf02..eef9cda832f 100755
> --- a/contrib/git-jump/git-jump
> +++ b/contrib/git-jump/git-jump
> @@ -23,7 +23,22 @@ EOF
>  
>  open_editor() {
>  	editor=`git var GIT_EDITOR`
> -	eval "$editor -q \$1"
> +	case "$editor" in
> +	*emacs*)
> +		# Supported editor values are:
> +		# - emacs
> +		# - emacsclient
> +		# - emacsclient -t
> +		#
> +		# Wait for completion of the asynchronously executed process
> +		# to avoid race conditions in case of "emacsclient".
> +		eval "$editor --eval \"(let ((buf (compilation-start \\\"cat \$1\\\" 'grep-mode))) (pop-to-buffer buf) (select-frame-set-input-focus (selected-frame)) (while (get-buffer-process buf) (sleep-for 0.1)))\""
> +		;;
> +	*)
> +		# assume anything else is vi-compatible
> +		eval "$editor -q \$1"
> +		;;
> +	esac
>  }
>  
>  mode_diff() {

I'd really like to have some closer and smarter emacs integration like
this.

But I don't see why we need to run the grep ourselves, pipe it to a
temporary file, and then discover that we're using emacs, and --eval
code into it to switch to that buffer, and fake up a "M-x grep" command
with a compilation buffer to make it look like we ran M-x grep in the
first place.

Let's just ... run M-x grep earlier? Then we can skip all the earlier
steps.

I experimented with this a bit locally, and I didn't get the "switch to
buffer" semantics to work with this (but that's presumably easy, I'm
just rusty on my elisp APIs), but something in this direction seems much
better:
	
	diff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump
	index eef9cda832f..c932d7acd0f 100755
	--- a/contrib/git-jump/git-jump
	+++ b/contrib/git-jump/git-jump
	@@ -22,23 +22,7 @@ EOF
	 }
	 
	 open_editor() {
	-	editor=`git var GIT_EDITOR`
	-	case "$editor" in
	-	*emacs*)
	-		# Supported editor values are:
	-		# - emacs
	-		# - emacsclient
	-		# - emacsclient -t
	-		#
	-		# Wait for completion of the asynchronously executed process
	-		# to avoid race conditions in case of "emacsclient".
	-		eval "$editor --eval \"(let ((buf (compilation-start \\\"cat \$1\\\" 'grep-mode))) (pop-to-buffer buf) (select-frame-set-input-focus (selected-frame)) (while (get-buffer-process buf) (sleep-for 0.1)))\""
	-		;;
	-	*)
	-		# assume anything else is vi-compatible
	-		eval "$editor -q \$1"
	-		;;
	-	esac
	+	eval "$editor -q \$1"
	 }
	 
	 mode_diff() {
	@@ -83,11 +67,14 @@ mode_ws() {
	 }
	 
	 use_stdout=
	+use_magic=t
	 while test $# -gt 0; do
	 	case "$1" in
	 	--stdout)
	 		use_stdout=t
	-		shift
	+		;;
	+	--no-magic)
	+		use_magic=
	 		;;
	 	--*)
	 		usage >&2
	@@ -96,7 +83,8 @@ while test $# -gt 0; do
	 	*)
	 		break
	 		;;
	-	esac
	+	esac &&
	+	shift
	 done
	 if test $# -lt 1; then
	 	usage >&2
	@@ -105,6 +93,22 @@ fi
	 mode=$1; shift
	 type "mode_$mode" >/dev/null 2>&1 || { usage >&2; exit 1; }
	 
	+editor=`git var GIT_EDITOR`
	+if test "$use_magic" && test "$mode" = "grep"
	+then
	+	case "$editor" in
	+	*emacs*)
	+		set -x
	+		eval "$editor --eval \" \
	+			(grep \\\"git grep -H "$@"\\\") \
	+		\""
	+		exit
	+		;;
	+	*)
	+		;;
	+	esac
	+fi
	+
	 if test "$use_stdout" = "t"; then
	 	"mode_$mode" "$@"
	 	exit 0

I.e. if we're going to trust emacs to eval this code, and assume that
grep.el etc. works, let's just run the equivalent of M-x grep with our
'git grep' command.

This is already better in that "grep" understands that I searched for
"foo.*bar", so that's highlighted in the resulting buffer, just as with
normal "grep" commands.

This is missing the bit where we'd need to jump.grepCmd etc, so it's
incomplete.

I think this is all the prior art we'd need to invoke "git grep" the
right way from emacs's "grep":
https://github.com/eglaysher/find-things-fast/blob/master/find-things-fast.el#L246

B.t.w. I'd think the "--no-magic" here is something you'd want too. I
like this new behavior (sans the comments above), but presumably there's
people using emacs as their EDITOR who don't want to have this magic
behavior, having an opt-out would be neat.

I.e. if you have an existing customization intercepting these then this
will screw with that, but maybe that's OK...

  reply	other threads:[~2022-11-25  9:09 UTC|newest]

Thread overview: 68+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-19 14:02 [PATCH 0/2] git-jump: support Emacs Yoichi NAKAYAMA via GitGitGadget
2022-11-19 14:02 ` [PATCH 1/2] git-jump: add an optional argument 'stdout' Yoichi Nakayama via GitGitGadget
2022-11-19 14:02 ` [PATCH 2/2] git-jump: invoke emacsclient Yoichi Nakayama via GitGitGadget
2022-11-19 15:53   ` Eric Sunshine
2022-11-19 23:44     ` Yoichi Nakayama
2022-11-19 23:59       ` Eric Sunshine
2022-11-21  4:05         ` Yoichi Nakayama
2022-11-20  1:27 ` [PATCH v2 0/2] git-jump: support Emacs Yoichi NAKAYAMA via GitGitGadget
2022-11-20  1:27   ` [PATCH v2 1/2] git-jump: add an optional argument 'stdout' Yoichi Nakayama via GitGitGadget
2022-11-21  5:43     ` Junio C Hamano
2022-11-21 11:25       ` Yoichi Nakayama
2022-11-21 18:18       ` Jeff King
2022-11-20  1:27   ` [PATCH v2 2/2] git-jump: invoke emacsclient Yoichi Nakayama via GitGitGadget
2022-11-21 12:26   ` [PATCH v3 0/2] git-jump: support Emacs Yoichi NAKAYAMA via GitGitGadget
2022-11-21 12:26     ` [PATCH v3 1/2] git-jump: add an optional argument '--stdout' Yoichi Nakayama via GitGitGadget
2022-11-21 18:38       ` Jeff King
2022-11-21 23:38         ` Junio C Hamano
2022-11-22 13:00           ` Yoichi Nakayama
2022-11-22 18:23             ` Jeff King
2022-11-22 13:29         ` Yoichi Nakayama
2022-11-21 12:27     ` [PATCH v3 2/2] git-jump: invoke emacs/emacsclient Yoichi Nakayama via GitGitGadget
2022-11-21 18:50       ` Jeff King
2022-11-22 12:06         ` Yoichi Nakayama
2022-11-22 14:18     ` [PATCH v4 0/2] git-jump: support Emacs Yoichi NAKAYAMA via GitGitGadget
2022-11-22 14:18       ` [PATCH v4 1/2] git-jump: add an optional argument '--stdout' Yoichi Nakayama via GitGitGadget
2022-11-22 18:30         ` Jeff King
2022-11-22 14:18       ` [PATCH v4 2/2] git-jump: invoke emacs/emacsclient Yoichi Nakayama via GitGitGadget
2022-11-22 16:40         ` Phillip Wood
2022-11-23  5:01           ` Yoichi Nakayama
2022-11-22 18:54         ` Jeff King
2022-11-23  5:33           ` Yoichi Nakayama
2022-11-24  1:09             ` Jeff King
2022-11-24 12:32               ` Yoichi Nakayama
2022-11-24 12:58                 ` Yoichi Nakayama
2022-11-24 16:31                   ` Jeff King
2022-11-24 16:29                 ` Jeff King
2022-11-25  3:46                   ` Yoichi Nakayama
2022-11-23  7:04       ` [PATCH v5 0/3] git-jump: support Emacs Yoichi NAKAYAMA via GitGitGadget
2022-11-23  7:04         ` [PATCH v5 1/3] git-jump: add an optional argument '--stdout' Yoichi Nakayama via GitGitGadget
2022-11-23  7:04         ` [PATCH v5 2/3] git-jump: move valid-mode check earlier Jeff King via GitGitGadget
2022-11-23  7:04         ` [PATCH v5 3/3] git-jump: invoke emacs/emacsclient Yoichi Nakayama via GitGitGadget
2022-11-23 14:58           ` Phillip Wood
2022-11-23 21:54             ` Yoichi Nakayama
2022-11-24  1:11         ` [PATCH v5 0/3] git-jump: support Emacs Jeff King
2022-11-24  3:47         ` [PATCH v6 " Yoichi NAKAYAMA via GitGitGadget
2022-11-24  3:47           ` [PATCH v6 1/3] git-jump: add an optional argument '--stdout' Yoichi Nakayama via GitGitGadget
2022-11-24  3:47           ` [PATCH v6 2/3] git-jump: move valid-mode check earlier Jeff King via GitGitGadget
2022-11-24  3:47           ` [PATCH v6 3/3] git-jump: invoke emacs/emacsclient Yoichi Nakayama via GitGitGadget
2022-11-25  3:36           ` [PATCH v7 0/3] git-jump: support Emacs Yoichi NAKAYAMA via GitGitGadget
2022-11-25  3:36             ` [PATCH v7 1/3] git-jump: add an optional argument '--stdout' Yoichi Nakayama via GitGitGadget
2022-11-25  9:06               ` Ævar Arnfjörð Bjarmason
2022-11-27  0:31                 ` Yoichi Nakayama
2022-11-25  3:37             ` [PATCH v7 2/3] git-jump: move valid-mode check earlier Jeff King via GitGitGadget
2022-11-25  3:37             ` [PATCH v7 3/3] git-jump: invoke emacs/emacsclient Yoichi Nakayama via GitGitGadget
2022-11-25  8:55               ` Ævar Arnfjörð Bjarmason [this message]
2022-11-25 16:01                 ` Yoichi Nakayama
2022-11-25 23:52                   ` Ævar Arnfjörð Bjarmason
2022-11-28  5:10                     ` Jeff King
2022-11-28 10:54                       ` Ævar Arnfjörð Bjarmason
2022-11-28 15:38                         ` Yoichi Nakayama
2022-11-27  0:37                   ` Yoichi Nakayama
2022-11-27  1:18             ` [PATCH v8 0/3] git-jump: support Emacs Yoichi NAKAYAMA via GitGitGadget
2022-11-27  1:18               ` [PATCH v8 1/3] git-jump: add an optional argument '--stdout' Yoichi Nakayama via GitGitGadget
2022-11-27  1:18               ` [PATCH v8 2/3] git-jump: move valid-mode check earlier Jeff King via GitGitGadget
2022-11-27  1:18               ` [PATCH v8 3/3] git-jump: invoke emacs/emacsclient Yoichi Nakayama via GitGitGadget
2022-11-28 10:13               ` [PATCH v8 0/3] git-jump: support Emacs Phillip Wood
2022-11-28 23:35                 ` Junio C Hamano
2022-11-29 21:05                 ` Yoichi Nakayama

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=221125.8635a7o123.gmgdl@evledraar.gmail.com \
    --to=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=peff@peff.net \
    --cc=yoichi.nakayama@gmail.com \
    /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.