Function: majutsu-diff-visit-file

majutsu-diff-visit-file is an interactive and natively compiled function defined in majutsu-diff.el.

Signature

(majutsu-diff-visit-file &optional FORCE-WORKSPACE)

Documentation

From a diff, visit the appropriate version of the file at point.

If point is on an added or context line, visit the new/right side. If point is on a removed line, visit the old/left side.

For diffs of the working copy (@), this visits the actual file in the workspace. For diffs of committed changes, this visits the blob from the appropriate revision.

With prefix argument FORCE-WORKSPACE, always visit the workspace file regardless of what the diff is about.

Key Bindings

This command is not in any keymaps.

Source Code

;; Defined in /nix/store/jagqw3nms546pad0gxi5f3wsckk6pji7-emacs-packages-deps/share/emacs/site-lisp/majutsu-diff.el
;;;###autoload
(defun majutsu-diff-visit-file (&optional force-workspace)
  "From a diff, visit the appropriate version of the file at point.

If point is on an added or context line, visit the new/right side.
If point is on a removed line, visit the old/left side.

For diffs of the working copy (@), this visits the actual file in
the workspace.  For diffs of committed changes, this visits the
blob from the appropriate revision.

With prefix argument FORCE-WORKSPACE, always visit the workspace file
regardless of what the diff is about."
  (interactive "P")
  (let* ((section (magit-current-section))
         (file (majutsu-file-at-point))
         (backend (majutsu-diff--sync-backend))
         (line-info (and (eq backend 'color-words)
                         (majutsu-diff--color-words-line-info))))
    (unless file
      (user-error "No file at point"))
    (let* ((revs (majutsu-diff--revisions))
           (goto-from (if line-info
                          (majutsu-diff--color-words-goto-from line-info)
                        (and section (magit-section-match 'jj-hunk section)
                             (majutsu-diff--on-removed-line-p))))
           (target-rev (if goto-from (car revs) (cdr revs)))
           (goto-workspace (or force-workspace
                               (and (majutsu-diff--visit-workspace-p)
                                    (not goto-from))))
           (line (cond
                  (line-info
                   (or (and goto-from (plist-get line-info :from-line))
                       (plist-get line-info :to-line)
                       (plist-get line-info :from-line)))
                  ((and section (magit-section-match 'jj-hunk section))
                   (majutsu-diff--hunk-line section goto-from))))
           (col (cond
                 (line-info (majutsu-diff--color-words-column line-info goto-from))
                 ((and section (magit-section-match 'jj-hunk section))
                  (majutsu-diff--hunk-column section goto-from)))))
      (if goto-workspace
          ;; Visit workspace file
          (let ((full-path (expand-file-name file default-directory)))
            (if (file-exists-p full-path)
                (progn
                  (find-file full-path)
                  (when (and line col)
                    (goto-char (point-min))
                    (forward-line (1- line))
                    (move-to-column col)))
              (user-error "File does not exist in workspace: %s" file)))
        ;; Visit blob from appropriate revision
        (let ((buf (majutsu-find-file target-rev file)))
          (when (and buf line col)
            (majutsu-diff--goto-line-col buf line col)))))))