macrostep icon indicating copy to clipboard operation
macrostep copied to clipboard

`macrostep-expand` fails with error on erroneous macros

Open wasamasa opened this issue 9 years ago • 3 comments

(defmacro my-bad ()
  `(1+ ,(/ 1 0)))

(my-bad)

Using macrostep-expand on the last form results in an arithmetic error. I'm not sure whether that's intended behaviour, but I'd expect a preview of the code instead. Any thoughts on this?

wasamasa avatar Jun 26 '15 19:06 wasamasa

@wasamasa What should it expand to? (1+ (arith-error))?

fice-t avatar Nov 04 '16 21:11 fice-t

Something like (1+ <error>), with <error> highlighted distinctly. That way one would immediately know what the problematic part is.

wasamasa avatar Nov 04 '16 21:11 wasamasa

It's a nice idea, but I'm not sure if it's feasible within Emacs Lisp. You need to be able to perform macroexpansion within a dynamic environment where you can trap error conditions without unwinding the stack, so that you can return some distinguished error-marker object instead. I think that requires something like Common Lisp's HANDLER-BIND mechanism, which Emacs Lisp lacks.

Maybe it could be done by binding the debugger variable? I'll try it next time I have a spare couple of hours.

joddie avatar Nov 20 '16 21:11 joddie