From a3bd16a010472ca6b4ce54cb5230f246e84c685d Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Fri, 15 Jul 2022 05:02:35 -0700 Subject: [PATCH 2/6] [5.6] Make ERC's message-sending functions more flexible * lisp/erc/erc-backend.el (erc--server-send, erc-server-send): Convert the latter to a wrapper that calls the former, a "new" internal generic function. Extend `no-penalty' parameter to mean ERC will schedule an imminent send via a timer. Always run `erc-server-send-queue' on a timer. * lisp/erc/erc.el (erc-send-action, erc--send-action): Make former a wrapper for latter, a new generic function. The rationale is that built-in modules should be able to elect to handle insertion themselves. Also fix bug involving /ME ACTIONs not having `erc-my-nick-face' applied to the speaker. (erc-send-message, erc--send-message): Make the former a wrapper for the latter, a new generic function. Since commands, like /SV, use this function to handle their own insertion, modules can't leverage the normal API to suppress insertion. (erc--send-input-lines): Convert to generic function. --- lisp/erc/erc-backend.el | 12 +++++++++--- lisp/erc/erc.el | 11 +++++++++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el index 32d891cd1c6..b16824b1f73 100644 --- a/lisp/erc/erc-backend.el +++ b/lisp/erc/erc-backend.el @@ -1171,7 +1171,7 @@ erc-server-send 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,9 @@ erc-server-send 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) (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 +1202,17 @@ erc-server-send (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))) diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index 2d8f388328d..a885038411d 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -2950,13 +2950,17 @@ erc-toggle-debug-irc-protocol (defun erc-send-action (tgt str &optional force) "Send CTCP ACTION information described by STR to TGT." + (erc--send-action tgt str force)) + +(cl-defmethod erc--send-action (tgt str &optional force) (erc-send-ctcp-message tgt (format "ACTION %s" str) force) ;; Allow hooks that act on inserted PRIVMSG and NOTICES to process us. (let ((erc--msg-prop-overrides `((erc-msg . msg) (erc-ctcp . ACTION) ,@erc--msg-prop-overrides)) (nick (erc-current-nick))) - (setq nick (propertize nick 'erc-speaker nick)) + (setq nick (propertize nick 'erc-speaker nick + 'font-lock-face 'erc-my-nick-face)) (erc-display-message nil '(t action input) (current-buffer) 'ACTION ?n nick ?a str ?u "" ?h ""))) @@ -4493,6 +4497,9 @@ erc-send-message "Send LINE to the current channel or user and display it. See also `erc-message' and `erc-display-line'." + (erc--send-message line force)) + +(cl-defgeneric erc--send-message (line force) (erc-message "PRIVMSG" (concat (erc-default-target) " " line) force) (erc-display-line (concat (erc-format-my-nick) line) @@ -6978,7 +6985,7 @@ erc--run-send-hooks (user-error "Multiline command detected" )) lines-obj) -(defun erc--send-input-lines (lines-obj) +(cl-defmethod erc--send-input-lines (lines-obj) "Send lines in `erc--input-split-lines' object LINES-OBJ." (when (erc--input-split-sendp lines-obj) (dolist (line (erc--input-split-lines lines-obj)) -- 2.41.0