From: Puneeth <punchagan@gmail.com>
To: Carsten Dominik <carsten.dominik@gmail.com>
Cc: emacs-orgmode@gnu.org, Jianshi Huang <jianshi.huang@gmail.com>
Subject: Re: include an .org file and lower the level of all its headers
Date: Sun, 14 Nov 2010 12:31:05 +0530 [thread overview]
Message-ID: <AANLkTim3NkqvC72QSjj1KuJtdP2T6E8bo_EfFX_7mUMb@mail.gmail.com> (raw)
In-Reply-To: <CAC72A12-3236-423E-A730-C15099E6DE50@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 729 bytes --]
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
[-- Attachment #2: org-export-minlevel.patch.txt --]
[-- Type: text/plain, Size: 2031 bytes --]
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)
[-- 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
next prev parent reply other threads:[~2010-11-14 7:01 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-10 9:46 include an .org file and lower the level of all its headers Jianshi Huang
2010-11-10 11:09 ` Scot Becker
2010-11-10 19:06 ` Mark Elston
2010-11-10 19:35 ` Samuel Wales
2010-11-12 19:42 ` Carsten Dominik
2010-11-14 7:01 ` Puneeth [this message]
2010-11-15 10:18 ` Carsten Dominik
2011-04-20 18:48 ` Robert Goldman
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=AANLkTim3NkqvC72QSjj1KuJtdP2T6E8bo_EfFX_7mUMb@mail.gmail.com \
--to=punchagan@gmail.com \
--cc=carsten.dominik@gmail.com \
--cc=emacs-orgmode@gnu.org \
--cc=jianshi.huang@gmail.com \
/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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.