From mboxrd@z Thu Jan 1 00:00:00 1970 From: Bastien Subject: Re: Finer-grained control of published files Date: Thu, 13 Mar 2014 15:22:27 +0100 Message-ID: <877g7yw53w.fsf@bzg.ath.cx> References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:40904) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WO6Wt-0004Ia-QL for emacs-orgmode@gnu.org; Thu, 13 Mar 2014 10:22:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WO6Wo-0002C3-5i for emacs-orgmode@gnu.org; Thu, 13 Mar 2014 10:22:39 -0400 Received: from rs249.mailgun.us ([209.61.151.249]:36852) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WO6Wn-0002Ba-SV for emacs-orgmode@gnu.org; Thu, 13 Mar 2014 10:22:34 -0400 In-Reply-To: (Brett Viren's message of "Sun, 09 Mar 2014 10:56:20 -0400") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Brett Viren Cc: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain Hi Brett, Brett Viren writes: > What I hope for is something equivalent to git's .gitignore > functionality where I can place, say, .orgignore files full of regexp > patterns anywhere in my org source tree and have org-publish honor > them. I like this idea. > Is there anything in this direction? Please test the attached patch against the tip of the master branch and let me know if it works: it checks against a .oxignore file, one regexp on each line. If you find it useful, I'll commit this for the next version. Thanks, --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=oxignore.patch Changes in stash@{0}^2^..stash@{0} 1 file changed, 32 insertions(+), 19 deletions(-) lisp/ox-publish.el | 51 ++++++++++++++++++++++++++++++++------------------- Modified lisp/ox-publish.el diff --git a/lisp/ox-publish.el b/lisp/ox-publish.el index ad8eb32..6f20151 100644 --- a/lisp/ox-publish.el +++ b/lisp/ox-publish.el @@ -435,37 +435,50 @@ 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-regexp skip-dir-regexp) "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." +MATCH. If SKIP-FILE-REGEXP is non-nil, skip file matching this +regexp. If SKIP-DIR-REGEXP is non-nil, don't check directories +matching the regexp SKIP-DIR-REGEXP when recursing through BASE-DIR." (mapc (lambda (f) (let ((fd-p (file-directory-p f)) (fnd (file-name-nondirectory f))) (if (and fd-p recurse (not (string-match "^\\.+$" fnd)) - (if skip-dir (not (string-match skip-dir fnd)) t)) + (if skip-dir-regexp (not (string-match skip-dir-regexp fnd)) t)) (org-publish-get-base-files-1 - f recurse match skip-file skip-dir) + f recurse match skip-file-regexp skip-dir-regexp) (unless (or fd-p ;; this is a directory - (and skip-file (string-match skip-file fnd)) + (and skip-file-regexp (string-match skip-file-regexp fnd)) (not (file-exists-p (file-truename f))) (not (string-match match fnd))) - (pushnew f org-publish-temp-files))))) - (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. - (org-remove-if-not - (lambda (file) - (or (file-directory-p file) - (and match (string-match match file)))) - (directory-files base-dir t))))) - (if (not org-publish-sitemap-requested) all-files - (sort all-files 'org-publish-compare-directory-files))))) + (let* ((oxi (expand-file-name (concat base-dir ".oxignore"))) + reoxi + (notmatch (when (file-exists-p oxi) + (with-temp-buffer + (insert-file-contents oxi) + (goto-char (point-min)) + (while (re-search-forward "^\\(.+\\)$" nil t) + (if (< 0 (length (org-trim (match-string 1)))) + (push (match-string 1) reoxi)))) + (if reoxi (mapconcat 'identity reoxi "\\|")))) + (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. + (org-remove-if-not + (lambda (file) + (or (file-directory-p file) + (and match (string-match match file)))) + (directory-files base-dir t)))) + (all-files2 (org-remove-if (lambda (file) + (and notmatch (string-match notmatch file))) + all-files))) + (if (not org-publish-sitemap-requested) all-files2 + (sort all-files2 'org-publish-compare-directory-files))))) (defun org-publish-get-base-files (project &optional exclude-regexp) "Return a list of all files in PROJECT. @@ -512,7 +525,7 @@ matching filenames." org-publish-temp-files)) (org-publish-get-base-files-1 base-dir recurse match ;; FIXME distinguish exclude regexp - ;; for skip-file and skip-dir? + ;; for skip-file-regexp and skip-dir-regexp? exclude-regexp exclude-regexp) (mapc (lambda (f) (pushnew --=-=-= Content-Type: text/plain -- Bastien --=-=-=--