如何在Emacs Lisp中使用Slime运行Common Lisp代码 [英] How to run Common Lisp code with Slime in Emacs Lisp

查看:336
本文介绍了如何在Emacs Lisp中使用Slime运行Common Lisp代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因为某些原因,我写了一些Common Lisp代码来做我想要的。而且我使用的是QuickLisp和Slime。现在我希望与Emacs Lisp集成。



我试图使用

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

在我的el文件,但它不工作。



我只是运行Common Lisp代码并捕获返回值,就是所有。
那么我应该怎么做?

解决方案

如果我理解正确,你想采用Common Lisp代码一个Elisp字符串,
在SLIME中评估它,并将输出作为Elisp字符串加上副作用。



您可以使用此设置代码: / p>

 (require'slime)
(defun lispy - eval-lisp(str)
Eval STR作为Common Lisp代码
(unless(slime-current-connection)
(let((wnd(current-window-configuration)))

(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))) )

或者只是(需要'le-lisp)如果您已经安装了 lispy 包从MELPA或
github



以下是 * 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)))


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)))"

这篇关于如何在Emacs Lisp中使用Slime运行Common Lisp代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆