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.
This commit is contained in:
2022-07-20 21:12:12 +01:00
parent 5784db0ff6
commit 92a6db71e6

View File

@@ -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