diff --git a/modules/completion/selectrum/README.org b/modules/completion/selectrum/README.org index 4ec0d0e3b..b35717633 100644 --- a/modules/completion/selectrum/README.org +++ b/modules/completion/selectrum/README.org @@ -133,7 +133,12 @@ An ~occur-edit~ buffer can be opened from ~consult-line~ with =C-c C-e=. | =SPC b b=, =SPC ,= | Switch to buffer in current workspace | | =SPC b B=, =SPC <= | Switch to buffer | -~find-file~ commands support exported to a =wdired= buffer using =C-c C-e=. +=SPC b b= and =SPC ,= support changing the workspace you're selecting a buffer from +via [[https://github.com/minad/consult#narrowing-and-grouping][Consult narrowing]], e.g. if you're on the first workspace, you can switch to +selecting a buffer from the third workspace by typing =3 SPC= into the prompt, +or the last workspace by typing =0 SPC=. + +=SPC f f= and =SPC .= support exporting to a =wdired= buffer using =C-c C-e=. *** Search | Keybind | Description | diff --git a/modules/completion/selectrum/TODO.org b/modules/completion/selectrum/TODO.org index 236820d7b..f6c08d737 100644 --- a/modules/completion/selectrum/TODO.org +++ b/modules/completion/selectrum/TODO.org @@ -70,16 +70,12 @@ currently =SPC n b= is bound to a function, but =bibtex-actions= doesn't have a main dispatch function like =ivy-bibtex=, rather it has a bunch of different ones. Binding the ~bibtex-actions-map~ there would probably be better, but there are nontrivial loading order shenanigans happening that make that not straightforward. +** TODO buffer switching +- =SPC b b= should switch workspace after choosing a buffer from a different one +- universal argument for opening buffer in another window? ** TODO Ivy Parity *** TODO pass module -*** TODO remaps -refactor these to use consult so previews can work, also maybe have narrowed number keys for workspaces? -#+begin_src elisp - [remap switch-to-buffer] #'+ivy/switch-buffer - [remap switch-to-buffer-other-window] #'+ivy/switch-buffer-other-window - [remap persp-switch-to-buffer] #'+ivy/switch-workspace-buffer - [remap evil-show-jumps] #'+ivy/jump-list -#+end_src +*** TODO ~+ivy/jump-list~ analogue *** TODO ~+irc/selectrum-jump-to-channel~ rework to use ~consult~ buffer narrowing, for some reason the current attempt breaks marginalia annotating *** WAIT lookup module diff --git a/modules/completion/selectrum/autoload/workspaces.el b/modules/completion/selectrum/autoload/workspaces.el new file mode 100644 index 000000000..673fc975e --- /dev/null +++ b/modules/completion/selectrum/autoload/workspaces.el @@ -0,0 +1,47 @@ +;;; completion/selectrum/autoload/workspaces.el -*- lexical-binding: t; -*- +;;;###if (featurep! :ui workspaces) + +;;;###autoload +(defun +selectrum--workspace-nth-source (n) + "Generate a consult buffer source for buffers in the NTH workspace" + (cond ((numberp n) + `(:name ,(nth (1- n) (+workspace-list-names)) + :hidden ,(not (string= (+workspace-current-name) (nth (1- n) (+workspace-list-names)))) + :narrow ,(string-to-char (number-to-string n)) + :category buffer + :state ,#'consult--buffer-state + :items ,(lambda () (mapcar #'buffer-name (+workspace-buffer-list (nth (1- n) (+workspace-list))))))) + ((eq n 'final) + `(:name ,(car (last (+workspace-list-names))) + :hidden t + :narrow ?0 + :category buffer + :state ,#'consult--buffer-state + :items ,(lambda () (mapcar #'buffer-name (+workspace-buffer-list (car (last (+workspace-list)))))))) + (t + (user-error "invalid workspace source %s" n)))) + +;;;###autoload +(defun +selectrum--workspace-generate-sources () + "Generate list of consult buffer sources for all workspaces" + (mapcar #'+selectrum--workspace-nth-source '(1 2 3 4 5 6 7 8 9 final))) + +(autoload 'consult--multi "consult") +;;;###autoload +(defun +selectrum/switch-workspace-buffer () + "Switch to another buffer in the same workspace. + +Use consult narrowing with another workspace number to open a buffer from that workspace + BUG but it opens it in the current workspace (ivy also does this, but who cares)" + (interactive) + (when-let (buffer (consult--multi (+selectrum--workspace-generate-sources) + :require-match + (confirm-nonexistent-file-or-buffer) + :prompt (format "Switch to buffer (%s): " + (+workspace-current-name) + :history 'consult--buffer-history + :sort nil))) + ;; When the buffer does not belong to a source, + ;; create a new buffer with the name. + (unless (cdr buffer) + (funcall consult--buffer-display (car buffer))))) diff --git a/modules/completion/selectrum/config.el b/modules/completion/selectrum/config.el index d3a12177a..457107630 100644 --- a/modules/completion/selectrum/config.el +++ b/modules/completion/selectrum/config.el @@ -91,7 +91,8 @@ [remap switch-to-buffer-other-window] #'consult-buffer-other-window [remap switch-to-buffer-other-frame] #'consult-buffer-other-frame [remap yank-pop] #'consult-yank-pop - [remap describe-bindings] #'embark-bindings) + [remap describe-bindings] #'embark-bindings + [remap persp-switch-to-buffer] #'+selectrum/switch-workspace-buffer) (setq completion-in-region-function #'consult-completion-in-region) :config (recentf-mode)