emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Connecting to an Already Running Scheme REPL with org-babel


From: Hunter Jozwiak
Subject: Re: Connecting to an Already Running Scheme REPL with org-babel
Date: Sun, 28 Jan 2024 22:08:21 -0500
User-agent: Gnus/5.13 (Gnus v5.13)

<#multipart type=alternative> <#part type=text/plain> 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.

<#part type=text/html> <p> Ihor Radchenko &lt;yantar92@posteo.net&gt; writes: </p>

<p> <blockquote class="gmailquote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div>Hunter Jozwiak &lt;hunter.t.joz@gmail.com&gt; writes: </div> <div> <br /></div> <div><blockquote class="gmailquote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div>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 &#x2013;listen=tcp:37146

</div></blockquote> </div> <div> <br /></div> <div>ob-scheme does not have such feature. Although, it might not be hard to implement. </div> <div> <br /></div> <div>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. </div> <div> <br /></div> <div>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' (-&gt; org-babel-scheme-execute-with-geiser -&gt; org-babel-scheme-get-repl) </div> <div> <br /></div> <div>Patches welcome!

</div></blockquote> </p>

<p> Hello, </p>

<p> Here is a patch that provides this functionality. </p> <#/multipart>

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: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]