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

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

[elpa] externals/denote d6b3269a17 8/9: Merge branch 'not-regexp'


From: ELPA Syncer
Subject: [elpa] externals/denote d6b3269a17 8/9: Merge branch 'not-regexp'
Date: Wed, 4 Dec 2024 09:58:05 -0500 (EST)

branch: externals/denote
commit d6b3269a17712bcd07212e25f1f107ad95bc866f
Merge: 7f4a66d802 fba0bb2650
Author: Protesilaos Stavrou <info@protesilaos.com>
Commit: Protesilaos Stavrou <info@protesilaos.com>

    Merge branch 'not-regexp'
---
 README.org           | 47 ++++++++++++++++++++++++++--------
 denote-org-extras.el | 54 ++++++++++++++++++++++++++-------------
 denote-sort.el       | 71 ++++++++++++++++++++++++++++++++++++++--------------
 denote.el            | 15 ++++++++---
 4 files changed, 138 insertions(+), 49 deletions(-)

diff --git a/README.org b/README.org
index a4d1f78b45..a0e4606641 100644
--- a/README.org
+++ b/README.org
@@ -3679,7 +3679,7 @@ The =denote-links= block can be inserted at point with 
the command
 ~denote-org-extras-dblock-insert-links~ or by manually including the
 following in an Org file:
 
-: #+BEGIN: denote-links :regexp "YOUR REGEXP HERE" :excluded-dirs-regexp nil 
:sort-by-component nil :reverse-sort nil :id-only nil :include-date nil
+: #+BEGIN: denote-links :regexp "YOUR REGEXP HERE" :not-regexp 
:excluded-dirs-regexp nil :sort-by-component nil :reverse-sort nil :id-only nil 
:include-date nil
 :
 : #+END:
 
@@ -3703,6 +3703,10 @@ line to update the block.
   meaningful results: even something like =_journal= will work to
   include all files that have a =journal= keyword.
 
+- The =:not-regexp= parameter is optional. It is a regular expression
+  that applies after =:regexp= to filter out the matching files. [
+  Part of {{{development-version}}}. ]
+
 - The =:excluded-dirs-regexp= is a string that contains a word or
   regular expression that matches against directory files names
   to-be-excluded from the results. This has the same meaning as
@@ -3835,7 +3839,7 @@ or manually write the following block in an Org file and 
then type
  =C-c C-x C-u= (~org-dblock-update~) on the =#+BEGIN= line to run it
 (do it again to recalculate the block):
 
-: #+BEGIN: denote-files :regexp "YOUR REGEXP HERE" :sort-by-component nil 
:reverse-sort nil :no-front-matter nil :file-separator nil :add-links nil
+: #+BEGIN: denote-files :regexp "YOUR REGEXP HERE" :not-regexp nil 
:sort-by-component nil :reverse-sort nil :no-front-matter nil :file-separator 
nil :add-links nil
 :
 : #+END:
 
@@ -3850,7 +3854,6 @@ Remember to type =C-c C-x C-u= (~org-dblock-update~) with 
point on the
 To fully control the output, include these additional optional
 parameters, which are described further below:
 
-
 - The =:regexp= parameter is mandatory. Its value is a string,
   representing a regular expression to match Denote file names. Its
   value may also be an ~rx~ expression instead of a string, as noted
@@ -3859,6 +3862,10 @@ parameters, which are described further below:
   get meaningful results: even something like =_journal= will work to
   include all files that have a =journal= keyword.
 
+- The =:not-regexp= parameter is optional. It is a regular expression
+  that applies after =:regexp= to filter out the matching files. [
+  Part of {{{development-version}}}. ]
+
 - The =:excluded-dirs-regexp= is a string that contains a word or
   regular expression that matches against directory files names
   to-be-excluded from the results. This has the same meaning as
@@ -3953,7 +3960,7 @@ In its simplest form, this dynamic block looks like this, 
with
 Though when you use the command 
~denote-org-extras-dblock-insert-files-as-headings~
 you get all the parameters included:
 
-: #+BEGIN: denote-files-as-headings :regexp "YOUR REGEXP HERE" 
:excluded-dirs-regexp nil :sort-by-component title :reverse-sort nil :add-links 
t
+: #+BEGIN: denote-files-as-headings :regexp "YOUR REGEXP HERE" :not-regexp nil 
:excluded-dirs-regexp nil :sort-by-component title :reverse-sort nil :add-links 
t
 :
 : #+END:
 
@@ -3965,6 +3972,10 @@ you get all the parameters included:
   get meaningful results: even something like =_journal= will work to
   include all files that have a =journal= keyword.
 
+- The =:not-regexp= parameter is optional. It is a regular expression
+  that applies after =:regexp= to filter out the matching files. [
+  Part of {{{development-version}}}. ]
+
 - The =:excluded-dirs-regexp= is a string that contains a word or
   regular expression that matches against directory files names
   to-be-excluded from the results. This has the same meaning as
@@ -4015,8 +4026,11 @@ given file name component 
([[#h:4e9c7512-84dc-4dfb-9fa9-e15d51178e5d][The file-n
 #+findex: denote-sort-dired
 The command ~denote-sort-dired~ produces a Dired file listing with a
 flat, filtered, and sorted set of files from the ~denote-directory~
-([[#h:c958e087-1d23-4a25-afdd-db7bf5606b4c][Define a sorting function per 
component]]). It does so by means of
-three minibuffer prompts:
+([[#h:c958e087-1d23-4a25-afdd-db7bf5606b4c][Define a sorting function per 
component]]). It does so by a series of
+prompts, which can be configured by the user option
+~denote-sort-dired-extra-prompts~ 
([[#h:a34228cb-484f-48fe-9cbc-8e41f313127b][Configure what extra prompts 
~denote-sort-dired~ issues]]).
+
+The out-of-the-box behaviour of ~denote-sort-dired~ is as follows:
 
 1. It first asks for a regular expression with which to match Denote
    files. Remember that due to Denote's efficient file-naming scheme,
@@ -4046,9 +4060,18 @@ match file names, (ii) a file name component to sort by, 
and (iii)
 whether to reverse the sorting. Users can configure the latter two by
 modifying the user option ~denote-sort-dired-extra-prompts~.
 
-It accepts either a nil value or a list of symbols among ~sort-by-component~
-and ~reverse-sort~. The order those symbols appear in the list is
-significant, with the leftmost coming first.
+It accepts either a nil value or a list of symbols among
+~sort-by-component~, ~reverse-sort~, and ~exclude-regexp~. The order
+those symbols appear in the list is significant, with the leftmost
+coming first. [ The ~exclude-regexp~ feature is part of
+{{{development-version}}}. ]
+
+These symbols correspond to the following:
+
+- A choice to select the file name component to sort by.
+- A yes or no prompt on whether to reverse the sorting.
+- A string (or regular expression) of files to be excluded from the
+  results.
 
 #+vindex: denote-sort-dired-default-sort-component
 #+vindex: denote-sort-dired-default-reverse-sort
@@ -5631,7 +5654,11 @@ might change them without further notice.
   regular expression. With optional =OMIT-CURRENT= as a non-nil value,
   do not include the current Denote file in the returned list. With
   optional =TEXT-ONLY= as a non-nil value, limit the results to text
-  files that satisfy ~denote-file-is-note-p~.
+  files that satisfy ~denote-file-is-note-p~. With optional
+  =EXCLUDE-REGEXP= exclude the files that match the given regular
+  expression. This is done after =FILES-MATCHING-REGEXP= and
+  =OMIT-CURRENT= have been applied. [ The optional =EXCLUDE-REGEXP= is
+  part of {{{development-version}}}. ]
 
 #+findex: denote-directory-subdirectories
 + Function ~denote-directory-subdirectories~ :: Return list of
diff --git a/denote-org-extras.el b/denote-org-extras.el
index e326b05737..f0dcb51742 100644
--- a/denote-org-extras.el
+++ b/denote-org-extras.el
@@ -356,22 +356,22 @@ point to a file with a Denote file name."
 
 ;;;;; Common helper functions
 
-(defun denote-org-extras-dblock--files (files-matching-regexp &optional 
sort-by-component reverse)
+(defun denote-org-extras-dblock--files (files-matching-regexp &optional 
sort-by-component reverse exclude-regexp)
   "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.
+SORT-BY-COMPONENT, REVERSE, EXCLUDE-REGEXP have the same meaning as
+`denote-sort-get-directory-files'.  If both are nil, do not try to
+perform any 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))
+    (denote-sort-get-directory-files files-matching-regexp sort-by-component 
reverse :omit-current exclude-regexp))
    (sort-by-component
-    (denote-sort-get-directory-files files-matching-regexp sort-by-component 
nil :omit-current))
+    (denote-sort-get-directory-files files-matching-regexp sort-by-component 
nil :omit-current exclude-regexp))
    (reverse
-    (denote-sort-get-directory-files files-matching-regexp 
:no-component-specified reverse :omit-current))
+    (denote-sort-get-directory-files files-matching-regexp 
:no-component-specified reverse :omit-current exclude-regexp))
    (t
-    (denote-directory-files files-matching-regexp :omit-current))))
+    (denote-directory-files files-matching-regexp :omit-current nil 
exclude-regexp))))
 
 (defun denote-org-extras-dblock--get-missing-links (regexp)
   "Return list of missing links to all notes matching REGEXP.
@@ -407,6 +407,7 @@ Also see `denote-org-extras-dblock--files'."
    org-mode)
   (org-create-dblock (list :name "denote-links"
                            :regexp regexp
+                           :not-regexp nil
                            :excluded-dirs-regexp nil
                            :sort-by-component nil
                            :reverse-sort nil
@@ -426,19 +427,24 @@ Also see `denote-org-extras-dblock--files'."
 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))
+         (not-rx (plist-get params :not-regexp))
          (sort (plist-get params :sort-by-component))
          (reverse (plist-get params :reverse-sort))
          (include-date (plist-get params :include-date))
          (block-name (plist-get params :block-name))
          (denote-excluded-directories-regexp (or (plist-get params 
:excluded-dirs-regexp)
                                                  
denote-excluded-directories-regexp))
-         (files (denote-org-extras-dblock--files rx sort reverse)))
+         (files (denote-org-extras-dblock--files rx sort reverse not-rx)))
     (when block-name (insert "#+name: " block-name "\n"))
     (denote-link--insert-links files 'org (plist-get params :id-only) 
:no-other-sorting include-date)
     (join-line))) ; remove trailing empty line
 
 ;;;;; Dynamic block to insert missing links
 
+;; TODO 2024-12-03: Do we need the :not-regexp here?  I think yes,
+;; though I prefer to have a user of this kind of dblock send me their
+;; feedback.
+
 ;;;###autoload
 (defun denote-org-extras-dblock-insert-missing-links (regexp)
   "Create Org dynamic block to insert Denote links matching REGEXP."
@@ -492,6 +498,10 @@ Used by `org-dblock-update' with PARAMS provided by the 
dynamic block."
    (t
     files)))
 
+;; TODO 2024-12-03: Do we need the :not-regexp here?  I think yes,
+;; though I prefer to have a user of this kind of dblock send me their
+;; feedback.
+
 ;;;###autoload
 (defun denote-org-extras-dblock-insert-backlinks ()
   "Create Org dynamic block to insert Denote backlinks to current file."
@@ -574,7 +584,7 @@ argument."
    ((stringp separator) separator)
    (t denote-org-extras-dblock-file-contents-separator)))
 
-(defun denote-org-extras-dblock-add-files (regexp &optional separator 
no-front-matter add-links sort-by-component reverse excluded-dirs-regexp)
+(defun denote-org-extras-dblock-add-files (regexp &optional separator 
no-front-matter add-links sort-by-component reverse excluded-dirs-regexp 
exclude-regexp)
   "Insert files matching REGEXP.
 
 Seaprate them with the optional SEPARATOR.  If SEPARATOR is nil,
@@ -597,9 +607,12 @@ If optional REVERSE is non-nil reverse the sort order.
 
 Optional EXCLUDED-DIRS-REGEXP is the `let' bound value of
 `denote-excluded-directories-regexp'.  When nil, the original value of
-that user option is used."
+that user option is used.
+
+Optional EXCLUDE-REGEXP is a more general way to exclude files whose
+name matches the given regular expression."
   (let* ((denote-excluded-directories-regexp (or excluded-dirs-regexp 
denote-excluded-directories-regexp))
-         (files (denote-org-extras-dblock--files regexp sort-by-component 
reverse))
+         (files (denote-org-extras-dblock--files regexp sort-by-component 
reverse exclude-regexp))
          (files-contents (mapcar
                           (lambda (file) 
(denote-org-extras-dblock--get-file-contents file no-front-matter add-links))
                           files)))
@@ -617,6 +630,7 @@ among `denote-sort-components'."
    org-mode)
   (org-create-dblock (list :name "denote-files"
                            :regexp regexp
+                           :not-regexp nil
                            :excluded-dirs-regexp nil
                            :sort-by-component sort-by-component
                            :reverse-sort nil
@@ -637,6 +651,7 @@ among `denote-sort-components'."
 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))
+         (not-rx (plist-get params :not-regexp))
          (sort (plist-get params :sort-by-component))
          (reverse (plist-get params :reverse-sort))
          (block-name (plist-get params :block-name))
@@ -645,7 +660,7 @@ Used by `org-dblock-update' with PARAMS provided by the 
dynamic block."
          (add-links (plist-get params :add-links))
          (excluded-dirs (plist-get params :excluded-dirs-regexp)))
     (when block-name (insert "#+name: " block-name "\n"))
-    (when rx (denote-org-extras-dblock-add-files rx separator no-f-m add-links 
sort reverse excluded-dirs)))
+    (when rx (denote-org-extras-dblock-add-files rx separator no-f-m add-links 
sort reverse excluded-dirs not-rx)))
   (join-line)) ; remove trailing empty line
 
 ;;;; Insert files as headings
@@ -682,7 +697,7 @@ With optional ADD-LINKS, make the title link to the 
original file."
           (replace-match (format "*%s " "\\1"))))
       (buffer-string))))
 
-(defun denote-org-extras-dblock-add-files-as-headings (regexp &optional 
add-links sort-by-component reverse excluded-dirs-regexp)
+(defun denote-org-extras-dblock-add-files-as-headings (regexp &optional 
add-links sort-by-component reverse excluded-dirs-regexp exclude-regexp)
   "Insert files matching REGEXP.
 
 If optional ADD-LINKS is non-nil, first insert a link to the file
@@ -698,9 +713,12 @@ If optional REVERSE is non-nil reverse the sort order.
 
 Optional EXCLUDED-DIRS-REGEXP is the `let' bound value of
 `denote-excluded-directories-regexp'.  When nil, the original value of
-that user option is used."
+that user option is used.
+
+Optional EXCLUDE-REGEXP is a more general way to exclude files whose
+name matches the given regular expression."
   (let* ((denote-excluded-directories-regexp (or excluded-dirs-regexp 
denote-excluded-directories-regexp))
-         (files (denote-org-extras-dblock--files regexp sort-by-component 
reverse))
+         (files (denote-org-extras-dblock--files regexp sort-by-component 
reverse exclude-regexp))
          (files-contents (mapcar
                           (lambda (file)
                             
(denote-org-extras-dblock--get-file-contents-as-heading file add-links))
@@ -731,6 +749,7 @@ as its own heading."
    org-mode)
   (org-create-dblock (list :name "denote-files-as-headings"
                            :regexp regexp
+                           :not-regexp nil
                            :excluded-dirs-regexp nil
                            :sort-by-component sort-by-component
                            :reverse-sort nil
@@ -749,13 +768,14 @@ as its own heading."
 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))
+         (not-rx (plist-get params :not-regexp))
          (sort (plist-get params :sort-by-component))
          (reverse (plist-get params :reverse-sort))
          (block-name (plist-get params :block-name))
          (add-links (plist-get params :add-links))
          (excluded-dirs (plist-get params :excluded-dirs-regexp)))
     (when block-name (insert "#+name: " block-name "\n"))
-    (when rx (denote-org-extras-dblock-add-files-as-headings rx add-links sort 
reverse excluded-dirs)))
+    (when rx (denote-org-extras-dblock-add-files-as-headings rx add-links sort 
reverse excluded-dirs not-rx)))
   (join-line)) ; remove trailing empty line
 
 (provide 'denote-org-extras)
diff --git a/denote-sort.el b/denote-sort.el
index 9daa8b9df4..3ea9760396 100644
--- a/denote-sort.el
+++ b/denote-sort.el
@@ -1,4 +1,4 @@
-;;; denote-sort.el ---  Sort Denote files based on a file name component -*- 
lexical-binding: t -*-
+;;; denote-sort.el --- Sort Denote files based on a file name component -*- 
lexical-binding: t -*-
 
 ;; Copyright (C) 2023-2024  Free Software Foundation, Inc.
 
@@ -73,8 +73,14 @@ whether to sort by a given file name component and to then 
reverse the
 sort.
 
 The value is a list of symbols, which can include the symbols
-`sort-by-component' and `reverse-sort'.  The order is significant, with
-the leftmost symbol coming first.
+`sort-by-component', `reverse-sort', and `exclude-regexp'.  The order is
+significant, with the leftmost symbol coming first.
+
+These symbols correspond to the following:
+
+- A choice to select the file name component to sort by.
+- A yes or no prompt on whether to reverse the sorting.
+- A string (or regular expression) of files to be excluded from the results.
 
 If the value is nil, skip all prompts.  In this scenario, the sorting is
 done according to `denote-sort-dired-default-sort-component' and
@@ -82,8 +88,9 @@ done according to `denote-sort-dired-default-sort-component' 
and
   :type '(radio (const :tag "Do not prompt for anything" nil)
                 (set :tag "Available prompts" :greedy t
                      (const :tag "Sort by file name component" 
sort-by-component)
-                     (const :tag "Reverse the sort" reverse-sort)))
-  :package-version '(denote . "3.1.0")
+                     (const :tag "Reverse the sort" reverse-sort)
+                     (const :tag "Exclude files matching regexp" 
exclude-regexp)))
+  :package-version '(denote . "3.2.0")
   :group 'denote-sort)
 
 (defcustom denote-sort-dired-default-sort-component 'identifier
@@ -156,7 +163,7 @@ With optional REVERSE as a non-nil value, reverse the sort 
order."
         (reverse sorted-files)
       sorted-files)))
 
-(defun denote-sort-get-directory-files (files-matching-regexp 
sort-by-component &optional reverse omit-current)
+(defun denote-sort-get-directory-files (files-matching-regexp 
sort-by-component &optional reverse omit-current exclude-regexp)
   "Return sorted list of files in variable `denote-directory'.
 
 With FILES-MATCHING-REGEXP as a string limit files to those
@@ -169,13 +176,17 @@ name component.
 With optional REVERSE as a non-nil value, reverse the sort order.
 
 With optional OMIT-CURRENT, do not include the current file in
-the list."
+the list.
+
+With optional EXCLUDE-REGEXP exclude the files that match the given
+regular expression.  This is done after FILES-MATCHING-REGEXP and
+OMIT-CURRENT have been applied."
   (denote-sort-files
-   (denote-directory-files files-matching-regexp omit-current)
+   (denote-directory-files files-matching-regexp omit-current nil 
exclude-regexp)
    sort-by-component
    reverse))
 
-(defun denote-sort-get-links (files-matching-regexp sort-by-component 
current-file-type id-only &optional reverse)
+(defun denote-sort-get-links (files-matching-regexp sort-by-component 
current-file-type id-only &optional reverse exclude-regexp)
   "Return sorted typographic list of links for FILES-MATCHING-REGEXP.
 
 With FILES-MATCHING-REGEXP as a string, match files stored in the
@@ -194,9 +205,13 @@ unknown non-nil value, default to the Org notation.
 With ID-ONLY as a non-nil value, produce links that consist only
 of the identifier, thus deviating from CURRENT-FILE-TYPE.
 
-With optional REVERSE as a non-nil value, reverse the sort order."
+With optional REVERSE as a non-nil value, reverse the sort order.
+
+With optional EXCLUDE-REGEXP exclude the files that match the given
+regular expression.  This is done after FILES-MATCHING-REGEXP and
+OMIT-CURRENT have been applied."
   (denote-link--prepare-links
-   (denote-sort-get-directory-files files-matching-regexp sort-by-component 
reverse)
+   (denote-sort-get-directory-files files-matching-regexp sort-by-component 
reverse exclude-regexp)
    current-file-type
    id-only))
 
@@ -215,24 +230,37 @@ With optional REVERSE as a non-nil value, reverse the 
sort order."
       denote-sort-components nil :require-match
       nil 'denote-sort-component-history default))))
 
+(defvar denote-sort-exclude-files-history nil
+  "Minibuffer history for `denote-sort-exclude-files-prompt'.")
+
+(defun denote-sort-exclude-files-prompt ()
+  "Prompt for regular expression of files to exclude."
+  ;; TODO 2024-12-03: Maybe use `read-regexp'?  We do not use it
+  ;; elsewhere, so maybe this is fine.
+  (let ((default (car denote-sort-exclude-files-history)))
+    (read-string
+     (format-prompt "Exclude files matching REGEXP" default)
+     default 'denote-sort-exclude-files-history)))
+
 (defvar-local denote-sort--dired-buffer nil
   "Buffer object of current `denote-sort-dired'.")
 
 (defun denote-sort-dired--prompts ()
   "Return list of prompts per `denote-sort-dired-extra-prompts'."
-  (let (sort-by-component reverse-sort)
+  (let (sort-by-component reverse-sort exclude-rx)
     (dolist (prompt denote-sort-dired-extra-prompts)
       (pcase prompt
         ('sort-by-component (setq sort-by-component 
(denote-sort-component-prompt)))
-        ('reverse-sort (setq reverse-sort (y-or-n-p "Reverse sort? ")))))
-    (list sort-by-component reverse-sort)))
+        ('reverse-sort (setq reverse-sort (y-or-n-p "Reverse sort? ")))
+        ('exclude-regexp (setq exclude-rx 
(denote-sort-exclude-files-prompt)))))
+    (list sort-by-component reverse-sort exclude-rx)))
 
 ;;;###autoload
-(defun denote-sort-dired (files-matching-regexp sort-by-component reverse)
+(defun denote-sort-dired (files-matching-regexp sort-by-component reverse 
exclude-regexp)
   "Produce Dired buffer with sorted files from variable `denote-directory'.
 When called interactively, prompt for FILES-MATCHING-REGEXP and,
 depending on the value of the user option `denote-sort-dired-extra-prompts',
-also prompt for SORT-BY-COMPONENT and REVERSE.
+also prompt for SORT-BY-COMPONENT, REVERSE, and EXCLUDE-REGEXP.
 
 1. FILES-MATCHING-REGEXP limits the list of Denote files to
    those matching the provided regular expression.
@@ -248,6 +276,10 @@ also prompt for SORT-BY-COMPONENT and REVERSE.
    `denote-sort-dired-default-reverse-sort', falling back to
    nil (i.e. no reverse sort).
 
+4. EXCLUDE-REGEXP excludes the files that match the given regular
+   expression.  This is done after FILES-MATCHING-REGEXP and
+   OMIT-CURRENT have been applied.
+
 When called from Lisp, the arguments are a string, a symbol among
 `denote-sort-components', and a non-nil value, respectively."
   (interactive
@@ -257,9 +289,10 @@ When called from Lisp, the arguments are a string, a 
symbol among
                        'identifier))
         (reverse-sort (or reverse
                           denote-sort-dired-default-reverse-sort
-                          nil)))
+                          nil))
+        (exclude-rx (or exclude-regexp nil)))
     (if-let* ((default-directory (denote-directory))
-              (files (denote-sort-get-directory-files files-matching-regexp 
component reverse-sort))
+              (files (denote-sort-get-directory-files files-matching-regexp 
component reverse-sort nil exclude-rx))
               ;; NOTE 2023-12-04: Passing the FILES-MATCHING-REGEXP as
               ;; buffer-name produces an error if the regexp contains a
               ;; wildcard for a directory. I can reproduce this in emacs
@@ -274,7 +307,7 @@ When called from Lisp, the arguments are a string, a symbol 
among
             (setq-local revert-buffer-function
                         (lambda (&rest _)
                           (kill-buffer dired-buffer)
-                          (denote-sort-dired files-matching-regexp component 
reverse-sort))))
+                          (denote-sort-dired files-matching-regexp component 
reverse-sort exclude-rx))))
           ;; Because of the above NOTE, I am printing a message.  Not
           ;; what I want, but it is better than nothing...
           (message denote-sort-dired-buffer-name))
diff --git a/denote.el b/denote.el
index 1b08dae15b..f5ba8372d3 100644
--- a/denote.el
+++ b/denote.el
@@ -1261,7 +1261,7 @@ are not backups."
            (not (backup-file-name-p file))))
     (denote--directory-all-files-recursively))))
 
-(defun denote-directory-files (&optional files-matching-regexp omit-current 
text-only)
+(defun denote-directory-files (&optional files-matching-regexp omit-current 
text-only exclude-regexp)
   "Return list of absolute file paths in variable `denote-directory'.
 Files that match `denote-excluded-files-regexp' are excluded from the
 list.
@@ -1277,7 +1277,11 @@ With optional OMIT-CURRENT as a non-nil value, do not 
include the
 current Denote file in the returned list.
 
 With optional TEXT-ONLY as a non-nil value, limit the results to
-text files that satisfy `denote-filename-is-note-p'."
+text files that satisfy `denote-filename-is-note-p'.
+
+With optional EXCLUDE-REGEXP exclude the files that match the given
+regular expression.  This is done after FILES-MATCHING-REGEXP and
+OMIT-CURRENT have been applied."
   (let ((files (denote--directory-get-files)))
     (when (and omit-current buffer-file-name (denote-file-has-identifier-p 
buffer-file-name))
       (setq files (delete buffer-file-name files)))
@@ -1288,7 +1292,12 @@ text files that satisfy `denote-filename-is-note-p'."
                    files)))
     (when text-only
       (setq files (seq-filter #'denote-filename-is-note-p files)))
-    files))
+    (if exclude-regexp
+        (seq-remove
+         (lambda (file)
+           (string-match-p exclude-regexp file))
+         files)
+      files)))
 
 (defun denote-directory-subdirectories ()
   "Return list of subdirectories in variable `denote-directory'.



reply via email to

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