From mboxrd@z Thu Jan 1 00:00:00 1970 From: Neil Jerram Subject: Re: Scheme output results Date: Sun, 20 Aug 2017 17:43:43 +0100 Message-ID: <66634adc-b42a-58eb-02fc-f043e54452e4@ossau.homelinux.net> References: <1498bbde-0912-a806-f665-47b6f8c5e6e4@ossau.homelinux.net> <877eyzo7q5.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------09B79BFDAB252C47C1ADE335" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:59123) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1djTKM-0000QH-7H for emacs-orgmode@gnu.org; Sun, 20 Aug 2017 12:43:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1djTKI-0005go-Ss for emacs-orgmode@gnu.org; Sun, 20 Aug 2017 12:43:54 -0400 Received: from smtp-out-1.talktalk.net ([62.24.135.65]:20247) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1djTKI-0005gJ-Hq for emacs-orgmode@gnu.org; Sun, 20 Aug 2017 12:43:50 -0400 Received: from [192.168.0.5] (unknown [213.205.251.113]) by arudy.520b.com (Postfix) with ESMTPSA id 13B8F3805B for ; Sun, 20 Aug 2017 17:34:12 +0100 (BST) In-Reply-To: <877eyzo7q5.fsf@nicolasgoaziou.fr> Content-Language: en-US List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org This is a multi-part message in MIME format. --------------09B79BFDAB252C47C1ADE335 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit On 23/07/17 09:52, Nicolas Goaziou wrote: > Hello, > > Neil Jerram writes: > >> I don't think that Scheme output results are correctly handled. Please >> consider: >> >> #+BEGIN_SRC scheme :results output >> (display "a") (newline) >> (display "b") (newline) >> (display "c") (newline) >> '(a b c) >> #+END_SRC >> >> >> #+RESULTS: : "a\nb\nc\n" >> >> As compared with the Elisp equivalent: >> >> #+BEGIN_SRC elisp :results output >> (princ "a") (terpri) >> (princ "b") (terpri) >> (princ "c") (terpri) >> '(a b c) >> #+END_SRC >> >> #+RESULTS: >> : a >> : b >> : c >> >> I have a possible fix for this - on another computer, so not to hand >> right now - but thought it would be check first whether you agree with >> me that the Scheme results should be more like the Elisp ones. > That sounds like a good idea. Could you send your fix as a proper patch > with a commit message? > > Thank you! > > Regards, With apologies for the slow follow up, attached is a patch that works well for me. I think a concern with it would be whether the Geiser retort object and functions have always existed, and whether we can rely on them continuing to exist. But - at least for me - every Scheme evaluation was previously giving "An error occurred", because of an unexpected extra "Mark set" message, so I am pretty sure that my patch is an improvement. I guess (following any revisions) you will also need assignment papers. I believe I have these on file for Guile already (since about 1990), and it's possible that those are worded so as to cover Emacs as well. Would you mind checking, as I've forgotten how to do that myself? Regards - Neil --------------09B79BFDAB252C47C1ADE335 Content-Type: text/x-patch; name="0001-Improve-Scheme-code-evaluation.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-Improve-Scheme-code-evaluation.patch" >From a02b60b88bcfd1896c05cd858ae80bb1ef183730 Mon Sep 17 00:00:00 2001 From: Neil Jerram Date: Sun, 20 Aug 2017 17:25:58 +0100 Subject: [PATCH] Improve Scheme code evaluation * lisp/ob-scheme.el (org-babel-scheme-execute-with-geiser): Use Geiser's explicit 'retort' object, instead of catching and parsing an expected Emacs message (which for me is in any case overwritten by a following "Mark set" message); this also means we don't need the with-output-to-string approach for getting 'output' results. Also 'let' Geiser variables so as to avoid popping up the REPL and *Geiser dbg* buffers. --- lisp/ob-scheme.el | 56 +++++++++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/lisp/ob-scheme.el b/lisp/ob-scheme.el index b8867d5f6..bf1da01b0 100644 --- a/lisp/ob-scheme.el +++ b/lisp/ob-scheme.el @@ -150,35 +150,35 @@ is true; otherwise returns the last value." (with-temp-buffer (insert (format ";; -*- geiser-scheme-implementation: %s -*-" impl)) (newline) - (insert (if output - (format "(with-output-to-string (lambda () %s))" code) - code)) + (insert code) (geiser-mode) - (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) - (setq result (org-babel-scheme-capture-current-message - (geiser-eval-region (point-min) (point-max)))) - (setq result - (if (and (stringp result) (equal (substring result 0 3) "=> ")) - (replace-regexp-in-string "^=> " "" result) - "\"An error occurred.\"")) - (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)) - (setq result (if (or (string= result "#") - (string= result "#")) - nil - result)))) + (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 (geiser-eval-region (point-min) (point-max)))) + (setq result (if output + (geiser-eval--retort-output ret) + (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)) + (setq result (if (or (string= result "#") + (string= result "#")) + nil + result))))) result)) (defun org-babel-scheme--table-or-string (results) -- 2.13.2 --------------09B79BFDAB252C47C1ADE335--