From: Hunter Jozwiak <hunter.t.joz@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: Connecting to an Already Running Scheme REPL with org-babel
Date: Sun, 28 Jan 2024 22:08:21 -0500 [thread overview]
Message-ID: <87r0i03kgq.fsf@gmail.com> (raw)
In-Reply-To: <87v87dm613.fsf@localhost> (Ihor Radchenko's message of "Sun, 28 Jan 2024 22:45:12 +0000")
[-- 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 --]
next prev parent reply other threads:[~2024-01-29 3:09 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87r0i03kgq.fsf@gmail.com \
--to=hunter.t.joz@gmail.com \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).