[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/denote 0fac78ada3 338/355: Refine how link format for t
From: |
ELPA Syncer |
Subject: |
[elpa] externals/denote 0fac78ada3 338/355: Refine how link format for target is done |
Date: |
Sun, 26 Jun 2022 23:58:37 -0400 (EDT) |
branch: externals/denote
commit 0fac78ada35107023d0e237e8b3376a2e172faae
Author: Protesilaos Stavrou <info@protesilaos.com>
Commit: Protesilaos Stavrou <info@protesilaos.com>
Refine how link format for target is done
---
denote-link.el | 45 ++++++++++++++++++++++++---------------------
1 file changed, 24 insertions(+), 21 deletions(-)
diff --git a/denote-link.el b/denote-link.el
index 5eaaebbb80..5bbad1a42c 100644
--- a/denote-link.el
+++ b/denote-link.el
@@ -222,6 +222,9 @@ Other files types beside Org always use the `denote:'
links."
(defconst denote-link--format-id-only "[[denote:%s]]"
"Format of identifier-only link to note.")
+(defconst denote-link--format-id-only-with-org-id "[[id:%s]]"
+ "Format of identifier-only link to note with Org id link type.")
+
(defconst denote-link--regexp-org
(concat "\\[\\[" "\\(denote\\|[Ii][Dd]\\):" "\\(?1:" denote--id-regexp
"\\)" "]" "\\[.*?]]"))
@@ -231,17 +234,28 @@ Other files types beside Org always use the `denote:'
links."
(defconst denote-link--regexp-plain
(concat "\\[\\[" "denote:" "\\(?1:" denote--id-regexp "\\)" "]]"))
-(defun denote-link--file-type-format (current-file target-file)
+(defun denote-link--file-type-format (current-file target-file id-only)
"Return link format based on CURRENT-FILE format.
-Account for TARGET-FILE format"
+Account for TARGET-FILE format when choosing the format.
+
+With non-nil ID-ONLY, use the generic link format without a
+title."
;; Includes backup files. Maybe we can remove them?
- (pcase (file-name-extension current-file)
- ("md" denote-link--format-markdown)
- ("txt" denote-link--format-org)
- (_ (if (and denote-link-use-org-id
- (string= (file-name-extension target-file) "org"))
- denote-link--format-org-with-id
- denote-link--format-org))))
+ (let* ((current-file-ext (file-name-extension current-file))
+ (target-file-ext (file-name-extension target-file))
+ (use-org-id (and denote-link-use-org-id (string= target-file-ext
"org"))))
+ (cond
+ (id-only
+ (if use-org-id
+ denote-link--format-id-only-with-org-id
+ denote-link--format-id-only))
+ ((string= current-file-ext "md")
+ denote-link--format-markdown)
+ ((string= current-file-ext "txt")
+ denote-link--format-org) ; Plain text uses [[denote:ID][TITLE]]
+ (t (if use-org-id
+ denote-link--format-org-with-id
+ denote-link--format-org)))))
(defun denote-link--file-type-regexp (file)
"Return link regexp based on FILE format."
@@ -256,17 +270,6 @@ Account for TARGET-FILE format"
(denote-retrieve--value-title file))))
(format pattern file-id file-title)))
-(defun denote-link--extension-format-or-id (id-only &optional target-file)
- "Determine format for link.
-If ID-ONLY is non-nil, use `denote-link--format-id-only', else
-delegate to `denote-link--file-type-format'.
-
-Optional TARGET-FILE is passed to `denote-link--format-id-only'
-to determine if the id: link format will be used in Org."
- (if id-only
- denote-link--format-id-only
- (denote-link--file-type-format (buffer-file-name) target-file)))
-
;;;###autoload
(defun denote-link (target &optional id-only)
"Create link to TARGET note in variable `denote-directory'.
@@ -279,7 +282,7 @@ format is always [[denote:IDENTIFIER]]."
(insert
(denote-link--format-link
target
- (denote-link--extension-format-or-id id-only target)))
+ (denote-link--file-type-format (buffer-file-name) target id-only)))
(unless (derived-mode-p 'org-mode)
(make-button beg (point) 'type 'denote-link-button))))
- [elpa] externals/denote 8eb27246a5 267/355: Refine buffer-local 'denote-directory'; update doc, (continued)
- [elpa] externals/denote 8eb27246a5 267/355: Refine buffer-local 'denote-directory'; update doc, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 385c7e9689 287/355: Clarify use of uspecified face attribute, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 90875d5419 233/355: Sort backlinks from oldest to newest, ELPA Syncer, 2022/06/27
- [elpa] externals/denote efd9d537cd 278/355: Give appropriate name to backlink button object, ELPA Syncer, 2022/06/27
- [elpa] externals/denote a062d9a351 294/355: Update link-related docs (cover buttonization), ELPA Syncer, 2022/06/27
- [elpa] externals/denote 750f8bf95c 307/355: Add FAQ about handling "last modified" scenario, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 627250dc0b 306/355: Make minor rewordings or clarifications to FAW, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 2e13b3451d 347/355: Update denote-link.el Commentary section, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 2d3a6fd8f3 327/355: Reword comment about multi-line button recognition, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 80eb7528aa 335/355: doc: Update documentation, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 0fac78ada3 338/355: Refine how link format for target is done,
ELPA Syncer <=
- [elpa] externals/denote 1f5077181a 326/355: Remove completed to-do about Embark, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 8182604ff3 343/355: Increase max-mini height for rename prompt, ELPA Syncer, 2022/06/27
- [elpa] externals/denote b14b5e201e 339/355: Make denote-link-add-links use id: when necessary, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 4f85d0ece8 355/355: Rephrase description about zk.el alternative, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 84ff0fb674 352/355: Fix alignment in sample front matter, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 1be0255183 340/355: Reword some statements in the manual, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 5c13cf4c1c 354/355: Rename internal id front matter rx for consistency, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 733a89ead5 007/355: Add missing autoload, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 8e7d42b160 016/355: Fix all (?) problems with org-capture integration, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 69f28cfd29 031/355: Re-indent form, ELPA Syncer, 2022/06/27