branch: externals/denote
commit 3dc772f683fdc5955e72c16d3119a6038b270da0
Author: Protesilaos Stavrou <i...@protesilaos.com>
Commit: Protesilaos Stavrou <i...@protesilaos.com>

    Split denote-directories into helper and public functions
    
    This way we can, in principle, re-use what we have there.
    
    The original code was contributed by Jean-Philippe Gagné Guay in pull
    request 613: <https://github.com/protesilaos/denote/pull/613>.
---
 denote.el | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)

diff --git a/denote.el b/denote.el
index a01c7ddba1..3ca404a304 100644
--- a/denote.el
+++ b/denote.el
@@ -970,8 +970,26 @@ Like `denote--completion-table' but also disable sorting."
      ((stringp dir-locals)
       dir-locals))))
 
+(defun denote-directories--make-paths (directories)
+  "Call `make-directory' on each element of DIRECTORIES unless it exists.
+Make any parent directories as well."
+  (dolist (directory directories)
+    (unless (file-directory-p directory)
+      (make-directory directory :parents))))
+
+(defun denote-directories--get-paths ()
+  "Return variable `denote-directory' as a list of directory paths."
+  (let ((get-dir (lambda (directory) (file-name-as-directory (expand-file-name 
directory)))))
+    (if (listp denote-directory)
+        (mapcar get-dir denote-directory)
+      (list (funcall get-dir denote-directory)))))
+
 (defun denote-directories ()
   "Return path of variable `denote-directory' as a proper directory.
+If the variable `denote-directory' is set to a list of file paths,
+return the list with each element expanded to be a directory.  Create
+any directories and their parents, if needed.
+
 Custom Lisp code can `let' bind the variable `denote-directory'
 to override what this function returns."
   (if-let* (((or (eq denote-directory 'default-directory) (eq denote-directory 
'local)))
@@ -982,16 +1000,8 @@ to override what this function returns."
          "Silo value must be a string; `local' or `default-directory' are 
obsolete"
          :error)
         silo-dir)
-    (let ((denote-directories
-           (if (listp denote-directory)
-               (mapcar (lambda (d)
-                         (file-name-as-directory (expand-file-name d)))
-                       denote-directory)
-             (list (file-name-as-directory (expand-file-name 
denote-directory))))))
-      (mapc (lambda (d)
-              (when (not (file-directory-p d))
-                (make-directory d :parents)))
-            denote-directories)
+    (let ((denote-directories (denote-directories--get-paths)))
+      (denote-directories--make-paths denote-directories)
       denote-directories)))
 
 (defun denote-has-single-denote-directory-p ()

Reply via email to