This is a utility for navigating between changes in your repository, by opening a diff, and by navigating to the lines inside it.
Available via melpa.
See demo video.
When working on a task that touches multiple files, it's often useful to navigate between these changes.
diff-at-point-open-and-goto-hunk- Creates a diff for the current repository, navigating to the current point (where possible).
diff-at-point-goto-source-and-close- Go to the location at the point, closing the current diff buffer.
You may bind the functions to keys, in specific modes.
This is not a minor mode, instead, there are two main functions you can bind yourself:
Here are example bindings which use Ctrl-Alt-Return.
(add-hook 'diff-mode-hook
(lambda ()
(define-key diff-mode-shared-map (kbd "<C-M-return>") 'diff-at-point-goto-source-and-close)))
(add-hook 'prog-mode-hook
(lambda ()
(define-key prog-mode-map (kbd "<C-M-return>") 'diff-at-point-open-and-goto-hunk)))Or you can use a global binding which checks the major mode.
(global-set-key (kbd "<C-M-return>")
(lambda () (interactive)
(cond
((string= major-mode "diff-mode")
(diff-at-point-goto-source-and-close))
(t
(diff-at-point-open-and-goto-hunk)))))diff-at-point-diff-commandThis is the function used to create the diff buffer.
While there is no need to change this value from it's default (calling
vc-root-diff) it can be overridden for different behavior.This example shows how Emacs 27's
vc-root-version-diffcan be used to diff the working copy against a branch instead ofHEADof a git repository.(define-key prog-mode-map (kbd "<C-M-return>") '(lambda () (interactive) (let ((diff-at-point-diff-command '(lambda () (vc-root-version-diff nil "main" nil)))) (diff-at-point-open-and-goto-hunk))))