Skip to content

Commit

Permalink
[compleseus] Add window and workspace buffer sources
Browse files Browse the repository at this point in the history
Additional sources for `spacemacs/compleseus-switch-to-buffer` and
`consult-buffer`:
- New source "Window Buffer": shows all buffers previously displayed in the selected
window (including hidden buffers and buffers from other layouts), hidden by default.
- New source "Workspace Buffer": shows all buffer previously displayed in all
live windows of the current window configuration (including hidden buffers and
buffers from other layouts), hidden by default.
  • Loading branch information
fnussbaum authored and smile13241324 committed Sep 14, 2024
1 parent 3c8cb6e commit 06067c3
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 2 deletions.
68 changes: 66 additions & 2 deletions layers/+completion/compleseus/config.el
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ To restrict the commands to buffers of the current layout, customize
the variable `spacemacs-layouts-restricted-functions'.")

(defcustom compleseus-switch-to-buffer-sources
`(consult--source-hidden-buffer
'(consult--source-hidden-buffer
compleseus--source-buffers-hidden
compleseus--source-persp-buffers
compleseus--source-persp-modified-buffers
consult--source-recent-file
consult--source-bookmark
consult--source-project-buffer-hidden
consult--source-project-recent-file-hidden)
consult--source-project-recent-file-hidden
compleseus--source-window-buffers
compleseus--source-workspace-buffers)
"Sources used by `spacemacs/compleseus-switch-to-buffer'
when persp-mode is used.
See also `consult-buffer-sources'.
Expand Down Expand Up @@ -102,3 +104,65 @@ and with narrowing key \"B\".")
"Per-perspective buffer source.")
(define-obsolete-variable-alias 'consult--source-persp-buffers
'compleseus--source-persp-buffers "2024-09")

(defvar compleseus--source-window-buffers
`(:name "Window Buffer"
:hidden t
:narrow ?w
:category buffer
:face consult-buffer
:history buffer-name-history
:state ,#'consult--buffer-state
:default t
:items
,(lambda ()
(let* ((prev-buffers (delq (window-buffer) (mapcar #'car (window-prev-buffers))))
(next-buffers (window-next-buffers))
(buffers
(if vertico-cycle
;; If cycling is enabled, this order makes sense:
;; One can move down to previous buffers,
;; and move up to next buffers.
(append (list (window-buffer))
(seq-difference prev-buffers next-buffers)
(nreverse next-buffers))
;; Note that next-buffers is a subset of prev-buffers.
(cons (window-buffer) prev-buffers))))
(consult--buffer-query
:sort nil
:filter nil
:as #'consult--buffer-pair
:buffer-list buffers))))
"Window buffer source for `consult-buffer'.
It contains all buffers previously displayed in the selected
window, including buffers from different layouts and hidden
buffers.")

(defvar compleseus--source-workspace-buffers
`(:name "Workspace Buffer"
:hidden t
:narrow ?k
:category buffer
:face consult-buffer
:history buffer-name-history
:state ,#'consult--buffer-state
:default t
:items
,(lambda ()
(let (prev-buffers)
(walk-windows
(lambda (win)
(setq prev-buffers
(append (mapcar #'car (window-prev-buffers win))
prev-buffers)))
'no-minibuffer)
(consult--buffer-query
:sort 'visibility
:filter nil
:as #'consult--buffer-pair
:predicate (lambda (buf)
(member buf prev-buffers))))))
"Workspace buffer source for `consult-buffer'.
It contains all buffers previously displayed in a live window of
the current window configuration, including buffers from
different layouts and hidden buffers.")
2 changes: 2 additions & 0 deletions layers/+completion/compleseus/packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@
;; Configure other variables and modes in the :config section,
;; after lazily loading the package.
:config
(add-to-list 'consult-buffer-sources 'compleseus--source-window-buffers)
(add-to-list 'consult-buffer-sources 'compleseus--source-workspace-buffers)

;; disable automatic preview by default,
;; selectively enable it for some prompts below.
Expand Down

0 comments on commit 06067c3

Please sign in to comment.