emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Babel (scheme): Evaluation errors are not shown
@ 2022-12-16 12:03 Marc Nieper-Wißkirchen
  2022-12-18 12:41 ` Ihor Radchenko
  0 siblings, 1 reply; 30+ messages in thread
From: Marc Nieper-Wißkirchen @ 2022-12-16 12:03 UTC (permalink / raw)
  To: emacs-orgmode

When I evaluate erroneous code of an Elisp code block like

#+BEGIN_SRC elisp
(x)
#+END_SRC

I see the error message ("Symbol's function definition is void: x") in
the minibuffer (and in the *Messages* buffer).

This is not the case with Scheme code blocks; evaluating the code block

#+BEGIN_SRC scheme
(x)
#+END_SRC

just gives "Code block evaluation complete (took 0.2s)." in the
minibuffer (and in the *Messages* buffer).

Is this a known error? Or is there a way to enable error messages?

I am using org 9.6 with geiser 20221205.1417 and geiser-chez
20221027.137 on Emacs 27.1.

Thanks,

Marc


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: Babel (scheme): Evaluation errors are not shown
  2022-12-16 12:03 Babel (scheme): Evaluation errors are not shown Marc Nieper-Wißkirchen
@ 2022-12-18 12:41 ` Ihor Radchenko
  2022-12-20  0:39   ` Rudolf Adamkovič
  0 siblings, 1 reply; 30+ messages in thread
From: Ihor Radchenko @ 2022-12-18 12:41 UTC (permalink / raw)
  To: Marc Nieper-Wißkirchen; +Cc: emacs-orgmode

Marc Nieper-Wißkirchen <marc@nieper-wisskirchen.de> writes:

> When I evaluate erroneous code of an Elisp code block like
>
> #+BEGIN_SRC elisp
> (x)
> #+END_SRC
>
> I see the error message ("Symbol's function definition is void: x") in
> the minibuffer (and in the *Messages* buffer).
>
> This is not the case with Scheme code blocks; evaluating the code block
>
> #+BEGIN_SRC scheme
> (x)
> #+END_SRC
>
> just gives "Code block evaluation complete (took 0.2s)." in the
> minibuffer (and in the *Messages* buffer).
>
> Is this a known error? Or is there a way to enable error messages?

ob-scheme.el relies on geiser library to handle code execution.
I do not know if it is possible to retrieve error messages using geiser
functions. You may check out `org-babel-scheme-execute-with-geiser' and
see if something can be done.

Note that we currently have no maintainer for ob-scheme and hence can
only provide very limited support. New features are hard for us without
experience with scheme and geiser.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: Babel (scheme): Evaluation errors are not shown
  2022-12-18 12:41 ` Ihor Radchenko
@ 2022-12-20  0:39   ` Rudolf Adamkovič
  2022-12-20 20:00     ` Marc Nieper-Wißkirchen
  2022-12-21 13:25     ` Ihor Radchenko
  0 siblings, 2 replies; 30+ messages in thread
From: Rudolf Adamkovič @ 2022-12-20  0:39 UTC (permalink / raw)
  To: Ihor Radchenko, Marc Nieper-Wißkirchen; +Cc: emacs-orgmode

Ihor Radchenko <yantar92@posteo.net> writes:

> Note that we currently have no maintainer for ob-scheme and hence can
> only provide very limited support. New features are hard for us
> without experience with scheme and geiser.

I volunteer to maintain `ob-scheme'.

(I use Scheme and Geiser heavily at work, albeit not via Org.)

Rudy
-- 
"Mathematics takes us still further from what is human into the region
of absolute necessity, to which not only the actual world, but every
possible world, must conform."
-- Bertrand Russell, 1902

Rudolf Adamkovič <salutis@me.com> [he/him]
Studenohorská 25
84103 Bratislava
Slovakia


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: Babel (scheme): Evaluation errors are not shown
  2022-12-20  0:39   ` Rudolf Adamkovič
@ 2022-12-20 20:00     ` Marc Nieper-Wißkirchen
  2022-12-31  9:50       ` Ihor Radchenko
  2022-12-21 13:25     ` Ihor Radchenko
  1 sibling, 1 reply; 30+ messages in thread
From: Marc Nieper-Wißkirchen @ 2022-12-20 20:00 UTC (permalink / raw)
  To: Rudolf Adamkovič; +Cc: Ihor Radchenko, emacs-orgmode

I have been talking to jao (from geiser).  The following version of
ob-scheme.el signals an error when executing Scheme code blocks.
Besides two function declarations, the only change is in the function
org-babel-scheme-execute-with-geiser.

;;; 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
;; URL: 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 <https://www.gnu.org/licenses/>.

;;; 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 'org-macs)
(org-assert-version)

(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 "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-eval-region/wait "ext:geiser-mode"
                  (start end &optional timeout))
(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))
(declare-function geiser-eval--retort-error "ext:geiser-eval" (ret))
(declare-function geiser-eval--retort-error-msg "ext:geiser-eval" (err))

(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
          (if (fboundp 'geiser)
              (geiser impl)
            ;; Obsolete since Geiser 0.26.
        (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))
            ;; `geiser-eval-region/wait' was introduced to await the
            ;; result of async evaluation in geiser version 0.22.
        (let ((ret (funcall (if (fboundp 'geiser-eval-region/wait)
                                    #'geiser-eval-region/wait
                                  #'geiser-eval-region)
                                (point-min)
                                (point-max))))
              (let ((err (geiser-eval--retort-error ret)))
                (unless err
              (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))
                (when err
                  (let ((msg (geiser-eval--error-msg err)))
                    (user-error "%s" (if (listp msg) (car msg) msg))))))))))
    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

Am Di., 20. Dez. 2022 um 01:39 Uhr schrieb Rudolf Adamkovič <salutis@me.com>:
>
> Ihor Radchenko <yantar92@posteo.net> writes:
>
> > Note that we currently have no maintainer for ob-scheme and hence can
> > only provide very limited support. New features are hard for us
> > without experience with scheme and geiser.
>
> I volunteer to maintain `ob-scheme'.
>
> (I use Scheme and Geiser heavily at work, albeit not via Org.)
>
> Rudy
> --
> "Mathematics takes us still further from what is human into the region
> of absolute necessity, to which not only the actual world, but every
> possible world, must conform."
> -- Bertrand Russell, 1902
>
> Rudolf Adamkovič <salutis@me.com> [he/him]
> Studenohorská 25
> 84103 Bratislava
> Slovakia


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: Babel (scheme): Evaluation errors are not shown
  2022-12-20  0:39   ` Rudolf Adamkovič
  2022-12-20 20:00     ` Marc Nieper-Wißkirchen
@ 2022-12-21 13:25     ` Ihor Radchenko
  2022-12-29 15:34       ` Bastien Guerry
  1 sibling, 1 reply; 30+ messages in thread
From: Ihor Radchenko @ 2022-12-21 13:25 UTC (permalink / raw)
  To: Rudolf Adamkovič, Bastien; +Cc: Marc Nieper-Wißkirchen, emacs-orgmode

Rudolf Adamkovič <salutis@me.com> writes:

> Ihor Radchenko <yantar92@posteo.net> writes:
>
>> Note that we currently have no maintainer for ob-scheme and hence can
>> only provide very limited support. New features are hard for us
>> without experience with scheme and geiser.
>
> I volunteer to maintain `ob-scheme'.
>
> (I use Scheme and Geiser heavily at work, albeit not via Org.)

CCing Bastien.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: Babel (scheme): Evaluation errors are not shown
  2022-12-21 13:25     ` Ihor Radchenko
@ 2022-12-29 15:34       ` Bastien Guerry
  2023-01-03 23:28         ` Rudolf Adamkovič
  0 siblings, 1 reply; 30+ messages in thread
From: Bastien Guerry @ 2022-12-29 15:34 UTC (permalink / raw)
  To: Ihor Radchenko
  Cc: Rudolf Adamkovič, Marc Nieper-Wißkirchen, emacs-orgmode

Hi Rudolf and Ihor,

Ihor Radchenko <yantar92@posteo.net> writes:

> Rudolf Adamkovič <salutis@me.com> writes:
>
>> Ihor Radchenko <yantar92@posteo.net> writes:
>>
>>> Note that we currently have no maintainer for ob-scheme and hence can
>>> only provide very limited support. New features are hard for us
>>> without experience with scheme and geiser.
>>
>> I volunteer to maintain `ob-scheme'.

I just added you as the maintainer of ob-scheme.el.

You are already in the list of FSF-copyrighted contributors on Worg.

Thank you very much!

-- 
 Bastien


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: Babel (scheme): Evaluation errors are not shown
  2022-12-20 20:00     ` Marc Nieper-Wißkirchen
@ 2022-12-31  9:50       ` Ihor Radchenko
  2022-12-31 10:09         ` Marc Nieper-Wißkirchen
  0 siblings, 1 reply; 30+ messages in thread
From: Ihor Radchenko @ 2022-12-31  9:50 UTC (permalink / raw)
  To: Marc Nieper-Wißkirchen; +Cc: Rudolf Adamkovič, emacs-orgmode

Marc Nieper-Wißkirchen <marc@nieper-wisskirchen.de> writes:

> I have been talking to jao (from geiser).  The following version of
> ob-scheme.el signals an error when executing Scheme code blocks.
> Besides two function declarations, the only change is in the function
> org-babel-scheme-execute-with-geiser.

Do you mean that `org-babel-scheme-execute-with-geiser' throws Elisp
error? It is not what we usually do in Org babel. If blocks execution
fails, we display the error in separate buffer and still return the
output available before error has been thrown. See `org-babel-eval' and
`org-babel-eval-error-notify'.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: Babel (scheme): Evaluation errors are not shown
  2022-12-31  9:50       ` Ihor Radchenko
@ 2022-12-31 10:09         ` Marc Nieper-Wißkirchen
  2022-12-31 10:19           ` Marc Nieper-Wißkirchen
  0 siblings, 1 reply; 30+ messages in thread
From: Marc Nieper-Wißkirchen @ 2022-12-31 10:09 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Rudolf Adamkovič, emacs-orgmode

Am Sa., 31. Dez. 2022 um 10:49 Uhr schrieb Ihor Radchenko <yantar92@posteo.net>:
>
> Marc Nieper-Wißkirchen <marc@nieper-wisskirchen.de> writes:
>
> > I have been talking to jao (from geiser).  The following version of
> > ob-scheme.el signals an error when executing Scheme code blocks.
> > Besides two function declarations, the only change is in the function
> > org-babel-scheme-execute-with-geiser.
>
> Do you mean that `org-babel-scheme-execute-with-geiser' throws Elisp
> error?

This is what it currently does; it packages the Scheme error as an
Elisp *user* error.

I chose this behavior to mimic what happens when Elisp code blocks
produce errors.

>  It is not what we usually do in Org babel. If blocks execution
> fails, we display the error in separate buffer and still return the
> output available before error has been thrown. See `org-babel-eval' and
> `org-babel-eval-error-notify'.

I will take a look.

Thanks,

Marc

>
> --
> Ihor Radchenko // yantar92,
> Org mode contributor,
> Learn more about Org mode at <https://orgmode.org/>.
> Support Org development at <https://liberapay.com/org-mode>,
> or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: Babel (scheme): Evaluation errors are not shown
  2022-12-31 10:09         ` Marc Nieper-Wißkirchen
@ 2022-12-31 10:19           ` Marc Nieper-Wißkirchen
  2022-12-31 10:50             ` Marc Nieper-Wißkirchen
  0 siblings, 1 reply; 30+ messages in thread
From: Marc Nieper-Wißkirchen @ 2022-12-31 10:19 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Rudolf Adamkovič, emacs-orgmode

Am Sa., 31. Dez. 2022 um 11:09 Uhr schrieb Marc Nieper-Wißkirchen
<marc@nieper-wisskirchen.de>:
>
> Am Sa., 31. Dez. 2022 um 10:49 Uhr schrieb Ihor Radchenko <yantar92@posteo.net>:
> >
> > Marc Nieper-Wißkirchen <marc@nieper-wisskirchen.de> writes:
> >
> > > I have been talking to jao (from geiser).  The following version of
> > > ob-scheme.el signals an error when executing Scheme code blocks.
> > > Besides two function declarations, the only change is in the function
> > > org-babel-scheme-execute-with-geiser.
> >
> > Do you mean that `org-babel-scheme-execute-with-geiser' throws Elisp
> > error?
>
> This is what it currently does; it packages the Scheme error as an
> Elisp *user* error.
>
> I chose this behavior to mimic what happens when Elisp code blocks
> produce errors.
>
> >  It is not what we usually do in Org babel. If blocks execution
> > fails, we display the error in separate buffer and still return the
> > output available before error has been thrown. See `org-babel-eval' and
> > `org-babel-eval-error-notify'.
>
> I will take a look.

Hmmm... `org-babel-eval-error-notify' assumes that the code was
evaluated by running an external script.  In the case of the Geiser
interface to Scheme, the concept of an exit code does not make any
sense.


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: Babel (scheme): Evaluation errors are not shown
  2022-12-31 10:19           ` Marc Nieper-Wißkirchen
@ 2022-12-31 10:50             ` Marc Nieper-Wißkirchen
  2022-12-31 12:07               ` Ihor Radchenko
  0 siblings, 1 reply; 30+ messages in thread
From: Marc Nieper-Wißkirchen @ 2022-12-31 10:50 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Rudolf Adamkovič, emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1199 bytes --]

Am Sa., 31. Dez. 2022 um 11:19 Uhr schrieb Marc Nieper-Wißkirchen
<marc@nieper-wisskirchen.de>:
>
> Am Sa., 31. Dez. 2022 um 11:09 Uhr schrieb Marc Nieper-Wißkirchen
> <marc@nieper-wisskirchen.de>:
> >
> > Am Sa., 31. Dez. 2022 um 10:49 Uhr schrieb Ihor Radchenko <yantar92@posteo.net>:
> > >
> > > Marc Nieper-Wißkirchen <marc@nieper-wisskirchen.de> writes:

[...]

> > >  It is not what we usually do in Org babel. If blocks execution
> > > fails, we display the error in separate buffer and still return the
> > > output available before error has been thrown. See `org-babel-eval' and
> > > `org-babel-eval-error-notify'.
> >
> > I will take a look.
>
> Hmmm... `org-babel-eval-error-notify' assumes that the code was
> evaluated by running an external script.  In the case of the Geiser
> interface to Scheme, the concept of an exit code does not make any
> sense.

Please find attached a version that does not signal an Elisp user
error, but calls `org-babel-eval-error-notify' instead.  To get rid of
the display of the arbitrary error code, could we modify
`org-babel-eval-error-notify' so that nothing is displayed about an
error if the error code is `nil'?

[-- Attachment #2: ob-scheme.el --]
[-- Type: application/octet-stream, Size: 11008 bytes --]

;;; 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
;; URL: 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 <https://www.gnu.org/licenses/>.

;;; 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 'org-macs)
(org-assert-version)

(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 "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-eval-region/wait "ext:geiser-mode"
                  (start end &optional timeout))
(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))
(declare-function geiser-eval--retort-error "ext:geiser-eval" (ret))
(declare-function geiser-eval--retort-error-msg "ext:geiser-eval" (err))

(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
          (if (fboundp 'geiser)
              (geiser impl)
            ;; Obsolete since Geiser 0.26.
        (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))
            ;; `geiser-eval-region/wait' was introduced to await the
            ;; result of async evaluation in geiser version 0.22.
            (let ((ret (funcall (if (fboundp 'geiser-eval-region/wait)
                                    #'geiser-eval-region/wait
                                  #'geiser-eval-region)
                                (point-min)
                                (point-max))))
              (let ((err (geiser-eval--retort-error ret)))
                (setq result (cond
                              (err "Geiser Interpreter produced an error")
                              (output
                               (or (geiser-eval--retort-output ret)
                                   "Geiser Interpreter produced no output"))
                              (t (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))
                (when err
                  (let ((msg (geiser-eval--error-msg err)))
                    (org-babel-eval-error-notify
                     1
                     (concat (if (listp msg) (car msg) msg) "\n"))))))))))
    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

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: Babel (scheme): Evaluation errors are not shown
  2022-12-31 10:50             ` Marc Nieper-Wißkirchen
@ 2022-12-31 12:07               ` Ihor Radchenko
  2022-12-31 13:11                 ` Marc Nieper-Wißkirchen
  0 siblings, 1 reply; 30+ messages in thread
From: Ihor Radchenko @ 2022-12-31 12:07 UTC (permalink / raw)
  To: Marc Nieper-Wißkirchen; +Cc: Rudolf Adamkovič, emacs-orgmode

Marc Nieper-Wißkirchen <marc@nieper-wisskirchen.de> writes:

> Please find attached a version that does not signal an Elisp user
> error, but calls `org-babel-eval-error-notify' instead.

If you can, could you please send the changes in form of a patch
instead? It is then easier to review.
See https://orgmode.org/worg/org-contribute.html#patches (you can just
attach the patch to your reply).

> To get rid of
> the display of the arbitrary error code, could we modify
> `org-babel-eval-error-notify' so that nothing is displayed about an
> error if the error code is `nil'?

Yes, we can. Feel free to make a patch, updating the docstring according
to your changes.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: Babel (scheme): Evaluation errors are not shown
  2022-12-31 12:07               ` Ihor Radchenko
@ 2022-12-31 13:11                 ` Marc Nieper-Wißkirchen
  2022-12-31 13:24                   ` Ihor Radchenko
  0 siblings, 1 reply; 30+ messages in thread
From: Marc Nieper-Wißkirchen @ 2022-12-31 13:11 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Rudolf Adamkovič, emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1120 bytes --]

Please find the patch file attached to this email.

Thank you,

Marc

Am Sa., 31. Dez. 2022 um 13:07 Uhr schrieb Ihor Radchenko <yantar92@posteo.net>:
>
> Marc Nieper-Wißkirchen <marc@nieper-wisskirchen.de> writes:
>
> > Please find attached a version that does not signal an Elisp user
> > error, but calls `org-babel-eval-error-notify' instead.
>
> If you can, could you please send the changes in form of a patch
> instead? It is then easier to review.
> See https://orgmode.org/worg/org-contribute.html#patches (you can just
> attach the patch to your reply).
>
> > To get rid of
> > the display of the arbitrary error code, could we modify
> > `org-babel-eval-error-notify' so that nothing is displayed about an
> > error if the error code is `nil'?
>
> Yes, we can. Feel free to make a patch, updating the docstring according
> to your changes.
>
> --
> Ihor Radchenko // yantar92,
> Org mode contributor,
> Learn more about Org mode at <https://orgmode.org/>.
> Support Org development at <https://liberapay.com/org-mode>,
> or support my work at <https://liberapay.com/yantar92>

[-- Attachment #2: 0001-Display-evaluation-errors-for-Scheme-code-blocks.patch --]
[-- Type: application/octet-stream, Size: 4193 bytes --]

From c804d69b6daad66d9d732b0f8adaf226af3641c8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marc=20Nieper-Wi=C3=9Fkirchen?= <marc@nieper-wisskirchen.de>
Date: Sat, 31 Dec 2022 14:08:53 +0100
Subject: [PATCH] Display evaluation errors for Scheme code blocks.

---
 lisp/ob-eval.el   |  9 ++++++---
 lisp/ob-scheme.el | 21 +++++++++++++++------
 2 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/lisp/ob-eval.el b/lisp/ob-eval.el
index f57566079..4f31b4109 100644
--- a/lisp/ob-eval.el
+++ b/lisp/ob-eval.el
@@ -37,16 +37,19 @@
 (declare-function org-babel-temp-file "ob-core" (prefix &optional suffix))
 
 (defun org-babel-eval-error-notify (exit-code stderr)
-  "Open a buffer to display STDERR and a message with the value of EXIT-CODE."
+  "Open a buffer to display STDERR and a message with the value of EXIT-CODE.
+If EXIT-CODE is nil, suppress the message."
   (let ((buf (get-buffer-create org-babel-error-buffer-name)))
     (with-current-buffer buf
       (goto-char (point-max))
       (save-excursion
         (unless (bolp) (insert "\n"))
         (insert stderr)
-        (insert (format "[ Babel evaluation exited with code %S ]" exit-code))))
+        (when exit-code
+          (insert (format "[ Babel evaluation exited with code %S ]" exit-code)))))
     (display-buffer buf))
-  (message "Babel evaluation exited with code %S" exit-code))
+  (when exit-code
+    (message "Babel evaluation exited with code %S" exit-code)))
 
 (defun org-babel-eval (command query)
   "Run COMMAND on QUERY.
diff --git a/lisp/ob-scheme.el b/lisp/ob-scheme.el
index 5be13bd89..e7c9db48d 100644
--- a/lisp/ob-scheme.el
+++ b/lisp/ob-scheme.el
@@ -4,7 +4,6 @@
 
 ;; Authors: Eric Schulte
 ;;        Michael Gauland
-;; Maintainer: Rudolf Adamkovič <salutis@me.com>
 ;; Keywords: literate programming, reproducible research, scheme
 ;; URL: https://orgmode.org
 
@@ -66,6 +65,8 @@
 (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))
+(declare-function geiser-eval--retort-error "ext:geiser-eval" (ret))
+(declare-function geiser-eval--retort-error-msg "ext:geiser-eval" (err))
 
 (defcustom org-babel-scheme-null-to 'hline
   "Replace `null' and empty lists in scheme tables with this before returning."
@@ -194,22 +195,30 @@ is true; otherwise returns the last value."
                                   #'geiser-eval-region)
                                 (point-min)
                                 (point-max))))
-	      (setq result (if output
+              (let ((err (geiser-eval--retort-error ret)))
+                (setq result (cond
+                              (err nil)
+                              (output
                                (or (geiser-eval--retort-output ret)
-				   "Geiser Interpreter produced no output")
-			     (geiser-eval--retort-result-str ret "")))))
+                                   "Geiser Interpreter produced no output"))
+                              (t (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)))))
+                  (kill-buffer repl-buffer))
+                (when err
+                  (let ((msg (geiser-eval--error-msg err)))
+                    (org-babel-eval-error-notify
+                     nil
+                     (concat (if (listp msg) (car msg) msg) "\n"))))))))))
     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)))
+  (let ((res (and results (org-babel-script-escape results))))
     (cond ((listp res)
            (mapcar (lambda (el)
                      (if (or (null el) (eq el 'null))
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* Re: Babel (scheme): Evaluation errors are not shown
  2022-12-31 13:11                 ` Marc Nieper-Wißkirchen
@ 2022-12-31 13:24                   ` Ihor Radchenko
  2022-12-31 14:46                     ` Marc Nieper-Wißkirchen
  0 siblings, 1 reply; 30+ messages in thread
From: Ihor Radchenko @ 2022-12-31 13:24 UTC (permalink / raw)
  To: Marc Nieper-Wißkirchen; +Cc: Rudolf Adamkovič, emacs-orgmode

Marc Nieper-Wißkirchen <marc@nieper-wisskirchen.de> writes:

> Please find the patch file attached to this email.

Thanks!
I will give some general comments and leave the ob-scheme changes for
Rudolf.

> Subject: [PATCH] Display evaluation errors for Scheme code blocks.

If you can, please provide changelog entries explaining each change. See
https://orgmode.org/worg/org-contribute.html#commit-messages

>    (let ((buf (get-buffer-create org-babel-error-buffer-name)))
>      (with-current-buffer buf
>        (goto-char (point-max))
>        (save-excursion
>          (unless (bolp) (insert "\n"))
>          (insert stderr)
> -        (insert (format "[ Babel evaluation exited with code %S ]" exit-code))))
> +        (when exit-code
> +          (insert (format "[ Babel evaluation exited with code %S ]" exit-code)))))

I think it will be more consistent to do something like

(if exit-code ... (insert " [ Babel evaluation exited abnormally ] "))

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: Babel (scheme): Evaluation errors are not shown
  2022-12-31 13:24                   ` Ihor Radchenko
@ 2022-12-31 14:46                     ` Marc Nieper-Wißkirchen
  2023-01-01 13:53                       ` Ihor Radchenko
  0 siblings, 1 reply; 30+ messages in thread
From: Marc Nieper-Wißkirchen @ 2022-12-31 14:46 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Rudolf Adamkovič, emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1367 bytes --]

Done!

Am Sa., 31. Dez. 2022 um 14:24 Uhr schrieb Ihor Radchenko <yantar92@posteo.net>:
>
> Marc Nieper-Wißkirchen <marc@nieper-wisskirchen.de> writes:
>
> > Please find the patch file attached to this email.
>
> Thanks!
> I will give some general comments and leave the ob-scheme changes for
> Rudolf.
>
> > Subject: [PATCH] Display evaluation errors for Scheme code blocks.
>
> If you can, please provide changelog entries explaining each change. See
> https://orgmode.org/worg/org-contribute.html#commit-messages
>
> >    (let ((buf (get-buffer-create org-babel-error-buffer-name)))
> >      (with-current-buffer buf
> >        (goto-char (point-max))
> >        (save-excursion
> >          (unless (bolp) (insert "\n"))
> >          (insert stderr)
> > -        (insert (format "[ Babel evaluation exited with code %S ]" exit-code))))
> > +        (when exit-code
> > +          (insert (format "[ Babel evaluation exited with code %S ]" exit-code)))))
>
> I think it will be more consistent to do something like
>
> (if exit-code ... (insert " [ Babel evaluation exited abnormally ] "))
>
> --
> Ihor Radchenko // yantar92,
> Org mode contributor,
> Learn more about Org mode at <https://orgmode.org/>.
> Support Org development at <https://liberapay.com/org-mode>,
> or support my work at <https://liberapay.com/yantar92>

[-- Attachment #2: 0001-lisp-ob-scheme.el-Do-not-hide-Scheme-evaluation-erro.patch --]
[-- Type: application/octet-stream, Size: 4479 bytes --]

From eb143517dce6152ab3559e74543f930efa78bd57 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marc=20Nieper-Wi=C3=9Fkirchen?= <marc@nieper-wisskirchen.de>
Date: Sat, 31 Dec 2022 15:41:59 +0100
Subject: [PATCH] lisp/ob-scheme.el: Do not hide Scheme evaluation errors.

* lisp/ob-eval.el (org-babel-eval-error-notify): Handle an exit code of nil.

* lisp/ob-scheme.el (org-babel-expand-body:scheme)
(org-babel-scheme-get-repl, org-babel-scheme-make-session-name)
(org-babel-scheme-execute-with-geiser)
(org-babel-scheme--table-or-string, org-babel-execute:scheme):
Display Scheme evaluation errors in an error buffer using
`org-babel-eval-error-notify'.
---
 lisp/ob-eval.el   | 11 ++++++++---
 lisp/ob-scheme.el | 20 +++++++++++++++-----
 2 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/lisp/ob-eval.el b/lisp/ob-eval.el
index f57566079..5c249fa13 100644
--- a/lisp/ob-eval.el
+++ b/lisp/ob-eval.el
@@ -37,16 +37,21 @@
 (declare-function org-babel-temp-file "ob-core" (prefix &optional suffix))
 
 (defun org-babel-eval-error-notify (exit-code stderr)
-  "Open a buffer to display STDERR and a message with the value of EXIT-CODE."
+  "Open a buffer to display STDERR and a message with the value of EXIT-CODE.
+If EXIT-CODE is nil, suppress the message."
   (let ((buf (get-buffer-create org-babel-error-buffer-name)))
     (with-current-buffer buf
       (goto-char (point-max))
       (save-excursion
         (unless (bolp) (insert "\n"))
         (insert stderr)
-        (insert (format "[ Babel evaluation exited with code %S ]" exit-code))))
+        (if exit-code
+            (insert (format "[ Babel evaluation exited with code %S ]" exit-code))
+          (insert "[ Babel evaluation exited abnormally ]"))))
     (display-buffer buf))
-  (message "Babel evaluation exited with code %S" exit-code))
+  (if exit-code
+      (message "Babel evaluation exited with code %S" exit-code)
+    (message "Babel evaluation exited abnormally")))
 
 (defun org-babel-eval (command query)
   "Run COMMAND on QUERY.
diff --git a/lisp/ob-scheme.el b/lisp/ob-scheme.el
index 5be13bd89..196e527f7 100644
--- a/lisp/ob-scheme.el
+++ b/lisp/ob-scheme.el
@@ -66,6 +66,8 @@
 (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))
+(declare-function geiser-eval--retort-error "ext:geiser-eval" (ret))
+(declare-function geiser-eval--retort-error-msg "ext:geiser-eval" (err))
 
 (defcustom org-babel-scheme-null-to 'hline
   "Replace `null' and empty lists in scheme tables with this before returning."
@@ -194,22 +196,30 @@ is true; otherwise returns the last value."
                                   #'geiser-eval-region)
                                 (point-min)
                                 (point-max))))
-	      (setq result (if output
+              (let ((err (geiser-eval--retort-error ret)))
+                (setq result (cond
+                              (err nil)
+                              (output
                                (or (geiser-eval--retort-output ret)
-				   "Geiser Interpreter produced no output")
-			     (geiser-eval--retort-result-str ret "")))))
+                                   "Geiser Interpreter produced no output"))
+                              (t (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)))))
+                  (kill-buffer repl-buffer))
+                (when err
+                  (let ((msg (geiser-eval--error-msg err)))
+                    (org-babel-eval-error-notify
+                     nil
+                     (concat (if (listp msg) (car msg) msg) "\n"))))))))))
     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)))
+  (let ((res (and results (org-babel-script-escape results))))
     (cond ((listp res)
            (mapcar (lambda (el)
                      (if (or (null el) (eq el 'null))
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* Re: Babel (scheme): Evaluation errors are not shown
  2022-12-31 14:46                     ` Marc Nieper-Wißkirchen
@ 2023-01-01 13:53                       ` Ihor Radchenko
  2023-01-01 15:21                         ` Marc Nieper-Wißkirchen
  0 siblings, 1 reply; 30+ messages in thread
From: Ihor Radchenko @ 2023-01-01 13:53 UTC (permalink / raw)
  To: Marc Nieper-Wißkirchen; +Cc: Rudolf Adamkovič, emacs-orgmode

Marc Nieper-Wißkirchen <marc@nieper-wisskirchen.de> writes:

>  (defun org-babel-eval-error-notify (exit-code stderr)
> -  "Open a buffer to display STDERR and a message with the value of EXIT-CODE."
> +  "Open a buffer to display STDERR and a message with the value of EXIT-CODE.
> +If EXIT-CODE is nil, suppress the message."

The docstring is not accurate now.
If EXIT-CODE is nil, the message is not suppressed.

> ...
> -  (message "Babel evaluation exited with code %S" exit-code))
> +  (if exit-code
> +      (message "Babel evaluation exited with code %S" exit-code)
> +    (message "Babel evaluation exited abnormally")))

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: Babel (scheme): Evaluation errors are not shown
  2023-01-01 13:53                       ` Ihor Radchenko
@ 2023-01-01 15:21                         ` Marc Nieper-Wißkirchen
  2023-01-02  9:38                           ` Ihor Radchenko
  0 siblings, 1 reply; 30+ messages in thread
From: Marc Nieper-Wißkirchen @ 2023-01-01 15:21 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Rudolf Adamkovič, emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1011 bytes --]

Fixed.

Am So., 1. Jan. 2023 um 14:53 Uhr schrieb Ihor Radchenko <yantar92@posteo.net>:
>
> Marc Nieper-Wißkirchen <marc@nieper-wisskirchen.de> writes:
>
> >  (defun org-babel-eval-error-notify (exit-code stderr)
> > -  "Open a buffer to display STDERR and a message with the value of EXIT-CODE."
> > +  "Open a buffer to display STDERR and a message with the value of EXIT-CODE.
> > +If EXIT-CODE is nil, suppress the message."
>
> The docstring is not accurate now.
> If EXIT-CODE is nil, the message is not suppressed.
>
> > ...
> > -  (message "Babel evaluation exited with code %S" exit-code))
> > +  (if exit-code
> > +      (message "Babel evaluation exited with code %S" exit-code)
> > +    (message "Babel evaluation exited abnormally")))
>
> --
> Ihor Radchenko // yantar92,
> Org mode contributor,
> Learn more about Org mode at <https://orgmode.org/>.
> Support Org development at <https://liberapay.com/org-mode>,
> or support my work at <https://liberapay.com/yantar92>

[-- Attachment #2: 0001-lisp-ob-scheme.el-Do-not-hide-Scheme-evaluation-erro.patch --]
[-- Type: application/octet-stream, Size: 4493 bytes --]

From 78d9fbbf52dc0d0d66cd6fc4a48995db6bd50dd7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marc=20Nieper-Wi=C3=9Fkirchen?= <marc@nieper-wisskirchen.de>
Date: Sat, 31 Dec 2022 15:41:59 +0100
Subject: [PATCH] lisp/ob-scheme.el: Do not hide Scheme evaluation errors.

* lisp/ob-eval.el (org-babel-eval-error-notify): Handle an exit code of nil.

* lisp/ob-scheme.el (org-babel-expand-body:scheme)
(org-babel-scheme-get-repl, org-babel-scheme-make-session-name)
(org-babel-scheme-execute-with-geiser)
(org-babel-scheme--table-or-string, org-babel-execute:scheme):
Display Scheme evaluation errors in an error buffer using
`org-babel-eval-error-notify'.
---
 lisp/ob-eval.el   | 11 ++++++++---
 lisp/ob-scheme.el | 20 +++++++++++++++-----
 2 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/lisp/ob-eval.el b/lisp/ob-eval.el
index f57566079..90e51aa1f 100644
--- a/lisp/ob-eval.el
+++ b/lisp/ob-eval.el
@@ -37,16 +37,21 @@
 (declare-function org-babel-temp-file "ob-core" (prefix &optional suffix))
 
 (defun org-babel-eval-error-notify (exit-code stderr)
-  "Open a buffer to display STDERR and a message with the value of EXIT-CODE."
+  "Open a buffer to display STDERR and a message with the value of EXIT-CODE.
+If EXIT-CODE is nil, display the message without a code."
   (let ((buf (get-buffer-create org-babel-error-buffer-name)))
     (with-current-buffer buf
       (goto-char (point-max))
       (save-excursion
         (unless (bolp) (insert "\n"))
         (insert stderr)
-        (insert (format "[ Babel evaluation exited with code %S ]" exit-code))))
+        (if exit-code
+            (insert (format "[ Babel evaluation exited with code %S ]" exit-code))
+          (insert "[ Babel evaluation exited abnormally ]"))))
     (display-buffer buf))
-  (message "Babel evaluation exited with code %S" exit-code))
+  (if exit-code
+      (message "Babel evaluation exited with code %S" exit-code)
+    (message "Babel evaluation exited abnormally")))
 
 (defun org-babel-eval (command query)
   "Run COMMAND on QUERY.
diff --git a/lisp/ob-scheme.el b/lisp/ob-scheme.el
index 5be13bd89..196e527f7 100644
--- a/lisp/ob-scheme.el
+++ b/lisp/ob-scheme.el
@@ -66,6 +66,8 @@
 (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))
+(declare-function geiser-eval--retort-error "ext:geiser-eval" (ret))
+(declare-function geiser-eval--retort-error-msg "ext:geiser-eval" (err))
 
 (defcustom org-babel-scheme-null-to 'hline
   "Replace `null' and empty lists in scheme tables with this before returning."
@@ -194,22 +196,30 @@ is true; otherwise returns the last value."
                                   #'geiser-eval-region)
                                 (point-min)
                                 (point-max))))
-	      (setq result (if output
+              (let ((err (geiser-eval--retort-error ret)))
+                (setq result (cond
+                              (err nil)
+                              (output
                                (or (geiser-eval--retort-output ret)
-				   "Geiser Interpreter produced no output")
-			     (geiser-eval--retort-result-str ret "")))))
+                                   "Geiser Interpreter produced no output"))
+                              (t (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)))))
+                  (kill-buffer repl-buffer))
+                (when err
+                  (let ((msg (geiser-eval--error-msg err)))
+                    (org-babel-eval-error-notify
+                     nil
+                     (concat (if (listp msg) (car msg) msg) "\n"))))))))))
     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)))
+  (let ((res (and results (org-babel-script-escape results))))
     (cond ((listp res)
            (mapcar (lambda (el)
                      (if (or (null el) (eq el 'null))
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* Re: Babel (scheme): Evaluation errors are not shown
  2023-01-01 15:21                         ` Marc Nieper-Wißkirchen
@ 2023-01-02  9:38                           ` Ihor Radchenko
  2023-01-02  9:52                             ` Marc Nieper-Wißkirchen
  0 siblings, 1 reply; 30+ messages in thread
From: Ihor Radchenko @ 2023-01-02  9:38 UTC (permalink / raw)
  To: Marc Nieper-Wißkirchen; +Cc: Rudolf Adamkovič, emacs-orgmode

Marc Nieper-Wißkirchen <marc@nieper-wisskirchen.de> writes:

> Fixed.

Thanks!
Note that your patch does not apply onto main.

> -	      (setq result (if output
> +              (let ((err (geiser-eval--retort-error ret)))
> +                (setq result (cond
> +                              (err nil)

We may still provide output, if any. Even in the case of error. Not sure
if it makes sense for ob-scheme though.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: Babel (scheme): Evaluation errors are not shown
  2023-01-02  9:38                           ` Ihor Radchenko
@ 2023-01-02  9:52                             ` Marc Nieper-Wißkirchen
  2023-01-03  9:07                               ` Ihor Radchenko
  2023-01-05  8:55                               ` Marc Nieper-Wißkirchen
  0 siblings, 2 replies; 30+ messages in thread
From: Marc Nieper-Wißkirchen @ 2023-01-02  9:52 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Rudolf Adamkovič, emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 806 bytes --]

Am Mo., 2. Jan. 2023 um 10:38 Uhr schrieb Ihor Radchenko <yantar92@posteo.net>:
>
> Marc Nieper-Wißkirchen <marc@nieper-wisskirchen.de> writes:
>
> > Fixed.
>
> Thanks!
> Note that your patch does not apply onto main.

Rebased against the latest main.  Please see the appended patch.

>
> > -           (setq result (if output
> > +              (let ((err (geiser-eval--retort-error ret)))
> > +                (setq result (cond
> > +                              (err nil)
>
> We may still provide output, if any. Even in the case of error. Not sure
> if it makes sense for ob-scheme though.

I switched the two cases, "err" and "output," in the attached patch.
For a value result, providing a result in case of an error does not
make sense.

Thanks for your patience,

Marc

[-- Attachment #2: 0001-lisp-ob-scheme.el-Do-not-hide-Scheme-evaluation-erro.patch --]
[-- Type: application/octet-stream, Size: 4493 bytes --]

From 4194e67f2edee60cc83e146f068d1892842de0da Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marc=20Nieper-Wi=C3=9Fkirchen?= <marc@nieper-wisskirchen.de>
Date: Sat, 31 Dec 2022 15:41:59 +0100
Subject: [PATCH] lisp/ob-scheme.el: Do not hide Scheme evaluation errors.

* lisp/ob-eval.el (org-babel-eval-error-notify): Handle an exit code of nil.

* lisp/ob-scheme.el (org-babel-expand-body:scheme)
(org-babel-scheme-get-repl, org-babel-scheme-make-session-name)
(org-babel-scheme-execute-with-geiser)
(org-babel-scheme--table-or-string, org-babel-execute:scheme):
Display Scheme evaluation errors in an error buffer using
`org-babel-eval-error-notify'.
---
 lisp/ob-eval.el   | 11 ++++++++---
 lisp/ob-scheme.el | 20 +++++++++++++++-----
 2 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/lisp/ob-eval.el b/lisp/ob-eval.el
index 6f6edb949..b9d1f7f23 100644
--- a/lisp/ob-eval.el
+++ b/lisp/ob-eval.el
@@ -37,16 +37,21 @@
 (declare-function org-babel-temp-file "ob-core" (prefix &optional suffix))
 
 (defun org-babel-eval-error-notify (exit-code stderr)
-  "Open a buffer to display STDERR and a message with the value of EXIT-CODE."
+  "Open a buffer to display STDERR and a message with the value of EXIT-CODE.
+If EXIT-CODE is nil, display the message without a code."
   (let ((buf (get-buffer-create org-babel-error-buffer-name)))
     (with-current-buffer buf
       (goto-char (point-max))
       (save-excursion
         (unless (bolp) (insert "\n"))
         (insert stderr)
-        (insert (format "[ Babel evaluation exited with code %S ]" exit-code))))
+        (if exit-code
+            (insert (format "[ Babel evaluation exited with code %S ]" exit-code))
+          (insert "[ Babel evaluation exited abnormally ]"))))
     (display-buffer buf))
-  (message "Babel evaluation exited with code %S" exit-code))
+  (if exit-code
+      (message "Babel evaluation exited with code %S" exit-code)
+    (message "Babel evaluation exited abnormally")))
 
 (defun org-babel-eval (command query)
   "Run COMMAND on QUERY.
diff --git a/lisp/ob-scheme.el b/lisp/ob-scheme.el
index 414bf13a6..e4ee7147c 100644
--- a/lisp/ob-scheme.el
+++ b/lisp/ob-scheme.el
@@ -66,6 +66,8 @@
 (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))
+(declare-function geiser-eval--retort-error "ext:geiser-eval" (ret))
+(declare-function geiser-eval--retort-error-msg "ext:geiser-eval" (err))
 
 (defcustom org-babel-scheme-null-to 'hline
   "Replace `null' and empty lists in scheme tables with this before returning."
@@ -194,22 +196,30 @@ is true; otherwise returns the last value."
                                   #'geiser-eval-region)
                                 (point-min)
                                 (point-max))))
-	      (setq result (if output
+              (let ((err (geiser-eval--retort-error ret)))
+                (setq result (cond
+                              (output
                                (or (geiser-eval--retort-output ret)
-				   "Geiser Interpreter produced no output")
-			     (geiser-eval--retort-result-str ret "")))))
+                                   "Geiser Interpreter produced no output"))
+                              (err nil)
+                              (t (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)))))
+                  (kill-buffer repl-buffer))
+                (when err
+                  (let ((msg (geiser-eval--error-msg err)))
+                    (org-babel-eval-error-notify
+                     nil
+                     (concat (if (listp msg) (car msg) msg) "\n"))))))))))
     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)))
+  (let ((res (and results (org-babel-script-escape results))))
     (cond ((listp res)
            (mapcar (lambda (el)
                      (if (or (null el) (eq el 'null))
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* Re: Babel (scheme): Evaluation errors are not shown
  2023-01-02  9:52                             ` Marc Nieper-Wißkirchen
@ 2023-01-03  9:07                               ` Ihor Radchenko
  2023-01-07 14:26                                 ` Marc Nieper-Wißkirchen
  2023-01-05  8:55                               ` Marc Nieper-Wißkirchen
  1 sibling, 1 reply; 30+ messages in thread
From: Ihor Radchenko @ 2023-01-03  9:07 UTC (permalink / raw)
  To: Marc Nieper-Wißkirchen; +Cc: Rudolf Adamkovič, emacs-orgmode

Marc Nieper-Wißkirchen <marc@nieper-wisskirchen.de> writes:

>> Thanks!
>> Note that your patch does not apply onto main.
>
> Rebased against the latest main.  Please see the appended patch.

Hmm.
Not sure what is going on here, but I am getting

128 git … am --3way -- /tmp/0001-lisp-ob-scheme.el-Do-not-hide-Scheme-evaluation-erro.patch
Applying: lisp/ob-scheme.el: Do not hide Scheme evaluation errors.
Using index info to reconstruct a base tree...
error: patch failed: lisp/ob-scheme.el:194
error: lisp/ob-scheme.el: patch does not apply
error: Did you hand edit your patch?
It does not apply to blobs recorded in its index.
Patch failed at 0001 lisp/ob-scheme.el: Do not hide Scheme evaluation errors.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: Babel (scheme): Evaluation errors are not shown
  2022-12-29 15:34       ` Bastien Guerry
@ 2023-01-03 23:28         ` Rudolf Adamkovič
  2023-01-03 23:35           ` Bastien
  0 siblings, 1 reply; 30+ messages in thread
From: Rudolf Adamkovič @ 2023-01-03 23:28 UTC (permalink / raw)
  To: Bastien Guerry, Ihor Radchenko; +Cc: Marc Nieper-Wißkirchen, emacs-orgmode

Bastien Guerry <bzg@gnu.org> writes:

> I just added you as the maintainer of ob-scheme.el.

A sudden turn of events:

My employer have just decided that we will convert all Scheme to Fennel,
a zero-runtime Lisp based on Lua, because it has a better bus factor,
meaning that, in the worst-case, the company can continue with Lua, a
language for which one can find programmers more easily than for Scheme.

So, my use of Scheme drops from 8 hours per day to effectively 0,
effective today.  As a result, I would like to kindly ask you to revert
the change, for without actively using something, I cannot maintain it.

That said, if my employer changes their mind during the transition from
Scheme to Fennel and decides to keep the current code base, I will
re-volunteer.

Thank you for understanding, and I again apologize for the churn!

Rudy
-- 
"Be especially critical of any statement following the word
'obviously.'"
-- Anna Pell Wheeler, 1883-1966

Rudolf Adamkovič <salutis@me.com> [he/him]
Studenohorská 25
84103 Bratislava
Slovakia


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: Babel (scheme): Evaluation errors are not shown
  2023-01-03 23:28         ` Rudolf Adamkovič
@ 2023-01-03 23:35           ` Bastien
  2023-01-06 20:45             ` Rudolf Adamkovič
  0 siblings, 1 reply; 30+ messages in thread
From: Bastien @ 2023-01-03 23:35 UTC (permalink / raw)
  To: Rudolf Adamkovič
  Cc: Ihor Radchenko, Marc Nieper-Wißkirchen, emacs-orgmode

Hi Rudolf,

Rudolf Adamkovič <salutis@me.com> writes:

> So, my use of Scheme drops from 8 hours per day to effectively 0,
> effective today.  As a result, I would like to kindly ask you to revert
> the change, for without actively using something, I cannot maintain it.

Sure, done.

> That said, if my employer changes their mind during the transition from
> Scheme to Fennel and decides to keep the current code base, I will
> re-volunteer.
>
> Thank you for understanding, and I again apologize for the churn!

No problem, I hope you can re-volunteer at some point!   (Or write
ob-fennel.el?)

Thanks,

-- 
 Bastien


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: Babel (scheme): Evaluation errors are not shown
  2023-01-02  9:52                             ` Marc Nieper-Wißkirchen
  2023-01-03  9:07                               ` Ihor Radchenko
@ 2023-01-05  8:55                               ` Marc Nieper-Wißkirchen
  2023-01-06 16:17                                 ` Ihor Radchenko
  1 sibling, 1 reply; 30+ messages in thread
From: Marc Nieper-Wißkirchen @ 2023-01-05  8:55 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Rudolf Adamkovič, emacs-orgmode

Despite the unfortunate lack of a maintainer, I hope the (latest
version of the) patch can still be applied as the current behavior of
ob-scheme.el, namely, silencing any evaluation errors is infeasible.

Do you need any FSF copyright assignments from me? (I already
contributed to GCC and Gnulib under such an assignment in the past.)

Thanks,

Marc

Am Mo., 2. Jan. 2023 um 10:52 Uhr schrieb Marc Nieper-Wißkirchen
<marc@nieper-wisskirchen.de>:
>
> Am Mo., 2. Jan. 2023 um 10:38 Uhr schrieb Ihor Radchenko <yantar92@posteo.net>:
> >
> > Marc Nieper-Wißkirchen <marc@nieper-wisskirchen.de> writes:
> >
> > > Fixed.
> >
> > Thanks!
> > Note that your patch does not apply onto main.
>
> Rebased against the latest main.  Please see the appended patch.
>
> >
> > > -           (setq result (if output
> > > +              (let ((err (geiser-eval--retort-error ret)))
> > > +                (setq result (cond
> > > +                              (err nil)
> >
> > We may still provide output, if any. Even in the case of error. Not sure
> > if it makes sense for ob-scheme though.
>
> I switched the two cases, "err" and "output," in the attached patch.
> For a value result, providing a result in case of an error does not
> make sense.
>
> Thanks for your patience,
>
> Marc


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: Babel (scheme): Evaluation errors are not shown
  2023-01-05  8:55                               ` Marc Nieper-Wißkirchen
@ 2023-01-06 16:17                                 ` Ihor Radchenko
  2023-01-06 16:20                                   ` Ihor Radchenko
  2023-01-07 13:28                                   ` Bastien Guerry
  0 siblings, 2 replies; 30+ messages in thread
From: Ihor Radchenko @ 2023-01-06 16:17 UTC (permalink / raw)
  To: Marc Nieper-Wißkirchen, Bastien; +Cc: Rudolf Adamkovič, emacs-orgmode

Marc Nieper-Wißkirchen <marc@nieper-wisskirchen.de> writes:

> Despite the unfortunate lack of a maintainer, I hope the (latest
> version of the) patch can still be applied as the current behavior of
> ob-scheme.el, namely, silencing any evaluation errors is infeasible.

Yes, it can. Can you please take a look at patch failure issue in my
last reply?

> Do you need any FSF copyright assignments from me? (I already
> contributed to GCC and Gnulib under such an assignment in the past.)

For this particular patch, your changes fall within TINYCHANGE (~15LOC),
so copyright should not be necessary.

As for GCC-related assignment, I am not sure if it is sufficient. In my
own assignment, GNU EMACS changes are mentioned explicitly. If your
assignment also mentions GCC and Gnulib only, I doubt that GNU EMACS is
also covered.

Bastien may know better.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: Babel (scheme): Evaluation errors are not shown
  2023-01-06 16:17                                 ` Ihor Radchenko
@ 2023-01-06 16:20                                   ` Ihor Radchenko
  2023-01-06 16:32                                     ` tomas
  2023-01-07 13:28                                   ` Bastien Guerry
  1 sibling, 1 reply; 30+ messages in thread
From: Ihor Radchenko @ 2023-01-06 16:20 UTC (permalink / raw)
  To: Bastien; +Cc: Rudolf Adamkovič, emacs-orgmode

Ihor Radchenko <yantar92@posteo.net> writes:

> Marc Nieper-Wißkirchen <marc@nieper-wisskirchen.de> writes:
> ...

May someone forward my last email to Marc?
For some reason, his mail server classifies my emails as spam and
rejects them.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: Babel (scheme): Evaluation errors are not shown
  2023-01-06 16:20                                   ` Ihor Radchenko
@ 2023-01-06 16:32                                     ` tomas
  2023-01-06 20:47                                       ` Marc Nieper-Wißkirchen
  0 siblings, 1 reply; 30+ messages in thread
From: tomas @ 2023-01-06 16:32 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Bastien, Rudolf Adamkovič, emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 381 bytes --]

On Fri, Jan 06, 2023 at 04:20:29PM +0000, Ihor Radchenko wrote:
> Ihor Radchenko <yantar92@posteo.net> writes:
> 
> > Marc Nieper-Wißkirchen <marc@nieper-wisskirchen.de> writes:
> > ...
> 
> May someone forward my last email to Marc?
> For some reason, his mail server classifies my emails as spam and
> rejects them.

Just tried. Happens for me too.

Cheers
-- 
t

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: Babel (scheme): Evaluation errors are not shown
  2023-01-03 23:35           ` Bastien
@ 2023-01-06 20:45             ` Rudolf Adamkovič
  0 siblings, 0 replies; 30+ messages in thread
From: Rudolf Adamkovič @ 2023-01-06 20:45 UTC (permalink / raw)
  To: Bastien; +Cc: Ihor Radchenko, Marc Nieper-Wißkirchen, emacs-orgmode

Bastien <bzg@gnu.org> writes:

> Sure, done.

Thank you for your understanding, Bastien!

> (Or write ob-fennel.el?)

It already exists, FYI:

https://gitlab.com/andreyorst/ob-fennel

Rudy
-- 
"Simplicity is complexity resolved."
-- Constantin Brâncuși, 1876-1957

Rudolf Adamkovič <salutis@me.com> [he/him]
Studenohorská 25
84103 Bratislava
Slovakia


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: Babel (scheme): Evaluation errors are not shown
  2023-01-06 16:32                                     ` tomas
@ 2023-01-06 20:47                                       ` Marc Nieper-Wißkirchen
  0 siblings, 0 replies; 30+ messages in thread
From: Marc Nieper-Wißkirchen @ 2023-01-06 20:47 UTC (permalink / raw)
  To: tomas; +Cc: Ihor Radchenko, Bastien, Rudolf Adamkovič, emacs-orgmode

Am Fr., 6. Jan. 2023 um 17:34 Uhr schrieb <tomas@tuxteam.de>:
>
> On Fri, Jan 06, 2023 at 04:20:29PM +0000, Ihor Radchenko wrote:
> > Ihor Radchenko <yantar92@posteo.net> writes:
> >
> > > Marc Nieper-Wißkirchen <marc@nieper-wisskirchen.de> writes:
> > > ...
> >
> > May someone forward my last email to Marc?
> > For some reason, his mail server classifies my emails as spam and
> > rejects them.
>
> Just tried. Happens for me too.

Strange.  Can you try marc.nieper@gmail.com instead?

Thanks,

Marc

>
> Cheers
> --
> t


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: Babel (scheme): Evaluation errors are not shown
  2023-01-06 16:17                                 ` Ihor Radchenko
  2023-01-06 16:20                                   ` Ihor Radchenko
@ 2023-01-07 13:28                                   ` Bastien Guerry
  1 sibling, 0 replies; 30+ messages in thread
From: Bastien Guerry @ 2023-01-07 13:28 UTC (permalink / raw)
  To: Ihor Radchenko
  Cc: Marc Nieper-Wißkirchen, Rudolf Adamkovič, emacs-orgmode

Ihor Radchenko <yantar92@posteo.net> writes:

> As for GCC-related assignment, I am not sure if it is sufficient.

I confirm that the copyright assignment should explicitely mention
EMACS as a GNU project.

-- 
 Bastien


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: Babel (scheme): Evaluation errors are not shown
  2023-01-03  9:07                               ` Ihor Radchenko
@ 2023-01-07 14:26                                 ` Marc Nieper-Wißkirchen
  2023-01-25 13:12                                   ` Ihor Radchenko
  0 siblings, 1 reply; 30+ messages in thread
From: Marc Nieper-Wißkirchen @ 2023-01-07 14:26 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Rudolf Adamkovič, emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1594 bytes --]

Am Sa., 7. Jan. 2023 um 08:44 Uhr schrieb Ihor Radchenko <yantar92@posteo.net>:
>
> Marc Nieper-Wißkirchen <marc@nieper-wisskirchen.de> writes:
>
> >> Thanks!
> >> Note that your patch does not apply onto main.
> >
> > Rebased against the latest main.  Please see the appended patch.
>
> Hmm.
> Not sure what is going on here, but I am getting
>
> 128 git … am --3way -- /tmp/0001-lisp-ob-scheme.el-Do-not-hide-Scheme-evaluation-erro.patch
> Applying: lisp/ob-scheme.el: Do not hide Scheme evaluation errors.
> Using index info to reconstruct a base tree...
> error: patch failed: lisp/ob-scheme.el:194
> error: lisp/ob-scheme.el: patch does not apply
> error: Did you hand edit your patch?
> It does not apply to blobs recorded in its index.
> Patch failed at 0001 lisp/ob-scheme.el: Do not hide Scheme evaluation errors.
> hint: Use 'git am --show-current-patch=diff' to see the failed patch
> When you have resolved this problem, run "git am --continue".
> If you prefer to skip this patch, run "git am --skip" instead.
> To restore the original branch and stop patching, run "git am --abort".

Okay, apparently, `git format-patch -w' to ignore whitespace changes
does not work (at least not as simple as I thought).

A new patch file is attached; `git am' against the upstream head works here.

Thanks,

Marc

>
> --
> Ihor Radchenko // yantar92,
> Org mode contributor,
> Learn more about Org mode at <https://orgmode.org/>.
> Support Org development at <https://liberapay.com/org-mode>,
> or support my work at <https://liberapay.com/yantar92>

[-- Attachment #2: 0001-lisp-ob-scheme.el-Do-not-hide-Scheme-evaluation-erro.patch --]
[-- Type: application/octet-stream, Size: 4189 bytes --]

From ad7c32487954b055f156bafb8df591e2af2106fd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marc=20Nieper-Wi=C3=9Fkirchen?= <marc@nieper-wisskirchen.de>
Date: Sat, 31 Dec 2022 15:41:59 +0100
Subject: [PATCH] lisp/ob-scheme.el: Do not hide Scheme evaluation errors.

* lisp/ob-eval.el (org-babel-eval-error-notify): Handle an exit code of nil.

* lisp/ob-scheme.el (org-babel-expand-body:scheme)
(org-babel-scheme-get-repl, org-babel-scheme-make-session-name)
(org-babel-scheme-execute-with-geiser)
(org-babel-scheme--table-or-string, org-babel-execute:scheme):
Display Scheme evaluation errors in an error buffer using
`org-babel-eval-error-notify'.
---
 lisp/ob-eval.el   | 11 ++++++++---
 lisp/ob-scheme.el | 20 +++++++++++++++-----
 2 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/lisp/ob-eval.el b/lisp/ob-eval.el
index 6f6edb949..b9d1f7f23 100644
--- a/lisp/ob-eval.el
+++ b/lisp/ob-eval.el
@@ -37,16 +37,21 @@
 (declare-function org-babel-temp-file "ob-core" (prefix &optional suffix))
 
 (defun org-babel-eval-error-notify (exit-code stderr)
-  "Open a buffer to display STDERR and a message with the value of EXIT-CODE."
+  "Open a buffer to display STDERR and a message with the value of EXIT-CODE.
+If EXIT-CODE is nil, display the message without a code."
   (let ((buf (get-buffer-create org-babel-error-buffer-name)))
     (with-current-buffer buf
       (goto-char (point-max))
       (save-excursion
         (unless (bolp) (insert "\n"))
         (insert stderr)
-        (insert (format "[ Babel evaluation exited with code %S ]" exit-code))))
+        (if exit-code
+            (insert (format "[ Babel evaluation exited with code %S ]" exit-code))
+          (insert "[ Babel evaluation exited abnormally ]"))))
     (display-buffer buf))
-  (message "Babel evaluation exited with code %S" exit-code))
+  (if exit-code
+      (message "Babel evaluation exited with code %S" exit-code)
+    (message "Babel evaluation exited abnormally")))
 
 (defun org-babel-eval (command query)
   "Run COMMAND on QUERY.
diff --git a/lisp/ob-scheme.el b/lisp/ob-scheme.el
index ef41a2ec4..a8cf7de45 100644
--- a/lisp/ob-scheme.el
+++ b/lisp/ob-scheme.el
@@ -65,6 +65,8 @@
 (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))
+(declare-function geiser-eval--retort-error "ext:geiser-eval" (ret))
+(declare-function geiser-eval--retort-error-msg "ext:geiser-eval" (err))
 
 (defcustom org-babel-scheme-null-to 'hline
   "Replace `null' and empty lists in scheme tables with this before returning."
@@ -193,22 +195,30 @@ is true; otherwise returns the last value."
                                   #'geiser-eval-region)
                                 (point-min)
                                 (point-max))))
-	      (setq result (if output
+	      (let ((err (geiser-eval--retort-error ret)))
+		(setq result (cond
+			      (output
 			       (or (geiser-eval--retort-output ret)
-				   "Geiser Interpreter produced no output")
-			     (geiser-eval--retort-result-str ret "")))))
+				   "Geiser Interpreter produced no output"))
+			      (err nil)
+			      (t (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)))))
+		  (kill-buffer repl-buffer))
+		(when err
+		  (let ((msg (geiser-eval--error-msg err)))
+		    (org-babel-eval-error-notify
+		     nil
+		     (concat (if (listp msg) (car msg) msg) "\n"))))))))))
     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)))
+  (let ((res (and results (org-babel-script-escape results))))
     (cond ((listp res)
            (mapcar (lambda (el)
 		     (if (or (null el) (eq el 'null))
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* Re: Babel (scheme): Evaluation errors are not shown
  2023-01-07 14:26                                 ` Marc Nieper-Wißkirchen
@ 2023-01-25 13:12                                   ` Ihor Radchenko
  0 siblings, 0 replies; 30+ messages in thread
From: Ihor Radchenko @ 2023-01-25 13:12 UTC (permalink / raw)
  To: Marc Nieper-Wißkirchen; +Cc: Rudolf Adamkovič, emacs-orgmode

Marc Nieper-Wißkirchen <marc.nieper+gnu@gmail.com> writes:

>> > Rebased against the latest main.  Please see the appended patch.

Applied, onto main, adding TINYCHANGE cookie and removing "." from the
commit summary.

https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=f35fb8ac2

You are now also listed as Org contributor:
https://git.sr.ht/~bzg/worg/commit/4f193b43

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 30+ messages in thread

end of thread, other threads:[~2023-01-25 13:13 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-16 12:03 Babel (scheme): Evaluation errors are not shown Marc Nieper-Wißkirchen
2022-12-18 12:41 ` Ihor Radchenko
2022-12-20  0:39   ` Rudolf Adamkovič
2022-12-20 20:00     ` Marc Nieper-Wißkirchen
2022-12-31  9:50       ` Ihor Radchenko
2022-12-31 10:09         ` Marc Nieper-Wißkirchen
2022-12-31 10:19           ` Marc Nieper-Wißkirchen
2022-12-31 10:50             ` Marc Nieper-Wißkirchen
2022-12-31 12:07               ` Ihor Radchenko
2022-12-31 13:11                 ` Marc Nieper-Wißkirchen
2022-12-31 13:24                   ` Ihor Radchenko
2022-12-31 14:46                     ` Marc Nieper-Wißkirchen
2023-01-01 13:53                       ` Ihor Radchenko
2023-01-01 15:21                         ` Marc Nieper-Wißkirchen
2023-01-02  9:38                           ` Ihor Radchenko
2023-01-02  9:52                             ` Marc Nieper-Wißkirchen
2023-01-03  9:07                               ` Ihor Radchenko
2023-01-07 14:26                                 ` Marc Nieper-Wißkirchen
2023-01-25 13:12                                   ` Ihor Radchenko
2023-01-05  8:55                               ` Marc Nieper-Wißkirchen
2023-01-06 16:17                                 ` Ihor Radchenko
2023-01-06 16:20                                   ` Ihor Radchenko
2023-01-06 16:32                                     ` tomas
2023-01-06 20:47                                       ` Marc Nieper-Wißkirchen
2023-01-07 13:28                                   ` Bastien Guerry
2022-12-21 13:25     ` Ihor Radchenko
2022-12-29 15:34       ` Bastien Guerry
2023-01-03 23:28         ` Rudolf Adamkovič
2023-01-03 23:35           ` Bastien
2023-01-06 20:45             ` Rudolf Adamkovič

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).