]> git.eshelyaron.com Git - emacs.git/commitdiff
Turn gdb-wait-for-pending into a plain function
authorMattias Engdegård <mattiase@acm.org>
Wed, 18 Nov 2020 09:55:41 +0000 (10:55 +0100)
committerMattias Engdegård <mattiase@acm.org>
Wed, 18 Nov 2020 12:51:55 +0000 (13:51 +0100)
This avoids unnecessary body duplication in expansion and macro
recursion (causing macro-expansions at runtime), making it clearer
what is going on.

* lisp/progmodes/gdb-mi.el (gdb-wait-for-pending): Make it a function,
remove lambda quoting,  η-reduce and simplify.
(gdb-thread-exited, gdb-thread-selected): Adapt callers.

lisp/progmodes/gdb-mi.el

index 0023e1fb5d0f8a6d461a0e24f43a7825dc068fa9..903005610d7ad1e5965e6e6dee5207698ac612f1 100644 (file)
@@ -373,19 +373,17 @@ were not yet received."
   (dolist (handler gdb-handler-list)
     (setf (gdb-handler-pending-trigger handler) nil)))
 
-(defmacro gdb-wait-for-pending (&rest body)
-  "Wait for all pending GDB commands to finish and evaluate BODY.
+(defun gdb-wait-for-pending (func)
+  "Wait for all pending GDB commands to finish and call FUNC.
 
 This function checks every 0.5 seconds if there are any pending
 triggers in `gdb-handler-list'."
-  `(run-with-timer
-    0.5 nil
-    '(lambda ()
-       (if (not (cl-find-if (lambda (handler)
-                               (gdb-handler-pending-trigger handler))
-                             gdb-handler-list))
-          (progn ,@body)
-        (gdb-wait-for-pending ,@body)))))
+  (run-with-timer
+   0.5 nil
+   (lambda ()
+     (if (cl-some #'gdb-handler-pending-trigger gdb-handler-list)
+        (gdb-wait-for-pending func)
+       (funcall func)))))
 
 ;; Publish-subscribe
 
@@ -2524,7 +2522,7 @@ Unset `gdb-thread-number' if current thread exited and update threads list."
     ;; disallow us to properly call -thread-info without --thread option.
     ;; Thus we need to use gdb-wait-for-pending.
     (gdb-wait-for-pending
-     (gdb-emit-signal gdb-buf-publisher 'update-threads))))
+     (lambda () (gdb-emit-signal gdb-buf-publisher 'update-threads)))))
 
 (defun gdb-thread-selected (_token output-field)
   "Handler for =thread-selected MI output record.
@@ -2538,11 +2536,10 @@ Sets `gdb-thread-number' to new id."
     ;; as usually. Things happen too fast and second call (from
     ;; gdb-thread-selected handler) gets cut off by our beloved
     ;; pending triggers.
-    ;; Solution is `gdb-wait-for-pending' macro: it guarantees that its
-    ;; body will get executed when `gdb-handler-list' if free of
+    ;; Solution is `gdb-wait-for-pending': it guarantees that its
+    ;; argument will get called when `gdb-handler-list' if free of
     ;; pending triggers.
-    (gdb-wait-for-pending
-     (gdb-update))))
+    (gdb-wait-for-pending #'gdb-update)))
 
 (defun gdb-running (_token output-field)
   (let* ((thread-id