branch: externals/vertico
commit e5ff720ef59c6975e620c4b98181709fb6f5ba0b
Author: Daniel Mendler <m...@daniel-mendler.de>
Commit: Daniel Mendler <m...@daniel-mendler.de>

    Improve vertico--guard
    
    Only override debug-on-error and debugger if an error occurred.
---
 vertico.el | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/vertico.el b/vertico.el
index 6c97e9a3d4..ff9d282cd9 100644
--- a/vertico.el
+++ b/vertico.el
@@ -478,12 +478,21 @@ The value should lie between 0 and vertico-count/2."
   nil)
 
 (defmacro vertico--guard (&rest body)
-  "Guard BODY showing a stack trace on error."
-  `(condition-case 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 #'vertico--debug))
+         (funcall body)))
+      ((funcall body)
        (let ((debug-on-error t)
              (debugger #'vertico--debug))
-         ,@body)
-     ((debug error) nil)))
+         (funcall body))))))
 
 (defun vertico--exhibit ()
   "Exhibit completion UI."

Reply via email to