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
This commit is contained in:
Itai Y. Efrat 2021-05-16 03:18:13 +03:00
parent 2945d2dd33
commit 5656e397de
2 changed files with 24 additions and 10 deletions

View file

@ -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 |

View file

@ -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