branch: externals/denote
commit 9e02bf4bd076d04d44a1915a21c0187b02c226ee
Merge: cf2a6b082b 786c86f567
Author: Protesilaos Stavrou <[email protected]>
Commit: GitHub <[email protected]>
Merge pull request #661 from jeanphilippegg/directories-parameter
Fix #654
---
README.org | 5 +--
denote.el | 124 +++++++++++++++++++++++++++++--------------------------------
2 files changed, 59 insertions(+), 70 deletions(-)
diff --git a/README.org b/README.org
index a0fb1ca23a..329cc7f593 100644
--- a/README.org
+++ b/README.org
@@ -5540,10 +5540,7 @@ The following sections cover the specifics.
expression. This is done after =FILES-MATCHING-REGEXP= and
=OMIT-CURRENT= have been applied. With optional =HAS-IDENTIFIER= as
a non-~nil~ value, limit the results to files that have an
- identifier. With Optional =DIRECTORIES= as a list of directories,
- search through instead of looking into the variable
- ~denote-directory~. [ The optional =DIRECTORIES= is part of
- {{{development-version}}}. ]
+ identifier.
#+findex: denote-directory-subdirectories
+ Function ~denote-directory-subdirectories~ :: Return list of
diff --git a/denote.el b/denote.el
index 1c5c02d905..7b38563356 100644
--- a/denote.el
+++ b/denote.el
@@ -996,9 +996,9 @@ to override what this function returns."
(format "/%s/" (mapconcat #'identity common-parent "/"))
"/"))
-(defun denote-directories-get-common-root (&optional directories)
- "Get the common root directory of DIRECTORIES or `denote-directories'."
- (denote--get-common-root-directory (or directories (denote-directories))))
+(defun denote-directories-get-common-root ()
+ "Get the common root directory of `denote-directories'."
+ (denote--get-common-root-directory (denote-directories)))
(defun denote-directory ()
"Return the `car' of `denote-directories'.
@@ -1248,19 +1248,20 @@ what remains."
(and (file-writable-p file)
(denote-file-has-supported-extension-p file)))
-(defun denote-get-file-name-relative-to-denote-directory (file &optional
directories)
- "Return FILE relative to the variable `denote-directory'.
-With optional DIRECTORIES, as a list of directories, return FILE
-relative to whichever one of those it belongs to."
+(defun denote--get-file-name-relative-to-directories (file directories)
+ "Return FILE relative to one of the DIRECTORIES."
(unless (file-name-absolute-p file)
(error "The file `%s' is not absolute" file))
- (when-let* ((dirs (or directories (denote-directories)))
- (directory (seq-find
+ (when-let* ((directory (seq-find
(lambda (d)
(string-prefix-p d file))
- dirs)))
+ directories)))
(substring-no-properties file (length directory))))
+(defun denote-get-file-name-relative-to-denote-directory (file)
+ "Return FILE relative to the variable `denote-directory'."
+ (denote--get-file-name-relative-to-directories file (denote-directories)))
+
(defun denote-extract-id-from-string (string)
"Return existing Denote identifier in STRING, else nil."
(when (string-match denote-date-identifier-regexp string)
@@ -1271,18 +1272,19 @@ relative to whichever one of those it belongs to."
(and (stringp denote-excluded-directories-regexp)
(string-match-p denote-excluded-directories-regexp file)))
-(defun denote--directory-all-files-recursively (directories)
- "Return list of all files in DIRECTORIES or `denote-directories'.
+(defun denote--directory-all-files-recursively ()
+ "Return list of all files in variable `denote-directories'.
Avoids traversing dotfiles (unconditionally) and whatever matches
`denote-excluded-directories-regexp'."
- (let ((predicate-fn
- (lambda (file)
- (let ((rel (denote-get-file-name-relative-to-denote-directory file
directories)))
- (cond
- ((string-match-p "\\`\\." rel) nil)
- ((string-match-p "/\\." rel) nil)
- ((denote--exclude-directory-regexp-p rel) nil)
- ((file-readable-p file)))))))
+ (let* ((directories (denote-directories))
+ (predicate-fn
+ (lambda (file)
+ (let ((rel (denote--get-file-name-relative-to-directories file
directories)))
+ (cond
+ ((string-match-p "\\`\\." rel) nil)
+ ((string-match-p "/\\." rel) nil)
+ ((denote--exclude-directory-regexp-p rel) nil)
+ ((file-readable-p file)))))))
(apply #'append
(mapcar
(lambda (directory)
@@ -1299,26 +1301,17 @@ Avoids traversing dotfiles (unconditionally) and
whatever matches
(and denote-excluded-files-regexp
(string-match-p denote-excluded-files-regexp file)))
-(define-obsolete-function-alias
- 'denote--directory-get-files
- 'denote-directory-get-files
- "4.1.0")
-
-(defun denote-directory-get-files (&optional directories)
+(defun denote--directory-get-files ()
"Return list with full path of valid files in variable `denote-directory'.
Consider files that satisfy `denote-file-has-denoted-filename-p' and
-are not backups.
-
-With optional DIRECTORIES, as a list of directories, perform the
-operation therein."
- (when-let* ((dirs (or directories (denote-directories))))
- (seq-filter
- (lambda (file)
- (and (file-regular-p file)
- (denote-file-has-denoted-filename-p file)
- (not (denote--file-excluded-p file))
- (not (backup-file-name-p file))))
- (denote--directory-all-files-recursively dirs))))
+are not backups."
+ (seq-filter
+ (lambda (file)
+ (and (file-regular-p file)
+ (denote-file-has-denoted-filename-p file)
+ (not (denote--file-excluded-p file))
+ (not (backup-file-name-p file))))
+ (denote--directory-all-files-recursively)))
(make-obsolete-variable
'denote-directory-get-files-function
@@ -1327,7 +1320,7 @@ operation therein."
;; The HAS-IDENTIFIER is there because we support cases where files do
;; not have an identifier.
-(defun denote-directory-files (&optional files-matching-regexp omit-current
text-only exclude-regexp has-identifier directories)
+(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.
@@ -1350,18 +1343,16 @@ regular expression. This is done after
FILES-MATCHING-REGEXP and
OMIT-CURRENT have been applied.
With optional HAS-IDENTIFIER as a non-nil value, limit the results to
-files that have an identifier.
-
-With optional DIRECTORIES, search through them instead of in the
-variable `denote-directory'."
- (let ((files (denote-directory-get-files directories)))
+files that have an identifier."
+ (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)))
(when files-matching-regexp
- (setq files (seq-filter
- (lambda (f)
- (string-match-p files-matching-regexp
(denote-get-file-name-relative-to-denote-directory f)))
- files)))
+ (let ((dirs (denote-directories)))
+ (setq files (seq-filter
+ (lambda (f)
+ (string-match-p files-matching-regexp
(denote--get-file-name-relative-to-directories f dirs)))
+ files))))
(when text-only
(setq files (seq-filter #'denote-file-has-supported-extension-p files)))
(when has-identifier
@@ -1373,18 +1364,19 @@ variable `denote-directory'."
files)))
files))
-(defun denote-directory-subdirectories (&optional directories)
- "Return list of subdirectories in DIRECTORIES or variable `denote-directory'.
+(defun denote-directory-subdirectories ()
+ "Return list of subdirectories in variable `denote-directory'.
Omit dotfiles (such as .git) unconditionally. Also exclude
whatever matches `denote-excluded-directories-regexp'."
- (seq-remove
- (lambda (filename)
- (let ((rel (denote-get-file-name-relative-to-denote-directory filename
directories)))
- (or (not (file-directory-p filename))
- (string-match-p "\\`\\." rel)
- (string-match-p "/\\." rel)
- (denote--exclude-directory-regexp-p rel))))
- (denote--directory-all-files-recursively (or directories
(denote-directories)))))
+ (let ((dirs (denote-directories)))
+ (seq-remove
+ (lambda (filename)
+ (let ((rel (denote--get-file-name-relative-to-directories filename
dirs)))
+ (or (not (file-directory-p filename))
+ (string-match-p "\\`\\." rel)
+ (string-match-p "/\\." rel)
+ (denote--exclude-directory-regexp-p rel))))
+ (denote--directory-all-files-recursively))))
;; TODO 2023-01-24: Perhaps there is a good reason to make this a user
;; option, but I am keeping it as a generic variable for now.
@@ -1555,14 +1547,14 @@ Return the absolute path to the matching file."
;; relative file paths of the completion candidates.
(default-directory (if single-dir-p
(car roots)
- (denote-directories-get-common-root roots)))
+ (denote-directories-get-common-root)))
(files (denote-directory-files
(or denote-file-prompt-use-files-matching-regexp
files-matching-regexp)
- :omit-current nil nil has-identifier roots))
+ :omit-current nil nil has-identifier))
(relative-files (if single-dir-p
(mapcar
(lambda (file)
-
(denote-get-file-name-relative-to-denote-directory file roots))
+ (denote--get-file-name-relative-to-directories
file roots))
files)
files))
(prompt (if single-dir-p
@@ -1995,7 +1987,7 @@ When called from Lisp, the arguments are a string, a
symbol among
files)))))
(if-let* ((directory (if single-dir-p ; see comment in `denote-file-prompt'
(car roots)
- (denote-directories-get-common-root roots)))
+ (denote-directories-get-common-root)))
(files (funcall files-fn))
(dired-name (format-message files-matching-regexp))
(buffer-name (funcall denote-sort-dired-buffer-name-function
files-matching-regexp sort-by-component reverse-sort exclude-regexp)))
@@ -3582,8 +3574,8 @@ packages such as `marginalia' and `embark')."
;; relative file paths of the completion candidates.
(default-directory (if single-dir-p
(car roots)
- (denote-directories-get-common-root roots)))
- (subdirectories (denote-directory-subdirectories roots))
+ (denote-directories-get-common-root)))
+ (subdirectories (denote-directory-subdirectories))
(directories (append roots subdirectories)))
(completing-read
(format-prompt "Select SUBDIRECTORY" default)
@@ -5447,7 +5439,7 @@ the generic one."
(file-names (if single-dir-p
(mapcar
(lambda (file)
- (denote-get-file-name-relative-to-denote-directory
file roots))
+ (denote--get-file-name-relative-to-directories
file roots))
files)
files))
(selected (completing-read
@@ -6628,7 +6620,7 @@ contents, not file names. Optional ID-ONLY has the same
meaning as in
(file-names (if single-dir-p
(mapcar
(lambda (file)
- (denote-get-file-name-relative-to-denote-directory
file roots))
+ (denote--get-file-name-relative-to-directories
file roots))
buffer-file-names)
buffer-file-names))
(selected (completing-read