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

ability to influence how entries in vulpea-find are sorted #121

Closed
edgimar opened this issue Nov 15, 2021 · 5 comments · Fixed by #123
Closed

ability to influence how entries in vulpea-find are sorted #121

edgimar opened this issue Nov 15, 2021 · 5 comments · Fixed by #123
Labels
enhancement New feature or request

Comments

@edgimar
Copy link

edgimar commented Nov 15, 2021

I have hundreds of org-roam 'dailies' files with titles like 2021-11-15. By default, all such numeric entries are placed at the beginning of the completion list that vulpea-find provides. Removing such notes from the list would prevent searching them by tag. In order to see the normal titled notes when vulpea-find starts, it would be preferable for the numeric-titled notes to be at the end of the list, while the rest of the list is still sorted as usual.

Would it be possible to add a sorting function hook to enable custom sorting like this?

@d12frosted
Copy link
Owner

Hey @edgimar,

In general, the order of notes returned by vulpea-db-query (that is used under the hood) is not defined. I am pretty sure that the sorting you see comes from your completion framework. Vulpea uses completing-read for completion and does nothing with the order of notes.

But just to confirm that this is the case, can you please verify what happens if you M-x (completing-read "Order: " '("hello" "a note" "2021-11-16" "2021-11-15")) <ret>? I see the following completion:

image

Maybe I am missing something. And if it is the case, sorting hook will not solve your problem. So let's dig into it 😄

@edgimar
Copy link
Author

edgimar commented Nov 17, 2021

Yes, I do see the same completion. (I guess you mean M-: ?)
So it seems that a hook that processes the list passed to completing-read is needed (could be something more general than just sorting -- as long as the function accepts a list and returns one). Does that sound right?

@d12frosted
Copy link
Owner

d12frosted commented Nov 17, 2021

Yes, I meant M-: 😄

Alright, I see. In general I don't think it's a good idea to provide something specific for ordering as it may be overridden by your completion framework (for example, to put on the top of the list recently used items) and vulpea-select-from can't give any guarantees here, so instead vulpea-find may provide a configuration variable that controls candidates. See #123.

So in your case you would define a function:

(defun my-vulpea-find-candidates (filter-fn)
  "Prepare a list of candidates for `vulpea-find'.

FILTER-FN is the function to apply on the candidates, which takes
as its argument a `vulpea-note'."
  (let ((notes (vulpea-db-query filter-fn)))
    (order-notes-somehow notes)))

And then you can use it as default source for candidates:

(setq vulpea-find-default-candidates-source #'my-vulpea-find-candidates)

What do you think?

@d12frosted
Copy link
Owner

PR was merged, if you think that it doesn't work let me know and I will reopen it.

@edgimar
Copy link
Author

edgimar commented Nov 18, 2021

Yes that seems like it should work - thanks!

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

Successfully merging a pull request may close this issue.

2 participants