branch: externals/denote
commit bea7718049f7344fa9f811a045fb3bf915d42377
Author: Protesilaos Stavrou <[email protected]>
Commit: Protesilaos Stavrou <[email protected]>

    Revert "REMOVE the has-identifier from denote-directory-files and make 
obsolete denote-directory-get-files-function"
    
    This reverts commit be6e713d88f008372ea0c47f9a1a15cbdf2f1e43.
    
    Thanks to Jean-Philippe Gagné Guay for reminding me that this change
    breaks some of the use-cases we support. This was done in issue 655:
    <https://github.com/protesilaos/denote/issues/655>
---
 README.org | 11 +++++++----
 denote.el  | 33 +++++++++++++++++++--------------
 2 files changed, 26 insertions(+), 18 deletions(-)

diff --git a/README.org b/README.org
index 260a978bf2..8733f00ec6 100644
--- a/README.org
+++ b/README.org
@@ -5527,6 +5527,12 @@ The following sections cover the specifics.
   of valid files in variable ~denote-directory~. Consider files that
   satisfy ~denote-file-has-identifier-p~ and are not backups.
 
+#+vindex: denote-directory-get-files-function
++ Variable ~denote-directory-get-files-function~ :: Function to return
+  list of Denote files. Each file is a string representing an absolute
+  file system path. This is intended for use in the function
+  ~denote-directory-files~.
+
 #+findex: denote-directory-files
 + Function ~denote-directory-files~ :: Return list of absolute file
   paths in variable ~denote-directory~. Files that match
@@ -5540,10 +5546,7 @@ The following sections cover the specifics.
   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. Optional =DIRECTORIES= is a list
-  of directories to search through instead of looking into the
-  variable ~denote-directory~. [ The =DIRECTORIES= is part of
-  {{{development-version}}}. ]
+  =OMIT-CURRENT= have been applied.
 
 #+findex: denote-directory-subdirectories
 + Function ~denote-directory-subdirectories~ :: Return list of
diff --git a/denote.el b/denote.el
index ef82e8f52a..dab0bfd583 100644
--- a/denote.el
+++ b/denote.el
@@ -1320,12 +1320,15 @@ operation therein."
             (not (backup-file-name-p file))))
      (denote--directory-all-files-recursively dirs))))
 
-(make-obsolete-variable
- 'denote-directory-get-files-function
- "advanced users should write an advice for `denote-directory-files'"
- "4.2.0")
-
-(defun denote-directory-files (&optional files-matching-regexp omit-current 
text-only exclude-regexp directories)
+(defvar denote-directory-get-files-function #'denote-directory-get-files
+  "Function to return list of Denote files.
+Each file is a string representing an absolute file system path.  This
+is intended for use in the function `denote-directory-files'.")
+
+;; NOTE 2025-12-22: The HAS-IDENTIFIER is there because we provide the
+;; `denote-directory-get-files-function'.  For core Denote, the
+;; `denote-directory-get-files' already does `denote-file-has-identifier-p'.
+(defun denote-directory-files (&optional files-matching-regexp omit-current 
text-only exclude-regexp has-identifier)
   "Return list of absolute file paths in variable `denote-directory'.
 Files that match `denote-excluded-files-regexp' are excluded from the
 list.
@@ -1347,9 +1350,9 @@ 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.
 
-With optional DIRECTORIES, search through them instead of in the
-variable `denote-directory'."
-  (let ((files (denote-directory-get-files directories)))
+With optional HAS-IDENTIFIER as a non-nil value, limit the results to
+files that have an identifier."
+  (let ((files (funcall denote-directory-get-files-function)))
     (when (and omit-current buffer-file-name (denote-file-has-identifier-p 
buffer-file-name))
       (setq files (delete buffer-file-name files)))
     (when files-matching-regexp
@@ -1359,6 +1362,8 @@ variable `denote-directory'."
                    files)))
     (when text-only
       (setq files (seq-filter #'denote-file-has-supported-extension-p files)))
+    (when has-identifier
+      (setq files (seq-filter #'denote-file-has-identifier-p files)))
     (when exclude-regexp
       (setq files (seq-remove
                    (lambda (file)
@@ -1421,7 +1426,7 @@ something like .org even if the actual file extension is
          (seq-filter
           (lambda (file)
             (string= id (denote-retrieve-filename-identifier file)))
-          (denote-directory-files))))
+          (denote-directory-files nil nil nil nil :has-identifier))))
     (if (length< files 2)
         (car files)
       (seq-find
@@ -1551,7 +1556,7 @@ Return the absolute path to the matching file."
                               (denote-directories-get-common-root roots)))
          (files (denote-directory-files
                  (or denote-file-prompt-use-files-matching-regexp 
files-matching-regexp)
-                 :omit-current nil nil roots))
+                 :omit-current nil nil has-identifier))
          (relative-files (if single-dir-p
                              (mapcar
                               (lambda (file)
@@ -3075,7 +3080,7 @@ It checks files in variable `denote-directory' and active 
buffer files."
   (let* ((ids (make-hash-table :test #'equal))
          (file-names (mapcar
                       (lambda (file) (file-name-nondirectory file))
-                      (denote-directory-files)))
+                      (denote-directory-files nil nil nil nil 
:has-identifier)))
          (names (append file-names (denote--buffer-file-names))))
     (dolist (name names)
       (when-let* ((id (denote-retrieve-filename-identifier name)))
@@ -5468,7 +5473,7 @@ Also see `denote-get-backlinks'."
               ((denote-file-has-supported-extension-p current-file))
               (file-type (denote-filetype-heuristics current-file))
               (regexp (denote--link-in-context-regexp file-type))
-              (files (or files (denote-directory-files)))
+              (files (or files (denote-directory-files nil nil nil nil 
:has-identifier)))
               (file-identifiers
                (with-temp-buffer
                  (insert-file-contents current-file)
@@ -6550,7 +6555,7 @@ inserts links with just the identifier."
               (and buffer-file-name (denote-file-has-supported-extension-p 
buffer-file-name)))
     (user-error "The current file type is not recognized by Denote"))
   (let ((file-type (denote-filetype-heuristics (buffer-file-name))))
-    (if-let* ((files (denote-directory-files regexp :omit-current)))
+    (if-let* ((files (denote-directory-files regexp :omit-current nil nil 
:has-identifier)))
         (denote-link--insert-links files file-type id-only)
       (message "No links matching `%s'" regexp))))
 

Reply via email to