summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Mendler <mail@daniel-mendler.de>2025-05-11 21:00:09 +0200
committerDaniel Mendler <mail@daniel-mendler.de>2025-05-11 21:00:09 +0200
commit5aef01a35fa9485571eb7b28b2b77958a5e2fb1a (patch)
treead672dc03f7f94790af8ee1597a2db51590c0920
parent51538f17f13aa926d59565d09bdb9b519eba82bd (diff)
Improve corfu--guard
Only override debug-on-error and debugger if an error occurred.
-rw-r--r--corfu.el19
1 files changed, 15 insertions, 4 deletions
diff --git a/corfu.el b/corfu.el
index 541136b..58a01e0 100644
--- a/corfu.el
+++ b/corfu.el
@@ -865,10 +865,21 @@ the last command must be listed in `corfu-continue-commands'."
nil)
(defmacro corfu--guard (&rest body)
- "Guard BODY showing a stack trace on error."
- `(condition-case nil
- (let ((debug-on-error t) (debugger #'corfu--debug)) ,@body)
- ((debug error) nil)))
+ "Guard BODY such that errors are caught.
+If an error occurs, the BODY is retried with `debug-on-error' enabled
+and the stack trace is shown in the *Messages* buffer."
+ `(let ((body (lambda ()
+ (condition-case nil
+ (progn ,@body nil)
+ ((debug error) t)))))
+ (cond
+ (debug-on-error
+ (let ((debugger #'corfu--debug))
+ (funcall body)))
+ ((funcall body)
+ (let ((debug-on-error t)
+ (debugger #'corfu--debug))
+ (funcall body))))))
(defun corfu--post-command ()
"Refresh Corfu after last command."