From 5656e397de013e1c2b1667b9d2cca8b4b75c1824 Mon Sep 17 00:00:00 2001 From: "Itai Y. Efrat" Date: Sun, 16 May 2021 03:18:13 +0300 Subject: [PATCH] selectrum: rework orderless style dispatchers - make all markers both prefixes and suffixes - add `\`` affix for initialism - add initialism matching to be on by default in `symbol` and `command` - category completions --- modules/completion/selectrum/README.org | 16 +++++++++------- modules/completion/selectrum/config.el | 18 +++++++++++++++--- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/modules/completion/selectrum/README.org b/modules/completion/selectrum/README.org index d51a0f6b7..a135dc796 100644 --- a/modules/completion/selectrum/README.org +++ b/modules/completion/selectrum/README.org @@ -150,10 +150,12 @@ A wgrep buffer can be opened from swiper with =C-c C-e=. ** Orderless filtering When using orderless to filter through candidates, the default behaviour is for each space separated inputs to match the candidate as a regular expression or -literally. You can further specify each space separated input in the following -ways: -| Input | Description | -|--------+--------------------------------------------| -| =!foo= | match without literal input =foo= | -| =bar== | match only with literal input =foo= | -| =baz~= | match input =foo= with fuzzy/flex matching | +literally. In ~command~ and ~symbol~ category searches such as =SPC h f= and =SPC +h v=, matching by initialism is also on by default. You can further specify each +space separated input in the following ways: +| Input | Description | +|------------------+--------------------------------------------| +| =!foo= or =foo!= | match without literal input =foo= | +| =`bar= or =bar`= | match input =bar= as an initialism | +| ==baz= or =baz== | match only with literal input =baz= | +| =~qux= or =qux~= | match input =qux= with fuzzy/flex matching | diff --git a/modules/completion/selectrum/config.el b/modules/completion/selectrum/config.el index 221bb4976..2d5e447e6 100644 --- a/modules/completion/selectrum/config.el +++ b/modules/completion/selectrum/config.el @@ -49,20 +49,32 @@ :config (defun +selectrum-orderless-dispatch (pattern _index _total) (cond - ;; Support $ as regexp end-of-line + ;; Ensure that $ works with Consult commands, which add disambiguation suffixes ((string-suffix-p "$" pattern) `(orderless-regexp . ,(concat (substring pattern 0 -1) "[\x100000-\x10FFFD]*$"))) ;; Ignore single ! ((string= "!" pattern) `(orderless-literal . "")) ;; Without literal ((string-prefix-p "!" pattern) `(orderless-without-literal . ,(substring pattern 1))) - ;; Literal + ((string-suffix-p "!" pattern) `(orderless-without-literal . ,(substring pattern 0 -1))) + ;; Initialism matching + ((string-prefix-p "`" pattern) `(orderless-initialism . ,(substring pattern 1))) + ((string-suffix-p "`" pattern) `(orderless-initialism . ,(substring pattern 0 -1))) + ;; Literal matching + ((string-prefix-p "=" pattern) `(orderless-literal . ,(substring pattern 1))) ((string-suffix-p "=" pattern) `(orderless-literal . ,(substring pattern 0 -1))) ;; Flex matching + ((string-prefix-p "~" pattern) `(orderless-flex . ,(substring pattern 1))) ((string-suffix-p "~" pattern) `(orderless-flex . ,(substring pattern 0 -1))))) + (orderless-define-completion-style orderless+initialism + (orderless-matching-styles '(orderless-initialism + orderless-literal + orderless-regexp))) (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 . (partial-completion))) + (command (styles orderless+initialism)) + (symbol (styles orderless+initialism))) orderless-style-dispatchers '(+selectrum-orderless-dispatch) orderless-component-separator "[ &]" selectrum-refine-candidates-function #'orderless-filter