Fix regression involving erc-query-buffer-p

* lisp/erc/erc.el (erc-server-or-unjoined-channel-buffer-p): Doc.
(erc-query-buffer-p): Don't return non-nil in non-ERC buffers and
server buffers, and continue to honor string arguments.  The
regression was introduced by 3d87e343 "Use modern fallback for channel
name detection in ERC".  Thanks to Libera user mekeor for reporting
this bug.
* test/lisp/erc/erc-tests.el (erc-query-buffer-p): New test.
(Bug#67220)
This commit is contained in:
F. Jason Park 2024-04-13 14:58:13 -07:00
parent 6000e48e0d
commit 473189ab69
2 changed files with 37 additions and 3 deletions

View file

@ -1647,7 +1647,7 @@ the process buffer."
"Return non-nil if argument BUFFER is an ERC server buffer.
If BUFFER is nil, use the current buffer. For historical
reasons, also return non-nil for channel buffers the client has
parted or from which it's been kicked."
parted or been kicked from."
(with-current-buffer (or buffer (current-buffer))
(and (eq major-mode 'erc-mode)
(null (erc-default-target)))))
@ -1669,8 +1669,13 @@ If BUFFER is nil, the current buffer is used."
(defun erc-query-buffer-p (&optional buffer)
"Return non-nil if BUFFER is an ERC query buffer.
If BUFFER is nil, the current buffer is used."
(not (erc-channel-p (or buffer (current-buffer)))))
If BUFFER is nil, use the current buffer."
(and-let* ((target (if buffer
(progn (when (stringp buffer)
(setq buffer (get-buffer buffer)))
(buffer-local-value 'erc--target buffer))
erc--target)))
(not (erc--target-channel-p target))))
(defun erc-ison-p (nick)
"Return non-nil if NICK is online."

View file

@ -1227,6 +1227,35 @@
(erc-tests-common-kill-buffers))
(ert-deftest erc-query-buffer-p ()
;; Nil in a non-ERC buffer.
(should-not (erc-query-buffer-p))
(should-not (erc-query-buffer-p (current-buffer)))
(should-not (erc-query-buffer-p (buffer-name)))
(erc-tests-common-make-server-buf)
;; Nil in a server buffer.
(should-not (erc-query-buffer-p))
(should-not (erc-query-buffer-p (current-buffer)))
(should-not (erc-query-buffer-p (buffer-name)))
;; Nil in a channel buffer.
(with-current-buffer (erc--open-target "#chan")
(should-not (erc-query-buffer-p))
(should-not (erc-query-buffer-p (current-buffer)))
(should-not (erc-query-buffer-p (buffer-name))))
;; Non-nil in a query buffer.
(with-current-buffer (erc--open-target "alice")
(should (erc-query-buffer-p))
(should (erc-query-buffer-p (current-buffer)))
(should (erc-query-buffer-p (buffer-name))))
(should (erc-query-buffer-p (get-buffer "alice")))
(should (erc-query-buffer-p "alice"))
(erc-tests-common-kill-buffers))
(ert-deftest erc--valid-local-channel-p ()
(ert-info ("Local channels not supported")
(let ((erc--isupport-params (make-hash-table)))