summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Berthier <nberth@member.fsf.org>2014-08-01 11:28:05 +0200
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2014-08-22 14:39:39 +0200
commit6f0843d8a32a71139b3f8375bef4ae768f4c24dd (patch)
treef74d52a77d74501d5797b87465806389fb022bca
parent2ea7bf4042ba1f9256138bd15089ed2b4b3518b4 (diff)
downloadorg-mode-6f0843d8a32a71139b3f8375bef4ae768f4c24dd.tar.gz
ob-core: Preserve inline-ness of source blocks when inserting results
* lisp/ob-core.el (org-babel-insert-result): Preserve inline-ness of source blocks. * testing/lisp/test-ob-exp.el: Update newly passing tests.
-rw-r--r--lisp/ob-core.el36
-rw-r--r--testing/lisp/test-ob-exp.el19
2 files changed, 29 insertions, 26 deletions
diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 5a621d1..e01c4d2 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -2095,9 +2095,11 @@ drawer -- results are added directly to the Org-mode file as with
\"raw\", but are wrapped in a RESULTS drawer, allowing
them to later be replaced or removed automatically.
-org ----- results are added inside of a \"#+BEGIN_SRC org\" block.
- They are not comma-escaped when inserted, but Org syntax
- here will be discarded when exporting the file.
+org ----- results are added inside of a \"src_org{}\" or \"#+BEGIN_SRC
+ org\" block depending on whether the current source block is
+ inline or not. They are not comma-escaped when inserted,
+ but Org syntax here will be discarded when exporting the
+ file.
html ---- results are added inside of a #+BEGIN_HTML block. This
is a good option if you code block will output html
@@ -2109,8 +2111,9 @@ latex --- results are added inside of a #+BEGIN_LATEX block.
code ---- the results are extracted in the syntax of the source
code of the language being evaluated and are added
- inside of a #+BEGIN_SRC block with the source-code
- language set appropriately. Note this relies on the
+ inside of a source block with the source-code language
+ set appropriately. Also, source block inlining is
+ preserved in this case. Note this relies on the
optional LANG argument."
(if (stringp result)
(progn
@@ -2172,12 +2175,15 @@ code ---- the results are extracted in the syntax of the source
((member "prepend" result-params)))) ; already there
(setq results-switches
(if results-switches (concat " " results-switches) ""))
- (let ((wrap (lambda (start finish &optional no-escape)
- (goto-char end) (insert (concat finish "\n"))
- (goto-char beg) (insert (concat start "\n"))
+ (let ((wrap (lambda (start finish &optional no-escape no-newlines)
+ (goto-char end)
+ (insert (concat finish (unless no-newlines "\n")))
+ (goto-char beg)
+ (insert (concat start (unless no-newlines "\n")))
(unless no-escape
(org-escape-code-in-region (min (point) end) end))
- (goto-char end) (goto-char (point-at-eol))
+ (goto-char end)
+ (unless no-newlines (goto-char (point-at-eol)))
(setq end (point-marker))))
(proper-list-p (lambda (it) (and (listp it) (null (cdr (last it)))))))
;; insert results based on type
@@ -2225,10 +2231,16 @@ code ---- the results are extracted in the syntax of the source
(funcall wrap "#+BEGIN_LaTeX" "#+END_LaTeX"))
((member "org" result-params)
(goto-char beg) (if (org-at-table-p) (org-cycle))
- (funcall wrap "#+BEGIN_SRC org" "#+END_SRC"))
+ (if inlinep
+ (funcall wrap "src_org{" "}" nil t)
+ (funcall wrap "#+BEGIN_SRC org" "#+END_SRC")))
((member "code" result-params)
- (funcall wrap (format "#+BEGIN_SRC %s%s" (or lang "none") results-switches)
- "#+END_SRC"))
+ (let ((lang (or lang "none")))
+ (if inlinep
+ (funcall wrap (format "src_%s[%s]{" lang results-switches)
+ "}" nil t)
+ (funcall wrap (format "#+BEGIN_SRC %s%s" lang results-switches)
+ "#+END_SRC"))))
((member "raw" result-params)
(goto-char beg) (if (org-at-table-p) (org-cycle)))
((or (member "drawer" result-params)
diff --git a/testing/lisp/test-ob-exp.el b/testing/lisp/test-ob-exp.el
index e319bd2..456f794 100644
--- a/testing/lisp/test-ob-exp.el
+++ b/testing/lisp/test-ob-exp.el
@@ -249,14 +249,10 @@ Here is one that is also evaluated: src_sh[]{echo 4} =4=")
(org-narrow-to-subtree)
(org-test-with-expanded-babel-code (buffer-string))))))
-(ert-deftest ob-exp/exports-inline-code-double-eval-bug ()
- "Failing for now as the result actually is
-`#+BEGIN_SRC emacs-lisp\n2#+END_SRC\n'.
-
-Based on default header arguments for inline code blocks (:exports
+(ert-deftest ob-exp/exports-inline-code-double-eval ()
+ "Based on default header arguments for inline code blocks (:exports
results), the resulting code block `src_emacs-lisp{2}' should also be
evaluated."
- :expected-result :failed
(should
(string-match "\\`=2=$"
(org-test-with-temp-text
@@ -264,11 +260,9 @@ evaluated."
(org-export-execute-babel-code)
(buffer-string)))))
-(ert-deftest ob-exp/exports-inline-code-eval-code-once-bug ()
+(ert-deftest ob-exp/exports-inline-code-eval-code-once ()
"Ibid above, except that the resulting inline code block should not
-be evaluated. Result for now is
-`#+BEGIN_SRC emacs-lisp :exports code\n2#+END_SRC\n'"
- :expected-result :failed
+be evaluated."
(should
(string-match "\\`src_emacs-lisp\\(?:\\[]\\)?{2}$"
(org-test-with-temp-text
@@ -277,10 +271,7 @@ be evaluated. Result for now is
(org-export-execute-babel-code)
(buffer-string)))))
-(ert-deftest ob-exp/exports-inline-code-double-eval-exports-both-bug ()
- "Failing for now as the result actually is
-`src_emacs-lisp[]{(+ 1 1)} #+BEGIN_SRC emacs-lisp\n2#+END_SRC\n'."
- :expected-result :failed
+(ert-deftest ob-exp/exports-inline-code-double-eval-exports-both ()
(should
(string-match (concat "\\`src_emacs-lisp\\(?:\\[]\\)?{(\\+ 1 1)} "
"src_emacs-lisp\\(?:\\[]\\)?{2}$")