emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] externals/denote efd5135835 039/355: Improve linking functionalit


From: ELPA Syncer
Subject: [elpa] externals/denote efd5135835 039/355: Improve linking functionality
Date: Sun, 26 Jun 2022 23:57:57 -0400 (EDT)

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

    Improve linking functionality
    
    * Add a backlinks' heading.
    * Delete duplicate links.
---
 denote-link.el | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/denote-link.el b/denote-link.el
index bb16594ca7..8273da23cd 100644
--- a/denote-link.el
+++ b/denote-link.el
@@ -79,7 +79,7 @@ Both are supplied by `denote-link'."
 (defun denote-link--read-file-prompt ()
   "Prompt for regular file in `denote-directory'."
   (read-file-name "Select note: " (denote--directory)
-                  nil t nil #'file-regular-p))
+                  nil t nil #'file-regular-p)) ; Includes backup files.  Maybe 
we can remove them?
 
 ;;;###autoload
 (defun denote-link (target)
@@ -101,16 +101,29 @@ Run `denote-link-insert-functions' afterwards."
     (insert target-link)
     (run-hook-with-args 'denote-link-insert-functions target origin-link)))
 
-;; NOTE 2022-06-05: A proof-of-concept.  We need to: (i) have a
-;; Backlinks heading, (ii) delete duplicates, (iii) ensure one backlink
-;; per line, (iv) have a `denote-unlink' command or a
+;; TODO 2022-06-07: have a `denote-unlink' command or a
 ;; `denote-clean-backlinks' for invalid links.
+
+(defconst denote-link-backlink-heading "Denote backlinks"
+  "String of the backlink's heading.
+This heading is appended to a file when another links to it.")
+
 (defun denote-link-backlink (target-file origin-link)
   "Insert ORIGIN-LINK to TARGET-FILE."
-  (let ((default-directory (denote--directory)))
+  (let ((default-directory (denote--directory))
+        (heading denote-link-backlink-heading)
+        heading-point)
     (with-current-buffer (find-file-noselect target-file)
       (goto-char (point-max))
-      (insert origin-link))))
+      (unless (save-excursion (setq heading-point (re-search-backward heading 
nil t)))
+        (unless (denote--line-regexp-p 'empty 0)
+          (newline))
+        (insert (format "* %s\n\n" heading)))
+      (insert (format "- %s\n" origin-link))
+      ;; delete duplicate links
+      (unwind-protect
+          (delete-duplicate-lines heading-point (point-max) nil nil t)
+        (widen)))))
 
 (provide 'denote-link)
 ;;; denote-link.el ends here



reply via email to

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