From b70ecb4ba0d300807488ba4fc9813900eead9436 Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Fri, 24 Feb 2023 08:21:40 +0100 Subject: [PATCH] Add a vertico module --- CHANGELOG.md | 1 + docs/installation.md | 2 +- docs/modules/index.md | 1 + modules/prelude-vertico.el | 124 +++++++++++++++++++++++++++++++++++++ sample/prelude-modules.el | 2 +- 5 files changed, 128 insertions(+), 2 deletions(-) create mode 100644 modules/prelude-vertico.el diff --git a/CHANGELOG.md b/CHANGELOG.md index 20b04a1..f8f9c79 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ * Auto-install `racket-mode` if needed. * Add a F# module. * Auto-install `use-package`. +* Add `prelude-vertico` module. Vertico a simpler alternative to `ivy-mode` and supersedes Selectrum. ### Changes diff --git a/docs/installation.md b/docs/installation.md index f1b9abe..e9dafa0 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -117,7 +117,7 @@ modules visit the [docs](modules/index.md). ;; (require 'prelude-ido) ;; Supercharges Emacs completion for C-x C-f and more (require 'prelude-ivy) ;; A mighty modern alternative to ido -;; (require 'prelude-selectrum) ;; A powerful, yet simple, alternative to ivy +;; (require 'prelude-vertico) ;; A powerful, yet simple, alternative to ivy ;; (require 'prelude-helm) ;; Interface for narrowing and search ;; (require 'prelude-helm-everywhere) ;; Enable Helm everywhere (require 'prelude-company) diff --git a/docs/modules/index.md b/docs/modules/index.md index c1d3d26..f2fbed9 100644 --- a/docs/modules/index.md +++ b/docs/modules/index.md @@ -100,3 +100,4 @@ The following programming languages have enhanced support in Prelude: - key-chord - Org Mode - selectrum +- vertico diff --git a/modules/prelude-vertico.el b/modules/prelude-vertico.el new file mode 100644 index 0000000..c2ca75a --- /dev/null +++ b/modules/prelude-vertico.el @@ -0,0 +1,124 @@ +;;; prelude-vertico.el --- Vertico setup +;; +;; Copyright © 2011-2023 Bozhidar Batsov +;; +;; Author: Bozhidar Batsov +;; URL: https://github.com/bbatsov/prelude + +;; This file is not part of GNU Emacs. + +;;; Commentary: + +;; Vertico-related config. Vertico is a smart framework for minibuffer +;; completion/filtering/selection (think of ivy/ido). + +;;; License: + +;; This program is free software; you can redistribute it and/or +;; modify it under the terms of the GNU General Public License +;; as published by the Free Software Foundation; either version 3 +;; of the License, or (at your option) any later version. +;; +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. +;; +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs; see the file COPYING. If not, write to the +;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +;; Boston, MA 02110-1301, USA. + +;; Enable vertico +(use-package vertico + :ensure t + :init + (vertico-mode) + + ;; Different scroll margin + ;; (setq vertico-scroll-margin 0) + + ;; Show more candidates + ;; (setq vertico-count 20) + + ;; Grow and shrink the Vertico minibuffer + ;; (setq vertico-resize t) + + ;; Optionally enable cycling for `vertico-next' and `vertico-previous'. + ;; (setq vertico-cycle t) + ) + +;; A few more useful configurations for Vertico +(use-package emacs + :init + ;; Add prompt indicator to `completing-read-multiple'. + ;; We display [CRM], e.g., [CRM,] if the separator is a comma. + (defun crm-indicator (args) + (cons (format "[CRM%s] %s" + (replace-regexp-in-string + "\\`\\[.*?]\\*\\|\\[.*?]\\*\\'" "" + crm-separator) + (car args)) + (cdr args))) + (advice-add #'completing-read-multiple :filter-args #'crm-indicator) + + ;; Do not allow the cursor in the minibuffer prompt + (setq minibuffer-prompt-properties + '(read-only t cursor-intangible t face minibuffer-prompt)) + (add-hook 'minibuffer-setup-hook #'cursor-intangible-mode) + + ;; Emacs 28: Hide commands in M-x which do not work in the current mode. + ;; Vertico commands are hidden in normal buffers. + ;; (setq read-extended-command-predicate + ;; #'command-completion-default-include-p) + + ;; Enable recursive minibuffers + (setq enable-recursive-minibuffers t)) + +;; use the `orderless' completion style. +(use-package orderless + :ensure t + :init + ;; Configure a custom style dispatcher (see the Consult wiki) + ;; (setq orderless-style-dispatchers '(+orderless-dispatch) + ;; orderless-component-separator #'orderless-escapable-split-on-space) + (setq completion-styles '(orderless basic) + completion-category-defaults nil + completion-category-overrides '((file (styles partial-completion))))) + +(use-package consult + :ensure t + :bind ( + ;; C-x bindings (ctl-x-map) + ("C-x M-:" . consult-complex-command) ;; orig. repeat-complex-command + ("C-x b" . consult-buffer) ;; orig. switch-to-buffer + ("C-x 4 b" . consult-buffer-other-window) ;; orig. switch-to-buffer-other-window + ("C-x 5 b" . consult-buffer-other-frame) ;; orig. switch-to-buffer-other-frame + ;; Custom M-# bindings for fast register access + ("M-#" . consult-register-load) + ("M-'" . consult-register-store) ;; orig. abbrev-prefix-mark (unrelated) + ("C-M-#" . consult-register) + ;; Other custom bindings + ("M-y" . consult-yank-pop) ;; orig. yank-pop + (" a" . consult-apropos) ;; orig. apropos-command + ;; M-g bindings (goto-map) + ("M-g e" . consult-compile-error) + ("M-g f" . consult-flycheck) + ("M-g g" . consult-goto-line) ;; orig. goto-line + ("M-g M-g" . consult-goto-line) ;; orig. goto-line + ("M-g o" . consult-outline) ;; Alternative: consult-org-heading + ("M-g m" . consult-mark) + ("M-g k" . consult-global-mark) + ("M-g i" . consult-imenu) + ("M-g I" . consult-imenu-multi) + ;; M-s bindings (search-map) + ("M-s f" . consult-find) + ("M-s F" . consult-locate) + ("M-s g" . consult-grep) + ("M-s G" . consult-git-grep) + ("M-s r" . consult-ripgrep) + ("M-s l" . consult-line) + ("M-s L" . consult-line-multi) + ("M-s m" . consult-multi-occur) + ("M-s k" . consult-keep-lines) + ("M-s u" . consult-focus-lines))) diff --git a/sample/prelude-modules.el b/sample/prelude-modules.el index 6f11b42..eaee425 100644 --- a/sample/prelude-modules.el +++ b/sample/prelude-modules.el @@ -43,7 +43,7 @@ ;; (require 'prelude-ido) ;; Supercharges Emacs completion for C-x C-f and more (require 'prelude-ivy) ;; A mighty modern alternative to ido -;; (require 'prelude-selectrum) ;; A powerful, yet simple, alternative to ivy +;; (require 'prelude-vertico) ;; A powerful, yet simple, alternative to ivy ;; (require 'prelude-helm) ;; Interface for narrowing and search ;; (require 'prelude-helm-everywhere) ;; Enable Helm everywhere (require 'prelude-company)