emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Eric Schulte" <schulte.eric@gmail.com>
To: Org Mode <emacs-orgmode@gnu.org>
Subject: [PATCH] recursively resolve #+INCLUDE files
Date: Sun, 13 Jun 2010 15:16:21 -0700	[thread overview]
Message-ID: <878w6izih6.fsf@gmail.com> (raw)

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

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.
`----


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-exp-now-recursively-resolve-INCLUDE-files-in-a-s.patch --]
[-- Type: text/x-diff, Size: 2863 bytes --]

From 3c3dbd683857041703109e950e0ad85e6fec8a13 Mon Sep 17 00:00:00 2001
From: Eric Schulte <schulte.eric@gmail.com>
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


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

_______________________________________________
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

             reply	other threads:[~2010-06-13 22:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-13 22:16 Eric Schulte [this message]
2010-06-16 19:34 ` [PATCH] recursively resolve #+INCLUDE files 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=878w6izih6.fsf@gmail.com \
    --to=schulte.eric@gmail.com \
    --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).