feat(vertico): allow affixes to be escaped

So we can search for "modulep\!" without it triggering the ! dispatcher.
This commit is contained in:
Henrik Lissner 2024-09-12 20:52:21 -04:00
parent 41987bb00f
commit b9eb662334
No known key found for this signature in database
GPG key ID: B60957CA074D39A3
2 changed files with 28 additions and 9 deletions

View file

@ -237,3 +237,27 @@ See minad/consult#770."
(defun +vertico-basic-remote-all-completions (string table pred point)
(and (vertico--remote-p string)
(completion-basic-all-completions string table pred point)))
;;;###autoload
(defun +vertico-orderless-dispatch (pattern _index _total)
"Like `orderless-affix-dispatch', but allows affixes to be escaped."
(let ((len (length pattern))
(alist orderless-affix-dispatch-alist))
(when (> len 0)
(cond
;; Ignore single dispatcher character
((and (= len 1) (alist-get (aref pattern 0) alist)) #'ignore)
;; Prefix
((when-let ((style (alist-get (aref pattern 0) alist))
((not (char-equal (aref pattern (max (1- len) 1)) ?\\))))
(cons style (substring pattern 1))))
;; Suffix
((when-let ((style (alist-get (aref pattern (1- len)) alist))
((not (char-equal (aref pattern (max 0 (- len 2))) ?\\))))
(cons style (substring pattern 0 -1))))))))
;;;###autoload
(defun +vertico-orderless-disambiguation-dispatch (pattern _index _total)
"Ensure $ works with Consult commands, which add disambiguation suffixes."
(when (char-equal (aref pattern (1- (length pattern))) ?$)
`(orderless-regexp . ,(concat (substring pattern 0 -1) "[\x200000-\x300000]*$"))))

View file

@ -81,15 +81,10 @@ orderless."
(?` . orderless-initialism)
(?= . orderless-literal)
(?^ . orderless-literal-prefix)
(?~ . orderless-flex)))
(defun +vertico-orderless-dispatch (pattern _index _total)
(cond
;; Ensure $ works with Consult commands, which add disambiguation suffixes
((string-suffix-p "$" pattern)
`(orderless-regexp . ,(concat (substring pattern 0 -1) "[\x200000-\x300000]*$")))))
(add-to-list 'orderless-style-dispatchers '+vertico-orderless-dispatch)
(?~ . orderless-flex))
orderless-style-dispatchers
'(+vertico-orderless-dispatch
+vertico-orderless-disambiguation-dispatch))
(add-to-list
'completion-styles-alist