[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/denote 9f192263db 092/355: Remove file path from front

From: ELPA Syncer
Subject: [elpa] externals/denote 9f192263db 092/355: Remove file path from front matter; improve links
Date: Sun, 26 Jun 2022 23:58:03 -0400 (EDT)

branch: externals/denote
commit 9f192263dbfadea388dbde390042cbc28f49a338
Author: Protesilaos Stavrou <info@protesilaos.com>
Commit: Protesilaos Stavrou <info@protesilaos.com>

    Remove file path from front matter; improve links
    It is not necessary to pollute the front matter with such details.
    Files are always relative to the present directory.  The linking
    facility is updated to work as intended (per commit 929157d).
    This is an update on commit cfe6e98, which was reverted earlier by
 denote-link.el | 30 ++++++++++++------------------
 denote.el      |  8 +++-----
 2 files changed, 15 insertions(+), 23 deletions(-)

diff --git a/denote-link.el b/denote-link.el
index 24b2dff1a0..e07d31e968 100644
--- a/denote-link.el
+++ b/denote-link.el
@@ -56,9 +56,6 @@ Both are supplied by `denote-link'."
 (defconst denote-link--title-regexp "^\\(#\\+title:\\)[\s\t]+\\(.*\\)"
   "Regular expression for title key and value.")
-(defconst denote-link--filename-regexp "^\\(#\\+filename:\\)[\s\t]+\\(.*\\)"
-  "Regular expression for filename key and value.")
 (defconst denote-link--identifier-regexp 
   "Regular expression for filename key and value.")
@@ -83,26 +80,23 @@ Both are supplied by `denote-link'."
   (read-file-name "Select note: " (denote-directory)
                   nil t nil #'file-regular-p)) ; Includes backup files.  Maybe 
we can remove them?
+(defun denote-link--format-link (file &optional backlink)
+  "Format link to FILE.
+With optional BACKLINK, format it as a backlink."
+  (let* ((dir (denote-directory))
+         (file-id (cdr (denote-link--retrieve-value file 
+         (file-path (file-name-completion file-id dir))
+         (file-title (cdr (denote-link--retrieve-value file 
+         (pattern (if backlink denote-link--backlink-format 
+    (format pattern file-path file-title file-id)))
 (defun denote-link (target)
   "Create Org link to TARGET note in variable `denote-directory'.
 Run `denote-link-insert-functions' afterwards."
   (interactive (list (denote-link--read-file-prompt)))
-  (let* ((dir (denote-directory))
-         ;; TODO 2022-06-09: This is probably the ugliest function in
-         ;; the whole project.  We need to make it more readable by
-         ;; extracting the parts that should go in helper functions.
-         (target-id (cdr (denote-link--retrieve-value target 
-         (target-name (string-remove-prefix
-                       dir (cdr (denote-link--retrieve-value target 
-         (target-title (cdr (denote-link--retrieve-value target 
-         (target-link (format denote-link--link-format target-name 
target-title target-id))
-         (origin-note (buffer-file-name))
-         (origin-id (cdr (denote-link--retrieve-value origin-note 
-         (origin-name (string-remove-prefix
-                       dir (cdr (denote-link--retrieve-value origin-note 
-         (origin-title (cdr (denote-link--retrieve-value origin-note 
-         (origin-link (format denote-link--backlink-format origin-name 
origin-title origin-id)))
+  (let* ((target-link (denote-link--format-link target))
+         (origin-link (denote-link--format-link (buffer-file-name) :backlink)))
     (insert target-link)
     (run-hook-with-args 'denote-link-insert-functions target origin-link)))
diff --git a/denote.el b/denote.el
index 639715639b..5dfa54d83d 100644
--- a/denote.el
+++ b/denote.el
@@ -288,7 +288,7 @@ is specified."
         (ext (or extension ".org")))
     (format "%s%s--%s--%s%s" path id kws slug ext)))
-(defun denote--file-meta-header (title date keywords filename id)
+(defun denote--file-meta-header (title date keywords id)
   "Front matter for new notes.
 TITLE, DATE, KEYWORDS, FILENAME, ID are all strings which are
@@ -298,9 +298,7 @@ TITLE, DATE, KEYWORDS, FILENAME, ID are all strings which 
             "#+date:       " date      "\n"
             "#+filetags:   " kw        "\n"
             "#+identifier: " id        "\n"
-            "#+filename:   " (string-remove-prefix denote-directory filename)  
-            "#+path:       " filename  "\n"
-            "\n\n")))
+            "\n")))
 (defun denote--path (title keywords)
   "Return path to new file with TITLE and KEYWORDS.
@@ -329,7 +327,7 @@ Use optional PATH, else create it with `denote--path'."
          (default-directory denote-directory)
          (buffer (unless path (find-file p)))
          (header (denote--file-meta-header
-                  title (denote--date) keywords p
+                  title (denote--date) keywords
                   (format-time-string denote--id))))
     (unless path
       (with-current-buffer buffer (insert header))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]