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.
By default, jump to the new source file.
With a prefix argument (when called from Lisp, with optional argument
OTHER-FILE non-nil), jump to the old source file.
If diff-jump-to-old-file is non-nil then the meaning of the prefix
argument (or, when called from Lisp, the meaning of optional argument
OTHER-FILE) is reversed: a prefix argument (respectively, OTHER-FILE
non-nil) means to jump to the new source file, and the lack of one
(respectively, OTHER-FILE nil) means to jump to the old source file.
In addition, if you supply a prefix argument bigger than 8 (for example
with C-u (universal-argument) C-u (universal-argument)), the value of diff-jump-to-old-file is toggled for the
remainder of this Emacs session (i.e., set to non-nil if nil, or
set to nil if non-nil). When called from Lisp this toggling
happens when the value of optional argument OTHER-FILE considered
as a prefix argument has a numeric value bigger than 8.
Under version control, jumping to the old file means jumping to the old
revision of the file in the manner of C-x v ~ (vc-revision-other-window), and occurs only when
point is on an old changed line (i.e. a removed line).
Probably introduced at or before Emacs version 27.1.
Key Bindings
Aliases
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.
By default, jump to the new source file.
With a prefix argument (when called from Lisp, with optional argument
OTHER-FILE non-nil), jump to the old source file.
If `diff-jump-to-old-file' is non-nil then the meaning of the prefix
argument (or, when called from Lisp, the meaning of optional argument
OTHER-FILE) is reversed: a prefix argument (respectively, OTHER-FILE
non-nil) means to jump to the new source file, and the lack of one
(respectively, OTHER-FILE nil) means to jump to the old source file.
In addition, if you supply a prefix argument bigger than 8 (for example
with \\[universal-argument] \\[universal-argument]), \
the value of `diff-jump-to-old-file' is toggled for the
remainder of this Emacs session (i.e., set to non-nil if nil, or
set to nil if non-nil). When called from Lisp this toggling
happens when the value of optional argument OTHER-FILE considered
as a prefix argument has a numeric value bigger than 8.
Under version control, jumping to the old file means jumping to the old
revision of the file in the manner of \\[vc-revision-other-window], \
and occurs only when
point is on an old changed line (i.e. a removed line)."
(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))))))