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
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]*$"))))