summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorF. Jason Park <jp@neverwas.me>2023-02-18 19:32:36 -0800
committerF. Jason Park <jp@neverwas.me>2023-04-08 14:23:50 -0700
commite69bd59ec59784b2f646e93355d4d63f41426cfc (patch)
treefff6062e04cf60606943301ca0528b895ef78350
parent8c0c98268440b27a77faf30738dfd72c909bb33f (diff)
downloademacs-e69bd59ec59784b2f646e93355d4d63f41426cfc.tar.gz
Honor arbitrary CHANTYPES in ERC
* lisp/erc/erc.el (erc-channel-p): Favor "CHANTYPES" ISUPPORT item before falling back to well known prefixes. * test/lisp/erc/erc-tests.el (erc-channel-p): Add test. Arbitrarily bundled with bug#60954.
-rw-r--r--lisp/erc/erc.el12
-rw-r--r--test/lisp/erc/erc-tests.el21
2 files changed, 29 insertions, 4 deletions
diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el
index 6d35a62518d..ef51f100f8b 100644
--- a/lisp/erc/erc.el
+++ b/lisp/erc/erc.el
@@ -1549,10 +1549,14 @@ effect when `erc-join-buffer' is set to `frame'."
(defun erc-channel-p (channel)
"Return non-nil if CHANNEL seems to be an IRC channel name."
(cond ((stringp channel)
- (memq (aref channel 0) '(?# ?& ?+ ?!)))
- ((and (bufferp channel) (buffer-live-p channel))
- (with-current-buffer channel
- (erc-channel-p (erc-default-target))))
+ (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)))
;; For the sake of compatibility, a historical quirk concerning this
diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el
index d6c63934163..bbf3269161d 100644
--- a/test/lisp/erc/erc-tests.el
+++ b/test/lisp/erc/erc-tests.el
@@ -447,6 +447,27 @@
(should (equal (erc-downcase "Tilde~") "tilde~" ))
(should (equal (erc-downcase "\\O/") "|o/" )))))
+(ert-deftest erc-channel-p ()
+ (let ((erc--isupport-params (make-hash-table))
+ 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-not (erc-channel-p "@chan"))
+
+ (push '("CHANTYPES" . "#&@+!") erc-server-parameters)
+
+ (should (erc-channel-p "!chan"))
+ (should (erc-channel-p "#chan"))
+
+ (with-current-buffer (get-buffer-create "#chan")
+ (setq erc--target (erc--target-from-string "#chan")))
+ (should (erc-channel-p (get-buffer "#chan"))))
+ (kill-buffer "#chan"))
+
(ert-deftest erc--valid-local-channel-p ()
(ert-info ("Local channels not supported")
(let ((erc--isupport-params (make-hash-table)))