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

    magit-diff-buffer-file: With prefix argument show only unstaged changes
    
    Closes #5013.
---
 docs/CHANGELOG.4   |  3 +++
 docs/magit.org     |  6 +++++-
 docs/magit.texi    |  6 +++++-
 lisp/magit-diff.el | 13 ++++++++-----
 4 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/docs/CHANGELOG.4 b/docs/CHANGELOG.4
index 8c7215ba8b..d8e5879726 100644
--- a/docs/CHANGELOG.4
+++ b/docs/CHANGELOG.4
@@ -67,6 +67,9 @@
 
 - Added new function ~magit-insert-nested-repositories~.  #5336
 
+- With a prefix argument ~magit-diff-buffer-file~ now only shows
+  unstaged changes.  #5013
+
 Bugfixes:
 
 - ~magit-ignore-submodules-p~ didn't return ~nil~ for ~none~.
diff --git a/docs/magit.org b/docs/magit.org
index e92b977f3e..4072a65a31 100644
--- a/docs/magit.org
+++ b/docs/magit.org
@@ -8140,7 +8140,11 @@ all, add this to your init file and restart Emacs.
 - Key: C-c M-g d (magit-diff-buffer-file) ::
 
   This command shows the diff for the file of blob that the current
-  buffer visits.
+  buffer visits.  The diff is limited to the file or blob.
+
+  When the buffer visits a blob, then show the respective commit.
+  When the buffer visits a file, then show the differences between
+  ~HEAD~ and the working tree, or the index with a prefix argument.
 
 - User Option: magit-diff-buffer-file-locked ::
 
diff --git a/docs/magit.texi b/docs/magit.texi
index 6af84f2aac..340f145210 100644
--- a/docs/magit.texi
+++ b/docs/magit.texi
@@ -9837,7 +9837,11 @@ file(s) is set to the visited file.
 @kindex C-c M-g d
 @findex magit-diff-buffer-file
 This command shows the diff for the file of blob that the current
-buffer visits.
+buffer visits.  The diff is limited to the file or blob.
+
+When the buffer visits a blob, then show the respective commit.
+When the buffer visits a file, then show the differences between
+@code{HEAD} and the working tree, or the index with a prefix argument.
 @end table
 
 @defopt magit-diff-buffer-file-locked
diff --git a/lisp/magit-diff.el b/lisp/magit-diff.el
index 5e4503bdf0..ecf325604d 100644
--- a/lisp/magit-diff.el
+++ b/lisp/magit-diff.el
@@ -1524,14 +1524,15 @@ be committed."
   (magit-commit-diff--show))
 
 ;;;###autoload
-(defun magit-diff-buffer-file ()
+(defun magit-diff-buffer-file (&optional unstaged-only)
   "Show diff for the blob or file visited in the current buffer.
 
+Limit the diff to the file or blob.
+
 When the buffer visits a blob, then show the respective commit.
 When the buffer visits a file, then show the differences between
-`HEAD' and the working tree.  In both cases limit the diff to
-the file or blob."
-  (interactive)
+`HEAD' and the working tree, or the index with a prefix argument."
+  (interactive (list current-prefix-arg))
   (require 'magit)
   (if-let ((file (magit-file-relative-name)))
       (if magit-buffer-revision
@@ -1542,7 +1543,9 @@ the file or blob."
         (let ((line (line-number-at-pos))
               (col (current-column)))
           (with-current-buffer
-              (magit-diff-setup-buffer (or (magit-get-current-branch) "HEAD")
+              (magit-diff-setup-buffer (and (not unstaged-only)
+                                            (or (magit-get-current-branch)
+                                                "HEAD"))
                                        nil
                                        (car (magit-diff-arguments))
                                        (list file)

Reply via email to