1 ;;; ob-lisp.el --- org-babel functions for common lisp evaluation
3 ;; Copyright (C) 2009-2011 Free Software Foundation, Inc.
5 ;; Author: Joel Boehland
7 ;; David T. O'Toole <dto@gnu.org>
8 ;; Keywords: literate programming, reproducible research
9 ;; Homepage: http://orgmode.org
12 ;; This file is part of GNU Emacs.
14 ;; GNU Emacs is free software: you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation, either version 3 of the License, or
17 ;; (at your option) any later version.
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
29 ;;; support for evaluating common lisp code, relies on slime for all eval
33 ;; Requires SLIME (Superior Lisp Interaction Mode for Emacs.)
34 ;; See http://common-lisp.net/project/slime/
39 (declare-function slime-eval
"ext:slime" (sexp &optional package
))
41 (defvar org-babel-tangle-lang-exts
)
42 (add-to-list 'org-babel-tangle-lang-exts
'("lisp" .
"lisp"))
44 (defvar org-babel-default-header-args
:lisp
'())
45 (defvar org-babel-header-arg-names
:lisp
'(package))
47 (defcustom org-babel-lisp-dir-fmt
48 "(let ((*default-pathname-defaults* #P%S)) %%s)"
49 "Format string used to wrap code bodies to set the current directory.
50 For example a value of \"(progn ;; %s\\n %%s)\" would ignore the
51 current directory string."
55 (defun org-babel-expand-body:lisp
(body params
)
56 "Expand BODY according to PARAMS, return the expanded body."
57 (let* ((vars (mapcar #'cdr
(org-babel-get-header params
:var
)))
58 (result-params (cdr (assoc :result-params params
)))
59 (print-level nil
) (print-length nil
)
61 (if (> (length vars
) 0)
65 (format "(%S (quote %S))" (car var
) (cdr var
)))
69 (if (or (member "code" result-params
)
70 (member "pp" result-params
))
71 (format "(pprint %s)" body
)
74 (defun org-babel-execute:lisp
(body params
)
75 "Execute a block of Common Lisp code with Babel."
77 (org-babel-reassemble-table
79 (if (member "output" (cdr (assoc :result-params params
)))
82 (read (org-bable-lisp-vector-to-list (cadr result
)))
83 (error (cadr result
)))))
85 (insert (org-babel-expand-body:lisp body params
))
86 (slime-eval `(swank:eval-and-grab-output
87 ,(let ((dir (if (assoc :dir params
)
88 (cdr (assoc :dir params
))
91 (if dir
(format org-babel-lisp-dir-fmt dir
) "(progn %s)")
92 (buffer-substring-no-properties
93 (point-min) (point-max)))))
94 (cdr (assoc :package params
)))))
95 (org-babel-pick-name (cdr (assoc :colname-names params
))
96 (cdr (assoc :colnames params
)))
97 (org-babel-pick-name (cdr (assoc :rowname-names params
))
98 (cdr (assoc :rownames params
)))))
100 (defun org-bable-lisp-vector-to-list (results)
101 ;; TODO: better would be to replace #(...) with [...]
102 (replace-regexp-in-string "#(" "(" results
))
108 ;;; ob-lisp.el ends here