diff options
author | Junio C Hamano <gitster@pobox.com> | 2022-12-14 09:55:46 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2022-12-14 09:55:46 +0300 |
commit | 06ae40f6e5f4a216b336088f1f513fbfb75e8b98 (patch) | |
tree | 9b91d1f7767f0292781b27c0bab4868c3a9a3836 /contrib | |
parent | 9ea1378d046d764642718f1b070689072bde4601 (diff) | |
parent | 9508dfd9f553019c2e3b2869926a0dcaed7a498f (diff) |
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'
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/git-jump/README | 10 | ||||
-rwxr-xr-x | contrib/git-jump/git-jump | 45 |
2 files changed, 51 insertions, 4 deletions
diff --git a/contrib/git-jump/README b/contrib/git-jump/README index 8bcace29d2..3211841305 100644 --- a/contrib/git-jump/README +++ b/contrib/git-jump/README @@ -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. diff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump index 92dbd4cde1..40c4b0d111 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,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" |