branch: externals/consult commit 36ac62c7de467dd8f677421a6366bd17f7c8446d Author: Daniel Mendler <m...@daniel-mendler.de> Commit: Daniel Mendler <m...@daniel-mendler.de>
Optimize consult--completion-filter --- consult-vertico.el | 14 ++++++++++++++ consult.el | 6 ++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/consult-vertico.el b/consult-vertico.el index 98f8e99..5e20143 100644 --- a/consult-vertico.el +++ b/consult-vertico.el @@ -32,6 +32,7 @@ (defvar vertico--lock-candidate) (declare-function vertico--exhibit "ext:vertico") (declare-function vertico--candidate "ext:vertico") +(declare-function vertico--all-completions "ext:vertico") (defun consult-vertico--candidate () "Return current candidate for Consult preview." @@ -46,6 +47,19 @@ vertico--lock-candidate nil)) (vertico--exhibit))) +(defun consult-vertico--filter-adv (orig pattern cands category highlight) + "Advice for ORIG `consult--completion-filter' function. +See `consult--completion-filter' for arguments PATTERN, CANDS, CATEGORY +and HIGHLIGHT." + (if (and (bound-and-true-p vertico-mode) (not highlight)) + ;; Optimize `consult--completion-filter' using the deferred highlighting + ;; from Vertico. The advice is not necessary - it is a pure optimization. + (nconc (car (vertico--all-completions pattern cands nil (length pattern) + `(metadata (category . ,category)))) + nil) + (funcall orig pattern cands category highlight))) + +(advice-add #'consult--completion-filter :around #'consult-vertico--filter-adv) (add-hook 'consult--completion-candidate-hook #'consult-vertico--candidate) (add-hook 'consult--completion-refresh-hook #'consult-vertico--refresh) (define-key consult-async-map [remap vertico-insert] 'vertico-next-group) diff --git a/consult.el b/consult.el index dbb69e4..3d96262 100644 --- a/consult.el +++ b/consult.el @@ -702,10 +702,8 @@ CATEGORY is the completion category, used to find the completion style via HIGHLIGHT must be non-nil if the resulting strings should be highlighted." ;; completion-all-completions returns an improper list ;; where the last link is not necessarily nil. - ;; TODO Implement support to disable highlighting as in Vertico deferred highlighting. - (nconc (completion-all-completions - pattern cands nil (length pattern) - `(metadata (category . ,category))) + (nconc (completion-all-completions pattern cands nil (length pattern) + `(metadata (category . ,category))) nil)) (defun consult--completion-filter-complement (pattern cands category _highlight)