1 ;;; ob-emacs-lisp.el --- org-babel functions for emacs-lisp code evaluation
3 ;; Copyright (C) 2009, 2010 Free Software Foundation, Inc
5 ;; Author: Eric Schulte
6 ;; Keywords: literate programming, reproducible research
7 ;; Homepage: http://orgmode.org
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
27 ;; Org-Babel support for evaluating emacs-lisp code
31 (eval-when-compile (require 'ob-comint
))
33 (defvar org-babel-default-header-args
:emacs-lisp
34 '((:hlines .
"yes") (:colnames .
"no"))
35 "Default arguments for evaluating an emacs-lisp source block.")
37 (declare-function orgtbl-to-generic
"org-table" (table params
))
39 (defun org-babel-expand-body:emacs-lisp
(body params
&optional processed-params
)
40 "Expand BODY according to PARAMS, return the expanded body."
41 (let* ((processed-params (or processed-params
42 (org-babel-process-params params
)))
43 (vars (nth 1 processed-params
))
44 (result-params (nth 2 processed-params
))
45 (print-level nil
) (print-length nil
)
46 (body (if (> (length vars
) 0)
50 (format "%S" (print `(,(car var
) ',(cdr var
)))))
54 (if (or (member "code" result-params
)
55 (member "pp" result-params
))
56 (concat "(pp " body
")") body
)))
58 (defun org-babel-execute:emacs-lisp
(body params
)
59 "Execute a block of emacs-lisp code with Babel."
60 (save-window-excursion
61 (let ((processed-params (org-babel-process-params params
)))
62 (org-babel-reassemble-table
63 (eval (read (format "(progn %s)"
64 (org-babel-expand-body:emacs-lisp
65 body params processed-params
))))
66 (org-babel-pick-name (nth 4 processed-params
)
67 (cdr (assoc :colnames params
)))
68 (org-babel-pick-name (nth 5 processed-params
)
69 (cdr (assoc :rownames params
)))))))
71 (provide 'ob-emacs-lisp
)
73 ;; arch-tag: e9a3acca-dc84-472a-9f5a-23c35befbcd6
75 ;;; ob-emacs-lisp.el ends here