From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id eN7RDjZh/mFdsQAAgWs5BA (envelope-from ) for ; Sat, 05 Feb 2022 12:36:22 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id gAMqDDZh/mHpXAAA9RJhRA (envelope-from ) for ; Sat, 05 Feb 2022 12:36:22 +0100 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id A9D3C2B7FE for ; Sat, 5 Feb 2022 12:36:21 +0100 (CET) Received: from localhost ([::1]:39678 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nGJMa-0007xl-Qw for larch@yhetil.org; Sat, 05 Feb 2022 06:36:20 -0500 Received: from eggs.gnu.org ([209.51.188.92]:54260) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nGJKa-0007xc-2d for emacs-orgmode@gnu.org; Sat, 05 Feb 2022 06:34:16 -0500 Received: from [2607:f8b0:4864:20::1033] (port=56159 helo=mail-pj1-x1033.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nGJKU-0003oV-Rr for emacs-orgmode@gnu.org; Sat, 05 Feb 2022 06:34:13 -0500 Received: by mail-pj1-x1033.google.com with SMTP id om8so217804pjb.5 for ; Sat, 05 Feb 2022 03:34:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:in-reply-to:references:date:message-id :mime-version; bh=Qnt/kCZHUGBHSCi5x+4pvWT/yA/tW3Xt7wEGe29TPjg=; b=QDw1qTdQ2d7x8mtZfEsSWX/P34pOH6K8g3ijRoChe5U1UsMAI3YdXc+m239/0gW/su oZ57KCy1z91TgTwWOcXzyoUafeIjFHjy6q+ZtITJ/uiNc5VeBwr9rFOwUPKv8M3S4n+s lsDgQNmhHbVENJBFFnR41uB+MVbevO2z7/XsWZFvyjKFN6T4mPZwNiMFfscWm+ZPBQiy Rk7ZmgHywnzzJ4S4BeoYPWmQXI/4Kp4J3ADwjGbhYH6F0wYSxZqBIDU0P9Rg33p6Timq Hm0NYizCBsZDYARCSxN9EmmMAI/4zEleNqCxCs9Zx/6N6H7Kv/LNvt7eqRAfEkL41Zi0 URxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=Qnt/kCZHUGBHSCi5x+4pvWT/yA/tW3Xt7wEGe29TPjg=; b=1LLSgsFXQ+K5gpCyRpGYF4Me5s/xJi+4QFJNtI5bnLkctSmirXaZQzM+AYC/BhtZTV 2I3+tB2zvodMOaiyx0kamP6rV8IbEAQIkLcYb6nxLhjExtP9afo2qqhBkPbYUsaIK/ct Eim+HSFV9pOJHNNC5epi2dozmEEFwyg9aRqHMT8WNwGk7gSV/z8zEEokRFiUxArrQRX0 Qw5jXkEVO3Xy8J07ns+HZpnHsdoL+UUJhRW0u0zXxxT9eO/qVKbbMUG6jXN1rb2o1LGh wZUUg82fVsXP6PYrQ6a6zlF7WrumMDis+ATkgAPfOe7o0DoZCLD+gY9Nl3A/w3DkXwNR /RKw== X-Gm-Message-State: AOAM532Q0YgyWE013gqFtypyzoUmnhpp90x+c15I/1bQpCy56sSuKi0/ AkRk0cPyFWF87wGRiyUfiWI= X-Google-Smtp-Source: ABdhPJzvwU5mowl4jhYNK02PqfHjj6/Nj+U3dMbH81gQvh/z8aBwulXyc0ppw/QJKTvDnlBBw9nCoA== X-Received: by 2002:a17:90a:ec0b:: with SMTP id l11mr8175495pjy.200.1644060849608; Sat, 05 Feb 2022 03:34:09 -0800 (PST) Received: from localhost ([103.125.234.210]) by smtp.gmail.com with ESMTPSA id q13sm5704547pfj.44.2022.02.05.03.34.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Feb 2022 03:34:08 -0800 (PST) From: Ihor Radchenko To: Bob Heffernan Subject: Re: Problem with org-babel and geiser In-Reply-To: <20220204150905.predc2uycuwo4yty@bob-nuc> References: <20220203170122.vxjavtebsbsxdeja@bob-mtu> <87r18jktfe.fsf@localhost> <20220204150905.predc2uycuwo4yty@bob-nuc> Date: Sat, 05 Feb 2022 19:39:16 +0800 Message-ID: <87o83l5yqj.fsf@localhost> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::1033 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::1033; envelope-from=yantar92@gmail.com; helo=mail-pj1-x1033.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: emacs-orgmode@gnu.org Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1644060981; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=Qnt/kCZHUGBHSCi5x+4pvWT/yA/tW3Xt7wEGe29TPjg=; b=qTwJQ+rweA9LjyHDSpK1X9B+U11W23qB9Tp+2HvaRu62vaCWblddLjEBliliPNnzNvcjRn DC8yyy5ljh+17BD21ARQoe162OhSfzSCS0Dn705XOOYdjMMJZR6WuFisJ5d6pUVB/gmTkf 9sBEj5TAuAuo76WyEZL1DlzTdYWBQPvbUEmVoDJM83CsIILEdbEEZ2Sd/234RR5N7Gcndx a/9gHOF/su5aRBZOyK+VsceFxkP1Mez9TOZ19vmxr9Zg21WsT3pY9/nrgRjJqfo5fUAeWd eQ3njFHQWr2ie5Rz4lf/1zSTNB0V7gkjT8QTfOrTd2pnLMTcNPXhTEeal190ug== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1644060981; a=rsa-sha256; cv=none; b=c/4Qn/ZK8i0m435yZHyufQFJ1aenmx1di76c460U02XjhcJIQvC4RaMDUoNpwHhY9dst1o 2C+yDc4hT9DOKFcQWPlXRCIUi8Uh/5bvWE6Ti07oqQP4vT5dSuaMNFhhHH4Gfz65V5Vbx4 tDuIXkywoP8FoWJQPeqfnaZ9U9A5CnEEEVxUYNWDqTHeZMtqbrSeR5d6Hbp9fZMvlicygM bap9/BlAa9qKfJXchKM1MGrngfT/GKbQ9iaWXxhFvnWK2TAp+KuusqyrFwfsU+yioNdZGw FpEEaWeiCtyOhTc7ovXqrzm5lFfojn8jbPB9YJQkbRsm47oGp2JAFqLSWFyUfw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=QDw1qTdQ; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -3.83 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=QDw1qTdQ; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: A9D3C2B7FE X-Spam-Score: -3.83 X-Migadu-Scanner: scn1.migadu.com X-TUID: tGyL9W6dLxtm --=-=-= Content-Type: text/plain Bob Heffernan writes: > Thank you for your response. > The patch you linked does seem to be intended to fix this issue. > > However, I have no experience with applying a patch (to Emacs or anything else). > On my system, ob-scheme.el.gz can be found at > /usr/share/emacs/27.2/lisp/org > can I uncompress the file, patch that, then compress again? > > Or, would I need to download the Emacs source, apply the patch and then recompile? It's not a good idea to modify Org packaged together with Emacs. For testing, you can just use the attached version of ob-scheme.el. Load your Emacs and Org mode, open the attached ob-scheme.el, and run M-x eval-buffer. That should be sufficient to test the proposed patch on your side. If the patch solves the problem you are experiencing, let us know. I will then apply the proposed patch upstream. Note that even if I apply the patch, it will only be available on the latest version of Org mode (Org 9.5.2). It is _not_ what is shipped together with your Emacs. You will need to upgrade your Org mode using M-x package-install. See https://orgmode.org/manual/Installation.html#Installation for details. Best, Ihor --=-=-= Content-Type: text/plain Content-Disposition: inline; filename=ob-scheme.el ;;; ob-scheme.el --- Babel Functions for Scheme -*- lexical-binding: t; -*- ;; Copyright (C) 2010-2022 Free Software Foundation, Inc. ;; Authors: Eric Schulte ;; Michael Gauland ;; Keywords: literate programming, reproducible research, scheme ;; Homepage: https://orgmode.org ;; This file is part of GNU Emacs. ;; GNU Emacs is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs. If not, see . ;;; Commentary: ;; Now working with SBCL for both session and external evaluation. ;; ;; This certainly isn't optimally robust, but it seems to be working ;; for the basic use cases. ;;; Requirements: ;; - a working scheme implementation ;; (e.g. guile https://www.gnu.org/software/guile/guile.html) ;; ;; - for session based evaluation geiser is required, which is available from ;; ELPA. ;;; Code: (require 'ob) (require 'geiser nil t) (require 'geiser-impl nil t) (defvar geiser-repl--repl) ; Defined in geiser-repl.el (defvar geiser-impl--implementation) ; Defined in geiser-impl.el (defvar geiser-scheme-implementation) ; Defined in geiser-impl.el (defvar geiser-default-implementation) ; Defined in geiser-impl.el (defvar geiser-active-implementations) ; Defined in geiser-impl.el (defvar geiser-debug-show-debug-p) ; Defined in geiser-debug.el (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 run-geiser "ext:geiser-repl" (impl)) (declare-function geiser-mode "ext:geiser-mode" ()) (declare-function geiser-eval-region "ext:geiser-mode" (start end &optional and-go raw nomsg)) (declare-function geiser-repl-exit "ext:geiser-repl" (&optional arg)) (declare-function geiser-eval--retort-output "ext:geiser-eval" (ret)) (declare-function geiser-eval--retort-result-str "ext:geiser-eval" (ret prefix)) (defcustom org-babel-scheme-null-to 'hline "Replace `null' and empty lists in scheme tables with this before returning." :group 'org-babel :version "26.1" :package-version '(Org . "9.1") :type 'symbol) (defvar org-babel-default-header-args:scheme '() "Default header arguments for scheme code blocks.") (defun org-babel-expand-body:scheme (body params) "Expand BODY according to PARAMS, return the expanded body." (let ((vars (org-babel--get-vars params)) (prepends (cdr (assq :prologue params))) (postpends (cdr (assq :epilogue params)))) (concat (and prepends (concat prepends "\n")) (if (null vars) body (format "(let (%s)\n%s\n)" (mapconcat (lambda (var) (format "%S" (print `(,(car var) ',(cdr var))))) vars "\n ") body)) (and postpends (concat "\n" postpends))))) (defvar org-babel-scheme-repl-map (make-hash-table :test #'equal) "Map of scheme sessions to session names.") (defun org-babel-scheme-cleanse-repl-map () "Remove dead buffers from the REPL map." (maphash (lambda (x y) (unless (buffer-name y) (remhash x org-babel-scheme-repl-map))) org-babel-scheme-repl-map)) (defun org-babel-scheme-get-session-buffer (session-name) "Look up the scheme buffer for a session; return nil if it doesn't exist." (org-babel-scheme-cleanse-repl-map) ; Prune dead sessions (gethash session-name org-babel-scheme-repl-map)) (defun org-babel-scheme-set-session-buffer (session-name buffer) "Record the scheme buffer used for a given session." (puthash session-name buffer org-babel-scheme-repl-map)) (defun org-babel-scheme-get-buffer-impl (buffer) "Return the scheme implementation geiser associates with the buffer." (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." (let ((buffer (org-babel-scheme-get-session-buffer name))) (or buffer (progn (run-geiser impl) (when name (rename-buffer name t) (org-babel-scheme-set-session-buffer name (current-buffer))) (current-buffer))))) (defun org-babel-scheme-make-session-name (buffer name impl) "Generate a name for the session buffer. For a named session, the buffer name will be the session name. If the session is unnamed (nil), generate a name. If the session is `none', use nil for the session name, and org-babel-scheme-execute-with-geiser will use a temporary session." (cond ((not name) (concat buffer " " (symbol-name impl) " REPL")) ((string= name "none") nil) (name))) (defmacro org-babel-scheme-capture-current-message (&rest body) "Capture current message in both interactive and noninteractive mode." `(if noninteractive (let ((original-message (symbol-function 'message)) (current-message nil)) (unwind-protect (progn (defun message (&rest args) (setq current-message (apply original-message args))) ,@body current-message) (fset 'message original-message))) (progn ,@body (current-message)))) (defun org-babel-scheme-execute-with-geiser (code output impl repl) "Execute code in specified REPL. If the REPL doesn't exist, create it using the given scheme implementation. Returns the output of executing the code if the OUTPUT parameter is true; otherwise returns the last value." (let ((result nil)) (with-temp-buffer (insert (format ";; -*- geiser-scheme-implementation: %s -*-" impl)) (newline) (insert code) (geiser-mode) (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)))) (when (not (eq impl (org-babel-scheme-get-buffer-impl (current-buffer)))) (message "Implementation mismatch: %s (%s) %s (%s)" impl (symbolp impl) (org-babel-scheme-get-buffer-impl (current-buffer)) (symbolp (org-babel-scheme-get-buffer-impl (current-buffer))))) (setq geiser-repl--repl repl-buffer) (setq geiser-impl--implementation nil) (let ((geiser-debug-jump-to-debug-p nil) (geiser-debug-show-debug-p nil)) (let ((ret (funcall ;; use `geiser-eval-region/wait' only when available ;; in newer versions of `geiser' (if (fboundp 'geiser-eval-region/wait) 'geiser-eval-region/wait 'geiser-eval-region) (point-min) (point-max)))) (setq result (if output (or (geiser-eval--retort-output ret) "Geiser Interpreter produced no output") (geiser-eval--retort-result-str ret ""))))) (when (not repl) (save-current-buffer (set-buffer repl-buffer) (geiser-repl-exit)) (set-process-query-on-exit-flag (get-buffer-process repl-buffer) nil) (kill-buffer repl-buffer))))) result)) (defun org-babel-scheme--table-or-string (results) "Convert RESULTS into an appropriate elisp value. If the results look like a list or tuple, then convert them into an Emacs-lisp table, otherwise return the results as a string." (let ((res (org-babel-script-escape results))) (cond ((listp res) (mapcar (lambda (el) (if (or (null el) (eq el 'null)) org-babel-scheme-null-to el)) res)) (t res)))) (defun org-babel-execute:scheme (body params) "Execute a block of Scheme code with org-babel. This function is called by `org-babel-execute-src-block'." (let* ((source-buffer (current-buffer)) (source-buffer-name (replace-regexp-in-string ;; zap surrounding * "^ ?\\*\\([^*]+\\)\\*" "\\1" (buffer-name source-buffer)))) (save-excursion (let* ((result-type (cdr (assq :result-type params))) (impl (or (when (cdr (assq :scheme params)) (intern (cdr (assq :scheme params)))) geiser-scheme-implementation geiser-default-implementation (car geiser-active-implementations))) (session (org-babel-scheme-make-session-name source-buffer-name (cdr (assq :session params)) impl)) (full-body (org-babel-expand-body:scheme body params)) (result-params (cdr (assq :result-params params))) (result (org-babel-scheme-execute-with-geiser full-body ; code (string= result-type "output") ; output? impl ; implementation (and (not (string= session "none")) session)))) ; session (let ((table (org-babel-reassemble-table 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)))))) (org-babel-result-cond result-params result (org-babel-scheme--table-or-string table))))))) (provide 'ob-scheme) ;;; ob-scheme.el ends here --=-=-=--