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'
This commit is contained in:
Junio C Hamano 2022-12-14 15:55:46 +09:00
commit 06ae40f6e5
2 changed files with 51 additions and 4 deletions

View File

@ -79,6 +79,14 @@ 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 instead of feeding it to the editor. You can use the
argument with M-x grep on Emacs:
--------------------------------------------------
# In Emacs, M-x grep and invoke "git jump --stdout <mode>"
M-x grep<RET>git jump --stdout diff<RET>
--------------------------------------------------
Related Programs
----------------
@ -100,7 +108,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.

View File

@ -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,12 +15,30 @@ 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 instead of feeding it to the editor.
EOF
}
open_editor() {
editor=`git var GIT_EDITOR`
eval "$editor -q \$1"
case "$editor" in
*emacs*)
# Supported editor values are:
# - emacs
# - emacsclient
# - emacsclient -t
#
# Wait for completion of the asynchronously executed process
# to avoid race conditions in case of "emacsclient".
eval "$editor --eval \"(let ((buf (grep \\\"cat \$1\\\"))) (pop-to-buffer buf) (select-frame-set-input-focus (selected-frame)) (while (get-buffer-process buf) (sleep-for 0.1)))\""
;;
*)
# assume anything else is vi-compatible
eval "$editor -q \$1"
;;
esac
}
mode_diff() {
@ -64,15 +82,36 @@ mode_ws() {
git diff --check "$@"
}
use_stdout=
while test $# -gt 0; do
case "$1" in
--stdout)
use_stdout=t
;;
--*)
usage >&2
exit 1
;;
*)
break
;;
esac
shift
done
if test $# -lt 1; then
usage >&2
exit 1
fi
mode=$1; shift
type "mode_$mode" >/dev/null 2>&1 || { usage >&2; exit 1; }
if test "$use_stdout" = "t"; then
"mode_$mode" "$@"
exit 0
fi
trap 'rm -f "$tmp"' 0 1 2 3 15
tmp=`mktemp -t git-jump.XXXXXX` || exit 1
type "mode_$mode" >/dev/null 2>&1 || { usage >&2; exit 1; }
"mode_$mode" "$@" >"$tmp"
test -s "$tmp" || exit 0
open_editor "$tmp"