org-roam / org-roam-bibtex

Org Roam integration with bibliography management software
GNU General Public License v3.0
568 stars 47 forks source link

(int) Bibtex-actions support #212

Closed myshevchuk closed 2 years ago

myshevchuk commented 2 years ago

orb-edit-notes can accept a list of strings or a list of lists whose element lists start with strings.

See #211.

@bdarcus On another thought I decided to not modify orb-edit-note. By design, it accepts a single argument, a citation key as string, and should probably stay as such. It would anyway require additional destructuring because plain (defun orb-edit-note (citekey &optional entry) would not work because (KEY . ENTRY) is still a single argument.

I instead modified the function orb-edit-notes, which is meant to be plugged in into bibtex-completion-edit-notes-function or bibtex-actions-file-open-note-function. This function used to accept a list of keys as returned by bibtex-comletion. Now it also accepts a list of lists to support bibtex-actions. Note the function still does not support "multi-editing". That is if more than one entry is selected, it will proceed only with the first entry.

Please check if this works for you and I'll merge it.

bdarcus commented 2 years ago

@bdarcus On another thought I decided to not modify orb-edit-note. By design, it accepts a single argument, a citation key as string, and should probably stay as such. It would anyway require additional destructuring because plain (defun orb-edit-note (citekey &optional entry) would not work because (KEY . ENTRY) is still a single argument.

Just to clarify, this last point wouldn't be a problem actually.

It's true bibtex-actions-select-refs returns (KEY . ENTRY) now, but my intention was for the interactive notes function that uses it (bibtex-actions-open-notes) to pass them as separate arguments; e.g:

  (funcall bibtex-actions-file-open-note-function key entry)))

.. since the first arg is just the car, and the second the cdr.

E.g. I'd change that part of the function like so:

  (dolist (key-entry keys-entries)
    (funcall bibtex-actions-file-open-note-function (car key-entry) (cdr key-entry)))

Given that, why not just modify orb-edit-note instead?

myshevchuk commented 2 years ago

Given that, why not just modify orb-edit-note instead

I would do that if the entry could seamlessly be propagated to orb--new-note, which actually does the job of fetching an entry and initiating org-roam-capture. Unfortunately, orb--new-note already takes another optional variable props for internal use, and I don't want to mess around it for I don't have much time right now. Defining the more or less central function orb-edit-note with a dangling argument doesn't look good to me either.

In principle, I like the idea of the completion system supplying the BibTeX information to orb-edit-note, so that orb--new-note wouldn't have to look it up. That's a more flexible solution too, since one could construct BibTeX entry programmatically and use orb-edit-note outside the scope of a completion system. As of now however, Bibtex-actions uses Bibtex-completion bibliography anyway, so that doesn't make a big difference.

As a current solution, I created a new function orb-bibtex-actions-edit-note, which does what you've requested. Furthermore, org-roam-bibtex-mode automatically sets bibtex-actions-file-open-note-function to orb-bibtex-actions-edit-note, so the user does not have to do that in their config.

Would this work for you?

bdarcus commented 2 years ago

In principle, I like the idea of the completion system supplying the BibTeX information to orb-edit-note, so that orb--new-note wouldn't have to look it up. That's a more flexible solution too, since one could construct BibTeX entry programmatically and use orb-edit-note outside the scope of a completion system.

Right.

As of now however, Bibtex-actions uses Bibtex-completion bibliography anyway, so that doesn't make a big difference.

Yes, I see that.

As a current solution, I created a new function orb-bibtex-actions-edit-note, which does what you've requested. Furthermore, org-roam-bibtex-mode automatically sets bibtex-actions-file-open-note-function to orb-bibtex-actions-edit-note, so the user does not have to do that in their config.

Would this work for you?

Yes, I think so. Thanks!

myshevchuk commented 2 years ago

Great, I'm merging the changes then.

bdarcus commented 2 years ago

I started the change here:

https://github.com/bdarcus/bibtex-actions/pull/289

Will finish (mainly adding documentation) later today.