summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <n.goaziou@gmail.com>2014-01-29 09:01:43 +0100
committerNicolas Goaziou <n.goaziou@gmail.com>2014-01-29 09:01:43 +0100
commit63a2a403a92f77ddb2035996a41a5fd77bed61af (patch)
treeb5017c78daac85361ad3198c395edf3d4f5e8545
parentb298a47eb1c4c4e2fcb3984e5facb33f46c70167 (diff)
downloadorg-mode-63a2a403a92f77ddb2035996a41a5fd77bed61af.tar.gz
ob-exp: Fix switches handling upon exporting
* lisp/ob-exp.el (org-babel-exp-code-template): Include switches in template. (org-babel-exp-code): Provide %switches placeholder. * testing/lisp/test-ob-exp.el (ob-export/export-src-block-with-switches): New test. (ob-export/export-src-block-with-flags): Fix indentation. This fixes dde6af3a6230b37aabfb4f75c2dee89433958375. The confusion came from the fact that "flags" placeholder had two meanings: the :flags value and the block's switches (e.g., "-n"). This patch separates these two meanings.
-rw-r--r--lisp/ob-exp.el7
-rw-r--r--testing/lisp/test-ob-exp.el13
2 files changed, 17 insertions, 3 deletions
diff --git a/lisp/ob-exp.el b/lisp/ob-exp.el
index 84eb011..cb64136 100644
--- a/lisp/ob-exp.el
+++ b/lisp/ob-exp.el
@@ -309,7 +309,7 @@ The function respects the value of the :exports header argument."
(org-babel-exp-code info)))))
(defcustom org-babel-exp-code-template
- "#+BEGIN_SRC %lang%flags\n%body\n#+END_SRC"
+ "#+BEGIN_SRC %lang%switches%flags\n%body\n#+END_SRC"
"Template used to export the body of code blocks.
This template may be customized to include additional information
such as the code block name, or the values of particular header
@@ -319,6 +319,7 @@ and the following %keys may be used.
lang ------ the language of the code block
name ------ the name of the code block
body ------ the body of the code block
+ switches -- the switches associated to the code block
flags ----- the flags passed to the code block
In addition to the keys mentioned above, every header argument
@@ -341,8 +342,10 @@ replaced with its value."
org-babel-exp-code-template
`(("lang" . ,(nth 0 info))
("body" . ,(org-escape-code-in-string (nth 1 info)))
+ ("switches" . ,(let ((f (nth 3 info)))
+ (and (org-string-nw-p f) (concat " " f))))
("flags" . ,(let ((f (assq :flags (nth 2 info))))
- (when f (concat " " (cdr f)))))
+ (and f (concat " " (cdr f)))))
,@(mapcar (lambda (pair)
(cons (substring (symbol-name (car pair)) 1)
(format "%S" (cdr pair))))
diff --git a/testing/lisp/test-ob-exp.el b/testing/lisp/test-ob-exp.el
index f8858b5..d09e9eb 100644
--- a/testing/lisp/test-ob-exp.el
+++ b/testing/lisp/test-ob-exp.el
@@ -303,10 +303,21 @@ Here is one at the end of a line. =2=
(org-export-execute-babel-code)
(buffer-string)))))
+(ert-deftest ob-export/export-src-block-with-switches ()
+ "Test exporting a source block with switches."
+ (should
+ (string-match
+ "\\`#\\+BEGIN_SRC emacs-lisp -n -r$"
+ (org-test-with-temp-text
+ "#+BEGIN_SRC emacs-lisp -n -r\n\(+ 1 1)\n#+END_SRC"
+ (org-export-execute-babel-code)
+ (buffer-string)))))
+
(ert-deftest ob-export/export-src-block-with-flags ()
"Test exporting a source block with a flag."
(should
- (string-match "\\`#\\+BEGIN_SRC emacs-lisp -some-flag$"
+ (string-match
+ "\\`#\\+BEGIN_SRC emacs-lisp -some-flag$"
(org-test-with-temp-text
"#+BEGIN_SRC emacs-lisp :flags -some-flag\n\(+ 1 1)\n#+END_SRC"
(org-export-execute-babel-code)