Skip to content

Commit

Permalink
Try replacing Selectrum with Vertico (#505)
Browse files Browse the repository at this point in the history
  • Loading branch information
raxod502 committed Oct 5, 2022
2 parents 9b5e551 + 98cf409 commit 7b6c23f
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 99 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
emacs_version: [26, 27, 28]
emacs_version: [27, 28]
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -44,5 +44,5 @@ clean: ## Remove build artifacts
@rm -f emacs/radian.elc

.PHONY: docker
docker: ## Start a Docker shell; e.g. make docker VERSION=26
docker: ## Start a Docker shell; e.g. make docker VERSION=27
@scripts/docker.bash "$(VERSION)" "$(CMD)"
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -24,7 +24,7 @@ more stability.

## Software configured, features

* [Emacs] (**minimum version supported: 26.1**)
* [Emacs] (**minimum version supported: 27.1**)
* Next-generation package manager, [`straight.el`][straight.el]
* Clean and DRY package customizations using
[`use-package`][use-package]
Expand Down
2 changes: 1 addition & 1 deletion emacs/init.el
Expand Up @@ -30,7 +30,7 @@ loading the init-file twice if it were not for this variable.")
(t
(setq radian--init-file-loaded-p t)

(defvar radian-minimum-emacs-version "26.1"
(defvar radian-minimum-emacs-version "27.1"
"Radian Emacs does not support any Emacs version below this.")

(defvar radian-local-init-file
Expand Down
195 changes: 103 additions & 92 deletions emacs/radian.el
Expand Up @@ -983,40 +983,61 @@ ourselves."
(setq input (car result))))
input))

;; Package `selectrum' is an incremental completion and narrowing
;; framework. Like Ivy and Helm, which it improves on, Selectrum
;; Package `vertico' is an incremental completion and narrowing
;; framework. Like Ivy and Helm, which it improves on, Vertico
;; provides a user interface for choosing from a list of options by
;; typing a query to narrow the list, and then selecting one of the
;; remaining candidates. This offers a significant improvement over
;; the default Emacs interface for candidate selection.
(radian-use-package selectrum
:straight (:host github :repo "raxod502/selectrum")
:defer t
:init
(radian-use-package vertico
:straight (:host github :repo "minad/vertico")
:demand t
:config

;; This doesn't actually load Selectrum.
(selectrum-mode +1))
(vertico-mode +1)

(radian-defadvice radian--advice-vertico-select-first-candidate (&rest _)
:after #'vertico--update-candidates
"Select first candidate rather than prompt by default.
Suggestion from https://github.com/minad/vertico/issues/272 about
how to recover previous Selectrum behavior, so that repeated TAB
navigates down a directory tree. Submit the prompt using M-TAB or
<up> RET."
(when (> vertico--total 0)
(setq vertico--index 0))))

;; Package `prescient' is a library for intelligent sorting and
;; filtering in various contexts.
(radian-use-package prescient
:demand t
:after vertico
:config

;; https://github.com/minad/vertico/wiki#using-prescientel-filtering-and-sorting

;; Remember usage statistics across Emacs sessions.
(prescient-persist-mode +1)

;; The default settings seem a little forgetful to me. Let's try
;; this out.
(setq prescient-history-length 1000))
(setq prescient-history-length 1000)

;; Package `selectrum-prescient' provides intelligent sorting and
;; filtering for candidates in Selectrum menus.
(radian-use-package selectrum-prescient
:demand t
:after selectrum
:config
;; Use prescient.el for filtering (`completion-styles') and sorting
;; (`vertico-sort-function').
(setq completion-styles '(prescient basic))
(setq vertico-sort-function #'prescient-completion-sort)

;; Common sense.
(setq prescient-sort-full-matches-first t)

(selectrum-prescient-mode +1))
(defun vertico-prescient-remember ()
"Remember the chosen candidate with Prescient."
(when (>= vertico--index 0)
(prescient-remember
(substring-no-properties
(nth vertico--index vertico--candidates)))))

(advice-add #'vertico-insert :after #'vertico-prescient-remember))

;;; Window management

Expand Down Expand Up @@ -1142,7 +1163,7 @@ active minibuffer, even if the minibuffer is not selected."
:bind-keymap* (("C-c p" . projectile-command-map))
:config

;; Use Selectrum (via `completing-read') for Projectile instead of
;; Use Vertico (via `completing-read') for Projectile instead of
;; IDO.
(setq projectile-completion-system 'default)

Expand Down Expand Up @@ -1580,49 +1601,48 @@ Interactively, reverse the characters in the current region."
;; for this, but I wrote this code before I knew about it. Also, I'm
;; not sure how well it handles the edge cases for docstrings and
;; such.
(radian-when-compiletime (version<= "26" emacs-version)
(radian-defadvice radian--advice-auto-fill-only-text (func &rest args)
:around #'internal-auto-fill
"Only perform auto-fill in text, comments, or docstrings."
(cl-block nil
;; Don't auto-fill on the first line of a docstring, since it
;; shouldn't be wrapped into the body.
(when (and (derived-mode-p #'emacs-lisp-mode)
(eq (get-text-property (point) 'face) 'font-lock-doc-face)
(save-excursion
(beginning-of-line)
(looking-at-p "[[:space:]]*\"")))
(cl-return))
(when (and (derived-mode-p 'text-mode)
(not (derived-mode-p 'yaml-mode)))
(apply func args)
(cl-return))
;; Inspired by <https://emacs.stackexchange.com/a/14716/12534>.
(when-let ((faces (save-excursion
;; In `web-mode', the end of the line isn't
;; fontified, so we have to step backwards
;; by one character before checking the
;; properties.
(ignore-errors
(backward-char))
(get-text-property (point) 'face))))
(unless (listp faces)
(setq faces (list faces)))
(when (cl-some
(lambda (face)
(memq face '(font-lock-comment-face
font-lock-comment-delimiter-face
font-lock-doc-face
web-mode-javascript-comment-face)))
faces)
;; Fill Elisp docstrings to the appropriate column. Why
;; docstrings are filled to a different column, I don't know.
(let ((fill-column (if (and
(derived-mode-p #'emacs-lisp-mode)
(memq 'font-lock-doc-face faces))
emacs-lisp-docstring-fill-column
fill-column)))
(apply func args)))))))
(radian-defadvice radian--advice-auto-fill-only-text (func &rest args)
:around #'internal-auto-fill
"Only perform auto-fill in text, comments, or docstrings."
(cl-block nil
;; Don't auto-fill on the first line of a docstring, since it
;; shouldn't be wrapped into the body.
(when (and (derived-mode-p #'emacs-lisp-mode)
(eq (get-text-property (point) 'face) 'font-lock-doc-face)
(save-excursion
(beginning-of-line)
(looking-at-p "[[:space:]]*\"")))
(cl-return))
(when (and (derived-mode-p 'text-mode)
(not (derived-mode-p 'yaml-mode)))
(apply func args)
(cl-return))
;; Inspired by <https://emacs.stackexchange.com/a/14716/12534>.
(when-let ((faces (save-excursion
;; In `web-mode', the end of the line isn't
;; fontified, so we have to step backwards
;; by one character before checking the
;; properties.
(ignore-errors
(backward-char))
(get-text-property (point) 'face))))
(unless (listp faces)
(setq faces (list faces)))
(when (cl-some
(lambda (face)
(memq face '(font-lock-comment-face
font-lock-comment-delimiter-face
font-lock-doc-face
web-mode-javascript-comment-face)))
faces)
;; Fill Elisp docstrings to the appropriate column. Why
;; docstrings are filled to a different column, I don't know.
(let ((fill-column (if (and
(derived-mode-p #'emacs-lisp-mode)
(memq 'font-lock-doc-face faces))
emacs-lisp-docstring-fill-column
fill-column)))
(apply func args))))))

(blackout 'auto-fill-mode)

Expand Down Expand Up @@ -2659,7 +2679,7 @@ order."

;; When there are multiple options for where a symbol might be
;; defined, use the default `completing-read' mechanism to decide
;; between them (i.e., delegate to Selectrum) rather than using the
;; between them (i.e., delegate to Vertico) rather than using the
;; janky built-in `xref' thingie.
(when (and
(boundp 'xref-show-definitions-function)
Expand Down Expand Up @@ -4077,7 +4097,6 @@ messages."
;; interacting with this data, including an agenda view, a time
;; clocker, etc. There are *many* extensions.
(use-package org
:functions (org-bookmark-jump-unhide) ; some issue with Emacs 26
:bind (:map org-mode-map

;; Prevent Org from overriding the bindings for
Expand Down Expand Up @@ -4993,7 +5012,7 @@ Also run `radian-atomic-chrome-setup-hook'."
(defvar radian--currently-profiling-p t)

;; Abbreviated (and flattened) version of init.el.
(defvar radian-minimum-emacs-version "26.1")
(defvar radian-minimum-emacs-version "27.1")
(defvar radian-local-init-file
(expand-file-name "init.local.el" user-emacs-directory))
(setq package-enable-at-startup nil)
Expand Down Expand Up @@ -5177,22 +5196,14 @@ This is passed to `set-frame-font'."
(setq which-key-echo-keystrokes echo-keystrokes))

;; Don't suggest shorter ways to type commands in M-x, since they
;; don't apply when using Selectrum.
;; don't apply when using Vertico.
(setq suggest-key-bindings 0)

;; Don't blink the cursor on the opening paren when you insert a
;; closing paren, as we already have superior handling of that from
;; Smartparens.
(setq blink-matching-paren nil)

(radian-defadvice radian--advice-read-passwd-hide-char (func &rest args)
:around #'read-passwd
"Display passwords as **** rather than .... in the minibuffer.
This is the default behavior is Emacs 27, so this advice only has
an effect for Emacs 26 or below."
(let ((read-hide-char (or read-hide-char ?*)))
(apply func args)))

(setq minibuffer-message-properties '(face minibuffer-prompt))

;; Disable the contextual menu that pops up when you right-click.
Expand Down Expand Up @@ -5349,32 +5360,32 @@ spaces."
:demand t
:config

;; Needed because `:no-require' for some reason disables the
;; load-time `require' invocation, as well as the compile-time
;; one.
(require 'zerodark-theme)

(let ((background-purple (if (true-color-p) "#48384c" "#5f5f5f"))
(class '((class color) (min-colors 89)))
(green (if (true-color-p) "#98be65" "#87af5f"))
(orange (if (true-color-p) "#da8548" "#d7875f"))
(purple (if (true-color-p) "#c678dd" "#d787d7")))
(custom-theme-set-faces
'zerodark
`(selectrum-current-candidate
((,class (:background
,background-purple
:weight bold
:foreground ,purple))))
`(selectrum-primary-highlight ((,class (:foreground ,orange))))
`(selectrum-secondary-highlight ((,class (:foreground ,green))))))
;; Needed because `:no-require' for some reason disables the
;; load-time `require' invocation, as well as the compile-time one.
(require 'zerodark-theme)

(let ((background-purple (if (true-color-p) "#48384c" "#5f5f5f"))
(class '((class color) (min-colors 89)))
(green (if (true-color-p) "#98be65" "#87af5f"))
(orange (if (true-color-p) "#da8548" "#d7875f"))
(purple (if (true-color-p) "#c678dd" "#d787d7")))
(custom-theme-set-faces
'zerodark
`(vertico-current
((,class (:background
,background-purple
:weight bold
:foreground ,purple))))
`(prescient-primary-highlight ((,class (:foreground ,orange))))
`(prescient-secondary-highlight ((,class (:foreground ,green))))
`(completions-common-part nil))

(dolist (face '(outline-1
outline-2
outline-3))
(set-face-attribute face nil :height 1.0))

(enable-theme 'zerodark))
(enable-theme 'zerodark)))

;; Make adjustments to color theme that was selected by Radian or
;; user. See <https://github.com/radian-software/radian/issues/456>.
Expand Down
6 changes: 3 additions & 3 deletions emacs/versions.el
@@ -1,7 +1,7 @@
(("Emacs-wgrep" . "f9687c28bbc2e84f87a479b6ce04407bb97cfb23")
("all-the-icons.el" . "6f876fa11ef64af20d9b2a44fdabac6446de51ba")
("apache-mode" . "f2c11aac2f5fc598123e04f4604bea248689a117")
("apheleia" . "8ff45766fad9b32f78aa99fa9ab11b715baa07f7")
("apheleia" . "7aa46ba84f06251f280d226f98cb06ef83a0a697")
("apples-mode" . "83a9ab0d6ba82496e2f7df386909b1a55701fccb")
("atomic-chrome" . "061958ab96c31085b5daf449b1d826b052777b59")
("auctex" . "53b82804c9dd9dbea306876f3be84ebacbeb7e74")
Expand Down Expand Up @@ -50,7 +50,7 @@
("json-snatcher" . "b28d1c0670636da6db508d03872d96ffddbc10f2")
("let-alist" . "592553db5929b54db40af0df90c5add0aaca045b")
("lsp-haskell" . "daa51072e1718ca075987901fccbbc2357bca1fc")
("lsp-mode" . "d9317f2f9e0ff08ec9fa7e93c2e4eeafa94c8b7e")
("lsp-mode" . "62a39447e03dc1d79c02e681c596e74ff4dde1e2")
("lsp-pyright" . "c745228f39fdb35372b29b909f25fa6c98dc7c88")
("lsp-ui" . "8d4fa5a14f5b5c6f57bc69f454eba6861ed2ba9f")
("lua-mode" . "d17a00ca50aee197cd017d573b83367eb241cc44")
Expand Down Expand Up @@ -82,7 +82,6 @@
("robe" . "993ae13791ba882076b644b0c8054b6e89e22dad")
("rust-mode" . "01ba44166cf16d9b78d99f2fa0c3c54c0f206894")
("s.el" . "08661efb075d1c6b4fa812184c1e5e90c08795a9")
("selectrum" . "810ea697bdd559d97b86b795e01769cddfa3daf2")
("sesman" . "e0f555f963c9f02f8e4a50e06fc353eb4c15ee77")
("smartparens" . "8b6a3c3b31afd5b3f846e09859b5fc62eb06e7c1")
("spinner" . "34905eae12a236753fa88abc831eff1e41e8576e")
Expand All @@ -97,6 +96,7 @@
("treepy.el" . "3ac940e97f3d03e48ca9d7fcd74916a9b01c72f3")
("undo-tree" . "16f4121032d09ef44b3d7d02c4d02c3c2f18041f")
("use-package" . "0ad5d9d5d8a61517a207ab04bf69e71c081149eb")
("vertico" . "8078b8cb940d6b2fe7578bc2e9c7cf1838cd092f")
("vimrc-mode" . "13bc150a870d5d4a95f1111e4740e2b22813c30e")
("visual-regexp-steroids.el" . "a6420b25ec0fbba43bf57875827092e1196d8a9e")
("visual-regexp.el" . "48457d42a5e0fe10fa3a9c15854f1f127ade09b5")
Expand Down

0 comments on commit 7b6c23f

Please sign in to comment.