emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
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: Tue, 30 Jan 2024 10:18:43 -0500	[thread overview]
Message-ID: <87v87akfxo.fsf@gmail.com> (raw)
In-Reply-To: <87v87b829j.fsf@localhost> (Ihor Radchenko's message of "Tue, 30 Jan 2024 11:54:48 +0000")


[-- 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 --]

  reply	other threads:[~2024-01-30 15:20 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
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 [this message]
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=87v87akfxo.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).