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

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

[elpa] externals/denote 91f0208506 3/3: Define Org dynamic block to inse


From: ELPA Syncer
Subject: [elpa] externals/denote 91f0208506 3/3: Define Org dynamic block to insert only missing links
Date: Mon, 29 Jan 2024 00:57:38 -0500 (EST)

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

    Define Org dynamic block to insert only missing links
    
    This brings back a feature that was deprecated in version 2.2.0, but
    makes changes to it so that (i) it is more limited in scope and (ii)
    available as a standalone Org dynamic block.
    
    Thanks to Stephen R. Kifer, Peter Prevos, and Elias Storms for the
    discussion which made it clear to me that users do have a need for
    such functionality:
    
<https://lists.sr.ht/~protesilaos/denote/%3C1db2104e-70bd-47f9-a7ed-b8d4bb370a7f%40app.fastmail.com%3E>.
---
 README.org           | 22 ++++++++++++++++----
 denote-org-extras.el | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 74 insertions(+), 5 deletions(-)

diff --git a/README.org b/README.org
index 734742a8cf..1854d62857 100644
--- a/README.org
+++ b/README.org
@@ -2611,6 +2611,20 @@ this in an Org file:
 :
 : #+END:
 
+[ The ~denote-org-extras-dblock-insert-missing-links~ is part of
+  {{{development-version}}}. ]
+
+#+findex: denote-org-extras-dblock-insert-missing-links
+Finally, the =denote-missing-links= block is available with the
+command ~denote-org-extras-dblock-insert-missing-links~. It is like
+the aforementioned =denote-links= block, except it only lists links to
+files that are not present in the current buffer. The parameters are
+otherwise the same:
+
+: #+BEGIN: denote-missing-links :regexp "YOUR REGEXP HERE" :sort-by-component 
nil :reverse-sort nil :id-only nil
+:
+: #+END:
+
 Remember to type =C-c C-x C-u= (~org-dblock-update~) with point on the
 =#+BEGIN= line to update the block.
 
@@ -4967,10 +4981,10 @@ Denote is meant to be a collective effort.  Every bit 
of help matters.
   Bagneris, Jean-Philippe Gagné Guay, Joseph Turner, Jürgen Hötzel,
   Kaushal Modi, Kai von Fintel, Kostas Andreadis, Kyle Meyer, Marc
   Fargas, Matthew Lemon, Noboru Ota (nobiot), Norwid Behrnd, Peter
-  Prevos, Philip Kaludercic, Quiliro Ordóñez, Stefan Monnier, Stefan
-  Thesing, Thibaut Benjamin, Tomasz Hołubowicz, Vedang Manerikar,
-  Wesley Harvey, arsaber101, ezchi, leinfink (Henrik), l-o-l-h
-  (Lincoln), mentalisttraceur, relict007.
+  Prevos, Philip Kaludercic, Quiliro Ordóñez, Stephen R. Kifer, Stefan
+  Monnier, Stefan Thesing, Thibaut Benjamin, Tomasz Hołubowicz, Vedang
+  Manerikar, Wesley Harvey, arsaber101, ezchi, leinfink (Henrik),
+  l-o-l-h (Lincoln), mentalisttraceur, relict007.
 
 + Ideas and/or user feedback :: Abin Simon, Aditya Yadav, Alan
   Schmitt, Aleksandr Vityazev, Alfredo Borrás, Ashton Wiersdorf,
diff --git a/denote-org-extras.el b/denote-org-extras.el
index 4af98e5fd5..9b5e10889f 100644
--- a/denote-org-extras.el
+++ b/denote-org-extras.el
@@ -185,7 +185,9 @@ Make the new note an Org file regardless of the value of
   "Return list of FILES-MATCHING-REGEXP in variable `denote-directory'.
 SORT-BY-COMPONENT and REVERSE have the same meaning as
 `denote-sort-files'.  If both are nil, do not try to perform any
-sorting."
+sorting.
+
+Also see `denote-org-extras-dblock--files-missing-only'."
   (cond
    ((and sort-by-component reverse)
     (denote-sort-get-directory-files files-matching-regexp sort-by-component 
reverse :omit-current))
@@ -196,6 +198,28 @@ sorting."
    (t
     (denote-directory-files files-matching-regexp :omit-current))))
 
+(defun denote-org-extras-dblock--get-missing-links (regexp)
+  "Return list of missing links to all notes matching REGEXP.
+Missing links are those for which REGEXP does not have a match in
+the current buffer."
+  (if-let ((found-files (denote-directory-files regexp :omit-current))
+           (linked-files (denote-link--expand-identifiers 
denote-org-link-in-context-regexp))
+           (final-files (seq-difference found-files linked-files)))
+      final-files
+    (message "All links matching `%s' are present" regexp)))
+
+(defun denote-org-extras-dblock--files-missing-only (files-matching-regexp 
&optional sort-by-component reverse)
+  "Return list of missing links to FILES-MATCHING-REGEXP.
+SORT-BY-COMPONENT and REVERSE have the same meaning as
+`denote-sort-files'.  If both are nil, do not try to perform any
+sorting.
+
+Also see `denote-org-extras-dblock--files'."
+  (denote-sort-files
+   (denote-org-extras-dblock--get-missing-links files-matching-regexp)
+   sort-by-component
+   reverse))
+
 ;;;;; Dynamic block to insert links
 
 ;;;###autoload
@@ -227,6 +251,37 @@ Used by `org-dblock-update' with PARAMS provided by the 
dynamic block."
     (denote-link--insert-links files 'org (plist-get params :id-only) 
:no-other-sorting)
     (join-line))) ; remove trailing empty line
 
+;;;;; Dynamic block to insert missing links
+
+;;;###autoload
+(defun denote-org-extras-dblock-insert-missing-links (regexp)
+  "Create Org dynamic block to insert Denote links matching REGEXP."
+  (interactive
+   (list
+    (denote-files-matching-regexp-prompt))
+   org-mode)
+  (org-create-dblock (list :name "denote-missing-links"
+                           :regexp regexp
+                           :sort-by-component nil
+                           :reverse-sort nil
+                           :id-only nil))
+  (org-update-dblock))
+
+(org-dynamic-block-define "denote-missing-links" 
'denote-org-extras-dblock-insert-links)
+
+(defun org-dblock-write:denote-missing-links (params)
+  "Function to update `denote-links' Org Dynamic blocks.
+Used by `org-dblock-update' with PARAMS provided by the dynamic block."
+  (let* ((regexp (plist-get params :regexp))
+         (rx (if (listp regexp) (macroexpand `(rx ,regexp)) regexp))
+         (sort (plist-get params :sort-by-component))
+         (reverse (plist-get params :reverse-sort))
+         (block-name (plist-get params :block-name))
+         (files (denote-org-extras-dblock--files-missing-only rx sort 
reverse)))
+    (when block-name (insert "#+name: " block-name "\n"))
+    (denote-link--insert-links files 'org (plist-get params :id-only) 
:no-other-sorting)
+    (join-line))) ; remove trailing empty line
+
 ;;;;; Dynamic block to insert backlinks
 
 (defun denote-org-extras-dblock--maybe-sort-backlinks (files sort-by-component 
reverse)



reply via email to

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