branch: elpa/magit
commit aa77ce625d602d4409ef844e3a4973c02da4cfd7
Author: Jonas Bernoulli <[email protected]>
Commit: Jonas Bernoulli <[email protected]>

    magit-diff-visit-file-*: Remove FILE argument
---
 lisp/magit-apply.el  |  3 +-
 lisp/magit-diff.el   | 86 +++++++++++++++++++++++++---------------------------
 lisp/magit-extras.el |  6 ++--
 3 files changed, 46 insertions(+), 49 deletions(-)

diff --git a/lisp/magit-apply.el b/lisp/magit-apply.el
index 30dafc2bc48..3115655892d 100644
--- a/lisp/magit-apply.el
+++ b/lisp/magit-apply.el
@@ -800,7 +800,8 @@ a separate commit.  A typical workflow would be:
 (defun magit-call-smerge (fn)
   (pcase-let* ((file (magit-file-at-point t t))
                (keep (get-file-buffer file))
-               (`(,buf ,pos) (magit-diff-visit-file--noselect file)))
+               (`(,buf ,pos) (magit-diff-visit-file--noselect))
+               (keep (eq keep buf)))
     (with-current-buffer buf
       (save-excursion
         (save-restriction
diff --git a/lisp/magit-diff.el b/lisp/magit-diff.el
index 00243ecdc88..95aff854db6 100644
--- a/lisp/magit-diff.el
+++ b/lisp/magit-diff.el
@@ -80,7 +80,7 @@
                   (&optional whoami file-name other-window))
 (declare-function magit-add-change-log-entry-other-window "magit-extras"
                   (&optional whoami file-name))
-(declare-function magit-diff-edit-hunk-commit "magit-extras" (file))
+(declare-function magit-diff-edit-hunk-commit "magit-extras" ())
 (declare-function magit-smerge-keep-current "magit-apply" ())
 (declare-function magit-smerge-keep-all "magit-apply" ())
 (declare-function magit-smerge-keep-upper "magit-apply" ())
@@ -1616,8 +1616,8 @@ Customize variable `magit-diff-refine-hunk' to change the 
default mode."
 ;;;; Visit Commands
 ;;;;; Dwim Variants
 
-(defun magit-diff-visit-file (file &optional other-window)
-  "From a diff visit the appropriate version of FILE.
+(defun magit-diff-visit-file (&optional other-window)
+  "From a diff visit a version of the file at point.
 
 Display the buffer in the selected window.  With a prefix
 argument OTHER-WINDOW display the buffer in another window
@@ -1647,30 +1647,28 @@ to the line that point is on in the diff.
 
 Note that this command only works if point is inside a diff.
 In other cases `magit-find-file' (which see) has to be used."
-  (interactive (list (magit-diff--file-at-point t t) current-prefix-arg))
-  (magit-diff-visit-file--internal file nil
+  (interactive "P")
+  (magit-diff-visit-file--internal nil
                                    (if other-window
                                        #'switch-to-buffer-other-window
                                      #'pop-to-buffer-same-window)))
 
-(defun magit-diff-visit-file-other-window (file)
-  "From a diff visit the appropriate version of FILE in another window.
-Like `magit-diff-visit-file' but use
-`switch-to-buffer-other-window'."
-  (interactive (list (magit-diff--file-at-point t t)))
-  (magit-diff-visit-file--internal file nil #'switch-to-buffer-other-window))
+(defun magit-diff-visit-file-other-window ()
+  "From a diff visit a version of the file at point in another window.
+Like `magit-diff-visit-file' but always display in another window."
+  (interactive)
+  (magit-diff-visit-file--internal nil #'switch-to-buffer-other-window))
 
-(defun magit-diff-visit-file-other-frame (file)
-  "From a diff visit the appropriate version of FILE in another frame.
-Like `magit-diff-visit-file' but use
-`switch-to-buffer-other-frame'."
-  (interactive (list (magit-diff--file-at-point t t)))
-  (magit-diff-visit-file--internal file nil #'switch-to-buffer-other-frame))
+(defun magit-diff-visit-file-other-frame ()
+  "From a diff visit a version of the file at point in another frame.
+Like `magit-diff-visit-file' but always display in another frame."
+  (interactive)
+  (magit-diff-visit-file--internal nil #'switch-to-buffer-other-frame))
 
 ;;;;; Worktree Variants
 
-(defun magit-diff-visit-worktree-file (file &optional other-window)
-  "From a diff visit the worktree version of FILE.
+(defun magit-diff-visit-worktree-file (&optional other-window)
+  "From a diff visit the worktree version of the file at point.
 
 Display the buffer in the selected window.  With a prefix
 argument OTHER-WINDOW display the buffer in another window
@@ -1686,40 +1684,39 @@ In the file-visiting buffer also go to the line that 
corresponds
 to the line that point is on in the diff.  Lines that were added
 or removed in the working tree, the index and other commits in
 between are automatically accounted for."
-  (interactive (list (magit-file-at-point t t) current-prefix-arg))
-  (magit-diff-visit-file--internal file t
+  (interactive "P")
+  (magit-diff-visit-file--internal t
                                    (if other-window
                                        #'switch-to-buffer-other-window
                                      #'pop-to-buffer-same-window)))
 
-(defun magit-diff-visit-worktree-file-other-window (file)
-  "From a diff visit the worktree version of FILE in another window.
-Like `magit-diff-visit-worktree-file' but use
-`switch-to-buffer-other-window'."
-  (interactive (list (magit-file-at-point t t)))
-  (magit-diff-visit-file--internal file t #'switch-to-buffer-other-window))
+(defun magit-diff-visit-worktree-file-other-window ()
+  "From a diff visit the file at point in another window.
+Like `magit-diff-visit-worktree-file' but display in another window."
+  (interactive)
+  (magit-diff-visit-file--internal t #'switch-to-buffer-other-window))
 
-(defun magit-diff-visit-worktree-file-other-frame (file)
-  "From a diff visit the worktree version of FILE in another frame.
-Like `magit-diff-visit-worktree-file' but use
-`switch-to-buffer-other-frame'."
-  (interactive (list (magit-file-at-point t t)))
-  (magit-diff-visit-file--internal file t #'switch-to-buffer-other-frame))
+(defun magit-diff-visit-worktree-file-other-frame ()
+  "From a diff visit the file at point in another frame.
+Like `magit-diff-visit-worktree-file' but display in another frame."
+  (interactive)
+  (magit-diff-visit-file--internal t #'switch-to-buffer-other-frame))
 
 ;;;;; Internal
 
-(defun magit-diff-visit-file--internal (file force-worktree fn)
+(defun magit-diff-visit-file--internal (force-worktree fn)
   "From a diff visit the appropriate version of FILE.
 If FORCE-WORKTREE is non-nil, then visit the worktree version of
 the file, even if the diff is about a committed change.  Use FN
 to display the buffer in some window."
-  (if (file-accessible-directory-p file)
-      (magit-diff-visit-directory file force-worktree)
-    (pcase-let ((`(,buf ,pos)
-                 (magit-diff-visit-file--noselect file force-worktree)))
-      (funcall fn buf)
-      (magit-diff-visit-file--setup buf pos)
-      buf)))
+  (let ((file (magit-diff--file-at-point t t)))
+    (if (file-accessible-directory-p file)
+        (magit-diff-visit-directory file force-worktree)
+      (pcase-let ((`(,buf ,pos)
+                   (magit-diff-visit-file--noselect force-worktree)))
+        (funcall fn buf)
+        (magit-diff-visit-file--setup buf pos)
+        buf))))
 
 (defun magit-diff-visit-directory (directory &optional other-window)
   "Visit DIRECTORY in some window.
@@ -1749,11 +1746,10 @@ the Magit-Status buffer for DIRECTORY."
         (smerge-start-session))
       (run-hooks 'magit-diff-visit-file-hook))))
 
-(defun magit-diff-visit-file--noselect (&optional file goto-worktree)
-  (unless file
-    (setq file (magit-diff--file-at-point t t)))
+(defun magit-diff-visit-file--noselect (&optional goto-worktree)
   (pcase-let*
-      ((hunk (magit-diff-visit--hunk))
+      ((file (magit-diff--file-at-point t t))
+       (hunk (magit-diff-visit--hunk))
        (goto-from
         (and (not goto-worktree)
              (magit-diff-on-removed-line-p)))
diff --git a/lisp/magit-extras.el b/lisp/magit-extras.el
index d95661faf70..c22feafe5ab 100644
--- a/lisp/magit-extras.el
+++ b/lisp/magit-extras.el
@@ -393,7 +393,7 @@ points at it) otherwise."
 (put 'magit-edit-line-commit 'disabled t)
 
 ;;;###autoload
-(defun magit-diff-edit-hunk-commit (file)
+(defun magit-diff-edit-hunk-commit ()
   "From a hunk, edit the respective commit and visit the file.
 
 First visit the file being modified by the hunk at the correct
@@ -410,10 +410,10 @@ to be visited.
 Neither the blob nor the file buffer are killed when finishing
 the rebase.  If that is undesirable, then it might be better to
 use `magit-rebase-edit-commit' instead of this command."
-  (interactive (list (magit-file-at-point t t)))
+  (interactive)
   (let ((magit-diff-visit-previous-blob nil))
     (with-current-buffer
-        (magit-diff-visit-file--internal file nil #'pop-to-buffer-same-window)
+        (magit-diff-visit-file--internal nil #'pop-to-buffer-same-window)
       (magit-edit-line-commit))))
 
 (put 'magit-diff-edit-hunk-commit 'disabled t)

Reply via email to