[slime-devel] Running CL code from elisp, and vice versa
Helmut Eller
heller at common-lisp.net
Mon Feb 13 16:19:36 UTC 2006
* Harald Hanche-Olsen [2006-02-13 16:13+0100] writes:
> Is there a convenient function for running bits of CL code (in the
> backend common lisp of course) from elisp?
>
> I've been playing around with slime-eval-with-transcript and
> slime-eval-async, with rather mixed success. Most commonly, I just
> get a protocol error and lose my slime connection.
>
> Am I looking in the wrong place, perhaps?
slime-eval-async is the recommended interface. E.g.
(slime-eval-async `(cl:lisp-implementation-type)
(lambda (x) (message "%S" x)))
Note that slime-eval-async is intended to write SLIME commands and is
a bit picky what you put in the expression. In particular you have to
package qualify all symbols (including CL symbols except nil and t).
If you forget the package, it's considered a read error and the
connection is terminated. By convention, the expression should look
like (SWANK:FUNCTION-NAME LITERAL ...) i.e. the arguments should only
be constants, but the convention isn't enforced (yet).
slime-eval is pretty much the same but waits for the result. slime-rex
is the low level interface for those few cases when you need some
special Emacs side error handling.
[Btw, those functions take a package argument which is only useful for
a few commands and I think it would be "cleaner" to include the
package in the SEXP instead.]
> And, while we're at it, how about the backend lisp asking emacs to run
> some elisp code? Most importantly, I want to be able to have the
> backend ask emacs to open a file, and perhaps move to a specified
> point in the file. I notice that the debugger seems able to do this,
> so surely, the functionality exist. But how accessible is it to the
> user?
swank::eval-in-emacs does that, but we use it rarely and the whole
Lisp->Emacs communication isn't very mature. E.g.
(swank::eval-in-emacs '(emacs-version))
Don't forget to set slime-enable-evaluate-in-emacs before you try it.
Helmut.
More information about the slime-devel
mailing list