Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple word support #24

Open
kim366 opened this issue Jan 22, 2025 · 0 comments
Open

Multiple word support #24

kim366 opened this issue Jan 22, 2025 · 0 comments

Comments

@kim366
Copy link

kim366 commented Jan 22, 2025

Hello, thank you for this great package! It has been fun to use and I love how it can read my mind.

I do find myself wanting to narrow my search by adding a second query. For a long time, I have tried combining hotfuzz with orderless, fussy, my own experimental algorithms, etc.

But what I have found most natural, is to split the query (needle) into words, then calculating hotfuzz--cost on each and summing the result. For a single-word query, nothing changes and each additional word narrows the results as expected.

Here is my horribly inefficient proof-of-concept code:

(defun my/completion-all-completions (string table pred &optional point)
  (let ((words (string-split string)))
    (cl-loop for (cost . candidate) in (sort (cl-loop for candidate in (all-completions "" table pred)
                                                      with candidate-copy = candidate
                                                      for cost = (cl-loop for word in words
                                                                          for cost = (hotfuzz--cost word candidate)
                                                                          if (>= cost 9000) return nil
                                                                          sum cost)
                                                      unless (null cost) do (setq candidate-copy (substring candidate))
                                                      and do (cl-loop for word in words
                                                                      do (hotfuzz-highlight word candidate-copy))
                                                      and collect (cons cost candidate-copy))
                                             'car-less-than-car)
             collect candidate)))

(put 'my/completion 'completion--adjust-metadata 'hotfuzz--adjust-metadata)
(cl-pushnew '(my/completion completion-flex-try-completion my/completion-all-completions "Custom completion style") completion-styles-alist)
(setq completion-styles '(my/completion))

As soon as we allow more than one word, we open up a world of possible semantics, so this has to be carefully chosen. This code, for example, doesn't do well when the words have characters in common, as the following words' characters are "eaten". This could be addressed by ranking results with a higher count of match characters higher. I will try this when I find time.

Thoughts on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant