branch: externals/vertico
commit 319687d041cc528d6a0e3196d2f94355ef5cbef7
Author: Daniel Mendler <m...@daniel-mendler.de>
Commit: Daniel Mendler <m...@daniel-mendler.de>

    vertico-repeat: Use minibuffer-setup-hook, don't let-bind 
vertico-repeat--restore
    
    This ensures that repeating recursive sessions works.
---
 extensions/vertico-repeat.el | 31 ++++++++++++++++---------------
 1 file changed, 16 insertions(+), 15 deletions(-)

diff --git a/extensions/vertico-repeat.el b/extensions/vertico-repeat.el
index a850906..19b2fd6 100644
--- a/extensions/vertico-repeat.el
+++ b/extensions/vertico-repeat.el
@@ -35,10 +35,10 @@
 
 (require 'vertico)
 
+(defvar-local vertico-repeat--restore nil)
 (defvar vertico-repeat--input nil)
 (defvar vertico-repeat--command nil)
 (defvar vertico-repeat--candidate nil)
-(defvar vertico-repeat--restore nil)
 
 (defun vertico-repeat--save-input ()
   "Save current minibuffer content for `vertico-repeat'."
@@ -53,18 +53,20 @@
 
 (defun vertico-repeat--save ()
   "Save Vertico status for `vertico-repeat'."
-  (unless vertico-repeat--restore
-    (setq vertico-repeat--command (if (boundp 'minibuffer-current-command)
-                                      minibuffer-current-command
-                                    this-command)
-          vertico-repeat--input ""
-          vertico-repeat--candidate nil
-          vertico-repeat--restore nil))
-  (add-hook 'post-command-hook #'vertico-repeat--save-input nil 'local)
-  (add-hook 'minibuffer-exit-hook #'vertico-repeat--save-candidate nil 'local))
+  (when vertico--input
+    (unless vertico-repeat--restore
+      (setq vertico-repeat--command (if (boundp 'minibuffer-current-command)
+                                        minibuffer-current-command
+                                      this-command)
+            vertico-repeat--input ""
+            vertico-repeat--candidate nil
+            vertico-repeat--restore nil))
+    (add-hook 'post-command-hook #'vertico-repeat--save-input nil 'local)
+    (add-hook 'minibuffer-exit-hook #'vertico-repeat--save-candidate nil 
'local)))
 
 (defun vertico-repeat--restore ()
   "Restore Vertico status for `vertico-repeat'."
+  (setq vertico-repeat--restore t)
   (delete-minibuffer-contents)
   (insert vertico-repeat--input)
   (when vertico-repeat--candidate
@@ -81,13 +83,12 @@
   (interactive)
   (unless vertico-repeat--command
     (user-error "No repeatable Vertico session"))
-  (let ((vertico-repeat--restore t))
-    (minibuffer-with-setup-hook
-        #'vertico-repeat--restore
-      (command-execute (setq this-command vertico-repeat--command)))))
+  (minibuffer-with-setup-hook
+      #'vertico-repeat--restore
+    (command-execute (setq this-command vertico-repeat--command))))
 
 ;;;###autoload
-(advice-add #'vertico--setup :after #'vertico-repeat--save)
+(add-hook 'minibuffer-setup-hook #'vertico-repeat--save)
 
 (provide 'vertico-repeat)
 ;;; vertico-repeat.el ends here

Reply via email to