[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/denote 153827f6c8 021/355: Add denote-link
From: |
ELPA Syncer |
Subject: |
[elpa] externals/denote 153827f6c8 021/355: Add denote-link |
Date: |
Sun, 26 Jun 2022 23:57:56 -0400 (EDT) |
branch: externals/denote
commit 153827f6c8009f5426a135c782097bae1463e754
Author: Protesilaos Stavrou <info@protesilaos.com>
Commit: Protesilaos Stavrou <info@protesilaos.com>
Add denote-link
---
denote.el | 45 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)
diff --git a/denote.el b/denote.el
index 0795c14efa..7bd2367277 100644
--- a/denote.el
+++ b/denote.el
@@ -364,5 +364,50 @@ sample template. We will eventually have a manual."
;; TODO 2022-06-04: `denote-rename-file'
+;;;; Link to note
+
+(defun denote--find-key-value-pair (regexp)
+ "Produce a cons cell from REGEXP by searching the file."
+ (goto-char (point-min))
+ (re-search-forward regexp)
+ (cons (match-string-no-properties 1)
+ (match-string-no-properties 2)))
+
+(defvar denote--title-regexp "^\\(#\\+title:\\)[\s\t]+\\(.*\\)"
+ "Regular expression for title key and value.")
+
+(defvar denote--filename-regexp "^\\(#\\+filename:\\)[\s\t]+\\(.*\\)"
+ "Regular expression for filename key and value.")
+
+(defvar denote--identifier-regexp "^\\(#\\+identifier:\\)[\s\t]+\\(.*\\)"
+ "Regular expression for filename key and value.")
+
+;; TODO 2022-06-05: Maybe this should be a defcustom?
+(defvar denote--link-format "[[denote:%s][%s (%s)]]"
+ "Format of Org link to note.")
+
+(defun denote--retrieve-value (note regexp)
+ "Return REGEXP value from NOTE."
+ (let ((default-directory (denote--directory)))
+ (with-temp-buffer
+ (insert-file-contents-literally note)
+ (denote--find-key-value-pair regexp))))
+
+(defun denote--read-file-prompt ()
+ "Prompt for regular file in `denote-directory'."
+ (read-file-name "Select note: " (denote--directory)
+ nil t nil #'file-regular-p))
+
+;;;###autoload
+(defun denote-link (note)
+ "Create Org link to NOTE in `denote-directory'."
+ (interactive (list (denote--read-file-prompt)))
+ (let ((identifier (cdr (denote--retrieve-value note
denote--identifier-regexp)))
+ (filename (string-remove-prefix
+ (denote--directory)
+ (cdr (denote--retrieve-value note
denote--filename-regexp))))
+ (title (cdr (denote--retrieve-value note denote--title-regexp))))
+ (insert (format denote--link-format filename title identifier))))
+
(provide 'denote)
;;; denote.el ends here
- [elpa] externals/denote e9f5c69846 010/355: Placate the compiler, (continued)
- [elpa] externals/denote e9f5c69846 010/355: Placate the compiler, ELPA Syncer, 2022/06/26
- [elpa] externals/denote 39d9870635 018/355: Change punct regexp location; make it defconst, ELPA Syncer, 2022/06/26
- [elpa] externals/denote dd488756f7 019/355: Refine denote--directory-files, ELPA Syncer, 2022/06/26
- [elpa] externals/denote 0aab5bc835 012/355: Tweak code for the sake of org-capture, ELPA Syncer, 2022/06/26
- [elpa] externals/denote d90ea28d00 013/355: Update one-line description, ELPA Syncer, 2022/06/26
- [elpa] externals/denote 0dd4700e32 014/355: Fix typo, ELPA Syncer, 2022/06/26
- [elpa] externals/denote c3674ff813 023/355: Fix typo, ELPA Syncer, 2022/06/26
- [elpa] externals/denote 3790125482 027/355: Remove to-do, ELPA Syncer, 2022/06/26
- [elpa] externals/denote 5744240289 036/355: Remove needless to-do, ELPA Syncer, 2022/06/26
- [elpa] externals/denote aaa691aa15 020/355: Refine front-matter, ELPA Syncer, 2022/06/26
- [elpa] externals/denote 153827f6c8 021/355: Add denote-link,
ELPA Syncer <=
- [elpa] externals/denote 21104787f7 024/355: Put link functionality in denote-link.el, ELPA Syncer, 2022/06/26
- [elpa] externals/denote b951a62245 025/355: Put capture code in denote-org-capture.el, ELPA Syncer, 2022/06/26
- [elpa] externals/denote 9f4a99243c 035/355: Change how org-capture hook is added, ELPA Syncer, 2022/06/26
- [elpa] externals/denote fa6a3315dc 047/355: Add correct group for org capture specifiers, ELPA Syncer, 2022/06/26
- [elpa] externals/denote f33f8a7040 053/355: Rewrite README as a manual, ELPA Syncer, 2022/06/26
- [elpa] externals/denote 251b35d8f5 003/355: Add GPL, ELPA Syncer, 2022/06/26
- [elpa] externals/denote 2aed386b84 006/355: Add denote-org-capture (WORK-IN-PROGRESS), ELPA Syncer, 2022/06/26
- [elpa] externals/denote 0e2cc10fe6 009/355: Improve integration with org-capture-templates, ELPA Syncer, 2022/06/26
- [elpa] externals/denote 1079beb858 017/355: Add todo about file deletion post org-capture, ELPA Syncer, 2022/06/26
- [elpa] externals/denote 27642bee14 026/355: Clarify 'denote' doc string, ELPA Syncer, 2022/06/26