From 92a6db71e61429ade2ed5f0e0b38d3781132899d Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Wed, 20 Jul 2022 21:12:12 +0100 Subject: [PATCH] fix(editor): correctly filter buffer results from consult-buffer It seems the string candidates produced by consult-buffer have some extra non-printable bytes appended at the end. These bytes makes flx-rs not match against the candidate properly. Consult does add a text property to the candidate string called 'buffer, which contains the original buffer name. So for now, we advice the flx-rs-score function and attempt to the extract the buffer text property from the input candidate and use that instead. If the candidate has no such text property, we use it as is. --- modules/editor/siren-fussy.el | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/modules/editor/siren-fussy.el b/modules/editor/siren-fussy.el index 55af804..2cf7d0f 100644 --- a/modules/editor/siren-fussy.el +++ b/modules/editor/siren-fussy.el @@ -18,7 +18,21 @@ (use-package flx-rs :straight (flx-rs :repo "jcs-elpa/flx-rs" :fetcher github :files (:defaults "bin")) + :preface + (defun siren-flx-rs-score-consult-buffer-fix (orig-fun str query &rest args) + "Fix input string provided by consult-buffer to be compatible with flx-rs. + +Consult buffer adds some extra bytes at the end of input +candidates which causes flx-rs to not match some inputs +correctly. This function will attempt to extract buffer name from +text properties added by consult-buffer, or fallback on the input +string as provided." + (let* ((props (text-properties-at 0 str)) + (buffer (if props (alist-get 'buffer props)))) + (apply orig-fun (or buffer str) query args))) + :config + (advice-add 'flx-rs-score :around 'siren-flx-rs-score-consult-buffer-fix) (flx-rs-load-dyn)) (use-package fussy