radian-software / prescient.el

☄️ Simple but effective sorting and filtering for Emacs.
MIT License
604 stars 25 forks source link

Selectrum M-x doesn't prioritize exact match #75

Closed WorldsEndless closed 3 years ago

WorldsEndless commented 3 years ago

Probably related to #62 . It is annoyingly difficult to select the item I'm looking for; pictured is an example where I have typed "eval-buffer". m-x-wrong-order

Here are the settings I'm using; is this user error?

       (use-package selectrum
     :bind (("C-x b" . switch-to-buffer)
        ("M-x" . execute-extended-command))

     :config
     (global-set-key (kbd "C-x b") 'switch-to-buffer)
     (global-set-key (kbd "M-x") 'execute-extended-command)
     (global-set-key (kbd "C-x C-z") #'selectrum-repeat)
     (selectrum-mode +1))

       (use-package selectrum-prescient
     :config
     (selectrum-prescient-mode +1))

  (use-package prescient
    :custom
    (prescient-history-length 200)
    (prescient-frequency-decay 0.997)
    (prescient-frequency-threshold 0.05)
    (prescient-sort-length-enable nil)
    (prescient-save-file "~/emacs/.emacs.d/var/prescient-save.el")
    (prescient-filter-method '(anchored literal regexp initialism))
    :config
    (prescient-persist-mode t))
raxod502 commented 3 years ago

Can I see a slightly larger screenshot? Based on the results, it really seems like you've typed eval buf. It's definitely possible that there is some bizarre bug which causes only buf to be highlighted even though you typed buffer, but I wanted to double check first.

The relevant customization would be prescient-filter-method. I adjusted it as in your configuration, and get the following results:

image image

Which seems as intended.

I think it's unlikely that this is related to #62, because at present it is the completion framework (Ivy or Selectrum) rather than prescient.el which is responsible for prioritizing exact matches. One never knows, of course.

WorldsEndless commented 3 years ago

image "eval buffer" . I would like this to be the first result as it is the shortest match

raxod502 commented 3 years ago

Ah! Yes, you haven't typed eval-buffer but rather eval buffer, so Selectrum has not prioritized it as an exact match. Because you've used checkdoc-eval-current-buffer more recently than eval-buffer, prescient.el sorts checkdoc-eval-current-buffer first. However, if you select eval-buffer from this menu, then the next time you type in the same query, eval-buffer will appear first.

The reason I implemented it like this is because there are situations when you might want to use checkdoc-eval-current-buffer frequently, say, and it would be annoying if your usage patterns were not taken into account.

Do you think there is an enhancement to be made? I could make it so you could disable usage-based sorting, but that doesn't seem particularly useful to me.

okamsn commented 3 years ago

Is it possible to sort candidates that are fully matched before recent candidates that are not fully matched? For example, eb would sort eval-buffer before the checkdoc version.

raxod502 commented 3 years ago

Hm. I suppose we can determine "fully matched" by seeing if the regexp match includes the entire text of the candidate. I think I would personally prefer the current behavior, because it's simpler, but I wouldn't be opposed to adding an option to implement what you are describing, where candidates are sorted by

  1. whether they are fully matched
  2. recent usage
  3. frequent usage
  4. length
WorldsEndless commented 3 years ago

Ah! Yes, you haven't typed eval-buffer but rather eval buffer, so Selectrum has not prioritized it as an exact match. Because you've used checkdoc-eval-current-buffer more recently than eval-buffer,

To the best of my knowledge, I've NEVER used checkdoc-eval-current-buffer (I'm not even sure what it does). This seems to be a pattern for how prescient is working for me; indeed, using a command and then pressing M-x doesn't seem to show the just-used command anywhere on the list and prescient actually seems to be actively making intended selections harder to find. Surely something is broken/misconfigured somewhere...

Example: plain M-x always shows eww-buffer-select at the top of the list, though it's not a command i've ever directly called and I certainly haven't used eww that recently. Then I try M-x find and would expect find-grep to be at the top, since I called it not long ago, but instead find-function-other-frame, again something I'm not aware of ever having typed, and find-grep isn't visible on the list at all. In general all hopes I have of issuing a command and then hitting M-x to find that command at the top of my list have never been achieved except for a few minues after I first installed/enabled prescient-selectrum.

okamsn commented 3 years ago

To be clear, is Prescient not working for any completion commands (e.g., describe-function), and you have enabled prescient-persist-mode and selectrum-prescient-mode?

WorldsEndless commented 3 years ago

The following are my Straight lines; does all look in order?

--8<---------------cut here---------------start------------->8--- (use-package prescient :custom (prescient-history-length 1000) (prescient-frequency-decay 0.997) (prescient-frequency-threshold 0.05) (prescient-sort-length-enable nil) ;(prescient-save-file "~/emacs/.emacs.d/var/prescient-save.el") (prescient-filter-method '(literal prefix regexp initialism)) :config (prescient-persist-mode t))

(use-package selectrum-prescient :config (selectrum-prescient-mode +1)) --8<---------------cut here---------------end--------------->8---

WorldsEndless commented 3 years ago

Also, I note that I had these lines off since our last message and, upon re-evaluating them now, things are temporarily working as expected (ie M-x shows my most recent command, which is also the one I searched for in describe-function). )

okamsn commented 3 years ago

I don't think that there's anything wrong with those settings, as far as I understand use-package.

This is how I'm doing it:

(use-package selectrum
  :init (selectrum-mode 1))
(use-package prescient
  :config
  (prescient-persist-mode 1))
(use-package selectrum-prescient
  :demand t
  :after selectrum
  :config (selectrum-prescient-mode 1))
WorldsEndless commented 3 years ago

I deleted the file and re-enabled everything and, for the moment, things are working beautifully, with all the help I want everywhere! Is there a chance that things get corrupted by git, or by multiple sessions trying to use the same prescient file, or some such thing?

WorldsEndless commented 3 years ago

Explanation about multiple sessons: as an EXWM user, I sometimes run emacs-in-emacs, so that both the host file and the sub-process would both be using prescient. I don't know if this causes issues, but I understand how it might depending on how the code is written. Are the errors I reported consistent with a broken/missing prescient file?

WorldsEndless commented 3 years ago

I believe the real culprit is #84 .

raxod502 commented 3 years ago

Yeah, sounds like it. Will follow up there.