>From c16e6faf21890f8cb572133d40dc2c3545821a23 Mon Sep 17 00:00:00 2001 From: Rasmus Date: Fri, 27 May 2016 16:50:28 +0200 Subject: [PATCH 3/6] ox-publish: Optionally add dirs to project files * lisp/ox-publish.el (org-publish-sitemap-file-entry-format): (org-publish-compare-directory-files): New optional argument that allows inclusion of directories in `org-publish-temp-files'. --- lisp/ox-publish.el | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/lisp/ox-publish.el b/lisp/ox-publish.el index 480c8de..8a72349 100644 --- a/lisp/ox-publish.el +++ b/lisp/ox-publish.el @@ -439,20 +439,21 @@ This splices all the components into the list." retval)) (defun org-publish-get-base-files-1 - (base-dir &optional recurse match skip-file skip-dir) + (base-dir &optional recurse match skip-file skip-dir include-dirs) "Set `org-publish-temp-files' with files from BASE-DIR directory. If RECURSE is non-nil, check BASE-DIR recursively. If MATCH is non-nil, restrict this list to the files matching the regexp MATCH. If SKIP-FILE is non-nil, skip file matching the regexp SKIP-FILE. If SKIP-DIR is non-nil, don't check directories -matching the regexp SKIP-DIR when recursing through BASE-DIR." +matching the regexp SKIP-DIR when recursing through BASE-DIR. +If INCLUDE-DIRS is non-nil include directories" (let ((all-files (if (not recurse) (directory-files base-dir t match) ;; If RECURSE is non-nil, we want all files ;; matching MATCH and sub-directories. (cl-remove-if-not (lambda (file) (or (file-directory-p file) - (and match (string-match match file)))) + (and match (string-match-p match file)))) (directory-files base-dir t))))) (dolist (f (if (not org-publish-sitemap-requested) all-files (sort all-files #'org-publish-compare-directory-files))) @@ -461,15 +462,18 @@ matching the regexp SKIP-DIR when recursing through BASE-DIR." (if (and fd-p recurse (not (string-match "^\\.+$" fnd)) (if skip-dir (not (string-match skip-dir fnd)) t)) - (org-publish-get-base-files-1 - f recurse match skip-file skip-dir) + (progn + (and include-dirs + (cl-pushnew f org-publish-temp-files :test #'file-equal-p)) + (org-publish-get-base-files-1 + f recurse match skip-file skip-dir include-dirs)) (unless (or fd-p ; This is a directory. (and skip-file (string-match skip-file fnd)) (not (file-exists-p (file-truename f))) (not (string-match match fnd))) (cl-pushnew f org-publish-temp-files :test #'file-equal-p))))))) -(defun org-publish-get-base-files (project &optional exclude-regexp) +(defun org-publish-get-base-files (project &optional exclude-regexp include-dirs) "Return a list of all files in PROJECT. If EXCLUDE-REGEXP is set, this will be used to filter out matching filenames." @@ -515,10 +519,20 @@ matching filenames." (org-publish-get-base-files-1 base-dir recurse match ;; FIXME distinguish exclude regexp ;; for skip-file and skip-dir? - exclude-regexp exclude-regexp) + exclude-regexp exclude-regexp include-dirs) (dolist (f include-list org-publish-temp-files) (cl-pushnew (expand-file-name (concat base-dir f)) - org-publish-temp-files)))) + org-publish-temp-files :test #'file-equal-p)) + ;; Remove directories from `org-publish-temp-files' that do not + ;; hold project files. + (when include-dirs + (let* ((dirs (cl-remove-if-not 'file-directory-p org-publish-temp-files)) + (file-dirs (mapcar 'file-name-directory + (cl-remove-if 'file-directory-p org-publish-temp-files)))) + (setq org-publish-temp-files + (cl-set-difference org-publish-temp-files + (cl-set-difference dirs file-dirs :test #'file-equal-p) + :test #'file-equal-p)))))) (defun org-publish-get-project-from-filename (filename &optional up) "Return the project that FILENAME belongs to." -- 2.8.3