0

Id like to use a diff on my repository to quickly navigate changes, without keeping the buffer open.

Is it possible to make a function that runs 'Jump to source', and deletes the diff buffer?

(Am looking to make a key-binding, but expect this will involve writing a function)

  • Do you want (delete-window) or (kill-buffer)? Both of those functions take arguments so that it is not necessary to be in the target while closing the window or killing the buffer. Look at the tail end of your Jump to source function and see if there is a hook, if so, consider using it. [You can use M-x find-function to locate the source code.] If not, consider creating a new function incorporating either or both of the above-mentioned functions. – lawlist Dec 29 '16 at 17:31
  • By default a split is opened, I wanted the split to be removed and the buffer deleted. – ideasman42 Dec 29 '16 at 17:38
  • If you look inside diff-goto-source you will see (pop-to-buffer buf), which is the source of your pain. Consider changing that to switch-to-buffer or set-window-buffer. See the doc-strings for each function to see what arguments are applicable. – lawlist Dec 29 '16 at 17:42
  • Does this mean maintaining a modified emacs? - or can this be done from the emacs config file? (monkey patch for eg) – ideasman42 Dec 29 '16 at 17:45
  • It's really up to whether you want to create a new function called my-diff-goto-source and rebind the keyboard shortcut to your new function. Or, you could do something like (require 'diff-mode) (defun diff-goto-source (&optional other-file event) ....) and redefine it in your init.el. If you want to save a split second loading Emacs, consider using eval-after-load to redefine the function. If you want to get really fancy, perhaps you could play with advice. Or, you could use cl-letf to redefine pop-to-buffer temporarily. Or, you could modifying the behavior of pop-to-buffer. – lawlist Dec 29 '16 at 17:55
2

Here are 2 functions I came up with that open a fullscreen diff and close it when jumping to the line.

;; Override pop-up-windows
(defun diff-goto-source-and-close ()
  "Go to the source and close the current diff buffer."
  (interactive)
  (let ((buf (current-buffer))
        (pop-up-windows nil))
    (diff-goto-source)
    (kill-buffer buf)))

(defun vc-root-diff-fullscreen ()
  "Open a diff of the repository in the current frame."
  (interactive)
  (let ((pop-up-windows nil))
    (call-interactively 'vc-root-diff)))

Notes:

  • pop-up-windows needed to be set so the window isn't opened in a split, for both opening the diff and switching to the buffer.
  • vc-root-diff is used to get a diff on the entire project (not just the current file).
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.