* [PATCH] In case of Sly, let org-babel-execute:lisp use Slynk instead of Swank
@ 2023-03-29 8:11 gerard.vermeulen
2023-03-29 9:42 ` Ihor Radchenko
0 siblings, 1 reply; 5+ messages in thread
From: gerard.vermeulen @ 2023-03-29 8:11 UTC (permalink / raw)
To: Emacs orgmode; +Cc: dto
[-- Attachment #1: Type: text/plain, Size: 1092 bytes --]
Hello,
The Emacs integrated development environments Slime and Sly
communicate by means of similar RPC protocols with different server
programs: Swank in case of Slime and Slynk in case of Sly. However,
the code in org-babel-execute:lisp always expects to talk with Swank
because of the hard-coded call to swank:eval-and-grab-output.
After starting a Sly REPL, calls to swank:eval-and-grab-output do not
talk with the Slynk server started by the Sly REPL.
The attached patch "soft-codes" eval-and-grab-output to become
swank:eval-and-grab-output when using Slime and
slynk:eval-and-grab-output when using Sly.
For more info: steps to test the patch are:
1. Open a Sly REPL with M-x sly
2. Look in the *sly-events for <LISP>* (<LISP> is sbcl in my case) for
slynk: prefixes
3. Type C-c C-c on the test block below
4. Look for an addition in *sly-events for <LISP>* looking like
(slynk:eval-and-grab-output "(let ((...)) (+ 1 1)\n)")
#+name: test-ob-lisp-with-sly
#+begin_src lisp -n :output results
(+ 1 1)
#+end_src
#+RESULTS: test-ob-lisp-with-sly
: 2
Best regards -- Gerard
[-- Attachment #2: 0001-lisp-ob-lisp-fix-org-babel-execute-lisp-for-use-with.patch --]
[-- Type: application/octet-stream, Size: 4335 bytes --]
From 999deeebf473cc39b90ccbaac04d7fb2ea6ad6c2 Mon Sep 17 00:00:00 2001
From: Gerard Vermeulen <gerard.vermeulen@posteo.net>
Date: Wed, 29 Mar 2023 09:21:08 +0200
Subject: [PATCH] lisp/ob-lisp: fix `org-babel-execute:lisp' for use with Sly
* lisp/ob-lisp (org-babel-execute:lisp): by default, Sly and Slime
talk with different RPC server programs with different names.
Specialize the prefix of eval-and-grab-output to Slime (prefix swank:)
or to Sly (prefix slynk:).
---
lisp/ob-lisp.el | 61 ++++++++++++++++++++++++++-----------------------
1 file changed, 32 insertions(+), 29 deletions(-)
diff --git a/lisp/ob-lisp.el b/lisp/ob-lisp.el
index 03f23c82d..c45bec20e 100644
--- a/lisp/ob-lisp.el
+++ b/lisp/ob-lisp.el
@@ -90,35 +90,38 @@ current directory string."
"Execute a block of Common Lisp code with Babel.
BODY is the contents of the block, as a string. PARAMS is
a property list containing the parameters of the block."
- (pcase org-babel-lisp-eval-fn
- (`slime-eval (org-require-package 'slime "SLIME"))
- (`sly-eval (org-require-package 'sly "SLY")))
- (org-babel-reassemble-table
- (let ((result
- (funcall (if (member "output" (cdr (assq :result-params params)))
- #'car #'cadr)
- (with-temp-buffer
- (insert (org-babel-expand-body:lisp body params))
- (funcall org-babel-lisp-eval-fn
- `(swank:eval-and-grab-output
- ,(let ((dir (if (assq :dir params)
- (cdr (assq :dir params))
- default-directory)))
- (format
- (if dir (format org-babel-lisp-dir-fmt dir)
- "(progn %s\n)")
- (buffer-substring-no-properties
- (point-min) (point-max)))))
- (cdr (assq :package params)))))))
- (org-babel-result-cond (cdr (assq :result-params params))
- (org-strip-quotes result)
- (condition-case nil
- (read (org-babel-lisp-vector-to-list result))
- (error result))))
- (org-babel-pick-name (cdr (assq :colname-names params))
- (cdr (assq :colnames params)))
- (org-babel-pick-name (cdr (assq :rowname-names params))
- (cdr (assq :rownames params)))))
+ (let (eval-and-grab-output)
+ (pcase org-babel-lisp-eval-fn
+ (`slime-eval (org-require-package 'slime "SLIME")
+ (setq eval-and-grab-output 'swank:eval-and-grab-output))
+ (`sly-eval (org-require-package 'sly "SLY")
+ (setq eval-and-grab-output 'slynk:eval-and-grab-output)))
+ (org-babel-reassemble-table
+ (let ((result
+ (funcall (if (member "output" (cdr (assq :result-params params)))
+ #'car #'cadr)
+ (with-temp-buffer
+ (insert (org-babel-expand-body:lisp body params))
+ (funcall org-babel-lisp-eval-fn
+ `(,eval-and-grab-output
+ ,(let ((dir (if (assq :dir params)
+ (cdr (assq :dir params))
+ default-directory)))
+ (format
+ (if dir (format org-babel-lisp-dir-fmt dir)
+ "(progn %s\n)")
+ (buffer-substring-no-properties
+ (point-min) (point-max)))))
+ (cdr (assq :package params)))))))
+ (org-babel-result-cond (cdr (assq :result-params params))
+ (org-strip-quotes result)
+ (condition-case nil
+ (read (org-babel-lisp-vector-to-list result))
+ (error result))))
+ (org-babel-pick-name (cdr (assq :colname-names params))
+ (cdr (assq :colnames params)))
+ (org-babel-pick-name (cdr (assq :rowname-names params))
+ (cdr (assq :rownames params))))))
(defun org-babel-lisp-vector-to-list (results)
;; TODO: better would be to replace #(...) with [...]
--
2.40.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] In case of Sly, let org-babel-execute:lisp use Slynk instead of Swank
2023-03-29 8:11 [PATCH] In case of Sly, let org-babel-execute:lisp use Slynk instead of Swank gerard.vermeulen
@ 2023-03-29 9:42 ` Ihor Radchenko
2023-03-30 4:56 ` gerard.vermeulen
0 siblings, 1 reply; 5+ messages in thread
From: Ihor Radchenko @ 2023-03-29 9:42 UTC (permalink / raw)
To: gerard.vermeulen; +Cc: Emacs orgmode, dto
gerard.vermeulen@posteo.net writes:
> The Emacs integrated development environments Slime and Sly
> communicate by means of similar RPC protocols with different server
> programs: Swank in case of Slime and Slynk in case of Sly. However,
> the code in org-babel-execute:lisp always expects to talk with Swank
> because of the hard-coded call to swank:eval-and-grab-output.
>
> After starting a Sly REPL, calls to swank:eval-and-grab-output do not
> talk with the Slynk server started by the Sly REPL.
>
> The attached patch "soft-codes" eval-and-grab-output to become
> swank:eval-and-grab-output when using Slime and
> slynk:eval-and-grab-output when using Sly.
I do not use ob-lisp, but this patch looks reasonable.
I'd appreciate if other ob-lisp users could test the patch with both SLY
and SLIME.
I have no comments on the Elisp part of the patch.
--
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] In case of Sly, let org-babel-execute:lisp use Slynk instead of Swank
2023-03-29 9:42 ` Ihor Radchenko
@ 2023-03-30 4:56 ` gerard.vermeulen
2023-03-30 10:10 ` Ihor Radchenko
0 siblings, 1 reply; 5+ messages in thread
From: gerard.vermeulen @ 2023-03-30 4:56 UTC (permalink / raw)
To: Ihor Radchenko
Cc: Emacs orgmode, dto,
emacs-orgmode-bounces+gerard.vermeulen=posteo.net
On 29.03.2023 11:42, Ihor Radchenko wrote:
> gerard.vermeulen@posteo.net writes:
>
>> The Emacs integrated development environments Slime and Sly
>> communicate by means of similar RPC protocols with different server
>> programs: Swank in case of Slime and Slynk in case of Sly. However,
>> the code in org-babel-execute:lisp always expects to talk with Swank
>> because of the hard-coded call to swank:eval-and-grab-output.
>>
>> After starting a Sly REPL, calls to swank:eval-and-grab-output do not
>> talk with the Slynk server started by the Sly REPL.
>>
>> The attached patch "soft-codes" eval-and-grab-output to become
>> swank:eval-and-grab-output when using Slime and
>> slynk:eval-and-grab-output when using Sly.
>
> I do not use ob-lisp, but this patch looks reasonable.
>
> I'd appreciate if other ob-lisp users could test the patch with both
> SLY
> and SLIME.
>
> I have no comments on the Elisp part of the patch.
I have a few additional remarks:
The patch is against main only because it overlaps a region where bugfix
and main diverged. I am willing to provide a similar patch against
main.
I have installed Slime and Sly with the same user-emacs-directory using
package-install. Normally, both autoload when doing M-x sly, but Sly
prompts you whether you want to disable Slime. I choose "yes" to test
Sly. I package-delete Sly when I want to test Slime.
See https://github.com/joaotavora/sly/blob/master/CONTRIBUTING.md
describes in detail how Sly uses the RPC protocol.
I hope that my mail reaches David (CC-ed dto@gnu.org taken from the
file header), but my previous message bounced (non-existent address).
Best regards -- Gerard
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] In case of Sly, let org-babel-execute:lisp use Slynk instead of Swank
2023-03-30 4:56 ` gerard.vermeulen
@ 2023-03-30 10:10 ` Ihor Radchenko
2023-05-02 12:15 ` Ihor Radchenko
0 siblings, 1 reply; 5+ messages in thread
From: Ihor Radchenko @ 2023-03-30 10:10 UTC (permalink / raw)
To: gerard.vermeulen
Cc: Emacs orgmode, dto,
emacs-orgmode-bounces+gerard.vermeulen=posteo.net,
David O'Toole
gerard.vermeulen@posteo.net writes:
>> I'd appreciate if other ob-lisp users could test the patch with both
>> SLY
>> and SLIME.
>>
>> I have no comments on the Elisp part of the patch.
>
> I have a few additional remarks:
>
> The patch is against main only because it overlaps a region where bugfix
> and main diverged. I am willing to provide a similar patch against
> main.
I do not think that we in a hurry to put this onto bugfix.
Bugfix is just for trivial and critical fixes.
https://orgmode.org/worg/org-maintenance.html#release-types
Writing the whole extra alternative patch is probably too much to bother.
> I hope that my mail reaches David (CC-ed dto@gnu.org taken from the
> file header), but my previous message bounced (non-existent address).
I am CCing his alternative (AFAIK) email.
David, if you are still interested to deal with ob-lisp, we can update
the email.
--
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-05-02 12:13 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-29 8:11 [PATCH] In case of Sly, let org-babel-execute:lisp use Slynk instead of Swank gerard.vermeulen
2023-03-29 9:42 ` Ihor Radchenko
2023-03-30 4:56 ` gerard.vermeulen
2023-03-30 10:10 ` Ihor Radchenko
2023-05-02 12:15 ` Ihor Radchenko
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
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).