From 60a5a63e6c6d66d1925f8cfc1191502bc34a7269 Mon Sep 17 00:00:00 2001 From: Dan Davison Date: Sat, 31 Oct 2009 20:39:57 -0400 Subject: [PATCH 2/2] Allow org-exp-blocks plugins to return block with indentation unaltered. With these changes, if org-src-preserve-indentation is non-nil, or if the block has a -i switch, then the behaviour of org-exp-blocks is altered as follows: 1. Indentation is not removed before passing the block contents to the block-transforming plugin. 2. The result returned by the plugin is not re-indented. --- lisp/org-exp-blocks.el | 17 ++++++++++------- 1 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lisp/org-exp-blocks.el b/lisp/org-exp-blocks.el index 646688d..c92a9fa 100644 --- a/lisp/org-exp-blocks.el +++ b/lisp/org-exp-blocks.el @@ -166,7 +166,7 @@ specified in BLOCKS which default to the value of (save-window-excursion (let ((case-fold-search t) (types '()) - indentation type func start) + indentation type func start body headers preserve-indent) (flet ((interblock (start end) (mapcar (lambda (pair) (funcall (second pair) start end)) org-export-interblocks))) @@ -176,17 +176,20 @@ specified in BLOCKS which default to the value of "^\\([ \t]*\\)#\\+begin_\\(\\S-+\\)[ \t]*\\(.*\\)?[\r\n]\\([^\000]*?\\)[\r\n][ \t]*#\\+end_\\S-+.*" nil t) (setq indentation (length (match-string 1))) (setq type (intern (match-string 2))) + (setq headers (save-match-data (split-string (match-string 3)))) + (setq body (match-string 4)) + (setq preserve-indent (or org-src-preserve-indentation (member "-i" headers))) + (unless preserve-indent + (setq body (save-match-data (org-remove-indentation body)))) (unless (memq type types) (setq types (cons type types))) (save-match-data (interblock start (match-beginning 0))) (if (setq func (cadr (assoc type org-export-blocks))) (progn (replace-match (save-match-data - (if (memq type org-export-blocks-witheld) - "" - (apply func (save-match-data (org-remove-indentation (match-string 4))) - (split-string (match-string 3) " ")))) t t) - ;; indent block - (indent-code-rigidly (match-beginning 0) (match-end 0) indentation))) + (if (memq type org-export-blocks-witheld) "" + (apply func body headers))) t t) + (unless preserve-indent + (indent-code-rigidly (match-beginning 0) (match-end 0) indentation)))) (setq start (match-end 0))) (interblock start (point-max)))))) -- 1.6.3.3