>From ef467e6e378b1098bfe60ac2ab25270b035a63c0 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Mon, 11 Jul 2022 05:14:57 -0700 Subject: [PATCH 06/10] [POC] Make erc-once-with-server-event more nimble * lisp/erc/erc.el (erc-once-with-server-event, erc-once-more): Allow ephemeral callbacks to indicate a need to postpone cleanup and go another round by signaling the new custom error called `erc-once-again'. Also add new optional `depth' argument to let caller specify a hook depth. --- lisp/erc/erc.el | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index f06bbc6ab0..39ec11c94b 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -1484,7 +1484,9 @@ erc--default-target (when erc--target (erc--target-string erc--target))) -(defun erc-once-with-server-event (event f) +(define-error 'erc-once-again "Untracked server event" 'error) + +(defun erc-once-with-server-event (event f &optional depth) "Run function F the next time EVENT occurs in the `current-buffer'. You should make sure that `current-buffer' is a server buffer. @@ -1507,11 +1509,16 @@ erc-once-with-server-event (hook (erc-get-hook event))) (put fun 'erc-original-buffer (current-buffer)) (fset fun (lambda (proc parsed) - (with-current-buffer (get fun 'erc-original-buffer) - (remove-hook hook fun t)) - (fmakunbound fun) - (funcall f proc parsed))) - (add-hook hook fun nil t) + (let (rv again) + (condition-case _err + (setq rv (funcall f proc parsed)) + (erc-once-again (setq again t))) + (unless again + (with-current-buffer (get fun 'erc-original-buffer) + (remove-hook hook fun t)) + (fmakunbound fun)) + rv))) + (add-hook hook fun depth t) fun)) (define-inline erc-log (string) -- 2.36.1