org-mode/lisp/ob-emacs-lisp.el

76 lines
2.6 KiB
EmacsLisp
Raw Normal View History

;;; ob-emacs-lisp.el --- org-babel functions for emacs-lisp code evaluation
2009-03-23 23:07:02 +00:00
;; Copyright (C) 2009, 2010 Free Software Foundation, Inc
2009-03-23 23:07:02 +00:00
;; Author: Eric Schulte
2009-03-23 23:07:02 +00:00
;; Keywords: literate programming, reproducible research
;; Homepage: http://orgmode.org
;; Version: 7.01trans
2009-03-23 23:07:02 +00:00
;; This file is part of GNU Emacs.
2009-03-23 23:07:02 +00:00
;; GNU Emacs is free software: you can redistribute it and/or modify
2009-03-23 23:07:02 +00:00
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
2009-03-23 23:07:02 +00:00
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
2009-03-23 23:07:02 +00:00
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
2009-03-23 23:07:02 +00:00
;;; Commentary:
;; Org-Babel support for evaluating emacs-lisp code
2009-03-23 23:07:02 +00:00
;;; Code:
(require 'ob)
(eval-when-compile (require 'ob-comint))
2009-03-23 23:07:02 +00:00
(defvar org-babel-default-header-args:emacs-lisp
'((:hlines . "yes") (:colnames . "no"))
2010-07-13 23:04:47 +00:00
"Default arguments for evaluating an emacs-lisp source block.")
(declare-function orgtbl-to-generic "org-table" (table params))
2010-04-20 06:07:46 +00:00
(defun org-babel-expand-body:emacs-lisp (body params &optional processed-params)
"Expand BODY according to PARAMS, return the expanded body."
(let* ((processed-params (or processed-params
(org-babel-process-params params)))
(vars (nth 1 processed-params))
(result-params (nth 2 processed-params))
2010-04-20 06:07:46 +00:00
(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 ")")
body)))
(if (or (member "code" result-params)
(member "pp" result-params))
(concat "(pp " body ")") body)))
2010-04-20 06:07:46 +00:00
(defun org-babel-execute:emacs-lisp (body params)
2010-07-13 23:04:47 +00:00
"Execute a block of emacs-lisp code with Babel."
(save-window-excursion
2010-04-20 06:07:46 +00:00
(let ((processed-params (org-babel-process-params params)))
(org-babel-reassemble-table
(eval (read (format "(progn %s)"
(org-babel-expand-body:emacs-lisp
body params processed-params))))
(org-babel-pick-name (nth 4 processed-params)
(cdr (assoc :colnames params)))
(org-babel-pick-name (nth 5 processed-params)
(cdr (assoc :rownames params)))))))
2010-06-15 00:28:09 +00:00
(provide 'ob-emacs-lisp)
;; arch-tag: e9a3acca-dc84-472a-9f5a-23c35befbcd6
;;; ob-emacs-lisp.el ends here