selectrum: add preview to non-consult functions

This commit is contained in:
Itai Y. Efrat 2021-05-22 01:21:10 +03:00
parent 188fc09d72
commit 89fd6b66b3
4 changed files with 33 additions and 14 deletions

View file

@ -96,6 +96,8 @@ These keybindings are available while a search is active:
| =C-c C-o= | Open a buffer with your search results |
| =C-c C-e= | Open a writable buffer of your search results |
| =C-SPC= | Preview the current candidate |
| =C-M-j= | Scroll down and preview. |
| =C-M-k= | Scroll up and preview. |
| =C-RET= | Open the selected candidate in other-window |
Changes to the resulting wgrep buffer (opened by =C-c C-e=) can be committed

View file

@ -20,6 +20,9 @@ Currently the =!= style dispatcher is only as a prefix, due to the abundance of
=!= final macros. In my opinion this is useful enough to break consistency.
** TODO =C-c C-e=
on ~consult-line~ this opens a ~occur-edit~ buffer, which is a more natural fit but breaks slightly from the =C-c C-e= = =wgrep= convention.
** TODO keep or discard =C-M-j= and =C-M-k=
Scroll up and down while previewing. Essentially shortcuts for =C-(j|k) C-SPC=.
I like having them around but I can always just add them to my private config.
* PROJ HACKs to be addressed
** ~fboundp~ issues
@ -32,16 +35,6 @@ Without [[file:~/.emacs.d/modules/ui/workspaces/config.el::;; HACK?? needs revie
working of this whole set up are a bit opaque to me.
* PROJ Bugs
** TODO =C-SPC= and live previews
Automatic live previews have been disabled on slow ~consult~ commands.
=C-SPC= is partially implemented as the preview key for ~consult-*~ commands.
Need to get it to work for other selectrum commands such =SPC h f=.
#+begin_src emacs-lisp
(let ((embark-quit-after-action nil))
(map! :map minibuffer-local-map "C-SPC" #'embark-default-action)))
#+end_src
gets us close but moves the cursor to the new screen which is undesirable.
probable best strategy: create an ~embark-preview~ that does this, upstream it.
** TODO ripgrep height logic bad
selectrum bug caused by file descriptors
https://github.com/raxod502/selectrum/issues/491
@ -74,10 +67,9 @@ are nontrivial loading order shenanigans happening that make that not straightfo
- =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 =C-RET= on minibuffer?
*** TODO pass module
*** 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
- ~dash-docs~ backend (needs to be created)
- ~+lookup--online..~ functionality (needs a consult analogue of ~counsel-search~)

View file

@ -91,3 +91,27 @@ Supports exporting consult-grep to wgrep, file to wdeired, and consult-location
('consult-location (let ((embark-after-export-hook #'occur-edit-mode))
(embark-export)))
(x (user-error "embark category %S doesn't support writable export" x)))))
;;;###autoload
(defun +selectrum/embark-preview ()
"Previews candidate in selectrum buffer, unless it's a consult command"
(interactive)
(unless (string-match-p "^consult" (symbol-name selectrum--last-command))
(print selectrum--last-command)
(save-selected-window
(let ((embark-quit-after-action nil))
(embark-default-action)))))
;;;###autoload
(defun +selectrum/next-candidate-preview ()
"Move to next candidate and preivew it"
(interactive)
(selectrum-next-candidate)
(+selectrum/embark-preview))
;;;###autoload
(defun +selectrum/previous-candidate-preview ()
"Move to previous candidate and preview it"
(interactive)
(selectrum-previous-candidate)
(+selectrum/embark-preview))

View file

@ -207,12 +207,13 @@
(:after selectrum
:map selectrum-minibuffer-map
"M-RET" #'selectrum-submit-exact-input
"C-SPC" #'+selectrum/embark-preview
"C-j" #'selectrum-next-candidate
"C-M-j" #'selectrum-next-candidate ;; with preview, see modules/completion/selectrum/config.el
"C-M-j" #'+selectrum/next-candidate-preview
"C-S-j" #'selectrum-next-page
"C-s-j" #'selectrum-goto-end
"C-k" #'selectrum-previous-candidate
"C-M-k" #'selectrum-previous-candidate ;; with preview, see modules/completion/selectrum/config.el
"C-M-k" #'+selectrum/previous-candidate-preview
"C-S-k" #'selectrum-previous-page
"C-s-k" #'selectrum-goto-beginning)))