[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 10237840d0 24/25: Optionally prevent sending multiline input in E
From: |
F. Jason Park |
Subject: |
master 10237840d0 24/25: Optionally prevent sending multiline input in ERC |
Date: |
Thu, 30 Jun 2022 18:29:54 -0400 (EDT) |
branch: master
commit 10237840d03c4ba647fd3045ee500af950a5df6e
Author: F. Jason Park <jp@neverwas.me>
Commit: F. Jason Park <jp@neverwas.me>
Optionally prevent sending multiline input in ERC
* lisp/erc/erc.el (erc-inhibit-multiline-input): Add option to cap the
number of lines to be sent before admonishing the user.
(erc-ask-about-multiline-input): Add option to ask instead of warning
user when `erc-inhibit-multiline-input' is reached.
(erc--check-prompt-input-for-excess-lines): Add validator to possibly
warn when too many lines are submitted for transmission.
* test/lisp/erc/erc-tests.el
(erc--check-prompt-input-for-excess-lines): Add test.
(Bug#54536)
---
lisp/erc/erc.el | 34 +++++++++++++++++++++++++++++++++-
test/lisp/erc/erc-tests.el | 25 +++++++++++++++++++++++++
2 files changed, 58 insertions(+), 1 deletion(-)
diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el
index 89ce713fe0..6f17e4ee7b 100644
--- a/lisp/erc/erc.el
+++ b/lisp/erc/erc.el
@@ -260,6 +260,20 @@ node `(auth) Top' and info node `(erc) Connecting'.")
:group 'erc
:type 'boolean)
+(defcustom erc-inhibit-multiline-input nil
+ "Conditionally disallow input consisting of multiple lines.
+Issue an error when the number of input lines submitted for
+sending exceeds this value."
+ :package-version '(ERC . "5.4.1") ; FIXME match to next release
+ :group 'erc
+ :type '(choice integer boolean))
+
+(defcustom erc-ask-about-multiline-input nil
+ "Ask to ignore `erc-inhibit-multiline-input' when tripped."
+ :package-version '(ERC . "5.4.1") ; FIXME match to next release
+ :group 'erc
+ :type 'boolean)
+
(defcustom erc-prompt-hidden ">"
"Text to show in lieu of the prompt when hidden."
:package-version '(ERC . "5.4.1") ; FIXME increment on next ELPA release
@@ -5890,6 +5904,23 @@ is empty or consists of one or more spaces, tabs, or
form-feeds."
(string-match (rx bot (* (in " \t\f")) eot) line))
(throw 'return t))))))
+(defun erc--check-prompt-input-for-excess-lines (_ lines)
+ "Return non-nil when trying to send too many LINES."
+ (when erc-inhibit-multiline-input
+ ;; Assume `erc--discard-trailing-multiline-nulls' is set to run
+ (let ((reversed (seq-drop-while #'string-empty-p (reverse lines)))
+ (max (if (eq erc-inhibit-multiline-input t)
+ 2
+ erc-inhibit-multiline-input))
+ (seen 0)
+ msg)
+ (while (and (pop reversed) (< (cl-incf seen) max)))
+ (when (= seen max)
+ (setq msg (format "(exceeded by %d)" (1+ (length reversed))))
+ (unless (and erc-ask-about-multiline-input
+ (y-or-n-p (concat "Send input " msg "?")))
+ (concat "Too many lines " msg))))))
+
(defun erc--check-prompt-input-for-multiline-blanks (_ lines)
"Return non-nil when multiline prompt input has blank LINES."
(when (erc--blank-in-multiline-input-p lines)
@@ -5911,7 +5942,8 @@ is empty or consists of one or more spaces, tabs, or
form-feeds."
(defvar erc--check-prompt-input-functions
'(erc--check-prompt-input-for-point-in-bounds
erc--check-prompt-input-for-multiline-blanks
- erc--check-prompt-input-for-running-process)
+ erc--check-prompt-input-for-running-process
+ erc--check-prompt-input-for-excess-lines)
"Validators for user input typed at prompt.
Called with latest input string submitted by user and the list of
lines produced by splitting it. If any member function returns
diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el
index 986988a335..62bea8fb3f 100644
--- a/test/lisp/erc/erc-tests.el
+++ b/test/lisp/erc/erc-tests.el
@@ -797,6 +797,31 @@
(should (equal (funcall next) '("there\n" nil t)))
(should-not (funcall next))))))
+(ert-deftest erc--check-prompt-input-for-excess-lines ()
+ (ert-info ("Without `erc-inhibit-multiline-input'")
+ (should-not erc-inhibit-multiline-input)
+ (should-not (erc--check-prompt-input-for-excess-lines "" '("a" "b"))))
+
+ (ert-info ("With `erc-inhibit-multiline-input' as t (2)")
+ (let ((erc-inhibit-multiline-input t))
+ (should-not (erc--check-prompt-input-for-excess-lines "" '("a")))
+ (should-not (erc--check-prompt-input-for-excess-lines "" '("a" "")))
+ (should (erc--check-prompt-input-for-excess-lines "" '("a" "b")))))
+
+ (ert-info ("With `erc-inhibit-multiline-input' as 3")
+ (let ((erc-inhibit-multiline-input 3))
+ (should-not (erc--check-prompt-input-for-excess-lines "" '("a" "b")))
+ (should-not (erc--check-prompt-input-for-excess-lines "" '("a" "b" "")))
+ (should (erc--check-prompt-input-for-excess-lines "" '("a" "b" "c")))))
+
+ (ert-info ("With `erc-ask-about-multiline-input'")
+ (let ((erc-inhibit-multiline-input t)
+ (erc-ask-about-multiline-input t))
+ (ert-simulate-keys '(?n ?\r ?y ?\r)
+ (should (erc--check-prompt-input-for-excess-lines "" '("a" "b")))
+ (should-not (erc--check-prompt-input-for-excess-lines "" '("a" "b")))))
+ (should-not erc-ask-about-multiline-input)))
+
;; The point of this test is to ensure output is handled identically
;; regardless of whether a command handler is summoned.
- master 752e860db4 16/25: Address long-standing ERC buffer-naming issues, (continued)
- master 752e860db4 16/25: Address long-standing ERC buffer-naming issues, F. Jason Park, 2022/06/30
- master 85c2f3bc3e 25/25: Update ERC's Info doc with network-ID related changes, F. Jason Park, 2022/06/30
- master 54414ec846 02/25: Initialize erc-server-filter-data in erc-backend, F. Jason Park, 2022/06/30
- master 4e312c07f7 11/25: Make ERC respect spaces in server passwords, F. Jason Park, 2022/06/30
- master 485b84cb7c 08/25: Require erc-networks in erc.el, F. Jason Park, 2022/06/30
- master c356f86b51 09/25: Update ISUPPORT handling in ERC, F. Jason Park, 2022/06/30
- master 1c24af0fcb 12/25: Add helper to determine local channels in ERC, F. Jason Park, 2022/06/30
- master 529e46f128 13/25: Add eventual replacement for erc-default-recipients, F. Jason Park, 2022/06/30
- master 1767b0bd7e 19/25: Don't call erc-auto-query twice on PRIVMSG, F. Jason Park, 2022/06/30
- master 7c47d6c52d 18/25: Register erc-kill-buffer-function locally, F. Jason Park, 2022/06/30
- master 10237840d0 24/25: Optionally prevent sending multiline input in ERC,
F. Jason Park <=
- master 9be08ceb31 15/25: Add ERC test server and related resources, F. Jason Park, 2022/06/30
- master 922ad23840 17/25: Add user-oriented test scenarios for ERC, F. Jason Park, 2022/06/30
- master e958a2b726 14/25: Discourage ill-defined use of buffer targets in ERC, F. Jason Park, 2022/06/30
- master 959fbcf34b 20/25: Favor network identities in erc-join, F. Jason Park, 2022/06/30
- master a9d89d083a 22/25: Fix regression in erc-send-input-line, F. Jason Park, 2022/06/30
- master 0590224343 21/25: Standardize auth-source queries in ERC, F. Jason Park, 2022/06/30
- master f46547294d 23/25: Improve ERC's handling of multiline prompt input, F. Jason Park, 2022/06/30