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:
parent
25d15391f2
commit
3d87e34327
3 changed files with 42 additions and 33 deletions
|
@ -158,7 +158,6 @@
|
||||||
(declare-function erc-parse-user "erc" (string))
|
(declare-function erc-parse-user "erc" (string))
|
||||||
(declare-function erc-process-away "erc" (proc away-p))
|
(declare-function erc-process-away "erc" (proc away-p))
|
||||||
(declare-function erc-process-ctcp-query "erc" (proc parsed nick login host))
|
(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-member "erc" (channel nick))
|
||||||
(declare-function erc-remove-channel-users "erc" nil)
|
(declare-function erc-remove-channel-users "erc" nil)
|
||||||
(declare-function erc-remove-user "erc" (nick))
|
(declare-function erc-remove-user "erc" (nick))
|
||||||
|
|
|
@ -1663,11 +1663,7 @@ If BUFFER is nil, the current buffer is used."
|
||||||
(defun erc-query-buffer-p (&optional buffer)
|
(defun erc-query-buffer-p (&optional buffer)
|
||||||
"Return non-nil if BUFFER is an ERC query buffer.
|
"Return non-nil if BUFFER is an ERC query buffer.
|
||||||
If BUFFER is nil, the current buffer is used."
|
If BUFFER is nil, the current buffer is used."
|
||||||
(with-current-buffer (or buffer (current-buffer))
|
(not (erc-channel-p (or buffer (current-buffer)))))
|
||||||
(let ((target (erc-target)))
|
|
||||||
(and (eq major-mode 'erc-mode)
|
|
||||||
target
|
|
||||||
(not (memq (aref target 0) '(?# ?& ?+ ?!)))))))
|
|
||||||
|
|
||||||
(defun erc-ison-p (nick)
|
(defun erc-ison-p (nick)
|
||||||
"Return non-nil if NICK is online."
|
"Return non-nil if NICK is online."
|
||||||
|
@ -1882,18 +1878,20 @@ buries those."
|
||||||
:group 'erc-buffers
|
:group 'erc-buffers
|
||||||
:type 'boolean)
|
:type 'boolean)
|
||||||
|
|
||||||
(defun erc-channel-p (channel)
|
(defvar erc--fallback-channel-prefixes "#&"
|
||||||
"Return non-nil if CHANNEL seems to be an IRC channel name."
|
"Prefix chars for distinguishing channel targets when CHANTYPES is unknown.")
|
||||||
(cond ((stringp channel)
|
|
||||||
(memq (aref channel 0)
|
(defun erc-channel-p (target)
|
||||||
(if-let ((types (erc--get-isupport-entry 'CHANTYPES 'single)))
|
"Return non-nil if TARGET is a valid channel name or a channel buffer."
|
||||||
(append types nil)
|
(cond ((stringp target)
|
||||||
'(?# ?& ?+ ?!))))
|
(and-let*
|
||||||
((and-let* (((bufferp channel))
|
(((not (string-empty-p target)))
|
||||||
((buffer-live-p channel))
|
(value (let ((entry (erc--get-isupport-entry 'CHANTYPES)))
|
||||||
(target (buffer-local-value 'erc--target channel)))
|
(if entry (cadr entry) erc--fallback-channel-prefixes)))
|
||||||
(erc-channel-p (erc--target-string target))))
|
((erc--strpos (aref target 0) value)))))
|
||||||
(t nil)))
|
((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
|
;; For the sake of compatibility, a historical quirk concerning this
|
||||||
;; option, when nil, has been preserved: all buffers are suffixed with
|
;; option, when nil, has been preserved: all buffers are suffixed with
|
||||||
|
|
|
@ -1167,25 +1167,37 @@
|
||||||
(should (equal (erc-downcase "\\O/") "|o/" )))))
|
(should (equal (erc-downcase "\\O/") "|o/" )))))
|
||||||
|
|
||||||
(ert-deftest erc-channel-p ()
|
(ert-deftest erc-channel-p ()
|
||||||
(let ((erc--isupport-params (make-hash-table))
|
(erc-tests-common-make-server-buf)
|
||||||
erc-server-parameters)
|
|
||||||
|
|
||||||
(should (erc-channel-p "#chan"))
|
(should (erc-channel-p "#chan"))
|
||||||
(should (erc-channel-p "##chan"))
|
(should (erc-channel-p "##chan"))
|
||||||
(should (erc-channel-p "&chan"))
|
(should (erc-channel-p "&chan"))
|
||||||
(should (erc-channel-p "+chan"))
|
(should-not (erc-channel-p "+chan"))
|
||||||
(should (erc-channel-p "!chan"))
|
(should-not (erc-channel-p "!chan"))
|
||||||
(should-not (erc-channel-p "@chan"))
|
(should-not (erc-channel-p "@chan"))
|
||||||
|
|
||||||
(push '("CHANTYPES" . "#&@+!") erc-server-parameters)
|
;; Server sends "CHANTYPES=#&+!"
|
||||||
|
(should-not erc-server-parameters)
|
||||||
|
(setq erc-server-parameters '(("CHANTYPES" . "#&+!")))
|
||||||
|
(should (erc-channel-p "#chan"))
|
||||||
|
(should (erc-channel-p "&chan"))
|
||||||
|
(should (erc-channel-p "+chan"))
|
||||||
|
(should (erc-channel-p "!chan"))
|
||||||
|
|
||||||
(should (erc-channel-p "!chan"))
|
(with-current-buffer (erc--open-target "#chan")
|
||||||
(should (erc-channel-p "#chan"))
|
(should (erc-channel-p (current-buffer))))
|
||||||
|
(with-current-buffer (erc--open-target "+chan")
|
||||||
|
(should (erc-channel-p (current-buffer))))
|
||||||
|
(should (erc-channel-p (get-buffer "#chan")))
|
||||||
|
(should (erc-channel-p (get-buffer "+chan")))
|
||||||
|
|
||||||
(with-current-buffer (get-buffer-create "#chan")
|
;; Server sends "CHANTYPES=" because it's query only.
|
||||||
(setq erc--target (erc--target-from-string "#chan")))
|
(puthash 'CHANTYPES '("CHANTYPES") erc--isupport-params)
|
||||||
(should (erc-channel-p (get-buffer "#chan"))))
|
(should-not (erc-channel-p "#spam"))
|
||||||
(kill-buffer "#chan"))
|
(should-not (erc-channel-p "&spam"))
|
||||||
|
(should-not (erc-channel-p (save-excursion (erc--open-target "#spam"))))
|
||||||
|
|
||||||
|
(erc-tests-common-kill-buffers))
|
||||||
|
|
||||||
(ert-deftest erc--valid-local-channel-p ()
|
(ert-deftest erc--valid-local-channel-p ()
|
||||||
(ert-info ("Local channels not supported")
|
(ert-info ("Local channels not supported")
|
||||||
|
|
Loading…
Add table
Reference in a new issue