{"thread":{"id":"58820","subject":"[PATCH 0/2] git-jump: support Emacs","startedAt":"2022-11-19T14:02:28Z","lastAt":"2022-11-29T21:06:02Z","messageCount":68,"participants":["Yoichi NAKAYAMA via GitGitGadget","Yoichi Nakayama via GitGitGadget","Eric Sunshine","Yoichi Nakayama","Junio C Hamano","Jeff King","Phillip Wood","Jeff King via GitGitGadget","Ævar Arnfjörð Bjarmason"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"467589","messageId":"pull.1423.git.1668866540.gitgitgadget@gmail.com","threadId":"58820","inReplyTo":null,"subject":"[PATCH 0/2] git-jump: support Emacs","fromName":"Yoichi NAKAYAMA via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2022-11-19T14:02:18Z","receivedAt":"2022-11-19T14:02:28Z","isPatch":true,"sender":{"key":"yoichi.nakayama@gmail.com","avatar":"https://avatars.githubusercontent.com/u/107537?v=4"},"body":"Add an optional argument 'stdout' to print the quickfix lines to standard\noutput. It can be used with M-x grep on Emacs.\n\nDetect emacsclient by GIT_EDITOR and invoke the function. Tested with\nEDITOR=\"emacsclient\" and EDITOR=\"emacsclient -t\".\n\nYoichi Nakayama (2):\n  git-jump: add an optional argument 'stdout'\n  git-jump: invoke emacsclient\n\n contrib/git-jump/README   |  9 ++++++++-\n contrib/git-jump/git-jump | 22 +++++++++++++++++++++-\n 2 files changed, 29 insertions(+), 2 deletions(-)\n\n\nbase-commit: eea7033409a0ed713c78437fc76486983d211e25\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-1423%2Fyoichi%2Fgit-jump-emacs-support-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1423/yoichi/git-jump-emacs-support-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/1423\n-- \ngitgitgadget\n"},{"id":"467590","messageId":"e56858a3eb212dcd0b8f71bdbf8db96f51c5d648.1668866540.git.gitgitgadget@gmail.com","threadId":"58820","inReplyTo":"pull.1423.git.1668866540.gitgitgadget@gmail.com","subject":"[PATCH 1/2] git-jump: add an optional argument 'stdout'","fromName":"Yoichi Nakayama via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2022-11-19T14:02:19Z","receivedAt":"2022-11-19T14:02:30Z","isPatch":true,"sender":{"key":"yoichi.nakayama@gmail.com","avatar":"https://avatars.githubusercontent.com/u/107537?v=4"},"body":"From: Yoichi Nakayama <yoichi.nakayama@gmail.com>\n\nIt can be used with M-x grep on Emacs.\n\nSigned-off-by: Yoichi Nakayama <yoichi.nakayama@gmail.com>\n---\n contrib/git-jump/README   |  9 ++++++++-\n contrib/git-jump/git-jump | 11 ++++++++++-\n 2 files changed, 18 insertions(+), 2 deletions(-)\n\ndiff --git a/contrib/git-jump/README b/contrib/git-jump/README\nindex 8bcace29d21..6aaa6a928d2 100644\n--- a/contrib/git-jump/README\n+++ b/contrib/git-jump/README\n@@ -79,6 +79,13 @@ git jump grep -i foo_bar\n git config jump.grepCmd \"ag --column\"\n --------------------------------------------------\n \n+You can use the optional argument 'stdout' to print the listing to\n+standard output. You can use it with M-x grep on Emacs.\n+\n+--------------------------------------------------\n+# In Emacs, M-x grep and invoke \"git jump stdout <mode>\"\n+Run grep (like this): git jump stdout diff\n+--------------------------------------------------\n \n Related Programs\n ----------------\n@@ -100,7 +107,7 @@ Limitations\n -----------\n \n This script was written and tested with vim. Given that the quickfix\n-format is the same as what gcc produces, I expect emacs users have a\n+format is the same as what gcc produces, I expect other tools have a\n similar feature for iterating through the list, but I know nothing about\n how to activate it.\n \ndiff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump\nindex 92dbd4cde18..a907f69304d 100755\n--- a/contrib/git-jump/git-jump\n+++ b/contrib/git-jump/git-jump\n@@ -2,7 +2,7 @@\n \n usage() {\n \tcat <<\\EOF\n-usage: git jump <mode> [<args>]\n+usage: git jump [stdout] <mode> [<args>]\n \n Jump to interesting elements in an editor.\n The <mode> parameter is one of:\n@@ -15,6 +15,9 @@ grep: elements are grep hits. Arguments are given to git grep or, if\n       configured, to the command in `jump.grepCmd`.\n \n ws: elements are whitespace errors. Arguments are given to diff --check.\n+\n+If the optional argument `stdout` is given, print the quickfix\n+lines to standard output.\n EOF\n }\n \n@@ -69,6 +72,12 @@ if test $# -lt 1; then\n \texit 1\n fi\n mode=$1; shift\n+if test \"$mode\" = \"stdout\"; then\n+\tmode=$1; shift\n+\ttype \"mode_$mode\" >/dev/null 2>&1 || { usage >&2; exit 1; }\n+\t\"mode_$mode\" \"$@\" 2>/dev/null\n+\texit 0\n+fi\n \n trap 'rm -f \"$tmp\"' 0 1 2 3 15\n tmp=`mktemp -t git-jump.XXXXXX` || exit 1\n-- \ngitgitgadget\n\n"},{"id":"467591","messageId":"ed19668db860c8aafcb008aef306520e36d12dee.1668866540.git.gitgitgadget@gmail.com","threadId":"58820","inReplyTo":"pull.1423.git.1668866540.gitgitgadget@gmail.com","subject":"[PATCH 2/2] git-jump: invoke emacsclient","fromName":"Yoichi Nakayama via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2022-11-19T14:02:20Z","receivedAt":"2022-11-19T14:02:37Z","isPatch":true,"sender":{"key":"yoichi.nakayama@gmail.com","avatar":"https://avatars.githubusercontent.com/u/107537?v=4"},"body":"From: Yoichi Nakayama <yoichi.nakayama@gmail.com>\n\nIt works with GIT_EDITOR=\"emacsclient\" or GIT_EDITOR=\"emacsclient -t\"\n\nSigned-off-by: Yoichi Nakayama <yoichi.nakayama@gmail.com>\n---\n contrib/git-jump/git-jump | 11 +++++++++++\n 1 file changed, 11 insertions(+)\n\ndiff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump\nindex a907f69304d..536f0341aaf 100755\n--- a/contrib/git-jump/git-jump\n+++ b/contrib/git-jump/git-jump\n@@ -26,6 +26,11 @@ open_editor() {\n \teval \"$editor -q \\$1\"\n }\n \n+open_emacsclient() {\n+\teditor=`git var GIT_EDITOR`\n+\teval \"$editor -e \\\"(prog1 (switch-to-buffer-other-frame (grep \\\\\\\"git jump stdout $@\\\\\\\")) (delete-other-windows) (select-frame-set-input-focus (selected-frame)))\\\"\"\n+}\n+\n mode_diff() {\n \tgit diff --no-prefix --relative \"$@\" |\n \tperl -ne '\n@@ -79,6 +84,12 @@ if test \"$mode\" = \"stdout\"; then\n \texit 0\n fi\n \n+if git var GIT_EDITOR | grep ^emacsclient >/dev/null; then\n+\ttype \"mode_$mode\" >/dev/null 2>&1 || { usage >&2; exit 1; }\n+\topen_emacsclient \"$mode\" \"$@\"\n+\texit 0\n+fi\n+\n trap 'rm -f \"$tmp\"' 0 1 2 3 15\n tmp=`mktemp -t git-jump.XXXXXX` || exit 1\n type \"mode_$mode\" >/dev/null 2>&1 || { usage >&2; exit 1; }\n-- \ngitgitgadget\n"},{"id":"467592","messageId":"CAPig+cSMoAoVW_NTidyN0rgTTY-FaQ49CAFQZhPyaYBsYu-RfA@mail.gmail.com","threadId":"58820","inReplyTo":"ed19668db860c8aafcb008aef306520e36d12dee.1668866540.git.gitgitgadget@gmail.com","subject":"Re: [PATCH 2/2] git-jump: invoke emacsclient","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2022-11-19T15:53:02Z","receivedAt":"2022-11-19T15:53:23Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Sat, Nov 19, 2022 at 9:09 AM Yoichi Nakayama via GitGitGadget\n<gitgitgadget@gmail.com> wrote:\n> It works with GIT_EDITOR=\"emacsclient\" or GIT_EDITOR=\"emacsclient -t\"\n>\n> Signed-off-by: Yoichi Nakayama <yoichi.nakayama@gmail.com>\n> ---\n> diff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump\n> @@ -26,6 +26,11 @@ open_editor() {\n> +if git var GIT_EDITOR | grep ^emacsclient >/dev/null; then\n> +       type \"mode_$mode\" >/dev/null 2>&1 || { usage >&2; exit 1; }\n> +       open_emacsclient \"$mode\" \"$@\"\n> +       exit 0\n> +fi\n\nWould it make sense to expand this to support the VISUAL and EDITOR\nenvironment variables too? For instance, since I want to use Emacs for\nall my editing needs, I have EDITOR set to reference emacsclient. So,\nif GIT_EDITOR is unset, then check VISUAL, and if that is unset, check\nEDITOR.\n\nAlso, on macOS, I need to set EDITOR (or GIT_EDITOR or VISUAL) to the\nfull path of emacsclient, but the regex used here is too tight to\nrecognize that. Perhaps loosening it to just 'emacsclient' would be a\ngood idea (as it seems unlikely to falsely match any other editor)?\n"},{"id":"467598","messageId":"CAF5D8-ujg3Tp2s2+eGMgZfXXcZEyRKreAj=EkG0KiMniKjoKBQ@mail.gmail.com","threadId":"58820","inReplyTo":"CAPig+cSMoAoVW_NTidyN0rgTTY-FaQ49CAFQZhPyaYBsYu-RfA@mail.gmail.com","subject":"Re: [PATCH 2/2] git-jump: invoke emacsclient","fromName":"Yoichi Nakayama","fromEmail":"yoichi.nakayama@gmail.com","sentAt":"2022-11-19T23:44:13Z","receivedAt":"2022-11-19T23:44:27Z","isPatch":true,"sender":{"key":"yoichi.nakayama@gmail.com","avatar":"https://avatars.githubusercontent.com/u/107537?v=4"},"body":"On Sun, Nov 20, 2022 at 12:53 AM Eric Sunshine <sunshine@sunshineco.com> wrote:\n> Would it make sense to expand this to support the VISUAL and EDITOR\n> environment variables too? For instance, since I want to use Emacs for\n> all my editing needs, I have EDITOR set to reference emacsclient. So,\n> if GIT_EDITOR is unset, then check VISUAL, and if that is unset, check\n> EDITOR.\n\n\"git var GIT_EDITOR\" does respect VISUAL and EDITOR environment variables.\nSee git-var(1) reference manual.\n\n> Also, on macOS, I need to set EDITOR (or GIT_EDITOR or VISUAL) to the\n> full path of emacsclient, but the regex used here is too tight to\n> recognize that. Perhaps loosening it to just 'emacsclient' would be a\n> good idea (as it seems unlikely to falsely match any other editor)?\n\nIt is a good idea. Thanks!\n-- \nYoichi NAKAYAMA\n"},{"id":"467599","messageId":"CAPig+cR6+H2gqZbnj9FHzZRefwTjYme94kNeQ9qmVi-wLYZ6fw@mail.gmail.com","threadId":"58820","inReplyTo":"CAF5D8-ujg3Tp2s2+eGMgZfXXcZEyRKreAj=EkG0KiMniKjoKBQ@mail.gmail.com","subject":"Re: [PATCH 2/2] git-jump: invoke emacsclient","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2022-11-19T23:59:05Z","receivedAt":"2022-11-19T23:59:25Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Sat, Nov 19, 2022 at 6:44 PM Yoichi Nakayama\n<yoichi.nakayama@gmail.com> wrote:\n> On Sun, Nov 20, 2022 at 12:53 AM Eric Sunshine <sunshine@sunshineco.com> wrote:\n> > Would it make sense to expand this to support the VISUAL and EDITOR\n> > environment variables too? For instance, since I want to use Emacs for\n> > all my editing needs, I have EDITOR set to reference emacsclient. So,\n> > if GIT_EDITOR is unset, then check VISUAL, and if that is unset, check\n> > EDITOR.\n>\n> \"git var GIT_EDITOR\" does respect VISUAL and EDITOR environment variables.\n> See git-var(1) reference manual.\n\nExcellent.\n\n> > Also, on macOS, I need to set EDITOR (or GIT_EDITOR or VISUAL) to the\n> > full path of emacsclient, but the regex used here is too tight to\n> > recognize that. Perhaps loosening it to just 'emacsclient' would be a\n> > good idea (as it seems unlikely to falsely match any other editor)?\n>\n> It is a good idea. Thanks!\n\nThanks.\n"},{"id":"467600","messageId":"e56858a3eb212dcd0b8f71bdbf8db96f51c5d648.1668907644.git.gitgitgadget@gmail.com","threadId":"58820","inReplyTo":"pull.1423.v2.git.1668907644.gitgitgadget@gmail.com","subject":"[PATCH v2 1/2] git-jump: add an optional argument 'stdout'","fromName":"Yoichi Nakayama via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2022-11-20T01:27:23Z","receivedAt":"2022-11-20T01:27:35Z","isPatch":true,"sender":{"key":"yoichi.nakayama@gmail.com","avatar":"https://avatars.githubusercontent.com/u/107537?v=4"},"body":"From: Yoichi Nakayama <yoichi.nakayama@gmail.com>\n\nIt can be used with M-x grep on Emacs.\n\nSigned-off-by: Yoichi Nakayama <yoichi.nakayama@gmail.com>\n---\n contrib/git-jump/README   |  9 ++++++++-\n contrib/git-jump/git-jump | 11 ++++++++++-\n 2 files changed, 18 insertions(+), 2 deletions(-)\n\ndiff --git a/contrib/git-jump/README b/contrib/git-jump/README\nindex 8bcace29d21..6aaa6a928d2 100644\n--- a/contrib/git-jump/README\n+++ b/contrib/git-jump/README\n@@ -79,6 +79,13 @@ git jump grep -i foo_bar\n git config jump.grepCmd \"ag --column\"\n --------------------------------------------------\n \n+You can use the optional argument 'stdout' to print the listing to\n+standard output. You can use it with M-x grep on Emacs.\n+\n+--------------------------------------------------\n+# In Emacs, M-x grep and invoke \"git jump stdout <mode>\"\n+Run grep (like this): git jump stdout diff\n+--------------------------------------------------\n \n Related Programs\n ----------------\n@@ -100,7 +107,7 @@ Limitations\n -----------\n \n This script was written and tested with vim. Given that the quickfix\n-format is the same as what gcc produces, I expect emacs users have a\n+format is the same as what gcc produces, I expect other tools have a\n similar feature for iterating through the list, but I know nothing about\n how to activate it.\n \ndiff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump\nindex 92dbd4cde18..a907f69304d 100755\n--- a/contrib/git-jump/git-jump\n+++ b/contrib/git-jump/git-jump\n@@ -2,7 +2,7 @@\n \n usage() {\n \tcat <<\\EOF\n-usage: git jump <mode> [<args>]\n+usage: git jump [stdout] <mode> [<args>]\n \n Jump to interesting elements in an editor.\n The <mode> parameter is one of:\n@@ -15,6 +15,9 @@ grep: elements are grep hits. Arguments are given to git grep or, if\n       configured, to the command in `jump.grepCmd`.\n \n ws: elements are whitespace errors. Arguments are given to diff --check.\n+\n+If the optional argument `stdout` is given, print the quickfix\n+lines to standard output.\n EOF\n }\n \n@@ -69,6 +72,12 @@ if test $# -lt 1; then\n \texit 1\n fi\n mode=$1; shift\n+if test \"$mode\" = \"stdout\"; then\n+\tmode=$1; shift\n+\ttype \"mode_$mode\" >/dev/null 2>&1 || { usage >&2; exit 1; }\n+\t\"mode_$mode\" \"$@\" 2>/dev/null\n+\texit 0\n+fi\n \n trap 'rm -f \"$tmp\"' 0 1 2 3 15\n tmp=`mktemp -t git-jump.XXXXXX` || exit 1\n-- \ngitgitgadget\n\n"},{"id":"467601","messageId":"pull.1423.v2.git.1668907644.gitgitgadget@gmail.com","threadId":"58820","inReplyTo":"pull.1423.git.1668866540.gitgitgadget@gmail.com","subject":"[PATCH v2 0/2] git-jump: support Emacs","fromName":"Yoichi NAKAYAMA via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2022-11-20T01:27:22Z","receivedAt":"2022-11-20T01:27:35Z","isPatch":true,"sender":{"key":"yoichi.nakayama@gmail.com","avatar":"https://avatars.githubusercontent.com/u/107537?v=4"},"body":"Add an optional argument 'stdout' to print the quickfix lines to standard\noutput. It can be used with M-x grep on Emacs.\n\nDetect emacsclient by GIT_EDITOR and invoke the function. Tested with\nEDITOR=\"emacsclient\" and EDITOR=\"emacsclient -t\".\n\nYoichi Nakayama (2):\n  git-jump: add an optional argument 'stdout'\n  git-jump: invoke emacsclient\n\n contrib/git-jump/README   |  9 ++++++++-\n contrib/git-jump/git-jump | 22 +++++++++++++++++++++-\n 2 files changed, 29 insertions(+), 2 deletions(-)\n\n\nbase-commit: eea7033409a0ed713c78437fc76486983d211e25\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-1423%2Fyoichi%2Fgit-jump-emacs-support-v2\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1423/yoichi/git-jump-emacs-support-v2\nPull-Request: https://github.com/gitgitgadget/git/pull/1423\n\nRange-diff vs v1:\n\n 1:  e56858a3eb2 = 1:  e56858a3eb2 git-jump: add an optional argument 'stdout'\n 2:  ed19668db86 ! 2:  72c4fd5532b git-jump: invoke emacsclient\n     @@ contrib/git-jump/git-jump: if test \"$mode\" = \"stdout\"; then\n       \texit 0\n       fi\n       \n     -+if git var GIT_EDITOR | grep ^emacsclient >/dev/null; then\n     ++if git var GIT_EDITOR | grep emacsclient >/dev/null; then\n      +\ttype \"mode_$mode\" >/dev/null 2>&1 || { usage >&2; exit 1; }\n      +\topen_emacsclient \"$mode\" \"$@\"\n      +\texit 0\n\n-- \ngitgitgadget\n"},{"id":"467602","messageId":"72c4fd5532b89e21b55913b780311ec7e9fda9df.1668907644.git.gitgitgadget@gmail.com","threadId":"58820","inReplyTo":"pull.1423.v2.git.1668907644.gitgitgadget@gmail.com","subject":"[PATCH v2 2/2] git-jump: invoke emacsclient","fromName":"Yoichi Nakayama via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2022-11-20T01:27:24Z","receivedAt":"2022-11-20T01:27:59Z","isPatch":true,"sender":{"key":"yoichi.nakayama@gmail.com","avatar":"https://avatars.githubusercontent.com/u/107537?v=4"},"body":"From: Yoichi Nakayama <yoichi.nakayama@gmail.com>\n\nIt works with GIT_EDITOR=\"emacsclient\" or GIT_EDITOR=\"emacsclient -t\"\n\nSigned-off-by: Yoichi Nakayama <yoichi.nakayama@gmail.com>\n---\n contrib/git-jump/git-jump | 11 +++++++++++\n 1 file changed, 11 insertions(+)\n\ndiff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump\nindex a907f69304d..f267eac2233 100755\n--- a/contrib/git-jump/git-jump\n+++ b/contrib/git-jump/git-jump\n@@ -26,6 +26,11 @@ open_editor() {\n \teval \"$editor -q \\$1\"\n }\n \n+open_emacsclient() {\n+\teditor=`git var GIT_EDITOR`\n+\teval \"$editor -e \\\"(prog1 (switch-to-buffer-other-frame (grep \\\\\\\"git jump stdout $@\\\\\\\")) (delete-other-windows) (select-frame-set-input-focus (selected-frame)))\\\"\"\n+}\n+\n mode_diff() {\n \tgit diff --no-prefix --relative \"$@\" |\n \tperl -ne '\n@@ -79,6 +84,12 @@ if test \"$mode\" = \"stdout\"; then\n \texit 0\n fi\n \n+if git var GIT_EDITOR | grep emacsclient >/dev/null; then\n+\ttype \"mode_$mode\" >/dev/null 2>&1 || { usage >&2; exit 1; }\n+\topen_emacsclient \"$mode\" \"$@\"\n+\texit 0\n+fi\n+\n trap 'rm -f \"$tmp\"' 0 1 2 3 15\n tmp=`mktemp -t git-jump.XXXXXX` || exit 1\n type \"mode_$mode\" >/dev/null 2>&1 || { usage >&2; exit 1; }\n-- \ngitgitgadget\n"},{"id":"467655","messageId":"CAF5D8-uYU3WdDW1GY=G9hcRkKx73Ha6dwdMQ19XcQS8630+mWA@mail.gmail.com","threadId":"58820","inReplyTo":"CAPig+cR6+H2gqZbnj9FHzZRefwTjYme94kNeQ9qmVi-wLYZ6fw@mail.gmail.com","subject":"Re: [PATCH 2/2] git-jump: invoke emacsclient","fromName":"Yoichi Nakayama","fromEmail":"yoichi.nakayama@gmail.com","sentAt":"2022-11-21T04:05:32Z","receivedAt":"2022-11-21T04:05:48Z","isPatch":true,"sender":{"key":"yoichi.nakayama@gmail.com","avatar":"https://avatars.githubusercontent.com/u/107537?v=4"},"body":"> > Also, on macOS, I need to set EDITOR (or GIT_EDITOR or VISUAL) to the\n> > full path of emacsclient, but the regex used here is too tight to\n> > recognize that. Perhaps loosening it to just 'emacsclient' would be a\n> > good idea (as it seems unlikely to falsely match any other editor)?\n>\n> It is a good idea. Thanks!\n\nI found we can support both emacs and emacsclient by using --eval\noption instead of -e option.\nI'll deal with it.\n\nOn Sun, Nov 20, 2022 at 8:59 AM Eric Sunshine <sunshine@sunshineco.com> wrote:\n>\n> On Sat, Nov 19, 2022 at 6:44 PM Yoichi Nakayama\n> <yoichi.nakayama@gmail.com> wrote:\n> > On Sun, Nov 20, 2022 at 12:53 AM Eric Sunshine <sunshine@sunshineco.com> wrote:\n> > > Would it make sense to expand this to support the VISUAL and EDITOR\n> > > environment variables too? For instance, since I want to use Emacs for\n> > > all my editing needs, I have EDITOR set to reference emacsclient. So,\n> > > if GIT_EDITOR is unset, then check VISUAL, and if that is unset, check\n> > > EDITOR.\n> >\n> > \"git var GIT_EDITOR\" does respect VISUAL and EDITOR environment variables.\n> > See git-var(1) reference manual.\n>\n> Excellent.\n>\n> > > Also, on macOS, I need to set EDITOR (or GIT_EDITOR or VISUAL) to the\n> > > full path of emacsclient, but the regex used here is too tight to\n> > > recognize that. Perhaps loosening it to just 'emacsclient' would be a\n> > > good idea (as it seems unlikely to falsely match any other editor)?\n> >\n> > It is a good idea. Thanks!\n>\n> Thanks.\n\n\n\n-- \nYoichi NAKAYAMA\n"},{"id":"467659","messageId":"xmqqedtwyi94.fsf@gitster.g","threadId":"58820","inReplyTo":"e56858a3eb212dcd0b8f71bdbf8db96f51c5d648.1668907644.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v2 1/2] git-jump: add an optional argument 'stdout'","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-11-21T05:43:51Z","receivedAt":"2022-11-21T05:43:56Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Yoichi Nakayama via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n\n> +You can use the optional argument 'stdout' to print the listing to\n> +standard output. You can use it with M-x grep on Emacs.\n\nIt is unclear what happens when you do not give 'stdout' from the\nabove description.  You say 'stdout' is a way to tell the command\n\"to print the listing to standard output\", but what is expected to\nfollow that sentence is left unsaid (i.e. \"you can give 'stdout' to\nprint to stdout, INSTEAD OF DOING X\").\n\nAlso, \n\n> +--------------------------------------------------\n> +# In Emacs, M-x grep and invoke \"git jump stdout <mode>\"\n> +Run grep (like this): git jump stdout diff\n\nthe command line structure of \"git jump\" being\n\n    git jump <mode> [<args>]\n\nwhere <mode> is one of 'diff', 'merge', 'grep', it somehow feels\nvery strange to insert an optional new word, that is not a dashed\noption, before the <mode>.  \"git jump --stdout diff\" might be less\nsurprising, but I dunno.\n\nBut I think this is a good idea.  In fact, it almost feels that the\ninterface to produce the list of \"$file:$line: <blah>\" that this\n\"stdout\" mode gives should have been in the command as the lowest\nlevel basic primitive, upon which the feature to drive a specific\neditor using such an output file should have been built, and the\ncurrent code is backwards in that sense.  Exposing that lower level\nprimitive directly is a welcome addition.\n\n\n"},{"id":"467670","messageId":"CAF5D8-uYnNkH-BkW0QNhBybQNN3ym5=S2FwZVjgouaqcXL2MMw@mail.gmail.com","threadId":"58820","inReplyTo":"xmqqedtwyi94.fsf@gitster.g","subject":"Re: [PATCH v2 1/2] git-jump: add an optional argument 'stdout'","fromName":"Yoichi Nakayama","fromEmail":"yoichi.nakayama@gmail.com","sentAt":"2022-11-21T11:25:23Z","receivedAt":"2022-11-21T11:31:32Z","isPatch":true,"sender":{"key":"yoichi.nakayama@gmail.com","avatar":"https://avatars.githubusercontent.com/u/107537?v=4"},"body":"On Mon, Nov 21, 2022 at 2:43 PM Junio C Hamano <gitster@pobox.com> wrote:\n>\n> \"Yoichi Nakayama via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n>\n> > +You can use the optional argument 'stdout' to print the listing to\n> > +standard output. You can use it with M-x grep on Emacs.\n>\n> It is unclear what happens when you do not give 'stdout' from the\n> above description.  You say 'stdout' is a way to tell the command\n> \"to print the listing to standard output\", but what is expected to\n> follow that sentence is left unsaid (i.e. \"you can give 'stdout' to\n> print to stdout, INSTEAD OF DOING X\").\n\nI agree. I'll add \"instead of feeding it to the editor\".\n\n> > +# In Emacs, M-x grep and invoke \"git jump stdout <mode>\"\n> > +Run grep (like this): git jump stdout diff\n>\n> the command line structure of \"git jump\" being\n>\n>     git jump <mode> [<args>]\n>\n> where <mode> is one of 'diff', 'merge', 'grep', it somehow feels\n> very strange to insert an optional new word, that is not a dashed\n> option, before the <mode>.  \"git jump --stdout diff\" might be less\n> surprising, but I dunno.\n>\n> But I think this is a good idea.  In fact, it almost feels that the\n> interface to produce the list of \"$file:$line: <blah>\" that this\n> \"stdout\" mode gives should have been in the command as the lowest\n> level basic primitive, upon which the feature to drive a specific\n> editor using such an output file should have been built, and the\n> current code is backwards in that sense.  Exposing that lower level\n> primitive directly is a welcome addition.\n\nThank you for your thoughtful consideration.\nThe value of git-jump is to launch the editor quickly from the command line.\nI think it's rare to manually use the additional option (e.g. M-x grep\nin Emacs).\nTherefore, I think there is not much needs to expose it directly.\nI'll change it to less surprising form \"--stdout\".\n-- \nYoichi NAKAYAMA\n"},{"id":"467680","messageId":"pull.1423.v3.git.1669033620.gitgitgadget@gmail.com","threadId":"58820","inReplyTo":"pull.1423.v2.git.1668907644.gitgitgadget@gmail.com","subject":"[PATCH v3 0/2] git-jump: support Emacs","fromName":"Yoichi NAKAYAMA via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2022-11-21T12:26:58Z","receivedAt":"2022-11-21T12:27:08Z","isPatch":true,"sender":{"key":"yoichi.nakayama@gmail.com","avatar":"https://avatars.githubusercontent.com/u/107537?v=4"},"body":"Add an optional argument 'stdout' to print the quickfix lines to standard\noutput. It can be used with M-x grep on Emacs.\n\nDetect emacsclient by GIT_EDITOR and invoke the function. Tested with\nEDITOR=\"emacsclient\" and EDITOR=\"emacsclient -t\".\n\nYoichi Nakayama (2):\n  git-jump: add an optional argument '--stdout'\n  git-jump: invoke emacs/emacsclient\n\n contrib/git-jump/README   | 10 +++++++++-\n contrib/git-jump/git-jump | 23 ++++++++++++++++++++++-\n 2 files changed, 31 insertions(+), 2 deletions(-)\n\n\nbase-commit: eea7033409a0ed713c78437fc76486983d211e25\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-1423%2Fyoichi%2Fgit-jump-emacs-support-v3\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1423/yoichi/git-jump-emacs-support-v3\nPull-Request: https://github.com/gitgitgadget/git/pull/1423\n\nRange-diff vs v2:\n\n 1:  e56858a3eb2 ! 1:  ccfea26de33 git-jump: add an optional argument 'stdout'\n     @@ Metadata\n      Author: Yoichi Nakayama <yoichi.nakayama@gmail.com>\n      \n       ## Commit message ##\n     -    git-jump: add an optional argument 'stdout'\n     +    git-jump: add an optional argument '--stdout'\n      \n          It can be used with M-x grep on Emacs.\n      \n     @@ contrib/git-jump/README: git jump grep -i foo_bar\n       git config jump.grepCmd \"ag --column\"\n       --------------------------------------------------\n       \n     -+You can use the optional argument 'stdout' to print the listing to\n     -+standard output. You can use it with M-x grep on Emacs.\n     ++You can use the optional argument '--stdout' to print the listing to\n     ++standard output instead of feeding it to the editor. You can use the\n     ++argument with M-x grep on Emacs:\n      +\n      +--------------------------------------------------\n     -+# In Emacs, M-x grep and invoke \"git jump stdout <mode>\"\n     -+Run grep (like this): git jump stdout diff\n     ++# In Emacs, M-x grep and invoke \"git jump --stdout <mode>\"\n     ++Run grep (like this): git jump --stdout diff\n      +--------------------------------------------------\n       \n       Related Programs\n     @@ contrib/git-jump/git-jump\n       usage() {\n       \tcat <<\\EOF\n      -usage: git jump <mode> [<args>]\n     -+usage: git jump [stdout] <mode> [<args>]\n     ++usage: git jump [--stdout] <mode> [<args>]\n       \n       Jump to interesting elements in an editor.\n       The <mode> parameter is one of:\n     @@ contrib/git-jump/git-jump: grep: elements are grep hits. Arguments are given to\n       \n       ws: elements are whitespace errors. Arguments are given to diff --check.\n      +\n     -+If the optional argument `stdout` is given, print the quickfix\n     -+lines to standard output.\n     ++If the optional argument `--stdout` is given, print the quickfix\n     ++lines to standard output instead of feeding it to the editor.\n       EOF\n       }\n       \n     @@ contrib/git-jump/git-jump: if test $# -lt 1; then\n       \texit 1\n       fi\n       mode=$1; shift\n     -+if test \"$mode\" = \"stdout\"; then\n     ++if test \"$mode\" = \"--stdout\"; then\n      +\tmode=$1; shift\n      +\ttype \"mode_$mode\" >/dev/null 2>&1 || { usage >&2; exit 1; }\n      +\t\"mode_$mode\" \"$@\" 2>/dev/null\n 2:  72c4fd5532b ! 2:  b4ad4c083c9 git-jump: invoke emacsclient\n     @@ Metadata\n      Author: Yoichi Nakayama <yoichi.nakayama@gmail.com>\n      \n       ## Commit message ##\n     -    git-jump: invoke emacsclient\n     +    git-jump: invoke emacs/emacsclient\n      \n     -    It works with GIT_EDITOR=\"emacsclient\" or GIT_EDITOR=\"emacsclient -t\"\n     +    It works with GIT_EDITOR=\"emacs\", \"emacsclient\" or \"emacsclient -t\"\n      \n          Signed-off-by: Yoichi Nakayama <yoichi.nakayama@gmail.com>\n      \n     @@ contrib/git-jump/git-jump: open_editor() {\n       \teval \"$editor -q \\$1\"\n       }\n       \n     -+open_emacsclient() {\n     ++open_emacs() {\n      +\teditor=`git var GIT_EDITOR`\n     -+\teval \"$editor -e \\\"(prog1 (switch-to-buffer-other-frame (grep \\\\\\\"git jump stdout $@\\\\\\\")) (delete-other-windows) (select-frame-set-input-focus (selected-frame)))\\\"\"\n     ++\teval \"$editor --eval \\\"(prog1 (switch-to-buffer-other-frame (compilation-start \\\\\\\"git jump --stdout $@\\\\\\\" 'grep-mode)) (delete-other-windows) (select-frame-set-input-focus (selected-frame)))\\\"\"\n      +}\n      +\n       mode_diff() {\n       \tgit diff --no-prefix --relative \"$@\" |\n       \tperl -ne '\n     -@@ contrib/git-jump/git-jump: if test \"$mode\" = \"stdout\"; then\n     +@@ contrib/git-jump/git-jump: if test \"$mode\" = \"--stdout\"; then\n       \texit 0\n       fi\n       \n     -+if git var GIT_EDITOR | grep emacsclient >/dev/null; then\n     ++# For emacs/emacsclient, call \"git jump --stdout\" from inside of them.\n     ++if git var GIT_EDITOR | grep emacs >/dev/null; then\n      +\ttype \"mode_$mode\" >/dev/null 2>&1 || { usage >&2; exit 1; }\n     -+\topen_emacsclient \"$mode\" \"$@\"\n     ++\topen_emacs \"$mode\" \"$@\"\n      +\texit 0\n      +fi\n      +\n\n-- \ngitgitgadget\n"},{"id":"467681","messageId":"ccfea26de333ac5a08a5df4c9b790811067bd437.1669033620.git.gitgitgadget@gmail.com","threadId":"58820","inReplyTo":"pull.1423.v3.git.1669033620.gitgitgadget@gmail.com","subject":"[PATCH v3 1/2] git-jump: add an optional argument '--stdout'","fromName":"Yoichi Nakayama via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2022-11-21T12:26:59Z","receivedAt":"2022-11-21T12:27:10Z","isPatch":true,"sender":{"key":"yoichi.nakayama@gmail.com","avatar":"https://avatars.githubusercontent.com/u/107537?v=4"},"body":"From: Yoichi Nakayama <yoichi.nakayama@gmail.com>\n\nIt can be used with M-x grep on Emacs.\n\nSigned-off-by: Yoichi Nakayama <yoichi.nakayama@gmail.com>\n---\n contrib/git-jump/README   | 10 +++++++++-\n contrib/git-jump/git-jump | 11 ++++++++++-\n 2 files changed, 19 insertions(+), 2 deletions(-)\n\ndiff --git a/contrib/git-jump/README b/contrib/git-jump/README\nindex 8bcace29d21..0340980959b 100644\n--- a/contrib/git-jump/README\n+++ b/contrib/git-jump/README\n@@ -79,6 +79,14 @@ git jump grep -i foo_bar\n git config jump.grepCmd \"ag --column\"\n --------------------------------------------------\n \n+You can use the optional argument '--stdout' to print the listing to\n+standard output instead of feeding it to the editor. You can use the\n+argument with M-x grep on Emacs:\n+\n+--------------------------------------------------\n+# In Emacs, M-x grep and invoke \"git jump --stdout <mode>\"\n+Run grep (like this): git jump --stdout diff\n+--------------------------------------------------\n \n Related Programs\n ----------------\n@@ -100,7 +108,7 @@ Limitations\n -----------\n \n This script was written and tested with vim. Given that the quickfix\n-format is the same as what gcc produces, I expect emacs users have a\n+format is the same as what gcc produces, I expect other tools have a\n similar feature for iterating through the list, but I know nothing about\n how to activate it.\n \ndiff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump\nindex 92dbd4cde18..091d1add0ec 100755\n--- a/contrib/git-jump/git-jump\n+++ b/contrib/git-jump/git-jump\n@@ -2,7 +2,7 @@\n \n usage() {\n \tcat <<\\EOF\n-usage: git jump <mode> [<args>]\n+usage: git jump [--stdout] <mode> [<args>]\n \n Jump to interesting elements in an editor.\n The <mode> parameter is one of:\n@@ -15,6 +15,9 @@ grep: elements are grep hits. Arguments are given to git grep or, if\n       configured, to the command in `jump.grepCmd`.\n \n ws: elements are whitespace errors. Arguments are given to diff --check.\n+\n+If the optional argument `--stdout` is given, print the quickfix\n+lines to standard output instead of feeding it to the editor.\n EOF\n }\n \n@@ -69,6 +72,12 @@ if test $# -lt 1; then\n \texit 1\n fi\n mode=$1; shift\n+if test \"$mode\" = \"--stdout\"; then\n+\tmode=$1; shift\n+\ttype \"mode_$mode\" >/dev/null 2>&1 || { usage >&2; exit 1; }\n+\t\"mode_$mode\" \"$@\" 2>/dev/null\n+\texit 0\n+fi\n \n trap 'rm -f \"$tmp\"' 0 1 2 3 15\n tmp=`mktemp -t git-jump.XXXXXX` || exit 1\n-- \ngitgitgadget\n\n"},{"id":"467682","messageId":"b4ad4c083c96d20873a649aab5f39cd061bd662a.1669033620.git.gitgitgadget@gmail.com","threadId":"58820","inReplyTo":"pull.1423.v3.git.1669033620.gitgitgadget@gmail.com","subject":"[PATCH v3 2/2] git-jump: invoke emacs/emacsclient","fromName":"Yoichi Nakayama via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2022-11-21T12:27:00Z","receivedAt":"2022-11-21T12:27:10Z","isPatch":true,"sender":{"key":"yoichi.nakayama@gmail.com","avatar":"https://avatars.githubusercontent.com/u/107537?v=4"},"body":"From: Yoichi Nakayama <yoichi.nakayama@gmail.com>\n\nIt works with GIT_EDITOR=\"emacs\", \"emacsclient\" or \"emacsclient -t\"\n\nSigned-off-by: Yoichi Nakayama <yoichi.nakayama@gmail.com>\n---\n contrib/git-jump/git-jump | 12 ++++++++++++\n 1 file changed, 12 insertions(+)\n\ndiff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump\nindex 091d1add0ec..43ca8bb1ee7 100755\n--- a/contrib/git-jump/git-jump\n+++ b/contrib/git-jump/git-jump\n@@ -26,6 +26,11 @@ open_editor() {\n \teval \"$editor -q \\$1\"\n }\n \n+open_emacs() {\n+\teditor=`git var GIT_EDITOR`\n+\teval \"$editor --eval \\\"(prog1 (switch-to-buffer-other-frame (compilation-start \\\\\\\"git jump --stdout $@\\\\\\\" 'grep-mode)) (delete-other-windows) (select-frame-set-input-focus (selected-frame)))\\\"\"\n+}\n+\n mode_diff() {\n \tgit diff --no-prefix --relative \"$@\" |\n \tperl -ne '\n@@ -79,6 +84,13 @@ if test \"$mode\" = \"--stdout\"; then\n \texit 0\n fi\n \n+# For emacs/emacsclient, call \"git jump --stdout\" from inside of them.\n+if git var GIT_EDITOR | grep emacs >/dev/null; then\n+\ttype \"mode_$mode\" >/dev/null 2>&1 || { usage >&2; exit 1; }\n+\topen_emacs \"$mode\" \"$@\"\n+\texit 0\n+fi\n+\n trap 'rm -f \"$tmp\"' 0 1 2 3 15\n tmp=`mktemp -t git-jump.XXXXXX` || exit 1\n type \"mode_$mode\" >/dev/null 2>&1 || { usage >&2; exit 1; }\n-- \ngitgitgadget\n"},{"id":"467704","messageId":"Y3vA5Jc3f84YIoYw@coredump.intra.peff.net","threadId":"58820","inReplyTo":"xmqqedtwyi94.fsf@gitster.g","subject":"Re: [PATCH v2 1/2] git-jump: add an optional argument 'stdout'","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2022-11-21T18:18:12Z","receivedAt":"2022-11-21T18:18:17Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Nov 21, 2022 at 02:43:51PM +0900, Junio C Hamano wrote:\n\n> the command line structure of \"git jump\" being\n> \n>     git jump <mode> [<args>]\n> \n> where <mode> is one of 'diff', 'merge', 'grep', it somehow feels\n> very strange to insert an optional new word, that is not a dashed\n> option, before the <mode>.  \"git jump --stdout diff\" might be less\n> surprising, but I dunno.\n\nFWIW, I had the same reaction: it should be --stdout.\n\n> But I think this is a good idea.  In fact, it almost feels that the\n> interface to produce the list of \"$file:$line: <blah>\" that this\n> \"stdout\" mode gives should have been in the command as the lowest\n> level basic primitive, upon which the feature to drive a specific\n> editor using such an output file should have been built, and the\n> current code is backwards in that sense.  Exposing that lower level\n> primitive directly is a welcome addition.\n\nThe main reason I didn't start with that primitive is because the\ninitial outputs were pretty simple and based around \"grep -n\" output.\nBut they've gotten a bit more complicated over time, especially the\n\"diff\" one. I agree that just dumping the quickfix list is a good\nfeature to have.\n\n-Peff\n"},{"id":"467705","messageId":"Y3vFpNbWswu/8gjb@coredump.intra.peff.net","threadId":"58820","inReplyTo":"ccfea26de333ac5a08a5df4c9b790811067bd437.1669033620.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v3 1/2] git-jump: add an optional argument '--stdout'","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2022-11-21T18:38:28Z","receivedAt":"2022-11-21T18:38:36Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Nov 21, 2022 at 12:26:59PM +0000, Yoichi Nakayama via GitGitGadget wrote:\n\n> From: Yoichi Nakayama <yoichi.nakayama@gmail.com>\n> \n> It can be used with M-x grep on Emacs.\n\nThanks, I like what this feature is doing overall, but I have some small\nnits about the implementation.\n\n> +You can use the optional argument '--stdout' to print the listing to\n> +standard output instead of feeding it to the editor. You can use the\n> +argument with M-x grep on Emacs:\n> +\n> +--------------------------------------------------\n> +# In Emacs, M-x grep and invoke \"git jump --stdout <mode>\"\n> +Run grep (like this): git jump --stdout diff\n> +--------------------------------------------------\n\nThis example confused me because it says \"run grep\", but then runs a\ndiff jump. But maybe this is because it means to run the emacs grep\ncommand? I don't use emacs, so it may make more sense to somebody who\ndoes.\n\n> @@ -69,6 +72,12 @@ if test $# -lt 1; then\n>  \texit 1\n>  fi\n>  mode=$1; shift\n> +if test \"$mode\" = \"--stdout\"; then\n> +\tmode=$1; shift\n> +\ttype \"mode_$mode\" >/dev/null 2>&1 || { usage >&2; exit 1; }\n> +\t\"mode_$mode\" \"$@\" 2>/dev/null\n> +\texit 0\n> +fi\n\nBecause this happens after we check that \"$1\" isn't empty and call\nshift, it may not notice if the mode is missing when we do this second\nshift. I.e., with your patch I get:\n\n  $ ./git-jump --stdout\n  ./git-jump: 76: shift: can't shift that many\n\nwhen I should get the usage message. We can fix that by parsing out\n--stdout before we try to read the mode. It's a little more code, but I\nthink it nicely sets us up if we ever want to parse more options.\n\nIt's also unfortunate that we have to repeat the ugly \"type\" check\nabove, which also happens again later, after we make the temp file. I\nsee why you did it this way; the stdout code path does not want to make\nthe tempfile. But the code before your patch was silly to do it this\nway; we should always have been checking the parameters before making a\ntempfile.\n\nI was also puzzled why the stdout mode redirects stderr from the mode\nfunction. Wouldn't the user want to see any errors?\n\nSo together, it might look something like this (instead of, rather than\non top of your patch):\n\ndiff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump\nindex b9cc602ebf..05a0ff1430 100755\n--- a/contrib/git-jump/git-jump\n+++ b/contrib/git-jump/git-jump\n@@ -67,15 +67,38 @@ mode_ws() {\n \tgit diff --check \"$@\"\n }\n \n+use_stdout=\n+while test $# -gt 0; do\n+\tcase \"$1\" in\n+\t--stdout)\n+\t\tuse_stdout=t\n+\t\tshift\n+\t\t;;\n+\t--*)\n+\t\tusage >&2\n+\t\texit 1\n+\t\t;;\n+\t*)\n+\t\tbreak\n+\t\t;;\n+\tesac\n+done\n+\n if test $# -lt 1; then\n \tusage >&2\n \texit 1\n fi\n+\n mode=$1; shift\n+type \"mode_$mode\" >/dev/null 2>&1 || { usage >&2; exit 1; }\n+\n+if test \"$use_stdout\" = \"t\"; then\n+\t\"mode_$mode\" \"$@\"\n+\texit 0\n+fi\n \n trap 'rm -f \"$tmp\"' 0 1 2 3 15\n tmp=`mktemp -t git-jump.XXXXXX` || exit 1\n-type \"mode_$mode\" >/dev/null 2>&1 || { usage >&2; exit 1; }\n \"mode_$mode\" \"$@\" >\"$tmp\"\n test -s \"$tmp\" || exit 0\n open_editor \"$tmp\"\n\nThough I'd perhaps break some of the shuffling into a preparatory patch.\nI'm happy to do that separately if you prefer.\n\n-Peff\n"},{"id":"467708","messageId":"Y3vId3rOmmkJnkGj@coredump.intra.peff.net","threadId":"58820","inReplyTo":"b4ad4c083c96d20873a649aab5f39cd061bd662a.1669033620.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v3 2/2] git-jump: invoke emacs/emacsclient","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2022-11-21T18:50:31Z","receivedAt":"2022-11-21T18:50:37Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Nov 21, 2022 at 12:27:00PM +0000, Yoichi Nakayama via GitGitGadget wrote:\n\n> +open_emacs() {\n> +\teditor=`git var GIT_EDITOR`\n> +\teval \"$editor --eval \\\"(prog1 (switch-to-buffer-other-frame (compilation-start \\\\\\\"git jump --stdout $@\\\\\\\" 'grep-mode)) (delete-other-windows) (select-frame-set-input-focus (selected-frame)))\\\"\"\n> +}\n\nI think this subjects the user's arguments to an extra round of\nwhitespace splitting. E.g., if I do:\n\n  git jump grep 'foo bar'\n\nthen the emacs command will see two arguments. The first is \"--eval\",\nand the second is the whole string:\n\n  prog1 (switch-to-buffer-other-frame (compilation-start \"git jump --stdout grep foo bar\" 'grep-mode)) (delete-other-windows) (select-frame-set-input-focus (selected-frame)))\n\nBut now we've lost fact that \"foo bar\" was a single string, and git-grep\nwill complain (because it treats \"bar\" as a file to look in, which does\nnot exist).\n\nYou'll have to either shell-quote the contents, or stuff it in a\ntempfile and read it with something like \"cat /path/to/tempfile\" in the\nemacs command (though I'm not sure if that would be racy when you're\nusing something like emacsclient which may exit before the main emacs\nprocess runs the command).\n\n-Peff\n"},{"id":"467727","messageId":"xmqq35abvpxm.fsf@gitster.g","threadId":"58820","inReplyTo":"Y3vFpNbWswu/8gjb@coredump.intra.peff.net","subject":"Re: [PATCH v3 1/2] git-jump: add an optional argument '--stdout'","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-11-21T23:38:29Z","receivedAt":"2022-11-21T23:38:41Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> On Mon, Nov 21, 2022 at 12:26:59PM +0000, Yoichi Nakayama via GitGitGadget wrote:\n>\n>> From: Yoichi Nakayama <yoichi.nakayama@gmail.com>\n>> \n>> It can be used with M-x grep on Emacs.\n>\n> Thanks, I like what this feature is doing overall, but I have some small\n> nits about the implementation.\n>\n>> +You can use the optional argument '--stdout' to print the listing to\n>> +standard output instead of feeding it to the editor. You can use the\n>> +argument with M-x grep on Emacs:\n>> +\n>> +--------------------------------------------------\n>> +# In Emacs, M-x grep and invoke \"git jump --stdout <mode>\"\n>> +Run grep (like this): git jump --stdout diff\n>> +--------------------------------------------------\n>\n> This example confused me because it says \"run grep\", but then runs a\n> diff jump. But maybe this is because it means to run the emacs grep\n> command? I don't use emacs, so it may make more sense to somebody who\n> does.\n\nYes.  \"M-x\" gives Emacs users a command line prompt to type (and tab\ncomplete) an Emacs command, and in the above explanation, the user\nis running the \"grep\" command of Emacs, which in turn prompts for a\nshell command that produces series of <filename>:<lineno>:<cruft> to\njump around [*].\n\n\"M-x grep<RET>git jump --stdout diff<RET>\" is what I would have\nwritten on the second line instead of \"Run grep (like this)...\".\n\n[Footnote]\n\n* People often run \"grep -n -r -e <pattern>\" but you can run things\nlike \"git grep -n -e <pattern> -- <pathspec>\" and \"find -name \\*.h |\nxargs grep -n -e <pattern>\".\n"},{"id":"467758","messageId":"CAF5D8-sAmxDkduPbvEf-myr6iBm0N00SEDgCcSfNE99t9qSBmw@mail.gmail.com","threadId":"58820","inReplyTo":"Y3vId3rOmmkJnkGj@coredump.intra.peff.net","subject":"Re: [PATCH v3 2/2] git-jump: invoke emacs/emacsclient","fromName":"Yoichi Nakayama","fromEmail":"yoichi.nakayama@gmail.com","sentAt":"2022-11-22T12:06:05Z","receivedAt":"2022-11-22T12:06:25Z","isPatch":true,"sender":{"key":"yoichi.nakayama@gmail.com","avatar":"https://avatars.githubusercontent.com/u/107537?v=4"},"body":"On Tue, Nov 22, 2022 at 3:50 AM Jeff King <peff@peff.net> wrote:\n> You'll have to either shell-quote the contents, or stuff it in a\n> tempfile and read it with something like \"cat /path/to/tempfile\" in the\n> emacs command (though I'm not sure if that would be racy when you're\n> using something like emacsclient which may exit before the main emacs\n> process runs the command).\n\nAs you pointed out, the previous implementation has a problem in cases such as:\n      git jump grep \"hello world\"\n\nThe reason I avoided using temporary files in the previous implementation was\na race condition when editor=\"emacsclient\" (emacsclient exits without\nwaiting for\nthe asynchronous execution of the external command). But I found a way around\nthe race condition, so I'll change to use cat on a temporary file.\n\nThanks,\n-- \nYoichi NAKAYAMA\n"},{"id":"467759","messageId":"CAF5D8-uQ633azqUfCv0vyQzFUaQdDhOwzEc8GOGnFrgmh-c9pQ@mail.gmail.com","threadId":"58820","inReplyTo":"xmqq35abvpxm.fsf@gitster.g","subject":"Re: [PATCH v3 1/2] git-jump: add an optional argument '--stdout'","fromName":"Yoichi Nakayama","fromEmail":"yoichi.nakayama@gmail.com","sentAt":"2022-11-22T13:00:45Z","receivedAt":"2022-11-22T13:01:02Z","isPatch":true,"sender":{"key":"yoichi.nakayama@gmail.com","avatar":"https://avatars.githubusercontent.com/u/107537?v=4"},"body":"On Tue, Nov 22, 2022 at 8:38 AM Junio C Hamano <gitster@pobox.com> wrote:\n>\n> Jeff King <peff@peff.net> writes:\n>\n> > On Mon, Nov 21, 2022 at 12:26:59PM +0000, Yoichi Nakayama via GitGitGadget wrote:\n> >\n> >> From: Yoichi Nakayama <yoichi.nakayama@gmail.com>\n> >> +--------------------------------------------------\n> >> +# In Emacs, M-x grep and invoke \"git jump --stdout <mode>\"\n> >> +Run grep (like this): git jump --stdout diff\n> >> +--------------------------------------------------\n> >\n> > This example confused me because it says \"run grep\", but then runs a\n> > diff jump. But maybe this is because it means to run the emacs grep\n> > command? I don't use emacs, so it may make more sense to somebody who\n> > does.\n>\n> Yes.  \"M-x\" gives Emacs users a command line prompt to type (and tab\n> complete) an Emacs command, and in the above explanation, the user\n> is running the \"grep\" command of Emacs, which in turn prompts for a\n> shell command that produces series of <filename>:<lineno>:<cruft> to\n> jump around [*].\n>\n> \"M-x grep<RET>git jump --stdout diff<RET>\" is what I would have\n> written on the second line instead of \"Run grep (like this)...\".\n\nI think Junio's suggestion of  \"M-x grep<RET>git jump --stdout diff<RET>\"\nis concise and understandable to most Emacs users, so I'd like to adopt it.\n\nBelow are the details of what I thought:\n\nBy M-x grep<RET>, Emacs displays\n      Run grep (like this): grep --color=auto -nH --null -e\nwhere\n- \"Run grep (like this): \" is a prompt (like \"$ \" in bash).\n- \"grep --color=auto -nH --null -e \" is a part of search command (missing\n  keyword part). We can supply \"keyword<RET>\" to execute the search.\n  We can also remove the whole command and replace it with the command\n  like \"git jump --stdout diff\".\n\nSo \"M-x grep<RET>git jump --stdout diff<RET>\" does not represent the\ncomplete procedure. It lacks the operation to remove the default command\n(controlled by the grep-command setting). For example, adding C-a C-k\nafter \"M-x grep<RET>\" is more accurate, but it feels a bit redundant.\n-- \nYoichi NAKAYAMA\n"},{"id":"467760","messageId":"CAF5D8-vjSz__06-Oy=GbByVL=_sqU5SXkjt3uLEjQKkVyBEgEA@mail.gmail.com","threadId":"58820","inReplyTo":"Y3vFpNbWswu/8gjb@coredump.intra.peff.net","subject":"Re: [PATCH v3 1/2] git-jump: add an optional argument '--stdout'","fromName":"Yoichi Nakayama","fromEmail":"yoichi.nakayama@gmail.com","sentAt":"2022-11-22T13:29:59Z","receivedAt":"2022-11-22T13:30:17Z","isPatch":true,"sender":{"key":"yoichi.nakayama@gmail.com","avatar":"https://avatars.githubusercontent.com/u/107537?v=4"},"body":"On Tue, Nov 22, 2022 at 3:38 AM Jeff King <peff@peff.net> wrote:\n> It's also unfortunate that we have to repeat the ugly \"type\" check\n> above, which also happens again later, after we make the temp file. I\n> see why you did it this way; the stdout code path does not want to make\n> the tempfile. But the code before your patch was silly to do it this\n> way; we should always have been checking the parameters before making a\n> tempfile.\n>\n> I was also puzzled why the stdout mode redirects stderr from the mode\n> function. Wouldn't the user want to see any errors?\n>\n> So together, it might look something like this (instead of, rather than\n> on top of your patch):\n\nThanks. I've applied it.\n\nI was throwing away stderr because Emacs' M-x grep inserted both stdout\nand stderr into the output destination, and a perl warning was issued.\nHowever, the warning itself is meaningful, and I thought it would be very bad\nnot to know the reason when an error occurred, so I came to the conclusion\nthat stderr should be left as is.\n-- \nYoichi NAKAYAMA\n"},{"id":"467762","messageId":"pull.1423.v4.git.1669126703.gitgitgadget@gmail.com","threadId":"58820","inReplyTo":"pull.1423.v3.git.1669033620.gitgitgadget@gmail.com","subject":"[PATCH v4 0/2] git-jump: support Emacs","fromName":"Yoichi NAKAYAMA via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2022-11-22T14:18:21Z","receivedAt":"2022-11-22T14:18:30Z","isPatch":true,"sender":{"key":"yoichi.nakayama@gmail.com","avatar":"https://avatars.githubusercontent.com/u/107537?v=4"},"body":"Add an optional argument 'stdout' to print the quickfix lines to standard\noutput. It can be used with M-x grep on Emacs.\n\nDetect emacsclient by GIT_EDITOR and invoke the function. Tested with\nEDITOR=\"emacsclient\" and EDITOR=\"emacsclient -t\".\n\nYoichi Nakayama (2):\n  git-jump: add an optional argument '--stdout'\n  git-jump: invoke emacs/emacsclient\n\n contrib/git-jump/README   | 10 +++++++++-\n contrib/git-jump/git-jump | 40 ++++++++++++++++++++++++++++++++++++++-\n 2 files changed, 48 insertions(+), 2 deletions(-)\n\n\nbase-commit: eea7033409a0ed713c78437fc76486983d211e25\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-1423%2Fyoichi%2Fgit-jump-emacs-support-v4\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1423/yoichi/git-jump-emacs-support-v4\nPull-Request: https://github.com/gitgitgadget/git/pull/1423\n\nRange-diff vs v3:\n\n 1:  ccfea26de33 ! 1:  446777d300d git-jump: add an optional argument '--stdout'\n     @@ contrib/git-jump/README: git jump grep -i foo_bar\n      +\n      +--------------------------------------------------\n      +# In Emacs, M-x grep and invoke \"git jump --stdout <mode>\"\n     -+Run grep (like this): git jump --stdout diff\n     ++M-x grep<RET>git jump --stdout diff<RET>\n      +--------------------------------------------------\n       \n       Related Programs\n     @@ contrib/git-jump/git-jump: grep: elements are grep hits. Arguments are given to\n       EOF\n       }\n       \n     -@@ contrib/git-jump/git-jump: if test $# -lt 1; then\n     +@@ contrib/git-jump/git-jump: mode_ws() {\n     + \tgit diff --check \"$@\"\n     + }\n     + \n     ++use_stdout=\n     ++while test $# -gt 0; do\n     ++\tcase \"$1\" in\n     ++\t--stdout)\n     ++\t\tuse_stdout=t\n     ++\t\tshift\n     ++\t\t;;\n     ++\t--*)\n     ++\t\tusage >&2\n     ++\t\texit 1\n     ++\t\t;;\n     ++\t*)\n     ++\t\tbreak\n     ++\t\t;;\n     ++\tesac\n     ++done\n     + if test $# -lt 1; then\n     + \tusage >&2\n       \texit 1\n       fi\n       mode=$1; shift\n     -+if test \"$mode\" = \"--stdout\"; then\n     -+\tmode=$1; shift\n     -+\ttype \"mode_$mode\" >/dev/null 2>&1 || { usage >&2; exit 1; }\n     -+\t\"mode_$mode\" \"$@\" 2>/dev/null\n     ++if test \"$use_stdout\" = \"t\"; then\n     ++\t\"mode_$mode\" \"$@\"\n      +\texit 0\n      +fi\n       \n 2:  b4ad4c083c9 ! 2:  2f0bffb484b git-jump: invoke emacs/emacsclient\n     @@ contrib/git-jump/git-jump: open_editor() {\n       }\n       \n      +open_emacs() {\n     ++\t# Supported editor values are:\n     ++\t# - emacs\n     ++\t# - emacsclient\n     ++\t# - emacsclient -t\n      +\teditor=`git var GIT_EDITOR`\n     -+\teval \"$editor --eval \\\"(prog1 (switch-to-buffer-other-frame (compilation-start \\\\\\\"git jump --stdout $@\\\\\\\" 'grep-mode)) (delete-other-windows) (select-frame-set-input-focus (selected-frame)))\\\"\"\n     ++\t# Wait for completion of the asynchronously executed process\n     ++\t# to avoid race conditions in case of \"emacsclient\".\n     ++\teval \"$editor --eval \\\"(prog1 (switch-to-buffer-other-frame (compilation-start \\\\\\\"cat $@\\\\\\\" 'grep-mode)) (delete-other-windows) (while (get-buffer-process (current-buffer)) (sleep-for 0.1)) (select-frame-set-input-focus (selected-frame)))\\\"\"\n      +}\n      +\n       mode_diff() {\n       \tgit diff --no-prefix --relative \"$@\" |\n       \tperl -ne '\n     -@@ contrib/git-jump/git-jump: if test \"$mode\" = \"--stdout\"; then\n     - \texit 0\n     - fi\n     - \n     -+# For emacs/emacsclient, call \"git jump --stdout\" from inside of them.\n     +@@ contrib/git-jump/git-jump: tmp=`mktemp -t git-jump.XXXXXX` || exit 1\n     + type \"mode_$mode\" >/dev/null 2>&1 || { usage >&2; exit 1; }\n     + \"mode_$mode\" \"$@\" >\"$tmp\"\n     + test -s \"$tmp\" || exit 0\n      +if git var GIT_EDITOR | grep emacs >/dev/null; then\n     -+\ttype \"mode_$mode\" >/dev/null 2>&1 || { usage >&2; exit 1; }\n     -+\topen_emacs \"$mode\" \"$@\"\n     ++\topen_emacs \"$tmp\"\n      +\texit 0\n      +fi\n     -+\n     - trap 'rm -f \"$tmp\"' 0 1 2 3 15\n     - tmp=`mktemp -t git-jump.XXXXXX` || exit 1\n     - type \"mode_$mode\" >/dev/null 2>&1 || { usage >&2; exit 1; }\n     + open_editor \"$tmp\"\n\n-- \ngitgitgadget\n"},{"id":"467763","messageId":"446777d300d73498bd7da709fad75731a13d0d59.1669126703.git.gitgitgadget@gmail.com","threadId":"58820","inReplyTo":"pull.1423.v4.git.1669126703.gitgitgadget@gmail.com","subject":"[PATCH v4 1/2] git-jump: add an optional argument '--stdout'","fromName":"Yoichi Nakayama via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2022-11-22T14:18:22Z","receivedAt":"2022-11-22T14:18:36Z","isPatch":true,"sender":{"key":"yoichi.nakayama@gmail.com","avatar":"https://avatars.githubusercontent.com/u/107537?v=4"},"body":"From: Yoichi Nakayama <yoichi.nakayama@gmail.com>\n\nIt can be used with M-x grep on Emacs.\n\nSigned-off-by: Yoichi Nakayama <yoichi.nakayama@gmail.com>\n---\n contrib/git-jump/README   | 10 +++++++++-\n contrib/git-jump/git-jump | 25 ++++++++++++++++++++++++-\n 2 files changed, 33 insertions(+), 2 deletions(-)\n\ndiff --git a/contrib/git-jump/README b/contrib/git-jump/README\nindex 8bcace29d21..3211841305f 100644\n--- a/contrib/git-jump/README\n+++ b/contrib/git-jump/README\n@@ -79,6 +79,14 @@ git jump grep -i foo_bar\n git config jump.grepCmd \"ag --column\"\n --------------------------------------------------\n \n+You can use the optional argument '--stdout' to print the listing to\n+standard output instead of feeding it to the editor. You can use the\n+argument with M-x grep on Emacs:\n+\n+--------------------------------------------------\n+# In Emacs, M-x grep and invoke \"git jump --stdout <mode>\"\n+M-x grep<RET>git jump --stdout diff<RET>\n+--------------------------------------------------\n \n Related Programs\n ----------------\n@@ -100,7 +108,7 @@ Limitations\n -----------\n \n This script was written and tested with vim. Given that the quickfix\n-format is the same as what gcc produces, I expect emacs users have a\n+format is the same as what gcc produces, I expect other tools have a\n similar feature for iterating through the list, but I know nothing about\n how to activate it.\n \ndiff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump\nindex 92dbd4cde18..babb3b5c68d 100755\n--- a/contrib/git-jump/git-jump\n+++ b/contrib/git-jump/git-jump\n@@ -2,7 +2,7 @@\n \n usage() {\n \tcat <<\\EOF\n-usage: git jump <mode> [<args>]\n+usage: git jump [--stdout] <mode> [<args>]\n \n Jump to interesting elements in an editor.\n The <mode> parameter is one of:\n@@ -15,6 +15,9 @@ grep: elements are grep hits. Arguments are given to git grep or, if\n       configured, to the command in `jump.grepCmd`.\n \n ws: elements are whitespace errors. Arguments are given to diff --check.\n+\n+If the optional argument `--stdout` is given, print the quickfix\n+lines to standard output instead of feeding it to the editor.\n EOF\n }\n \n@@ -64,11 +67,31 @@ mode_ws() {\n \tgit diff --check \"$@\"\n }\n \n+use_stdout=\n+while test $# -gt 0; do\n+\tcase \"$1\" in\n+\t--stdout)\n+\t\tuse_stdout=t\n+\t\tshift\n+\t\t;;\n+\t--*)\n+\t\tusage >&2\n+\t\texit 1\n+\t\t;;\n+\t*)\n+\t\tbreak\n+\t\t;;\n+\tesac\n+done\n if test $# -lt 1; then\n \tusage >&2\n \texit 1\n fi\n mode=$1; shift\n+if test \"$use_stdout\" = \"t\"; then\n+\t\"mode_$mode\" \"$@\"\n+\texit 0\n+fi\n \n trap 'rm -f \"$tmp\"' 0 1 2 3 15\n tmp=`mktemp -t git-jump.XXXXXX` || exit 1\n-- \ngitgitgadget\n\n"},{"id":"467764","messageId":"2f0bffb484beccf58f2440ed5e2c04a1ba26e6c3.1669126703.git.gitgitgadget@gmail.com","threadId":"58820","inReplyTo":"pull.1423.v4.git.1669126703.gitgitgadget@gmail.com","subject":"[PATCH v4 2/2] git-jump: invoke emacs/emacsclient","fromName":"Yoichi Nakayama via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2022-11-22T14:18:23Z","receivedAt":"2022-11-22T14:18:45Z","isPatch":true,"sender":{"key":"yoichi.nakayama@gmail.com","avatar":"https://avatars.githubusercontent.com/u/107537?v=4"},"body":"From: Yoichi Nakayama <yoichi.nakayama@gmail.com>\n\nIt works with GIT_EDITOR=\"emacs\", \"emacsclient\" or \"emacsclient -t\"\n\nSigned-off-by: Yoichi Nakayama <yoichi.nakayama@gmail.com>\n---\n contrib/git-jump/git-jump | 15 +++++++++++++++\n 1 file changed, 15 insertions(+)\n\ndiff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump\nindex babb3b5c68d..bfd759aa4b2 100755\n--- a/contrib/git-jump/git-jump\n+++ b/contrib/git-jump/git-jump\n@@ -26,6 +26,17 @@ open_editor() {\n \teval \"$editor -q \\$1\"\n }\n \n+open_emacs() {\n+\t# Supported editor values are:\n+\t# - emacs\n+\t# - emacsclient\n+\t# - emacsclient -t\n+\teditor=`git var GIT_EDITOR`\n+\t# Wait for completion of the asynchronously executed process\n+\t# to avoid race conditions in case of \"emacsclient\".\n+\teval \"$editor --eval \\\"(prog1 (switch-to-buffer-other-frame (compilation-start \\\\\\\"cat $@\\\\\\\" 'grep-mode)) (delete-other-windows) (while (get-buffer-process (current-buffer)) (sleep-for 0.1)) (select-frame-set-input-focus (selected-frame)))\\\"\"\n+}\n+\n mode_diff() {\n \tgit diff --no-prefix --relative \"$@\" |\n \tperl -ne '\n@@ -98,4 +109,8 @@ tmp=`mktemp -t git-jump.XXXXXX` || exit 1\n type \"mode_$mode\" >/dev/null 2>&1 || { usage >&2; exit 1; }\n \"mode_$mode\" \"$@\" >\"$tmp\"\n test -s \"$tmp\" || exit 0\n+if git var GIT_EDITOR | grep emacs >/dev/null; then\n+\topen_emacs \"$tmp\"\n+\texit 0\n+fi\n open_editor \"$tmp\"\n-- \ngitgitgadget\n"},{"id":"467772","messageId":"61b42a7c-5772-dec2-c895-386f1613ac35@dunelm.org.uk","threadId":"58820","inReplyTo":"2f0bffb484beccf58f2440ed5e2c04a1ba26e6c3.1669126703.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v4 2/2] git-jump: invoke emacs/emacsclient","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2022-11-22T16:40:52Z","receivedAt":"2022-11-22T16:41:01Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"Hi Yoichi\n\nOn 22/11/2022 14:18, Yoichi Nakayama via GitGitGadget wrote:\n> From: Yoichi Nakayama <yoichi.nakayama@gmail.com>\n> \n> It works with GIT_EDITOR=\"emacs\", \"emacsclient\" or \"emacsclient -t\"\n\nThanks for working on this, I'm looking forward to being able to use \n\"git jump\" with emacs.\n\n> Signed-off-by: Yoichi Nakayama <yoichi.nakayama@gmail.com>\n> ---\n>   contrib/git-jump/git-jump | 15 +++++++++++++++\n>   1 file changed, 15 insertions(+)\n> \n> diff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump\n> index babb3b5c68d..bfd759aa4b2 100755\n> --- a/contrib/git-jump/git-jump\n> +++ b/contrib/git-jump/git-jump\n> @@ -26,6 +26,17 @@ open_editor() {\n>   \teval \"$editor -q \\$1\"\n>   }\n>   \n> +open_emacs() {\n> +\t# Supported editor values are:\n> +\t# - emacs\n> +\t# - emacsclient\n> +\t# - emacsclient -t\n> +\teditor=`git var GIT_EDITOR`\n> +\t# Wait for completion of the asynchronously executed process\n> +\t# to avoid race conditions in case of \"emacsclient\".\n> +\teval \"$editor --eval \\\"(prog1 (switch-to-buffer-other-frame (compilation-start \\\\\\\"cat $@\\\\\\\" 'grep-mode)) (delete-other-windows) (while (get-buffer-process (current-buffer)) (sleep-for 0.1)) (select-frame-set-input-focus (selected-frame)))\\\"\"\n\nI just tried this out in a frame (window for non emacs users) showing \ntwo files and the (delete-other-windows) call replaced both of them with \nthe grep buffer. It would be nicer if it created a new window in the \ncurrent frame or showed the grep buffer in one of the existing windows. \nIf I delete (delete-other-windows) then the first time I run \"git jump\" \nit shows the grep buffer in the frame I already have open, but then if I \nrun it again without closing the grep buffer it opens a new frame. I \nwonder if it would be better just to close the buffer if it exists \nbefore creating the new one or pass NAME-FUNCTION argument to \ncompilation-start that creates unique names.\n\nI'm using emacsclient as my editor and when I run \"git jump\" it prints\n\n#<buffer *grep*>\n\nin the terminal (presumably because that is the return value of \nselect-frame-set-input-focus)\n\nCould we read the file and set the buffer's mode to grep-mode (or \ncompilation-mode?) without forking cat?\n\nBest Wishes\n\nPhillip\n\n> +}\n> +\n>   mode_diff() {\n>   \tgit diff --no-prefix --relative \"$@\" |\n>   \tperl -ne '\n> @@ -98,4 +109,8 @@ tmp=`mktemp -t git-jump.XXXXXX` || exit 1\n>   type \"mode_$mode\" >/dev/null 2>&1 || { usage >&2; exit 1; }\n>   \"mode_$mode\" \"$@\" >\"$tmp\"\n>   test -s \"$tmp\" || exit 0\n> +if git var GIT_EDITOR | grep emacs >/dev/null; then\n> +\topen_emacs \"$tmp\"\n> +\texit 0\n> +fi\n>   open_editor \"$tmp\"\n"},{"id":"467791","messageId":"Y30TvhkfBeUkoIVk@coredump.intra.peff.net","threadId":"58820","inReplyTo":"CAF5D8-uQ633azqUfCv0vyQzFUaQdDhOwzEc8GOGnFrgmh-c9pQ@mail.gmail.com","subject":"Re: [PATCH v3 1/2] git-jump: add an optional argument '--stdout'","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2022-11-22T18:23:58Z","receivedAt":"2022-11-22T18:24:03Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Nov 22, 2022 at 10:00:45PM +0900, Yoichi Nakayama wrote:\n\n> > \"M-x grep<RET>git jump --stdout diff<RET>\" is what I would have\n> > written on the second line instead of \"Run grep (like this)...\".\n> \n> I think Junio's suggestion of  \"M-x grep<RET>git jump --stdout diff<RET>\"\n> is concise and understandable to most Emacs users, so I'd like to adopt it.\n> \n> Below are the details of what I thought:\n> \n> By M-x grep<RET>, Emacs displays\n>       Run grep (like this): grep --color=auto -nH --null -e\n> where\n> - \"Run grep (like this): \" is a prompt (like \"$ \" in bash).\n> - \"grep --color=auto -nH --null -e \" is a part of search command (missing\n>   keyword part). We can supply \"keyword<RET>\" to execute the search.\n>   We can also remove the whole command and replace it with the command\n>   like \"git jump --stdout diff\".\n\nAh, OK. I am happy with anything that emacs users will understand, and I\ntrust the two of you to come up with something there. :)\n\n-Peff\n"},{"id":"467794","messageId":"Y30VQzJ93h98hVhH@coredump.intra.peff.net","threadId":"58820","inReplyTo":"446777d300d73498bd7da709fad75731a13d0d59.1669126703.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v4 1/2] git-jump: add an optional argument '--stdout'","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2022-11-22T18:30:27Z","receivedAt":"2022-11-22T18:30:32Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Nov 22, 2022 at 02:18:22PM +0000, Yoichi Nakayama via GitGitGadget wrote:\n\n> @@ -64,11 +67,31 @@ mode_ws() {\n>  \tgit diff --check \"$@\"\n>  }\n>  \n> +use_stdout=\n> +while test $# -gt 0; do\n> +\tcase \"$1\" in\n> +\t--stdout)\n> +\t\tuse_stdout=t\n> +\t\tshift\n> +\t\t;;\n> +\t--*)\n> +\t\tusage >&2\n> +\t\texit 1\n> +\t\t;;\n> +\t*)\n> +\t\tbreak\n> +\t\t;;\n> +\tesac\n> +done\n>  if test $# -lt 1; then\n>  \tusage >&2\n>  \texit 1\n>  fi\n>  mode=$1; shift\n> +if test \"$use_stdout\" = \"t\"; then\n> +\t\"mode_$mode\" \"$@\"\n> +\texit 0\n> +fi\n\nThanks, this looks pretty good. I think we'd want this on top.\n\n-- >8 --\nSubject: git-jump: move valid-mode check earlier\n\nWe check if the \"mode\" argument supplied by the user is valid by seeing\nif we have a mode_$mode function defined. But we don't do that until\nafter creating the tempfile. This is wasteful (we create a tempfile but\nnever use it), and makes it harder to add new options (the recent stdout\noption exits before creating the tempfile, so it misses the check and\n\"git jump --stdout foo\" will produce \"git-jump: 92: mode_foo: not found\"\nrather than the regular usage message).\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n contrib/git-jump/git-jump | 3 ++-\n 1 file changed, 2 insertions(+), 1 deletion(-)\n\ndiff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump\nindex babb3b5c68..cc97b0dcf0 100755\n--- a/contrib/git-jump/git-jump\n+++ b/contrib/git-jump/git-jump\n@@ -88,14 +88,15 @@ if test $# -lt 1; then\n \texit 1\n fi\n mode=$1; shift\n+type \"mode_$mode\" >/dev/null 2>&1 || { usage >&2; exit 1; }\n+\n if test \"$use_stdout\" = \"t\"; then\n \t\"mode_$mode\" \"$@\"\n \texit 0\n fi\n \n trap 'rm -f \"$tmp\"' 0 1 2 3 15\n tmp=`mktemp -t git-jump.XXXXXX` || exit 1\n-type \"mode_$mode\" >/dev/null 2>&1 || { usage >&2; exit 1; }\n \"mode_$mode\" \"$@\" >\"$tmp\"\n test -s \"$tmp\" || exit 0\n open_editor \"$tmp\"\n-- \n2.38.1.970.g3b99f132c8\n\n"},{"id":"467798","messageId":"Y30a0ulfxyE7dnYi@coredump.intra.peff.net","threadId":"58820","inReplyTo":"2f0bffb484beccf58f2440ed5e2c04a1ba26e6c3.1669126703.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v4 2/2] git-jump: invoke emacs/emacsclient","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2022-11-22T18:54:10Z","receivedAt":"2022-11-22T18:54:14Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Nov 22, 2022 at 02:18:23PM +0000, Yoichi Nakayama via GitGitGadget wrote:\n\n> diff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump\n> index babb3b5c68d..bfd759aa4b2 100755\n> --- a/contrib/git-jump/git-jump\n> +++ b/contrib/git-jump/git-jump\n> @@ -26,6 +26,17 @@ open_editor() {\n>  \teval \"$editor -q \\$1\"\n>  }\n>  \n> +open_emacs() {\n> +\t# Supported editor values are:\n> +\t# - emacs\n> +\t# - emacsclient\n> +\t# - emacsclient -t\n> +\teditor=`git var GIT_EDITOR`\n> +\t# Wait for completion of the asynchronously executed process\n> +\t# to avoid race conditions in case of \"emacsclient\".\n> +\teval \"$editor --eval \\\"(prog1 (switch-to-buffer-other-frame (compilation-start \\\\\\\"cat $@\\\\\\\" 'grep-mode)) (delete-other-windows) (while (get-buffer-process (current-buffer)) (sleep-for 0.1)) (select-frame-set-input-focus (selected-frame)))\\\"\"\n> +}\n\nHmm, I know I suggested using a temporary file since \"cat $tmpfile\"\nshould be pretty safe. But it does still have problems if your tmp\ndirectory has spaces. Or even other metacharacters, which I think will\nbe interpreted by the eval, since $@ is expanded in the outermost level\nof the shell.\n\nThose are fairly unlikely, but we could handle it. I think you'd need\nsomething like:\n\n\topen_emacs() {\n\t\tquoted_args=\n\t\tfor i in \"$@\"; do\n\t\t\tquoted_args=\"$quoted_args '$(printf %s \"$i\" | sed \"s/'/'\\\\\\\\''/g\")'\"\n\t\tdone\n\t\teval \"$editor --eval \\\"...\\\\\\\"cat \\$quoted_args\\\\\\\"...\\\"\"\n\t}\n\nwhich you can test with:\n\n\tcat >fake-emacs <<-\\EOF\n\t#!/bin/sh\n\techo \"fake-emacs got args: \"\n\tfor i in \"$@\"; do\n\t\techo \"arg: $i\"\n\tdone\n\tEOF\n\tchmod +x fake-emacs\n\n\teditor=./fake-emacs\n\topen_emacs 'multiple args' 'with spaces'\n\topen_emacs '$dollar is ok because we use single-quotes'\n\topen_emacs \"but 'single quotes' themselves need quoted\"\n\nThough it's possible you also need to be adding an extra layer of\nquoting due to emacs parsing the string. So you'd probably need to\nadditionally escape double-quotes and backslashes, perhaps by changing\nthe sed invocation to:\n\n  sed -e 's/\\\\/\\\\\\\\/g' \\\n      -e \"s/'/'\\\\\\\\''/g\" \\\n      -e 's/\"/\\\\\"/g'\n\nWhich is kind of horrific, but I think is bullet-proof.\n\nLike I said, it's not that likely that somebody's tempfile path would\nneed all that (though spaces aren't totally out of the question,\nespecially on Windows). But...\n\nIf we have bullet-proof quoting, then you could go back to skipping the\ntempfile for emacs, which avoids the race and sleep that you have here.\n\n> @@ -98,4 +109,8 @@ tmp=`mktemp -t git-jump.XXXXXX` || exit 1\n>  type \"mode_$mode\" >/dev/null 2>&1 || { usage >&2; exit 1; }\n>  \"mode_$mode\" \"$@\" >\"$tmp\"\n>  test -s \"$tmp\" || exit 0\n> +if git var GIT_EDITOR | grep emacs >/dev/null; then\n> +\topen_emacs \"$tmp\"\n> +\texit 0\n> +fi\n>  open_editor \"$tmp\"\n\nIf we are going to use a tempfile, this logic should probably get\nstuffed into open_editor itself, like:\n\n  open_editor() {\n          editor=`git var GIT_EDITOR`\n          case \"$editor\" in\n          *emacs*)\n                  ...do-the-emacs-thing...\n          *)\n                  # assume anything else is vi-compatible\n                  eval \"$editor -q \\$1\"\n          esac\n  }\n\nbut if you take the quoting suggestion above, then open_emacs() would\ncontinue to be a top-level thing, before we even create the tempfile.\n\n-Peff\n"},{"id":"467848","messageId":"CAF5D8-vMLNzi4F06MoLvWV3XBe62B6VTqtXs4VCjsFKMVQkv-A@mail.gmail.com","threadId":"58820","inReplyTo":"61b42a7c-5772-dec2-c895-386f1613ac35@dunelm.org.uk","subject":"Re: [PATCH v4 2/2] git-jump: invoke emacs/emacsclient","fromName":"Yoichi Nakayama","fromEmail":"yoichi.nakayama@gmail.com","sentAt":"2022-11-23T05:01:51Z","receivedAt":"2022-11-23T05:02:27Z","isPatch":true,"sender":{"key":"yoichi.nakayama@gmail.com","avatar":"https://avatars.githubusercontent.com/u/107537?v=4"},"body":"On Wed, Nov 23, 2022 at 1:40 AM Phillip Wood <phillip.wood123@gmail.com> wrote:\n> > +     # Wait for completion of the asynchronously executed process\n> > +     # to avoid race conditions in case of \"emacsclient\".\n> > +     eval \"$editor --eval \\\"(prog1 (switch-to-buffer-other-frame (compilation-start \\\\\\\"cat $@\\\\\\\" 'grep-mode)) (delete-other-windows) (while (get-buffer-process (current-buffer)) (sleep-for 0.1)) (select-frame-set-input-focus (selected-frame)))\\\"\"\n>\n> I just tried this out in a frame (window for non emacs users) showing\n> two files and the (delete-other-windows) call replaced both of them with\n> the grep buffer. It would be nicer if it created a new window in the\n> current frame or showed the grep buffer in one of the existing windows.\n\nThanks for your feedback.\n\nThe first point is that you want to keep the same window configuration\nas before you do git jump, and reuse existing window (like M-x grep), right?\n\nI think \"(delete-other-windows)\" was superfluous, so I'll remove it.\nWill it do what you want?\n- In case of  editor=\"emacsclient\", it will try to keep window configuration.\n- In case of editor=\"emacsclient -t\" and editor=\"emacs\", it will\ncreate two window\nconfiguration (up and down).\n\n> If I delete (delete-other-windows) then the first time I run \"git jump\"\n> it shows the grep buffer in the frame I already have open, but then if I\n> run it again without closing the grep buffer it opens a new frame. I\n> wonder if it would be better just to close the buffer if it exists\n> before creating the new one or pass NAME-FUNCTION argument to\n> compilation-start that creates unique names.\n\nI've also seen a new frame being created unintentionally.\nIt is caused by the wrong use of switch-to-buffer-other-frame.\nI'll try to fix.\n-- \nYoichi NAKAYAMA\n"},{"id":"467849","messageId":"CAF5D8-vSsBsdiA8SiDgqUFkL9_3N-v+psVxj-AcibOB88gxWfA@mail.gmail.com","threadId":"58820","inReplyTo":"Y30a0ulfxyE7dnYi@coredump.intra.peff.net","subject":"Re: [PATCH v4 2/2] git-jump: invoke emacs/emacsclient","fromName":"Yoichi Nakayama","fromEmail":"yoichi.nakayama@gmail.com","sentAt":"2022-11-23T05:33:50Z","receivedAt":"2022-11-23T05:34:07Z","isPatch":true,"sender":{"key":"yoichi.nakayama@gmail.com","avatar":"https://avatars.githubusercontent.com/u/107537?v=4"},"body":"On Wed, Nov 23, 2022 at 3:54 AM Jeff King <peff@peff.net> wrote:\n> Hmm, I know I suggested using a temporary file since \"cat $tmpfile\"\n> should be pretty safe. But it does still have problems if your tmp\n> directory has spaces. Or even other metacharacters, which I think will\n> be interpreted by the eval, since $@ is expanded in the outermost level\n> of the shell.\n\nRight. But the problem is not specific to emacs (it happens in vim too).\nLet's fix it another time (as you noted, that's pretty unlikely, and we may\nnot even need to fix it).\n\n> If we are going to use a tempfile, this logic should probably get\n> stuffed into open_editor itself, like:\n>\n>   open_editor() {\n>           editor=`git var GIT_EDITOR`\n>           case \"$editor\" in\n>           *emacs*)\n>                   ...do-the-emacs-thing...\n>           *)\n>                   # assume anything else is vi-compatible\n>                   eval \"$editor -q \\$1\"\n>           esac\n>   }\n\nSure.\n-- \nYoichi NAKAYAMA\n"},{"id":"467851","messageId":"446777d300d73498bd7da709fad75731a13d0d59.1669187053.git.gitgitgadget@gmail.com","threadId":"58820","inReplyTo":"pull.1423.v5.git.1669187053.gitgitgadget@gmail.com","subject":"[PATCH v5 1/3] git-jump: add an optional argument '--stdout'","fromName":"Yoichi Nakayama via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2022-11-23T07:04:11Z","receivedAt":"2022-11-23T07:04:24Z","isPatch":true,"sender":{"key":"yoichi.nakayama@gmail.com","avatar":"https://avatars.githubusercontent.com/u/107537?v=4"},"body":"From: Yoichi Nakayama <yoichi.nakayama@gmail.com>\n\nIt can be used with M-x grep on Emacs.\n\nSigned-off-by: Yoichi Nakayama <yoichi.nakayama@gmail.com>\n---\n contrib/git-jump/README   | 10 +++++++++-\n contrib/git-jump/git-jump | 25 ++++++++++++++++++++++++-\n 2 files changed, 33 insertions(+), 2 deletions(-)\n\ndiff --git a/contrib/git-jump/README b/contrib/git-jump/README\nindex 8bcace29d21..3211841305f 100644\n--- a/contrib/git-jump/README\n+++ b/contrib/git-jump/README\n@@ -79,6 +79,14 @@ git jump grep -i foo_bar\n git config jump.grepCmd \"ag --column\"\n --------------------------------------------------\n \n+You can use the optional argument '--stdout' to print the listing to\n+standard output instead of feeding it to the editor. You can use the\n+argument with M-x grep on Emacs:\n+\n+--------------------------------------------------\n+# In Emacs, M-x grep and invoke \"git jump --stdout <mode>\"\n+M-x grep<RET>git jump --stdout diff<RET>\n+--------------------------------------------------\n \n Related Programs\n ----------------\n@@ -100,7 +108,7 @@ Limitations\n -----------\n \n This script was written and tested with vim. Given that the quickfix\n-format is the same as what gcc produces, I expect emacs users have a\n+format is the same as what gcc produces, I expect other tools have a\n similar feature for iterating through the list, but I know nothing about\n how to activate it.\n \ndiff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump\nindex 92dbd4cde18..babb3b5c68d 100755\n--- a/contrib/git-jump/git-jump\n+++ b/contrib/git-jump/git-jump\n@@ -2,7 +2,7 @@\n \n usage() {\n \tcat <<\\EOF\n-usage: git jump <mode> [<args>]\n+usage: git jump [--stdout] <mode> [<args>]\n \n Jump to interesting elements in an editor.\n The <mode> parameter is one of:\n@@ -15,6 +15,9 @@ grep: elements are grep hits. Arguments are given to git grep or, if\n       configured, to the command in `jump.grepCmd`.\n \n ws: elements are whitespace errors. Arguments are given to diff --check.\n+\n+If the optional argument `--stdout` is given, print the quickfix\n+lines to standard output instead of feeding it to the editor.\n EOF\n }\n \n@@ -64,11 +67,31 @@ mode_ws() {\n \tgit diff --check \"$@\"\n }\n \n+use_stdout=\n+while test $# -gt 0; do\n+\tcase \"$1\" in\n+\t--stdout)\n+\t\tuse_stdout=t\n+\t\tshift\n+\t\t;;\n+\t--*)\n+\t\tusage >&2\n+\t\texit 1\n+\t\t;;\n+\t*)\n+\t\tbreak\n+\t\t;;\n+\tesac\n+done\n if test $# -lt 1; then\n \tusage >&2\n \texit 1\n fi\n mode=$1; shift\n+if test \"$use_stdout\" = \"t\"; then\n+\t\"mode_$mode\" \"$@\"\n+\texit 0\n+fi\n \n trap 'rm -f \"$tmp\"' 0 1 2 3 15\n tmp=`mktemp -t git-jump.XXXXXX` || exit 1\n-- \ngitgitgadget\n\n"},{"id":"467852","messageId":"972d51888ba015a6697475025466432218efa6dd.1669187053.git.gitgitgadget@gmail.com","threadId":"58820","inReplyTo":"pull.1423.v5.git.1669187053.gitgitgadget@gmail.com","subject":"[PATCH v5 2/3] git-jump: move valid-mode check earlier","fromName":"Jeff King via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2022-11-23T07:04:12Z","receivedAt":"2022-11-23T07:04:27Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"From: Jeff King <peff@peff.net>\n\nWe check if the \"mode\" argument supplied by the user is valid by seeing\nif we have a mode_$mode function defined. But we don't do that until\nafter creating the tempfile. This is wasteful (we create a tempfile but\nnever use it), and makes it harder to add new options (the recent stdout\noption exits before creating the tempfile, so it misses the check and\n\"git jump --stdout foo\" will produce \"git-jump: 92: mode_foo: not found\"\nrather than the regular usage message).\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n contrib/git-jump/git-jump | 3 ++-\n 1 file changed, 2 insertions(+), 1 deletion(-)\n\ndiff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump\nindex babb3b5c68d..cc97b0dcf02 100755\n--- a/contrib/git-jump/git-jump\n+++ b/contrib/git-jump/git-jump\n@@ -88,6 +88,8 @@ if test $# -lt 1; then\n \texit 1\n fi\n mode=$1; shift\n+type \"mode_$mode\" >/dev/null 2>&1 || { usage >&2; exit 1; }\n+\n if test \"$use_stdout\" = \"t\"; then\n \t\"mode_$mode\" \"$@\"\n \texit 0\n@@ -95,7 +97,6 @@ fi\n \n trap 'rm -f \"$tmp\"' 0 1 2 3 15\n tmp=`mktemp -t git-jump.XXXXXX` || exit 1\n-type \"mode_$mode\" >/dev/null 2>&1 || { usage >&2; exit 1; }\n \"mode_$mode\" \"$@\" >\"$tmp\"\n test -s \"$tmp\" || exit 0\n open_editor \"$tmp\"\n-- \ngitgitgadget\n\n"},{"id":"467853","messageId":"pull.1423.v5.git.1669187053.gitgitgadget@gmail.com","threadId":"58820","inReplyTo":"pull.1423.v4.git.1669126703.gitgitgadget@gmail.com","subject":"[PATCH v5 0/3] git-jump: support Emacs","fromName":"Yoichi NAKAYAMA via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2022-11-23T07:04:10Z","receivedAt":"2022-11-23T07:04:29Z","isPatch":true,"sender":{"key":"yoichi.nakayama@gmail.com","avatar":"https://avatars.githubusercontent.com/u/107537?v=4"},"body":"Add an optional argument 'stdout' to print the quickfix lines to standard\noutput. It can be used with M-x grep on Emacs.\n\nDetect emacsclient by GIT_EDITOR and invoke the function. Tested with\nEDITOR=\"emacsclient\" and EDITOR=\"emacsclient -t\".\n\nJeff King (1):\n  git-jump: move valid-mode check earlier\n\nYoichi Nakayama (2):\n  git-jump: add an optional argument '--stdout'\n  git-jump: invoke emacs/emacsclient\n\n contrib/git-jump/README   | 10 ++++++++-\n contrib/git-jump/git-jump | 45 ++++++++++++++++++++++++++++++++++++---\n 2 files changed, 51 insertions(+), 4 deletions(-)\n\n\nbase-commit: eea7033409a0ed713c78437fc76486983d211e25\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-1423%2Fyoichi%2Fgit-jump-emacs-support-v5\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1423/yoichi/git-jump-emacs-support-v5\nPull-Request: https://github.com/gitgitgadget/git/pull/1423\n\nRange-diff vs v4:\n\n 1:  446777d300d = 1:  446777d300d git-jump: add an optional argument '--stdout'\n 2:  2f0bffb484b ! 2:  972d51888ba git-jump: invoke emacs/emacsclient\n     @@\n       ## Metadata ##\n     -Author: Yoichi Nakayama <yoichi.nakayama@gmail.com>\n     +Author: Jeff King <peff@peff.net>\n      \n       ## Commit message ##\n     -    git-jump: invoke emacs/emacsclient\n     +    git-jump: move valid-mode check earlier\n      \n     -    It works with GIT_EDITOR=\"emacs\", \"emacsclient\" or \"emacsclient -t\"\n     +    We check if the \"mode\" argument supplied by the user is valid by seeing\n     +    if we have a mode_$mode function defined. But we don't do that until\n     +    after creating the tempfile. This is wasteful (we create a tempfile but\n     +    never use it), and makes it harder to add new options (the recent stdout\n     +    option exits before creating the tempfile, so it misses the check and\n     +    \"git jump --stdout foo\" will produce \"git-jump: 92: mode_foo: not found\"\n     +    rather than the regular usage message).\n      \n     -    Signed-off-by: Yoichi Nakayama <yoichi.nakayama@gmail.com>\n     +    Signed-off-by: Jeff King <peff@peff.net>\n      \n       ## contrib/git-jump/git-jump ##\n     -@@ contrib/git-jump/git-jump: open_editor() {\n     - \teval \"$editor -q \\$1\"\n     - }\n     - \n     -+open_emacs() {\n     -+\t# Supported editor values are:\n     -+\t# - emacs\n     -+\t# - emacsclient\n     -+\t# - emacsclient -t\n     -+\teditor=`git var GIT_EDITOR`\n     -+\t# Wait for completion of the asynchronously executed process\n     -+\t# to avoid race conditions in case of \"emacsclient\".\n     -+\teval \"$editor --eval \\\"(prog1 (switch-to-buffer-other-frame (compilation-start \\\\\\\"cat $@\\\\\\\" 'grep-mode)) (delete-other-windows) (while (get-buffer-process (current-buffer)) (sleep-for 0.1)) (select-frame-set-input-focus (selected-frame)))\\\"\"\n     -+}\n     +@@ contrib/git-jump/git-jump: if test $# -lt 1; then\n     + \texit 1\n     + fi\n     + mode=$1; shift\n     ++type \"mode_$mode\" >/dev/null 2>&1 || { usage >&2; exit 1; }\n      +\n     - mode_diff() {\n     - \tgit diff --no-prefix --relative \"$@\" |\n     - \tperl -ne '\n     -@@ contrib/git-jump/git-jump: tmp=`mktemp -t git-jump.XXXXXX` || exit 1\n     - type \"mode_$mode\" >/dev/null 2>&1 || { usage >&2; exit 1; }\n     + if test \"$use_stdout\" = \"t\"; then\n     + \t\"mode_$mode\" \"$@\"\n     + \texit 0\n     +@@ contrib/git-jump/git-jump: fi\n     + \n     + trap 'rm -f \"$tmp\"' 0 1 2 3 15\n     + tmp=`mktemp -t git-jump.XXXXXX` || exit 1\n     +-type \"mode_$mode\" >/dev/null 2>&1 || { usage >&2; exit 1; }\n       \"mode_$mode\" \"$@\" >\"$tmp\"\n       test -s \"$tmp\" || exit 0\n     -+if git var GIT_EDITOR | grep emacs >/dev/null; then\n     -+\topen_emacs \"$tmp\"\n     -+\texit 0\n     -+fi\n       open_editor \"$tmp\"\n -:  ----------- > 3:  ad7c299cb0f git-jump: invoke emacs/emacsclient\n\n-- \ngitgitgadget\n"},{"id":"467854","messageId":"ad7c299cb0f78ae3f36d57b67fa91e5ccaab3181.1669187053.git.gitgitgadget@gmail.com","threadId":"58820","inReplyTo":"pull.1423.v5.git.1669187053.gitgitgadget@gmail.com","subject":"[PATCH v5 3/3] git-jump: invoke emacs/emacsclient","fromName":"Yoichi Nakayama via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2022-11-23T07:04:13Z","receivedAt":"2022-11-23T07:04:33Z","isPatch":true,"sender":{"key":"yoichi.nakayama@gmail.com","avatar":"https://avatars.githubusercontent.com/u/107537?v=4"},"body":"From: Yoichi Nakayama <yoichi.nakayama@gmail.com>\n\nIt works with GIT_EDITOR=\"emacs\", \"emacsclient\" or \"emacsclient -t\"\n\nSigned-off-by: Yoichi Nakayama <yoichi.nakayama@gmail.com>\n---\n contrib/git-jump/git-jump | 17 ++++++++++++++++-\n 1 file changed, 16 insertions(+), 1 deletion(-)\n\ndiff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump\nindex cc97b0dcf02..316e9628725 100755\n--- a/contrib/git-jump/git-jump\n+++ b/contrib/git-jump/git-jump\n@@ -23,7 +23,22 @@ EOF\n \n open_editor() {\n \teditor=`git var GIT_EDITOR`\n-\teval \"$editor -q \\$1\"\n+\tcase \"$editor\" in\n+\t*emacs*)\n+\t\t# Supported editor values are:\n+\t\t# - emacs\n+\t\t# - emacsclient\n+\t\t# - emacsclient -t\n+\t\t#\n+\t\t# Wait for completion of the asynchronously executed process\n+\t\t# to avoid race conditions in case of \"emacsclient\".\n+\t\teval \"$editor --eval \\\"(prog1 (pop-to-buffer (compilation-start \\\\\\\"cat $@\\\\\\\" 'grep-mode)) (while (get-buffer-process (current-buffer)) (sleep-for 0.1)) (select-frame-set-input-focus (selected-frame)))\\\"\"\n+\t\t;;\n+\t*)\n+\t\t# assume anything else is vi-compatible\n+\t\teval \"$editor -q \\$1\"\n+\t\t;;\n+\tesac\n }\n \n mode_diff() {\n-- \ngitgitgadget\n"},{"id":"467867","messageId":"feb7db00-db00-6190-47cf-9101052b9be8@dunelm.org.uk","threadId":"58820","inReplyTo":"ad7c299cb0f78ae3f36d57b67fa91e5ccaab3181.1669187053.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v5 3/3] git-jump: invoke emacs/emacsclient","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2022-11-23T14:58:27Z","receivedAt":"2022-11-23T14:58:58Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"Hi Yoichi\n\nOn 23/11/2022 07:04, Yoichi Nakayama via GitGitGadget wrote:\n> From: Yoichi Nakayama <yoichi.nakayama@gmail.com>\n> \n> It works with GIT_EDITOR=\"emacs\", \"emacsclient\" or \"emacsclient -t\"\n> \n> Signed-off-by: Yoichi Nakayama <yoichi.nakayama@gmail.com>\n> ---\n>   contrib/git-jump/git-jump | 17 ++++++++++++++++-\n>   1 file changed, 16 insertions(+), 1 deletion(-)\n> \n> diff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump\n> index cc97b0dcf02..316e9628725 100755\n> --- a/contrib/git-jump/git-jump\n> +++ b/contrib/git-jump/git-jump\n> @@ -23,7 +23,22 @@ EOF\n>   \n>   open_editor() {\n>   \teditor=`git var GIT_EDITOR`\n> -\teval \"$editor -q \\$1\"\n> +\tcase \"$editor\" in\n> +\t*emacs*)\n> +\t\t# Supported editor values are:\n> +\t\t# - emacs\n> +\t\t# - emacsclient\n> +\t\t# - emacsclient -t\n> +\t\t#\n> +\t\t# Wait for completion of the asynchronously executed process\n> +\t\t# to avoid race conditions in case of \"emacsclient\".\n> +\t\teval \"$editor --eval \\\"(prog1 (pop-to-buffer (compilation-start \\\\\\\"cat $@\\\\\\\" 'grep-mode)) (while (get-buffer-process (current-buffer)) (sleep-for 0.1)) (select-frame-set-input-focus (selected-frame)))\\\"\"\n\nI've just tried this out and it is much nicer than v4, thank you for \ntweaking it. It is a little sluggish to pop up the emacs window though - \nare you sure we need the while loop? I've commented it out and it seems \nto work just fine. The documentation for pop-to-buffer says it selects \nthe frame displaying the buffer so I don't think we need to wait before \ncalling select-frame-set-input-focus (I'm no emacs expert though). I do \nthink it would be better to quote the filename or better still call \ngit-jump from compilation-start as Peff suggested. It would also be nice \nto stop emacsclient from printing anything in the terminal.\n\nIt would be nice to be able to run git-jump from within emacs. I came up \nwith the code below which prompts the user for the directory to run \ngit-jump in (which only matters for grep and diff --relative I think) \nand then checks for modified buffers visiting files in that repository \nbefore running git-jump.\n\nBest Wishes\n\nPhillip\n\n---- >8 ----\n(require 'cl-lib)\n\n(defun git-jump (dir)\n   \"Run 'git jump', prompts for the directory to run in. Also prompts to\n    save modified buffers visiting files in the repository containing DIR\"\n   (interactive \"DDirectory:\")\n   (let* ((dir (expand-file-name dir))\n\t (worktree (git-jump--get-worktree dir)))\n     (unless worktree\n       (error \"Not in a git repository\"))\n     (git-jump--save-worktree-buffers worktree)\n     ;; Use \"cd\" rather than \"git -C\" so emacs can tell which directory\n     ;; the command is being run in.\n     (compilation-start (concat \"cd \" (shell-quote-argument dir)\n\t\t\t       \" && git jump --stdout \"\n\t\t\t       (read-string \"Jump command: \"))\n\t\t       'grep-mode\n\t\t       (lambda (mode) \"*git-jump*\"))))\n\n\n(defun git-jump--save-worktree-buffers (worktree)\n   \"Prompt the user to save all the modified buffers in WORKTREE\"\n   (let ((ht (make-hash-table :test 'equal))\n\t(off (length worktree))\n\t(buffers nil))\n     (dolist (b (buffer-list))\n       (when (buffer-modified-p b)\n\t(let ((file (buffer-file-name b)))\n\t  (when file\n\t    (let ((path (file-truename file)))\n\t      (when (string-prefix-p worktree path)\n\t\t(puthash (substring path off) b ht)))))))\n     (let ((modified (hash-table-keys ht)))\n       (when modified\n\t(git-jump--ls-files worktree\n\t\t\t       modified\n\t\t\t       (lambda (path)\n\t\t\t\t (push (gethash path ht) buffers)))\n\t(when buffers\n\t  (save-some-buffers nil (lambda ()\n\t\t\t\t   (memq (current-buffer) buffers))))))))\n\n\n(defun git-jump--get-worktree (dir)\n   \"Get the git worktree containing DIR. Returns nil if DIR is not in a\n    repository\"\n   (message (concat \"dir: \" dir))\n   (let* ((toplevel \"\")\n\t    (filter (lambda (_proc text)\n\t\t      (setf toplevel (concat toplevel text))))\n\t    (proc (make-process :name \"rev-parse--toplevel\"\n\t\t\t\t:buffer nil\n\t\t\t\t:coding (or file-name-coding-system\n\t\t\t\t\t    default-file-name-coding-system)\n\t\t\t\t:command (list \"git\" \"-C\" dir \"rev-parse\"\n\t\t\t\t\t       \"--show-toplevel\")\n\t\t\t\t:connection-type 'pipe\n\t\t\t\t:filter filter)))\n        (while (or (accept-process-output proc 120)\n\t\t  (not (memq (process-status proc) '(exit signal)))))\n        (prog1\n\t   (if (and (eq (process-status proc) 'exit)\n\t\t    (zerop (process-exit-status proc)))\n\t       (concat (substring toplevel 0 -1) \"/\")\n\t     nil)\n\t (delete-process proc))))\n\n\n(defun git-jump--ls-files (worktree paths func)\n   \"Run FUNC on PATHS that are tracked by worktree. NB takes paths not \npathspecs\"\n   (let* ((remainder \"\")\n\t (filter (lambda (_proc text)\n\t\t   (let* ((text (concat remainder text))\n\t\t\t  (len (length text))\n\t\t\t  (pos 0))\n\t\t     (while (< pos len)\n\t\t       (cond\n\t\t\t((= pos (string-match \"\\\\([^\\0]+\\\\)\\0\" text pos))\n\t\t\t (funcall func (match-string 1 text))\n\t\t\t (setq pos (match-end 0)))\n\t\t\t(t\n\t\t\t (setq remainder (substring text pos))\n\t\t\t (setq pos len)))))))\n        (proc (make-process :name \"ls-files\"\n\t\t\t   :buffer nil\n\t\t\t   :coding (or file-name-coding-system\n\t\t\t\t       default-file-name-coding-system)\n\t\t\t   :command (cl-list* \"git\" \"-C\" worktree\n\t\t\t\t\t      \"--literal-pathspecs\" \"ls-files\"\n\t\t\t\t\t      \"-z\" \"--\" paths)\n\t\t\t   :connection-type 'pipe\n\t\t\t   :filter filter)))\n     (while (or (accept-process-output proc 120)\n\t       (not (memq (process-status proc) '(exit signal)))))\n     (delete-process proc)))\n\n(provide 'git-jump)\n\n\n\n"},{"id":"467885","messageId":"CAF5D8-uo5rWZ-8vMz3EXVownaBEfKZ4s5R=cjX5XqHCN4DHaiQ@mail.gmail.com","threadId":"58820","inReplyTo":"feb7db00-db00-6190-47cf-9101052b9be8@dunelm.org.uk","subject":"Re: [PATCH v5 3/3] git-jump: invoke emacs/emacsclient","fromName":"Yoichi Nakayama","fromEmail":"yoichi.nakayama@gmail.com","sentAt":"2022-11-23T21:54:08Z","receivedAt":"2022-11-23T21:54:25Z","isPatch":true,"sender":{"key":"yoichi.nakayama@gmail.com","avatar":"https://avatars.githubusercontent.com/u/107537?v=4"},"body":"On Wed, Nov 23, 2022 at 11:58 PM Phillip Wood <phillip.wood123@gmail.com> wrote:\n> I've just tried this out and it is much nicer than v4, thank you for\n> tweaking it. It is a little sluggish to pop up the emacs window though -\n> are you sure we need the while loop? I've commented it out and it seems\n> to work just fine. The documentation for pop-to-buffer says it selects\n> the frame displaying the buffer so I don't think we need to wait before\n> calling select-frame-set-input-focus (I'm no emacs expert though). I do\n> think it would be better to quote the filename or better still call\n> git-jump from compilation-start as Peff suggested. It would also be nice\n> to stop emacsclient from printing anything in the terminal.\n\nAs I wrote in the code comment, there is a race condition in\neditor=\"emacsclient\" case.\nYou can observe it by removing the while loop and insert \"sleep 1 &&\"\nbefore cat command.\nHowever, the while loop can be moved to the end, which reduces latency.\nSo, I'll change its position.\n\nIn editor=\"emacsclient\" case, we can stop emacsclient from printing\nanything in the\nterminal by redirecting stdout to /dev/null. But it causes following error with\neditor=\"emacsclient -t\" case:\n     emacsclient: could not get terminal name\nYou can use editor=\"emacsclient -u\" to suppress output.\n\nBest Wishes,\n-- \nYoichi NAKAYAMA\n"},{"id":"467897","messageId":"Y37EPdUkBhsSPmRD@coredump.intra.peff.net","threadId":"58820","inReplyTo":"CAF5D8-vSsBsdiA8SiDgqUFkL9_3N-v+psVxj-AcibOB88gxWfA@mail.gmail.com","subject":"Re: [PATCH v4 2/2] git-jump: invoke emacs/emacsclient","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2022-11-24T01:09:17Z","receivedAt":"2022-11-24T01:09:36Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Nov 23, 2022 at 02:33:50PM +0900, Yoichi Nakayama wrote:\n\n> On Wed, Nov 23, 2022 at 3:54 AM Jeff King <peff@peff.net> wrote:\n> > Hmm, I know I suggested using a temporary file since \"cat $tmpfile\"\n> > should be pretty safe. But it does still have problems if your tmp\n> > directory has spaces. Or even other metacharacters, which I think will\n> > be interpreted by the eval, since $@ is expanded in the outermost level\n> > of the shell.\n> \n> Right. But the problem is not specific to emacs (it happens in vim too).\n> Let's fix it another time (as you noted, that's pretty unlikely, and we may\n> not even need to fix it).\n\nGood point. The vim version is easier to fix (we just need to\ndouble-quote \\$1 inside the eval), but the fact that nobody has\ncomplained is an indication that it does not really matter.\n\n-Peff\n"},{"id":"467898","messageId":"Y37Eyqxrrfe5OkTY@coredump.intra.peff.net","threadId":"58820","inReplyTo":"pull.1423.v5.git.1669187053.gitgitgadget@gmail.com","subject":"Re: [PATCH v5 0/3] git-jump: support Emacs","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2022-11-24T01:11:38Z","receivedAt":"2022-11-24T01:11:43Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Nov 23, 2022 at 07:04:10AM +0000, Yoichi NAKAYAMA via GitGitGadget wrote:\n\n> Add an optional argument 'stdout' to print the quickfix lines to standard\n> output. It can be used with M-x grep on Emacs.\n> \n> Detect emacsclient by GIT_EDITOR and invoke the function. Tested with\n> EDITOR=\"emacsclient\" and EDITOR=\"emacsclient -t\".\n\nThanks, this version looks fine to me. I see your response to Phillip\nmay result in a v6 where the loop within the emacs code is moved, but I\nhave no opinion on that. :) So assuming that is the only change, my\nreview will still stand.\n\n-Peff\n"},{"id":"467905","messageId":"pull.1423.v6.git.1669261642.gitgitgadget@gmail.com","threadId":"58820","inReplyTo":"pull.1423.v5.git.1669187053.gitgitgadget@gmail.com","subject":"[PATCH v6 0/3] git-jump: support Emacs","fromName":"Yoichi NAKAYAMA via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2022-11-24T03:47:19Z","receivedAt":"2022-11-24T03:47:32Z","isPatch":true,"sender":{"key":"yoichi.nakayama@gmail.com","avatar":"https://avatars.githubusercontent.com/u/107537?v=4"},"body":"Add an optional argument 'stdout' to print the quickfix lines to standard\noutput. It can be used with M-x grep on Emacs.\n\nDetect emacsclient by GIT_EDITOR and invoke the function. Tested with\nEDITOR=\"emacsclient\" and EDITOR=\"emacsclient -t\".\n\nJeff King (1):\n  git-jump: move valid-mode check earlier\n\nYoichi Nakayama (2):\n  git-jump: add an optional argument '--stdout'\n  git-jump: invoke emacs/emacsclient\n\n contrib/git-jump/README   | 10 ++++++++-\n contrib/git-jump/git-jump | 45 ++++++++++++++++++++++++++++++++++++---\n 2 files changed, 51 insertions(+), 4 deletions(-)\n\n\nbase-commit: eea7033409a0ed713c78437fc76486983d211e25\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-1423%2Fyoichi%2Fgit-jump-emacs-support-v6\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1423/yoichi/git-jump-emacs-support-v6\nPull-Request: https://github.com/gitgitgadget/git/pull/1423\n\nRange-diff vs v5:\n\n 1:  446777d300d = 1:  446777d300d git-jump: add an optional argument '--stdout'\n 2:  972d51888ba = 2:  972d51888ba git-jump: move valid-mode check earlier\n 3:  ad7c299cb0f ! 3:  446d39f62fb git-jump: invoke emacs/emacsclient\n     @@ contrib/git-jump/git-jump: EOF\n      +\t\t#\n      +\t\t# Wait for completion of the asynchronously executed process\n      +\t\t# to avoid race conditions in case of \"emacsclient\".\n     -+\t\teval \"$editor --eval \\\"(prog1 (pop-to-buffer (compilation-start \\\\\\\"cat $@\\\\\\\" 'grep-mode)) (while (get-buffer-process (current-buffer)) (sleep-for 0.1)) (select-frame-set-input-focus (selected-frame)))\\\"\"\n     ++\t\teval \"$editor --eval \\\"(let ((buf (compilation-start \\\\\\\"cat $@\\\\\\\" 'grep-mode))) (pop-to-buffer buf) (select-frame-set-input-focus (selected-frame)) (while (get-buffer-process buf) (sleep-for 0.1)))\\\"\"\n      +\t\t;;\n      +\t*)\n      +\t\t# assume anything else is vi-compatible\n\n-- \ngitgitgadget\n"},{"id":"467906","messageId":"446777d300d73498bd7da709fad75731a13d0d59.1669261642.git.gitgitgadget@gmail.com","threadId":"58820","inReplyTo":"pull.1423.v6.git.1669261642.gitgitgadget@gmail.com","subject":"[PATCH v6 1/3] git-jump: add an optional argument '--stdout'","fromName":"Yoichi Nakayama via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2022-11-24T03:47:20Z","receivedAt":"2022-11-24T03:47:35Z","isPatch":true,"sender":{"key":"yoichi.nakayama@gmail.com","avatar":"https://avatars.githubusercontent.com/u/107537?v=4"},"body":"From: Yoichi Nakayama <yoichi.nakayama@gmail.com>\n\nIt can be used with M-x grep on Emacs.\n\nSigned-off-by: Yoichi Nakayama <yoichi.nakayama@gmail.com>\n---\n contrib/git-jump/README   | 10 +++++++++-\n contrib/git-jump/git-jump | 25 ++++++++++++++++++++++++-\n 2 files changed, 33 insertions(+), 2 deletions(-)\n\ndiff --git a/contrib/git-jump/README b/contrib/git-jump/README\nindex 8bcace29d21..3211841305f 100644\n--- a/contrib/git-jump/README\n+++ b/contrib/git-jump/README\n@@ -79,6 +79,14 @@ git jump grep -i foo_bar\n git config jump.grepCmd \"ag --column\"\n --------------------------------------------------\n \n+You can use the optional argument '--stdout' to print the listing to\n+standard output instead of feeding it to the editor. You can use the\n+argument with M-x grep on Emacs:\n+\n+--------------------------------------------------\n+# In Emacs, M-x grep and invoke \"git jump --stdout <mode>\"\n+M-x grep<RET>git jump --stdout diff<RET>\n+--------------------------------------------------\n \n Related Programs\n ----------------\n@@ -100,7 +108,7 @@ Limitations\n -----------\n \n This script was written and tested with vim. Given that the quickfix\n-format is the same as what gcc produces, I expect emacs users have a\n+format is the same as what gcc produces, I expect other tools have a\n similar feature for iterating through the list, but I know nothing about\n how to activate it.\n \ndiff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump\nindex 92dbd4cde18..babb3b5c68d 100755\n--- a/contrib/git-jump/git-jump\n+++ b/contrib/git-jump/git-jump\n@@ -2,7 +2,7 @@\n \n usage() {\n \tcat <<\\EOF\n-usage: git jump <mode> [<args>]\n+usage: git jump [--stdout] <mode> [<args>]\n \n Jump to interesting elements in an editor.\n The <mode> parameter is one of:\n@@ -15,6 +15,9 @@ grep: elements are grep hits. Arguments are given to git grep or, if\n       configured, to the command in `jump.grepCmd`.\n \n ws: elements are whitespace errors. Arguments are given to diff --check.\n+\n+If the optional argument `--stdout` is given, print the quickfix\n+lines to standard output instead of feeding it to the editor.\n EOF\n }\n \n@@ -64,11 +67,31 @@ mode_ws() {\n \tgit diff --check \"$@\"\n }\n \n+use_stdout=\n+while test $# -gt 0; do\n+\tcase \"$1\" in\n+\t--stdout)\n+\t\tuse_stdout=t\n+\t\tshift\n+\t\t;;\n+\t--*)\n+\t\tusage >&2\n+\t\texit 1\n+\t\t;;\n+\t*)\n+\t\tbreak\n+\t\t;;\n+\tesac\n+done\n if test $# -lt 1; then\n \tusage >&2\n \texit 1\n fi\n mode=$1; shift\n+if test \"$use_stdout\" = \"t\"; then\n+\t\"mode_$mode\" \"$@\"\n+\texit 0\n+fi\n \n trap 'rm -f \"$tmp\"' 0 1 2 3 15\n tmp=`mktemp -t git-jump.XXXXXX` || exit 1\n-- \ngitgitgadget\n\n"},{"id":"467907","messageId":"972d51888ba015a6697475025466432218efa6dd.1669261642.git.gitgitgadget@gmail.com","threadId":"58820","inReplyTo":"pull.1423.v6.git.1669261642.gitgitgadget@gmail.com","subject":"[PATCH v6 2/3] git-jump: move valid-mode check earlier","fromName":"Jeff King via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2022-11-24T03:47:21Z","receivedAt":"2022-11-24T03:47:36Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"From: Jeff King <peff@peff.net>\n\nWe check if the \"mode\" argument supplied by the user is valid by seeing\nif we have a mode_$mode function defined. But we don't do that until\nafter creating the tempfile. This is wasteful (we create a tempfile but\nnever use it), and makes it harder to add new options (the recent stdout\noption exits before creating the tempfile, so it misses the check and\n\"git jump --stdout foo\" will produce \"git-jump: 92: mode_foo: not found\"\nrather than the regular usage message).\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n contrib/git-jump/git-jump | 3 ++-\n 1 file changed, 2 insertions(+), 1 deletion(-)\n\ndiff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump\nindex babb3b5c68d..cc97b0dcf02 100755\n--- a/contrib/git-jump/git-jump\n+++ b/contrib/git-jump/git-jump\n@@ -88,6 +88,8 @@ if test $# -lt 1; then\n \texit 1\n fi\n mode=$1; shift\n+type \"mode_$mode\" >/dev/null 2>&1 || { usage >&2; exit 1; }\n+\n if test \"$use_stdout\" = \"t\"; then\n \t\"mode_$mode\" \"$@\"\n \texit 0\n@@ -95,7 +97,6 @@ fi\n \n trap 'rm -f \"$tmp\"' 0 1 2 3 15\n tmp=`mktemp -t git-jump.XXXXXX` || exit 1\n-type \"mode_$mode\" >/dev/null 2>&1 || { usage >&2; exit 1; }\n \"mode_$mode\" \"$@\" >\"$tmp\"\n test -s \"$tmp\" || exit 0\n open_editor \"$tmp\"\n-- \ngitgitgadget\n\n"},{"id":"467908","messageId":"446d39f62fb90658149cae2f6046e1a292969531.1669261642.git.gitgitgadget@gmail.com","threadId":"58820","inReplyTo":"pull.1423.v6.git.1669261642.gitgitgadget@gmail.com","subject":"[PATCH v6 3/3] git-jump: invoke emacs/emacsclient","fromName":"Yoichi Nakayama via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2022-11-24T03:47:22Z","receivedAt":"2022-11-24T03:47:38Z","isPatch":true,"sender":{"key":"yoichi.nakayama@gmail.com","avatar":"https://avatars.githubusercontent.com/u/107537?v=4"},"body":"From: Yoichi Nakayama <yoichi.nakayama@gmail.com>\n\nIt works with GIT_EDITOR=\"emacs\", \"emacsclient\" or \"emacsclient -t\"\n\nSigned-off-by: Yoichi Nakayama <yoichi.nakayama@gmail.com>\n---\n contrib/git-jump/git-jump | 17 ++++++++++++++++-\n 1 file changed, 16 insertions(+), 1 deletion(-)\n\ndiff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump\nindex cc97b0dcf02..3e3911b1f9d 100755\n--- a/contrib/git-jump/git-jump\n+++ b/contrib/git-jump/git-jump\n@@ -23,7 +23,22 @@ EOF\n \n open_editor() {\n \teditor=`git var GIT_EDITOR`\n-\teval \"$editor -q \\$1\"\n+\tcase \"$editor\" in\n+\t*emacs*)\n+\t\t# Supported editor values are:\n+\t\t# - emacs\n+\t\t# - emacsclient\n+\t\t# - emacsclient -t\n+\t\t#\n+\t\t# Wait for completion of the asynchronously executed process\n+\t\t# to avoid race conditions in case of \"emacsclient\".\n+\t\teval \"$editor --eval \\\"(let ((buf (compilation-start \\\\\\\"cat $@\\\\\\\" 'grep-mode))) (pop-to-buffer buf) (select-frame-set-input-focus (selected-frame)) (while (get-buffer-process buf) (sleep-for 0.1)))\\\"\"\n+\t\t;;\n+\t*)\n+\t\t# assume anything else is vi-compatible\n+\t\teval \"$editor -q \\$1\"\n+\t\t;;\n+\tesac\n }\n \n mode_diff() {\n-- \ngitgitgadget\n"},{"id":"467930","messageId":"CAF5D8-u14grTa9cUo=ge8TVRKNYtVHWhFHDW8yYD9gD8=f0Byg@mail.gmail.com","threadId":"58820","inReplyTo":"Y37EPdUkBhsSPmRD@coredump.intra.peff.net","subject":"Re: [PATCH v4 2/2] git-jump: invoke emacs/emacsclient","fromName":"Yoichi Nakayama","fromEmail":"yoichi.nakayama@gmail.com","sentAt":"2022-11-24T12:32:45Z","receivedAt":"2022-11-24T12:33:00Z","isPatch":true,"sender":{"key":"yoichi.nakayama@gmail.com","avatar":"https://avatars.githubusercontent.com/u/107537?v=4"},"body":"On Thu, Nov 24, 2022 at 10:09 AM Jeff King <peff@peff.net> wrote:\n>\n> On Wed, Nov 23, 2022 at 02:33:50PM +0900, Yoichi Nakayama wrote:\n>\n> > On Wed, Nov 23, 2022 at 3:54 AM Jeff King <peff@peff.net> wrote:\n> > > Hmm, I know I suggested using a temporary file since \"cat $tmpfile\"\n> > > should be pretty safe. But it does still have problems if your tmp\n> > > directory has spaces. Or even other metacharacters, which I think will\n> > > be interpreted by the eval, since $@ is expanded in the outermost level\n> > > of the shell.\n> >\n> > Right. But the problem is not specific to emacs (it happens in vim too).\n> > Let's fix it another time (as you noted, that's pretty unlikely, and we may\n> > not even need to fix it).\n>\n> Good point. The vim version is easier to fix (we just need to\n> double-quote \\$1 inside the eval), but the fact that nobody has\n> complained is an indication that it does not really matter.\n\nI've confirmed the vim version is fixed by\n    eval \"$editor -q \\\"\\$1\\\"\"\n\nWith your hint, I found the emacs version can be fixed\nby single-quoting the variable (I found a mistake in the\nemacs version. Since there is only one argument, I\nshould use $1 instead of $@. I'll fix it.), and the vim\nversion can be also in the similar form with single quote:\n    eval \"$editor -q '$1'\"\n\nThe original vim version used the notation \\$1 instead of $1.\nI'm worried that the emacs version might need the backslash.\nWhat does the backslash mean? Is it necessary?\n-- \nYoichi NAKAYAMA\n"},{"id":"467934","messageId":"CAF5D8-vXK81U_n06u=p=B9urTWyQ5+fN8_w9FeCWQOv1xen07Q@mail.gmail.com","threadId":"58820","inReplyTo":"CAF5D8-u14grTa9cUo=ge8TVRKNYtVHWhFHDW8yYD9gD8=f0Byg@mail.gmail.com","subject":"Re: [PATCH v4 2/2] git-jump: invoke emacs/emacsclient","fromName":"Yoichi Nakayama","fromEmail":"yoichi.nakayama@gmail.com","sentAt":"2022-11-24T12:58:04Z","receivedAt":"2022-11-24T12:58:31Z","isPatch":true,"sender":{"key":"yoichi.nakayama@gmail.com","avatar":"https://avatars.githubusercontent.com/u/107537?v=4"},"body":"On Thu, Nov 24, 2022 at 9:32 PM Yoichi Nakayama\n<yoichi.nakayama@gmail.com> wrote:\n>\n> On Thu, Nov 24, 2022 at 10:09 AM Jeff King <peff@peff.net> wrote:\n> >\n> > On Wed, Nov 23, 2022 at 02:33:50PM +0900, Yoichi Nakayama wrote:\n> >\n> > > On Wed, Nov 23, 2022 at 3:54 AM Jeff King <peff@peff.net> wrote:\n> > > > Hmm, I know I suggested using a temporary file since \"cat $tmpfile\"\n> > > > should be pretty safe. But it does still have problems if your tmp\n> > > > directory has spaces. Or even other metacharacters, which I think will\n> > > > be interpreted by the eval, since $@ is expanded in the outermost level\n> > > > of the shell.\n> > >\n> > > Right. But the problem is not specific to emacs (it happens in vim too).\n> > > Let's fix it another time (as you noted, that's pretty unlikely, and we may\n> > > not even need to fix it).\n> >\n> > Good point. The vim version is easier to fix (we just need to\n> > double-quote \\$1 inside the eval), but the fact that nobody has\n> > complained is an indication that it does not really matter.\n>\n> I've confirmed the vim version is fixed by\n>     eval \"$editor -q \\\"\\$1\\\"\"\n>\n> With your hint, I found the emacs version can be fixed\n> by single-quoting the variable (I found a mistake in the\n> emacs version. Since there is only one argument, I\n> should use $1 instead of $@. I'll fix it.), and the vim\n> version can be also in the similar form with single quote:\n>     eval \"$editor -q '$1'\"\n>\n> The original vim version used the notation \\$1 instead of $1.\n> I'm worried that the emacs version might need the backslash.\n> What does the backslash mean? Is it necessary?\n\nI found the answer myself. The backslash is to leave the\nevaluation of the argument to the 'eval' execution.\nAnd another question arose. Why do we use eval?\nWhat is the difference from running it directly like below?\n    $editor -q $1\n\n-- \nYoichi NAKAYAMA\n"},{"id":"467943","messageId":"Y3+b80Vb2/6lKQ40@coredump.intra.peff.net","threadId":"58820","inReplyTo":"CAF5D8-u14grTa9cUo=ge8TVRKNYtVHWhFHDW8yYD9gD8=f0Byg@mail.gmail.com","subject":"Re: [PATCH v4 2/2] git-jump: invoke emacs/emacsclient","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2022-11-24T16:29:39Z","receivedAt":"2022-11-24T16:29:48Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Nov 24, 2022 at 09:32:45PM +0900, Yoichi Nakayama wrote:\n\n> > Good point. The vim version is easier to fix (we just need to\n> > double-quote \\$1 inside the eval), but the fact that nobody has\n> > complained is an indication that it does not really matter.\n> \n> I've confirmed the vim version is fixed by\n>     eval \"$editor -q \\\"\\$1\\\"\"\n> \n> With your hint, I found the emacs version can be fixed\n> by single-quoting the variable (I found a mistake in the\n> emacs version. Since there is only one argument, I\n> should use $1 instead of $@. I'll fix it.), and the vim\n> version can be also in the similar form with single quote:\n>     eval \"$editor -q '$1'\"\n\nThis isn't quite a full solution, though. The \"$1\" is expanded by the\nouter double-quoted string, which is then fed to eval. The inner\nsingle-quotes make most characters literally except for single-quotes\nthemselves. So if $1 has single-quotes, the eval will barf due to bad\nsyntax.\n\n> The original vim version used the notation \\$1 instead of $1.\n> I'm worried that the emacs version might need the backslash.\n> What does the backslash mean? Is it necessary?\n\nAs you figured out in the other email, it inhibits the outer layer of\nexpansion, and lets the eval expand it. This is the easiest way to pass\nthings through levels of shell evals (since otherwise you have to\nactually quote, which is a real pain).\n\nNone of this is sufficient for your emacs example, though. There you\nhave three levels of quoting:\n\n  - getting the argument intact into the eval; this can use the \"\\$\"\n    trick\n\n  - the argument then appears inside a double-quoted string which will\n    be evaluated by emacs. You'd want to protect it against\n    double-quotes and presumably backslashes.\n\n  - emacs will then execute the final command, presumably you a shell.\n    So you'd want to protect against expansion in that shell. The\n    easiest way to do that is usually to wrap each argument in\n    single-quotes, and quoting against interior single quotes (by ending\n    single-quote, adding a single backslashed single-quote, and then\n    re-opening the single-quote). It's horribly ugly, but is (AFAIK) the\n    shortest way to quote shell arguments, and what we usually do in\n    Git.\n\nThose are the three tricks I sent in the earlier email (though looking\nat it again, I think the single-quote bits need to come first, so their\nbackslashes are then quoted to protect against emacs evaluation).\n\nIt's all quite confusing, which is why I am OK with just skipping it for\nnow. ;) The nice thing, though, is that doing the quoting right means\nit's safe to get rid of the \"cat\", which solves your race problems in a\nmore direct and robust way.\n\n-Peff\n"},{"id":"467944","messageId":"Y3+cepfUpi0vm7yM@coredump.intra.peff.net","threadId":"58820","inReplyTo":"CAF5D8-vXK81U_n06u=p=B9urTWyQ5+fN8_w9FeCWQOv1xen07Q@mail.gmail.com","subject":"Re: [PATCH v4 2/2] git-jump: invoke emacs/emacsclient","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2022-11-24T16:31:54Z","receivedAt":"2022-11-24T16:31:59Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Nov 24, 2022 at 09:58:04PM +0900, Yoichi Nakayama wrote:\n\n> > The original vim version used the notation \\$1 instead of $1.\n> > I'm worried that the emacs version might need the backslash.\n> > What does the backslash mean? Is it necessary?\n> \n> I found the answer myself. The backslash is to leave the\n> evaluation of the argument to the 'eval' execution.\n> And another question arose. Why do we use eval?\n> What is the difference from running it directly like below?\n>     $editor -q $1\n\nThe value of $editor is not a single program name, but is itself a shell\ncommand. So you could imagine:\n\n  git config core.editor \"some_command --with --args\"\n\nor even more complicated shell hackery. From within Git, we'd run it as:\n\n  sh -c \"some_command --with --args\"\n\nbut when you are in a shell already, \"eval\" is a more efficient way of\ndoing the same.\n\n-Peff\n"},{"id":"467961","messageId":"pull.1423.v7.git.1669347422.gitgitgadget@gmail.com","threadId":"58820","inReplyTo":"pull.1423.v6.git.1669261642.gitgitgadget@gmail.com","subject":"[PATCH v7 0/3] git-jump: support Emacs","fromName":"Yoichi NAKAYAMA via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2022-11-25T03:36:58Z","receivedAt":"2022-11-25T03:37:20Z","isPatch":true,"sender":{"key":"yoichi.nakayama@gmail.com","avatar":"https://avatars.githubusercontent.com/u/107537?v=4"},"body":"Add an optional argument 'stdout' to print the quickfix lines to standard\noutput. It can be used with M-x grep on Emacs.\n\nDetect emacsclient by GIT_EDITOR and invoke the function. Tested with\nEDITOR=\"emacsclient\" and EDITOR=\"emacsclient -t\".\n\nJeff King (1):\n  git-jump: move valid-mode check earlier\n\nYoichi Nakayama (2):\n  git-jump: add an optional argument '--stdout'\n  git-jump: invoke emacs/emacsclient\n\n contrib/git-jump/README   | 10 ++++++++-\n contrib/git-jump/git-jump | 45 ++++++++++++++++++++++++++++++++++++---\n 2 files changed, 51 insertions(+), 4 deletions(-)\n\n\nbase-commit: eea7033409a0ed713c78437fc76486983d211e25\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-1423%2Fyoichi%2Fgit-jump-emacs-support-v7\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1423/yoichi/git-jump-emacs-support-v7\nPull-Request: https://github.com/gitgitgadget/git/pull/1423\n\nRange-diff vs v6:\n\n 1:  446777d300d = 1:  446777d300d git-jump: add an optional argument '--stdout'\n 2:  972d51888ba = 2:  972d51888ba git-jump: move valid-mode check earlier\n 3:  446d39f62fb ! 3:  d8233f96175 git-jump: invoke emacs/emacsclient\n     @@ contrib/git-jump/git-jump: EOF\n      +\t\t#\n      +\t\t# Wait for completion of the asynchronously executed process\n      +\t\t# to avoid race conditions in case of \"emacsclient\".\n     -+\t\teval \"$editor --eval \\\"(let ((buf (compilation-start \\\\\\\"cat $@\\\\\\\" 'grep-mode))) (pop-to-buffer buf) (select-frame-set-input-focus (selected-frame)) (while (get-buffer-process buf) (sleep-for 0.1)))\\\"\"\n     ++\t\teval \"$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)))\\\"\"\n      +\t\t;;\n      +\t*)\n      +\t\t# assume anything else is vi-compatible\n\n-- \ngitgitgadget\n"},{"id":"467962","messageId":"446777d300d73498bd7da709fad75731a13d0d59.1669347422.git.gitgitgadget@gmail.com","threadId":"58820","inReplyTo":"pull.1423.v7.git.1669347422.gitgitgadget@gmail.com","subject":"[PATCH v7 1/3] git-jump: add an optional argument '--stdout'","fromName":"Yoichi Nakayama via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2022-11-25T03:36:59Z","receivedAt":"2022-11-25T03:37:22Z","isPatch":true,"sender":{"key":"yoichi.nakayama@gmail.com","avatar":"https://avatars.githubusercontent.com/u/107537?v=4"},"body":"From: Yoichi Nakayama <yoichi.nakayama@gmail.com>\n\nIt can be used with M-x grep on Emacs.\n\nSigned-off-by: Yoichi Nakayama <yoichi.nakayama@gmail.com>\n---\n contrib/git-jump/README   | 10 +++++++++-\n contrib/git-jump/git-jump | 25 ++++++++++++++++++++++++-\n 2 files changed, 33 insertions(+), 2 deletions(-)\n\ndiff --git a/contrib/git-jump/README b/contrib/git-jump/README\nindex 8bcace29d21..3211841305f 100644\n--- a/contrib/git-jump/README\n+++ b/contrib/git-jump/README\n@@ -79,6 +79,14 @@ git jump grep -i foo_bar\n git config jump.grepCmd \"ag --column\"\n --------------------------------------------------\n \n+You can use the optional argument '--stdout' to print the listing to\n+standard output instead of feeding it to the editor. You can use the\n+argument with M-x grep on Emacs:\n+\n+--------------------------------------------------\n+# In Emacs, M-x grep and invoke \"git jump --stdout <mode>\"\n+M-x grep<RET>git jump --stdout diff<RET>\n+--------------------------------------------------\n \n Related Programs\n ----------------\n@@ -100,7 +108,7 @@ Limitations\n -----------\n \n This script was written and tested with vim. Given that the quickfix\n-format is the same as what gcc produces, I expect emacs users have a\n+format is the same as what gcc produces, I expect other tools have a\n similar feature for iterating through the list, but I know nothing about\n how to activate it.\n \ndiff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump\nindex 92dbd4cde18..babb3b5c68d 100755\n--- a/contrib/git-jump/git-jump\n+++ b/contrib/git-jump/git-jump\n@@ -2,7 +2,7 @@\n \n usage() {\n \tcat <<\\EOF\n-usage: git jump <mode> [<args>]\n+usage: git jump [--stdout] <mode> [<args>]\n \n Jump to interesting elements in an editor.\n The <mode> parameter is one of:\n@@ -15,6 +15,9 @@ grep: elements are grep hits. Arguments are given to git grep or, if\n       configured, to the command in `jump.grepCmd`.\n \n ws: elements are whitespace errors. Arguments are given to diff --check.\n+\n+If the optional argument `--stdout` is given, print the quickfix\n+lines to standard output instead of feeding it to the editor.\n EOF\n }\n \n@@ -64,11 +67,31 @@ mode_ws() {\n \tgit diff --check \"$@\"\n }\n \n+use_stdout=\n+while test $# -gt 0; do\n+\tcase \"$1\" in\n+\t--stdout)\n+\t\tuse_stdout=t\n+\t\tshift\n+\t\t;;\n+\t--*)\n+\t\tusage >&2\n+\t\texit 1\n+\t\t;;\n+\t*)\n+\t\tbreak\n+\t\t;;\n+\tesac\n+done\n if test $# -lt 1; then\n \tusage >&2\n \texit 1\n fi\n mode=$1; shift\n+if test \"$use_stdout\" = \"t\"; then\n+\t\"mode_$mode\" \"$@\"\n+\texit 0\n+fi\n \n trap 'rm -f \"$tmp\"' 0 1 2 3 15\n tmp=`mktemp -t git-jump.XXXXXX` || exit 1\n-- \ngitgitgadget\n\n"},{"id":"467963","messageId":"972d51888ba015a6697475025466432218efa6dd.1669347422.git.gitgitgadget@gmail.com","threadId":"58820","inReplyTo":"pull.1423.v7.git.1669347422.gitgitgadget@gmail.com","subject":"[PATCH v7 2/3] git-jump: move valid-mode check earlier","fromName":"Jeff King via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2022-11-25T03:37:00Z","receivedAt":"2022-11-25T03:37:22Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"From: Jeff King <peff@peff.net>\n\nWe check if the \"mode\" argument supplied by the user is valid by seeing\nif we have a mode_$mode function defined. But we don't do that until\nafter creating the tempfile. This is wasteful (we create a tempfile but\nnever use it), and makes it harder to add new options (the recent stdout\noption exits before creating the tempfile, so it misses the check and\n\"git jump --stdout foo\" will produce \"git-jump: 92: mode_foo: not found\"\nrather than the regular usage message).\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n contrib/git-jump/git-jump | 3 ++-\n 1 file changed, 2 insertions(+), 1 deletion(-)\n\ndiff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump\nindex babb3b5c68d..cc97b0dcf02 100755\n--- a/contrib/git-jump/git-jump\n+++ b/contrib/git-jump/git-jump\n@@ -88,6 +88,8 @@ if test $# -lt 1; then\n \texit 1\n fi\n mode=$1; shift\n+type \"mode_$mode\" >/dev/null 2>&1 || { usage >&2; exit 1; }\n+\n if test \"$use_stdout\" = \"t\"; then\n \t\"mode_$mode\" \"$@\"\n \texit 0\n@@ -95,7 +97,6 @@ fi\n \n trap 'rm -f \"$tmp\"' 0 1 2 3 15\n tmp=`mktemp -t git-jump.XXXXXX` || exit 1\n-type \"mode_$mode\" >/dev/null 2>&1 || { usage >&2; exit 1; }\n \"mode_$mode\" \"$@\" >\"$tmp\"\n test -s \"$tmp\" || exit 0\n open_editor \"$tmp\"\n-- \ngitgitgadget\n\n"},{"id":"467964","messageId":"d8233f9617563d7c7168afc6e1abfaba57e54038.1669347422.git.gitgitgadget@gmail.com","threadId":"58820","inReplyTo":"pull.1423.v7.git.1669347422.gitgitgadget@gmail.com","subject":"[PATCH v7 3/3] git-jump: invoke emacs/emacsclient","fromName":"Yoichi Nakayama via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2022-11-25T03:37:01Z","receivedAt":"2022-11-25T03:37:23Z","isPatch":true,"sender":{"key":"yoichi.nakayama@gmail.com","avatar":"https://avatars.githubusercontent.com/u/107537?v=4"},"body":"From: Yoichi Nakayama <yoichi.nakayama@gmail.com>\n\nIt works with GIT_EDITOR=\"emacs\", \"emacsclient\" or \"emacsclient -t\"\n\nSigned-off-by: Yoichi Nakayama <yoichi.nakayama@gmail.com>\n---\n contrib/git-jump/git-jump | 17 ++++++++++++++++-\n 1 file changed, 16 insertions(+), 1 deletion(-)\n\ndiff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump\nindex cc97b0dcf02..eef9cda832f 100755\n--- a/contrib/git-jump/git-jump\n+++ b/contrib/git-jump/git-jump\n@@ -23,7 +23,22 @@ EOF\n \n open_editor() {\n \teditor=`git var GIT_EDITOR`\n-\teval \"$editor -q \\$1\"\n+\tcase \"$editor\" in\n+\t*emacs*)\n+\t\t# Supported editor values are:\n+\t\t# - emacs\n+\t\t# - emacsclient\n+\t\t# - emacsclient -t\n+\t\t#\n+\t\t# Wait for completion of the asynchronously executed process\n+\t\t# to avoid race conditions in case of \"emacsclient\".\n+\t\teval \"$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)))\\\"\"\n+\t\t;;\n+\t*)\n+\t\t# assume anything else is vi-compatible\n+\t\teval \"$editor -q \\$1\"\n+\t\t;;\n+\tesac\n }\n \n mode_diff() {\n-- \ngitgitgadget\n"},{"id":"467965","messageId":"CAF5D8-ufUcCfQYMTTRwD07p7+37OBC4zkiWmAa5n1P5pL9EtOQ@mail.gmail.com","threadId":"58820","inReplyTo":"Y3+b80Vb2/6lKQ40@coredump.intra.peff.net","subject":"Re: [PATCH v4 2/2] git-jump: invoke emacs/emacsclient","fromName":"Yoichi Nakayama","fromEmail":"yoichi.nakayama@gmail.com","sentAt":"2022-11-25T03:46:34Z","receivedAt":"2022-11-25T03:46:49Z","isPatch":true,"sender":{"key":"yoichi.nakayama@gmail.com","avatar":"https://avatars.githubusercontent.com/u/107537?v=4"},"body":"On Fri, Nov 25, 2022 at 1:29 AM Jeff King <peff@peff.net> wrote:\n> Those are the three tricks I sent in the earlier email (though looking\n> at it again, I think the single-quote bits need to come first, so their\n> backslashes are then quoted to protect against emacs evaluation).\n>\n> It's all quite confusing, which is why I am OK with just skipping it for\n> now. ;) The nice thing, though, is that doing the quoting right means\n> it's safe to get rid of the \"cat\", which solves your race problems in a\n> more direct and robust way.\n\nThank you for taking the time to explain the details. I don't fully\nunderstand it yet, but I know it's hard to deal with properly.\n\nIn PATCH v7, I made it the same level as the vim version (although it\nis not strictly at the same level because there is a Emacs Lisp processing).\nI skip futher treatment of temporary file paths.\n\nRegards,\n-- \nYoichi NAKAYAMA\n"},{"id":"467981","messageId":"221125.8635a7o123.gmgdl@evledraar.gmail.com","threadId":"58820","inReplyTo":"d8233f9617563d7c7168afc6e1abfaba57e54038.1669347422.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v7 3/3] git-jump: invoke emacs/emacsclient","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-25T08:55:13Z","receivedAt":"2022-11-25T09:09:02Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Fri, Nov 25 2022, Yoichi Nakayama via GitGitGadget wrote:\n\n> From: Yoichi Nakayama <yoichi.nakayama@gmail.com>\n>\n> It works with GIT_EDITOR=\"emacs\", \"emacsclient\" or \"emacsclient -t\"\n>\n> Signed-off-by: Yoichi Nakayama <yoichi.nakayama@gmail.com>\n> ---\n>  contrib/git-jump/git-jump | 17 ++++++++++++++++-\n>  1 file changed, 16 insertions(+), 1 deletion(-)\n>\n> diff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump\n> index cc97b0dcf02..eef9cda832f 100755\n> --- a/contrib/git-jump/git-jump\n> +++ b/contrib/git-jump/git-jump\n> @@ -23,7 +23,22 @@ EOF\n>  \n>  open_editor() {\n>  \teditor=`git var GIT_EDITOR`\n> -\teval \"$editor -q \\$1\"\n> +\tcase \"$editor\" in\n> +\t*emacs*)\n> +\t\t# Supported editor values are:\n> +\t\t# - emacs\n> +\t\t# - emacsclient\n> +\t\t# - emacsclient -t\n> +\t\t#\n> +\t\t# Wait for completion of the asynchronously executed process\n> +\t\t# to avoid race conditions in case of \"emacsclient\".\n> +\t\teval \"$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)))\\\"\"\n> +\t\t;;\n> +\t*)\n> +\t\t# assume anything else is vi-compatible\n> +\t\teval \"$editor -q \\$1\"\n> +\t\t;;\n> +\tesac\n>  }\n>  \n>  mode_diff() {\n\nI'd really like to have some closer and smarter emacs integration like\nthis.\n\nBut I don't see why we need to run the grep ourselves, pipe it to a\ntemporary file, and then discover that we're using emacs, and --eval\ncode into it to switch to that buffer, and fake up a \"M-x grep\" command\nwith a compilation buffer to make it look like we ran M-x grep in the\nfirst place.\n\nLet's just ... run M-x grep earlier? Then we can skip all the earlier\nsteps.\n\nI experimented with this a bit locally, and I didn't get the \"switch to\nbuffer\" semantics to work with this (but that's presumably easy, I'm\njust rusty on my elisp APIs), but something in this direction seems much\nbetter:\n\t\n\tdiff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump\n\tindex eef9cda832f..c932d7acd0f 100755\n\t--- a/contrib/git-jump/git-jump\n\t+++ b/contrib/git-jump/git-jump\n\t@@ -22,23 +22,7 @@ EOF\n\t }\n\t \n\t open_editor() {\n\t-\teditor=`git var GIT_EDITOR`\n\t-\tcase \"$editor\" in\n\t-\t*emacs*)\n\t-\t\t# Supported editor values are:\n\t-\t\t# - emacs\n\t-\t\t# - emacsclient\n\t-\t\t# - emacsclient -t\n\t-\t\t#\n\t-\t\t# Wait for completion of the asynchronously executed process\n\t-\t\t# to avoid race conditions in case of \"emacsclient\".\n\t-\t\teval \"$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)))\\\"\"\n\t-\t\t;;\n\t-\t*)\n\t-\t\t# assume anything else is vi-compatible\n\t-\t\teval \"$editor -q \\$1\"\n\t-\t\t;;\n\t-\tesac\n\t+\teval \"$editor -q \\$1\"\n\t }\n\t \n\t mode_diff() {\n\t@@ -83,11 +67,14 @@ mode_ws() {\n\t }\n\t \n\t use_stdout=\n\t+use_magic=t\n\t while test $# -gt 0; do\n\t \tcase \"$1\" in\n\t \t--stdout)\n\t \t\tuse_stdout=t\n\t-\t\tshift\n\t+\t\t;;\n\t+\t--no-magic)\n\t+\t\tuse_magic=\n\t \t\t;;\n\t \t--*)\n\t \t\tusage >&2\n\t@@ -96,7 +83,8 @@ while test $# -gt 0; do\n\t \t*)\n\t \t\tbreak\n\t \t\t;;\n\t-\tesac\n\t+\tesac &&\n\t+\tshift\n\t done\n\t if test $# -lt 1; then\n\t \tusage >&2\n\t@@ -105,6 +93,22 @@ fi\n\t mode=$1; shift\n\t type \"mode_$mode\" >/dev/null 2>&1 || { usage >&2; exit 1; }\n\t \n\t+editor=`git var GIT_EDITOR`\n\t+if test \"$use_magic\" && test \"$mode\" = \"grep\"\n\t+then\n\t+\tcase \"$editor\" in\n\t+\t*emacs*)\n\t+\t\tset -x\n\t+\t\teval \"$editor --eval \\\" \\\n\t+\t\t\t(grep \\\\\\\"git grep -H \"$@\"\\\\\\\") \\\n\t+\t\t\\\"\"\n\t+\t\texit\n\t+\t\t;;\n\t+\t*)\n\t+\t\t;;\n\t+\tesac\n\t+fi\n\t+\n\t if test \"$use_stdout\" = \"t\"; then\n\t \t\"mode_$mode\" \"$@\"\n\t \texit 0\n\nI.e. if we're going to trust emacs to eval this code, and assume that\ngrep.el etc. works, let's just run the equivalent of M-x grep with our\n'git grep' command.\n\nThis is already better in that \"grep\" understands that I searched for\n\"foo.*bar\", so that's highlighted in the resulting buffer, just as with\nnormal \"grep\" commands.\n\nThis is missing the bit where we'd need to jump.grepCmd etc, so it's\nincomplete.\n\nI think this is all the prior art we'd need to invoke \"git grep\" the\nright way from emacs's \"grep\":\nhttps://github.com/eglaysher/find-things-fast/blob/master/find-things-fast.el#L246\n\nB.t.w. I'd think the \"--no-magic\" here is something you'd want too. I\nlike this new behavior (sans the comments above), but presumably there's\npeople using emacs as their EDITOR who don't want to have this magic\nbehavior, having an opt-out would be neat.\n\nI.e. if you have an existing customization intercepting these then this\nwill screw with that, but maybe that's OK...\n"},{"id":"467982","messageId":"221125.86y1rzmmfc.gmgdl@evledraar.gmail.com","threadId":"58820","inReplyTo":"446777d300d73498bd7da709fad75731a13d0d59.1669347422.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v7 1/3] git-jump: add an optional argument '--stdout'","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-25T09:06:50Z","receivedAt":"2022-11-25T09:10:23Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Fri, Nov 25 2022, Yoichi Nakayama via GitGitGadget wrote:\n\n> From: Yoichi Nakayama <yoichi.nakayama@gmail.com>\n\n> +use_stdout=\n> +while test $# -gt 0; do\n> +\tcase \"$1\" in\n> +\t--stdout)\n> +\t\tuse_stdout=t\n> +\t\tshift\n\nPut this \"shift\"....\n\n> +\t\t;;\n> +\t--*)\n> +\t\tusage >&2\n> +\t\texit 1\n> +\t\t;;\n> +\t*)\n> +\t\tbreak\n> +\t\t;;\n> +\tesac\n\n... here instead, as I showed in a comment on 3/3 you'd need to to that,\nor copy/paste it for every option once you have >1 option. See\ne.g. \"test_commit\" in \"t/test-lib-functions.sh\" for a function with that\npattern.\n"},{"id":"468000","messageId":"CAF5D8-uxZOFi8p0bUMaqJCLFxipXCB9fo_Kx=QE6s=DW8Jspgg@mail.gmail.com","threadId":"58820","inReplyTo":"221125.8635a7o123.gmgdl@evledraar.gmail.com","subject":"Re: [PATCH v7 3/3] git-jump: invoke emacs/emacsclient","fromName":"Yoichi Nakayama","fromEmail":"yoichi.nakayama@gmail.com","sentAt":"2022-11-25T16:01:12Z","receivedAt":"2022-11-25T16:01:31Z","isPatch":true,"sender":{"key":"yoichi.nakayama@gmail.com","avatar":"https://avatars.githubusercontent.com/u/107537?v=4"},"body":"On Fri, Nov 25, 2022 at 6:08 PM Ævar Arnfjörð Bjarmason\n<avarab@gmail.com> wrote:\n> I'd really like to have some closer and smarter emacs integration like\n> this.\n>\n> But I don't see why we need to run the grep ourselves, pipe it to a\n> temporary file, and then discover that we're using emacs, and --eval\n> code into it to switch to that buffer, and fake up a \"M-x grep\" command\n> with a compilation buffer to make it look like we ran M-x grep in the\n> first place.\n>\n> Let's just ... run M-x grep earlier? Then we can skip all the earlier\n> steps.\n\nThere are two reasons.\n\nFirst, I want to reuse the modes that git-jump already have. In\naddition to mode_grep,\nmode_{diff,merge,ws} exist, and if we re-implement each for editor\nsupport, I think it will be\ndifficult to maintain.\n\nSecond, there is a difficulty passing arbitrary arguments properly to\nEmacs Lisp properly.\nFor example, your version will cause error with\n        git jump grep \"hello world\"\nMy early patch was doing something similar. But the second problem was\nhard to deal with,\nso I switched to using a temporary file.\n-- \nYoichi NAKAYAMA\n"},{"id":"468010","messageId":"221126.86h6ymmvyc.gmgdl@evledraar.gmail.com","threadId":"58820","inReplyTo":"CAF5D8-uxZOFi8p0bUMaqJCLFxipXCB9fo_Kx=QE6s=DW8Jspgg@mail.gmail.com","subject":"Re: [PATCH v7 3/3] git-jump: invoke emacs/emacsclient","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-25T23:52:50Z","receivedAt":"2022-11-25T23:54:40Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Sat, Nov 26 2022, Yoichi Nakayama wrote:\n\n> On Fri, Nov 25, 2022 at 6:08 PM Ævar Arnfjörð Bjarmason\n> <avarab@gmail.com> wrote:\n>> I'd really like to have some closer and smarter emacs integration like\n>> this.\n>>\n>> But I don't see why we need to run the grep ourselves, pipe it to a\n>> temporary file, and then discover that we're using emacs, and --eval\n>> code into it to switch to that buffer, and fake up a \"M-x grep\" command\n>> with a compilation buffer to make it look like we ran M-x grep in the\n>> first place.\n>>\n>> Let's just ... run M-x grep earlier? Then we can skip all the earlier\n>> steps.\n>\n> There are two reasons.\n>\n> First, I want to reuse the modes that git-jump already have. In\n> addition to mode_grep,\n> mode_{diff,merge,ws} exist, and if we re-implement each for editor\n> support, I think it will be\n> difficult to maintain.\n\nYeah, maybe that'll be painful. I haven't poked much at it...\n\n> Second, there is a difficulty passing arbitrary arguments properly to\n> Emacs Lisp properly.\n> For example, your version will cause error with\n>         git jump grep \"hello world\"\n> My early patch was doing something similar. But the second problem was\n> hard to deal with,\n> so I switched to using a temporary file.\n\nTo the extent that that's painful couldn't we write the grep expression\n/ arguments to the tempfile, then feed the tempfile to the ad-hoc elisp\ncode?\n\nIt would then read it, get the argument to grep for, and we'd call (grep\nthat-argument).\n"},{"id":"468025","messageId":"CAF5D8-uaR-BMoCzGuDsYDbBxaKFS0vzAvWY0mq12vBGtecwajQ@mail.gmail.com","threadId":"58820","inReplyTo":"221125.86y1rzmmfc.gmgdl@evledraar.gmail.com","subject":"Re: [PATCH v7 1/3] git-jump: add an optional argument '--stdout'","fromName":"Yoichi Nakayama","fromEmail":"yoichi.nakayama@gmail.com","sentAt":"2022-11-27T00:31:48Z","receivedAt":"2022-11-27T00:32:03Z","isPatch":true,"sender":{"key":"yoichi.nakayama@gmail.com","avatar":"https://avatars.githubusercontent.com/u/107537?v=4"},"body":"On Fri, Nov 25, 2022 at 6:10 PM Ævar Arnfjörð Bjarmason\n<avarab@gmail.com> wrote:\n>\n>\n> On Fri, Nov 25 2022, Yoichi Nakayama via GitGitGadget wrote:\n>\n> > From: Yoichi Nakayama <yoichi.nakayama@gmail.com>\n>\n> > +use_stdout=\n> > +while test $# -gt 0; do\n> > +     case \"$1\" in\n> > +     --stdout)\n> > +             use_stdout=t\n> > +             shift\n>\n> Put this \"shift\"....\n>\n> > +             ;;\n> > +     --*)\n> > +             usage >&2\n> > +             exit 1\n> > +             ;;\n> > +     *)\n> > +             break\n> > +             ;;\n> > +     esac\n>\n> ... here instead, as I showed in a comment on 3/3 you'd need to to that,\n> or copy/paste it for every option once you have >1 option. See\n> e.g. \"test_commit\" in \"t/test-lib-functions.sh\" for a function with that\n> pattern.\n\nThanks. I'll apply this.\n\n-- \nYoichi NAKAYAMA\n"},{"id":"468026","messageId":"CAF5D8-s=6eJSXZbVwebbVcqtzVG1vLGopq7_2HT7rSjDbbJ6aQ@mail.gmail.com","threadId":"58820","inReplyTo":"CAF5D8-uxZOFi8p0bUMaqJCLFxipXCB9fo_Kx=QE6s=DW8Jspgg@mail.gmail.com","subject":"Re: [PATCH v7 3/3] git-jump: invoke emacs/emacsclient","fromName":"Yoichi Nakayama","fromEmail":"yoichi.nakayama@gmail.com","sentAt":"2022-11-27T00:37:08Z","receivedAt":"2022-11-27T00:37:22Z","isPatch":true,"sender":{"key":"yoichi.nakayama@gmail.com","avatar":"https://avatars.githubusercontent.com/u/107537?v=4"},"body":"On Sat, Nov 26, 2022 at 1:01 AM Yoichi Nakayama\n<yoichi.nakayama@gmail.com> wrote:\n> Second, there is a difficulty passing arbitrary arguments properly to\n> Emacs Lisp properly.\n> For example, your version will cause error with\n>         git jump grep \"hello world\"\n> My early patch was doing something similar. But the second problem was\n> hard to deal with,\n> so I switched to using a temporary file.\n\nBut even in that case it was fine to use the original grep function\ndefined in grep.el.\nI'll fix it in v8.\n\n\n--\nYoichi NAKAYAMA\n"},{"id":"468027","messageId":"pull.1423.v8.git.1669511933.gitgitgadget@gmail.com","threadId":"58820","inReplyTo":"pull.1423.v7.git.1669347422.gitgitgadget@gmail.com","subject":"[PATCH v8 0/3] git-jump: support Emacs","fromName":"Yoichi NAKAYAMA via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2022-11-27T01:18:50Z","receivedAt":"2022-11-27T01:19:02Z","isPatch":true,"sender":{"key":"yoichi.nakayama@gmail.com","avatar":"https://avatars.githubusercontent.com/u/107537?v=4"},"body":"Add an optional argument 'stdout' to print the quickfix lines to standard\noutput. It can be used with M-x grep on Emacs.\n\nDetect emacsclient by GIT_EDITOR and invoke the function. Tested with\nEDITOR=\"emacsclient\" and EDITOR=\"emacsclient -t\".\n\nJeff King (1):\n  git-jump: move valid-mode check earlier\n\nYoichi Nakayama (2):\n  git-jump: add an optional argument '--stdout'\n  git-jump: invoke emacs/emacsclient\n\n contrib/git-jump/README   | 10 ++++++++-\n contrib/git-jump/git-jump | 45 ++++++++++++++++++++++++++++++++++++---\n 2 files changed, 51 insertions(+), 4 deletions(-)\n\n\nbase-commit: eea7033409a0ed713c78437fc76486983d211e25\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-1423%2Fyoichi%2Fgit-jump-emacs-support-v8\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1423/yoichi/git-jump-emacs-support-v8\nPull-Request: https://github.com/gitgitgadget/git/pull/1423\n\nRange-diff vs v7:\n\n 1:  446777d300d ! 1:  afface9b010 git-jump: add an optional argument '--stdout'\n     @@ contrib/git-jump/git-jump: mode_ws() {\n      +\tcase \"$1\" in\n      +\t--stdout)\n      +\t\tuse_stdout=t\n     -+\t\tshift\n      +\t\t;;\n      +\t--*)\n      +\t\tusage >&2\n     @@ contrib/git-jump/git-jump: mode_ws() {\n      +\t\tbreak\n      +\t\t;;\n      +\tesac\n     ++\tshift\n      +done\n       if test $# -lt 1; then\n       \tusage >&2\n 2:  972d51888ba = 2:  e9aa6fdf836 git-jump: move valid-mode check earlier\n 3:  d8233f96175 ! 3:  048f508ca99 git-jump: invoke emacs/emacsclient\n     @@ contrib/git-jump/git-jump: EOF\n      +\t\t#\n      +\t\t# Wait for completion of the asynchronously executed process\n      +\t\t# to avoid race conditions in case of \"emacsclient\".\n     -+\t\teval \"$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)))\\\"\"\n     ++\t\teval \"$editor --eval \\\"(let ((buf (grep \\\\\\\"cat \\$1\\\\\\\"))) (pop-to-buffer buf) (select-frame-set-input-focus (selected-frame)) (while (get-buffer-process buf) (sleep-for 0.1)))\\\"\"\n      +\t\t;;\n      +\t*)\n      +\t\t# assume anything else is vi-compatible\n\n-- \ngitgitgadget\n"},{"id":"468028","messageId":"afface9b0102c888817f3bd3481dbd7278236954.1669511933.git.gitgitgadget@gmail.com","threadId":"58820","inReplyTo":"pull.1423.v8.git.1669511933.gitgitgadget@gmail.com","subject":"[PATCH v8 1/3] git-jump: add an optional argument '--stdout'","fromName":"Yoichi Nakayama via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2022-11-27T01:18:51Z","receivedAt":"2022-11-27T01:19:02Z","isPatch":true,"sender":{"key":"yoichi.nakayama@gmail.com","avatar":"https://avatars.githubusercontent.com/u/107537?v=4"},"body":"From: Yoichi Nakayama <yoichi.nakayama@gmail.com>\n\nIt can be used with M-x grep on Emacs.\n\nSigned-off-by: Yoichi Nakayama <yoichi.nakayama@gmail.com>\n---\n contrib/git-jump/README   | 10 +++++++++-\n contrib/git-jump/git-jump | 25 ++++++++++++++++++++++++-\n 2 files changed, 33 insertions(+), 2 deletions(-)\n\ndiff --git a/contrib/git-jump/README b/contrib/git-jump/README\nindex 8bcace29d21..3211841305f 100644\n--- a/contrib/git-jump/README\n+++ b/contrib/git-jump/README\n@@ -79,6 +79,14 @@ git jump grep -i foo_bar\n git config jump.grepCmd \"ag --column\"\n --------------------------------------------------\n \n+You can use the optional argument '--stdout' to print the listing to\n+standard output instead of feeding it to the editor. You can use the\n+argument with M-x grep on Emacs:\n+\n+--------------------------------------------------\n+# In Emacs, M-x grep and invoke \"git jump --stdout <mode>\"\n+M-x grep<RET>git jump --stdout diff<RET>\n+--------------------------------------------------\n \n Related Programs\n ----------------\n@@ -100,7 +108,7 @@ Limitations\n -----------\n \n This script was written and tested with vim. Given that the quickfix\n-format is the same as what gcc produces, I expect emacs users have a\n+format is the same as what gcc produces, I expect other tools have a\n similar feature for iterating through the list, but I know nothing about\n how to activate it.\n \ndiff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump\nindex 92dbd4cde18..be0642bbe34 100755\n--- a/contrib/git-jump/git-jump\n+++ b/contrib/git-jump/git-jump\n@@ -2,7 +2,7 @@\n \n usage() {\n \tcat <<\\EOF\n-usage: git jump <mode> [<args>]\n+usage: git jump [--stdout] <mode> [<args>]\n \n Jump to interesting elements in an editor.\n The <mode> parameter is one of:\n@@ -15,6 +15,9 @@ grep: elements are grep hits. Arguments are given to git grep or, if\n       configured, to the command in `jump.grepCmd`.\n \n ws: elements are whitespace errors. Arguments are given to diff --check.\n+\n+If the optional argument `--stdout` is given, print the quickfix\n+lines to standard output instead of feeding it to the editor.\n EOF\n }\n \n@@ -64,11 +67,31 @@ mode_ws() {\n \tgit diff --check \"$@\"\n }\n \n+use_stdout=\n+while test $# -gt 0; do\n+\tcase \"$1\" in\n+\t--stdout)\n+\t\tuse_stdout=t\n+\t\t;;\n+\t--*)\n+\t\tusage >&2\n+\t\texit 1\n+\t\t;;\n+\t*)\n+\t\tbreak\n+\t\t;;\n+\tesac\n+\tshift\n+done\n if test $# -lt 1; then\n \tusage >&2\n \texit 1\n fi\n mode=$1; shift\n+if test \"$use_stdout\" = \"t\"; then\n+\t\"mode_$mode\" \"$@\"\n+\texit 0\n+fi\n \n trap 'rm -f \"$tmp\"' 0 1 2 3 15\n tmp=`mktemp -t git-jump.XXXXXX` || exit 1\n-- \ngitgitgadget\n\n"},{"id":"468029","messageId":"e9aa6fdf836e620ac16ce6fbe429f29481c839ec.1669511933.git.gitgitgadget@gmail.com","threadId":"58820","inReplyTo":"pull.1423.v8.git.1669511933.gitgitgadget@gmail.com","subject":"[PATCH v8 2/3] git-jump: move valid-mode check earlier","fromName":"Jeff King via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2022-11-27T01:18:52Z","receivedAt":"2022-11-27T01:19:03Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"From: Jeff King <peff@peff.net>\n\nWe check if the \"mode\" argument supplied by the user is valid by seeing\nif we have a mode_$mode function defined. But we don't do that until\nafter creating the tempfile. This is wasteful (we create a tempfile but\nnever use it), and makes it harder to add new options (the recent stdout\noption exits before creating the tempfile, so it misses the check and\n\"git jump --stdout foo\" will produce \"git-jump: 92: mode_foo: not found\"\nrather than the regular usage message).\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n contrib/git-jump/git-jump | 3 ++-\n 1 file changed, 2 insertions(+), 1 deletion(-)\n\ndiff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump\nindex be0642bbe34..a5a8a77e20e 100755\n--- a/contrib/git-jump/git-jump\n+++ b/contrib/git-jump/git-jump\n@@ -88,6 +88,8 @@ if test $# -lt 1; then\n \texit 1\n fi\n mode=$1; shift\n+type \"mode_$mode\" >/dev/null 2>&1 || { usage >&2; exit 1; }\n+\n if test \"$use_stdout\" = \"t\"; then\n \t\"mode_$mode\" \"$@\"\n \texit 0\n@@ -95,7 +97,6 @@ fi\n \n trap 'rm -f \"$tmp\"' 0 1 2 3 15\n tmp=`mktemp -t git-jump.XXXXXX` || exit 1\n-type \"mode_$mode\" >/dev/null 2>&1 || { usage >&2; exit 1; }\n \"mode_$mode\" \"$@\" >\"$tmp\"\n test -s \"$tmp\" || exit 0\n open_editor \"$tmp\"\n-- \ngitgitgadget\n\n"},{"id":"468030","messageId":"048f508ca99409d8c023d12639ff9c6fc4550b2a.1669511933.git.gitgitgadget@gmail.com","threadId":"58820","inReplyTo":"pull.1423.v8.git.1669511933.gitgitgadget@gmail.com","subject":"[PATCH v8 3/3] git-jump: invoke emacs/emacsclient","fromName":"Yoichi Nakayama via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2022-11-27T01:18:53Z","receivedAt":"2022-11-27T01:19:05Z","isPatch":true,"sender":{"key":"yoichi.nakayama@gmail.com","avatar":"https://avatars.githubusercontent.com/u/107537?v=4"},"body":"From: Yoichi Nakayama <yoichi.nakayama@gmail.com>\n\nIt works with GIT_EDITOR=\"emacs\", \"emacsclient\" or \"emacsclient -t\"\n\nSigned-off-by: Yoichi Nakayama <yoichi.nakayama@gmail.com>\n---\n contrib/git-jump/git-jump | 17 ++++++++++++++++-\n 1 file changed, 16 insertions(+), 1 deletion(-)\n\ndiff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump\nindex a5a8a77e20e..40c4b0d1110 100755\n--- a/contrib/git-jump/git-jump\n+++ b/contrib/git-jump/git-jump\n@@ -23,7 +23,22 @@ EOF\n \n open_editor() {\n \teditor=`git var GIT_EDITOR`\n-\teval \"$editor -q \\$1\"\n+\tcase \"$editor\" in\n+\t*emacs*)\n+\t\t# Supported editor values are:\n+\t\t# - emacs\n+\t\t# - emacsclient\n+\t\t# - emacsclient -t\n+\t\t#\n+\t\t# Wait for completion of the asynchronously executed process\n+\t\t# to avoid race conditions in case of \"emacsclient\".\n+\t\teval \"$editor --eval \\\"(let ((buf (grep \\\\\\\"cat \\$1\\\\\\\"))) (pop-to-buffer buf) (select-frame-set-input-focus (selected-frame)) (while (get-buffer-process buf) (sleep-for 0.1)))\\\"\"\n+\t\t;;\n+\t*)\n+\t\t# assume anything else is vi-compatible\n+\t\teval \"$editor -q \\$1\"\n+\t\t;;\n+\tesac\n }\n \n mode_diff() {\n-- \ngitgitgadget\n"},{"id":"468062","messageId":"Y4RC3NZsiy5gXPoJ@coredump.intra.peff.net","threadId":"58820","inReplyTo":"221126.86h6ymmvyc.gmgdl@evledraar.gmail.com","subject":"Re: [PATCH v7 3/3] git-jump: invoke emacs/emacsclient","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2022-11-28T05:10:52Z","receivedAt":"2022-11-28T05:16:44Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sat, Nov 26, 2022 at 12:52:50AM +0100, Ævar Arnfjörð Bjarmason wrote:\n\n> > Second, there is a difficulty passing arbitrary arguments properly to\n> > Emacs Lisp properly.\n> > For example, your version will cause error with\n> >         git jump grep \"hello world\"\n> > My early patch was doing something similar. But the second problem was\n> > hard to deal with,\n> > so I switched to using a temporary file.\n> \n> To the extent that that's painful couldn't we write the grep expression\n> / arguments to the tempfile, then feed the tempfile to the ad-hoc elisp\n> code?\n> \n> It would then read it, get the argument to grep for, and we'd call (grep\n> that-argument).\n\nYou'd still need to quote the arguments, since you'll be reading\npotentially multiple arguments out of the bytestream of the file[1].\n\nIf you're not going to quote, the simplest thing is to generate the\nline-oriented output and read that.\n\nIf you are going to quote, then you don't need the tempfile at all. You\ncan shove the command into the eval, as if git-jump were run from emacs\ndirectly (but you want to use the --stdout mode introduced in this\nseries, and not the git commands directly, because of course they're\nnon-trivial).\n\nI showed how to do the quoting earlier in the thread. But it is ugly,\nand this tempfile hack should work (modulo the gross wait loop\nafterwards).\n\n-Peff\n\n[1] Of course you could have a stripped-down version that only greps and\n    only takes one argument, but then why are you using git-jump in the\n    first place?\n"},{"id":"468070","messageId":"b79a4852-1e20-2c9a-a91c-f1ea629af402@dunelm.org.uk","threadId":"58820","inReplyTo":"pull.1423.v8.git.1669511933.gitgitgadget@gmail.com","subject":"Re: [PATCH v8 0/3] git-jump: support Emacs","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2022-11-28T10:13:46Z","receivedAt":"2022-11-28T10:13:54Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"Hi Yoichi\n\nOn 27/11/2022 01:18, Yoichi NAKAYAMA via GitGitGadget wrote:\n> Add an optional argument 'stdout' to print the quickfix lines to standard\n> output. It can be used with M-x grep on Emacs.\n> \n> Detect emacsclient by GIT_EDITOR and invoke the function. Tested with\n> EDITOR=\"emacsclient\" and EDITOR=\"emacsclient -t\".\n\nI've tested this version and it addresses all of my previous concerns, \nthanks for working on it.\n\nBest Wishes\n\nPhillip\n\n> Jeff King (1):\n>    git-jump: move valid-mode check earlier\n> \n> Yoichi Nakayama (2):\n>    git-jump: add an optional argument '--stdout'\n>    git-jump: invoke emacs/emacsclient\n> \n>   contrib/git-jump/README   | 10 ++++++++-\n>   contrib/git-jump/git-jump | 45 ++++++++++++++++++++++++++++++++++++---\n>   2 files changed, 51 insertions(+), 4 deletions(-)\n> \n> \n> base-commit: eea7033409a0ed713c78437fc76486983d211e25\n> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1423%2Fyoichi%2Fgit-jump-emacs-support-v8\n> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1423/yoichi/git-jump-emacs-support-v8\n> Pull-Request: https://github.com/gitgitgadget/git/pull/1423\n> \n> Range-diff vs v7:\n> \n>   1:  446777d300d ! 1:  afface9b010 git-jump: add an optional argument '--stdout'\n>       @@ contrib/git-jump/git-jump: mode_ws() {\n>        +\tcase \"$1\" in\n>        +\t--stdout)\n>        +\t\tuse_stdout=t\n>       -+\t\tshift\n>        +\t\t;;\n>        +\t--*)\n>        +\t\tusage >&2\n>       @@ contrib/git-jump/git-jump: mode_ws() {\n>        +\t\tbreak\n>        +\t\t;;\n>        +\tesac\n>       ++\tshift\n>        +done\n>         if test $# -lt 1; then\n>         \tusage >&2\n>   2:  972d51888ba = 2:  e9aa6fdf836 git-jump: move valid-mode check earlier\n>   3:  d8233f96175 ! 3:  048f508ca99 git-jump: invoke emacs/emacsclient\n>       @@ contrib/git-jump/git-jump: EOF\n>        +\t\t#\n>        +\t\t# Wait for completion of the asynchronously executed process\n>        +\t\t# to avoid race conditions in case of \"emacsclient\".\n>       -+\t\teval \"$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)))\\\"\"\n>       ++\t\teval \"$editor --eval \\\"(let ((buf (grep \\\\\\\"cat \\$1\\\\\\\"))) (pop-to-buffer buf) (select-frame-set-input-focus (selected-frame)) (while (get-buffer-process buf) (sleep-for 0.1)))\\\"\"\n>        +\t\t;;\n>        +\t*)\n>        +\t\t# assume anything else is vi-compatible\n> \n"},{"id":"468071","messageId":"221128.86cz97mjdj.gmgdl@evledraar.gmail.com","threadId":"58820","inReplyTo":"Y4RC3NZsiy5gXPoJ@coredump.intra.peff.net","subject":"Re: [PATCH v7 3/3] git-jump: invoke emacs/emacsclient","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-28T10:54:20Z","receivedAt":"2022-11-28T11:03:11Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Mon, Nov 28 2022, Jeff King wrote:\n\n> On Sat, Nov 26, 2022 at 12:52:50AM +0100, Ævar Arnfjörð Bjarmason wrote:\n>\n>> > Second, there is a difficulty passing arbitrary arguments properly to\n>> > Emacs Lisp properly.\n>> > For example, your version will cause error with\n>> >         git jump grep \"hello world\"\n>> > My early patch was doing something similar. But the second problem was\n>> > hard to deal with,\n>> > so I switched to using a temporary file.\n>> \n>> To the extent that that's painful couldn't we write the grep expression\n>> / arguments to the tempfile, then feed the tempfile to the ad-hoc elisp\n>> code?\n>> \n>> It would then read it, get the argument to grep for, and we'd call (grep\n>> that-argument).\n>\n> You'd still need to quote the arguments, since you'll be reading\n> potentially multiple arguments out of the bytestream of the file[1].\n>\n> If you're not going to quote, the simplest thing is to generate the\n> line-oriented output and read that.\n>\n> If you are going to quote, then you don't need the tempfile at all. You\n> can shove the command into the eval, as if git-jump were run from emacs\n> directly (but you want to use the --stdout mode introduced in this\n> series, and not the git commands directly, because of course they're\n> non-trivial).\n>\n> I showed how to do the quoting earlier in the thread. But it is ugly,\n> and this tempfile hack should work (modulo the gross wait loop\n> afterwards).\n\nThanks, I'd missed\nhttps://lore.kernel.org/git/Y30a0ulfxyE7dnYi@coredump.intra.peff.net/\n\nI think the case where the temporary directory itself has spaces in it\nisn't worth worrying about.\n\nSo, all we'd need to worry about is getting the arguments to be grep'd\nto emacs.\n\nThat should be simpler & bug-free with some equivalent of\n\n     echo \"args\" >$tmpfile\n\nthen in Emacs, given some \"<tmpfile>\" variable:\n\n  (with-temp-buffer\n    (insert-file-contents <tempfile>)\n    (buffer-string)))\n\nWe'd then invoke M-x grep with that.\n\nI think getting rid of the tempfile isn't worth it, or worth worrying\nabout, what I was pointing out is that the implementation as it stands\nworks notably differently than if you invoked M-x grep itself.\n\nI.e. it doesn't do highlighting, and (I didn't note this before) if it\ntakes a while we'll \"hang\", if we had emacs itself invoke the \"git grep\"\nwe'd stream out grep results as they came in.\n"},{"id":"468111","messageId":"CAF5D8-ub3_R=tWZ7NKOg7azVqAsK+DXe_XWgh4gYbCWXQfm-wQ@mail.gmail.com","threadId":"58820","inReplyTo":"221128.86cz97mjdj.gmgdl@evledraar.gmail.com","subject":"Re: [PATCH v7 3/3] git-jump: invoke emacs/emacsclient","fromName":"Yoichi Nakayama","fromEmail":"yoichi.nakayama@gmail.com","sentAt":"2022-11-28T15:38:36Z","receivedAt":"2022-11-28T15:38:52Z","isPatch":true,"sender":{"key":"yoichi.nakayama@gmail.com","avatar":"https://avatars.githubusercontent.com/u/107537?v=4"},"body":"On Mon, Nov 28, 2022 at 8:03 PM Ævar Arnfjörð Bjarmason\n<avarab@gmail.com> wrote:\n> I think getting rid of the tempfile isn't worth it, or worth worrying\n> about, what I was pointing out is that the implementation as it stands\n> works notably differently than if you invoked M-x grep itself.\n>\n> I.e. it doesn't do highlighting, and (I didn't note this before) if it\n> takes a while we'll \"hang\", if we had emacs itself invoke the \"git grep\"\n> we'd stream out grep results as they came in.\n\nIn PATCH v8, we stopped imitating the grep function and\nchanged it to call the grep function.\n\nAbout the first problem,\nI still don't understand what you mean by highlighting problem.\nOn my environment, the \"*grep*\" buffer is colored\n(i.e. filnemame:line_number part on each line is colored).\n\nAbout the second problem,\nIf the \"hang\" is until writing to tempfile is completed, it is unavoidable\nas long as tempfile is used.\nIf the \"hang\" is no response from Emacs when \"cat tempfile\" takes a\nlong time, we can reduce the duration by detecting a change in\n(point-max) and exiting the loop.\n\n--\nYoichi NAKAYAMA\n"},{"id":"468132","messageId":"xmqqiliy64b1.fsf@gitster.g","threadId":"58820","inReplyTo":"b79a4852-1e20-2c9a-a91c-f1ea629af402@dunelm.org.uk","subject":"Re: [PATCH v8 0/3] git-jump: support Emacs","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-11-28T23:35:14Z","receivedAt":"2022-11-28T23:35:19Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Phillip Wood <phillip.wood123@gmail.com> writes:\n\n> Hi Yoichi\n>\n> On 27/11/2022 01:18, Yoichi NAKAYAMA via GitGitGadget wrote:\n>> Add an optional argument 'stdout' to print the quickfix lines to standard\n>> output. It can be used with M-x grep on Emacs.\n>> Detect emacsclient by GIT_EDITOR and invoke the function. Tested\n>> with\n>> EDITOR=\"emacsclient\" and EDITOR=\"emacsclient -t\".\n>\n> I've tested this version and it addresses all of my previous concerns,\n> thanks for working on it.\n\nThanks.\n"},{"id":"468207","messageId":"CAF5D8-vTmDEX1aF1a3hh_U81Zk=pUGbHQtgp69Zz4bPwZRq99A@mail.gmail.com","threadId":"58820","inReplyTo":"b79a4852-1e20-2c9a-a91c-f1ea629af402@dunelm.org.uk","subject":"Re: [PATCH v8 0/3] git-jump: support Emacs","fromName":"Yoichi Nakayama","fromEmail":"yoichi.nakayama@gmail.com","sentAt":"2022-11-29T21:05:43Z","receivedAt":"2022-11-29T21:06:02Z","isPatch":true,"sender":{"key":"yoichi.nakayama@gmail.com","avatar":"https://avatars.githubusercontent.com/u/107537?v=4"},"body":"Hi Phillip\n\nOn Mon, Nov 28, 2022 at 7:13 PM Phillip Wood <phillip.wood123@gmail.com> wrote:\n>\n> Hi Yoichi\n>\n> On 27/11/2022 01:18, Yoichi NAKAYAMA via GitGitGadget wrote:\n> > Add an optional argument 'stdout' to print the quickfix lines to standard\n> > output. It can be used with M-x grep on Emacs.\n> >\n> > Detect emacsclient by GIT_EDITOR and invoke the function. Tested with\n> > EDITOR=\"emacsclient\" and EDITOR=\"emacsclient -t\".\n>\n> I've tested this version and it addresses all of my previous concerns,\n> thanks for working on it.\n\nThank you for confirming.\nYour feedback has allowed us to refine the implementation.\n\n-- \nYoichi NAKAYAMA\n"}]}