diff mbox series

[v2,1/2] git-jump: add an optional argument 'stdout'

Message ID e56858a3eb212dcd0b8f71bdbf8db96f51c5d648.1668907644.git.gitgitgadget@gmail.com (mailing list archive)
State Superseded
Headers show
Series git-jump: support Emacs | expand

Commit Message

Yoichi Nakayama Nov. 20, 2022, 1:27 a.m. UTC
From: Yoichi Nakayama <yoichi.nakayama@gmail.com>

It can be used with M-x grep on Emacs.

Signed-off-by: Yoichi Nakayama <yoichi.nakayama@gmail.com>
---
 contrib/git-jump/README   |  9 ++++++++-
 contrib/git-jump/git-jump | 11 ++++++++++-
 2 files changed, 18 insertions(+), 2 deletions(-)

Comments

Junio C Hamano Nov. 21, 2022, 5:43 a.m. UTC | #1
"Yoichi Nakayama via GitGitGadget" <gitgitgadget@gmail.com> writes:

> +You can use the optional argument 'stdout' to print the listing to
> +standard output. You can use it with M-x grep on Emacs.

It is unclear what happens when you do not give 'stdout' from the
above description.  You say 'stdout' is a way to tell the command
"to print the listing to standard output", but what is expected to
follow that sentence is left unsaid (i.e. "you can give 'stdout' to
print to stdout, INSTEAD OF DOING X").

Also, 

> +--------------------------------------------------
> +# In Emacs, M-x grep and invoke "git jump stdout <mode>"
> +Run grep (like this): git jump stdout diff

the command line structure of "git jump" being

    git jump <mode> [<args>]

where <mode> is one of 'diff', 'merge', 'grep', it somehow feels
very strange to insert an optional new word, that is not a dashed
option, before the <mode>.  "git jump --stdout diff" might be less
surprising, but I dunno.

But I think this is a good idea.  In fact, it almost feels that the
interface to produce the list of "$file:$line: <blah>" that this
"stdout" mode gives should have been in the command as the lowest
level basic primitive, upon which the feature to drive a specific
editor using such an output file should have been built, and the
current code is backwards in that sense.  Exposing that lower level
primitive directly is a welcome addition.
Yoichi Nakayama Nov. 21, 2022, 11:25 a.m. UTC | #2
On Mon, Nov 21, 2022 at 2:43 PM Junio C Hamano <gitster@pobox.com> wrote:
>
> "Yoichi Nakayama via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
> > +You can use the optional argument 'stdout' to print the listing to
> > +standard output. You can use it with M-x grep on Emacs.
>
> It is unclear what happens when you do not give 'stdout' from the
> above description.  You say 'stdout' is a way to tell the command
> "to print the listing to standard output", but what is expected to
> follow that sentence is left unsaid (i.e. "you can give 'stdout' to
> print to stdout, INSTEAD OF DOING X").

I agree. I'll add "instead of feeding it to the editor".

> > +# In Emacs, M-x grep and invoke "git jump stdout <mode>"
> > +Run grep (like this): git jump stdout diff
>
> the command line structure of "git jump" being
>
>     git jump <mode> [<args>]
>
> where <mode> is one of 'diff', 'merge', 'grep', it somehow feels
> very strange to insert an optional new word, that is not a dashed
> option, before the <mode>.  "git jump --stdout diff" might be less
> surprising, but I dunno.
>
> But I think this is a good idea.  In fact, it almost feels that the
> interface to produce the list of "$file:$line: <blah>" that this
> "stdout" mode gives should have been in the command as the lowest
> level basic primitive, upon which the feature to drive a specific
> editor using such an output file should have been built, and the
> current code is backwards in that sense.  Exposing that lower level
> primitive directly is a welcome addition.

Thank you for your thoughtful consideration.
The value of git-jump is to launch the editor quickly from the command line.
I think it's rare to manually use the additional option (e.g. M-x grep
in Emacs).
Therefore, I think there is not much needs to expose it directly.
I'll change it to less surprising form "--stdout".
Jeff King Nov. 21, 2022, 6:18 p.m. UTC | #3
On Mon, Nov 21, 2022 at 02:43:51PM +0900, Junio C Hamano wrote:

> the command line structure of "git jump" being
> 
>     git jump <mode> [<args>]
> 
> where <mode> is one of 'diff', 'merge', 'grep', it somehow feels
> very strange to insert an optional new word, that is not a dashed
> option, before the <mode>.  "git jump --stdout diff" might be less
> surprising, but I dunno.

FWIW, I had the same reaction: it should be --stdout.

> But I think this is a good idea.  In fact, it almost feels that the
> interface to produce the list of "$file:$line: <blah>" that this
> "stdout" mode gives should have been in the command as the lowest
> level basic primitive, upon which the feature to drive a specific
> editor using such an output file should have been built, and the
> current code is backwards in that sense.  Exposing that lower level
> primitive directly is a welcome addition.

The main reason I didn't start with that primitive is because the
initial outputs were pretty simple and based around "grep -n" output.
But they've gotten a bit more complicated over time, especially the
"diff" one. I agree that just dumping the quickfix list is a good
feature to have.

-Peff
diff mbox series

Patch

diff --git a/contrib/git-jump/README b/contrib/git-jump/README
index 8bcace29d21..6aaa6a928d2 100644
--- a/contrib/git-jump/README
+++ b/contrib/git-jump/README
@@ -79,6 +79,13 @@  git jump grep -i foo_bar
 git config jump.grepCmd "ag --column"
 --------------------------------------------------
 
+You can use the optional argument 'stdout' to print the listing to
+standard output. You can use it with M-x grep on Emacs.
+
+--------------------------------------------------
+# In Emacs, M-x grep and invoke "git jump stdout <mode>"
+Run grep (like this): git jump stdout diff
+--------------------------------------------------
 
 Related Programs
 ----------------
@@ -100,7 +107,7 @@  Limitations
 -----------
 
 This script was written and tested with vim. Given that the quickfix
-format is the same as what gcc produces, I expect emacs users have a
+format is the same as what gcc produces, I expect other tools have a
 similar feature for iterating through the list, but I know nothing about
 how to activate it.
 
diff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump
index 92dbd4cde18..a907f69304d 100755
--- a/contrib/git-jump/git-jump
+++ b/contrib/git-jump/git-jump
@@ -2,7 +2,7 @@ 
 
 usage() {
 	cat <<\EOF
-usage: git jump <mode> [<args>]
+usage: git jump [stdout] <mode> [<args>]
 
 Jump to interesting elements in an editor.
 The <mode> parameter is one of:
@@ -15,6 +15,9 @@  grep: elements are grep hits. Arguments are given to git grep or, if
       configured, to the command in `jump.grepCmd`.
 
 ws: elements are whitespace errors. Arguments are given to diff --check.
+
+If the optional argument `stdout` is given, print the quickfix
+lines to standard output.
 EOF
 }
 
@@ -69,6 +72,12 @@  if test $# -lt 1; then
 	exit 1
 fi
 mode=$1; shift
+if test "$mode" = "stdout"; then
+	mode=$1; shift
+	type "mode_$mode" >/dev/null 2>&1 || { usage >&2; exit 1; }
+	"mode_$mode" "$@" 2>/dev/null
+	exit 0
+fi
 
 trap 'rm -f "$tmp"' 0 1 2 3 15
 tmp=`mktemp -t git-jump.XXXXXX` || exit 1