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

    Turn vertico--guard into a function
    
    With the macro I got bug reports about native-comp-speed=3. I still do not
    recommend native-comp-speed=3 since it leads to miscompilation.
---
 vertico.el | 39 ++++++++++++++++++++-------------------
 1 file changed, 20 insertions(+), 19 deletions(-)

diff --git a/vertico.el b/vertico.el
index e1d868da4d..7d35f764fc 100644
--- a/vertico.el
+++ b/vertico.el
@@ -477,28 +477,29 @@ The value should lie between 0 and vertico-count/2."
              (substitute-command-keys "Press \\[view-echo-area-messages] to 
see the stack trace")))
   nil)
 
-(defmacro vertico--guard (&rest body)
-  "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)))))
-     (when (or debug-on-error (funcall body))
-       (let ((debug-on-error t)
-             (debugger #'vertico--debug))
-         (funcall body)))))
+(defun vertico--protect (fun)
+  "Protect FUN such that errors are caught.
+If an error occurs, the FUN is retried with `debug-on-error' enabled and
+the stack trace is shown in the *Messages* buffer."
+  (let ((fun (lambda ()
+               (condition-case nil
+                   (progn (funcall fun) nil)
+                 ((debug error) t)))))
+    (when (or debug-on-error (funcall fun))
+      (let ((debug-on-error t)
+            (debugger #'vertico--debug))
+        (funcall fun)))))
 
 (defun vertico--exhibit ()
   "Exhibit completion UI."
-  (vertico--guard
-   (let ((buffer-undo-list t)) ;; Overlays affect point position and undo list!
-     (vertico--update 'interruptible)
-     (vertico--prompt-selection)
-     (vertico--display-count)
-     (vertico--display-candidates (vertico--arrange-candidates))
-     (vertico--resize))))
+  (vertico--protect
+   (lambda ()
+     (let ((buffer-undo-list t)) ;; Overlays affect point position and undo 
list!
+       (vertico--update 'interruptible)
+       (vertico--prompt-selection)
+       (vertico--display-count)
+       (vertico--display-candidates (vertico--arrange-candidates))
+       (vertico--resize)))))
 
 (defun vertico--goto (index)
   "Go to candidate with INDEX."

Reply via email to