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

Full support for orgmode links (denote: type) #104

Closed
telenieko opened this issue Sep 3, 2022 · 8 comments
Closed

Full support for orgmode links (denote: type) #104

telenieko opened this issue Sep 3, 2022 · 8 comments

Comments

@telenieko
Copy link

telenieko commented Sep 3, 2022

Hi,

Denote, within orgmode files, uses the denote: link type internally. denote-link inserts such links.

One may expect such links to work on any orgmode files, for example on your org-agenda-files. Which works, because:

          (org-link-set-parameters
           "denote"
           :follow #'denote-link-ol-follow
           :face #'denote-link-ol-face
           :complete #'denote-link-ol-complete
           :export #'denote-link-ol-export)

But there is someone missing there, :store. This means you cannot save a denote: links to a note using standard orgmode tooling (org-store-link). For example:

  • if you want to get a link to the current note to insert it somewhere.
  • you want to use org-capture from a note, for example to add a task on your agenda linking to that note.

This is unrelated to #8 / #20 / denote-link-use-org-id though mixed with org-id-extra-files might enable some workflows (only to orgmode format notes).

So:

  1. you can, now, follow denote: links from any org file anywhere to your denote notes in any format.
  2. you can, now, insert (org-insert-link) links to denote: notes in any orgmode file.
  3. you can NOT, use org-store-link to get a link to the current note; which prevents using %a in org-capture

The fix is easy though, implement :store; This is my current take on it:

;; only add :store, all else is already set by denote.
(org-link-set-parameters
 "denote"
 :store #'denote-link-ol-store)


(defun denote-link-ol-store()
  "Store an org-link to a denote note using denote: link."
  (when (denote--current-file-is-note-p)
    ;; this let* comes from `denote-link--format-link'
    (let* ((file (buffer-file-name))
           (file-type (denote--filetype-heuristics file))
           (file-id (denote--retrieve-filename-identifier file))
           (file-title (denote--retrieve-title-or-filename file file-type)))
      
      (org-link-store-props
       :type "denote"
       :description file-title
       :link (concat "denote:" file-id)))
    org-store-link-plist))

This should work with notes in any format, now org-capture works and org-store-link too.

Did I miss anything? Is there any particular reason this is not yet in denote? (seems odd that all other org-link-set-parameters are there but this).

If the code looks good I can open a PR (or try to submit it via the mailing list as an exercise!!), maybe in time for 1.0 !!

@protesilaos
Copy link
Owner

Hello @telenieko and thanks for the detailed explanation!

Yes, please proceed to the PR. The denote-link-ol-store is within the ~15 line limit we have before requiring copyright assignment to the Free Software Foundation.

As for why this wasn't already done: (i) I was not sure it was needed, as I thought people might prefer the regular file: hyperlink type, and (ii) you are the first one to ask about it. So here we are!

@protesilaos
Copy link
Owner

I forgot to mention: you are welcome to try the mailing list+patch workflow. Whatever you prefer.

@telenieko
Copy link
Author

Submitted via e-mail: https://lists.sr.ht/~protesilaos/denote/patches/35137
closing this.

@protesilaos
Copy link
Owner

Thank you!

protesilaos pushed a commit that referenced this issue Sep 5, 2022
Hi,

Denote, uses the `denote:` link type internally.

This patch adds support for `org-store-link` of denote files meaning
that you can call `org-store-link` from a note and get a `denote:` link
instead of the current `file:` link.

The main benefit of a denote link is that it is resilient to renames,
etc. A file link would brake if the note was ever to be renamed.

As a side benefit, as `org-capture` uses `org-store-link` now you can
capture tasks on notes with resilient links!

This may seem related to `denote-link-use-org-id` though that one would
only work with orgmode notes (and, I think, as long as those were
withing `org-directory` when using `id:` links).

This should work with notes in any format, now `org-capture` works and
`org-store-link` too.

Best,
Marc

PS: This closes #104 on Github[1].
PSS: Second attempt at submitting a patch via git-email ...

[1]: #104

Signed-off-by: Marc Fargas <[email protected]>
protesilaos added a commit that referenced this issue Sep 5, 2022
The patch is below the ~15 line threshold and thus does not require
copyright assignment to the Free Software Foundation.

It was discussed on the mailing list:
<https://lists.sr.ht/~protesilaos/denote/patches/35137>.  A prior
exchange took place on issue 104 over at the GitHub mirror:
<#104>.
@gregoryg
Copy link

As for why this wasn't already done: (i) I was not sure it was needed, as I thought people might prefer the regular file: hyperlink type, and (ii) you are the first one to ask about it. So here we are!

@protesilaos are the denote: links requisite for Denote to compute backlinks? I would prefer to use file: links, mostly for interop with non-Emacs tools such as Logseq and Hugo.

@protesilaos
Copy link
Owner

Hello @gregoryg! Yes, the backlinks work with the file: links. I tried it with the following files:

#+title:      Another test
#+date:       [2022-10-23 Sun 19:47]
#+filetags:   :denote:testing:
#+identifier: 20221023T194724

[[file:20221023T194710--this-is-a-test__denote_testing.org][Just a test]]
#+title:      This is a test
#+date:       [2022-10-23 Sun 19:47]
#+filetags:   :denote:testing:
#+identifier: 20221023T194710

In the latter I invoked denote-link-backlinks and got the backlinks' buffer. Same principle for the denote-link-find-backlink, which uses the minibuffer to show a list of the backlinks (with completion).


The downside of the file: links is that they will break if you rename the file. Whereas the denote: ones will work for as long as the file is in the denote-directory.

@gregoryg
Copy link

OK - I should have done that test myself - but it's good to know from you that there are no "hidden" downsides! Thank you for this response and for the excellent package!

Your lean approach is refreshing - when I first stared using Denote, I would look for the "search notes" function and the "go to directory" function and so forth. Suddenly realizing I could just add a regular bookmark made me laugh.

@protesilaos
Copy link
Owner

OK - I should have done that test myself - but it's good to know from you that there are no "hidden" downsides!

There shouldn't be any hidden downsides, though please let me know if you encounter any. I have not done any work using your approach.

Thank you for this response and for the excellent package!

You are welcome!

Your lean approach is refreshing - when I first stared using Denote, I would look for the "search notes" function and the "go to directory" function and so forth. Suddenly realizing I could just add a regular bookmark made me laugh.

Ah yes, this the point where you realise that these are regular files/buffers and Emacs already has a tone of ways to operate on them. I am happy to accommodate extensions or other packages in general. This way we have a maintainable core and can integrate with a variety of tools.

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

No branches or pull requests

3 participants