From dd9f78ea159958ccef4eabf3f782d4f29d4d24e7 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Mon, 24 Apr 2023 06:29:49 -0700 Subject: [PATCH 0/4] *** NOT A PATCH *** *** BLURB HERE *** F. Jason Park (4): [5.6] Revive option erc-query-on-unjoined-chan-privmsg [5.6] Move ERC's buffer-display tests to separate file [5.6] Extend erc-interactive-display to cover /JOINs [5.6] Ignore erc-reconnect-display after a timeout etc/ERC-NEWS | 36 ++- lisp/erc/erc-backend.el | 41 ++- lisp/erc/erc.el | 160 ++++++++---- test/lisp/erc/erc-scenarios-base-attach.el | 191 ++++++++++++++ .../erc/erc-scenarios-base-buffer-display.el | 236 ++++++++++++++++++ test/lisp/erc/erc-scenarios-base-reconnect.el | 89 ------- test/lisp/erc/erc-tests.el | 13 +- .../base/channel-buffer-revival/reattach.eld | 56 +++++ 8 files changed, 660 insertions(+), 162 deletions(-) create mode 100644 test/lisp/erc/erc-scenarios-base-attach.el create mode 100644 test/lisp/erc/erc-scenarios-base-buffer-display.el create mode 100644 test/lisp/erc/resources/base/channel-buffer-revival/reattach.eld Interdiff: diff --git a/etc/ERC-NEWS b/etc/ERC-NEWS index e9de48b2e34..f1fac8e5baa 100644 --- a/etc/ERC-NEWS +++ b/etc/ERC-NEWS @@ -48,9 +48,16 @@ of interactive invocations, hence the borrowing of an old option, 'erc-query-display', and the bestowing of a new alias, 'erc-interactive-display', which better describes its expanded role as a more general buffer-display knob for interactive commands ("/QUERY" -still among them). Accompanying this addition are "display"-suffixed -aliases for related options 'erc-join-buffer' and 'erc-auto-query', -which users have reported as being difficult to discover and remember. +still among them). + +Accompanying this addition are "display"-suffixed aliases for related +options 'erc-join-buffer' and 'erc-auto-query', which users have +reported as being difficult to discover and remember. As for the +latter option specifically (now known as 'erc-receive-query-display'), +assigning it a nil value now tells ERC to use 'erc-join-buffer' in its +place, much like with related buffer-display options, like +'erc-interactive-display'. The old nil behavior can still be gotten +via a new compatibility flag, 'erc-receive-query-display-defer'. ** Setting a module's mode variable via Customize earns a warning. Trying and failing to activate a module via its minor mode's Custom @@ -111,7 +118,8 @@ other than the symbol 'erc-button-buttonize-nicks' appearing in the "FORM" field (third element) of this entry are considered deprecated and will incur a warning. -** The option erc-query-on-unjoined-chan-privmsg has been restored. +** The option 'erc-query-on-unjoined-chan-privmsg' has been restored. +(Although it's now called 'erc-ensure-target-buffer-on-privmsg'.) In ERC 5.5, this option was removed from the default client code and thus prevented from influencing PRIVMSG handling because its precise purpose could not be determined with any confidence. After some diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el index c72c769f2e1..d14640e798d 100644 --- a/lisp/erc/erc-backend.el +++ b/lisp/erc/erc-backend.el @@ -102,11 +102,11 @@ (require 'erc-common) (defvar erc--target) -(defvar erc-auto-query) (defvar erc-channel-list) (defvar erc-channel-users) (defvar erc-default-nicks) (defvar erc-default-recipients) +(defvar erc-ensure-target-buffer-on-privmsg) (defvar erc-format-nick-function) (defvar erc-format-query-as-channel-p) (defvar erc-hide-prompt) @@ -123,7 +123,8 @@ erc-nick (defvar erc-nick-change-attempt-count) (defvar erc-prompt-for-channel-key) (defvar erc-prompt-hidden) -(defvar erc-query-on-unjoined-chan-privmsg) +(defvar erc-receive-query-display) +(defvar erc-receive-query-display-defer) (defvar erc-reuse-buffers) (defvar erc-verbose-server-ping) (defvar erc-whowas-on-nosuchnick) @@ -1854,11 +1855,15 @@ define-erc-response-handler (unless (or buffer noticep (string-empty-p tgt) (eq ?$ (aref tgt 0)) (erc-is-message-ctcp-and-not-action-p msg)) (if privp - (when erc-auto-query - (let ((erc-join-buffer erc-auto-query)) - (setq buffer (erc--open-target nick)))) - ;; A channel buffer has been killed but is still joined - (when erc-query-on-unjoined-chan-privmsg + (when-let ((erc-join-buffer + (or (and (not erc-receive-query-display-defer) + erc-receive-query-display) + (and erc-ensure-target-buffer-on-privmsg + (or erc-receive-query-display + erc-join-buffer))))) + (setq buffer (erc--open-target nick))) + ;; A channel buffer has been killed but is still joined. + (when erc-ensure-target-buffer-on-privmsg (setq buffer (erc--open-target tgt))))) (when buffer (with-current-buffer buffer diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index 85b3d8bb650..847e27904b1 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -1521,16 +1521,16 @@ erc-buffer-display `bury' - bury it in a new buffer, `buffer' - in place of the current buffer, -See related options `erc-interactive-display' and -`erc-reconnect-display' as well as `erc-receive-query-display', -which resides in the customization group `erc-query'." +See related options `erc-interactive-display', +`erc-reconnect-display', and `erc-receive-query-display'." :package-version '(ERC . "5.5") :group 'erc-buffers :type '(choice (const :tag "Split window and select" window) (const :tag "Split window, don't select" window-noselect) (const :tag "New frame" frame) (const :tag "Bury in new buffer" bury) - (const :tag "Use current buffer" buffer))) + (const :tag "Use current buffer" buffer) + (const :tag "Use current buffer" t))) (defvaralias 'erc-query-display 'erc-interactive-display) (defcustom erc-interactive-display 'window @@ -1557,7 +1557,7 @@ erc-reconnect-display `erc-buffer-display' for a description of possible values." :package-version '(ERC . "5.5") :group 'erc-buffers - :type '(choice (const :tag "Use value of `erc-join-buffer'" nil) + :type '(choice (const :tag "Use value of `erc-buffer-display'" nil) (const :tag "Split window and select" window) (const :tag "Split window, don't select" window-noselect) (const :tag "New frame" frame) @@ -1569,7 +1569,7 @@ erc-reconnect-display-timeout The countdown starts on MOTD and is canceled early by any \"slash\" command." :type 'integer - :group 'erc-buffer) + :group 'erc-buffers) (defcustom erc-frame-alist nil "Alist of frame parameters for creating erc frames. @@ -3984,7 +3984,7 @@ erc-cmd-QUOTE (defun erc-cmd-QUERY (&optional user) "Open a query with USER. How the query is displayed (in a new window, frame, etc.) depends -on the value of `erc-query-display'." +on the value of `erc-interactive-display'." ;; FIXME: The doc string used to say at the end: ;; "If USER is omitted, close the current query buffer if one exists ;; - except this is broken now ;-)" @@ -3995,8 +3995,8 @@ erc-cmd-QUERY (unless user ;; currently broken, evil hack to display help anyway ;(erc-delete-query)))) - (signal 'wrong-number-of-arguments "")) - (let ((erc-join-buffer erc-query-display)) + (signal 'wrong-number-of-arguments '(erc-cmd-QUERY 0))) + (let ((erc-join-buffer erc-interactive-display)) (erc-with-server-buffer (erc--open-target user)))) @@ -4747,44 +4747,64 @@ erc-query (defvaralias 'erc-auto-query 'erc-receive-query-display) (defcustom erc-receive-query-display 'window-noselect - "How to display a query buffer when you receive a private message. + "If non-nil, create a query buffer each time you receive a private message. If the buffer doesn't already exist, it is created. This can be set to a symbol, to control how the new query window should appear. The default behavior is to display the buffer in -a new window, but not to select it. See the documentation for -`erc-buffer-display' for a description of available values. Note -that setting this option to nil forgoes buffer creation entirely. -It does not mean \"fall back on `erc-buffer-display'\", like it -does for buffer-display options, like `erc-interactive-display', -that reside in the customization group `erc-buffers'." +a new window but not to select it. See the documentation for +`erc-buffer-display' for a description of available values. + +Note that the legacy behavior of forgoing buffer creation +entirely when this option is nil requires setting the +compatibility flag `erc-receive-query-display-defer' to nil. Use +`erc-ensure-target-buffer-on-privmsg' to achieve the same effect." + :package-version '(ERC . "5.6") + :group 'erc-buffers :group 'erc-query - :type '(choice (const :tag "Don't create query window" nil) + :type '(choice (const :tag "Defer to value of `erc-buffer-display'" nil) (const :tag "Split window and select" window) (const :tag "Split window, don't select" window-noselect) (const :tag "New frame" frame) (const :tag "Bury in new buffer" bury) - (const :tag "Use current buffer" buffer))) + (const :tag "Use current buffer" buffer) + (const :tag "Use current buffer" t))) + +(defcustom erc-receive-query-display-defer t + "How to interpret a null `erc-receive-query-display'. +When this option is non-nil, ERC defers to `erc-buffer-display' +upon seeing a nil value for `erc-receive-query-display', much +like it does with other buffer-display options, like +`erc-interactive-display'. Otherwise, when this option is nil, +ERC retains the legacy behavior of not creating a new query +buffer." + :package-version '(ERC . "5.6") + :group 'erc-buffers + :group 'erc-query + :type 'boolean) -(defcustom erc-query-on-unjoined-chan-privmsg t - "If non-nil create query buffer on receiving any PRIVMSG at all. +(defvaralias 'erc-query-on-unjoined-chan-privmsg + 'erc-ensure-target-buffer-on-privmsg) +(defcustom erc-ensure-target-buffer-on-privmsg t + "When non-nil, create a target buffer upon receiving a PRIVMSG. This includes PRIVMSGs directed to channels. If you are using an IRC bouncer, such as dircproxy, to keep a log of channels when you are disconnected, you should set this option to t. +For queries (direct messages), this option's non-nil meaning is +straightforward: if a buffer doesn't exist for the sender, create +one. For channels, the use case is more niche and usually +involves receiving playback (via commands like ZNC's +\"PLAYBUFFER\") for channels to which your bouncer is joined but +from which you've \"detached\". + Note that this option was absent from ERC 5.5 because knowledge of its intended role was \"unavailable\" during a major refactoring involving buffer management. The option has since -been restored in ERC 5.6 with the caveat that its purpose is -assumed to more or less reflect the following, which can be -thought of as an updated version of the paragraph above: - -If non-nil, create a channel buffer on receiving a PRIVMSG if -none exists. This only affects messages targeting a channel -whose buffer was killed but to which you're still joined or one -whose buffer never existed, presumably because a bouncer is -sending playback summoned with a command similar to ZNC's -PLAYBUFFER." +been restored in ERC 5.6 but now also affects queries in the +manner implied above, which was lost sometime before ERC 5.4." + :package-version '(ERC . "5.6") ; revived + :group 'erc-buffers :group 'erc-query :type 'boolean) diff --git a/test/lisp/erc/erc-scenarios-base-attach.el b/test/lisp/erc/erc-scenarios-base-attach.el index 91763842879..ccf5d1f9582 100644 --- a/test/lisp/erc/erc-scenarios-base-attach.el +++ b/test/lisp/erc/erc-scenarios-base-attach.el @@ -61,9 +61,9 @@ (let ((load-path (cons (ert-resource-directory) load-path))) (require 'erc-scenarios-common))) -(ert-deftest erc-scenarios-base-attach--query-on-unjoined-enabled () +(ert-deftest erc-scenarios-base-attach--ensure-target-buffer--enabled () :tags '(:expensive-test) - (should erc-query-on-unjoined-chan-privmsg) + (should erc-ensure-target-buffer-on-privmsg) (erc-scenarios-common-with-cleanup ((erc-scenarios-common-dialog "base/channel-buffer-revival") @@ -103,16 +103,16 @@ erc-scenarios-base-attach--query-on-unjoined-enabled (erc-scenarios-common-say "bob: hi") (funcall expect 10 "Pawn me to this"))))) -(ert-deftest erc-scenarios-base-attach--query-on-unjoined-disabled () +(ert-deftest erc-scenarios-base-attach--ensure-target-buffer--disabled () :tags '(:expensive-test) - (should erc-query-on-unjoined-chan-privmsg) + (should erc-ensure-target-buffer-on-privmsg) (erc-scenarios-common-with-cleanup ((erc-scenarios-common-dialog "base/channel-buffer-revival") (dumb-server (erc-d-run "localhost" t 'reattach)) (port (process-contact dumb-server :service)) (erc-server-flood-penalty 0.1) - (erc-query-on-unjoined-chan-privmsg nil) ; off + (erc-ensure-target-buffer-on-privmsg nil) ; off (expect (erc-d-t-make-expecter))) (ert-info ("Connect to foonet") @@ -144,4 +144,48 @@ erc-scenarios-base-attach--query-on-unjoined-disabled (erc-scenarios-common-say "bob: hi") (funcall expect 10 "Pawn me to this"))))) + +;; We omit the `enabled' case for queries because it's the default for +;; this option and already covered many times over by other tests in +;; this directory. + +(ert-deftest erc-scenarios-base-attach--ensure-target-buffer--disabled-query () + :tags '(:expensive-test) + (should erc-ensure-target-buffer-on-privmsg) + + (erc-scenarios-common-with-cleanup + ((erc-scenarios-common-dialog "base/assoc/queries") + (dumb-server (erc-d-run "localhost" t 'non-erc)) + (port (process-contact dumb-server :service)) + (expect (erc-d-t-make-expecter)) + (erc-ensure-target-buffer-on-privmsg nil) + (erc-server-flood-penalty 0.1)) + + (ert-info ("Connect to foonet") + (with-current-buffer (erc :server "127.0.0.1" + :port port + :nick "tester" + :user "tester" + :full-name "tester") + (erc-scenarios-common-assert-initial-buf-name nil port) + (erc-d-t-wait-for 5 (eq erc-network 'foonet)) + (funcall expect 15 "debug mode"))) + + (ert-info ("User dummy's greeting appears in server buffer") + (erc-d-t-wait-for -1 (get-buffer "dummy")) + (with-current-buffer "foonet" + (funcall expect 5 "hi") + + (ert-info ("Option being nil doesn't queries we create") + (with-current-buffer (erc-cmd-QUERY "nitwit") + (should (equal (buffer-name) "nitwit")) + (erc-scenarios-common-say "hola") + (funcall expect 5 "ciao"))) + + (erc-scenarios-common-say "howdy") + (funcall expect 5 "no target") + (erc-cmd-MSG "dummy howdy") + (funcall expect 5 "bye") + (erc-cmd-QUIT ""))))) + ;;; erc-scenarios-base-attach.el ends here -- 2.39.2