[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/denote 25fe9870dc 225/355: Finalise 'denote:' custom Or
From: |
ELPA Syncer |
Subject: |
[elpa] externals/denote 25fe9870dc 225/355: Finalise 'denote:' custom Org hyperlink type |
Date: |
Sun, 26 Jun 2022 23:58:27 -0400 (EDT) |
branch: externals/denote
commit 25fe9870dc4db51e022872453d771d6978bf69b5
Author: Protesilaos Stavrou <info@protesilaos.com>
Commit: Protesilaos Stavrou <info@protesilaos.com>
Finalise 'denote:' custom Org hyperlink type
The export part was missing. It is important to return the right
values.
Relevant discussion with Frank Ehmsen on the mailing list:
<https://lists.sr.ht/~protesilaos/denote/%3Ccfb70295-4e54-0f54-559c-c9423df5a1d8@eh-is.de%3E>.
---
denote-link.el | 50 +++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 39 insertions(+), 11 deletions(-)
diff --git a/denote-link.el b/denote-link.el
index b412b69017..117d1cddaf 100644
--- a/denote-link.el
+++ b/denote-link.el
@@ -294,10 +294,28 @@ manual for more on the matter)."
(org-link-set-parameters
"denote"
:follow #'denote-link-ol-follow
- :complete #'denote-link-ol-complete))
+ :complete #'denote-link-ol-complete
+ :export #'denote-link-ol-export))
(declare-function org-link-open-as-file "ol" (path arg))
+(defun denote-link--ol-resolve-link-to-target (link &optional path-id)
+ "Resolve LINK into the appropriate target.
+With optional PATH-ID return a cons cell consisting of the path
+and the identifier."
+ (let* ((search (and (string-match "::\\(.*\\)\\'" link)
+ (match-string 1 link)))
+ (id (if (and (stringp search) (not (string-empty-p search)))
+ (substring link 0 (match-beginning 0))
+ link))
+ (path (expand-file-name (file-name-completion id
(denote-directory)))))
+ (cond
+ (path-id
+ (cons (format "%s" path) (format "%s" id)))
+ ((and (stringp search) (not (string-empty-p search)))
+ (concat path "::" search))
+ (path))))
+
(defun denote-link-ol-follow (link)
"Find file of type `denote:' matching LINK.
LINK is the identifier of the note, optionally followed by a
@@ -306,16 +324,9 @@ Read Info node `(org) Search Options'.
Uses the function `denote-directory' to establish the path to the
file."
- (let* ((search (and (string-match "::\\(.*\\)\\'" link)
- (match-string 1 link)))
- (id (if (and (stringp search) (not (string-empty-p search)))
- (substring link 0 (match-beginning 0))
- link))
- (path (expand-file-name (file-name-completion id (denote-directory))))
- (target (if (and (stringp search) (not (string-empty-p search)))
- (concat path "::" search)
- path)))
- (org-link-open-as-file target nil)))
+ (org-link-open-as-file
+ (denote-link--ol-resolve-link-to-target link)
+ nil))
(defun denote-link-ol-complete ()
"Like `denote-link' but for Org integration.
@@ -326,5 +337,22 @@ interface by first selecting the `denote:' hyperlink type."
(denote-retrieve--read-file-prompt)
(denote-link--file-type-format (buffer-file-name)))))
+(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
+backend."
+ (let* ((path-id (denote-link--ol-resolve-link-to-target link :path-id))
+ (path (file-name-nondirectory (car path-id)))
+ (p (file-name-sans-extension path))
+ (id (cdr path-id))
+ (desc (or description (concat "denote:" id))))
+ (cond
+ ((eq format 'html) (format "<a target=\"_blank\" href=\"%s.html\">%s</a>"
p desc))
+ ((eq format 'latex) (format "\\href{%s}{%s}" (replace-regexp-in-string
"[\\{}$%&_#~^]" "\\\\\\&" path) desc))
+ ((eq format 'texinfo) (format "@uref{%s,%s}" path desc))
+ ((eq format 'ascii) (format "[%s] <denote:%s>" desc path)) ; NOTE
2022-06-16: May be tweaked further
+ ((eq format 'md) (format "[%s](%s.md)" desc p))
+ (t path))))
+
(provide 'denote-link)
;;; denote-link.el ends here
- [elpa] externals/denote 72f77178af 344/355: Refine denote-link-use-org-id doc string, (continued)
- [elpa] externals/denote 72f77178af 344/355: Refine denote-link-use-org-id doc string, ELPA Syncer, 2022/06/27
- [elpa] externals/denote f307e32693 011/355: Expand the README, ELPA Syncer, 2022/06/27
- [elpa] externals/denote bfb2cdefd7 195/355: Rewrite manual on links (getting closer to v0.1.0), ELPA Syncer, 2022/06/27
- [elpa] externals/denote e37e429844 198/355: Add possible to-do for using xref, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 2327b5beb6 212/355: Add helper FNs to return title and date values, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 98113698a7 202/355: Expand sample configuration, ELPA Syncer, 2022/06/27
- [elpa] externals/denote cbaab43170 240/355: Update Acknowledgement: svnsbck => Sven Seebeck, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 9be3cfab99 215/355: Relocate defcustom where it belongs, ELPA Syncer, 2022/06/27
- [elpa] externals/denote b25704e041 211/355: Make denote-retrieve--value pass optional group, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 24997c6bc5 226/355: Remove "work-in-progress" from backlinks' section, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 25fe9870dc 225/355: Finalise 'denote:' custom Org hyperlink type,
ELPA Syncer <=
- [elpa] externals/denote 13bae5f9c4 235/355: Remove instability warnings (v0.1.0 is close), ELPA Syncer, 2022/06/27
- [elpa] externals/denote 1b4dc74e3c 224/355: Update denote-dired.el Commentary section, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 3a63c763c5 218/355: Improve post-rename front matter rewrite, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 5213c9e7af 241/355: Add section with alternatives to Denote, ELPA Syncer, 2022/06/27
- [elpa] externals/denote e0ff114a93 238/355: Update Denote sources in manual's introduction, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 7ce2f7d3e3 251/355: Use the 'denote-directory' function, not variable, ELPA Syncer, 2022/06/27
- [elpa] externals/denote c8f3e707c2 223/355: Revise one-line descriptions, where needed, ELPA Syncer, 2022/06/27
- [elpa] externals/denote a436cdf07e 221/355: Tweak doc strings, ELPA Syncer, 2022/06/27
- [elpa] externals/denote a5940b315a 265/355: Replace needless 'let*' with 'let', ELPA Syncer, 2022/06/27
- [elpa] externals/denote 5686e86cfc 262/355: Only show valid notes in file prompt, ELPA Syncer, 2022/06/27