summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRavi R Kiran <aine.marina@gmail.com>2022-04-16 00:44:44 (GMT)
committerRavi R Kiran <aine.marina@gmail.com>2022-04-16 00:44:44 (GMT)
commitece9d8ece8e98782460da79ab0f2cf428e8f815a (patch)
tree53644e3ec876955b899a6200cf70c1be8a5ae203
parent37327f3bf04a423ef886c6c73c9c2762ef6e69fd (diff)
downloaddotemacs-ece9d8ece8e98782460da79ab0f2cf428e8f815a.zip
dotemacs-ece9d8ece8e98782460da79ab0f2cf428e8f815a.tar.gz
dotemacs-ece9d8ece8e98782460da79ab0f2cf428e8f815a.tar.bz2
Replace selectrum with vertico
-rw-r--r--init.el4
-rw-r--r--lisp/ravi-init-completion.el73
2 files changed, 73 insertions, 4 deletions
diff --git a/init.el b/init.el
index 4909704..b558716 100644
--- a/init.el
+++ b/init.el
@@ -72,8 +72,10 @@
(require 'diminish)
(setq use-package-always-ensure t
use-package-hook-name-suffix nil)
+;; (setq use-package-verbose t
+;; use-package-compute-statistics t)
-(defvar ravi/use-selection-system 'selectrum
+(defvar ravi/use-selection-system 'vertico
"Valid values are 'ido 'helm 'selectrum 'vertico")
(when (file-exists-p (ravi/emacs-file "local.el"))
diff --git a/lisp/ravi-init-completion.el b/lisp/ravi-init-completion.el
index 95f49ca..2e548e8 100644
--- a/lisp/ravi-init-completion.el
+++ b/lisp/ravi-init-completion.el
@@ -34,10 +34,67 @@
(use-package orderless
:if (member ravi/use-selection-system '(selectrum vertico))
- :custom (completion-styles '(orderless))
:config
(when (equal ravi/use-selection-system 'selectrum)
- (setq orderless-skip-highlighting (lambda () selectrum-is-active))))
+ (setq completion-styles '(orderless))
+ (setq orderless-skip-highlighting (lambda () selectrum-is-active)))
+ (when (equal ravi/use-selection-system 'vertico)
+ ;; From the consult wiki: https://github.com/minad/consult/wiki
+ (defvar +orderless-dispatch-alist
+ '((?% . char-fold-to-regexp)
+ (?! . orderless-without-literal)
+ (?`. orderless-initialism)
+ (?= . orderless-literal)
+ (?~ . orderless-flex)))
+
+ ;; Recognizes the following patterns:
+ ;; * ~flex flex~
+ ;; * =literal literal=
+ ;; * %char-fold char-fold%
+ ;; * `initialism initialism`
+ ;; * !without-literal without-literal!
+ ;; * .ext (file extension)
+ ;; * regexp$ (regexp matching at end)
+ (defun +orderless-dispatch (pattern index _total)
+ (cond
+ ;; Ensure that $ works with Consult commands, which add disambiguation suffixes
+ ((string-suffix-p "$" pattern)
+ `(orderless-regexp . ,(concat (substring pattern 0 -1) "[\x200000-\x300000]*$")))
+ ;; File extensions
+ ((and
+ ;; Completing filename or eshell
+ (or minibuffer-completing-file-name
+ (derived-mode-p 'eshell-mode))
+ ;; File extension
+ (string-match-p "\\`\\.." pattern))
+ `(orderless-regexp . ,(concat "\\." (substring pattern 1) "[\x200000-\x300000]*$")))
+ ;; Ignore single !
+ ((string= "!" pattern) `(orderless-literal . ""))
+ ;; Prefix and suffix
+ ((if-let (x (assq (aref pattern 0) +orderless-dispatch-alist))
+ (cons (cdr x) (substring pattern 1))
+ (when-let (x (assq (aref pattern (1- (length pattern))) +orderless-dispatch-alist))
+ (cons (cdr x) (substring pattern 0 -1)))))))
+
+ ;; Define orderless style with initialism by default
+ (orderless-define-completion-style +orderless-with-initialism
+ (orderless-matching-styles '(orderless-initialism orderless-literal orderless-regexp)))
+ (setq completion-styles '(orderless basic)
+ completion-category-defaults nil
+ ;;; Enable partial-completion for files.
+ ;;; Either give orderless precedence or partial-completion.
+ ;;; Note that completion-category-overrides is not really an override,
+ ;;; but rather prepended to the default completion-styles.
+ ;; completion-category-overrides '((file (styles orderless partial-completion))) ;; orderless is tried first
+ completion-category-overrides '((file (styles partial-completion)) ;; partial-completion is tried first
+ ;; enable initialism by default for symbols
+ (command (styles +orderless-with-initialism))
+ (variable (styles +orderless-with-initialism))
+ (symbol (styles +orderless-with-initialism)))
+ orderless-component-separator #'orderless-escapable-split-on-space ;; allow escaping space with backslash!
+ orderless-style-dispatchers '(+orderless-dispatch))
+ )
+ )
(use-package selectrum
:if (equal ravi/use-selection-system 'selectrum)
@@ -67,7 +124,17 @@
(use-package vertico
:if (equal ravi/use-selection-system 'vertico)
:init
- (vertico-mode))
+ (vertico-mode)
+ :config
+ (bind-key [remap forward-list] 'vertico-next-group)
+ (bind-key [remap backward-list] 'vertico-previous-group)
+ (defun +vertico-crm-exit ()
+ (interactive)
+ (run-at-time 0 nil #'vertico-exit)
+ (funcall #'vertico-exit))
+ (with-eval-after-load "consult"
+ (define-key consult-crm-map "\r" #'+vertico-crm-exit)
+ (define-key consult-crm-map "\t" #'vertico-exit)))
(defun ravi/bind-key-selection-system-map (key func)
"Bind to appropriate minibuffer completion map"