From: "João Távora" <joaotavora@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: emacs-devel@gnu.org
Subject: Re: Attaching context info to an error
Date: Sat, 23 Dec 2023 03:02:04 +0000 [thread overview]
Message-ID: <CALDnm50KysROY2NbV0N=Q-SNr8KeTDKL+_rs8MM-n1zTwZBhKA@mail.gmail.com> (raw)
In-Reply-To: <jwvle9nmcox.fsf-monnier+emacs@gnu.org>
On Thu, Dec 21, 2023 at 10:31 PM Stefan Monnier
<monnier@iro.umontreal.ca> wrote:
> I'm playing with `handler-bind` and trying to see how we could make use
> of such a functionality in Emacs.
*loud cheers*
> So far I have encountered basically two use case:
(...proceeds to list three use cases...)
Amongst the killer weaponry this gives us is a restart system,
finally.
This completely changes interactive development. Whereas before
you couldn't restart from an nearby stack frame after doing
some changes to the state (say recompiling a buggy function, or
setting a global variable), with a handler-bind-powered restart
system you finally can.
So I had to try your branch...
;; -*- lexical-binding: t -*-
(require 'cl-lib)
(defvar pm/restarts nil)
(defun pm/call-with-retry-restart (outer inner msg fn)
(catch outer
(let ((saved-restarts pm/restarts))
(unwind-protect
(while t
(catch inner
(handler-bind ((error (lambda (_e)
(push
(list 'retry msg
(lambda ()
(throw inner nil)))
pm/restarts))))
(throw outer (funcall fn)))))
(setq pm/restarts saved-restarts)))))
(cl-defmacro pm/with-retry-restart ((&key (msg "Retry.")) &body body)
`(pm/call-with-retry-restart (gensym) (gensym) ,msg (lambda () ,@body)))
(defun pm/invoke-restart (restart)
(interactive
(some-read-from-minibuffer-or-somesuch))
(funcall (caadr restart)))
(defun baz (sym)
(error "whoops, it happened again for %s" sym))
(defun bar ()
(pm/with-retry-restart (:msg "Retry") (baz (gensym))))
(defun foo ()
(bar))
(foo)
;; Local Variables:
;; read-symbol-shorthands: (("pm/" . "poor-mans-restarts-"))
;; End:
This very code works fine in Common Lisp (just add a WHILE
macro to it) however when I try this in your Emacs branch and
evaluate (foo) I get:
Re-entering top level after C stack overflow
and Emacs dies immediately.
João
PS: Of course Common Lisp has all of this built-in and with
much, much better primitives that cover a wealth of use cases.
So this was just a quick-n-dirty proof of concept.
next prev parent reply other threads:[~2023-12-23 3:02 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-21 22:30 Attaching context info to an error Stefan Monnier
2023-12-22 6:50 ` Gerd Möllmann
2023-12-22 8:37 ` Gerd Möllmann
2023-12-22 15:58 ` Stefan Monnier
2023-12-28 6:57 ` Gerd Möllmann
2023-12-22 20:56 ` Jens Schmidt
2023-12-22 22:37 ` Stefan Monnier
2023-12-23 3:02 ` João Távora [this message]
2023-12-23 3:28 ` João Távora
2023-12-26 20:12 ` Stefan Monnier
2023-12-26 20:47 ` Stefan Monnier
2023-12-26 22:43 ` João Távora
2023-12-27 6:50 ` Gerd Möllmann
2023-12-27 10:29 ` João Távora
2023-12-27 10:35 ` Gerd Möllmann
2023-12-27 17:50 ` Stefan Monnier
2023-12-27 18:08 ` João Távora
2023-12-27 18:28 ` João Távora
2023-12-27 19:08 ` Stefan Monnier
2023-12-27 19:27 ` João Távora
2023-12-27 20:27 ` Stefan Monnier
2023-12-27 23:08 ` João Távora
2023-12-28 7:05 ` Stefan Monnier
2023-12-28 14:12 ` João Távora
2023-12-28 16:03 ` Stefan Monnier
2023-12-28 17:15 ` João Távora
2023-12-28 19:22 ` Stefan Monnier
2023-12-28 23:53 ` João Távora
2023-12-29 2:54 ` Stefan Monnier
2023-12-29 3:43 ` João Távora
2023-12-29 16:54 ` Stefan Monnier
2023-12-29 17:29 ` João Távora
2023-12-29 17:39 ` João Távora
2023-12-30 4:29 ` Stefan Monnier
2023-12-30 16:45 ` João Távora
2023-12-29 17:19 ` Alan Mackenzie
2023-12-29 17:24 ` João Távora
2023-12-29 17:43 ` Alan Mackenzie
2023-12-29 17:54 ` João Távora
2023-12-29 18:08 ` Alan Mackenzie
2023-12-29 18:45 ` João Távora
2023-12-29 18:35 ` Stefan Monnier
2023-12-29 18:48 ` João Távora
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CALDnm50KysROY2NbV0N=Q-SNr8KeTDKL+_rs8MM-n1zTwZBhKA@mail.gmail.com' \
--to=joaotavora@gmail.com \
--cc=emacs-devel@gnu.org \
--cc=monnier@iro.umontreal.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.