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.
This commit is contained in:
Nicolas Berthier 2014-08-01 11:28:05 +02:00 committed by Nicolas Goaziou
parent 2ea7bf4042
commit 6f0843d8a3
2 changed files with 29 additions and 26 deletions

View file

@ -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 \"raw\", but are wrapped in a RESULTS drawer, allowing
them to later be replaced or removed automatically. them to later be replaced or removed automatically.
org ----- results are added inside of a \"#+BEGIN_SRC org\" block. org ----- results are added inside of a \"src_org{}\" or \"#+BEGIN_SRC
They are not comma-escaped when inserted, but Org syntax org\" block depending on whether the current source block is
here will be discarded when exporting the file. 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 html ---- results are added inside of a #+BEGIN_HTML block. This
is a good option if you code block will output html 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 ---- the results are extracted in the syntax of the source
code of the language being evaluated and are added code of the language being evaluated and are added
inside of a #+BEGIN_SRC block with the source-code inside of a source block with the source-code language
language set appropriately. Note this relies on the set appropriately. Also, source block inlining is
preserved in this case. Note this relies on the
optional LANG argument." optional LANG argument."
(if (stringp result) (if (stringp result)
(progn (progn
@ -2172,12 +2175,15 @@ code ---- the results are extracted in the syntax of the source
((member "prepend" result-params)))) ; already there ((member "prepend" result-params)))) ; already there
(setq results-switches (setq results-switches
(if results-switches (concat " " results-switches) "")) (if results-switches (concat " " results-switches) ""))
(let ((wrap (lambda (start finish &optional no-escape) (let ((wrap (lambda (start finish &optional no-escape no-newlines)
(goto-char end) (insert (concat finish "\n")) (goto-char end)
(goto-char beg) (insert (concat start "\n")) (insert (concat finish (unless no-newlines "\n")))
(goto-char beg)
(insert (concat start (unless no-newlines "\n")))
(unless no-escape (unless no-escape
(org-escape-code-in-region (min (point) end) end)) (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)))) (setq end (point-marker))))
(proper-list-p (lambda (it) (and (listp it) (null (cdr (last it))))))) (proper-list-p (lambda (it) (and (listp it) (null (cdr (last it)))))))
;; insert results based on type ;; 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")) (funcall wrap "#+BEGIN_LaTeX" "#+END_LaTeX"))
((member "org" result-params) ((member "org" result-params)
(goto-char beg) (if (org-at-table-p) (org-cycle)) (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) ((member "code" result-params)
(funcall wrap (format "#+BEGIN_SRC %s%s" (or lang "none") results-switches) (let ((lang (or lang "none")))
"#+END_SRC")) (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) ((member "raw" result-params)
(goto-char beg) (if (org-at-table-p) (org-cycle))) (goto-char beg) (if (org-at-table-p) (org-cycle)))
((or (member "drawer" result-params) ((or (member "drawer" result-params)

View file

@ -249,14 +249,10 @@ Here is one that is also evaluated: src_sh[]{echo 4} =4=")
(org-narrow-to-subtree) (org-narrow-to-subtree)
(org-test-with-expanded-babel-code (buffer-string)))))) (org-test-with-expanded-babel-code (buffer-string))))))
(ert-deftest ob-exp/exports-inline-code-double-eval-bug () (ert-deftest ob-exp/exports-inline-code-double-eval ()
"Failing for now as the result actually is "Based on default header arguments for inline code blocks (:exports
`#+BEGIN_SRC emacs-lisp\n2#+END_SRC\n'.
Based on default header arguments for inline code blocks (:exports
results), the resulting code block `src_emacs-lisp{2}' should also be results), the resulting code block `src_emacs-lisp{2}' should also be
evaluated." evaluated."
:expected-result :failed
(should (should
(string-match "\\`=2=$" (string-match "\\`=2=$"
(org-test-with-temp-text (org-test-with-temp-text
@ -264,11 +260,9 @@ evaluated."
(org-export-execute-babel-code) (org-export-execute-babel-code)
(buffer-string))))) (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 "Ibid above, except that the resulting inline code block should not
be evaluated. Result for now is be evaluated."
`#+BEGIN_SRC emacs-lisp :exports code\n2#+END_SRC\n'"
:expected-result :failed
(should (should
(string-match "\\`src_emacs-lisp\\(?:\\[]\\)?{2}$" (string-match "\\`src_emacs-lisp\\(?:\\[]\\)?{2}$"
(org-test-with-temp-text (org-test-with-temp-text
@ -277,10 +271,7 @@ be evaluated. Result for now is
(org-export-execute-babel-code) (org-export-execute-babel-code)
(buffer-string))))) (buffer-string)))))
(ert-deftest ob-exp/exports-inline-code-double-eval-exports-both-bug () (ert-deftest ob-exp/exports-inline-code-double-eval-exports-both ()
"Failing for now as the result actually is
`src_emacs-lisp[]{(+ 1 1)} #+BEGIN_SRC emacs-lisp\n2#+END_SRC\n'."
:expected-result :failed
(should (should
(string-match (concat "\\`src_emacs-lisp\\(?:\\[]\\)?{(\\+ 1 1)} " (string-match (concat "\\`src_emacs-lisp\\(?:\\[]\\)?{(\\+ 1 1)} "
"src_emacs-lisp\\(?:\\[]\\)?{2}$") "src_emacs-lisp\\(?:\\[]\\)?{2}$")