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]: https://github.com/protesilaos/denote/issues/104
Signed-off-by: Marc Fargas <marc@marcfargas.com>
---
denote.el | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/denote.el b/denote.el
index bb134b3..15da94b 100644
--- a/denote.el+++ b/denote.el
@@ -2371,6 +2371,20 @@ interface by first selecting the `denote:' hyperlink type."
"denote:"
(denote--retrieve-filename-identifier (denote--retrieve-read-file-prompt))))
+(defun denote-link-ol-store()+ "Handler for `org-store-link' adding support for denote: links."+ (when (denote--current-file-is-note-p)+ (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))+(defun denote-link-ol-export (link description format)
"Export a `denote:' link from Org files.
The LINK, DESCRIPTION, and FORMAT are handled by the export
@@ -2404,6 +2418,7 @@ backend."
:follow #'denote-link-ol-follow
:face #'denote-link-ol-face
:complete #'denote-link-ol-complete
+ :store #'denote-link-ol-store :export #'denote-link-ol-export)))))
;;;; Glue code for org-capture
--
> From: Marc Fargas <marc@marcfargas.com>> Date: Mon, 05 Sep 2022 12:25:29 +0200>> Hi,
Hello Marc and thanks for patch!
[ Also thanks for our discussion on the GitHub issue you linked to! ]
> 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.
The reason I had not implemented this was that I was not sure about its
implications.
For example, a user may want to create a regular Org 'file:' link to a
Denote note from outside their 'denote-directory'. They have a
~/tasks.org where they maintain all their TODOs. Their notes are in
~/Documents/notes and they need to capture a TODO that is related to one
of their Org notes. Since the link will be written in ~/tasks.org only
the 'file:' link type will work. The 'denote:' link type works within
the 'denote-directory'.
With your patch, such a workflow will no longer be possible, right? On
the other hand, there are the benefits you mention, which make more
sense for Denote's purposes.
Does anyone reading this has an opinion on the matter? Do you think
'M-x org-store-link' and, by extension, 'M-x org-capture' should always
store a 'denote:' link type when in the context of our notes? Or should
we keep the 'file:'?
All the best,
Protesilaos (or simply "Prot")
--
Protesilaos Stavrou
https://protesilaos.com
Hi,
El lun. 5 de sep. 2022, Protesilaos escribió
>> From: Marc Fargas <marc@marcfargas.com>>> Date: Mon, 05 Sep 2022 12:25:29 +0200>>>> (...)>> 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 reason I had not implemented this was that I was not sure about its> implications.>> For example, a user may want to create a regular Org 'file:' link to a> Denote note from outside their 'denote-directory'.
Note that this does not affect `org-insert-link` (manually creating
links) where you can still opt for `file:`, `id:` or `denote:`. It only
affects the `org-store-link` system:
- When you call `org-store-link` manually (like you would call it from
an email viewer, a PDF file or elsewhere)
- When you call `org-capture` which uses the `org-store-link` system to
make the "origin" available to the capture template.
> They have a> ~/tasks.org where they maintain all their TODOs. Their notes are in> ~/Documents/notes and they need to capture a TODO that is related to one> of their Org notes. Since the link will be written in ~/tasks.org only> the 'file:' link type will work.
The workflow you described is precisely mine:
Having `org-directory` and/or `org-agenda-files` set to something out of
`denote-directory`. And `denote-directory` not being inside any of
those: be able to follow `denote:` links.
Right now if I do `org-capture` to add a task on my tasks file I get
a `file:` link, this is the current behaviour of `org-store-link`
because it does not know any better.
But those links will break if the note is renamed (title or
keywords changed).
> The 'denote:' link type works within the 'denote-directory'.> With your patch, such a workflow will no longer be possible, right?
As far as I see the `denote:` link will work anywhere as
long as the *target* note is in `denote-directory`. This is because
`denote-link-ol-follow` does not really care about the link location,
only the target.
You can quickly check this by creating an org file inside /tmp or
elsewhere, call `org-insert-link`, insert a `denote:` link and follow it.
Bottom line: `denote:` links should (already) work regardless of where
the link is as long as the target note file is in `denote-directory`.
> On the other hand, there are the benefits you mention, which make more> sense for Denote's purposes.
The main benefit would be that (I believe) most users will expect that
using org-capture from within a Denote note will create a "permanent"
link that does not break if the note title or keywords are changed.
Specially given that `denote:` link type exists, can be inserted and can
be followed and is what `denote-link` inserts.
> Does anyone reading this has an opinion on the matter? Do you think> 'M-x org-store-link' and, by extension, 'M-x org-capture' should always> store a 'denote:' link type when in the context of our notes? Or should> we keep the 'file:'?
Also, does anyone anticipate any other possibly unwelcome side-effects?
Best,
marc
> From: Marc Fargas <marc@marcfargas.com>> Date: Mon, 05 Sep 2022 13:09:36 +0200>> The 'denote:' link type works within the 'denote-directory'.>> With your patch, such a workflow will no longer be possible, right?>> As far as I see the `denote:` link will work anywhere as> long as the *target* note is in `denote-directory`. This is because> `denote-link-ol-follow` does not really care about the link location,> only the target.>> You can quickly check this by creating an org file inside /tmp or> elsewhere, call `org-insert-link`, insert a `denote:` link and follow it.>> Bottom line: `denote:` links should (already) work regardless of where> the link is as long as the target note file is in `denote-directory`.
You are right! They do work with Org files. I thus need to revise the
mechanism for the others because they don't...
I am thus installing your patch, as I cannot think of any other
downsides.
Thanks again!
--
Protesilaos Stavrou
https://protesilaos.com
> From: Protesilaos Stavrou <info@protesilaos.com>> Date: Mon, 05 Sep 2022 14:37:32 +0300> [... 15 lines elided]>> Bottom line: `denote:` links should (already) work regardless of where>> the link is as long as the target note file is in `denote-directory`.>> You are right! They do work with Org files. I thus need to revise the> mechanism for the others because they don't...
A quick follow-up on my point about this. The mechanism is fine. It's
just the command 'denote-link-find-file' that needs some tweaks.
Working on it now.
--
Protesilaos Stavrou
https://protesilaos.com