From d5ac6679df4925ef51cc0f299af2a84f27faafe7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mattias=20Engdeg=C3=A5rd?= Date: Wed, 18 Nov 2020 10:55:41 +0100 Subject: [PATCH] Turn gdb-wait-for-pending into a plain function MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/lisp/progmodes/gdb-mi.el b/lisp/progmodes/gdb-mi.el index 0023e1fb5d0..903005610d7 100644 --- a/lisp/progmodes/gdb-mi.el +++ b/lisp/progmodes/gdb-mi.el @@ -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 -- 2.39.5