Commit | Line | Data |
---|---|---|
86fbb8ca CD |
1 | ;;; ob-emacs-lisp.el --- org-babel functions for emacs-lisp code evaluation |
2 | ||
3 | ;; Copyright (C) 2009, 2010 Free Software Foundation, Inc | |
4 | ||
5 | ;; Author: Eric Schulte | |
6 | ;; Keywords: literate programming, reproducible research | |
7 | ;; Homepage: http://orgmode.org | |
8 | ;; Version: 7.01 | |
9 | ||
10 | ;; This file is part of GNU Emacs. | |
11 | ||
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. | |
16 | ||
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. | |
21 | ||
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/>. | |
24 | ||
25 | ;;; Commentary: | |
26 | ||
27 | ;; Org-Babel support for evaluating emacs-lisp code | |
28 | ||
29 | ;;; Code: | |
30 | (require 'ob) | |
31 | ||
32 | (defvar org-babel-default-header-args:emacs-lisp | |
33 | '((:hlines . "yes") (:colnames . "no")) | |
34 | "Default arguments for evaluating an emacs-lisp source block.") | |
35 | ||
36 | (declare-function org-babel-comint-with-output "ob-comint" (&rest body)) | |
37 | (declare-function org-babel-comint-buffer-livep "ob-comint" (buffer)) | |
38 | (declare-function org-babel-comint-wait-for-output "ob-comint" (buffer)) | |
39 | (declare-function org-babel-comint-in-buffer "ob-comint" (buffer &rest body)) | |
40 | (declare-function orgtbl-to-generic "org-table" (table params)) | |
41 | ||
42 | (defun org-babel-expand-body:emacs-lisp (body params &optional processed-params) | |
43 | "Expand BODY according to PARAMS, return the expanded body." | |
44 | (let* ((processed-params (or processed-params (org-babel-process-params params))) | |
45 | (vars (nth 1 processed-params)) | |
46 | (result-params (nth 2 processed-params)) | |
47 | (print-level nil) (print-length nil) | |
48 | (body (if (> (length vars) 0) | |
49 | (concat "(let (" | |
50 | (mapconcat | |
51 | (lambda (var) (format "%S" (print `(,(car var) ',(cdr var))))) | |
52 | vars "\n ") | |
53 | ")\n" body ")") | |
54 | body))) | |
55 | (if (or (member "code" result-params) | |
56 | (member "pp" result-params)) | |
57 | (concat "(pp " body ")") body))) | |
58 | ||
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 ((processed-params (org-babel-process-params params))) | |
63 | (org-babel-reassemble-table | |
64 | (eval (read (format "(progn %s)" | |
65 | (org-babel-expand-body:emacs-lisp | |
66 | body params processed-params)))) | |
67 | (org-babel-pick-name (nth 4 processed-params) (cdr (assoc :colnames params))) | |
68 | (org-babel-pick-name (nth 5 processed-params) (cdr (assoc :rownames params))))))) | |
69 | ||
70 | (provide 'ob-emacs-lisp) | |
71 | ||
72 | ;; arch-tag: e9a3acca-dc84-472a-9f5a-23c35befbcd6 | |
73 | ||
74 | ;;; ob-emacs-lisp.el ends here |