From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Kevin Brubeck Unhammer Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] Allow irc networks in erc-autojoin-channels-alist Date: Thu, 22 Feb 2018 11:16:03 +0100 Message-ID: <87vaepmisc.fsf@mm.st> References: <1425467187-22491-1-git-send-email-unhammer@fsfe.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" X-Trace: blaine.gmane.org 1519294501 29588 195.159.176.226 (22 Feb 2018 10:15:01 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 22 Feb 2018 10:15:01 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Feb 22 11:14:57 2018 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eontw-0007K0-AX for ged-emacs-devel@m.gmane.org; Thu, 22 Feb 2018 11:14:56 +0100 Original-Received: from localhost ([::1]:37124 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eonvy-0001XK-G5 for ged-emacs-devel@m.gmane.org; Thu, 22 Feb 2018 05:17:02 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:48374) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eonvA-0001Wy-Il for emacs-devel@gnu.org; Thu, 22 Feb 2018 05:16:14 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eonv7-0002Iq-C5 for emacs-devel@gnu.org; Thu, 22 Feb 2018 05:16:12 -0500 Original-Received: from out1-smtp.messagingengine.com ([66.111.4.25]:59177) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eonv7-0002Gf-1e for emacs-devel@gnu.org; Thu, 22 Feb 2018 05:16:09 -0500 Original-Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 544AE20F99; Thu, 22 Feb 2018 05:16:07 -0500 (EST) Original-Received: from frontend2 ([10.202.2.161]) by compute1.internal (MEProxy); Thu, 22 Feb 2018 05:16:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; bh=7kDWF8cr4CnaHSq0sgjL6uTOJhVXH K81qsggc2xTrDA=; b=BNS0XGjJKW/Uy29IAUYSwzvsAhDW+vWaApS5TZCG/Gbxe ycloZIDVsVTuqLlW6shMJxTD8+gZD5mLbtOpGzBTIq74KuBk1HL2vC8TXe/3ijOi gUG277Bc34JsqdGW3A9L+Lx1PxOEXKXSLayUtAz/rqztCy1YXGfII8NGIVyj3R3P 0sXnScrnB3yM5WA/JF9CDx8qzO3SlFJZL7Tv91I9fdT2thnxBiL1AxEfO9f8YofU aXmJH+WpUCeCHurHVhZdO8ek+b5oKoqEZwog9KmptUH5dNUlRTuX31NZkF4KqcSr st/6zsC3D2b/EgGfFJQ10tX5hCF7V05biA4oNF9mw== X-ME-Sender: In-Reply-To: <1425467187-22491-1-git-send-email-unhammer@fsfe.org> (Kevin Brubeck Unhammer's message of "Wed, 4 Mar 2015 12:06:27 +0100") X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.111.4.25 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:222985 Archived-At: --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi, I don't think this ever got merged after I signed the copyright papers. I've updated the patch so it applies to current git master =E2=80=93 does it still seem OK? best regards, Kevin Brubeck Unhammer --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Allow-irc-network-symbols-in-erc-autojoin-channels-a.patch Content-Transfer-Encoding: quoted-printable From=200c666032301437974d028494249bab78f8d92a55 Mon Sep 17 00:00:00 2001 From: Kevin Brubeck Unhammer Date: Thu, 22 Feb 2018 11:12:29 +0100 Subject: [PATCH] Allow irc network symbols in erc-autojoin-channels-alist This can be useful when connecting to an IRC proxy like Weechat that relays several networks under the same server. If we just keyed on the server name, we would end up joining a channel on all networks whenever we join one network on that server. Networks are simply stored as symbols instead of regexes, since that's how `erc-network' works. The `erc-autojoin-add' function will still auto-add servers as strings if the network doesn't have at least one entry in `erc-autojoin-channels-alist'. More information at https://lists.gnu.org/archive/html/emacs-devel/2015-03/msg00195.html =2D-- lisp/erc/erc-join.el | 48 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/lisp/erc/erc-join.el b/lisp/erc/erc-join.el index d7ae93316c..c5eb4444c1 100644 =2D-- a/lisp/erc/erc-join.el +++ b/lisp/erc/erc-join.el @@ -54,8 +54,12 @@ (defcustom erc-autojoin-channels-alist nil "Alist of channels to autojoin on IRC networks. Every element in the alist has the form (SERVER . CHANNELS). =2DSERVER is a regexp matching the server, and channels is the =2Dlist of channels to join. +SERVER is a regexp matching the server, and channels is the list +of channels to join. SERVER can also be a symbol, in which case +it is matched against the value of `erc-network' instead of +`erc-server-announced-name' or `erc-session-server' (this can be +useful when connecting to an IRC proxy that relays several +networks under the same server). =20 If the channel(s) require channel keys for joining, the passwords are found via auth-source. For instance, if you use ~/.authinfo @@ -122,6 +126,14 @@ This is called from a timer set up by `erc-autojoin-ch= annels'." (erc-log "Delayed autojoin started (no ident success detected yet)") (erc-autojoin-channels server nick)))) =20 +(defun erc-autojoin-server-match (candidate) + "Match the current network or server against CANDIDATE, a key +from `erc-autojoin-channels-alist'." + (or (eq candidate erc-network) + (and (stringp candidate) + (string-match candidate (or erc-server-announced-name + erc-session-server))))) + (defun erc-autojoin-after-ident (network nick) "Autojoin channels in `erc-autojoin-channels-alist'. This function is run from `erc-nickserv-identified-hook'." @@ -136,7 +148,7 @@ This function is run from `erc-nickserv-identified-hook= '." ;; We may already be in these channels, e.g. because the ;; autojoin timer went off. (dolist (l erc-autojoin-channels-alist) =2D (when (string-match (car l) server) + (when (erc-autojoin-server-match (car l)) (dolist (chan (cdr l)) (unless (erc-member-ignore-case chan joined) (erc-server-join-channel server chan))))))) @@ -154,7 +166,7 @@ This function is run from `erc-nickserv-identified-hook= '." server nick (current-buffer)))) ;; `erc-autojoin-timing' is `connect': (dolist (l erc-autojoin-channels-alist) =2D (when (string-match (car l) server) + (when (erc-autojoin-server-match (car l)) (let ((server (or erc-session-server erc-server-announced-name))) (dolist (chan (cdr l)) (let ((buffer (erc-get-buffer chan))) @@ -167,20 +179,30 @@ This function is run from `erc-nickserv-identified-ho= ok'." ;; Return nil to avoid stomping on any other hook funcs. nil) =20 +(defun erc-autojoin-current-server () + "Compute the current server for lookup in `erc-autojoin-channels-alist'. +Respects `erc-autojoin-domain-only'." + (let ((server (or erc-server-announced-name erc-session-server))) + (if (and erc-autojoin-domain-only + (string-match "[^.\n]+\\.\\([^.\n]+\\.[^.\n]+\\)$" server)) + (match-string 1 server) + server))) + (defun erc-autojoin-add (proc parsed) "Add the channel being joined to `erc-autojoin-channels-alist'." (let* ((chnl (erc-response.contents parsed)) (nick (car (erc-parse-user (erc-response.sender parsed)))) (server (with-current-buffer (process-buffer proc) =2D (or erc-session-server erc-server-announced-name)))) + (erc-autojoin-current-server)))) (when (erc-current-nick-p nick) =2D (when (and erc-autojoin-domain-only =2D (string-match "[^.\n]+\\.\\([^.\n]+\\.[^.\n]+\\)$" server)) =2D (setq server (match-string 1 server))) =2D (let ((elem (assoc server erc-autojoin-channels-alist))) + (let ((elem (or (assoc erc-network erc-autojoin-channels-alist) + (assoc server erc-autojoin-channels-alist)))) (if elem (unless (member chnl (cdr elem)) (setcdr elem (cons chnl (cdr elem)))) + ;; This always keys on server, not network -- user can + ;; override by simply adding a network to + ;; `erc-autojoin-channels-alist' (setq erc-autojoin-channels-alist (cons (list server chnl) erc-autojoin-channels-alist)))))) @@ -195,12 +217,10 @@ This function is run from `erc-nickserv-identified-ho= ok'." (let* ((chnl (car (erc-response.command-args parsed))) (nick (car (erc-parse-user (erc-response.sender parsed)))) (server (with-current-buffer (process-buffer proc) =2D (or erc-session-server erc-server-announced-name)))) + (erc-autojoin-current-server)))) (when (erc-current-nick-p nick) =2D (when (and erc-autojoin-domain-only =2D (string-match "[^.\n]+\\.\\([^.\n]+\\.[^.\n]+\\)$" server)) =2D (setq server (match-string 1 server))) =2D (let ((elem (assoc server erc-autojoin-channels-alist))) + (let ((elem (or (assoc erc-network erc-autojoin-channels-alist) + (assoc server erc-autojoin-channels-alist)))) (when elem (setcdr elem (delete chnl (cdr elem))) (unless (cdr elem) =2D-=20 2.14.1 --=-=-=-- --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIcBAEBCAAGBQJajphjAAoJEPw8Hn0AkxZncqQP/3ZnKu0nw6S0HlKDzqvhWnQv EmQJAtjRdtJkVmbD4RaUqcmwo8fcwzHgFMJIFDUXDla9P7F+pxWUZPySiHg5DORp cHqkqPRy2Bh1bcNg4iK3seD1RxoN/auuxBGdnjSqtSRkiULfG36Ga0lSetJNkdT1 IU0kvaSy1HChwAoMxqbNWKEke09H67uv9MIySMlYnEYizZyZkp8tBe7daUUW8Su3 FyI1YGVBYPsdPiYO//ClJegwA1ysLMAjO4sJMsVsvxBB99hI1Rr96rsojeW0MB/c q9bwUNTycscLETdnEaBEPf6O4CDZFRvT+kL0wrQcAbX8lRZ4n5xJOWZhfVD/yKaI tZOnJPvVts9s3y7g3nt9U3+t+gUbb3BS42UWMc5aPNW7xsUoLSVfNYUe+zjRtIVJ x4WjXwg+J8pfyZF6AdYp3rDWf6uV4/AMsNO6/5lDcy11kzAMTr5Wa+hrz5bfiVHT EUgaDLanyC45wGPsjp32qAcDg6TAxc/D2ExLQaAu+p0wYz7OCeYCkehEY0HFbLQg x8ov+1Wt+w+QYz2iFvN4g1X3y5qmJEr94eIi3czkHpKWgo/CQns+zLFDL2K/H+TH SY3J3zKr/qI6p4MdLIGBktUCrT1WdARApGPTrw9jfIgrzsPxnq4DWjbPUPvaCDew ceGzPolil+zgo5/I+yAj =C51x -----END PGP SIGNATURE----- --==-=-=--