From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Eric Schulte" Subject: Re: [Orgmode] [babel] some lisp/slime progress Date: Thu, 31 Mar 2011 00:37:49 -0600 Message-ID: <87sju3okw2.fsf@gmail.com> References: <4D61CC7E.7030109@ccbr.umn.edu> <4D61CDE7.3030404@ccbr.umn.edu> <8762qzq0js.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from [140.186.70.92] (port=32941 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q5BW1-00071T-G2 for Emacs-orgmode@gnu.org; Thu, 31 Mar 2011 02:37:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q5BVz-0006dU-QM for Emacs-orgmode@gnu.org; Thu, 31 Mar 2011 02:37:57 -0400 Received: from mail-px0-f179.google.com ([209.85.212.179]:36122) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q5BVz-0006cx-Hv for Emacs-orgmode@gnu.org; Thu, 31 Mar 2011 02:37:55 -0400 Received: by pxi2 with SMTP id 2so514545pxi.38 for ; Wed, 30 Mar 2011 23:37:54 -0700 (PDT) In-Reply-To: <8762qzq0js.fsf@gmail.com> (Eric Schulte's message of "Thu, 31 Mar 2011 00:14:15 -0600") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Erik Iverson Cc: Emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain This newly attached version includes some slight improvements over the previous, namely, - support for declaring the CL package in which evaluation takes place - support for the ":results output" header argument - and better handling of non-elisp-parsable results. Best -- Eric --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=ob-lisp.el Content-Transfer-Encoding: quoted-printable ;;; ob-lisp.el --- org-babel functions for common lisp evaluation ;; Copyright (C) 2009, 2010, 2011 Free Software Foundation, Inc. ;; Author: Joel Boehland, Eric Schulte ;; Keywords: literate programming, reproducible research ;; Homepage: http://orgmode.org ;; Version: 7.5 ;; This file is part of GNU Emacs. ;; GNU Emacs is free software: you can redistribute it and/or modify ;; 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, ;; 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. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs. If not, see . ;;; Commentary: ;;; support for evaluating common lisp code, relies on slime for all eval ;;; Code: (require 'ob) (declare-function slime-eval "ext:slime" (sexp &optional package)) (add-to-list 'org-babel-tangle-lang-exts '("lisp" . "lisp")) (defvar org-babel-default-header-args:lisp '()) (defvar org-babel-header-arg-names:lisp '(package)) (defun org-babel-expand-body:lisp (body params) "Expand BODY according to PARAMS, return the expanded body." (let* ((vars (mapcar #'cdr (org-babel-get-header params :var))) (result-params (cdr (assoc :result-params params))) (print-level nil) (print-length nil) (body (org-babel-trim (if (> (length vars) 0) (concat "(let (" (mapconcat (lambda (var) (format "(%S (quote %S))" (car var) (cdr var))) vars "\n ") ")\n" body ")") (format "(progn %s)" body))))) (if (or (member "code" result-params) (member "pp" result-params)) (format "(pprint %s)" body) body))) (defun org-babel-execute:lisp (body params) "Execute a block of Common Lisp code with Babel." (require 'slime) (with-temp-buffer (insert (org-babel-expand-body:lisp body params)) ((lambda (result) (if (member "output" (cdr (assoc :result-params params))) (car result) (condition-case nil (read (cadr result)) (error (cadr result))))) (slime-eval `(swank:eval-and-grab-output ,(buffer-substring-no-properties (point-min) (point-max))) (cdr (assoc :package params)))))) (provide 'ob-lisp) ;; arch-tag: 18086168-009f-4947-bbb5-3532375d851d ;;; ob-lisp.el ends here --=-=-= Content-Type: text/plain "Eric Schulte" writes: > Hi Erik, > > I've had an opportunity to return to Babel support for common lisp > recently. I just copied over the existing ob-clojure.el file to > ob-lisp.el and changed the clojure/swank specific parts. The resulting > file seems to work after some initial tests and is exceedingly simple. > > If this works for you as well, then I'd propose replacing the existing > ob-lisp.el with this new implementation. > > Please let me know what you think. > > Thanks -- Eric > > > > Erik Iverson writes: > >>> Then, things like the following work, where I assume you've already >>> started M-x slime. >>> >>> #+begin_src emacs-lisp :session >>> >>> (defvar test1 "test1 value") >>> (defvar test2 "test2 value") >>> test2 >>> >>> #+end_src >>> >>> #+results: >>> : test2 value >> >> Er, not emacs-lisp, just lisp... like the following >> >> #+begin_src lisp :session >> >> (defvar test1 "test1 value") >> (defvar test2 "test2 value") >> test2 >> >> #+end_src >> >> #+results: >> : test2 value >> >> _______________________________________________ >> Emacs-orgmode mailing list >> Please use `Reply All' to send replies to the list. >> Emacs-orgmode@gnu.org >> http://lists.gnu.org/mailman/listinfo/emacs-orgmode --=-=-=--