From b9eb6623347a0cbbb721bd1175fc2d5479d01657 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Thu, 12 Sep 2024 20:52:21 -0400 Subject: [PATCH] feat(vertico): allow affixes to be escaped So we can search for "modulep\!" without it triggering the ! dispatcher. --- .../completion/vertico/autoload/vertico.el | 24 +++++++++++++++++++ modules/completion/vertico/config.el | 13 ++++------ 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/modules/completion/vertico/autoload/vertico.el b/modules/completion/vertico/autoload/vertico.el index 7689a18bb..2ed8a7d97 100644 --- a/modules/completion/vertico/autoload/vertico.el +++ b/modules/completion/vertico/autoload/vertico.el @@ -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]*$")))) diff --git a/modules/completion/vertico/config.el b/modules/completion/vertico/config.el index b0a5e7a16..94e8581d5 100644 --- a/modules/completion/vertico/config.el +++ b/modules/completion/vertico/config.el @@ -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