如何在Emacs Lisp中使用Slime运行Common Lisp代码 [英] How to run Common Lisp code with Slime in 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屋!