@@ -336,19 +336,30 @@ Used for interactive selection one of them."
336336 (apply-partially #'pr-review--update-pr-title (alist-get 'id pr-review--pr-info))
337337 'refresh-after-exit )))
338338
339- (defun pr-review-view-file ()
340- " View the full file under current point (must in some diff)."
341- (interactive )
342- (pcase-let ((`(, side . (, filepath . , line )) (pr-review--get-diff-line-info (point ))))
343- (when (and side filepath line)
344- (let* ((content (pr-review--fetch-file filepath
345- (if (equal side " LEFT" ) 'base 'head )))
346- (tempfile (make-temp-file (if (equal side " LEFT" ) " BASE~" " HEAD~" )
347- nil
348- (concat " ~" (file-name-nondirectory filepath))
349- content)))
350- (with-current-buffer (find-file-other-window tempfile)
351- (goto-char (point-min ))
339+ (defun pr-review-view-file (head-or-base filepath &optional line )
340+ " View the full file content in a temporary buffer.
341+ By default, view the file under current point (must in some diff).
342+ When invoked with prefix, prompt for head-or-base and filepath."
343+ (interactive
344+ (let (head-or-base filepath line)
345+ (when-let* ((line-info (pr-review--get-diff-line-info (point ))))
346+ (setq head-or-base (if (equal (car line-info) " LEFT" ) 'base 'head )
347+ filepath (cadr line-info)
348+ line (cddr line-info)))
349+ (when (or current-prefix-arg (null head-or-base) (null filepath))
350+ (let ((res (completing-read " Ref: " '(" head" " base" ) nil t )))
351+ (setq head-or-base (intern res)))
352+ (setq filepath (read-from-minibuffer " File path: " filepath)))
353+ (list head-or-base filepath line)))
354+ (when (and head-or-base filepath)
355+ (let* ((content (pr-review--fetch-file filepath head-or-base))
356+ (tempfile (make-temp-file (concat (upcase (symbol-name head-or-base)) " ~" )
357+ nil
358+ (concat " ~" (file-name-nondirectory filepath))
359+ content)))
360+ (with-current-buffer (find-file-other-window tempfile)
361+ (goto-char (point-min ))
362+ (when line
352363 (forward-line (1- line)))))))
353364
354365(defun pr-review-open-in-default-browser ()
0 commit comments