emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Report error in scheme evaluation
@ 2021-12-21 19:58 Felipe Lema
  2021-12-21 23:07 ` Rudolf Adamkovič
                   ` (4 more replies)
  0 siblings, 5 replies; 14+ messages in thread
From: Felipe Lema @ 2021-12-21 19:58 UTC (permalink / raw)
  To: emacs-orgmode

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

Sup, y'all

I started using guile with Org Babel and I was a little confused that errors weren't being reported. The attached patch will report the error the same way as python evaluation does.

Actually, most of the code was taken from ob-python.el

Let me know if I'm missing anything so this can be merged. It is correct to report errors this way, right?

Felipe

[-- Attachment #2: org-babel-scheme-show-error-in-buffer.diff --]
[-- Type: text/x-patch, Size: 2027 bytes --]

report error in scheme dialect evaluation to user

* ob-scheme.el (org-babel-scheme-execute-with-geiser): paste error into `org-babel-error-buffer-name` and setup buffer to compilation-mode

diff --git a/lisp/org/ob-scheme.el b/lisp/org/ob-scheme.el
index f4836b23fe..2828464bb5 100644
--- a/lisp/org/ob-scheme.el
+++ b/lisp/org/ob-scheme.el
@@ -58,6 +58,7 @@ geiser-repl-window-allow-split
 (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))

 (defcustom org-babel-scheme-null-to 'hline
   "Replace `null' and empty lists in scheme tables with this before returning."
@@ -180,8 +181,20 @@ org-babel-scheme-execute-with-geiser
 	      (setq result (if output
 			       (or (geiser-eval--retort-output ret)
 				   "Geiser Interpreter produced no output")
-			     (geiser-eval--retort-result-str ret "")))))
-	  (when (not repl)
+			     (geiser-eval--retort-result-str ret "")))
+              (when-let* ((err (geiser-eval--retort-error ret)))
+                ;; there was an error, report it!
+                (org-babel-eval-error-notify
+                 -1 ;; filler value, anything non-zero should do
+                 (geiser-eval--retort-output ret))
+                (save-excursion
+                  (when (get-buffer org-babel-error-buffer-name)
+                    (with-current-buffer org-babel-error-buffer-name
+                      (unless (derived-mode-p 'compilation-mode)
+                        (compilation-mode))
+                      ;; Compilation-mode enforces read-only, but Babel expects the buffer modifiable.
+                      (setq buffer-read-only nil)))))))
+          (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)

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

* Re: Report error in scheme evaluation
  2021-12-21 19:58 Felipe Lema
@ 2021-12-21 23:07 ` Rudolf Adamkovič
  2021-12-22  5:27   ` Felipe Lema
  2021-12-22 14:54 ` Ihor Radchenko
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 14+ messages in thread
From: Rudolf Adamkovič @ 2021-12-21 23:07 UTC (permalink / raw)
  To: Felipe Lema, emacs-orgmode

Felipe Lema <felipelema@mortemale.org> writes:

> Sup, y'all
>
> I started using guile with Org Babel […]

Sup! I plan to write some literate Scheme soon as well.  How do you find
the experience so far?  As of today, I use 'scheme-mode' with a set of
TAGS files for completion and help, all based on my (incomplete) notes
about R7RS.  Org requires Geiser to run Scheme, from what I gather.
Also, do Org bugs cause any issues when writing literate Scheme?  Thanks
in advance for any insights.  Cheers!

Rudy
-- 
"Programming reliably --- must be an activity of an undeniably mathematical nature […] You see, mathematics is about thinking, and doing mathematics is always trying to think as well as possible." -- Edsger W. Dijkstra (1981)

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


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

* Re: Report error in scheme evaluation
  2021-12-21 23:07 ` Rudolf Adamkovič
@ 2021-12-22  5:27   ` Felipe Lema
  2021-12-23 21:01     ` Rudolf Adamkovič
  0 siblings, 1 reply; 14+ messages in thread
From: Felipe Lema @ 2021-12-22  5:27 UTC (permalink / raw)
  To: Rudolf Adamkovič; +Cc: emacs-orgmode

On Tuesday, 21 December 2021 20.07.01 -03 Rudolf Adamkovič wrote:
> Felipe Lema <felipelema@mortemale.org> writes:
> 
> > Sup, y'all
> >
> > I started using guile with Org Babel […]
> 
> Sup! I plan to write some literate Scheme soon as well.  How do you find
> the experience so far?  As of today, I use 'scheme-mode' with a set of
> TAGS files for completion and help, all based on my (incomplete) notes
> about R7RS.  Org requires Geiser to run Scheme, from what I gather.
> Also, do Org bugs cause any issues when writing literate Scheme?  Thanks
> in advance for any insights.  Cheers!
> 
> Rudy
> 
Hey, Rudy

I think this was not clear, but just in case: this patch is not a bugfix. I just thought having an error buffer just like with Python is a good idea (specially since I'm relatively new to Guile). I also believe that fine-tuning a workflow with libre softweare through can be considered an improvement and, thus, should be shared for others to use.

For anyone interested about my Org + Babel + GNU Guile flow, read below.

I think the experience is good if you're not picky. This is my opinion for Emacs workflows in general. At the same time, I'd say it takes some resources (mainly time) to get things running comfortably.

Some context ahead. I'm using Org for Get Things Done workflows in which I basically log a shell session (you may think of it as data processing on text files too: grep, awk sed... but logged and reproducible). Because of my everyday job, I need to switch context several times within a week and I find it helpful to use Org for two reasons: 1) When I write stuff myself (describing stuff in Org file) I find it easier to remember 2) If I cannot remember, I can grep for similar text / tags.

I'm trying GNU Guile as scripting language because... well, for one, that is its purpose. And two, because I've mostly discarded other languages as being too costly (too slow, too much needs to be done...).

I'd say that geiser transforms Emacs into a full blown IDE: code completion, documentation, symbol/tag search... you name it. This also applies to Org when you edit the source code using C-c C-c, so that helps a ton with learning the language.

Hope this helps. You can contact me privately if you want to follow up.

FelipeL




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

* Re: Report error in scheme evaluation
  2021-12-21 19:58 Felipe Lema
  2021-12-21 23:07 ` Rudolf Adamkovič
@ 2021-12-22 14:54 ` Ihor Radchenko
  2021-12-22 16:56   ` Felipe Lema
  2021-12-22 14:58 ` Ihor Radchenko
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 14+ messages in thread
From: Ihor Radchenko @ 2021-12-22 14:54 UTC (permalink / raw)
  To: Felipe Lema; +Cc: emacs-orgmode

Felipe Lema <felipelema@mortemale.org> writes:

> I started using guile with Org Babel and I was a little confused that errors weren't being reported. The attached patch will report the error the same way as python evaluation does.

The patch looks fine to me. Though never used scheme...

The only thing that can be improved is copy-paste from ob-eval.el It
might be better to split the compile-mode code into separate function
and reuse it.

> Let me know if I'm missing anything so this can be merged. It is correct to report errors this way, right?

Should be. Did you have a chance run the code for some time locally
while actively playing around with scheme?

Best,
Ihor


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

* Re: Report error in scheme evaluation
  2021-12-21 19:58 Felipe Lema
  2021-12-21 23:07 ` Rudolf Adamkovič
  2021-12-22 14:54 ` Ihor Radchenko
@ 2021-12-22 14:58 ` Ihor Radchenko
  2021-12-22 16:34 ` Max Nikulin
  2022-09-12 11:27 ` Ihor Radchenko
  4 siblings, 0 replies; 14+ messages in thread
From: Ihor Radchenko @ 2021-12-22 14:58 UTC (permalink / raw)
  To: Felipe Lema; +Cc: emacs-orgmode

Felipe Lema <felipelema@mortemale.org> writes:

> * ob-scheme.el (org-babel-scheme-execute-with-geiser): paste error into `org-babel-error-buffer-name` and setup buffer to compilation-mode

Marking this as a patch for updates.orgmode.org

Best,
Ihor


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

* Re: Report error in scheme evaluation
  2021-12-21 19:58 Felipe Lema
                   ` (2 preceding siblings ...)
  2021-12-22 14:58 ` Ihor Radchenko
@ 2021-12-22 16:34 ` Max Nikulin
  2021-12-22 17:04   ` Ihor Radchenko
  2022-09-12 11:27 ` Ihor Radchenko
  4 siblings, 1 reply; 14+ messages in thread
From: Max Nikulin @ 2021-12-22 16:34 UTC (permalink / raw)
  To: emacs-orgmode

On 22/12/2021 02:58, Felipe Lema wrote:
> 
> Let me know if I'm missing anything so this can be merged. It is correct to report errors this way, right?

> +              (when-let* ((err (geiser-eval--retort-error ret)))

Doesn't (require 'subr-x) should be added to the file?




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

* Re: Report error in scheme evaluation
  2021-12-22 14:54 ` Ihor Radchenko
@ 2021-12-22 16:56   ` Felipe Lema
  0 siblings, 0 replies; 14+ messages in thread
From: Felipe Lema @ 2021-12-22 16:56 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: emacs-orgmode

On Wednesday, 22 December 2021 11.54.33 -03 Ihor Radchenko wrote:
> Felipe Lema <felipelema@mortemale.org> writes:
> 
> > I started using guile with Org Babel and I was a little confused that errors weren't being reported. The attached patch will report the error the same way as python evaluation does.
> 
> The patch looks fine to me. Though never used scheme...
> 
> The only thing that can be improved is copy-paste from ob-eval.el It
> might be better to split the compile-mode code into separate function
> and reuse it.

I can do that in a separate patch after this one is merged.

> 
> > Let me know if I'm missing anything so this can be merged. It is correct to report errors this way, right?
> 
> Should be. Did you have a chance run the code for some time locally
> while actively playing around with scheme?

yup. Seems to work as I expected 

> 
> Best,
> Ihor
> 
Thanks
Felipe




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

* Re: Report error in scheme evaluation
  2021-12-22 16:34 ` Max Nikulin
@ 2021-12-22 17:04   ` Ihor Radchenko
  0 siblings, 0 replies; 14+ messages in thread
From: Ihor Radchenko @ 2021-12-22 17:04 UTC (permalink / raw)
  To: Max Nikulin; +Cc: emacs-orgmode

Max Nikulin <manikulin@gmail.com> writes:

>> Let me know if I'm missing anything so this can be merged. It is correct to report errors this way, right?
>
>> +              (when-let* ((err (geiser-eval--retort-error ret)))
>
> Doesn't (require 'subr-x) should be added to the file?

Hmm. You are right. I thought that it is already built-in in Emacs 26.
But apparently, when-let becomes autoloaded only since Emacs 27.

As I remember, I was previously told to avoid when-let and other subr-x
staff for backwards compatibility.

Best,
Ihor


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

* Re: Report error in scheme evaluation
  2021-12-22  5:27   ` Felipe Lema
@ 2021-12-23 21:01     ` Rudolf Adamkovič
  0 siblings, 0 replies; 14+ messages in thread
From: Rudolf Adamkovič @ 2021-12-23 21:01 UTC (permalink / raw)
  To: Felipe Lema; +Cc: emacs-orgmode

Felipe Lema <felipelema@mortemale.org> writes:

> I'd say that geiser transforms Emacs into a full blown IDE: code
> completion, documentation, symbol/tag search... you name it. This also
> applies to Org when you edit the source code using C-c C-c, so that
> helps a ton with learning the language.

That sounds fantastic!  I use Scheme for game development at work, and I
thought about trying Geiser at some point.  As for now, like I
mentioned, I use the built-in "scheme-mode" with a couple of functions
that take my Scheme notes in Org and provide code completion and
documentation from them.  Hence, I do not get completion for local
variables and the like.  Your post made me move the "Try Geiser" task
from Someday/Maybe to Next.  Thank you for sharing!

Rudy
-- 
"I love deadlines. I love the whooshing noise they make as they go by." -- Douglas Adams, The Salmon of Doubt

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


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

* Re: Report error in scheme evaluation
@ 2021-12-28  1:03 Felipe Lema
  2022-04-30  8:11 ` Ihor Radchenko
  0 siblings, 1 reply; 14+ messages in thread
From: Felipe Lema @ 2021-12-28  1:03 UTC (permalink / raw)
  To: yantar92, emacs-orgmode

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

I just realized I was un-CCed out of the thread

Here's the updated patch with the requested changes (actually single one)

Lemme know if I'm missing anything else.

Felipe

[-- Attachment #2: org-babel-scheme-show-error-in-buffer_updated_req.diff --]
[-- Type: text/x-patch, Size: 2025 bytes --]

diff --git a/lisp/org/ob-scheme.el b/lisp/org/ob-scheme.el
index f4836b23fe..8720bd099e 100644
--- a/lisp/org/ob-scheme.el
+++ b/lisp/org/ob-scheme.el
@@ -39,6 +39,7 @@
 
 ;;; Code:
 (require 'ob)
+(require 'subr-x)
 (require 'geiser nil t)
 (require 'geiser-impl nil t)
 (defvar geiser-repl--repl)             ; Defined in geiser-repl.el
@@ -58,6 +59,7 @@ geiser-repl-window-allow-split
 (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))
 
 (defcustom org-babel-scheme-null-to 'hline
   "Replace `null' and empty lists in scheme tables with this before returning."
@@ -180,8 +182,20 @@ org-babel-scheme-execute-with-geiser
 	      (setq result (if output
 			       (or (geiser-eval--retort-output ret)
 				   "Geiser Interpreter produced no output")
-			     (geiser-eval--retort-result-str ret "")))))
-	  (when (not repl)
+			     (geiser-eval--retort-result-str ret "")))
+              (when-let* ((err (geiser-eval--retort-error ret)))
+                ;; there was an error, report it!
+                (org-babel-eval-error-notify
+                 -1 ;; filler value, anything non-zero should do
+                 (geiser-eval--retort-output ret))
+                (save-excursion
+                  (when (get-buffer org-babel-error-buffer-name)
+                    (with-current-buffer org-babel-error-buffer-name
+                      (unless (derived-mode-p 'compilation-mode)
+                        (compilation-mode))
+                      ;; Compilation-mode enforces read-only, but Babel expects the buffer modifiable.
+                      (setq buffer-read-only nil)))))))
+          (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)

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

* Re: Report error in scheme evaluation
  2021-12-28  1:03 Report error in scheme evaluation Felipe Lema
@ 2022-04-30  8:11 ` Ihor Radchenko
  2022-04-30 10:35   ` Neil Jerram
  0 siblings, 1 reply; 14+ messages in thread
From: Ihor Radchenko @ 2022-04-30  8:11 UTC (permalink / raw)
  To: Felipe Lema; +Cc: emacs-orgmode

Felipe Lema <felipelema@mortemale.org> writes:

> I just realized I was un-CCed out of the thread
>
> Here's the updated patch with the requested changes (actually single one)
>
> Lemme know if I'm missing anything else.

Can you update the patch making it a proper patch under your name?
See https://orgmode.org/worg/org-contribute.html#patches for
instructions.

Best,
Ihor


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

* Re: Report error in scheme evaluation
  2022-04-30  8:11 ` Ihor Radchenko
@ 2022-04-30 10:35   ` Neil Jerram
  2022-05-04  2:52     ` Felipe Lema
  0 siblings, 1 reply; 14+ messages in thread
From: Neil Jerram @ 2022-04-30 10:35 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Felipe Lema, Org Mode List

On Sat, 30 Apr 2022 at 09:14, Ihor Radchenko <yantar92@gmail.com> wrote:
>
> Felipe Lema <felipelema@mortemale.org> writes:
>
> > I just realized I was un-CCed out of the thread
> >
> > Here's the updated patch with the requested changes (actually single one)
> >
> > Lemme know if I'm missing anything else.
>
> Can you update the patch making it a proper patch under your name?
> See https://orgmode.org/worg/org-contribute.html#patches for
> instructions.

Hi Felipe,

Sorry for not commenting on this back in December.

Is the error that your patch shows equivalent to (or less than) taking
a look at the '*Geiser dbg*' buffer?  If it is, I wonder if it would
be better just to pop up the existing '*Geiser dbg*' buffer?  (Example
appended below.)

Best wishes,
    Neil

------- example of *Geiser dbg* buffer -------------
geiser-debugger
ice-9/boot-9.scm:1669:16: In procedure raise-exception:
Unbound variable: categorize-transactions-by-weeks

Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue.
scheme@(guile-user) [1]>
ice-9/boot-9.scm:1669:16: In procedure raise-exception:
Unbound variable: categorize-transactions-by-weeks

Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue.
scheme@(guile-user) [1]>
Expression evaluated was:

;; -*- geiser-scheme-implementation: guile -*-
(load "nationwide.scm")
(let ((classification '(<redacted>)))
(categorize-transactions-by-weeks (pre-2022 2020)
(two-column-table->alist classification) #t)
)
------- example of *Geiser dbg* buffer -------------


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

* Re: Report error in scheme evaluation
  2022-04-30 10:35   ` Neil Jerram
@ 2022-05-04  2:52     ` Felipe Lema
  0 siblings, 0 replies; 14+ messages in thread
From: Felipe Lema @ 2022-05-04  2:52 UTC (permalink / raw)
  To: Neil Jerram, Ihor Radchenko; +Cc: Org Mode List


On 2022-04-30 06:35, Neil Jerram wrote:
> On Sat, 30 Apr 2022 at 09:14, Ihor Radchenko <yantar92@gmail.com> wrote:
>> Felipe Lema <felipelema@mortemale.org> writes:
>>
>>> I just realized I was un-CCed out of the thread
>>>
>>> Here's the updated patch with the requested changes (actually single one)
>>>
>>> Lemme know if I'm missing anything else.
>> Can you update the patch making it a proper patch under your name?
>> See https://orgmode.org/worg/org-contribute.html#patches for
>> instructions.
> Hi Felipe,
>
> Sorry for not commenting on this back in December.
>
> Is the error that your patch shows equivalent to (or less than) taking
> a look at the '*Geiser dbg*' buffer?  If it is, I wonder if it would
> be better just to pop up the existing '*Geiser dbg*' buffer?  (Example
> appended below.)
>
> Best wishes,
>      Neil
>
> ------- example of *Geiser dbg* buffer -------------
> geiser-debugger
> ice-9/boot-9.scm:1669:16: In procedure raise-exception:
> Unbound variable: categorize-transactions-by-weeks
>
> Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue.
> scheme@(guile-user) [1]>
> ice-9/boot-9.scm:1669:16: In procedure raise-exception:
> Unbound variable: categorize-transactions-by-weeks
>
> Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue.
> scheme@(guile-user) [1]>
> Expression evaluated was:
>
> ;; -*- geiser-scheme-implementation: guile -*-
> (load "nationwide.scm")
> (let ((classification '(<redacted>)))
> (categorize-transactions-by-weeks (pre-2022 2020)
> (two-column-table->alist classification) #t)
> )
> ------- example of *Geiser dbg* buffer -------------

Hey, Neil


I believe there's an customizable option for that (opening the geiser 
repl with the debugger on). The patch I posted mimics current behavior 
with python, although the latter does have an option to pop the repl.

Lemme check if I can work something out and I'll post a new patch. I'll 
also address  Ihor's request for a proper patch.

Gards

Felipe



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

* Re: Report error in scheme evaluation
  2021-12-21 19:58 Felipe Lema
                   ` (3 preceding siblings ...)
  2021-12-22 16:34 ` Max Nikulin
@ 2022-09-12 11:27 ` Ihor Radchenko
  4 siblings, 0 replies; 14+ messages in thread
From: Ihor Radchenko @ 2022-09-12 11:27 UTC (permalink / raw)
  To: Felipe Lema; +Cc: emacs-orgmode

Felipe Lema <felipelema@mortemale.org> writes:

> Let me know if I'm missing anything so this can be merged. It is correct to report errors this way, right?

I am going through old patch submission that have not been resolved.
Note that this is not a patch, but a diff.

Also,

> +              (when-let* ((err (geiser-eval--retort-error ret)))

err variable binding here is unused in the code.
Is it an oversight?

-- 
Ihor Radchenko,
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] 14+ messages in thread

end of thread, other threads:[~2022-09-12 11:55 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-12-28  1:03 Report error in scheme evaluation Felipe Lema
2022-04-30  8:11 ` Ihor Radchenko
2022-04-30 10:35   ` Neil Jerram
2022-05-04  2:52     ` Felipe Lema
  -- strict thread matches above, loose matches on Subject: below --
2021-12-21 19:58 Felipe Lema
2021-12-21 23:07 ` Rudolf Adamkovič
2021-12-22  5:27   ` Felipe Lema
2021-12-23 21:01     ` Rudolf Adamkovič
2021-12-22 14:54 ` Ihor Radchenko
2021-12-22 16:56   ` Felipe Lema
2021-12-22 14:58 ` Ihor Radchenko
2021-12-22 16:34 ` Max Nikulin
2021-12-22 17:04   ` Ihor Radchenko
2022-09-12 11:27 ` Ihor Radchenko

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