Вопрос

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?

Это было полезно?

Решение

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)))"
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top