fix(vertico): orderless filtering

The original implementation of `+vertico-orderless-dispatch` match
pattern by prefix and suffix in pairs. In that case, '=&&' will go for
branch `(string-suffix-p "&" pattern)`, not `(string-prefix-p "="
pattern)`, which fail to filter literal '&&'.

We probably should match all prefixes first, then all suffixes. Just
like orderless does.

Ref: 178b0c55f2/orderless.el (L159)
This commit is contained in:
Wang Kai 2024-07-12 20:09:02 +08:00 committed by Henrik Lissner
parent db48f767b0
commit 3ad8ecc063

View file

@ -74,30 +74,23 @@ orderless."
(completion-styles +vertico-company-completion-styles)) (completion-styles +vertico-company-completion-styles))
(apply fn args))) (apply fn args)))
(setq orderless-affix-dispatch-alist
`((?! . ,#'orderless-without-literal)
(?& . ,#'orderless-annotation)
(?% . ,#'char-fold-to-regexp)
(?` . ,#'orderless-initialism)
(?= . ,#'orderless-literal)
(?^ . ,#'orderless-literal-prefix)
(?~ . ,#'orderless-flex)))
(defun +vertico-orderless-dispatch (pattern _index _total) (defun +vertico-orderless-dispatch (pattern _index _total)
(cond (cond
;; Ensure $ works with Consult commands, which add disambiguation suffixes ;; Ensure $ works with Consult commands, which add disambiguation suffixes
((string-suffix-p "$" pattern) ((string-suffix-p "$" pattern)
`(orderless-regexp . ,(concat (substring pattern 0 -1) "[\x200000-\x300000]*$"))) `(orderless-regexp . ,(concat (substring pattern 0 -1) "[\x200000-\x300000]*$")))))
;; Ignore single !
((string= "!" pattern) `(orderless-literal . "")) (add-to-list 'orderless-style-dispatchers '+vertico-orderless-dispatch)
;; Without literal
((string-prefix-p "!" pattern) `(orderless-without-literal . ,(substring pattern 1)))
;; Annotation
((string-prefix-p "&" pattern) `(orderless-annotation . ,(substring pattern 1)))
((string-suffix-p "&" pattern) `(orderless-annotation . ,(substring pattern 0 -1)))
;; Character folding
((string-prefix-p "%" pattern) `(char-fold-to-regexp . ,(substring pattern 1)))
((string-suffix-p "%" pattern) `(char-fold-to-regexp . ,(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)))))
(add-to-list (add-to-list
'completion-styles-alist 'completion-styles-alist
'(+vertico-basic-remote '(+vertico-basic-remote
@ -109,7 +102,6 @@ orderless."
;; note that despite override in the name orderless can still be used in ;; note that despite override in the name orderless can still be used in
;; find-file etc. ;; find-file etc.
completion-category-overrides '((file (styles +vertico-basic-remote orderless partial-completion))) completion-category-overrides '((file (styles +vertico-basic-remote orderless partial-completion)))
orderless-style-dispatchers '(+vertico-orderless-dispatch)
orderless-component-separator #'orderless-escapable-split-on-space) orderless-component-separator #'orderless-escapable-split-on-space)
;; ...otherwise find-file gets different highlighting than other commands ;; ...otherwise find-file gets different highlighting than other commands
(set-face-attribute 'completions-first-difference nil :inherit nil)) (set-face-attribute 'completions-first-difference nil :inherit nil))