selectrum: refactor orderless use-package

This commit is contained in:
Itai Y. Efrat 2021-05-04 16:16:36 +03:00
parent fa527c00e8
commit 53e4e8c4d8

View file

@ -44,33 +44,28 @@
(use-package! orderless (use-package! orderless
:when (not (featurep! +prescient)) :when (not (featurep! +prescient))
:after selectrum :demand t
:init
(setq orderless-component-separator "[ &]"
orderless-matching-styles '(orderless-prefixes
orderless-initialism
orderless-regexp))
:config :config
(defun +selectrum--orderless-flex-if-twiddle (pattern _index _total) (defun +selectrum-orderless-dispatch (pattern _index _total)
(when (string-suffix-p "~" pattern) (cond
`(orderless-flex . ,(substring pattern 0 -1)))) ;; Support $ as regexp end-of-line
((string-suffix-p "$" pattern) `(orderless-regexp . ,(concat (substring pattern 0 -1) "[\x100000-\x10FFFD]*$")))
(defun +selectrum--orderless-first-initialism (pattern index _total) ;; Ignore single !
(if (= index 0) 'orderless-initialism)) ((string= "!" pattern) `(orderless-literal . ""))
;; Without literal
(defun +selectrum--orderless-without-if-bang (pattern _index _total) ((string-prefix-p "!" pattern) `(orderless-without-literal . ,(substring pattern 1)))
"Define a '!not' exclusion prefix for literal strings." ;; Literal
(when (string-prefix-p "!" pattern) ((string-suffix-p "=" pattern) `(orderless-literal . ,(substring pattern 0 -1)))
`(orderless-without-literal . ,(substring pattern 1)))) ;; Flex matching
((string-suffix-p "~" pattern) `(orderless-flex . ,(substring pattern 0 -1)))))
(setq completion-styles '(orderless) (setq completion-styles '(orderless)
orderless-skip-highlighting (lambda () selectrum-is-active) 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))))
orderless-style-dispatchers '(+selectrum-orderless-dispatch)
orderless-component-separator "[ &]"
selectrum-refine-candidates-function #'orderless-filter selectrum-refine-candidates-function #'orderless-filter
selectrum-highlight-candidates-function #'orderless-highlight-matches selectrum-highlight-candidates-function #'orderless-highlight-matches))
orderless-matching-styles '(orderless-regexp)
orderless-style-dispatchers '(+selectrum--orderless-flex-if-twiddle
+selectrum--orderless-first-initialism
+selectrum--orderless-without-if-bang)))
(use-package! consult (use-package! consult
:defer t :defer t