Skip to content

Commit

Permalink
Add support for org-store-link.
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Marc Fargas authored and protesilaos committed Sep 5, 2022
1 parent a143347 commit dd086b7
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions denote.el
Original file line number Diff line number Diff line change
Expand Up @@ -2374,6 +2374,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
Expand Down Expand Up @@ -2407,6 +2421,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
Expand Down

0 comments on commit dd086b7

Please sign in to comment.