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)))) 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) 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)))