-
Notifications
You must be signed in to change notification settings - Fork 37
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
Provide example integration with Citar for notes #299
base: master
Are you sure you want to change the base?
Conversation
This looks pretty cool. Thanks! |
In other Ebib files, the double dash for internal functions always comes directly after `ebib`, so `ebib--citar-previous-values` is more consistent.
Since we have an implementation of external notes using Citar, we may as well provide an explicit option for it.
It should. If you are a citar user, I'd appreciate testing of the citar-specific functionality, as note creation is definitely somewhat unstable. Else, please test with the patch to Edit: I'd like to note, I pretty heavily considered your comment on #263, and had initially written a version that did exactly that. I realized however, that it would be simpler to use a single function with a defined interface instead of having 3--4 variables that have to be checked. This means simpler code, and hopefully simpler, more likely to be consistent, configuration. As a note for |
I pushed a few commits, mostly cosmetic. I also added an option for Citar to Personally, I would also change the signature of the function from One serious issue, though: |
citar-has-notes may return nil (e.g., when Citar hasn't been configured yet), which cannot be called as a function.
Cool! Thanks -- I was hesitant to include that, though would a
I think that's a reasonable change, and I've gone ahead and made that
That's what I get for ignoring docstrings! I've pushed a fix. |
I've also made it so that the note checking closure is cached to improve performance. |
Opening citar notes should work now as well. |
Absolutely, and if I had known about it, I would have used it. 😄
Thanks! Though just to be on the safe side, perhaps we should put the |
I've wrapped it in a |
I've just had a look at this -- it's really cool but I have some worries. It seems that
I have a citar setup in which neither is true. I thought this might be an abuse of the code, but looking at how citar handles this sort of thing, I think actually the opposite is the case: citar's documentation carefully avoids assuming that notes objects are filepaths -- the docstring for I use org-roam for all my note taking. This means: Concerning 1: in my setup, each note object is a list of the titles of every org-roam node which has the citekey as in its Concerning 2: because of this tight integration, my citar setup uses I don't have the time right now to look into how to solve all this, but I hope it's relatively straightforward. For possible reference, here are the relevant parts my citar setup: (leaf citar
:require bibtex-completion
:config
;; Use org-roam for citar notes
(require 'cl-lib)
(require 'org-roam)
(defun my/citar-org-roam-has-notes ()
(lambda (key) (org-roam-node-from-ref (concat "@" key))))
(defun my/citar-org-roam-titles-hash-table (keys)
"Return hash table of KEYS and lists of notes.
Each key in KEYS is a key in the hash table. Each value is a list
of strings: the titles of every org roam node which has a
ROAM_REFS property with that KEY."
(let ((table (make-hash-table)))
(mapcar
(lambda (key)
;; TODO relies on an open PR
(when-let ((nodes (org-roam-nodes-from-ref (concat "@" key)))
(formatted (mapcar #'org-roam-node-title nodes)))
(puthash key formatted table)))
keys)
table))
(defun my/citar-capture-org-roam (key entry)
"Capture to "
(let ((title (citar-format--entry "${title}" entry)))
(org-roam-capture-
:templates `(,my/org-roam-reference-capture-template)
:props '(:finalize find-file)
:node (org-roam-node-create
:title title
:refs key))))
(defun my/citar-open-org-roam-note-title (note-title)
"Capture to the Org Roam node with with title NOTE-TITLE."
(when-let ((node (org-roam-node-from-title-or-alias note-title)))
(org-roam-capture- :node node)))
(defun my/citar-transform-title-to-org-roam-cand (title)
"Return `org-roam-node-read'-like candidate string for TITLE."
(let ((node (org-roam-node-from-title-or-alias
(substring-no-properties title))))
(org-roam-node-formatted-candidate node)))
(citar-register-notes-source
'my/citar-org-roam
(list :name "Org-Roam Notes"
:category 'org-roam-node
:hasitems #'my/citar-org-roam-has-notes
:open #'my/citar-open-org-roam-note-title
:items #'my/citar-org-roam-titles-hash-table
:create #'my/citar-capture-org-roam
:transform #'my/citar-transform-title-to-org-roam-cand))
:custom
(citar-bibliography . `(,my/bib-file))
(citar-library-paths . `(,my/bib-dir))
(citar-notes-paths . `(,my/bib-dir))
(citar-latex-prompt-for-cite-style . nil)
(citar-latex-default-cite-command . "autocite")
(citar-notes-source . 'my/citar-org-roam)) |
Well that adds a wrinkle in design. I wonder if there's a way to determine how to resolve that into a buffer without knowing the specific citar backend (not having a way to do so seems like a miss in the design of citar as it is so generic).
Hmm. That does make things difficult. How would you want it to decide which note(s) would be displayed given the integration?
I certainly hope so as well, but I suspect there will probably be some other work that's necessary.
|
Haha yes! I seem to remember running up against similar things last time I looked into this, though you've got a lot further than I have.
If there was, why would that be useful? Citar's infrastructure does not assume that the background application (citar or ebib) will always have to handle display (in fact I think citar assumes the opposite -- that the notes backend will deal with this). In my setup, it would definitely not be useful, since
... so I think this sort of gets it the wrong way round: citar is so generic that it doesn't assume this is the sort of thing you would need (I think?)
This is one thing that citar does handle. If an entry has more than one note, citar:
This is all handled by Ideally, if we integrate with citar, I would want exactly this to happen, using citar's infrastructure. Ebib shouldn't reimplement |
Since I don't use Citar, I can't really be of much help, but if you guys manage to sort this out, I'd love to add it to Ebib. There's one question above that I wanted to get back to:
Do you mean specifically the option This extraction is done using In order to be able to format the text in the entry buffer, it is then split into lines and returned as a list of strings.
|
Ideally, Ebib's note-management would be split into a frontend and a backend, with the frontend flexible enough to be able to plug in different backends. This PR could be a first step in that direction, by defining an interface and an example backend. The traditional options, |
This sounds good. Do you envisage that the current user-facing api for configuring notes would remain the same (i.e. setting |
I think starting anew would be better in this case. A new user option, I think a lot of the current code can be kept, once such an interface has been set up, so ideally, users who want to keep using Ebib's note-taking system (or one of them, as there are actually two) shouldn't have to do more than set the new user option. But if it turns out that bigger changes would be better in the long run, I wouldn't rule them out just to maintain backward compatibility. |
In fact, one thing I might decide to remove from the current system is the ability to use other formats than Org, at least for the |
I've now started working on this, in a separate branch based off of this PR. So @swflint , for any work you may do on |
I've now pushed an initial implementation of the notes back-end idea to https://github.com/joostkremers/ebib/tree/devel/notes-redesign. I've had to make a small modification to the interface suggested by @swflint , in that I've also indicated in the doc string of |
Good idea. You could actually do that in BTW, I added |
Sorry for the slow response -- it's end of term around these parts.
I'd missed that -- but I'll have to see if I can get it to work.
Do you want me working on |
Don't worry. 🙂 I happen to have some time now, but that may change any time.
Good question... Your PR is included in the new branch, so it would make the most sense to work on that (the new branch, I mean). I'm not sure how that would work from a practical point of view, though. Suggestions welcome.
That'd be great. |
I can branch off of that & rebase regularly to get the citar implementation working (and work only on |
I think my updates should get it pretty close (https://github.com/swflint/ebib/tree/improve-ebib-citar). The only thing is, it may make sense to have an option to return buffer focus to the index or entry buffer. |
Is there anything I can do to get this moving? |
I'm sure there is, but I'd need to go through the whole thread and the code again to be more specific. 😞 IIRC, though, the Ebib side of things works as described in the doc string of Citar's notes API centres around |
Do you think it would be possible to get the new, redesigned backend merged in, even if the only provided support is for the two original notes styles? In the mean time, I can work on a local, development version of the citar backend that's better designed around the citar API. |
Pending #298, this PR provides an example integration with Citar to demonstrate how external packages can be used to manage notes.