(feat): Allow one file to have multiple roam_key statements#1215
Merged
jethrokuan merged 5 commits intoorg-roam:masterfrom Nov 7, 2020
Merged
(feat): Allow one file to have multiple roam_key statements#1215jethrokuan merged 5 commits intoorg-roam:masterfrom
jethrokuan merged 5 commits intoorg-roam:masterfrom
Conversation
5050e86 to
373a1ce
Compare
af3cb52 to
3a47bf9
Compare
3d393e5 to
f7c5e56
Compare
f7c5e56 to
4ac5d25
Compare
Member
|
Looks like in this PR you're able to extract multiple refs from a single file, but you're not saving them all into the database. Any reason why? |
Contributor
Author
|
This PR does save all extracted refs into the database: (defun org-roam-db--insert-ref (&optional update-p)
"Update the ref of the current buffer into the cache.
If UPDATE-P is non-nil, first remove the ref for the file in the database."
(let ((file (or org-roam-file-name (buffer-file-name)))
(count 0))
(when update-p
(org-roam-db-query [:delete :from refs
:where (= file $s1)]
file))
(when-let ((refs (org-roam--extract-refs)))
(dolist (ref refs) ; <= this should insert all refs from this file
(let ((key (cdr ref))
(type (car ref)))
...although I just realized that the I kept |
This changes org-roam--extract-global-props to collect all props, but alist shadowing means that other uses of this function will still extract the property they want correctly.
db--insert-{titles, links, tags, ...} all correspond to
org-roam--extract-{titles, links, tags, ...}, so
org-roam--extract-refs should also correspond to
org-roam-db--insert-refs.
03c5e19 to
5335a8d
Compare
jethrokuan
approved these changes
Nov 7, 2020
Contributor
|
@kisaragi-hiu nice. I was looking for this in #1095. I opted for something more suited for my problem at the end though. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation for this change
I'd like to be able to associate multiple
ROAM_KEYkeywords to the same file. This will allow multiple bibliographical entries to share the same file.My actual use case is that I want to add both a book and its chapters to my bibliographical database. If a file can only have one
ROAM_KEYkeyword, we have to create a note file for each chapter and the book. I'd like to have the choice of putting them all in one file.Note that this is the inverse of #587. #587 wants one-key-to-many-files, while this implements many-keys-to-one-file.
This also allows setting both a URL and a cite key as referring to a file. For example:
Potential concerns
This PR makes
org-roam--extract-global-propsextract all matching props in the form(("key" . "val1") ("key" . "val2"))instead of only extracting the first match. I don't think this would be an issue, though, becauseassocand other alist functions will simply take the first match themselves.