* A question about Sly/Slime: how do I invoke the inspector from Common Lisp?
@ 2023-01-15 2:24 Eduardo Ochs
2023-01-15 18:55 ` Jean Louis
2023-02-05 14:22 ` Madhu
0 siblings, 2 replies; 3+ messages in thread
From: Eduardo Ochs @ 2023-01-15 2:24 UTC (permalink / raw)
To: help-gnu-emacs
Hi list,
this is a question about a part of the guts of Sly/Slime that looks
very technical, but that is very close to the surface. Answers like
"it's better to ask this in the places such and such" are welcome -
I'm only asking this here because I couldn't find the places such and
such in the docs.
The standard way to learn Common Lisp is to use Emacs as its
interface, and use either Sly or Slime - I will say just "Sly" from
here onwards because it's what I'm using, but they're similar - to
make Emacs and CL talk to one another. This is explained here:
http://joaotavora.github.io/sly/#Introduction
I am working on some "executable notes" - in this sense:
http://angg.twu.net/eev-for-longtime-emacs-users.html
that would help eev users with no experience with Common Lisp to
install and test CL and Sly in just a few minutes. The initial parts
of these "executable notes" are working very well, but as far as I
know the people who like eev are a tiny subset of the people who like
to explore how things are implemented...
...but let me go straight to the point. Suppose that we have SBCL and
Sly installed, and we have a SBCL/Sly REPL running in a buffer that I
will refer to as the "mrepl". One way to open an "inspector" - see:
http://joaotavora.github.io/sly/#Inspector
is to go to the mrepl and type something like this there:
C-c I (list 2 3) RET
C-c I (macroexpand '(defstruct mypoint x y)) RET
the first `C-c I' "inspects" a small object, the second inspects a big
one.
A more low-level way to invoke the inspector is to run this in the
mrepl:
M-: (sly-inspect "(macroexpand '(defstruct mypoint x y))") RET
The buffer "*sly-events for sbcl*" holds a kind of log of the last
messages exchanged between Emacs and SBCL - or: "between Sly and
Slynk". We can inspect it with:
(switch-to-buffer "*sly-events for sbcl*")
and it gives us a good starting point for understanding the details of
how this communication happens.
My Main Question
================
When we run this in the mrepl,
M-: (sly-inspect "(list 2 3)") RET
The elisp function `sly-inspect' runs some preparations and then
sends, via Sly->Slynk->SBCL, a sexp that SBCL should execute. I am
trying to recreate that sexp, but the closest that I could get was
this:
(slynk:eval-for-inspector nil nil 'slynk:init-inspector "(list 2 3)")
but when I run that in the SBCL/Sly REPL I get this,
CL-USER> (slynk:eval-for-inspector nil nil 'slynk:init-inspector "(list 2 3)")
; Debugger entered on #<UNBOUND-VARIABLE *BUFFER-PACKAGE* {10043176C3}>
[1] CL-USER>
so there's something missing - the CL sexp above needs to invoked
inside some wrapper that sets up the correct context.
Anyone knows how to call that function in right way?
Thanks in advance!
Eduardo Ochs
http://angg.twu.net/#eev
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: A question about Sly/Slime: how do I invoke the inspector from Common Lisp?
2023-01-15 2:24 A question about Sly/Slime: how do I invoke the inspector from Common Lisp? Eduardo Ochs
@ 2023-01-15 18:55 ` Jean Louis
2023-02-05 14:22 ` Madhu
1 sibling, 0 replies; 3+ messages in thread
From: Jean Louis @ 2023-01-15 18:55 UTC (permalink / raw)
To: Eduardo Ochs; +Cc: help-gnu-emacs
At one time, Slime worked well for me. Then it gained some
instability.
Since then I simple do M-x run-lisp in lisp-mode and watch in other
window definitions.
--
Jean
Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns
In support of Richard M. Stallman
https://stallmansupport.org/
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: A question about Sly/Slime: how do I invoke the inspector from Common Lisp?
2023-01-15 2:24 A question about Sly/Slime: how do I invoke the inspector from Common Lisp? Eduardo Ochs
2023-01-15 18:55 ` Jean Louis
@ 2023-02-05 14:22 ` Madhu
1 sibling, 0 replies; 3+ messages in thread
From: Madhu @ 2023-02-05 14:22 UTC (permalink / raw)
To: help-gnu-emacs
* Eduardo Ochs <CADs++6hZUDHNTTASjtDjtPw3MayhukKNnQNeEHDeCzu0Ad_8Ng @mail.gmail.com> :
Wrote on Sat, 14 Jan 2023 23:24:21 -0300:
> When we run this in the mrepl,
>
> M-: (sly-inspect "(list 2 3)") RET
>
> The elisp function `sly-inspect' runs some preparations and then
> sends, via Sly->Slynk->SBCL, a sexp that SBCL should execute. I am
> trying to recreate that sexp, but the closest that I could get was
> this:
If you just want to call the inspector from lisp, you could do
* (slynk::eval-in-emacs '(sly-inspect "(list 2 3)"))
after doing a (setq sly-enable-evaluate-in-emacs t)
> (slynk:eval-for-inspector nil nil 'slynk:init-inspector "(list 2 3)")
[I've traced this execution path many times and I always forget the next
day and have to do it from scratch. It's involved and I don't have the
energy to document it]
> but when I run that in the SBCL/Sly REPL I get this,
>
> CL-USER> (slynk:eval-for-inspector nil nil 'slynk:init-inspector "(list 2 3)")
> ; Debugger entered on #<UNBOUND-VARIABLE *BUFFER-PACKAGE* {10043176C3}>
> [1] CL-USER>
>
> so there's something missing - the CL sexp above needs to invoked
> inside some wrapper that sets up the correct context.
> Anyone knows how to call that function in right way?
You could make it work by evaluating, on the lisp side
```
(let ((SLYNK::*BUFFER-PACKAGE* (find-package "CL-USER"))
(SLYNK::*BUFFER-READTABLE* *READTABLE*)) (slynk:eval-for-inspector nil
nil 'slynk:init-inspector "(list 2 3)"))
```
Which would print out a form (which would get sent back to emacs with
SEND-TO-EMACS) in the normal course of thing when there is an emacs
connection. Emacs would have first sent an asynchronous request with a
form with '(:emacs-rex ...) and with an ID which is handled by
SLYNK::EVAL-FOR-EMACS, which binds the buffer-package and read-table,
evaluates the form and sends results asynchronously back (to emacs with
SEND-TO-EMACS, tagging it with the same ID)
If you were only interested in the form you could also see it with, on
the lisp side with
```
(slynk::inspect-object '(2 3))
```
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-02-05 14:22 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-15 2:24 A question about Sly/Slime: how do I invoke the inspector from Common Lisp? Eduardo Ochs
2023-01-15 18:55 ` Jean Louis
2023-02-05 14:22 ` Madhu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).