From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Eric Schulte" Subject: [PATCH] recursively resolve #+INCLUDE files Date: Sun, 13 Jun 2010 15:16:21 -0700 Message-ID: <878w6izih6.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from [140.186.70.92] (port=51445 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1ONvTf-0005cQ-Dy for emacs-orgmode@gnu.org; Sun, 13 Jun 2010 18:16:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1ONvTe-0006qe-6R for emacs-orgmode@gnu.org; Sun, 13 Jun 2010 18:16:27 -0400 Received: from mail-pv0-f169.google.com ([74.125.83.169]:59863) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1ONvTe-0006qX-0Y for emacs-orgmode@gnu.org; Sun, 13 Jun 2010 18:16:26 -0400 Received: by pva18 with SMTP id 18so5309678pva.0 for ; Sun, 13 Jun 2010 15:16:25 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Org Mode --=-=-= What do people think of this proposed patch. I'd like to apply it, but figured I'd run it by the list first Best -- Eric ,----[from the commit message] | org-exp: now recursively resolve #+INCLUDE: files in a safe way | | * lisp/org-exp.el (org-export-preprocess-string): | now using `org-export-handle-include-files-recurse' to resolve | included files | | (org-export-handle-include-files): now returns a list of the | included files | | (org-export-handle-include-files-recurse): recursively calls | `org-export-handle-include-files' while checking to see if the | process has entered an infinite loop. `---- --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-org-exp-now-recursively-resolve-INCLUDE-files-in-a-s.patch >From 3c3dbd683857041703109e950e0ad85e6fec8a13 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Sun, 13 Jun 2010 15:14:08 -0700 Subject: [PATCH] org-exp: now recursively resolve #+INCLUDE: files in a safe way * lisp/org-exp.el (org-export-preprocess-string): now using `org-export-handle-include-files-recurse' to resolve included files (org-export-handle-include-files): now returns a list of the included files (org-export-handle-include-files-recurse): recursively calls `org-export-handle-include-files' while checking to see if the process has entered an infinite loop. --- lisp/org-exp.el | 22 +++++++++++++++++++--- 1 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lisp/org-exp.el b/lisp/org-exp.el index 915e1f5..9428439 100644 --- a/lisp/org-exp.el +++ b/lisp/org-exp.el @@ -1032,7 +1032,7 @@ on this string to produce the exported version." (untabify (point-min) (point-max)) ;; Handle include files, and call a hook - (org-export-handle-include-files) + (org-export-handle-include-files-recurse) (run-hooks 'org-export-preprocess-after-include-files-hook) ;; Get rid of archived trees @@ -1969,7 +1969,7 @@ TYPE must be a string, any of: (defun org-export-handle-include-files () "Include the contents of include files, with proper formatting." (let ((case-fold-search t) - params file markup lang start end prefix prefix1 switches) + params file markup lang start end prefix prefix1 switches all) (goto-char (point-min)) (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t) (setq params (read (concat "(" (match-string 1) ")")) @@ -1986,6 +1986,7 @@ TYPE must be a string, any of: (not (file-exists-p file)) (not (file-readable-p file))) (insert (format "CANNOT INCLUDE FILE %s" file)) + (setq all (cons file all)) (when markup (if (equal (downcase markup) "src") (setq start (format "#+begin_src %s %s\n" @@ -1998,7 +1999,22 @@ TYPE must be a string, any of: (insert (org-get-file-contents (expand-file-name file) prefix prefix1 markup)) (or (bolp) (newline)) - (insert (or end "")))))) + (insert (or end "")))) + all)) + +(defun org-export-handle-include-files-recurse () + "Recursively include files aborting on circular inclusion." + (let ((now (list org-current-export-file)) all) + (while now + (setq all (remove-duplicates (append now all))) + (setq now (org-export-handle-include-files)) + (let ((intersection + (delq nil + (mapcar + (lambda (el) (when (member el all) el)) + now)))) + (when (intersection now all) + (error "recursive #+INCLUDE: %S" intersection)))))) (defun org-get-file-contents (file &optional prefix prefix1 markup) "Get the contents of FILE and return them as a string. -- 1.7.0.4 --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-orgmode mailing list Please use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode --=-=-=--