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

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

[elpa] externals/denote 89d324b28f 2/7: Merge pull request #108 from EFL


From: ELPA Syncer
Subject: [elpa] externals/denote 89d324b28f 2/7: Merge pull request #108 from EFLS/missing-links
Date: Fri, 30 Sep 2022 09:57:33 -0400 (EDT)

branch: externals/denote
commit 89d324b28f190dc6f5480e50ec945fe91f0e2924
Merge: 9b969da55c 6bf916b03e
Author: Protesilaos Stavrou <info@protesilaos.com>
Commit: GitHub <noreply@github.com>

    Merge pull request #108 from EFLS/missing-links
    
    Add denote-link-add-missing-links
---
 README.org | 11 +++++++++++
 denote.el  | 24 ++++++++++++++++++++++++
 2 files changed, 35 insertions(+)

diff --git a/README.org b/README.org
index 66528d7a1a..b3bd2fbf16 100644
--- a/README.org
+++ b/README.org
@@ -1204,6 +1204,17 @@ above is for interactive usage.
 Links are created only for files which qualify as a "note" for our
 purposes ([[#h:fc913d54-26c8-4c41-be86-999839e8ad31][Linking notes]]).
 
+** Insert links, but only those missing from current buffer
+
+#+findex: denote-link-add-missing-links
+As a variation on the =denote-link-add-links= function, one may wish to
+only include 'missing links', i.e. links that are not yet present in
+the current file.
+
+This can be achieved with =denote-link-add-missing-links=. The function
+is similar to =denote-link-add-links=, but will only include links to
+notes that are not yet linked to.
+
 ** Insert links from marked files in Dired
 :PROPERTIES:
 :CUSTOM_ID: h:9cbb692e-5d8a-44a6-9193-899a07872a07
diff --git a/denote.el b/denote.el
index 4036d422b3..5634b69df8 100644
--- a/denote.el
+++ b/denote.el
@@ -2518,6 +2518,30 @@ inserts links with just the identifier."
 
 (defalias 'denote-link-insert-links-matching-regexp (symbol-function 
'denote-link-add-links))
 
+;;;###autoload
+(defun denote-link-add-missing-links (regexp &optional id-only)
+  "Insert missing links to all notes matching REGEXP.
+Similar to `denote-link-add-links' but insert only links not yet
+present in the current buffer.
+
+Optional ID-ONLY has the same meaning as in `denote-link': it
+inserts links with just the identifier."
+  (interactive
+   (list
+    (read-regexp "Insert links matching REGEX: " nil 
'denote-link--add-links-history)
+    current-prefix-arg))
+  (let* ((current-file (buffer-file-name))
+         (current-id (denote-link--file-type-regexp current-file))
+         (linked-files (denote-link--expand-identifiers current-id)))
+    (if-let* ((found-files (delete current-file
+                                  (denote-directory-files-matching-regexp 
regexp)))
+              (final-files (seq-difference found-files linked-files)))
+        (let ((beg (point)))
+          (insert (denote-link--prepare-links final-files current-file 
id-only))
+          (unless (derived-mode-p 'org-mode)
+            (denote-link-buttonize-buffer beg (point))))
+      (user-error "No links matching `%s' that aren't yet present in the 
current buffer." regexp))))
+
 ;;;;; Links from Dired marks
 
 ;; NOTE 2022-07-21: I don't think we need a history for this one.



reply via email to

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