Hi Brett,

Brett Viren <b...@bnl.gov> 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,

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

-- 
 Bastien

Reply via email to