Skip to content

Commit 06ae40f

Browse files
committed
Merge branch 'yn/git-jump-emacs'
"git jump" (in contrib/) learned to present the "quickfix list" to its standard output (instead of letting it consumed by the editor it invokes), and learned to also drive emacs/emacsclient. * yn/git-jump-emacs: git-jump: invoke emacs/emacsclient git-jump: move valid-mode check earlier git-jump: add an optional argument '--stdout'
2 parents 9ea1378 + 9508dfd commit 06ae40f

File tree

2 files changed

+51
-4
lines changed

2 files changed

+51
-4
lines changed

contrib/git-jump/README

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ git jump grep -i foo_bar
7979
git config jump.grepCmd "ag --column"
8080
--------------------------------------------------
8181

82+
You can use the optional argument '--stdout' to print the listing to
83+
standard output instead of feeding it to the editor. You can use the
84+
argument with M-x grep on Emacs:
85+
86+
--------------------------------------------------
87+
# In Emacs, M-x grep and invoke "git jump --stdout <mode>"
88+
M-x grep<RET>git jump --stdout diff<RET>
89+
--------------------------------------------------
8290

8391
Related Programs
8492
----------------
@@ -100,7 +108,7 @@ Limitations
100108
-----------
101109

102110
This script was written and tested with vim. Given that the quickfix
103-
format is the same as what gcc produces, I expect emacs users have a
111+
format is the same as what gcc produces, I expect other tools have a
104112
similar feature for iterating through the list, but I know nothing about
105113
how to activate it.
106114

contrib/git-jump/git-jump

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
usage() {
44
cat <<\EOF
5-
usage: git jump <mode> [<args>]
5+
usage: git jump [--stdout] <mode> [<args>]
66
77
Jump to interesting elements in an editor.
88
The <mode> parameter is one of:
@@ -15,12 +15,30 @@ grep: elements are grep hits. Arguments are given to git grep or, if
1515
configured, to the command in `jump.grepCmd`.
1616
1717
ws: elements are whitespace errors. Arguments are given to diff --check.
18+
19+
If the optional argument `--stdout` is given, print the quickfix
20+
lines to standard output instead of feeding it to the editor.
1821
EOF
1922
}
2023

2124
open_editor() {
2225
editor=`git var GIT_EDITOR`
23-
eval "$editor -q \$1"
26+
case "$editor" in
27+
*emacs*)
28+
# Supported editor values are:
29+
# - emacs
30+
# - emacsclient
31+
# - emacsclient -t
32+
#
33+
# Wait for completion of the asynchronously executed process
34+
# to avoid race conditions in case of "emacsclient".
35+
eval "$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)))\""
36+
;;
37+
*)
38+
# assume anything else is vi-compatible
39+
eval "$editor -q \$1"
40+
;;
41+
esac
2442
}
2543

2644
mode_diff() {
@@ -64,15 +82,36 @@ mode_ws() {
6482
git diff --check "$@"
6583
}
6684

85+
use_stdout=
86+
while test $# -gt 0; do
87+
case "$1" in
88+
--stdout)
89+
use_stdout=t
90+
;;
91+
--*)
92+
usage >&2
93+
exit 1
94+
;;
95+
*)
96+
break
97+
;;
98+
esac
99+
shift
100+
done
67101
if test $# -lt 1; then
68102
usage >&2
69103
exit 1
70104
fi
71105
mode=$1; shift
106+
type "mode_$mode" >/dev/null 2>&1 || { usage >&2; exit 1; }
107+
108+
if test "$use_stdout" = "t"; then
109+
"mode_$mode" "$@"
110+
exit 0
111+
fi
72112

73113
trap 'rm -f "$tmp"' 0 1 2 3 15
74114
tmp=`mktemp -t git-jump.XXXXXX` || exit 1
75-
type "mode_$mode" >/dev/null 2>&1 || { usage >&2; exit 1; }
76115
"mode_$mode" "$@" >"$tmp"
77116
test -s "$tmp" || exit 0
78117
open_editor "$tmp"

0 commit comments

Comments
 (0)