1 ;;; ob-emacs-lisp.el --- Babel Functions for Emacs-lisp Code -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2009-2016 Free Software Foundation, Inc.
5 ;; Author: Eric Schulte
6 ;; Keywords: literate programming, reproducible research
7 ;; Homepage: http://orgmode.org
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 ;; Org-Babel support for evaluating emacs-lisp code
31 (defconst org-babel-header-args
:emacs-lisp
'((lexical .
:any
))
32 "Emacs-lisp specific header arguments.")
34 (defvar org-babel-default-header-args
:emacs-lisp
'((:lexical .
"no"))
35 "Default arguments for evaluating an emacs-lisp source block.
37 A value of \"yes\" or t causes src blocks to be eval'd using
38 lexical scoping. It can also be an alist mapping symbols to
39 their value. It is used as the optional LEXICAL argument to
42 (defun org-babel-expand-body:emacs-lisp
(body params
)
43 "Expand BODY according to PARAMS, return the expanded body."
44 (let* ((vars (org-babel--get-vars params
))
45 (result-params (cdr (assq :result-params params
)))
46 (print-level nil
) (print-length nil
)
47 (body (if (> (length vars
) 0)
51 (format "%S" (print `(,(car var
) ',(cdr var
)))))
55 (if (or (member "code" result-params
)
56 (member "pp" result-params
))
57 (concat "(pp " body
")") body
)))
59 (defun org-babel-execute:emacs-lisp
(body params
)
60 "Execute a block of emacs-lisp code with Babel."
61 (save-window-excursion
62 (let* ((lexical (cdr (assq :lexical params
)))
64 (eval (read (format (if (member "output"
65 (cdr (assq :result-params params
)))
66 "(with-output-to-string %s)"
68 (org-babel-expand-body:emacs-lisp
73 (member lexical
'("yes" "t"))))))
74 (org-babel-result-cond (cdr (assq :result-params params
))
75 (let ((print-level nil
)
77 (if (or (member "scalar" (cdr (assq :result-params params
)))
78 (member "verbatim" (cdr (assq :result-params params
))))
80 (format "%s" result
)))
81 (org-babel-reassemble-table
83 (org-babel-pick-name (cdr (assq :colname-names params
))
84 (cdr (assq :colnames params
)))
85 (org-babel-pick-name (cdr (assq :rowname-names params
))
86 (cdr (assq :rownames params
))))))))
88 (org-babel-make-language-alias "elisp" "emacs-lisp")
90 (provide 'ob-emacs-lisp
)
94 ;;; ob-emacs-lisp.el ends here