summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPuneeth Chaganti <punchagan@gmail.com>2010-11-14 12:01:05 +0000
committerCarsten Dominik <carsten.dominik@gmail.com>2010-11-15 11:15:53 +0100
commit249ae99b183958f698ed279034cf834f64e604bd (patch)
treebf878c7699b53580005283f4f7efe814bdbac3d1
parent0adcd5d619647c947011ff8b1d9da3d5f5ae5068 (diff)
downloadorg-mode-249ae99b183958f698ed279034cf834f64e604bd.tar.gz
Include an .org file and lower the level of all its headers
* doc/org.texi (Include files): Document :minlevel. * lisp/org-exp.el (org-export-handle-include-files): Support :minlevel property. (org-get-file-contents): New argument minlevel to demote included content. On Sat, Nov 13, 2010 at 1:12 AM, Carsten Dominik <carsten.dominik@gmail.com> wrote: > > On Nov 10, 2010, at 3:46 AM, Jianshi Huang wrote: > >> Hi, >> >> I know I can include any file using #+INCLUDE. >> >> I need to include several org files, but they were edited >> independently as a complete document. >> >> Now I want to lower the levels of headers in these org files >> automatically during inclusion. Is there a way to do that? > > No.  But since #+include accepts arguments, it could be implemented, > something like > > #+include "aaa.org" :minlevel 4 > > or so.  I would accept a good patch to this effect. Here's a patch. I tested it with a simple document and works fine. Thanks, Puneeth
-rw-r--r--doc/org.texi6
-rw-r--r--lisp/org-exp.el10
2 files changed, 11 insertions, 5 deletions
diff --git a/doc/org.texi b/doc/org.texi
index 61f90d4..ae4a016 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -8832,8 +8832,10 @@ language for formatting the contents. The markup is optional, if it is not
given, the text will be assumed to be in Org-mode format and will be
processed normally. The include line will also allow additional keyword
parameters @code{:prefix1} and @code{:prefix} to specify prefixes for the
-first line and for each following line, as well as any options accepted by
-the selected markup. For example, to include a file as an item, use
+first line and for each following line, @code{:minlevel} in order to get
+org-mode content demoted to a specified level, as well as any options
+accepted by the selected markup. For example, to include a file as an item,
+use
@example
#+INCLUDE: "~/snippets/xx" :prefix1 " + " :prefix " "
diff --git a/lisp/org-exp.el b/lisp/org-exp.el
index 2affcba..08c0ac6 100644
--- a/lisp/org-exp.el
+++ b/lisp/org-exp.el
@@ -2126,12 +2126,13 @@ 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 all)
+ params file markup lang start end prefix prefix1 switches all minlevel)
(goto-char (point-min))
(while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t)
(setq params (read (concat "(" (match-string 1) ")"))
prefix (org-get-and-remove-property 'params :prefix)
prefix1 (org-get-and-remove-property 'params :prefix1)
+ minlevel (org-get-and-remove-property 'params :minlevel)
file (org-symname-or-string (pop params))
markup (org-symname-or-string (pop params))
lang (and (member markup '("src" "SRC"))
@@ -2154,7 +2155,7 @@ TYPE must be a string, any of:
end (format "#+end_%s" markup))))
(insert (or start ""))
(insert (org-get-file-contents (expand-file-name file)
- prefix prefix1 markup))
+ prefix prefix1 markup minlevel))
(or (bolp) (newline))
(insert (or end ""))))
all))
@@ -2171,7 +2172,7 @@ TYPE must be a string, any of:
(when intersection
(error "Recursive #+INCLUDE: %S" intersection))))))
-(defun org-get-file-contents (file &optional prefix prefix1 markup)
+(defun org-get-file-contents (file &optional prefix prefix1 markup minlevel)
"Get the contents of FILE and return them as a string.
If PREFIX is a string, prepend it to each line. If PREFIX1
is a string, prepend it to the first line instead of PREFIX.
@@ -2193,6 +2194,9 @@ take care of the block they are in."
(goto-char (match-beginning 0))
(insert ",")
(end-of-line 1)))
+ (when minlevel
+ (dotimes (lvl minlevel)
+ (org-map-region 'org-demote (point-min) (point-max))))
(buffer-string)))
(defun org-get-and-remove-property (listvar prop)