>From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Mon, 16 Aug 2021 05:01:16 -0700 Subject: [PATCH 07/28] Add helper to determine local channels in ERC * lisp/erc/erc.el (erc-valid-local-channel-p): add helper to determine whether some channel is local according to network's CHANTYPES param. --- lisp/erc/erc.el | 6 ++++++ test/lisp/erc/erc-tests.el | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index 77e773c828..ae386cc096 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -3212,6 +3212,12 @@ erc-server-join-channel (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 (cadr (assq 'CHANTYPES erc-isupport-parameters))) + ((string-search "&" 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 160688c1cf..e1454305c2 100644 --- a/test/lisp/erc/erc-tests.el +++ b/test/lisp/erc/erc-tests.el @@ -217,6 +217,16 @@ erc-downcase (should (equal (erc-downcase "Tilde~") "tilde~" )) (should (equal (erc-downcase "\\O/") "|o/" ))))) +(ert-deftest erc-local-channel-p () + (ert-info ("Local channels not supported") + (let ((erc-isupport-parameters '((CHANTYPES "#")))) + (should-not (erc-valid-local-channel-p "#chan")) + (should-not (erc-valid-local-channel-p "&local")))) + (ert-info ("Local channels supported") + (let ((erc-isupport-parameters '((CHANTYPES "&#")))) + (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 -- 2.31.1