-
Notifications
You must be signed in to change notification settings - Fork 54
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
Revise note API (again) #646
Comments
@roshanshariff I had an epiphany on this just now, and so have revised the proposal to simplify. OTOH, I don't want to hold up #634 too much longer; we've been working on that for I think more than a month at this point. It might be good to keep status quo there, and worry about proper support for In any case, some further info, and demo code ... The code in citar-org-roam (the config plist and the functions it specifies) should be ready for you to play with. As in, this works to return a candidate list: (funcall (plist-get citar-org-roam-open-notes-config :items) keys) ... and to open a selected candidate: (funcall (plist-get citar-org-roam-open-notes-config :action) candidate) Note also that (multi-category
('org-roam-node .
#("fd1e8dfa-8bfd-43fb-884a-b350a7a0850a agnew2003 Notes on Agnew, From Megalopolis to Global City-Region?" 0 37
(invisible t)
37 46
(face citar-highlight)
67 122
(face citar)))
face citar)
122 123 So we seem to have a cons embedded in a string propertized with "multi-category". This again raises the question for me of whether we should just use (defun citar-consult-open ()
"Open related resources."
(interactive)
(let* ((keys (citar-select-refs))
(sources
`((:name "Org-Roam Ref Notes"
:category org-roam-node
:action ,#'citar-org-roam-open-note-from-id
:annotate ,#'citar-org-roam--annotate
:items ,(citar-org-roam--get-candidates keys))
(:name "Related Files"
:category file
:action ,#'citar-file-open-external
:items ,(citar-get-files keys))
(:name "Links"
:category url
:action ,#'browse-url
:items ,(citar-get-links keys)))))
(consult--multi sources))) I just can't figure out how to avoid let-binding the sources because of that keys arg. Edit: see minad's comment below; |
@minad we're again thinking about We need to dynamically generate the |
This doesn't look like a good use case of consult--multi. consult--multi is mostly useful if the sources can be configured flexibly and if they are not hard coded. If you have hard coded sources anyway I suggest to use completing-read with the group-function. |
That's what we do now. Any tips how to address the fact that we have multiple categories, and in the case of notes, we won't know what they are upfront (can be files, as now, or with Org-Roam can be files or sub-file nodes)? I don't really understand that part of |
You can use the multi-category category in the same way as consult--multi uses it. The multi-category is also supported by Marginalia and Embark. The candidates must carry a multi-category text property, see consult--multi-candidates. You should read through the Consult source for the details. |
Yes, I have. I just wanted to confirm that. So no to I guess we're already using As always, thank you! |
I have an idea for a possible solution: Add an optional Actually, have all the args optional then, and have them keywords. I just pushed a commit for this to #634, and I think it's all working correctly ATM. For example: ELISP> (citar--get-resource-candidates '("toly2017") :files t :notes t :links t)
(#("https://doi.org/10.1080/14747731.2016.1233679" 0 45
(multi-category
(url . "https://doi.org/10.1080/14747731.2016.1233679")))
#("/home/bruce/Zotero/storage/PKZ88BS7/14747731.2016.html" 0 54
(multi-category
(file . "/home/bruce/Zotero/storage/PKZ88BS7/14747731.2016.html")))
#("/home/bruce/Zotero/storage/4XRNSQEB/Toly_2017_Brexit, global cities, and the future of world order.pdf" 0 102
(multi-category
(file . "/home/bruce/Zotero/storage/4XRNSQEB/Toly_2017_Brexit, global cities, and the future of world order.pdf")))) |
Looking now at note config, here's the new plist as it stands: (defvar citar-notes-config-file
`(:name "Notes"
:category file
:key-predicate ,#'citar-file-has-notes
:action ,#'citar-file--open-note
:items ,#'citar--get-file-notes)
"Default file-per-note configuration.") And here's the current defcustoms:
Observations/thoughts:
|
@myshevchuk - turns out our earlier discussion on note config got a little more complex. Any feedback, particularly on my last post? These changes will allow a package like ORB to directly update the citar UI for presence of notes, configure the candidate display (including annotations), and open the selected candidate from The idea would be to keep the current defcustom around a bit, until I tag v1.0 sometime in the next month or so. Or I suppose we could iterate the current config approach. |
@bdarcus, I like the new API design. I would just make one small change: instead of just having the (defcustom citar-notes-sources ((citar-file . PLIST)) Then there should be another variable which selects the source (or sources) to actually use, which will actually be modified by the user: (defcustom citar-notes-source 'citar-file) Then |
@roshanshariff OK, will take a look tomorrow. While I have you, do you know how to modify our group function so it will work with non-file notes? This is the primary bug I'm stuck on. Can we just inspect the (defun citar--select-group-related-resources (resource transform)
"Group RESOURCE by type or TRANSFORM."
(let ((extension (file-name-extension resource)))
(if transform
(if (file-regular-p resource)
(file-name-nondirectory resource)
resource)
(cond
;; FIX doesn't work with node-id notes
((member extension citar-file-note-extensions) "Notes")
((string-prefix-p "http" resource 'ignore-case) "Links")
(t "Library Files"))))) |
Maybe |
I was thinking it's valuable to use So distinguish file notes from node-notes. |
Maybe the |
Right now, the category is specified in the plist, so I think it's already as you suggest. I was really just thinking for the default plist and the org-roam one. Edit: also I was wondering about using that metadata. I was wanting to do something like this (which actually works with the org-roam nodes, but probably won't with the default file notes), or even have all of these configured similarly. (defun citar--select-group-related-resources (resource transform)
"Group RESOURCE by type or TRANSFORM."
(if transform
(if (file-regular-p resource)
(file-name-nondirectory resource)
resource)
(let ((cat (car (get-text-property 0 'multi-category resource))))
(pcase cat
('file "Files")
('url "Links")
(_ (plist-get citar-notes-config :name)))))) I think I can use a variation of this trick I just figured out for the annotation function here as well: (let* ((nodecat (car (get-text-property 0 'multi-category cand)))
(notecat (plist-get citar-notes-config :category))
(annotate (plist-get citar-notes-config :annotate))
(ann (when (and annotate (string= nodecat notecat)) ; check that category matches the plist Just need to fix the annotation alignment, and get file note grouping working again. |
Maybe we could define default category as |
I pushed the defcustoms, but can't figure out how to access the plists from them. ELISP> (plist-get (cdr (assoc citar-notes-source citar-notes-sources)) :name)
nil
ELISP> citar-notes-config-file
(:name "Notes" :category file :key-predicate citar-file-has-notes :action citar-file--open-note :items citar-file--get-note-files) And here's what I have: (defcustom citar-notes-sources
'((citar-file . citar-notes-config-file)) Once I get that sorted, I'll add a Or maybe |
I ended up adding a (if notep (plist-get citar-notes-config :name) ; if note, get the group name from plist
(pcase cat ; else use the completion category
('file "Library Files")
('url "Links")))))) So this allows us to use |
I implemented it with some help from someone suggesting:
|
I definitely love the approach where an external package like ORB could feed the necessary information to Citar using the exposed API. I remember the difficulties I had with ORB trying to hijack Ivy-bibtex to update the "has-note" indicator, and I think it ended up buggy anyway. I can't speak much about the new Citar API right now because I haven't had time to look at it in detail yet. In any case, the suggested fine-grained control over the different citation resources looks very thorough and systematic. Whatever the new Citar API will look like, ORB will support it. |
@myshevchuk - sounds good. Note I'm developing this small extension alongside this to make sure the API is correct. https://github.com/emacs-citar/citar-org-roam/blob/main/citar-org-roam.el I'm not sure how it will evolve, but am thinking it will remain pretty small and just handle the integration, and other packages can build on it. Or they write their own integration functions, and that becomes a demonstration of how. |
Here's another example of a notes source, using the new API; from today! https://github.com/localauthor/zk/blob/main/zk-citar.el PS - any comments on the notes API can go here. I'll likely make one tweak based on the feedback so far. |
FYI, I'll be tagging 1.0 in the coming days, and then bumping the doom biblio module. I will post this on the wiki, I think, for folks who want to continue to use ORB: (citar-register-notes-source
'orb-citar-source
(list :name "Org-Roam Notes"
:category 'org-roam-node
:items #'citar-org-roam--get-candidates
:hasitems #'citar-org-roam-has-notes
:open #'citar-org-roam-open-note
:create #'orb-citar-edit-note
:annotate #'citar-org-roam--annotate))
(setq citar-notes-source 'orb-citar-source) This relies on https://github.com/emacs-citar/citar-org-roam. |
@bdarcus excellent! I will update the ORB readme too. |
FYI seems like |
It's always had two arguments, since it's just adding to an alist. Oh sorry; my bad, fixed. :-) I wasn't sure on your second question either. I copied and pasted it from the citar-org-roam example (though just removed it to avoid confusion). @roshanshariff? |
I'm not sure I understand, but there's never any "need" for (citar-register-notes-source 'my-notes-source '(:name "My Notes Source" :create my-note-create-function ...)) But in The (citar-register-notes-source 'my-notes-source (plist-put (copy-sequence citar-org-roam-config) :create #'my-note-create-function)
(setq citar-notes-source 'my-notes-source) I hope that answers your question, but I'm happy to clarify otherwise. |
We need to revise again the note API so that notes work correctly with
citar-open
, while also being configurable, but I suggest we do this after #634.The problem
With notes, the issue is that we don't can't assume the category is always a file; it could also be some sub-file section.
For purposes of this discussion, the completion category can be
file
ororg-roam-node
.If the category is
file
, then the candidates need be no different thancitar-get-files
; it's only with theorg-roam-node
case that it gets complicated.And even more specifically, it's only if we insist on allowing different categories within the same group, which I'm skeptical about. I'm not even clear how we do that from a technical POV.
Proposed solution
Per minad below:
So have
citar-get-notes
return a list of completion strings regardless of completion category, and changecitar-open-note-functions
to a plist something like this, which is howconsult--multi
does it:That's simple and flexible, with the sole constraint that all notes within a group must be the same category.
Then with citar-org-roam can just do:
On the candidates: I have an experimental
citar-org-roam--get-ref-nodes
function in the citar-org-roam repo that returns a list of propertized strings, using the hidden id trick, with citekey and title in the visible part.Conclusion
I see no downside to this approach. I think the question is just whether the defcustom becomes
citar-notes-config
, orcitar-notes-configs
. The latter would allow multiple plists, and hence notes groups. I have no opinion on this question.Except, if it's a list, the whole
citar-open
UI may as well be configured with this approach; not just notes? Socitar-open-config
?(setq citar-open-config '(citar-open-note-config citar-open-file-config citar-open-link-config))
Originally posted by @bdarcus in #634 (comment)
The text was updated successfully, but these errors were encountered: