Closed edgimar closed 2 years ago
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:
Maybe I am missing something. And if it is the case, sorting hook will not solve your problem. So let's dig into it 😄
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?
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?
PR was merged, if you think that it doesn't work let me know and I will reopen it.
Yes that seems like it should work - thanks!
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 thatvulpea-find
provides. Removing such notes from the list would prevent searching them by tag. In order to see the normal titled notes whenvulpea-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?