1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-15 10:30:25 -08:00

Use modern fallback for channel name detection in ERC

* lisp/erc/erc-backend.el (erc-query-buffer-p): Remove forward declaration.
* lisp/erc/erc.el (erc-query-buffer-p): Defer to `erc-channel-p'.
(erc-channel-p): Refactor and use `erc--fallback-channel-prefixes' for
the default CHANTYPES value.  Honor an empty CHANTYPES value as valid,
e.g., for servers that only support direct messages.
(erc--fallback-channel-prefixes): New variable to hold fallback
CHANTYPES prefixes recommended by RFC1459 and modern authorities on
the matter.
* test/lisp/erc/erc-tests.el (erc-channel-p): Revise test.  (Bug#67220)
This commit is contained in:
F. Jason Park 2024-02-11 20:01:54 -08:00
parent 25d15391f2
commit 3d87e34327
3 changed files with 42 additions and 33 deletions

View file

@ -158,7 +158,6 @@
(declare-function erc-parse-user "erc" (string))
(declare-function erc-process-away "erc" (proc away-p))
(declare-function erc-process-ctcp-query "erc" (proc parsed nick login host))
(declare-function erc-query-buffer-p "erc" (&optional buffer))
(declare-function erc-remove-channel-member "erc" (channel nick))
(declare-function erc-remove-channel-users "erc" nil)
(declare-function erc-remove-user "erc" (nick))

View file

@ -1663,11 +1663,7 @@ 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."
(with-current-buffer (or buffer (current-buffer))
(let ((target (erc-target)))
(and (eq major-mode 'erc-mode)
target
(not (memq (aref target 0) '(?# ?& ?+ ?!)))))))
(not (erc-channel-p (or buffer (current-buffer)))))
(defun erc-ison-p (nick)
"Return non-nil if NICK is online."
@ -1882,18 +1878,20 @@ buries those."
:group 'erc-buffers
:type 'boolean)
(defun erc-channel-p (channel)
"Return non-nil if CHANNEL seems to be an IRC channel name."
(cond ((stringp channel)
(memq (aref channel 0)
(if-let ((types (erc--get-isupport-entry 'CHANTYPES 'single)))
(append types nil)
'(?# ?& ?+ ?!))))
((and-let* (((bufferp channel))
((buffer-live-p channel))
(target (buffer-local-value 'erc--target channel)))
(erc-channel-p (erc--target-string target))))
(t nil)))
(defvar erc--fallback-channel-prefixes "#&"
"Prefix chars for distinguishing channel targets when CHANTYPES is unknown.")
(defun erc-channel-p (target)
"Return non-nil if TARGET is a valid channel name or a channel buffer."
(cond ((stringp target)
(and-let*
(((not (string-empty-p target)))
(value (let ((entry (erc--get-isupport-entry 'CHANTYPES)))
(if entry (cadr entry) erc--fallback-channel-prefixes)))
((erc--strpos (aref target 0) value)))))
((and-let* (((buffer-live-p target))
(target (buffer-local-value 'erc--target target))
((erc--target-channel-p target)))))))
;; For the sake of compatibility, a historical quirk concerning this
;; option, when nil, has been preserved: all buffers are suffixed with