emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 1c24af0fcb 12/25: Add helper to determine local channels in ERC


From: F. Jason Park
Subject: master 1c24af0fcb 12/25: Add helper to determine local channels in ERC
Date: Thu, 30 Jun 2022 18:29:53 -0400 (EDT)

branch: master
commit 1c24af0fcb8a8326fe5cdc75672bf4099b191a00
Author: F. Jason Park <jp@neverwas.me>
Commit: F. Jason Park <jp@neverwas.me>

    Add helper to determine local channels in ERC
    
    * lisp/erc/erc.el (erc--valid-local-channel-p): Add internal helper to
    determine whether an IRC channel is local according to its network's
    CHANTYPES ISUPPORT parameter.
    
    * test/lisp/erc/erc-tests.el (erc--valid-local-channel-p): Add test
    for this helper.
---
 lisp/erc/erc.el            |  8 ++++++++
 test/lisp/erc/erc-tests.el | 12 ++++++++++++
 2 files changed, 20 insertions(+)

diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el
index 4c54ef2ef9..d4cf28a86d 100644
--- a/lisp/erc/erc.el
+++ b/lisp/erc/erc.el
@@ -3251,6 +3251,14 @@ For a list of user commands (/join /part, ...):
                                 (concat " " password)
                               "")))))
 
+(defun erc--valid-local-channel-p (channel)
+  "Non-nil when channel is server-local on a network that allows them."
+  (and-let* (((eq ?& (aref channel 0)))
+             (chan-types (erc--get-isupport-entry 'CHANTYPES 'single))
+             ((if (>= emacs-major-version 28)
+                  (string-search "&" chan-types)
+                (string-match-p "&" chan-types))))))
+
 (defun erc-cmd-JOIN (channel &optional key)
   "Join the channel given in CHANNEL, optionally with KEY.
 If CHANNEL is specified as \"-invite\", join the channel to which you
diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el
index cffb61f708..4026ebaf33 100644
--- a/test/lisp/erc/erc-tests.el
+++ b/test/lisp/erc/erc-tests.el
@@ -466,6 +466,18 @@
       (should (equal (erc-downcase "Tilde~") "tilde~" ))
       (should (equal (erc-downcase "\\O/") "|o/" )))))
 
+(ert-deftest erc--valid-local-channel-p ()
+  (ert-info ("Local channels not supported")
+    (let ((erc--isupport-params (make-hash-table)))
+      (puthash 'CHANTYPES  '("#") erc--isupport-params)
+      (should-not (erc--valid-local-channel-p "#chan"))
+      (should-not (erc--valid-local-channel-p "&local"))))
+  (ert-info ("Local channels supported")
+    (let ((erc--isupport-params (make-hash-table)))
+      (puthash 'CHANTYPES  '("&#") erc--isupport-params)
+      (should-not (erc--valid-local-channel-p "#chan"))
+      (should (erc--valid-local-channel-p "&local")))))
+
 (ert-deftest erc-ring-previous-command-base-case ()
   (ert-info ("Create ring when nonexistent and do nothing")
     (let (erc-input-ring



reply via email to

[Prev in Thread] Current Thread [Next in Thread]