From 3e1aeac3b3d57dfab86c2cc230fad1459a0cecc8 Mon Sep 17 00:00:00 2001 From: Stig Brautaset Date: Fri, 14 Jul 2017 20:55:17 +0100 Subject: [PATCH 1/3] use cl-lib functions rather than cl ones in org-test From ead36e862d150e3a83d363bdead850a2e3ec281d Mon Sep 17 00:00:00 2001 From: Stig Brautaset Date: Fri, 14 Jul 2017 20:43:11 +0100 Subject: [PATCH 1/3] org-test.el: use prefixed functions from cl-lib.el rather than cl.el --- testing/org-test.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testing/org-test.el b/testing/org-test.el index 844178e5a..5989907dd 100644 --- a/testing/org-test.el +++ b/testing/org-test.el @@ -104,7 +104,7 @@ org-test searches this directory up the directory tree.") This can be used at the top of code-block-language specific test files to avoid loading the file on systems without the executable." - (unless (reduce + (unless (cl-reduce (lambda (acc dir) (or acc (file-exists-p (expand-file-name exe dir)))) exec-path :initial-value nil) @@ -200,7 +200,7 @@ otherwise place the point at the beginning of the inserted text." (defmacro org-test-with-temp-text-in-file (text &rest body) "Run body in a temporary file buffer with Org mode as the active mode." (declare (indent 1)) - (let ((results (gensym))) + (let ((results (cl-gensym))) `(let ((file (make-temp-file "org-test")) (kill-buffer-query-functions nil) (inside-text (if (stringp ,text) ,text (eval ,text))) From a49e146621d03cd726b8b77c99c9a2e182611d65 Mon Sep 17 00:00:00 2001 From: Stig Brautaset Date: Fri, 14 Jul 2017 20:57:39 +0100 Subject: [PATCH 2/3] Use cl-lib rather than cl variants in org-drill org-drill requires only cl-lib rather than cl, so should use cl-gensym rather than gensym I believe. From 1eef99d550e467bf4a3eaf6bdbe4d3a482f6c187 Mon Sep 17 00:00:00 2001 From: Stig Brautaset Date: Fri, 14 Jul 2017 20:45:37 +0100 Subject: [PATCH 2/3] org-drill.el: use cl-gensym rather than gensym cl-lib is already required by this file, but cl is not. --- contrib/lisp/org-drill.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/lisp/org-drill.el b/contrib/lisp/org-drill.el index fb578ab86..7c4a29930 100644 --- a/contrib/lisp/org-drill.el +++ b/contrib/lisp/org-drill.el @@ -622,7 +622,7 @@ regardless of whether the test was successful.") (defmacro pop-random (place) - (let ((idx (gensym))) + (let ((idx (cl-gensym))) `(if (null ,place) nil (let ((,idx (random* (length ,place)))) From 5e0db079884f0544049de24e43f928b724fa2990 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Sun, 23 Jul 2017 22:41:27 +0200 Subject: [PATCH 3/3] 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 --- lisp/ob-emacs-lisp.el | 53 ++++++++++++++---------------- testing/lisp/test-ob-emacs-lisp.el | 16 ++++----- 2 files changed, 33 insertions(+), 36 deletions(-) diff --git a/lisp/ob-emacs-lisp.el b/lisp/ob-emacs-lisp.el index c0bd12a87..989561db7 100644 --- a/lisp/ob-emacs-lisp.el +++ b/lisp/ob-emacs-lisp.el @@ -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 diff --git a/testing/lisp/test-ob-emacs-lisp.el b/testing/lisp/test-ob-emacs-lisp.el index 29f3e1f3f..1cbb0815c 100644 --- a/testing/lisp/test-ob-emacs-lisp.el +++ b/testing/lisp/test-ob-emacs-lisp.el @@ -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)