Skip to content
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

Merged
merged 33 commits into from
May 4, 2020
Merged

Adding key column to db #547

merged 33 commits into from
May 4, 2020

Conversation

goktug97
Copy link
Member

@goktug97 goktug97 commented May 1, 2020

Refer #540
The key column is added to the refs table to be able to properly link references in the graph view.

org-roam-db.el Outdated
[:insert :into refs
:values $v1]
(list (vector ref file))))
(let ((key (elt (split-string ref ":") 1)))
Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(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)))
Copy link
Contributor

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)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(let ((key (elt (split-string ref ":") 1)))
(let ((key ref))
(dolist (prefix org-ref-cite-types)
(setq key (string-remove-prefix (concat prefix ":") key)))

Copy link
Member

@jethrokuan jethrokuan left a 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)])))
Copy link
Member

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:

  1. cite if the prefix is an org-ref cite link (as per org-ref-cite-types)
  2. website if it's a URL (optional, nothing is being done with this)
  3. `roam' otherwise.

Copy link
Contributor

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

Copy link
Member

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.

Copy link
Contributor

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

@goktug97
Copy link
Member Author

goktug97 commented May 2, 2020

Let's call this type instead, same as the links table. Key will then take on values:

1. `cite` if the prefix is an org-ref cite link (as per `org-ref-cite-types`)

2. `website` if it's a URL (optional, nothing is being done with this)

3. `roam' otherwise.

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)))))

@bdarcus
Copy link
Contributor

bdarcus commented May 2, 2020

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."

@TimQuelch
Copy link
Contributor

TimQuelch commented May 2, 2020

Maybe something like this?

I don't think that cl-find will work correctly.. parencite:key will match to cite. You'll then try to remove the prefix cite: which does not exist. Therefore ref will remain parencite:key

Edit: Actually I may have misunderstood cl-find

@TimQuelch
Copy link
Contributor

TimQuelch commented May 2, 2020

@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)))))

@goktug97
Copy link
Member Author

goktug97 commented May 2, 2020

@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 s-prefix? so I added that.

(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

"cite"

"website"

"roam"
nil

@TimQuelch
Copy link
Contributor

TimQuelch commented May 2, 2020

It works perfectly but prefix was missing in s-prefix? so I added that.

oops my bad.

Yeah I just tested too and it seems to work

@goktug97
Copy link
Member Author

goktug97 commented May 2, 2020

Okay if we are choosing this route what are we going to do here.
https://github.com/jethrokuan/org-roam/blob/e698ed7f5378106da8a8fec4537658392157657c/org-roam-graph.el#L175-L176

EDIT: Of course it should be ref instead of key :D

@goktug97
Copy link
Member Author

goktug97 commented May 2, 2020

I added preview functionality to the org-roam-server,
as soon as we are done with this PR, I will push the changes to the repo and open a pull request for the MELPA

EDIT: Pushed to Github because it seems there is no change needed to org-roam-server after this PR is pushed.

image

@goktug97
Copy link
Member Author

goktug97 commented May 2, 2020

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.

@goktug97
Copy link
Member Author

goktug97 commented May 2, 2020

I don't know how MELPA works but should we also update this to 1.1.2

@zaeph
Copy link
Member

zaeph commented May 2, 2020

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?

@goktug97
Copy link
Member Author

goktug97 commented May 2, 2020

I should have appended the changelog to 1.1.1 instead of creating a new version? If that's true, do you recommend ammend or a new commit?

@zaeph
Copy link
Member

zaeph commented May 4, 2020

Allow edits by maintainers was on but I merged the PR

Now I know. It's because you've been making your changes on master instead of on a feature-branch.

@jethrokuan
Copy link
Member

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

@zaeph
Copy link
Member

zaeph commented May 4, 2020

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 bibtex-completion to require Emacs 26.1.

Edit: Oh, just realised you meant this for org-ref, and that it's probably just a checking they need to change for their Travis.

@goktug97
Copy link
Member Author

goktug97 commented May 4, 2020

289a792 Docstring update by @jethrokuan
7d1fc3e Same docstring update by @goktug97
Sorry it seems you've already made the changes

@goktug97 goktug97 requested a review from jethrokuan May 4, 2020 12:19
@TimQuelch
Copy link
Contributor

Woooo tests passing. That red x has been haunting this PR for a long time

@jethrokuan jethrokuan merged commit 11d239d into org-roam:master May 4, 2020
zaeph added a commit to zaeph/org-roam that referenced this pull request May 4, 2020
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.
zaeph added a commit that referenced this pull request May 4, 2020
* (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
goktug97 added a commit to goktug97/org-roam that referenced this pull request Jun 4, 2020
goktug97 added a commit to goktug97/org-roam that referenced this pull request Jun 4, 2020
goktug97 added a commit to goktug97/org-roam that referenced this pull request Jun 4, 2020
goktug97 added a commit to goktug97/org-roam that referenced this pull request Jun 4, 2020
goktug97 added a commit to goktug97/org-roam that referenced this pull request Jun 4, 2020
goktug97 added a commit to goktug97/org-roam that referenced this pull request Jun 4, 2020
goktug97 added a commit to goktug97/org-roam that referenced this pull request Jun 4, 2020
goktug97 added a commit to goktug97/org-roam that referenced this pull request Jun 4, 2020
goktug97 added a commit to goktug97/org-roam that referenced this pull request Jun 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants