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)) ;; Only preview in current window and other window.
cleanup-buffers) ;; Preview in frames and tabs is not possible since these don't get cleaned up.
(lambda (cand restore) (if (memq consult--buffer-display
(when (and (not restore) '(switch-to-buffer switch-to-buffer-other-window))
;; Only preview in current window and other window. (let ((orig-buf (current-buffer))
;; Preview in frames and tabs is not possible since other-win
;; these don't get cleaned up. cleanup-buffers)
(or (eq consult--buffer-display #'switch-to-buffer) (lambda (action cand)
(eq consult--buffer-display #'switch-to-buffer-other-window))) (when (eq action 'preview)
(cond (when (and (eq consult--buffer-display #'switch-to-buffer-other-window)
((and cand (get-buffer cand)) (not other-win))
(unless (+workspace-contains-buffer-p cand) (switch-to-buffer-other-window orig-buf)
(cl-pushnew cand cleanup-buffers)) (setq other-win (selected-window)))
(consult--buffer-action cand 'norecord)) (let ((win (or other-win (selected-window))))
((buffer-live-p orig-buf) (when (window-live-p win)
(consult--buffer-action orig-buf 'norecord) (with-selected-window win
(mapc #'persp-remove-buffer cleanup-buffers)))))))) (cond
(lambda (cand restore) ((and cand (get-buffer cand))
(funcall preview cand restore)))) (unless (+workspace-contains-buffer-p cand)
(cl-pushnew cand cleanup-buffers))
(switch-to-buffer cand 'norecord))
((buffer-live-p orig-buf)
(switch-to-buffer orig-buf 'norecord)
(mapc #'persp-remove-buffer cleanup-buffers)))))))))
#'ignore)))
(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"