3

For some reason I wrote some Common Lisp code to do what I want. And I use the QuickLisp and the Slime. Now I hope to integrate with the Emacs Lisp.

I tried to use

(slime)
(slime-eval-region start end)
...

in my el file but it doesn't work.

I just to run the Common Lisp code and catch the return value , that is all. So what should I do?

1 Answer 1

5

If I understood you correctly, you want to take a Common Lisp code as an Elisp string, eval it within SLIME and obtain the output as an Elisp string plus side-effects.

You can do this with this setup code:

(require 'slime)
(defun lispy--eval-lisp (str)
  "Eval STR as Common Lisp code."
  (unless (slime-current-connection)
    (let ((wnd (current-window-configuration)))
      (slime)
      (while (not (and (slime-current-connection)
                       (get-buffer-window (slime-output-buffer))))
        (sit-for 0.2))
      (set-window-configuration wnd)))
  (let (deactivate-mark)
    (cadr (slime-eval `(swank:eval-and-grab-output ,str)))))

or alternatively just (require 'le-lisp) if you have installed lispy package from MELPA or github.

Here's a sample usage in *scratch*:

(lispy--eval-lisp "(load \"~/quicklisp/setup\")")
;; "T"

(lispy--eval-lisp "(ql:quickload 'png)")
;; "(PNG)"

(lispy--eval-lisp "(png:make-image 5 5 1)")
;; "#3A(((0) (0) (0) (0) (0))
;;     ((0) (0) (0) (0) (0))
;;     ((0) (0) (0) (0) (0))
;;     ((0) (0) (0) (0) (0))
;;     ((0) (0) (0) (0) (0)))"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.