>From aaf22460711d8d669da296dfbf024053270e1cef Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Tue, 17 May 2022 05:43:52 -0700 Subject: [PATCH 0/4] *** NOT A PATCH *** *** BLURB HERE *** F. Jason Park (4): Fix regression in erc-send-input-line Add some ERC test helpers Improve ERC's handling of multiline prompt input Optionally prevent sending multiline input in ERC lisp/erc/erc.el | 195 +++++++++++++++++++++------ test/lisp/erc/erc-tests.el | 267 +++++++++++++++++++++++++++++++++++-- 2 files changed, 410 insertions(+), 52 deletions(-) Interdiff: diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index 14194492e8..17bf3c9c0c 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -1068,11 +1068,12 @@ erc-pre-send-functions :type 'hook :version "27.1") -;; This is being auditioned for possible exporting (as a custom +;; This is being auditioned for possible exporting (as a custom hook ;; option). Likewise for (public versions of) `erc--input-split' and ;; `erc--discard-trailing-multiline-nulls'. If unneeded, we'll just ;; run the latter on the input after `erc-pre-send-functions', and -;; remove this hook and the struct completely. +;; remove this hook and the struct completely. It you need this, +;; please say so! (defvar erc--pre-send-split-functions '(erc--discard-trailing-multiline-nulls) "Special hook for modifying individual lines in multiline prompt input. @@ -5594,18 +5595,6 @@ erc--blank-in-multiline-input-p (string-match (rx bot (* (in " \t\f")) eot) line)) (throw 'return t)))))) -(defun erc--discard-trailing-multiline-nulls (state) - "Ensure last line of `erc-input' STATE's string is non-null. -But only when `erc-send-whitespace-lines' is non-nil." - (when erc-send-whitespace-lines - (when (string-match "[\r\n]+\\'" (erc-input-string state)) - (setf (erc--input-split-lines state) - (split-string (substring (erc-input-string state) - 0 - (match-beginning 0)) - erc--input-line-delim-regexp) - (erc--input-split-cmdp state) nil)))) - (defun erc--check-prompt-input-for-excess-lines (_ lines) "Return non-nil when trying to send too many LINES." (when erc-inhibit-multiline-input @@ -5715,6 +5704,17 @@ erc-input (cl-defstruct (erc--input-split (:include erc-input)) lines cmdp) +(defun erc--discard-trailing-multiline-nulls (state) + "Ensure last line of STATE's string is non-null. +But only when `erc-send-whitespace-lines' is non-nil. STATE is an +`erc--input-split' object." + (when (and erc-send-whitespace-lines (erc--input-split-lines state)) + (let ((reversed (nreverse (erc--input-split-lines state)))) + (when (string-empty-p (car reversed)) + (pop reversed) + (setf (erc--input-split-cmdp state) nil)) + (nreverse (seq-drop-while #'string-empty-p reversed))))) + (defun erc-send-input (input &optional skip-ws-chk) "Treat INPUT as typed in by the user. It is assumed that the input and the prompt is already deleted. diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el index fa39f4fcc6..e956538afa 100644 --- a/test/lisp/erc/erc-tests.el +++ b/test/lisp/erc/erc-tests.el @@ -115,6 +115,8 @@ erc-with-all-buffers-of-server (kill-buffer "#spam"))) (defun erc-tests--send-prep () + ;; Caller should probably shadow `erc-insert-modify-hook' or + ;; populate user tables for erc-button. (erc-mode) (insert "\n\n") (setq erc-input-marker (make-marker) @@ -483,13 +485,19 @@ erc-send-whitespace-lines (should-not (funcall next))) (ert-info ("Multiline command with trailing blank filtered") - (insert "/msg #chan hi\r") - (erc-send-current-line) - (ert-info ("Input cleared") + (pcase-dolist (`(,p . ,q) + '(("/a b\r" "/a b\n") ("/a b\n" "/a b\n") + ("/a b\n\n" "/a b\n") ("/a b\r\n" "/a b\n") + ("a b\nc\n\n" "c\n" "a b\n") + ("/a b\nc\n\n" "c\n" "/a b\n") + ("/a b\n\nc\n\n" "c\n" "\n" "/a b\n"))) + (insert p) + (erc-send-current-line) (erc-bol) - (should (eq (point) (point-max)))) - (should (equal (funcall next) '("/msg #chan hi\n" nil t))) - (should-not (funcall next))) + (should (eq (point) (point-max))) + (while q + (should (equal (funcall next) (list (pop q) nil t)))) + (should-not (funcall next)))) (ert-info ("Multiline hunk with trailing whitespace not filtered") (insert "there\n ") -- 2.36.1