emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Connecting to an Already  Running Scheme REPL with org-babel
@ 2024-01-28 22:17 Hunter Jozwiak
  2024-01-28 22:45 ` Ihor Radchenko
  0 siblings, 1 reply; 10+ messages in thread
From: Hunter Jozwiak @ 2024-01-28 22:17 UTC (permalink / raw)
  To: emacs-orgmode, hhelp-guix


[-- Attachment #1.1.1: Type: text/plain, Size: 2 bytes --]




[-- Attachment #1.1.2.1: Type: text/plain, Size: 2 bytes --]




[-- Attachment #1.1.2.2.1: Type: text/plain, Size: 317 bytes --]


Hello,

i am curious whether or not it is possible to connect Org babel to a
remotely running  scheme REPL, more specifically the Guile REPL that you
get by running something like src_shell[:exports code]{guix repl --listen=tcp:37146}

If so, what are the header arguments I need to put into place?

Thanks,

Hunter

[-- Attachment #1.1.2.2.2: Type: text/html, Size: 370 bytes --]

[-- Attachment #1.1.2.3: Type: text/html, Size: 979 bytes --]

[-- Attachment #1.1.3: Type: text/html, Size: 2446 bytes --]

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 519 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Connecting to an Already  Running Scheme REPL with org-babel
  2024-01-28 22:17 Connecting to an Already Running Scheme REPL with org-babel Hunter Jozwiak
@ 2024-01-28 22:45 ` Ihor Radchenko
  2024-01-29  3:08   ` Hunter Jozwiak
  0 siblings, 1 reply; 10+ messages in thread
From: Ihor Radchenko @ 2024-01-28 22:45 UTC (permalink / raw)
  To: Hunter Jozwiak; +Cc: emacs-orgmode, hhelp-guix

Hunter Jozwiak <hunter.t.joz@gmail.com> writes:

> i am curious whether or not it is possible to connect Org babel to a remotely running scheme REPL, more
> specifically the Guile REPL that you get by running something like guix repl --listen=tcp:37146

ob-scheme does not have such feature.
Although, it might not be hard to implement.

Check out `org-babel-scheme-get-repl' function. Now, it calls
 (geiser impl)
You would need
 (geiser-connect impl host port)
to connect to server.

Of course, you'd also need to somehow get HOST and PORT values. For
example, passing them all the way down from the header argument plist
stored in PARAMS argument of `org-babel-execute:scheme' (->
org-babel-scheme-execute-with-geiser -> org-babel-scheme-get-repl)

Patches welcome!

-- 
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] 10+ messages in thread

* Re: Connecting to an Already  Running Scheme REPL with org-babel
  2024-01-28 22:45 ` Ihor Radchenko
@ 2024-01-29  3:08   ` Hunter Jozwiak
  2024-01-29 13:19     ` Ihor Radchenko
  0 siblings, 1 reply; 10+ messages in thread
From: Hunter Jozwiak @ 2024-01-29  3:08 UTC (permalink / raw)
  To: emacs-orgmode


[-- Attachment #1.1.1: Type: text/plain, Size: 2 bytes --]




[-- Attachment #1.1.2.1: Type: text/plain, Size: 908 bytes --]

Ihor Radchenko <yantar92@posteo.net> writes:

> Hunter Jozwiak <hunter.t.joz@gmail.com> writes:
>
>> i am curious whether or not it is possible to connect Org babel to a remotely running scheme REPL, more
>> specifically the Guile REPL that you get by running something like guix repl --listen=tcp:37146
>
> ob-scheme does not have such feature.
> Although, it might not be hard to implement.
>
> Check out `org-babel-scheme-get-repl' function. Now, it calls
>  (geiser impl)
> You would need
>  (geiser-connect impl host port)
> to connect to server.
>
> Of course, you'd also need to somehow get HOST and PORT values. For
> example, passing them all the way down from the header argument plist
> stored in PARAMS argument of `org-babel-execute:scheme' (->
> org-babel-scheme-execute-with-geiser -> org-babel-scheme-get-repl)
>
> Patches welcome!

Hello,

Here is a patch that provides this functionality.


[-- Attachment #1.1.2.2: Type: text/html, Size: 1338 bytes --]

[-- Attachment #1.1.3: Type: text/html, Size: 3158 bytes --]

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: Patch for ob-scheme to allow for remote connections. --]
[-- Type: text/x-patch, Size: 4172 bytes --]

From f64f82b34a7ec6418687fb9b028dda7a80059811 Mon Sep 17 00:00:00 2001
From: Hunter Jozwiak <hunter.t.joz@gmail.com>
Date: Sun, 28 Jan 2024 21:48:05 -0500
Subject: [PATCH] org-mode: allow ob-scheme to accept a remote connection.

* lisp/org/ob-scheme.el (org-babel-scheme-get-repl): introduce two
optional variables  host  and port. If there are not given, just run
Geiser as before. In the case when  both are given, connect to the
remotely running Scheme process.
* lisp/org/ob-scheme (org-babel-scheme-execute-with-geiser,
org-babel-execute:scheme): take these  optional arguments into account.
---
 lisp/org/ob-scheme.el | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/lisp/org/ob-scheme.el b/lisp/org/ob-scheme.el
index d13b975084c..c9779185903 100644
--- a/lisp/org/ob-scheme.el
+++ b/lisp/org/ob-scheme.el
@@ -1,4 +1,4 @@
-;;; ob-scheme.el --- Babel Functions for Scheme      -*- lexical-binding: t; -*-
+;; ob-scheme.el --- Babel Functions for Scheme      -*- lexical-binding: t; -*-
 
 ;; Copyright (C) 2010-2024 Free Software Foundation, Inc.
 
@@ -54,7 +54,7 @@ geiser-debug-show-debug-p
 (defvar geiser-debug-jump-to-debug-p)  ; Defined in geiser-debug.el
 (defvar geiser-repl-use-other-window)  ; Defined in geiser-repl.el
 (defvar geiser-repl-window-allow-split)	; Defined in geiser-repl.el
-
+(declare-function geiser-connect "ext:geiser-repl" (impl &optional host port))
 (declare-function run-geiser "ext:geiser-repl" (impl))
 (declare-function geiser "ext:geiser-repl" (impl))
 (declare-function geiser-mode "ext:geiser-mode" ())
@@ -116,13 +116,17 @@ org-babel-scheme-get-buffer-impl
   (with-current-buffer (set-buffer buffer)
     geiser-impl--implementation))
 
-(defun org-babel-scheme-get-repl (impl name)
-  "Switch to a scheme REPL, creating it if it doesn't exist."
+(defun org-babel-scheme-get-repl (impl name &optional host port)
+  "Switch to a scheme REPL, creating it if it doesn't exist.
+
+If the variables host and port are set, connect to the running Scheme REPL."
   (let ((buffer (org-babel-scheme-get-session-buffer name)))
     (or buffer
 	(progn
           (if (fboundp 'geiser)
-              (geiser impl)
+              (if (and host port)
+                  (geiser-connect impl host port)
+                (geiser impl))
             ;; Obsolete since Geiser 0.26.
 	    (run-geiser impl))
 	  (when name
@@ -159,7 +163,7 @@ org-babel-scheme-capture-current-message
        ,@body
        (current-message))))
 
-(defun org-babel-scheme-execute-with-geiser (code output impl repl)
+(defun org-babel-scheme-execute-with-geiser (code output impl repl  &optional host port)
   "Execute code in specified REPL.
 If the REPL doesn't exist, create it using the given scheme
 implementation.
@@ -175,7 +179,7 @@ org-babel-scheme-execute-with-geiser
       (let ((geiser-repl-window-allow-split nil)
 	    (geiser-repl-use-other-window nil))
 	(let ((repl-buffer (save-current-buffer
-			     (org-babel-scheme-get-repl impl repl))))
+			     (org-babel-scheme-get-repl impl repl host port))))
 	  (when (not (eq impl (org-babel-scheme-get-buffer-impl
 			       (current-buffer))))
 	    (message "Implementation mismatch: %s (%s) %s (%s)" impl (symbolp impl)
@@ -231,6 +235,8 @@ org-babel-execute:scheme
 		       geiser-scheme-implementation
 		       geiser-default-implementation
 		       (car geiser-active-implementations)))
+             (host (cdr (assq :host params)))
+             (port (cdr (assq :port params)))
 	     (session (org-babel-scheme-make-session-name
 		       source-buffer-name (cdr (assq :session params)) impl))
 	     (full-body (org-babel-expand-body:scheme body params))
@@ -240,7 +246,7 @@ org-babel-execute:scheme
 	       full-body		       ; code
 	       (string= result-type "output")  ; output?
 	       impl			       ; implementation
-	       (and (not (string= session "none")) session)))) ; session
+	       (and (not (string= session "none")) session)  host port))) ; session
 	(let ((table
 	       (org-babel-reassemble-table
 		result
-- 
2.43.0


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 519 bytes --]

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: Connecting to an Already  Running Scheme REPL with org-babel
  2024-01-29  3:08   ` Hunter Jozwiak
@ 2024-01-29 13:19     ` Ihor Radchenko
  2024-01-29 17:21       ` Hunter Jozwiak
  2024-01-29 19:10       ` Hunter Jozwiak
  0 siblings, 2 replies; 10+ messages in thread
From: Ihor Radchenko @ 2024-01-29 13:19 UTC (permalink / raw)
  To: Hunter Jozwiak; +Cc: emacs-orgmode

Hunter Jozwiak <hunter.t.joz@gmail.com> writes:

>   Here is a patch that provides this functionality.

Thank you!

> Subject: [PATCH] org-mode: allow ob-scheme to accept a remote connection.
>
> * lisp/org/ob-scheme.el (org-babel-scheme-get-repl): introduce two
> optional variables  host  and port. If there are not given, just run
           ^^^^^^^^^ arguments

> * lisp/org/ob-scheme (org-babel-scheme-execute-with-geiser,
> org-babel-execute:scheme): take these  optional arguments into
> account.

... and add two new optional arguments.

> @@ -231,6 +235,8 @@ org-babel-execute:scheme
>  		       geiser-scheme-implementation
>  		       geiser-default-implementation
>  		       (car geiser-active-implementations)))
> +             (host (cdr (assq :host params)))
> +             (port (cdr (assq :port params)))

Please declare these new scheme-specific header argument in
`org-babel-header-args:scheme'.
See `org-babel-header-args:C' for an example.
This is necessary for header argument completion to work.

Also, please document the new header argument in the ob-scheme
documentation at
https://orgmode.org/worg/org-contrib/babel/languages/ob-doc-scheme.html
(you can submit a patch against
https://git.sr.ht/~bzg/worg/tree/master/item/org-contrib/babel/languages/ob-doc-scheme.org )

> -	       (and (not (string= session "none")) session)))) ; session
> +	       (and (not (string= session "none")) session)  host port))) ; session

This does not look right. Your change will disable session support
completely when host and port are not provided.

-- 
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] 10+ messages in thread

* Re: Connecting to an Already  Running Scheme REPL with org-babel
  2024-01-29 13:19     ` Ihor Radchenko
@ 2024-01-29 17:21       ` Hunter Jozwiak
  2024-01-30 11:54         ` Ihor Radchenko
  2024-01-29 19:10       ` Hunter Jozwiak
  1 sibling, 1 reply; 10+ messages in thread
From: Hunter Jozwiak @ 2024-01-29 17:21 UTC (permalink / raw)
  To: emacs-orgmode


[-- Attachment #1.1.1: Type: text/plain, Size: 2853 bytes --]

Ihor Radchenko <yantar92@posteo.net> writes:

> Hunter Jozwiak <hunter.t.joz@gmail.com> writes:
>
>>   Here is a patch that provides this functionality.
>
> Thank you!
>
>> Subject: [PATCH] org-mode: allow ob-scheme to accept a remote connection.
>>
>> * lisp/org/ob-scheme.el (org-babel-scheme-get-repl): introduce two
>> optional variables  host  and port. If there are not given, just run
>            ^^^^^^^^^ arguments
>
>> * lisp/org/ob-scheme (org-babel-scheme-execute-with-geiser,
>> org-babel-execute:scheme): take these  optional arguments into
>> account.
>
> ... and add two new optional arguments.
>
>> @@ -231,6 +235,8 @@ org-babel-execute:scheme
>>  		       geiser-scheme-implementation
>>  		       geiser-default-implementation
>>  		       (car geiser-active-implementations)))
>> +             (host (cdr (assq :host params)))
>> +             (port (cdr (assq :port params)))
>
> Please declare these new scheme-specific header argument in
> `org-babel-header-args:scheme'.
> See `org-babel-header-args:C' for an example.
> This is necessary for header argument completion to work.
>
Okay. Is there a way to tighten these inputs further? I have them set to
:any for the moment, but I wonder if there is a way to leverage the
values for `geiser-repl-default-host` and `geiser-repl-default-port`.
> Also, please document the new header argument in the ob-scheme
> documentation at
> https://orgmode.org/worg/org-contrib/babel/languages/ob-doc-scheme.html
> (you can submit a patch against
> https://git.sr.ht/~bzg/worg/tree/master/item/org-contrib/babel/languages/ob-doc-scheme.org )
>
Sure thing; I can do that after I finish this message.
>> -	       (and (not (string= session "none")) session)))) ; session
>> +	       (and (not (string= session "none")) session)  host port))) ; session
>
> This does not look right. Your change will disable session support
> completely when host and port are not provided.
Is there a way to test this and pinpoint the problem? I'm not familiar with using :sessions. Here is what I tested so far:
#+begin_example
#+begin_src scheme :scheme guile :host localhost :port 37146 :session *image*
  (use-modules (gnu)
               (guix)
               (guix gexp))
#+end_src

#+begin_src scheme :host localhost :port 37146 :session *image*
  (use-service-modules sound)
  (use-package-modules linux)
#+end_src

#+begin_src scheme :scheme guile :session *other*
  (use-srfis '(26)) 
#+end_src
#+end_example
This particular test gave me two REPLS. In the =*image*= REPL, I have access to the packages and services I would need to build part of the current project I am working on. The other REPL  gives me access to the `cut` and `cute` macros, and there isn't any plution between the two. Is there something else I'm missing here?


[-- Attachment #1.1.2: Type: text/html, Size: 4412 bytes --]

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 519 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Connecting to an Already Running Scheme REPL with org-babel
  2024-01-29 13:19     ` Ihor Radchenko
  2024-01-29 17:21       ` Hunter Jozwiak
@ 2024-01-29 19:10       ` Hunter Jozwiak
  2024-01-30 15:47         ` Ihor Radchenko
  1 sibling, 1 reply; 10+ messages in thread
From: Hunter Jozwiak @ 2024-01-29 19:10 UTC (permalink / raw)
  To: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 2079 bytes --]

On Mon, Jan 29, 2024 at 8:15 AM Ihor Radchenko <yantar92@posteo.net> wrote:

> Hunter Jozwiak <hunter.t.joz@gmail.com> writes:
>
> >   Here is a patch that provides this functionality.
>
> Thank you!
>
> > Subject: [PATCH] org-mode: allow ob-scheme to accept a remote connection.
> >
> > * lisp/org/ob-scheme.el (org-babel-scheme-get-repl): introduce two
> > optional variables  host  and port. If there are not given, just run
>            ^^^^^^^^^ arguments
>
> > * lisp/org/ob-scheme (org-babel-scheme-execute-with-geiser,
> > org-babel-execute:scheme): take these  optional arguments into
> > account.
>
> ... and add two new optional arguments.
>
> > @@ -231,6 +235,8 @@ org-babel-execute:scheme
> >                      geiser-scheme-implementation
> >                      geiser-default-implementation
> >                      (car geiser-active-implementations)))
> > +             (host (cdr (assq :host params)))
> > +             (port (cdr (assq :port params)))
>
> Please declare these new scheme-specific header argument in
> `org-babel-header-args:scheme'.
> See `org-babel-header-args:C' for an example.
> This is necessary for header argument completion to work.
>
> Also, please document the new header argument in the ob-scheme
> documentation at
> https://orgmode.org/worg/org-contrib/babel/languages/ob-doc-scheme.html
> (you can submit a patch against
>
> https://git.sr.ht/~bzg/worg/tree/master/item/org-contrib/babel/languages/ob-doc-scheme.org
> )
> Here is the worg patch.
> > -            (and (not (string= session "none")) session)))) ; session
> > +            (and (not (string= session "none")) session)  host port)))
> ; session
>
> This does not look right. Your change will disable session support
> completely when host and port are not provided.
>
> --
> 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>
>

[-- Attachment #1.2: Type: text/html, Size: 3231 bytes --]

[-- Attachment #2: 0001-ob-scheme-document-the-new-header-arguments.patch --]
[-- Type: text/x-patch, Size: 1114 bytes --]

From 2dc78a7edbbe38614a5f7fafa2c295f52528f04d Mon Sep 17 00:00:00 2001
From: Hunter Jozwiak <hunter.t.joz@gmail.com>
Date: Mon, 29 Jan 2024 12:48:41 -0500
Subject: [PATCH] ob-scheme: document  the new header arguments.

* org-contrib/babel/languages/ob-doc-scheme.org (header-arguments):
note the  new options :host and :port.
---
 org-contrib/babel/languages/ob-doc-scheme.org | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/org-contrib/babel/languages/ob-doc-scheme.org b/org-contrib/babel/languages/ob-doc-scheme.org
index 46315d82..8f7ef52a 100644
--- a/org-contrib/babel/languages/ob-doc-scheme.org
+++ b/org-contrib/babel/languages/ob-doc-scheme.org
@@ -71,7 +71,9 @@ pair to =org-babel-load-languages=:
 There are no language-specific default values for header arguments to
 Scheme code blocks.
 
-There are no language-specific header arguments for Scheme code blocks.
+The following two options are available for Scheme code blocks:
+- :host :: the host of a remotely running Scheme process.
+- :port :: the port of the remotely running Scheme process.
 
 ** Sessions
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: Connecting to an Already  Running Scheme REPL with org-babel
  2024-01-29 17:21       ` Hunter Jozwiak
@ 2024-01-30 11:54         ` Ihor Radchenko
  2024-01-30 15:18           ` Hunter Jozwiak
  0 siblings, 1 reply; 10+ messages in thread
From: Ihor Radchenko @ 2024-01-30 11:54 UTC (permalink / raw)
  To: Hunter Jozwiak; +Cc: emacs-orgmode

Hunter Jozwiak <hunter.t.joz@gmail.com> writes:

>>> +             (host (cdr (assq :host params)))
>>> +             (port (cdr (assq :port params)))
>>
>> Please declare these new scheme-specific header argument in
>> `org-babel-header-args:scheme'.
>> See `org-babel-header-args:C' for an example.
>> This is necessary for header argument completion to work.

> Okay. Is there a way to tighten these inputs further? I have them set to
> :any for the moment, but I wonder if there is a way to leverage the
> values for `geiser-repl-default-host` and `geiser-repl-default-port`.

Org-mode currently does not provide completion for header argument
values. (see `pcomplete/org-mode/block-option/src')

If Org were to support such completion, you could theoretically allow
special values for :host/:port like default:

#+begin_src scheme :host default :port default
...
#+end_src

to use `geiser-repl-default-host'/`...-port'.

Then, you could add these values as (default :any).

>>> -	       (and (not (string= session "none")) session)))) ; session
>>> +	       (and (not (string= session "none")) session)  host port))) ; session
>>
>> This does not look right. Your change will disable session support
>> completely when host and port are not provided.
> Is there a way to test this and pinpoint the problem?

Hmm. I just realized that I am reading that line wrongly - host and port
are additional arguments passed to
`org-babel-scheme-execute-with-geiser', not a part of
(and (not ...) host port)

So, my only comment remaining is to put each argument in its own line,
like it is done for all the previous arguments:

(org-babel-scheme-execute-with-geiser
	       full-body		       ; code
	       (string= result-type "output")  ; output?
	       impl			       ; implementation
	       (and (not (string= session "none")) session) ; session
               host ; repl host name
               port) ; repl port

That will make the code more readable.

-- 
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] 10+ messages in thread

* Re: Connecting to an Already  Running Scheme REPL with org-babel
  2024-01-30 11:54         ` Ihor Radchenko
@ 2024-01-30 15:18           ` Hunter Jozwiak
  2024-01-30 15:46             ` Ihor Radchenko
  0 siblings, 1 reply; 10+ messages in thread
From: Hunter Jozwiak @ 2024-01-30 15:18 UTC (permalink / raw)
  To: emacs-orgmode


[-- Attachment #1.1.1: Type: text/plain, Size: 2105 bytes --]

Ihor Radchenko <yantar92@posteo.net> writes:

> Hunter Jozwiak <hunter.t.joz@gmail.com> writes:
>
>>>> +             (host (cdr (assq :host params)))
>>>> +             (port (cdr (assq :port params)))
>>>
>>> Please declare these new scheme-specific header argument in
>>> `org-babel-header-args:scheme'.
>>> See `org-babel-header-args:C' for an example.
>>> This is necessary for header argument completion to work.
>
>> Okay. Is there a way to tighten these inputs further? I have them set to
>> :any for the moment, but I wonder if there is a way to leverage the
>> values for `geiser-repl-default-host` and `geiser-repl-default-port`.
>
> Org-mode currently does not provide completion for header argument
> values. (see `pcomplete/org-mode/block-option/src')
>
> If Org were to support such completion, you could theoretically allow
> special values for :host/:port like default:
>
> #+begin_src scheme :host default :port default
> ...
> #+end_src
>
> to use `geiser-repl-default-host'/`...-port'.
>
> Then, you could add these values as (default :any).
>
>>>> -	       (and (not (string= session "none")) session)))) ; session
>>>> +	       (and (not (string= session "none")) session)  host port))) ; session
>>>
>>> This does not look right. Your change will disable session support
>>> completely when host and port are not provided.
>> Is there a way to test this and pinpoint the problem?
>
> Hmm. I just realized that I am reading that line wrongly - host and port
> are additional arguments passed to
> `org-babel-scheme-execute-with-geiser', not a part of
> (and (not ...) host port)
>
> So, my only comment remaining is to put each argument in its own line,
> like it is done for all the previous arguments:
>
> (org-babel-scheme-execute-with-geiser
> 	       full-body		       ; code
> 	       (string= result-type "output")  ; output?
> 	       impl			       ; implementation
> 	       (and (not (string= session "none")) session) ; session
>                host ; repl host name
>                port) ; repl port
>
> That will make the code more readable.

Here is an updated patch.


[-- Attachment #1.1.2: Type: text/html, Size: 3454 bytes --]

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: Updated patch. --]
[-- Type: text/x-patch, Size: 4764 bytes --]

From ff82afda9b862a7899abf10b7d1a4cde3c1d5314 Mon Sep 17 00:00:00 2001
From: Hunter Jozwiak <hunter.t.joz@gmail.com>
Date: Sun, 28 Jan 2024 21:48:05 -0500
Subject: [PATCH] org-mode: allow ob-scheme to accept a remote connection.

* lisp/org/ob-scheme.el (org-babel-scheme-get-repl): introduce two
optional variables  host  and port. If there are not given, just run
Geiser as before. In the case when  both are given, connect to the
remotely running Scheme process.
* lisp/org/ob-scheme (org-babel-scheme-execute-with-geiser,
org-babel-execute:scheme): take these  optional arguments into account.
* lisp/org/ob-scheme.el (org-babel-header-args:scheme): define host
and port for completion.
---
 lisp/org/ob-scheme.el | 27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/lisp/org/ob-scheme.el b/lisp/org/ob-scheme.el
index d13b975084c..4a214b222eb 100644
--- a/lisp/org/ob-scheme.el
+++ b/lisp/org/ob-scheme.el
@@ -1,4 +1,4 @@
-;;; ob-scheme.el --- Babel Functions for Scheme      -*- lexical-binding: t; -*-
+;; ob-scheme.el --- Babel Functions for Scheme      -*- lexical-binding: t; -*-
 
 ;; Copyright (C) 2010-2024 Free Software Foundation, Inc.
 
@@ -54,7 +54,7 @@ geiser-debug-show-debug-p
 (defvar geiser-debug-jump-to-debug-p)  ; Defined in geiser-debug.el
 (defvar geiser-repl-use-other-window)  ; Defined in geiser-repl.el
 (defvar geiser-repl-window-allow-split)	; Defined in geiser-repl.el
-
+(declare-function geiser-connect "ext:geiser-repl" (impl &optional host port))
 (declare-function run-geiser "ext:geiser-repl" (impl))
 (declare-function geiser "ext:geiser-repl" (impl))
 (declare-function geiser-mode "ext:geiser-mode" ())
@@ -75,6 +75,9 @@ org-babel-scheme-null-to
 
 (defvar org-babel-default-header-args:scheme '()
   "Default header arguments for scheme code blocks.")
+(defconst org-babel-header-args:scheme '((host . :any)
+                                         (port . :any))
+  "Header arguments supported in  Scheme.")
 
 (defun org-babel-expand-body:scheme (body params)
   "Expand BODY according to PARAMS, return the expanded body."
@@ -116,13 +119,17 @@ org-babel-scheme-get-buffer-impl
   (with-current-buffer (set-buffer buffer)
     geiser-impl--implementation))
 
-(defun org-babel-scheme-get-repl (impl name)
-  "Switch to a scheme REPL, creating it if it doesn't exist."
+(defun org-babel-scheme-get-repl (impl name &optional host port)
+  "Switch to a scheme REPL, creating it if it doesn't exist.
+
+If the variables host and port are set, connect to the running Scheme REPL."
   (let ((buffer (org-babel-scheme-get-session-buffer name)))
     (or buffer
 	(progn
           (if (fboundp 'geiser)
-              (geiser impl)
+              (if (and host port)
+                  (geiser-connect impl host port)
+                (geiser impl))
             ;; Obsolete since Geiser 0.26.
 	    (run-geiser impl))
 	  (when name
@@ -159,7 +166,7 @@ org-babel-scheme-capture-current-message
        ,@body
        (current-message))))
 
-(defun org-babel-scheme-execute-with-geiser (code output impl repl)
+(defun org-babel-scheme-execute-with-geiser (code output impl repl  &optional host port)
   "Execute code in specified REPL.
 If the REPL doesn't exist, create it using the given scheme
 implementation.
@@ -175,7 +182,7 @@ org-babel-scheme-execute-with-geiser
       (let ((geiser-repl-window-allow-split nil)
 	    (geiser-repl-use-other-window nil))
 	(let ((repl-buffer (save-current-buffer
-			     (org-babel-scheme-get-repl impl repl))))
+			     (org-babel-scheme-get-repl impl repl host port))))
 	  (when (not (eq impl (org-babel-scheme-get-buffer-impl
 			       (current-buffer))))
 	    (message "Implementation mismatch: %s (%s) %s (%s)" impl (symbolp impl)
@@ -231,6 +238,8 @@ org-babel-execute:scheme
 		       geiser-scheme-implementation
 		       geiser-default-implementation
 		       (car geiser-active-implementations)))
+             (host (cdr (assq :host params)))
+             (port (cdr (assq :port params)))
 	     (session (org-babel-scheme-make-session-name
 		       source-buffer-name (cdr (assq :session params)) impl))
 	     (full-body (org-babel-expand-body:scheme body params))
@@ -240,7 +249,9 @@ org-babel-execute:scheme
 	       full-body		       ; code
 	       (string= result-type "output")  ; output?
 	       impl			       ; implementation
-	       (and (not (string= session "none")) session)))) ; session
+	       (and (not (string= session "none")) session) ; session
+               host ; REPL host
+               port))) ; REPL port
 	(let ((table
 	       (org-babel-reassemble-table
 		result
-- 
2.43.0


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 519 bytes --]

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: Connecting to an Already  Running Scheme REPL with org-babel
  2024-01-30 15:18           ` Hunter Jozwiak
@ 2024-01-30 15:46             ` Ihor Radchenko
  0 siblings, 0 replies; 10+ messages in thread
From: Ihor Radchenko @ 2024-01-30 15:46 UTC (permalink / raw)
  To: Hunter Jozwiak; +Cc: emacs-orgmode

Hunter Jozwiak <hunter.t.joz@gmail.com> writes:

> Here is an updated patch.

Applied, onto main, with minor amendments and adding TINYCHANGE cookie
(you don't seem to have copyright assignment; see
https://orgmode.org/worg/org-contribute.html#first-patch).

https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=86c4038da

Thanks for your contribution!
You are now listed as one of Org mode contributors:
https://git.sr.ht/~bzg/worg/commit/07c4796e

-- 
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] 10+ messages in thread

* Re: Connecting to an Already Running Scheme REPL with org-babel
  2024-01-29 19:10       ` Hunter Jozwiak
@ 2024-01-30 15:47         ` Ihor Radchenko
  0 siblings, 0 replies; 10+ messages in thread
From: Ihor Radchenko @ 2024-01-30 15:47 UTC (permalink / raw)
  To: Hunter Jozwiak; +Cc: emacs-orgmode

Hunter Jozwiak <hunter.t.joz@gmail.com> writes:

> From 2dc78a7edbbe38614a5f7fafa2c295f52528f04d Mon Sep 17 00:00:00 2001
> From: Hunter Jozwiak <hunter.t.joz@gmail.com>
> Date: Mon, 29 Jan 2024 12:48:41 -0500
> Subject: [PATCH] ob-scheme: document  the new header arguments.
>
> * org-contrib/babel/languages/ob-doc-scheme.org (header-arguments):
> note the  new options :host and :port.
> ---
>  org-contrib/babel/languages/ob-doc-scheme.org | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)

Applied.
https://git.sr.ht/~bzg/worg/commit/8b7824b4

-- 
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] 10+ messages in thread

end of thread, other threads:[~2024-01-30 15:44 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-28 22:17 Connecting to an Already Running Scheme REPL with org-babel Hunter Jozwiak
2024-01-28 22:45 ` Ihor Radchenko
2024-01-29  3:08   ` Hunter Jozwiak
2024-01-29 13:19     ` Ihor Radchenko
2024-01-29 17:21       ` Hunter Jozwiak
2024-01-30 11:54         ` Ihor Radchenko
2024-01-30 15:18           ` Hunter Jozwiak
2024-01-30 15:46             ` Ihor Radchenko
2024-01-29 19:10       ` Hunter Jozwiak
2024-01-30 15:47         ` 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).