-
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
Improve note creation functionality (and tweak API) #661
Conversation
The `citar-get-files`, `citar-get-links`, and `citar-get-notes` functions now return hash tables mapping each key to a list of associated resources. They used to just return lists of resources for all the given keys, but that interface doesn't allow callers to determine which key corresponds to each resource. The `:items` function in the notes source API has also been modified, and must now return a hash table instead of a list of notes.
Both these functions now offer to create notes for the chosen keys. The customization variable `citar-open-always-create-note` controls whether the "create" option is offered only for keys that don't already have notes. This new feature is implemented as an extra option to `citar--select-resource`, which has now learned about the `create-note` pseudo-resource type. The `citar-open-notes` and `citar--open-resource` also learned to create new notes. Other Changes There is a new command called `citar-open-note`, which prompts to select a note from all the available notes and opens it. It can also be called non-interactively with a note returned by `citar-get-notes`, which is its primary purpose. The customization variable `citar-open-prompt` can now be set to a list of commands that will always prompt before selecting resources. The default is to always prompt for `citar-open`, `citar-attach-files`, and `citar-open-note`.
763a83d
to
218511a
Compare
Return note candidates as a hash table rather than as a list.
If appropriate, can you include a screenshot when you get a chance? |
Are you also a geographer Grant??? |
Not exactly. My dissertation was on literary and geographical discourse in 19th-C America, but my degree is in English. So I'm sort geography adjacent. :) |
I don't want to open a new issue for this, but @roshanshariff, can you please explain why you use Line 849 in c5ed78e
... and also I'm sure there's a reason, but I'd like to understand it. Perhaps even code comments there might be helpful? |
The line (setf (alist-get name citar-notes-sources) config) means "in the It's also possible to extend this machinery, so if you're writing a library that has a
Finally, why is it not enough to just call ELISP> (setq mylist '(foo bar baz))
(foo bar baz)
ELISP> (delq 'bar mylist)
(foo baz)
ELISP> mylist
(foo baz)
ELISP> (delq 'foo mylist)
(baz)
ELISP> mylist
(foo baz) You can see that although
I'm not sure if code comments are the right approach here. I find that they're not as helpful as the built-in documentation to understand a construct you might not have seen before. In this case, the documentation would be here. I myself learned about them by stumbling across them in other Elisp code and looking up what they did. |
Many thanks. I recall part of the discussion on the Doom discord was about |
You're welcome! I realized I forgot to address the first part, why not use ELISP> (setq myalist '((foo . "bar") (baz . "qux")))
((foo . "bar")
(baz . "qux"))
ELISP> (cl-pushnew '(foo . "bar") myalist)
((foo . "bar")
(foo . "bar")
(baz . "qux"))
ELISP> (cl-pushnew '(foo . "???") myalist)
((foo . "???")
(foo . "bar")
(foo . "bar")
(baz . "qux")) So
As an aside, (push 42 (gethash 'foo ht))
(cl-callf2 cons 42 (gethash 'foo ht))
(setf (gethash 'foo ht) (cons 42 (gethash 'foo ht)))
(puthash 'foo (cons 42 (gethash 'foo ht)) ht) This works because |
OK, so they're more fine-grained tools, and |
Two things on the PR, @roshanshariff:
|
Sounds good, I'll merge it now. I was hoping to get to the multi-select functionality, but I'll have to leave that for later when I have time. |
Return note candidates as a hash table rather than as a list.
Great! What else, if anything, do you think needs to be done before 1.0? |
This PR continues #658.
citar-open
andcitar-open-notes
can now create notesBoth these functions now offer to create notes for the chosen keys. The customization variable
citar-open-always-create-note
controls whether the "create" option is offered only for keys that don't already have notes. Regardless of this variable's value, thecitar-create-note
command can always be used to create multiple notes for any key, if supported by thecitar-note-source
.This new feature is implemented as an extra option to
citar--select-resource
, which has now learned about thecreate-note
pseudo-resource type. Thecitar-open-notes
andcitar--open-resource
functions also learned to create new notes.Other Changes
There is a new command called
citar-open-note
, which prompts to select a note from all the available notes and opens it. It can also be called non-interactively with a note returned bycitar-get-notes
, which is its primary purpose.The customization variable
citar-open-prompt
can now be set to a list of commands that will always prompt before selecting resources. The default is to always prompt forcitar-open
,citar-attach-files
, andcitar-open-note
. This should fix the UX issue identified in #656.The new customization variable
citar-open-resources
controls which resources are offered bycitar-open
. By default it is set to'(:files :links :notes :create-notes)
, but any of those can be removed if desired.API changes
The first commit in this PR modifies the API to make the above changes easier.
The
citar-get-files
,citar-get-links
, andcitar-get-notes
functions now return hash tables mapping each key to a list of associated resources. They used to just return lists of resources for all the given keys, but that interface doesn't allow callers to determine which key corresponds to each resource.The
:items
function in the notes source API has also been modified, and must now return a hash table instead of a list of notes.emacs-citar/citar-org-roam#6 updates the
citar-org-roam
note source to conform to this change.Remaining work
We don't yet have a "multi-select" interface to
citar-open
and friends.embark-act-all
can be used to act on all the presented candidates, but this doesn't allow you to select some smaller subset.