From 30eec5a63e4f720fa3880b9aef06aedd84072078 Mon Sep 17 00:00:00 2001 From: stardiviner Date: Sat, 2 Apr 2016 00:46:36 +0800 Subject: [PATCH] add SLY support in ob-lisp * ob-lisp.el (org-babel-execute:lisp): Support using SLY to evaluate lisp src block. SLY has some advantages over SLIME, let user can evaluate Lisp src block with SLY. modified from a patch proposal by stardiviner. TINYCHANGE --- etc/ORG-NEWS | 2 ++ lisp/ob-lisp.el | 51 ++++++++++++++++++++++++++++++++------------------- 2 files changed, 34 insertions(+), 19 deletions(-) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 3ddc3f9..bb8a00d 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -819,6 +819,8 @@ See the docstring of ~org-latex-classes~ and *** `org-insert-heading' can be forced to insert top-level headline +*** let ob-lisp supporting use SLY to evaluate + ** Removed functions *** Removed function ~org-translate-time~ diff --git a/lisp/ob-lisp.el b/lisp/ob-lisp.el index 64b032d..68ea5e2 100644 --- a/lisp/ob-lisp.el +++ b/lisp/ob-lisp.el @@ -25,16 +25,26 @@ ;;; Commentary: -;;; support for evaluating common lisp code, relies on slime for all eval +;;; Support for evaluating Common Lisp code, relies on SLY or SLIME for all eval. ;;; Requirements: -;; Requires SLIME (Superior Lisp Interaction Mode for Emacs.) -;; See http://common-lisp.net/project/slime/ +;; Requires SLY (Sylvester the Cat's Common Lisp IDE) or SLIME. +;; See: +;; - https://github.com/capitaomorte/sly +;; - http://common-lisp.net/project/slime/ ;;; Code: (require 'ob) +(defcustom org-babel-lisp-eval-fn "sly-eval" + "The function to be called to evaluate code on the Lisp side." + :group 'org-babel + :version "24.1" + :options '("sly-eval" "slime-eval") + :type 'stringp) + +(declare-function sly-eval "ext:sly" (sexp &optional package)) (declare-function slime-eval "ext:slime" (sexp &optional package)) (defvar org-babel-tangle-lang-exts) @@ -72,24 +82,27 @@ current directory string." body))) (defun org-babel-execute:lisp (body params) - "Execute a block of Common Lisp code with Babel." - (require 'slime) + "Execute a block `BODY' with `PARAMS' of Common Lisp code with Babel." + (pcase org-babel-lisp-eval-fn + ("slime-eval" (require 'slime)) + ("sly-eval" (require 'sly))) (org-babel-reassemble-table (let ((result - (funcall (if (member "output" (cdr (assoc :result-params params))) - #'car #'cadr) - (with-temp-buffer - (insert (org-babel-expand-body:lisp body params)) - (slime-eval `(swank:eval-and-grab-output - ,(let ((dir (if (assoc :dir params) - (cdr (assoc :dir params)) - default-directory))) - (format - (if dir (format org-babel-lisp-dir-fmt dir) - "(progn %s\n)") - (buffer-substring-no-properties - (point-min) (point-max))))) - (cdr (assoc :package params))))))) + (funcall (if (member "output" (cdr (assoc :result-params params))) + #'car #'cadr) + (with-temp-buffer + (insert (org-babel-expand-body:lisp body params)) + (funcall org-babel-lisp-eval-fn + `(swank:eval-and-grab-output + ,(let ((dir (if (assoc :dir params) + (cdr (assoc :dir params)) + default-directory))) + (format + (if dir (format org-babel-lisp-dir-fmt dir) + "(progn %s\n)") + (buffer-substring-no-properties + (point-min) (point-max))))) + (cdr (assoc :package params))))))) (org-babel-result-cond (cdr (assoc :result-params params)) result (condition-case nil -- 2.8.0