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

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

[elpa] externals/consult 2ef56c9: consult--multi-state: Fix source destr


From: ELPA Syncer
Subject: [elpa] externals/consult 2ef56c9: consult--multi-state: Fix source destruction/restoration order (Fix #359)
Date: Mon, 12 Jul 2021 08:57:08 -0400 (EDT)

branch: externals/consult
commit 2ef56c90bc45161fa4e4b8abf573e8a846d43a58
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>

    consult--multi-state: Fix source destruction/restoration order (Fix #359)
---
 consult.el | 26 ++++++++++++++++----------
 1 file changed, 16 insertions(+), 10 deletions(-)

diff --git a/consult.el b/consult.el
index a6a8780..40f57ee 100644
--- a/consult.el
+++ b/consult.el
@@ -1919,20 +1919,26 @@ INHERIT-INPUT-METHOD, if non-nil the minibuffer 
inherits the input method."
                                       sources)))
     (let ((last-fun))
       (pcase-lambda (`(,cand . ,src) restore)
-        (if restore
-            ;; Restore all state functions
-            (dolist (state states)
-              (funcall (cdr state) (and (eq (car state) src) cand) t))
-          ;; Get state function to call for preview
-          (let ((fun (cdr (assq src states))))
+        ;; Get state function
+        (let ((selected-fun (cdr (assq src states))))
+          (if restore
+              (progn
+                ;; If the candidate source changed, destruct first the last 
source.
+                (when (and last-fun (not (eq last-fun selected-fun)))
+                  (funcall last-fun nil t))
+                ;; Destruct all the sources, except the last and selected 
source
+                (dolist (state states)
+                  (unless (or (eq (cdr state) last-fun) (eq (cdr state) 
selected-fun))
+                    (funcall (cdr state) nil t)))
+                ;; Finally destruct the source with the selected candidate
+                (when selected-fun (funcall selected-fun cand t)))
             ;; If the candidate source changed during preview communicate to
             ;; the last source, that none of its candidates is previewed 
anymore.
-            (when (and last-fun (not (eq last-fun fun)))
+            (when (and last-fun (not (eq last-fun selected-fun)))
               (funcall last-fun nil nil))
-            (setq last-fun fun)
+            (setq last-fun selected-fun)
             ;; Call the state function.
-            (when fun
-              (funcall fun cand nil))))))))
+            (when selected-fun (funcall selected-fun cand nil))))))))
 
 (defun consult--multi (sources &rest options)
   "Select from candidates taken from a list of SOURCES.



reply via email to

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