-
-
Notifications
You must be signed in to change notification settings - Fork 463
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
Adding key column to db #547
Conversation
org-roam-db.el
Outdated
[:insert :into refs | ||
:values $v1] | ||
(list (vector ref file)))) | ||
(let ((key (elt (split-string ref ":") 1))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't this run into trouble with other types of links in the ROAM_KEY? e.g. https://example.com
will get stripped to //example.com
Maybe we should check if the prefix is in org-ref-cite-types
before splitting, and then strip off that prefix. Otherwise leave the key untouched.
Another issue this might run into is if a citekey has a ':' in it, this will strip off the stuff afterwards (after a quick search it appears that ':' is allowed in a bibtex citekey). e.g. in a pathological case: cite:key:withcolon
would get stripped to key
instead of key:withcolon
, or key:withcolon
would get stripped to just withcolon
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(let ((key (elt (split-string ref ":") 1))) | |
(let ((key ref)) | |
(dolist (prefix org-ref-cite-types) | |
(setq key (string-remove-prefix (concat prefix ":") key))) |
org-roam-db.el
Outdated
(when-let ((ref (org-roam--extract-ref))) | ||
(setq all-refs (cons (vector ref file) all-refs)))) | ||
(when-let* ((ref (org-roam--extract-ref)) | ||
(key (elt (split-string ref ":") 1))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same issue as above
org-roam-db.el
Outdated
[:insert :into refs | ||
:values $v1] | ||
(list (vector ref file)))) | ||
(let ((key (elt (split-string ref ":") 1))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(let ((key (elt (split-string ref ":") 1))) | |
(let ((key ref)) | |
(dolist (prefix org-ref-cite-types) | |
(setq key (string-remove-prefix (concat prefix ":") key))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of storing the citekey as key, let's have a db structure as follows:
| ref | file | type | (original key) |
|--------------------+-----------------+-----------+--------------------|
| https://google.com | /path/to/f1.org | "website" | https://google.com |
| ahrens2017 | /path/to/f2.org | "cite" | cite:ahrens2017 |
| foo | /path/to/f3.org | "roam" | foo |
org-roam-db.el
Outdated
@@ -133,7 +133,8 @@ SQL can be either the emacsql vector representation, or a string." | |||
|
|||
(refs | |||
[(ref :unique :not-null) | |||
(file :not-null)]))) | |||
(file :not-null) | |||
(key :not-null)]))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's call this type
instead, same as the links
table. Key will then take on values:
cite
if the prefix is an org-ref cite link (as perorg-ref-cite-types
)website
if it's a URL (optional, nothing is being done with this)- `roam' otherwise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't this break setups where the ROAM_KEY
is just the citekey?
e.g. ROAM_KEY: ahrens2017
would be detected as a roam type rather than a cite type.
having the key
(or whatever column name is chosen) just be the original ROAM_KEY
stripped of any org-ref-cite-types
prefixes should allow both cite:ahrens2017
and ahrens2017
to work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's fine to keep the cite:
in ROAM_KEY
as a way to identify bibliographic notes. It comes at very little cost to us, and I agree with @jethrokuan that it helps with entry if you're not using org-roam-bibtex
to generate those files.
This stems from the desire to have different types of keys co-exists with just one file-metadata tag. Otherwise, another option which wouldn't be as elegant would be to have different file-metadata tags like ROAM_CITEKEY
, ROAM_URLKEY
, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough. I can see the logic for future extendability. ROAM_CITEKEY
and ROAM_URLKEY
does not sound like a nice solution IMO.
I might submit a quick PR to fix the backlinks buffer not catering for all cite types
Maybe something like this? (defun org-roam-db--insert-ref (file ref)
"Insert REF for FILE into the Org-roam cache."
(let* ((url (url-generic-parse-url ref))
(type (url-type url)))
(cond ((cl-find type org-ref-cite-types :test #'string=)
(setq ref (string-remove-prefix (concat type ":")))
(setq type "cite"))
((cl-member type '("http" "https") :test #'string=)
(setq type "website"))
(t
(setq type "roam")))
(org-roam-db-query
[:insert :into refs :values $v1]
(list (vector ref file type))))) |
I'm not following the details here, but did just want to mention somewhere that native org citation support is finally moving forward, and I expect to be merged to master "soon." |
I don't think that Edit: Actually I may have misunderstood |
@goktug97 how about something like this? (untested) (defun org-roam-db--insert-ref (file ref)
"Insert REF for FILE into the Org-roam cache."
(let* ((cite-prefix (seq-find
(lambda (prefix) (s-prefix? ref))
(-map (lambda (type) (concat type ":"))
org-ref-cite-types)))
(is-website (seq-some
(lambda (prefix) (s-prefix? ref))
'("http" "https")))
(type (cond (cite-prefix "cite")
(is-website "website")
(t "roam")))
(key (cond ((string= "cite" type) (s-chop-prefix cite-prefix ref))
(t ref))))
(org-roam-db-query
[:insert :into refs :values $v1]
(list (vector key file type))))) |
It works perfectly but prefix was missing in (defun org-roam-db--insert-ref (file ref)
"Insert REF for FILE into the Org-roam cache."
(let* ((cite-prefix (seq-find
(lambda (prefix) (s-prefix? prefix ref))
(-map (lambda (type) (concat type ":"))
org-ref-cite-types)))
(is-website (seq-some
(lambda (prefix) (s-prefix? prefix ref))
'("http" "https")))
(type (cond (cite-prefix "cite")
(is-website "website")
(t "roam")))
(key (cond ((string= "cite" type) (s-chop-prefix cite-prefix ref))
(t ref))))
(org-roam-db-query
[:insert :into refs :values $v1]
(list (vector key file type))))) To test it; (dolist (ref '("cite:test" "https://www.github.com" "file:///home/user"))
(let* ((cite-prefix (seq-find
(lambda (prefix) (s-prefix? prefix ref))
(-map (lambda (type) (concat type ":"))
org-ref-cite-types)))
(is-website (seq-some
(lambda (prefix) (s-prefix? prefix ref))
'("http" "https")))
(type (cond (cite-prefix "cite")
(is-website "website")
(t "roam")))
(key (cond ((string= "cite" type) (s-chop-prefix cite-prefix ref))
(t ref))))
(print type))) and it prints
|
oops my bad. Yeah I just tested too and it seems to work |
Okay if we are choosing this route what are we going to do here. EDIT: Of course it should be ref instead of key :D |
The latest commits are not working. I thought they are working but after resetting the emacs I realized the new functions weren't properly loaded in the previous session. EDIT: It is fixed and everything works properly. |
I don't know how MELPA works but should we also update this to 1.1.2 |
I don't think this plays a rôle in MELPA, but yes, this is something that we should update. Edit: Oh, I thought we'd made it to 1.1.2. It seems that we're still on 1.1.0, though, so what's the problem? |
I should have appended the changelog to 1.1.1 instead of creating a new version? If that's true, do you recommend |
Now I know. It's because you've been making your changes on |
CI fails without #562 merged, but #562 causes CI to fail because of compilation errors in org-ref, which I'm tracking here: jkitchin/org-ref#735 |
Thanks for the work. I'm not sure if it's needed for Edit: Oh, just realised you meant this for |
289a792 Docstring update by @jethrokuan |
Woooo tests passing. That red x has been haunting this PR for a long time |
The format of `INFO` argument of `org-roam-find` has been simplified, thanks to the split of `type` and `ref` in the db permitted by org-roam#547. The non-interactive behaviour of `org-roam-find-ref` has also been isolated into `org-roam--find-ref`. Even if it makes us repeat ourselves a bit, it avoids having to nil the interactive argument just to get the non-interactive us, which I think is better syntax.
* (feat): simplify format of `INFO` for find-ref The format of the `INFO` argument of `org-roam-find` has been simplified, thanks to the split of `type` and `ref` in the db permitted by #547. The non-interactive behaviour of `org-roam-find-ref` has also been isolated into `org-roam--find-ref`. Even if it makes us repeat ourselves a bit, it avoids having to nil the interactive argument just to get the non-interactive us, which I think is better syntax. * (feat): implement get-ref-path-completions filtering
… in extract-ref
…rg-roam-db--update-maybe`
Refer #540
The key column is added to the refs table to be able to properly link references in the graph view.