selectrum: add experimental vertico flag

This commit is contained in:
Itai Y. Efrat 2021-06-30 17:36:08 +03:00
parent 78955d8a64
commit d3eff82b9d
7 changed files with 90 additions and 20 deletions

View file

@ -28,6 +28,7 @@ TODO
instead of orderless.
** Plugins
[[https://github.com/minad/vertico][vertico]] (~+vertico~, experimental for the moment)
[[https://github.com/raxod502/selectrum][selectrum]]
[[https://github.com/minad/consult][consult]]
[[https://github.com/oantolin/embark/][embark]]

View file

@ -66,7 +66,32 @@ Do we want to have the annotations be more like ivy? e.g.
=:completion selectrum= is a bit of a misnomer. Selectrum is probably the
most easily replaceable part of the module as it can replaced with Vertico
fairly easily, other than losing the ~selectrum-repeat~ command. However,
naming is hard™. Best alternative I can think of is =:completion modular=.
naming is hard™. Best alternative I can think of is this:
#+begin_src emacs-lisp
:completion
;...
;ivy ;; a search engine for love and life
compleseus ;; a search engine with all the planks replaced
#+end_src
** TODO Consider dropping Selectrum in favor of Vertico:
To this end there is currently a ~+vertico~ flag to try it out, weird naming
aside. I want to do this for a few reasons:
*** Selectrum is more buggy
Selectrum has a few longstanding bugs that don't exist in Vertico, namely: [[https://github.com/raxod502/selectrum/issues/491][491]]
and [[https://github.com/raxod502/selectrum/issues/561][561]], as well as having worse handling when having lines of varying height
(important for good icon support).
*** Feature Comparison
- Minad, Vertico's author, provides a detailed comparison [[https://github.com/hlissner/doom-emacs/pull/4664#issuecomment-871524782][here]]. I will note
however that I was seriously considering the switch before he wrote this
comparison due to the frustration of dealing with the rough edges.
- Vertico doesn't support prescient, but I want to drop it anyway.
- The [[https://github.com/raxod502/selectrum#vertico][feature comparison]] in the selectrum readme has been updated to better
reflect the current state of affairs. Both Vertico and Selectrum have some
features that the other package lacks. In my mind Vertico's features are more
useful, but the feature difference is small enough for it to be less important
than the bugginess imo.
*** Vertico is more actively maintained
This might be a temporary concern, but still.
* PROJ HACKs to be addressed
** TODO ~fboundp~ issues

View file

@ -123,12 +123,24 @@ Supports exporting consult-grep to wgrep, file to wdeired, and consult-location
(defun +selectrum/next-candidate-preview ()
"Move to next candidate and preivew it"
(interactive)
(selectrum-next-candidate)
(if (featurep! :completion selectrum +vertico)
(vertico-next)
(selectrum-next-candidate))
(+selectrum/embark-preview))
;;;###autoload
(defun +selectrum/previous-candidate-preview ()
"Move to previous candidate and preview it"
(interactive)
(selectrum-previous-candidate)
(if (featurep! :completion selectrum +vertico)
(vertico-previous)
(selectrum-previous-candidate))
(+selectrum/embark-preview))
;;;###autoload
(defun +selectrum/repeat ()
"Repeat the last selectrum/vertico command."
(interactive)
(if (featurep! :completion selectrum +vertico)
(user-error "The vertico flag doesn't support repeating commands (yet)")
(selectrum-repeat)))

View file

@ -1,6 +1,7 @@
;;; completion/selectrum/config.el -*- lexical-binding: t; -*-
(use-package! selectrum
:when (not (featurep! +vertico))
:hook (doom-first-input . selectrum-mode)
:init
(setq selectrum-extend-current-candidate-highlight t
@ -12,6 +13,17 @@
(map! :map selectrum-minibuffer-map
[backspace] #'+selectrum/backward-updir))
(use-package! vertico
:when (featurep! +vertico)
:hook (doom-first-input . vertico-mode)
:init
(setq vertico-resize nil
vertico-count 17
vertico-cycle t)
:config
(map! :map vertico-map
[backspace] #'+selectrum/backward-updir))
(use-package! selectrum-prescient
:when (featurep! +prescient)
:hook (selectrum-mode . selectrum-prescient-mode)
@ -41,11 +53,14 @@
(setq completion-styles '(orderless)
completion-category-defaults nil
;; note that despite override in the name orderless can still be used in find-file etc.
completion-category-overrides '((file (styles . (partial-completion))))
completion-category-overrides '((file (styles . (orderless partial-completion))))
orderless-style-dispatchers '(+selectrum-orderless-dispatch)
orderless-component-separator "[ &]"
selectrum-refine-candidates-function #'orderless-filter
selectrum-highlight-candidates-function #'orderless-highlight-matches))
orderless-component-separator "[ &]")
;; otherwise find-file gets different highlighting than other commands
(set-face-attribute 'completions-first-difference nil :inherit nil)
(unless (featurep! +vertico)
(setq selectrum-refine-candidates-function #'orderless-filter
selectrum-highlight-candidates-function #'orderless-highlight-matches)))
(use-package! consult
:defer t

View file

@ -1,7 +1,11 @@
;; -*- no-byte-compile: t; -*-
;;; completion/selectrum/packages.el
(package! selectrum :pin "a19bbe94de492bf504399c093cfc5695eb630fa8")
(if (featurep! +vertico)
(package! vertico
:recipe (:host github :repo "minad/vertico")
:pin "c9157759a015ac32cb299c18c84c6d5fb34e0aa1")
(package! selectrum :pin "a19bbe94de492bf504399c093cfc5695eb630fa8"))
(if (featurep! +prescient)
(package! selectrum-prescient :pin "4a0f5405798cfcb98ea005078ef2e2d490e922c4")

View file

@ -464,7 +464,7 @@
"C-S-s" #'swiper-helm
"C-S-r" #'helm-resume)
(:when (featurep! :completion selectrum)
"C-S-r" #'selectrum-repeat)
"C-S-r" #'+selectrum/repeat)
;;; objed
(:when (featurep! :editor objed +manual)

View file

@ -204,16 +204,29 @@
[C-return] #'helm-grep-run-other-window-action))
(:when (featurep! :completion selectrum)
(: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-preview
"C-S-j" #'selectrum-next-page
"C-k" #'selectrum-previous-candidate
"C-M-k" #'+selectrum/previous-candidate-preview
"C-S-k" #'selectrum-previous-page)))
(:when (featurep! :completion selectrum +vertico)
(:after vertico
:map vertico-map
"M-RET" #'vertico-exit-input
"C-SPC" #'+selectrum/embark-preview
"C-j" #'vertico-next
"C-M-j" #'+selectrum/next-candidate-preview
"C-S-j" #'vertico-next-group
"C-k" #'vertico-previous
"C-M-k" #'+selectrum/previous-candidate-preview
"C-S-k" #'vertico-previous-group))
(:when (not (featurep! :completion selectrum +vertico))
(: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-preview
"C-S-j" #'selectrum-next-page
"C-k" #'selectrum-previous-candidate
"C-M-k" #'+selectrum/previous-candidate-preview
"C-S-k" #'selectrum-previous-page))))
;;; :ui
(map! (:when (featurep! :ui popup)
@ -305,7 +318,7 @@
:desc "Resume last search" "'"
(cond ((featurep! :completion ivy) #'ivy-resume)
((featurep! :completion helm) #'helm-resume)
((featurep! :completion selectrum) #'selectrum-repeat))
((featurep! :completion selectrum) #'+selectrum/repeat))
:desc "Search for symbol in project" "*" #'+default/search-project-for-symbol-at-point
:desc "Search project" "/" #'+default/search-project