branch: externals/denote-org
commit 7873643ac5541e0137e05fbab7c20f788ecd24be
Author: Protesilaos Stavrou <i...@protesilaos.com>
Commit: Protesilaos Stavrou <i...@protesilaos.com>

    Implement :not-regexp for backlinks Org dynamic block
---
 README.org    |   4 ++-
 denote-org.el | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 114 insertions(+), 4 deletions(-)

diff --git a/README.org b/README.org
index 59992be2e0..dc54a167ba 100644
--- a/README.org
+++ b/README.org
@@ -221,13 +221,15 @@ Remember to type =C-c C-x C-u= (~org-dblock-update~) with 
point on the
 :CUSTOM_ID: h:f9a97859-1deb-47dd-bdae-52f8b424ff46
 :END:
 
+[ The parameter =:not-regexp= for the ~denote-org-dblock-insert-backlinks~ is 
part of {{{development-version}}}. ]
+
 #+findex: denote-org-dblock-insert-backlinks
 Apart from links to files matching a regular expression, we can also
 produce a list of backlinks to the current file. The dynamic block can
 be inserted at point with the command ~denote-org-dblock-insert-backlinks~
 or by manually writing this in an Org file:
 
-: #+BEGIN: denote-backlinks :excluded-dirs-regexp nil :sort-by-component nil 
:reverse-sort nil :id-only nil :this-heading-only nil :include-date nil
+: #+BEGIN: denote-backlinks :not-regexp nil :excluded-dirs-regexp nil 
:sort-by-component nil :reverse-sort nil :id-only nil :this-heading-only nil 
:include-date nil
 :
 : #+END:
 
diff --git a/denote-org.el b/denote-org.el
index a3a5b940e8..d3bb0daa74 100644
--- a/denote-org.el
+++ b/denote-org.el
@@ -40,6 +40,107 @@
   :link '(url-link :tag "Denote homepage" 
"https://protesilaos.com/emacs/denote";)
   :link '(url-link :tag "Denote Org homepage" 
"https://protesilaos.com/emacs/denote-org";))
 
+(defconst denote-org--common-extra-parameters
+  '((list :inline t
+         :not-regexp
+         (choice (const :tag "Do not exclude anything" nil)
+                 (string :tag "Regular expression to exclude")))
+   (list :inline t
+         :excluded-dirs-regexp
+         (choice (const :tag "Do not exclude directories" nil)
+                 (string :tag "Regular expression to exclude directories")))
+   (list :inline t
+         :sort-by-component
+         ;; TODO 2025-07-30: Check the other sort options we provide.
+         (choice (const :tag "Sort by title" title)
+                 (const :tag "Sort by signature" signature)
+                 (const :tag "Sort by keywords" keywords)))
+   (list :inline t
+         :reverse-sort
+         (choice (const :tag "No reverse sort" nil)
+                 (const :tag "Reverse sort" t)))
+   (list :inline t
+         :id-only
+         (choice (const :tag "Links with full description" nil)
+                 (const :tag "Links with just the identifier" t)))
+   (list :inline t
+         :include-date
+         (choice (const :tag "Do not show the date" nil)
+                 (const :tag "Show the date" t))))
+  "For use in the :type of `denote-org-extra-parameters-alist'.")
+
+(defcustom denote-org-extra-parameters-alist
+  '((denote-links :not-regexp nil :excluded-dirs-regexp nil :sort-by-component 
nil :reverse-sort nil :id-only nil :include-date nil)
+    (denote-missing-links :not-regexp nil :excluded-dirs-regexp nil 
:sort-by-component nil :reverse-sort nil :id-only nil :include-date nil)
+    (denote-backlinks :not-regexp nil :excluded-dirs-regexp nil 
:sort-by-component nil :reverse-sort nil :id-only nil :this-heading-only nil 
:include-date nil)
+    (denote-files :not-regexp nil :excluded-dirs-regexp nil :sort-by-component 
title :reverse-sort nil :no-front-matter nil :file-separator nil :add-links nil)
+    (denote-files-as-headings :not-regexp nil :excluded-dirs-regexp nil 
:sort-by-component title :reverse-sort nil :add-links nil))
+  "Extra parameters for each Denote Org dynamic block.
+Those are in addition to the mandatory parameters that will always be
+present in a dynamic block."
+  :type '(set
+          (list
+           (list :inline t
+                 (const denote-links)
+                 (set
+                  (list :inline t
+                        :not-regexp
+                        (choice (const :tag "Do not exclude anything" nil)
+                                (string :tag "Regular expression to exclude")))
+                  (list :inline t
+                        :excluded-dirs-regexp
+                        (choice (const :tag "Do not exclude directories" nil)
+                                (string :tag "Regular expression to exclude 
directories")))
+                  (list :inline t
+                        :sort-by-component
+                        ;; TODO 2025-07-30: Check the other sort options we 
provide.
+                        (choice (const :tag "Sort by title" title)
+                                (const :tag "Sort by signature" signature)
+                                (const :tag "Sort by keywords" keywords)))
+                  (list :inline t
+                        :reverse-sort
+                        (choice (const :tag "No reverse sort" nil)
+                                (const :tag "Reverse sort" t)))
+                  (list :inline t
+                        :id-only
+                        (choice (const :tag "Links with full description" nil)
+                                (const :tag "Links with just the identifier" 
t)))
+                  (list :inline t
+                        :include-date
+                        (choice (const :tag "Do not show the date" nil)
+                                (const :tag "Show the date" t)))))
+
+           (list :inline t
+                 (const denote-missing-links)
+                 (set
+                  (list :inline t
+                        :excluded-dirs-regexp
+                        (choice (const :tag "Do not exclude directories" nil)
+                                (string :tag "Regular expression to exclude 
directories")))
+                  (list :inline t
+                        :sort-by-component
+                        (choice (const :tag "Sort by title" title)
+                                (const :tag "Sort by title" signature)
+                                (const :tag "Sort by title" keywords)))
+                  (list :inline t
+                        :reverse-sort
+                        (choice (const :tag "No reverse sort" nil)
+                                (const :tag "Reverse sort" t)))
+                  (list :inline t
+                        :id-only
+                        (choice (const :tag "Links with full description" nil)
+                                (const :tag "Links with just the identifier" 
t)))
+                  (list :inline t
+                        :include-date
+                        (choice (const :tag "Do not show the date" nil)
+                                (const :tag "Show the date" t)))))))
+                             
+           ;; (const denote-missing-links)
+           ;; (const denote-backlinks)
+           ;; (const denote-files)
+           ;; (const denote-files-as-headings))
+  :group 'denote-org)
+
 ;;;; Link to file and heading
 
 (defun denote-org--get-outline (file)
@@ -592,12 +693,19 @@ Used by `org-dblock-update' with PARAMS provided by the 
dynamic block."
   (when-let* ((files (if (plist-get params :this-heading-only)
                          (denote-org--get-backlinks-for-heading 
(denote-org--get-file-id-and-heading-id-or-context))
                        (denote-get-backlinks))))
-    (let* ((sort (plist-get params :sort-by-component))
+    (let* ((not-rx (plist-get params :not-regexp))
+           (sort (plist-get params :sort-by-component))
            (reverse (plist-get params :reverse-sort))
            (denote-excluded-directories-regexp (or (plist-get params 
:excluded-dirs-regexp)
                                                    
denote-excluded-directories-regexp))
-           (files (denote-org-dblock--maybe-sort-backlinks files sort 
reverse)))
-      (denote-org--insert-links files (plist-get params :id-only) (plist-get 
params :include-date))
+           (files (denote-org-dblock--maybe-sort-backlinks files sort reverse))
+           (output (if not-rx
+                       (seq-remove
+                        (lambda (file)
+                          (string-match-p not-rx file))
+                        files)
+                     files)))
+      (denote-org--insert-links output (plist-get params :id-only) (plist-get 
params :include-date))
       (join-line)))) ; remove trailing empty line
 
 ;;;;; Dynamic block to insert entire file contents

Reply via email to