branch: externals/consult
commit 42fb3eab4c693b83d890a1431f80837e90488c2e
Author: Daniel Mendler <m...@daniel-mendler.de>
Commit: Daniel Mendler <m...@daniel-mendler.de>

    consult--buffer-preview: Restore window configuration properly (Fix #547)
---
 consult.el | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/consult.el b/consult.el
index ca568f72b6..2d17ee9d3c 100644
--- a/consult.el
+++ b/consult.el
@@ -4124,18 +4124,19 @@ Report progress and return a list of the results"
 
 (defun consult--buffer-preview ()
   "Buffer preview function."
-  (let ((orig-buf (current-buffer)))
+  (let (orig-conf)
     (lambda (action cand)
       ;; Only preview in current window and other window.
       ;; Preview in frames and tabs is not possible since these don't get 
cleaned up.
-      (when (or (eq action 'preview)
-                (eq consult--buffer-display #'switch-to-buffer)
-                (eq consult--buffer-display #'switch-to-buffer-other-window))
+      (when (and (eq action 'preview)
+                 (memq consult--buffer-display
+                       '(switch-to-buffer switch-to-buffer-other-window)))
         (cond
          ((and cand (get-buffer cand))
+          (unless orig-conf
+            (setq orig-conf (current-window-configuration)))
           (consult--buffer-action cand 'norecord))
-         ((buffer-live-p orig-buf)
-          (consult--buffer-action orig-buf 'norecord)))))))
+         (t (ignore-errors (set-window-configuration orig-conf))))))))
 
 (defun consult--buffer-action (buffer &optional norecord)
   "Switch to BUFFER via `consult--buffer-display' function.

Reply via email to