emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/git-commit 8406b08 4/4: Add additional default when readin


From: ELPA Syncer
Subject: [nongnu] elpa/git-commit 8406b08 4/4: Add additional default when reading branch or commit
Date: Sun, 29 Aug 2021 15:57:30 -0400 (EDT)

branch: elpa/git-commit
commit 8406b084a31c9f4f331fb9846938deffdbe740e2
Author: Jonas Bernoulli <jonas@bernoul.li>
Commit: Jonas Bernoulli <jonas@bernoul.li>

    Add additional default when reading branch or commit
    
    The modified readers prefer the branch at point (if any) over the
    commit at point.  In some cases the user might prefer the commit in
    some cases so we now offer that as the first "next history element".
    
    Closes #4291.
---
 Documentation/RelNotes/3.3.0.org |  5 +++++
 lisp/magit-git.el                | 30 +++++++++++++++++++++---------
 2 files changed, 26 insertions(+), 9 deletions(-)

diff --git a/Documentation/RelNotes/3.3.0.org b/Documentation/RelNotes/3.3.0.org
index 5ec65ea..447a8bb 100644
--- a/Documentation/RelNotes/3.3.0.org
+++ b/Documentation/RelNotes/3.3.0.org
@@ -32,6 +32,11 @@
 - Added new tranient prefix command ~magit-bundle~, which provides
   support for ~git bundle~.  #4392
 
+- When minibuffer completion allows for a branch or a commit to be
+  selected and the former is preferred and thus offered as default
+  if possible, then offer the commit at point as the first choice
+  initially accessible with ~next-history-element~.  #4291
+
 ** Fixes since v3.2.0
 
 - Make ~magit-branch-remote-head~ and ~magit-branch-current~ fall back
diff --git a/lisp/magit-git.el b/lisp/magit-git.el
index 7efeba9..3a02767 100644
--- a/lisp/magit-git.el
+++ b/lisp/magit-git.el
@@ -2212,6 +2212,14 @@ and this option only controls what face is used.")
 
 (defvar magit-revision-history nil)
 
+(defun magit--minibuf-default-add-commit ()
+  (let ((fn minibuffer-default-add-function))
+    (lambda ()
+      (if-let ((commit (with-selected-window (minibuffer-selected-window)
+                         (magit-commit-at-point))))
+          (cons commit (delete commit (funcall fn)))
+        (funcall fn)))))
+
 (defun magit-read-branch (prompt &optional secondary-default)
   (magit-completing-read prompt (magit-list-branch-names)
                          nil t nil 'magit-revision-history
@@ -2220,12 +2228,13 @@ and this option only controls what face is used.")
                              (magit-get-current-branch))))
 
 (defun magit-read-branch-or-commit (prompt &optional secondary-default)
-  (or (magit-completing-read prompt (magit-list-refnames nil t)
-                             nil nil nil 'magit-revision-history
-                             (or (magit-branch-or-commit-at-point)
-                                 secondary-default
-                                 (magit-get-current-branch)))
-      (user-error "Nothing selected")))
+  (let ((minibuffer-default-add-function (magit--minibuf-default-add-commit)))
+    (or (magit-completing-read prompt (magit-list-refnames nil t)
+                               nil nil nil 'magit-revision-history
+                               (or (magit-branch-or-commit-at-point)
+                                   secondary-default
+                                   (magit-get-current-branch)))
+        (user-error "Nothing selected"))))
 
 (defun magit-read-range-or-commit (prompt &optional secondary-default)
   (magit-read-range
@@ -2238,7 +2247,8 @@ and this option only controls what face is used.")
        (magit-get-current-branch))))
 
 (defun magit-read-range (prompt &optional default)
-  (let ((crm-separator "\\.\\.\\.?"))
+  (let ((minibuffer-default-add-function (magit--minibuf-default-add-commit))
+        (crm-separator "\\.\\.\\.?"))
     (magit-completing-read-multiple*
      (concat prompt ": ")
      (magit-list-refnames)
@@ -2273,7 +2283,8 @@ and this option only controls what face is used.")
                              (magit-get-current-branch))))
 
 (defun magit-read-local-branch-or-commit (prompt)
-  (let ((choices (nconc (magit-list-local-branch-names)
+  (let ((minibuffer-default-add-function (magit--minibuf-default-add-commit))
+        (choices (nconc (magit-list-local-branch-names)
                         (magit-list-special-refnames)))
         (commit (magit-commit-at-point)))
     (when commit
@@ -2306,7 +2317,8 @@ and this option only controls what face is used.")
 
 (defun magit-read-other-branch-or-commit
     (prompt &optional exclude secondary-default)
-  (let* ((current (magit-get-current-branch))
+  (let* ((minibuffer-default-add-function (magit--minibuf-default-add-commit))
+         (current (magit-get-current-branch))
          (atpoint (magit-branch-or-commit-at-point))
          (exclude (or exclude current))
          (default (or (and (not (equal atpoint exclude))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]