From 4ed6ba90e7c4d2148a7bb1d2ff1027ebc765f606 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Mon, 18 Sep 2023 03:39:57 -0700 Subject: [PATCH] Allow opting out of empty message padding in ERC * lisp/erc/erc.el (erc--allow-empty-outgoing-lines-p): New internal variable. (erc-send-input-line, erc--run-send-hooks): Don't pad output when `erc--allow-empty-outgoing-lines-p' is non-nil. (Bug#67031) --- lisp/erc/erc.el | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index c9c24f2642f..6d7251f0677 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -3684,6 +3684,11 @@ This is for special cases in which a \"slash\" command needs details about the input it's handling or needs to detect whether it's been dispatched by `erc-send-current-line'.") +(defvar erc--allow-empty-outgoing-lines-p nil + "Flag to opt out of last-minute padding of empty lines. +Useful to extensions, like `multiline', and for interop with +IRC-adjacent protocols.") + (defvar-local erc-send-input-line-function #'erc-send-input-line "Function for sending lines lacking a leading \"slash\" command. When prompt input starts with a \"slash\" command, like \"/MSG\", @@ -3697,7 +3702,7 @@ for other purposes.") (defun erc-send-input-line (target line &optional force) "Send LINE to TARGET." - (when (string= line "\n") + (when (and (not erc--allow-empty-outgoing-lines-p) (string= line "\n")) (setq line " \n")) (erc-message "PRIVMSG" (concat target " " line) force)) @@ -7033,9 +7038,11 @@ queue. Expect LINES-OBJ to be an `erc--input-split' object." (erc--input-split-insertp lines-obj) (erc-input-insertp state) ;; See note in test of same name re trailing newlines. (erc--input-split-lines lines-obj) - (cl-nsubst " " "" (split-string (erc-input-string state) - erc--input-line-delim-regexp) - :test #'equal)) + (let ((lines (split-string (erc-input-string state) + erc--input-line-delim-regexp))) + (if erc--allow-empty-outgoing-lines-p + lines + (cl-nsubst " " "" lines :test #'equal)))) (when (erc-input-refoldp state) (erc--split-lines lines-obj))))) (when (and (erc--input-split-cmdp lines-obj) -- 2.39.2