Function: diff-goto-source

diff-goto-source is an interactive and byte-compiled function defined in diff-mode.el.gz.

Signature

(diff-goto-source &optional OTHER-FILE EVENT)

Documentation

Jump to the corresponding source line.

diff-jump-to-old-file (or its opposite if the OTHER-FILE prefix arg is given) determines whether to jump to the old or the new file. If the prefix arg is bigger than 8 (for example with C-u (universal-argument) C-u (universal-argument)) then diff-jump-to-old-file is also set, for the next invocations.

Under version control, the OTHER-FILE prefix arg means jump to the old revision of the file if point is on an old changed line, or to the new revision of the file otherwise.

Probably introduced at or before Emacs version 27.1.

Key Bindings

Aliases

diff-mouse-goto-source

Source Code

;; Defined in /usr/src/emacs/lisp/vc/diff-mode.el.gz
(defun diff-goto-source (&optional other-file event)
  "Jump to the corresponding source line.
`diff-jump-to-old-file' (or its opposite if the OTHER-FILE prefix arg
is given) determines whether to jump to the old or the new file.
If the prefix arg is bigger than 8 (for example with \\[universal-argument] \\[universal-argument])
then `diff-jump-to-old-file' is also set, for the next invocations.

Under version control, the OTHER-FILE prefix arg means jump to the old
revision of the file if point is on an old changed line, or to the new
revision of the file otherwise."
  (interactive (list current-prefix-arg last-input-event))
  ;; When pointing at a removal line, we probably want to jump to
  ;; the old location, and else to the new (i.e. as if reverting).
  ;; This is a convenient detail when using smerge-diff.
  (if event (posn-set-point (event-end event)))
  (let ((buffer (when event (current-buffer)))
        (reverse (not (save-excursion (beginning-of-line) (looking-at "[-<]")))))
    (pcase-let ((`(,buf ,_line-offset ,pos ,src ,_dst ,_switched)
                 (diff-find-source-location other-file reverse)))
      (pop-to-buffer buf)
      (goto-char (+ (car pos) (cdr src)))
      (when buffer (next-error-found buffer (current-buffer))))))