Subject: Re: bug#66073: 30.0.50; ERC 5.6: Improve handling of blank lines at ERC's prompt

From: "J.P." <[email-masked]>
Date: Wed, 06 Dec 2023 23:24:43 -0800

Changes from this bug attempted to fix a number of historical behavioral
quirks related to intercepting and validating prompt input preflight.
One thing they glossed over was not dealing with the confusing "No
process running" warning issued when a user submits input in an orphaned
target buffer. This unfortunate behavior has been with ERC for ages and
might well be cemented into the wider user "ecosystem" such that fixing
it interferes with things like a `condition-case' handler matching
against the exact wording, etc. However, given the annoying nature of
this style of input feedback, I think it makes sense to bite the bullet
here and just chance a minimally churn-inducing change. See attached.

>From 62797d2b97fd8aa00dd45f778555f3c78ea1a6c1 Mon Sep 17 00:00:00 2001
From: "F. Jason Park" <[email-masked]>
Date: Mon, 27 Nov 2023 19:41:09 -0800
Subject: [PATCH 08/11] [5.6] Clarify warning for process-dependent input in
 ERC

* lisp/erc/erc.el (erc--check-prompt-input-for-running-process):
Resolve dissonance between content of ancient `user-error' message and
condition that triggered it by favoring the former because it's
supported by the underlying mechanism, which revolves around the
`process-not-needed' symbol property.
* test/lisp/erc/erc-tests.el (erc--check-prompt-input-functions):
Revise expected output for error assertion.  (Bug#66073, originally
from bug#54536)
---
 lisp/erc/erc.el            | 17 +++++++++++++----
 test/lisp/erc/erc-tests.el |  4 ++--
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el
index 3e45949688d..98621302abd 100644
--- a/lisp/erc/erc.el
+++ b/lisp/erc/erc.el
@@ -7318,11 +7318,20 @@ erc--check-prompt-input-for-point-in-bounds
   (when (< (point) (erc-beg-of-input-line))
     "Point is not in the input area"))
 
+;; Originally, `erc-send-current-line' inhibited sends whenever a
+;; server buffer was missing.  In 2007, this was narrowed to
+;; occurrences involving process-dependent commands.  However, the
+;; accompanying error message, which was identical to that emitted by
+;; `erc-server-send', "ERC: No process running", was always inaccurate
+;; because a server buffer can be alive and its process dead.
 (defun erc--check-prompt-input-for-running-process (string _)
-  "Return non-nil unless in an active ERC server buffer."
-  (unless (or (erc-server-buffer-live-p)
-              (erc-command-no-process-p string))
-    "ERC: No process running"))
+  "Return non-nil if STRING is a slash command missing a process.
+Also do so when the server buffer has been killed."
+  ;; Even if the server buffer has been killed, the user should still
+  ;; be able /reconnect and recall previous commands.
+  (and (not (erc-command-no-process-p string))
+       (or (and (not (erc-server-buffer-live-p)) "Server buffer missing")
+           (and (not (erc-server-process-alive)) "Process not running"))))
 
 (defun erc--check-prompt-input-for-multiline-command (line lines)
   "Return non-nil when non-blank lines follow a command line."
diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el
index ac6eb6b5e3c..eb954112ce8 100644
--- a/test/lisp/erc/erc-tests.el
+++ b/test/lisp/erc/erc-tests.el
@@ -1414,9 +1414,9 @@ erc--check-prompt-input-functions
        (ert-info ("Input remains untouched")
          (should (save-excursion (erc-bol) (looking-at "/msg #chan hi")))))
 
-     (ert-info ("Errors when no process running")
+     (ert-info ("Errors when server buffer absent")
        (let ((e (should-error (erc-send-current-line))))
-         (should (equal "ERC: No process running" (cadr e))))
+         (should (equal "Server buffer missing" (cadr e))))
        (ert-info ("Input remains untouched")
          (should (save-excursion (erc-bol) (looking-at "/msg #chan hi")))))
 
-- 
2.42.0