Re: [O] [PATCH] Dynamically demote included file relatively to the current heading level

2012-04-23 Thread Bastien
Hi Daniel,

Daniel Dehennin daniel.dehen...@baby-gnu.org writes:

 You can get the following patchset by pulling:

  git pull git://git.baby-gnu.net/org-mode dad/add-level-to-headings

 Regards.

 This patch permits a more flexible usage than :minlevel.

I applied your patch with a small modification that fixes it.
Thanks for your contribution and sorry for the delay.

Best,

-- 
 Bastien



[O] [PATCH] Dynamically demote included file relatively to the current heading level

2011-12-12 Thread Daniel Dehennin
Hello,

You can get the following patchset by pulling:

 git pull git://git.baby-gnu.net/org-mode dad/add-level-to-headings

Regards.

This patch permits a more flexible usage than :minlevel.

It's possible to include files with their heading demoted by 'X' levels
relatively to the current one.

This is useful to make some glue documentation based on many little
parts:

- each little part starts its heading at level 1
- each part can include other parts:
  * as children by setting :addlevel 1
  * as same level by setting :addlevel 0

The test files are provided but 'org-test-compare-with-file' is TODO.

* lisp/org-exp.el (org-export-handle-include-files): Save heading level
  of the parent of the included file as currentlevel.
  Included files are demoted relatively by addlevel.

* lisp/org-exp.el (org-get-file-contents): Demote included file
  relatively to partentlevel by addlevel increment.

* testing/examples/include-master.org: Entry point of the addlevel test
  case.

* testing/examples/include-1.org: File included by include-master.org,
  both at level1 (i.e. no addlevel) and level2.

* testing/examples/include-2.org: File included by include-1.org, level
  incremented by one relatively to include-1.org

* testing/examples/include-addlevel.txt: Attended result to ASCII
  export.
---
 lisp/org-exp.el   |   24 ++---
 testing/examples/include-1.org|8 
 testing/examples/include-2.org|4 ++
 testing/examples/include-addlevel.txt |   58 +
 testing/examples/include-master.org   |   15 
 5 files changed, 103 insertions(+), 6 deletions(-)
 create mode 100644 testing/examples/include-1.org
 create mode 100644 testing/examples/include-2.org
 create mode 100644 testing/examples/include-addlevel.txt
 create mode 100644 testing/examples/include-master.org

diff --git a/lisp/org-exp.el b/lisp/org-exp.el
index eae5be7..7e0512d 100644
--- a/lisp/org-exp.el
+++ b/lisp/org-exp.el
@@ -2381,13 +2381,14 @@ 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 minlevel 
lines)
+   params file markup lang start end prefix prefix1 switches all 
currentlevel minlevel addlevel lines)
 (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)
+   addlevel (org-get-and-remove-property 'params :addlevel)
lines (org-get-and-remove-property 'params :lines)
file (org-symname-or-string (pop params))
markup (org-symname-or-string (pop params))
@@ -2396,6 +2397,8 @@ TYPE must be a string, any of:
switches (mapconcat #'(lambda (x) (format %s x)) params  )
start nil end nil)
   (delete-region (match-beginning 0) (match-end 0))
+  (setq currentlevel (or (org-current-level)
+0))
   (if (or (not file)
  (not (file-exists-p file))
  (not (file-readable-p file)))
@@ -2411,7 +2414,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 minlevel lines))
+  prefix prefix1 markup currentlevel 
minlevel addlevel lines))
(or (bolp) (newline))
(insert (or end 
 all))
@@ -2428,13 +2431,15 @@ TYPE must be a string, any of:
(when intersection
  (error Recursive #+INCLUDE: %S intersection))
 
-(defun org-get-file-contents (file optional prefix prefix1 markup minlevel 
lines)
+(defun org-get-file-contents (file optional prefix prefix1 markup parentlevel 
minlevel addlevel lines)
   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.
 If MARKUP, don't protect org-like lines, the exporter will
-take care of the block they are in.  If LINES is a string
-specifying a range of lines, include only those lines .
+take care of the block they are in.  If ADDLEVEL is a number,
+demote included file to current heading level+ADDLEVEL.
+If LINES is a string specifying a range of lines,
+include only those lines.
   (if (stringp markup) (setq markup (downcase markup)))
   (with-temp-buffer
 (insert-file-contents file)
@@ -2467,7 +2472,14 @@ specifying a range of lines, include only those lines .
 (when minlevel
   (dotimes (lvl minlevel)
(org-map-region 'org-demote