about summary refs log tree commit diff stats
path: root/.emacs.d/lisp/init-minibuffer.el
diff options
context:
space:
mode:
authorDavid Morgan <djm_uk@protonmail.com>2021-09-11 06:41:47 +0100
committerDavid Morgan <djm_uk@protonmail.com>2021-09-11 06:41:47 +0100
commit33b0b94d454b648c2509cd8a5b782dc72d0ceeb4 (patch)
tree39d166e6f494ff3012346ffe6fe298fc21a2928d /.emacs.d/lisp/init-minibuffer.el
parent1bfe1dd58369de4f8159a59447810cc53c84e3fa (diff)
downloaddotfiles-33b0b94d454b648c2509cd8a5b782dc72d0ceeb4.tar.gz
Make consult-buffer switch perspective when needed
Diffstat (limited to '.emacs.d/lisp/init-minibuffer.el')
-rw-r--r--.emacs.d/lisp/init-minibuffer.el14
1 files changed, 12 insertions, 2 deletions
diff --git a/.emacs.d/lisp/init-minibuffer.el b/.emacs.d/lisp/init-minibuffer.el
index 45b4fbc..f6d64e1 100644
--- a/.emacs.d/lisp/init-minibuffer.el
+++ b/.emacs.d/lisp/init-minibuffer.el
@@ -285,8 +285,18 @@ DEFS is a plist associating completion categories to commands."
           (when-let (project (project-current))
             (project-root project))))
 
-  ;; Switch perspective when switching buffer if needed ;; TODO this doesn't work
-  ;; (setq consult--display-buffer #'persp-switch-to-buffer)
+  ;; Switches perspective if we select a buffer from another perspective, but note that previewing
+  ;; a buffer adds it to the current perspective, so preview should be disabled before removing
+  ;; perspective narrowing
+  (defun consult--persp-buffer-action (orig &rest args)
+    (when (not (cdr args)) ;; (cdr args) is norecord, which should distinguish preview/non-preview
+      (let ((buffer (window-normalize-buffer-to-switch-to (car args))))
+        (unless (persp-is-current-buffer buffer)
+          (let ((other-persp (persp-buffer-in-other-p buffer)))
+            (when (eq (car-safe other-persp) (selected-frame))
+              (persp-switch (cdr other-persp)))))))
+    (apply orig args))
+  (advice-add 'consult--buffer-action :around 'consult--persp-buffer-action)
 
   (defvar consult-initial-narrow-config
     '((consult-buffer . ?x)