>From 2476ad0cb7b8016dbef1e41080941a727d2be992 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Mon, 25 Apr 2022 22:42:10 -0700 Subject: [PATCH 0/2] *** NOT A PATCH *** *** BLURB HERE *** F. Jason Park (2): Add some ERC test helpers [SQUASH-ME] Remove duplicate ERC prompt on reconnect lisp/erc/erc-backend.el | 41 ++++++++-- lisp/erc/erc.el | 74 ++++++++++-------- test/lisp/erc/erc-tests.el | 150 +++++++++++++++++++++++++++++++++++-- 3 files changed, 221 insertions(+), 44 deletions(-) Interdiff: diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el index ff5c28b5d8..a09c1608f9 100644 --- a/lisp/erc/erc-backend.el +++ b/lisp/erc/erc-backend.el @@ -713,14 +713,20 @@ erc--hide-prompt (erc-with-all-buffers-of-server proc nil ; sorta wish this was indent 2 (when (and erc-hide-prompt - (memq erc-hide-prompt - (list t (if (erc-default-target) 'target 'server))) + (or (eq erc-hide-prompt t) + ;; FIXME use `erc--target' after bug#48598 + (memq (if (erc-default-target) + (if (erc-channel-p (car erc-default-recipients)) + 'channel + 'query) + 'server) + erc-hide-prompt)) (marker-position erc-insert-marker) (marker-position erc-input-marker) (get-text-property erc-insert-marker 'erc-prompt)) (with-silent-modifications - (add-text-properties erc-insert-marker - erc-input-marker `(display ,erc-prompt-hidden))) + (add-text-properties erc-insert-marker (1- erc-input-marker) + `(display ,erc-prompt-hidden))) (add-hook 'pre-command-hook #'erc--unhide-prompt-on-self-insert 0 t)))) (defun erc-process-sentinel (cproc event) diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index 8ce4e91812..500f8d7406 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -234,14 +234,25 @@ erc-hide-prompt "If non-nil, hide input prompt upon disconnecting. To unhide, type something in the input area. Once revealed, a prompt remains unhidden until the next disconnection. Channel prompts are -unhidden upon rejoining. Query prompts remain hidden until user input -is detected or a new message arrives from the target." +unhidden upon rejoining. See `erc-unhide-query-prompt' for behavior +concerning query prompts." :package-version '(ERC . "5.4.1") ; FIXME increment on next ELPA release :group 'erc-display :type '(choice (const :tag "Always hide prompt" t) - (const :tag "Never hide prompt" nil) - (const :tag "Only hide target prompt" 'target) - (const :tag "Only hide server prompt" 'server))) + (set (const server) + (const query) + (const channel)))) + +(defcustom erc-unhide-query-prompt nil + "When non-nil, always reveal query prompts upon reconnecting. +Otherwise, prompts in a connection's query buffers remain hidden until +the user types in the input area or a new message arrives from the +target." + :package-version '(ERC . "5.4.1") + :group 'erc-display + ;; Extensions may one day offer a way to discover whether a target + ;; is online. When that happens, this can be expanded accordingly. + :type 'boolean) ;; tunable GUI stuff @@ -4722,7 +4733,14 @@ erc-connection-established (erc-update-mode-line) (erc-set-initial-user-mode nick buffer) (erc-server-setup-periodical-ping buffer) - (run-hook-with-args 'erc-after-connect server nick))))) + (run-hook-with-args 'erc-after-connect server nick)))) + + (when erc-unhide-query-prompt + (erc-with-all-buffers-of-server proc + nil ; FIXME use `erc--target' after bug#48598 + (when (and (erc-default-target) + (not (erc-channel-p (car erc-default-recipients)))) + (erc--unhide-prompt))))) (defun erc-set-initial-user-mode (nick buffer) "If `erc-user-mode' is non-nil for NICK, set the user modes. diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el index c1d2196a38..961aab4338 100644 --- a/test/lisp/erc/erc-tests.el +++ b/test/lisp/erc/erc-tests.el @@ -148,6 +148,14 @@ erc-hide-prompt (get-buffer "ServNet")) erc-default-recipients '("#chan"))) + (with-current-buffer (get-buffer-create "bob") + (erc-tests--send-prep) + (goto-char erc-insert-marker) + (should (looking-at-p (regexp-quote erc-prompt))) + (setq erc-server-process (buffer-local-value 'erc-server-process + (get-buffer "ServNet")) + erc-default-recipients '("bob"))) + (ert-info ("Value: t (default)") (should (eq erc-hide-prompt t)) (with-current-buffer "ServNet" @@ -166,6 +174,17 @@ erc-hide-prompt (should-not (memq #'erc--unhide-prompt-on-self-insert pre-command-hook))) + (with-current-buffer "bob" + (goto-char erc-insert-marker) + (should (string= ">" (get-text-property (point) 'display))) + (should (memq #'erc--unhide-prompt-on-self-insert pre-command-hook)) + (goto-char erc-input-marker) + (ert-simulate-command '(self-insert-command 1 ?/)) + (goto-char erc-insert-marker) + (should-not (get-text-property (point) 'display)) + (should-not (memq #'erc--unhide-prompt-on-self-insert + pre-command-hook))) + (with-current-buffer "ServNet" (should (get-text-property erc-insert-marker 'display)) (should (memq #'erc--unhide-prompt-on-self-insert pre-command-hook)) @@ -175,7 +194,7 @@ erc-hide-prompt (should-not (get-text-property erc-insert-marker 'display)))) (ert-info ("Value: server") - (setq erc-hide-prompt 'server) + (setq erc-hide-prompt '(server)) (with-current-buffer "ServNet" (erc--hide-prompt erc-server-process) (should (string= ">" (get-text-property erc-insert-marker 'display)))) @@ -183,27 +202,50 @@ erc-hide-prompt (with-current-buffer "#chan" (should-not (get-text-property erc-insert-marker 'display))) + (with-current-buffer "bob" + (should-not (get-text-property erc-insert-marker 'display))) + (with-current-buffer "ServNet" (erc--unhide-prompt) (should-not (get-text-property erc-insert-marker 'display)))) - (ert-info ("Value: target") - (setq erc-hide-prompt 'target) + (ert-info ("Value: channel") + (setq erc-hide-prompt '(channel)) (with-current-buffer "ServNet" (erc--hide-prompt erc-server-process) (should-not (get-text-property erc-insert-marker 'display))) + (with-current-buffer "bob" + (should-not (get-text-property erc-insert-marker 'display))) + (with-current-buffer "#chan" (should (string= ">" (get-text-property erc-insert-marker 'display))) (erc--unhide-prompt) (should-not (get-text-property erc-insert-marker 'display)))) + (ert-info ("Value: query") + (setq erc-hide-prompt '(query)) + (with-current-buffer "ServNet" + (erc--hide-prompt erc-server-process) + (should-not (get-text-property erc-insert-marker 'display))) + + (with-current-buffer "bob" + (should (string= ">" (get-text-property erc-insert-marker 'display))) + (erc--unhide-prompt) + (should-not (get-text-property erc-insert-marker 'display))) + + (with-current-buffer "#chan" + (should-not (get-text-property erc-insert-marker 'display)))) + (ert-info ("Value: nil") (setq erc-hide-prompt nil) (with-current-buffer "ServNet" (erc--hide-prompt erc-server-process) (should-not (get-text-property erc-insert-marker 'display))) + (with-current-buffer "bob" + (should-not (get-text-property erc-insert-marker 'display))) + (with-current-buffer "#chan" (should-not (get-text-property erc-insert-marker 'display)) (erc--unhide-prompt) ; won't blow up when prompt already showing @@ -211,6 +253,7 @@ erc-hide-prompt (when noninteractive (kill-buffer "#chan") + (kill-buffer "bob") (kill-buffer "ServNet")))) (ert-deftest erc--switch-to-buffer () -- 2.35.1