From: Kevin Brubeck Unhammer <unhammer@fsfe.org>
To: emacs-devel@gnu.org
Subject: Re: [PATCH] Allow irc networks in erc-autojoin-channels-alist
Date: Thu, 22 Feb 2018 11:16:03 +0100 [thread overview]
Message-ID: <87vaepmisc.fsf@mm.st> (raw)
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")
[-- Attachment #1.1: Type: text/plain, Size: 211 bytes --]
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 – does it
still seem OK?
best regards,
Kevin Brubeck Unhammer
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: 0001-Allow-irc-network-symbols-in-erc-autojoin-channels-a.patch --]
[-- Type: text/x-diff, Size: 5980 bytes --]
From 0c666032301437974d028494249bab78f8d92a55 Mon Sep 17 00:00:00 2001
From: Kevin Brubeck Unhammer <unhammer@fsfe.org>
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
---
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
--- 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).
-SERVER is a regexp matching the server, and channels is the
-list 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).
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-channels'."
(erc-log "Delayed autojoin started (no ident success detected yet)")
(erc-autojoin-channels server nick))))
+(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)
- (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)
- (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-hook'."
;; Return nil to avoid stomping on any other hook funcs.
nil)
+(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)
- (or erc-session-server erc-server-announced-name))))
+ (erc-autojoin-current-server))))
(when (erc-current-nick-p nick)
- (when (and erc-autojoin-domain-only
- (string-match "[^.\n]+\\.\\([^.\n]+\\.[^.\n]+\\)$" server))
- (setq server (match-string 1 server)))
- (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-hook'."
(let* ((chnl (car (erc-response.command-args parsed)))
(nick (car (erc-parse-user (erc-response.sender parsed))))
(server (with-current-buffer (process-buffer proc)
- (or erc-session-server erc-server-announced-name))))
+ (erc-autojoin-current-server))))
(when (erc-current-nick-p nick)
- (when (and erc-autojoin-domain-only
- (string-match "[^.\n]+\\.\\([^.\n]+\\.[^.\n]+\\)$" server))
- (setq server (match-string 1 server)))
- (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)
--
2.14.1
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 800 bytes --]
next prev parent reply other threads:[~2018-02-22 10:16 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-04 11:06 [PATCH] Allow irc networks in erc-autojoin-channels-alist Kevin Brubeck Unhammer
2015-03-05 14:54 ` Kelvin White
2015-03-09 9:48 ` Kevin Brubeck Unhammer
2018-02-22 10:16 ` Kevin Brubeck Unhammer [this message]
2018-06-17 21:45 ` Amin Bandali
-- strict thread matches above, loose matches on Subject: below --
2015-03-09 19:55 Kelvin White
2015-03-10 19:34 ` Kevin Brubeck Unhammer
2015-03-10 20:10 ` Kelvin White
2015-03-11 0:51 ` Stefan Monnier
2015-03-11 1:23 ` Kelvin White
2015-03-11 5:34 ` Kelvin White
2015-03-11 13:49 ` Stefan Monnier
2015-03-11 14:58 ` Kevin Brubeck Unhammer
2015-03-11 15:13 ` Kelvin White
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87vaepmisc.fsf@mm.st \
--to=unhammer@fsfe.org \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.