emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master e2130fe9272 4/9: Always run erc-server-send-queue via timer


From: F. Jason Park
Subject: master e2130fe9272 4/9: Always run erc-server-send-queue via timer
Date: Sun, 12 Nov 2023 23:56:29 -0500 (EST)

branch: master
commit e2130fe9272b6fdc3d32f19734570347a8d580fd
Author: F. Jason Park <jp@neverwas.me>
Commit: F. Jason Park <jp@neverwas.me>

    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)
---
 lisp/erc/erc-backend.el | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

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)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]