Re: [PATCH v4 2/2] git-jump: invoke emacs/emacsclient

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Yoichi

On 22/11/2022 14:18, Yoichi Nakayama via GitGitGadget wrote:
From: Yoichi Nakayama <yoichi.nakayama@xxxxxxxxx>

It works with GIT_EDITOR="emacs", "emacsclient" or "emacsclient -t"

Thanks for working on this, I'm looking forward to being able to use "git jump" with emacs.

Signed-off-by: Yoichi Nakayama <yoichi.nakayama@xxxxxxxxx>
---
  contrib/git-jump/git-jump | 15 +++++++++++++++
  1 file changed, 15 insertions(+)

diff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump
index babb3b5c68d..bfd759aa4b2 100755
--- a/contrib/git-jump/git-jump
+++ b/contrib/git-jump/git-jump
@@ -26,6 +26,17 @@ 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)))\""

I just tried this out in a frame (window for non emacs users) showing two files and the (delete-other-windows) call replaced both of them with the grep buffer. It would be nicer if it created a new window in the current frame or showed the grep buffer in one of the existing windows. If I delete (delete-other-windows) then the first time I run "git jump" it shows the grep buffer in the frame I already have open, but then if I run it again without closing the grep buffer it opens a new frame. I wonder if it would be better just to close the buffer if it exists before creating the new one or pass NAME-FUNCTION argument to compilation-start that creates unique names.

I'm using emacsclient as my editor and when I run "git jump" it prints

#<buffer *grep*>

in the terminal (presumably because that is the return value of select-frame-set-input-focus)

Could we read the file and set the buffer's mode to grep-mode (or compilation-mode?) without forking cat?

Best Wishes

Phillip

+}
+
  mode_diff() {
  	git diff --no-prefix --relative "$@" |
  	perl -ne '
@@ -98,4 +109,8 @@ 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"



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux