mbox series

[v5,0/3] git-jump: support Emacs

Message ID pull.1423.v5.git.1669187053.gitgitgadget@gmail.com (mailing list archive)
Headers show
Series git-jump: support Emacs | expand

Message

John Passaro via GitGitGadget Nov. 23, 2022, 7:04 a.m. UTC
Add an optional argument 'stdout' to print the quickfix lines to standard
output. It can be used with M-x grep on Emacs.

Detect emacsclient by GIT_EDITOR and invoke the function. Tested with
EDITOR="emacsclient" and EDITOR="emacsclient -t".

Jeff King (1):
  git-jump: move valid-mode check earlier

Yoichi Nakayama (2):
  git-jump: add an optional argument '--stdout'
  git-jump: invoke emacs/emacsclient

 contrib/git-jump/README   | 10 ++++++++-
 contrib/git-jump/git-jump | 45 ++++++++++++++++++++++++++++++++++++---
 2 files changed, 51 insertions(+), 4 deletions(-)


base-commit: eea7033409a0ed713c78437fc76486983d211e25
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1423%2Fyoichi%2Fgit-jump-emacs-support-v5
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1423/yoichi/git-jump-emacs-support-v5
Pull-Request: https://github.com/gitgitgadget/git/pull/1423

Range-diff vs v4:

 1:  446777d300d = 1:  446777d300d git-jump: add an optional argument '--stdout'
 2:  2f0bffb484b ! 2:  972d51888ba git-jump: invoke emacs/emacsclient
     @@
       ## Metadata ##
     -Author: Yoichi Nakayama <yoichi.nakayama@gmail.com>
     +Author: Jeff King <peff@peff.net>
      
       ## Commit message ##
     -    git-jump: invoke emacs/emacsclient
     +    git-jump: move valid-mode check earlier
      
     -    It works with GIT_EDITOR="emacs", "emacsclient" or "emacsclient -t"
     +    We check if the "mode" argument supplied by the user is valid by seeing
     +    if we have a mode_$mode function defined. But we don't do that until
     +    after creating the tempfile. This is wasteful (we create a tempfile but
     +    never use it), and makes it harder to add new options (the recent stdout
     +    option exits before creating the tempfile, so it misses the check and
     +    "git jump --stdout foo" will produce "git-jump: 92: mode_foo: not found"
     +    rather than the regular usage message).
      
     -    Signed-off-by: Yoichi Nakayama <yoichi.nakayama@gmail.com>
     +    Signed-off-by: Jeff King <peff@peff.net>
      
       ## contrib/git-jump/git-jump ##
     -@@ contrib/git-jump/git-jump: open_editor() {
     - 	eval "$editor -q \$1"
     - }
     - 
     -+open_emacs() {
     -+	# Supported editor values are:
     -+	# - emacs
     -+	# - emacsclient
     -+	# - emacsclient -t
     -+	editor=`git var GIT_EDITOR`
     -+	# Wait for completion of the asynchronously executed process
     -+	# to avoid race conditions in case of "emacsclient".
     -+	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)))\""
     -+}
     +@@ contrib/git-jump/git-jump: if test $# -lt 1; then
     + 	exit 1
     + fi
     + mode=$1; shift
     ++type "mode_$mode" >/dev/null 2>&1 || { usage >&2; exit 1; }
      +
     - mode_diff() {
     - 	git diff --no-prefix --relative "$@" |
     - 	perl -ne '
     -@@ contrib/git-jump/git-jump: tmp=`mktemp -t git-jump.XXXXXX` || exit 1
     - type "mode_$mode" >/dev/null 2>&1 || { usage >&2; exit 1; }
     + if test "$use_stdout" = "t"; then
     + 	"mode_$mode" "$@"
     + 	exit 0
     +@@ contrib/git-jump/git-jump: 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
     -+if git var GIT_EDITOR | grep emacs >/dev/null; then
     -+	open_emacs "$tmp"
     -+	exit 0
     -+fi
       open_editor "$tmp"
 -:  ----------- > 3:  ad7c299cb0f git-jump: invoke emacs/emacsclient

Comments

Jeff King Nov. 24, 2022, 1:11 a.m. UTC | #1
On Wed, Nov 23, 2022 at 07:04:10AM +0000, Yoichi NAKAYAMA via GitGitGadget wrote:

> Add an optional argument 'stdout' to print the quickfix lines to standard
> output. It can be used with M-x grep on Emacs.
> 
> Detect emacsclient by GIT_EDITOR and invoke the function. Tested with
> EDITOR="emacsclient" and EDITOR="emacsclient -t".

Thanks, this version looks fine to me. I see your response to Phillip
may result in a v6 where the loop within the emacs code is moved, but I
have no opinion on that. :) So assuming that is the only change, my
review will still stand.

-Peff