branch: elpa/magit
commit b172fa0c33cc37c763676399670aad81ab34aca2
Author: Jonas Bernoulli <jo...@bernoul.li>
Commit: Jonas Bernoulli <jo...@bernoul.li>

    magit--minibuf-default-add-commit: Call using minibuffer-with-setup-hook
---
 lisp/magit-git.el | 64 +++++++++++++++++++++++++++++--------------------------
 1 file changed, 34 insertions(+), 30 deletions(-)

diff --git a/lisp/magit-git.el b/lisp/magit-git.el
index 1571ee1bcad..7dd26a225bc 100644
--- a/lisp/magit-git.el
+++ b/lisp/magit-git.el
@@ -2602,17 +2602,19 @@ and this option only controls what face is used.")
 
 (defun magit--minibuf-default-add-commit ()
   (let ((fn minibuffer-default-add-function))
-    (lambda ()
-      (let ((rest (and (functionp fn) (funcall fn))))
-        (if-let ((commit (with-selected-window (minibuffer-selected-window)
-                           (or (magit-thing-at-point 'git-revision-range t)
-                               (magit-commit-at-point)))))
-            (let ((rest (cons commit (delete commit rest)))
-                  (def minibuffer-default))
-              (if (listp def)
-                  (append def rest)
-                (cons def (delete def rest))))
-          rest)))))
+    (setq-local
+     minibuffer-default-add-function
+     (lambda ()
+       (let ((rest (and (functionp fn) (funcall fn))))
+         (if-let ((commit (with-selected-window (minibuffer-selected-window)
+                            (or (magit-thing-at-point 'git-revision-range t)
+                                (magit-commit-at-point)))))
+             (let ((rest (cons commit (delete commit rest)))
+                   (def minibuffer-default))
+               (if (listp def)
+                   (append def rest)
+                 (cons def (delete def rest))))
+           rest))))))
 
 (defun magit-read-branch (prompt &optional secondary-default)
   (magit-completing-read prompt (magit-list-branch-names)
@@ -2625,18 +2627,18 @@ and this option only controls what face is used.")
   (let ((current (magit-get-current-branch))
         (branch-at-point (magit-branch-at-point))
         (commit-at-point (magit-commit-at-point))
-        (choices (delete exclude (magit-list-refnames nil t)))
-        (minibuffer-default-add-function (magit--minibuf-default-add-commit)))
+        (choices (delete exclude (magit-list-refnames nil t))))
     (when (equal current exclude)
       (setq current nil))
     (when (equal branch-at-point exclude)
       (setq branch-at-point nil))
     (when (and commit-at-point (not branch-at-point))
       (setq choices (cons commit-at-point choices)))
-    (or (magit-completing-read
-         prompt choices nil nil nil 'magit-revision-history
-         (or branch-at-point commit-at-point secondary-default current))
-        (user-error "Nothing selected"))))
+    (minibuffer-with-setup-hook #'magit--minibuf-default-add-commit
+      (or (magit-completing-read
+           prompt choices nil nil nil 'magit-revision-history
+           (or branch-at-point commit-at-point secondary-default current))
+          (user-error "Nothing selected")))))
 
 (defun magit-read-range-or-commit (prompt &optional secondary-default)
   (magit-read-range
@@ -2650,8 +2652,10 @@ and this option only controls what face is used.")
        (magit-get-current-branch))))
 
 (defun magit-read-range (prompt &optional default)
-  (let ((minibuffer-default-add-function (magit--minibuf-default-add-commit))
-        (crm-separator "\\.\\.\\.?"))
+  (minibuffer-with-setup-hook
+      (lambda ()
+        (magit--minibuf-default-add-commit)
+        (setq-local crm-separator "\\.\\.\\.?"))
     (magit-completing-read-multiple
      (concat prompt ": ")
      (magit-list-refnames)
@@ -2687,16 +2691,16 @@ and this option only controls what face is used.")
                              (magit-get-current-branch))))
 
 (defun magit-read-local-branch-or-commit (prompt)
-  (let ((minibuffer-default-add-function (magit--minibuf-default-add-commit))
-        (choices (nconc (magit-list-local-branch-names)
+  (let ((choices (nconc (magit-list-local-branch-names)
                         (magit-list-special-refnames)))
         (commit (magit-commit-at-point)))
     (when commit
       (push commit choices))
-    (or (magit-completing-read prompt choices
-                               nil nil nil 'magit-revision-history
-                               (or (magit-local-branch-at-point) commit))
-        (user-error "Nothing selected"))))
+    (minibuffer-with-setup-hook #'magit--minibuf-default-add-commit
+      (or (magit-completing-read prompt choices
+                                 nil nil nil 'magit-revision-history
+                                 (or (magit-local-branch-at-point) commit))
+          (user-error "Nothing selected")))))
 
 (defun magit-read-local-branch-or-ref (prompt &optional secondary-default)
   (magit-completing-read prompt (nconc (magit-list-local-branch-names)
@@ -2721,8 +2725,7 @@ and this option only controls what face is used.")
 
 (defun magit-read-other-branch-or-commit
     (prompt &optional exclude secondary-default)
-  (let* ((minibuffer-default-add-function (magit--minibuf-default-add-commit))
-         (current (magit-get-current-branch))
+  (let* ((current (magit-get-current-branch))
          (atpoint (magit-branch-or-commit-at-point))
          (exclude (or exclude current))
          (default (or (and (not (equal atpoint exclude))
@@ -2732,9 +2735,10 @@ and this option only controls what face is used.")
                       (and (not (equal current exclude)) current)
                       secondary-default
                       (magit-get-previous-branch))))
-    (or (magit-completing-read prompt (delete exclude (magit-list-refnames))
-                               nil nil nil 'magit-revision-history default)
-        (user-error "Nothing selected"))))
+    (minibuffer-with-setup-hook #'magit--minibuf-default-add-commit
+      (or (magit-completing-read prompt (delete exclude (magit-list-refnames))
+                                 nil nil nil 'magit-revision-history default)
+          (user-error "Nothing selected")))))
 
 (defun magit-read-other-local-branch
     (prompt &optional exclude secondary-default no-require-match)

Reply via email to