emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Bastien <bzg@gnu.org>
To: Brett Viren <bv@bnl.gov>
Cc: emacs-orgmode@gnu.org
Subject: Re: Finer-grained control of published files
Date: Thu, 13 Mar 2014 15:22:27 +0100	[thread overview]
Message-ID: <877g7yw53w.fsf@bzg.ath.cx> (raw)
In-Reply-To: <ir4r46bto8b.fsf@lycastus.phy.bnl.gov> (Brett Viren's message of	"Sun, 09 Mar 2014 10:56:20 -0400")

[-- Attachment #1: Type: text/plain, Size: 547 bytes --]

Hi Brett,

Brett Viren <bv@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,


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: oxignore.patch --]
[-- Type: text/x-diff, Size: 3831 bytes --]

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


[-- Attachment #3: Type: text/plain, Size: 14 bytes --]


-- 
 Bastien

  reply	other threads:[~2014-03-13 14:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-09 14:56 Finer-grained control of published files Brett Viren
2014-03-13 14:22 ` Bastien [this message]
2014-03-14  0:32   ` Brett Viren
2014-03-14  8:56     ` Bastien

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=877g7yw53w.fsf@bzg.ath.cx \
    --to=bzg@gnu.org \
    --cc=bv@bnl.gov \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).