axelf4 / hotfuzz

🚓 Fuzzy Emacs completion style
GNU General Public License v3.0
98 stars 4 forks source link

Most recent first #1

Closed CGenie closed 3 years ago

CGenie commented 3 years ago

Hello, When using orderless (or in fact any other completion style I know of), when typing, say M-x, I get the most recently called commands first. This is not the case with hotfuzz however. This is a major usability issue for me. Best and thank you for this code.

axelf4 commented 3 years ago

This cannot be fixed by hotfuzz, I am afraid. Presuming you would have the same problem with the flex completion style, the issue lies in the flex sorting hack, which hotfuzz piggybacks on.

Completion UIs such as Vertico sort based on MRU only when the collection does not specify a display-sort-function metadata entry. However flex must always adjust the sort function metadata, even though flex sorting only makes sense when the search string is nonempty.

I guess completion UIs could compare display-sort-function before and after completion-all-completions to know if the sort function stemmed only from the completion style and in that case ignore it initially. Otherwise, I think this is something @minad's deferred-highlighting branch would fix.

hotfuzz-selectrum-mode does not have this problem.

minad commented 3 years ago

Vertico has very flexible sorting, see the vertico-sort-function variable. By advising the function vertico--sort-function you can also remix the completion style sorting with the mru sorting and other sorting functions.

villytiger commented 7 months ago

https://github.com/emacs-mirror/emacs/blob/13c7249105ec0d1a070c6d4e9f73f3c21d905bc8/lisp/minibuffer.el#L4517

It seems that flex now allows to get most recent entries. Would it be possible to add a similar hack to hotfuzz?

villytiger commented 7 months ago
  (defvar +hotfuzz--is-empty nil)
  (defun +hotfuzz-all-completions--enable-history-a (orig content &rest args)
    "Set a variable needed for showing most recent entries."
    (setq +hotfuzz--is-empty (string-empty-p content))
    (apply orig content args))
  (advice-add #'hotfuzz-all-completions
              :around #'+hotfuzz-all-completions--enable-history-a)
  (defun +hotfuzz--adjust-metadata--enable-history-a (orig metadata)
    "Enable showing most recent entries for empty input."
    (if +hotfuzz--is-empty
        metadata
        (funcall orig metadata)))
  (advice-add #'hotfuzz--adjust-metadata
              :around #'+hotfuzz--adjust-metadata--enable-history-a)

This workaround allows to get the most recently called commands.