Function: magit-diff-show-or-scroll

magit-diff-show-or-scroll is a byte-compiled function defined in magit-diff.el.

Signature

(magit-diff-show-or-scroll FN)

Source Code

;; Defined in ~/.emacs.d/elpa/magit-20260411.1452/magit-diff.el
(defun magit-diff-show-or-scroll (fn)
  (let (rev cmd buf)
    (cond
      ((and (bound-and-true-p magit-blame-mode)
            (fboundp 'magit-current-blame-chunk))
       (setq rev (oref (magit-current-blame-chunk) orig-rev))
       (setq cmd #'magit-show-commit)
       (setq buf (magit-get-mode-buffer 'magit-revision-mode)))
      ((derived-mode-p 'git-rebase-mode)
       (with-slots (action-type target)
           (git-rebase-current-line)
         (if (not (eq action-type 'commit))
             (user-error "No commit on this line")
           (setq rev target)
           (setq cmd #'magit-show-commit)
           (setq buf (magit-get-mode-buffer 'magit-revision-mode)))))
      ((magit-section-case
         (branch
          (setq rev (magit-ref-maybe-qualify (oref it value)))
          (setq cmd #'magit-show-commit)
          (setq buf (magit-get-mode-buffer 'magit-revision-mode)))
         (commit
          (setq rev (oref it value))
          (setq cmd #'magit-show-commit)
          (setq buf (magit-get-mode-buffer 'magit-revision-mode)))
         (tag
          (setq rev (magit-commit-oid (oref it value)))
          (setq cmd #'magit-show-commit)
          (setq buf (magit-get-mode-buffer 'magit-revision-mode)))
         (stash
          (setq rev (oref it value))
          (setq cmd #'magit-stash-show)
          (setq buf (magit-get-mode-buffer 'magit-stash-mode))))))
    (cond-let*
      ((not rev)
       (call-interactively #'magit-show-commit))
      ([_ buf]
       [win (get-buffer-window buf)]
       [_ (equal (buffer-local-value 'magit-buffer-revision buf) rev)]
       [_ (equal (buffer-local-value 'magit-buffer-revision-oid buf)
                 (magit-rev-parse rev))]
       (with-selected-window win
         (condition-case nil
             (funcall fn)
           (error
            (pcase-exhaustive fn
              ('scroll-up   (goto-char (point-min)))
              ('scroll-down (goto-char (point-max))))))))
      [[magit-display-buffer-noselect t]]
      ((eq cmd #'magit-show-commit)
       (apply #'magit-show-commit rev (magit-show-commit--arguments)))
      ((funcall cmd rev)))))