From: F. Jason Park Date: Fri, 15 Jul 2022 12:02:35 +0000 (-0700) Subject: Always run erc-server-send-queue via timer X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=e2130fe9272b6fdc3d32f19734570347a8d580fd;p=emacs.git Always run erc-server-send-queue via timer * lisp/erc/erc-backend.el (erc--server-send, erc-server-send): Convert the latter into a wrapper that calls the former, a "new" internal generic function, so that built-in modules can do things like prepend tags to outgoing messages and send messages over other transports or proxy protocols. Extend the `no-penalty' parameter to mean ERC will schedule an imminent send via a timer. And always run the function `erc-server-send-queue' on a timer. (Bug#67031) --- diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el index 32d891cd1c6..9281c107d06 100644 --- a/lisp/erc/erc-backend.el +++ b/lisp/erc/erc-backend.el @@ -1171,7 +1171,7 @@ Use DISPLAY-FN to show the results." When FORCE is non-nil, bypass flood protection so that STRING is sent directly without modifying the queue. When FORCE is the symbol `no-penalty', exempt this round from accumulating a -timeout penalty. +timeout penalty and schedule it to run ASAP instead of blocking. If TARGET is specified, look up encoding information for that channel in `erc-encoding-coding-alist' or @@ -1179,6 +1179,11 @@ channel in `erc-encoding-coding-alist' or See `erc-server-flood-margin' for an explanation of the flood protection algorithm." + (erc--server-send string force target)) + +(cl-defmethod erc--server-send (string force target) + "Encode and send STRING to `erc-server-process'. +Expect STRING, FORCE, and TARGET to originate from `erc-server-send'." (erc-log (concat "erc-server-send: " string "(" (buffer-name) ")")) (setq erc-server-last-sent-time (erc-current-time)) (let ((encoding (erc-coding-system-for-target target))) @@ -1199,14 +1204,17 @@ protection algorithm." (when (fboundp 'set-process-coding-system) (set-process-coding-system erc-server-process 'raw-text encoding)) - (process-send-string erc-server-process str)) + (if (and (eq force 'no-penalty)) + (run-at-time nil nil #'process-send-string + erc-server-process str) + (process-send-string erc-server-process str))) ;; See `erc-server-send-queue' for full ;; explanation of why we need this condition-case (error nil))) (setq erc-server-flood-queue (append erc-server-flood-queue (list (cons str encoding)))) - (erc-server-send-queue (current-buffer)))) + (run-at-time nil nil #'erc-server-send-queue (current-buffer)))) t) (message "ERC: No process running") nil)))