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

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

Closed
WorldsEndless opened this issue Nov 13, 2020 · 14 comments
Closed

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

WorldsEndless opened this issue Nov 13, 2020 · 14 comments

Comments

@WorldsEndless
Copy link

WorldsEndless commented Nov 13, 2020

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
Copy link
Member

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
Copy link
Author

WorldsEndless commented Nov 17, 2020

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

@raxod502
Copy link
Member

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
Copy link
Contributor

okamsn commented Nov 26, 2020

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
Copy link
Member

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
Copy link
Author

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
Copy link
Contributor

okamsn commented Dec 11, 2020

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
Copy link
Author

WorldsEndless commented Dec 11, 2020 via email

@WorldsEndless
Copy link
Author

WorldsEndless commented Dec 11, 2020 via email

@okamsn
Copy link
Contributor

okamsn commented Dec 12, 2020

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
Copy link
Author

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
Copy link
Author

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
Copy link
Author

I believe the real culprit is #84 .

@raxod502
Copy link
Member

Yeah, sounds like it. Will follow up there.

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

No branches or pull requests

3 participants