fix(vertico): update +vertico-workspace-buffer-state to new api

also adapt upstream improvements
This commit is contained in:
Itai Y. Efrat 2022-04-09 17:23:55 +03:00 committed by Henrik Lissner
parent 136e7df76e
commit c9665f733b

View file

@ -3,25 +3,33 @@
(defun +vertico--workspace-buffer-state () (defun +vertico--workspace-buffer-state ()
(let ((preview (let ((preview
(let ((orig-buf (current-buffer))
cleanup-buffers)
(lambda (cand restore)
(when (and (not restore)
;; Only preview in current window and other window. ;; Only preview in current window and other window.
;; Preview in frames and tabs is not possible since ;; Preview in frames and tabs is not possible since these don't get cleaned up.
;; these don't get cleaned up. (if (memq consult--buffer-display
(or (eq consult--buffer-display #'switch-to-buffer) '(switch-to-buffer switch-to-buffer-other-window))
(eq consult--buffer-display #'switch-to-buffer-other-window))) (let ((orig-buf (current-buffer))
other-win
cleanup-buffers)
(lambda (action cand)
(when (eq action 'preview)
(when (and (eq consult--buffer-display #'switch-to-buffer-other-window)
(not other-win))
(switch-to-buffer-other-window orig-buf)
(setq other-win (selected-window)))
(let ((win (or other-win (selected-window))))
(when (window-live-p win)
(with-selected-window win
(cond (cond
((and cand (get-buffer cand)) ((and cand (get-buffer cand))
(unless (+workspace-contains-buffer-p cand) (unless (+workspace-contains-buffer-p cand)
(cl-pushnew cand cleanup-buffers)) (cl-pushnew cand cleanup-buffers))
(consult--buffer-action cand 'norecord)) (switch-to-buffer cand 'norecord))
((buffer-live-p orig-buf) ((buffer-live-p orig-buf)
(consult--buffer-action orig-buf 'norecord) (switch-to-buffer orig-buf 'norecord)
(mapc #'persp-remove-buffer cleanup-buffers)))))))) (mapc #'persp-remove-buffer cleanup-buffers)))))))))
(lambda (cand restore) #'ignore)))
(funcall preview cand restore)))) (lambda (action cand)
(funcall preview action cand))))
(defun +vertico--workspace-generate-sources () (defun +vertico--workspace-generate-sources ()
"Generate list of consult buffer sources for all workspaces" "Generate list of consult buffer sources for all workspaces"