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

How to get a list of keys for references that have notes? #594

Closed
bdarcus opened this issue May 17, 2022 · 7 comments · Fixed by #595
Closed

How to get a list of keys for references that have notes? #594

bdarcus opened this issue May 17, 2022 · 7 comments · Fixed by #595

Comments

@bdarcus
Copy link
Contributor

bdarcus commented May 17, 2022

I thought this would be straightforward, and it's possible I'm missing something, but I can't figure it out.

From a discussion on a related project.

Thoughts on this @roshanshariff @aikrahguzar?

EDIT: I linked a simple PR to make this easier.


So you need a list keys for all entries that have associated notes?

E.g.:

("doe1" "doe2" "doe3")

That's all?

If so, could you not just take the code you reference above to filter the candidates, and from there extract the keys?

EDIT: maybe not. I'll dig a little.

Originally posted by @bdarcus in Vidianos-Giannitsis/zetteldesk.el#5 (comment)

bdarcus added a commit that referenced this issue May 18, 2022
When creating candidates, add cons cells for files or notes, to
facilitate programmatic access.

Close #594
@roshanshariff
Copy link
Collaborator

roshanshariff commented May 18, 2022

This function seems to do the trick:

(defun citar-get-keys-with-note (&optional force-rebuild-cache)
  (let ((candidates (citar--get-candidates force-rebuild-cache))
        (hasnotep (citar-has-note)))
    (seq-map #'cadr (seq-filter (pcase-lambda (`(_ ,citekey . ,entry))
                                  (funcall hasnotep citekey entry))
                                candidates))))

The seq-filter call gets the list of candidates that have notes, each element being of the form (candstring citekey . entry), and the seq-map extracts just the citekeys from that filtered list.

@roshanshariff
Copy link
Collaborator

Also, I didn't fully read the context of this request, but one thing to beware of if you're adding the "has-note" key to citation entries: the candidates are usually only refreshed when the bib file is updated on disk. If notes are created/deleted without the bib file being changed, the has-note information will get out of date.

That is avoided if you call citar--has-note freshly every time and use the returned predicate to filter. That'll make it scan your notes directory each time. I'm not sure if that matters in this case.

@bdarcus
Copy link
Contributor Author

bdarcus commented May 18, 2022

What is that pcase-lambda doing? Why is that needed?

Edit: https://www.reddit.com/r/emacs/comments/53z616/no_examples_of_pcaselambda_online_so_heres_one

If notes are created/deleted without the bib file being changed, the has-note information will get out of date.

Yes; good point.

Hmm; need to think on that a bit.

@aikrahguzar
Copy link
Contributor

If notes are created/deleted without the bib file being changed, the has-note information will get out of date.

I think citar-filenotify can handle this, add 'notes to the citar-filenotify-files.

@bdarcus
Copy link
Contributor Author

bdarcus commented May 18, 2022

think citar-filenotify can handle this, add 'notes to the citar-filenotify-files.

Yes, it can.

But the downside I can imagine is that's a more user-facing option, that a programmer wouldn't have any control of.

I suppose we could have both options?

@aikrahguzar
Copy link
Contributor

But the downside I can imagine is that's a more user-facing option, that a programmer wouldn't have any control of.

I suppose we could have both options?

I don't understand what are the two options you are referring to. But it should be user option although I think default can be changed to '(bibliography notes). It won't hurt people like me who haven't set a notes path and if people with notes opted in to filenotify they probably want to have their notes taken into account?

@bdarcus
Copy link
Contributor Author

bdarcus commented May 18, 2022

I don't understand what are the two options you are referring to.

The linked PR (add cons cells to the candidate entries) and the suggestion from Roshan.

Or, as a more general solution, I was thinking maybe citar---get-candidates should allow a filter arg instead?

(seq-map #'cadr 
  (citar--get-candidates t (citar-has-note)))

That would allow a developer to filter the candidates however they want, and control the cache rebuilding too.

Edit: added to the PR 728e810.

But it should be user option although I think default can be changed to '(bibliography notes). It won't hurt people like me who haven't set a notes path and if people with notes opted in to filenotify they probably want to have their notes taken into account?

Now that I think about it, I'm not actually sure, TBH.

Maybe @Vidianos-Giannitsis can weigh in.

Edit: here replied in general Vidianos-Giannitsis/zetteldesk.el#5 (comment)

bdarcus added a commit that referenced this issue May 18, 2022
When creating candidates, add cons cells for files or notes, to
facilitate programmatic access.

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

Successfully merging a pull request may close this issue.

3 participants