mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2024-11-23 07:18:53 +00:00
ob-emacs-lisp: Fix pp results
* lisp/ob-emacs-lisp.el (org-babel-expand-body:emacs-lisp): Move "pp" handling... (org-babel-execute:emacs-lisp): ... here. * testing/lisp/test-ob-emacs-lisp.el (ob-emacs-lisp/commented-last-block-line): Small refactoring. Reported-by: Chunyang Xu <mail@xuchunyang.me> <http://lists.gnu.org/archive/html/emacs-orgmode/2017-07/msg00355.html>
This commit is contained in:
parent
a49e146621
commit
5e0db07988
@ -41,41 +41,38 @@ their value. It is used as the optional LEXICAL argument to
|
||||
|
||||
(defun org-babel-expand-body:emacs-lisp (body params)
|
||||
"Expand BODY according to PARAMS, return the expanded body."
|
||||
(let* ((vars (org-babel--get-vars params))
|
||||
(result-params (cdr (assq :result-params params)))
|
||||
(print-level nil) (print-length nil)
|
||||
(body (if (> (length vars) 0)
|
||||
(concat "(let ("
|
||||
(mapconcat
|
||||
(lambda (var)
|
||||
(format "%S" (print `(,(car var) ',(cdr var)))))
|
||||
vars "\n ")
|
||||
")\n" body "\n)")
|
||||
(concat body "\n"))))
|
||||
(if (or (member "code" result-params)
|
||||
(member "pp" result-params))
|
||||
(concat "(pp " body ")") body)))
|
||||
(let ((vars (org-babel--get-vars params))
|
||||
(print-level nil)
|
||||
(print-length nil))
|
||||
(if (null vars) (concat body "\n")
|
||||
(format "(let (%s)\n%s\n)"
|
||||
(mapconcat
|
||||
(lambda (var)
|
||||
(format "%S" (print `(,(car var) ',(cdr var)))))
|
||||
vars "\n ")
|
||||
body))))
|
||||
|
||||
(defun org-babel-execute:emacs-lisp (body params)
|
||||
"Execute a block of emacs-lisp code with Babel."
|
||||
(save-window-excursion
|
||||
(let* ((lexical (cdr (assq :lexical params)))
|
||||
(result
|
||||
(eval (read (format (if (member "output"
|
||||
(cdr (assq :result-params params)))
|
||||
"(with-output-to-string %s)"
|
||||
"(progn %s)")
|
||||
(org-babel-expand-body:emacs-lisp
|
||||
body params)))
|
||||
|
||||
(if (listp lexical)
|
||||
lexical
|
||||
(member lexical '("yes" "t"))))))
|
||||
(org-babel-result-cond (cdr (assq :result-params params))
|
||||
(result-params (cdr (assq :result-params params)))
|
||||
(body (format (if (member "output" result-params)
|
||||
"(with-output-to-string %s\n)"
|
||||
"(progn %s\n)")
|
||||
(org-babel-expand-body:emacs-lisp body params)))
|
||||
(result (eval (read (if (or (member "code" result-params)
|
||||
(member "pp" result-params))
|
||||
(concat "(pp " body ")")
|
||||
body))
|
||||
(if (listp lexical)
|
||||
lexical
|
||||
(member lexical '("yes" "t"))))))
|
||||
(org-babel-result-cond result-params
|
||||
(let ((print-level nil)
|
||||
(print-length nil))
|
||||
(if (or (member "scalar" (cdr (assq :result-params params)))
|
||||
(member "verbatim" (cdr (assq :result-params params))))
|
||||
(if (or (member "scalar" result-params)
|
||||
(member "verbatim" result-params))
|
||||
(format "%S" result)
|
||||
(format "%s" result)))
|
||||
(org-babel-reassemble-table
|
||||
|
@ -64,17 +64,17 @@
|
||||
(buffer-substring-no-properties (point-at-bol) (point-at-eol))))))
|
||||
|
||||
(ert-deftest ob-emacs-lisp/commented-last-block-line ()
|
||||
(org-test-with-temp-text-in-file "
|
||||
(should
|
||||
(string= ": 2"
|
||||
(org-test-with-temp-text-in-file "
|
||||
#+begin_src emacs-lisp :var a=2
|
||||
2;;
|
||||
#+end_src"
|
||||
(org-babel-next-src-block)
|
||||
(org-babel-execute-maybe)
|
||||
(re-search-forward "results" nil t)
|
||||
(forward-line)
|
||||
(should (string=
|
||||
": 2"
|
||||
(buffer-substring-no-properties (point-at-bol) (point-at-eol))))))
|
||||
(org-babel-next-src-block)
|
||||
(org-babel-execute-maybe)
|
||||
(re-search-forward "results" nil t)
|
||||
(buffer-substring-no-properties (line-beginning-position 2)
|
||||
(line-end-position 2))))))
|
||||
|
||||
(provide 'test-ob-emacs-lisp)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user