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 (usually: in a *vc-diff* buffer), by default jump to the version of the file in the working tree. This version of the file may be unrelated to the diff's old and new revisions. With a prefix argument (when called from Lisp, with optional argument OTHER-FILE non-nil), jump to source code corresponding to one of the diff's old or new revisions as follows:
- if point is on an old changed line (i.e. a removed line),
  jump to the old source file in the manner of C-x v ~ (vc-revision-other-window)
- otherwise, jump to the new source file,
  either by visiting the version of the file in the working tree
  (when the new source file is the working tree's),
  or in the manner of C-x v ~.
diff-jump-to-old-file non-nil and a prefix argument bigger than 8 are as above.

View in manual

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.

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 (usually: in a *vc-diff* buffer), by default jump
to the version of the file in the working tree.  This version of the
file may be unrelated to the diff's old and new revisions.
With a prefix argument (when called from Lisp, with optional argument
OTHER-FILE non-nil), jump to source code corresponding to one of the
diff's old or new revisions as follows:
- if point is on an old changed line (i.e. a removed line),
  jump to the old source file in the manner of \\[vc-revision-other-window]
- otherwise, jump to the new source file,
  either by visiting the version of the file in the working tree
  (when the new source file is the working tree's),
  or in the manner of \\[vc-revision-other-window].
`diff-jump-to-old-file' non-nil and a prefix argument bigger than 8 are
as above."
  (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))))))