unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH] Allow irc networks in erc-autojoin-channels-alist
@ 2015-03-04 11:06 Kevin Brubeck Unhammer
  2015-03-05 14:54 ` Kelvin White
  2018-02-22 10:16 ` Kevin Brubeck Unhammer
  0 siblings, 2 replies; 14+ messages in thread
From: Kevin Brubeck Unhammer @ 2015-03-04 11:06 UTC (permalink / raw)
  To: emacs-devel; +Cc: Kevin Brubeck Unhammer

This can be useful when connecting to an IRC proxy that relays several
networks under the same server (where keying on the server name means
we end up joining a channel on all networks when we join on one
network).

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'.

Question: `erc-autojoin-after-ident' never did any string-match to
strip the server down to domain, should it?
---
 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 4c99898..aafd916 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))
 	(dolist (chan (cdr l))
 	  (erc-server-join-channel server chan)))))
   ;; Return nil to avoid stomping on any other hook funcs.
@@ -175,20 +187,30 @@ This function is run from `erc-nickserv-identified-hook'."
 				 (concat " " password)
 			       "")))))
 
+(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-server-announced-name erc-session-server))))
+		   (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))))))
@@ -203,12 +225,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-server-announced-name erc-session-server))))
+		   (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.3.1




^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH] Allow irc networks in erc-autojoin-channels-alist
  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
  1 sibling, 1 reply; 14+ messages in thread
From: Kelvin White @ 2015-03-05 14:54 UTC (permalink / raw)
  To: Kevin Brubeck Unhammer, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 188 bytes --]

Hi Keivn, I have a few questions about this...
Can you elaborate on the use case here a bit more? What do you mean by
'keying on the server'
What version of emacs are you using with this?

[-- Attachment #2: Type: text/html, Size: 234 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] Allow irc networks in erc-autojoin-channels-alist
  2015-03-05 14:54 ` Kelvin White
@ 2015-03-09  9:48   ` Kevin Brubeck Unhammer
  0 siblings, 0 replies; 14+ messages in thread
From: Kevin Brubeck Unhammer @ 2015-03-09  9:48 UTC (permalink / raw)
  To: Kelvin White; +Cc: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1011 bytes --]

(Thought I'd posted this reply earlier, but I don't see it in the list;
sorry if I'm posting a duplicate here.)

Kelvin White <kwhite@gnu.org> writes:

> Hi Keivn, I have a few questions about this...
> Can you elaborate on the use case here a bit more? What do you mean by
> 'keying on the server'

The key in the assoc list is typically something like "freenode\\.net"
(a regex matching the IRC server).

I use ERC to connect to my Weechat IRC proxy; the same proxy *server*
provides access to several *networks*, but the
`erc-server-announced-name' is always "weechat.ssl.irc" (more info at
https://weechat.org/files/doc/stable/weechat_user.en.html#relay_irc_proxy
). The only way I've seen to differentiate is by the value of
`erc-network' (well, also each server buffer contains a string like
NETWORK=freenode or NETWORK=BitlBee, I suppose that's how `erc-network'
is set).

> What version of emacs are you using with this?

24.4.1

-- 
Kevin Brubeck Unhammer

GPG: 0x766AC60C

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 818 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] Allow irc networks in erc-autojoin-channels-alist
@ 2015-03-09 19:55 Kelvin White
  2015-03-10 19:34 ` Kevin Brubeck Unhammer
  0 siblings, 1 reply; 14+ messages in thread
From: Kelvin White @ 2015-03-09 19:55 UTC (permalink / raw)
  To: Kevin Brubeck Unhammer; +Cc: Emacs development discussions

[-- Attachment #1: Type: text/plain, Size: 258 bytes --]

In the Emacs 24.5 release there is an option to use network name as the
buffer name. Can you install this version and see if it solves the issue?
I'm still not quite sure where what your issue is specifically, where
you're seeing the problem exactly

Thanks

[-- Attachment #2: Type: text/html, Size: 301 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] Allow irc networks in erc-autojoin-channels-alist
  2015-03-09 19:55 Kelvin White
@ 2015-03-10 19:34 ` Kevin Brubeck Unhammer
  2015-03-10 20:10   ` Kelvin White
  0 siblings, 1 reply; 14+ messages in thread
From: Kevin Brubeck Unhammer @ 2015-03-10 19:34 UTC (permalink / raw)
  To: Kelvin White; +Cc: Emacs development discussions

[-- Attachment #1: Type: text/plain, Size: 1444 bytes --]

Kelvin White <kwhite@gnu.org> writes:

> In the Emacs 24.5 release there is an option to use network name as
> the buffer name. Can you install this version and see if it solves the
> issue? I'm still not quite sure where what your issue is specifically,
> where you're seeing the problem exactly

I tried emacs-git-25.0.50.r120726 now (without my patched erc-join.el),
and tried setting the new option `erc-rename-buffers' to t, but that
doesn't fix my problem. From what I can tell, the erc-join code doesn't
care about buffer names (or the mode-line format), only
erc-server-announced-name/erc-session-server, when choosing what
channels to join.

The problem is that the erc-server-announced-name/erc-session-server
returned from my Weechat relay is "relay.irc" (while erc-network is the
more useful 'freenode or 'Bitlbee).

So say that I first join the freenode network through my relay, then
join #fsf; now erc-autojoin-channels-alist will contain an entry

    ("relay.irc" "#fsf")

Then I join the BitlBee network though my relay, which also has that
same server-name "relay.irc", and erc tries to autojoin #fsf on the
BitlBee network since it doesn't know how to tell that they're different
From each other. (Similarly, I would have to use "relay.irc" as the key
in erc-autojoin-channels-alist in order to autojoin anything at all on
the first connect.)


-- 
Kevin Brubeck Unhammer

GPG: 0x766AC60C

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 818 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] Allow irc networks in erc-autojoin-channels-alist
  2015-03-10 19:34 ` Kevin Brubeck Unhammer
@ 2015-03-10 20:10   ` Kelvin White
  2015-03-11  0:51     ` Stefan Monnier
  0 siblings, 1 reply; 14+ messages in thread
From: Kelvin White @ 2015-03-10 20:10 UTC (permalink / raw)
  To: Kevin Brubeck Unhammer; +Cc: Stefan Monnier, Emacs development discussions

> The problem is that the erc-server-announced-name/erc-session-server
> returned from my Weechat relay is "relay.irc" (while erc-network is the
> more useful 'freenode or 'Bitlbee).

Ah yes, that makes sense. Thanks for the clarity

I would call this a trivial patch, however it is 20 lines of code so
I'll let Stefan chime in here

Stefan, would you consider this to be a trivial contribution? If so I
will install it in trunk

Thanks Kevin



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] Allow irc networks in erc-autojoin-channels-alist
  2015-03-10 20:10   ` Kelvin White
@ 2015-03-11  0:51     ` Stefan Monnier
  2015-03-11  1:23       ` Kelvin White
  0 siblings, 1 reply; 14+ messages in thread
From: Stefan Monnier @ 2015-03-11  0:51 UTC (permalink / raw)
  To: Kelvin White; +Cc: Kevin Brubeck Unhammer, Emacs development discussions

> Stefan, would you consider this to be a trivial contribution? If so I
> will install it in trunk

Sorry, can't find the patch, can someone resend it?


        Stefan



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] Allow irc networks in erc-autojoin-channels-alist
  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
  0 siblings, 2 replies; 14+ messages in thread
From: Kelvin White @ 2015-03-11  1:23 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Kevin Brubeck Unhammer, Emacs development discussions

 Stefan Monnier <monnier@iro.umontreal.ca> wrote:
 > Sorry, can't find the patch, can someone resend it?

Sorry, I thought it was attached.

---
 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 4c99898..aafd916 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))
        (dolist (chan (cdr l))
          (erc-server-join-channel server chan)))))
   ;; Return nil to avoid stomping on any other hook funcs.
@@ -175,20 +187,30 @@ This function is run from `erc-nickserv-identified-hook'."
                                 (concat " " password)
                               "")))))

+(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-server-announced-name erc-session-server))))
+                  (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))))))
@@ -203,12 +225,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-server-announced-name erc-session-server))))
+                  (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)



^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH] Allow irc networks in erc-autojoin-channels-alist
  2015-03-11  1:23       ` Kelvin White
@ 2015-03-11  5:34         ` Kelvin White
  2015-03-11 13:49         ` Stefan Monnier
  1 sibling, 0 replies; 14+ messages in thread
From: Kelvin White @ 2015-03-11  5:34 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Kevin Brubeck Unhammer, Emacs development discussions

[-- Attachment #1: Type: text/plain, Size: 5564 bytes --]

 Stefan Monnier <monnier@iro.umontreal.ca> wrote:
 > Sorry, can't find the patch, can someone resend it?

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 4c99898..aafd916 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))
        (dolist (chan (cdr l))
          (erc-server-join-channel server chan)))))
   ;; Return nil to avoid stomping on any other hook funcs.
@@ -175,20 +187,30 @@ This function is run from
`erc-nickserv-identified-hook'."
                                 (concat " " password)
                               "")))))

+(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-server-announced-name erc-session-server))))
+                  (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))))))
@@ -203,12 +225,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-server-announced-name erc-session-server))))
+                  (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)

 On Tue, Mar 10, 2015, 9:23 PM Kelvin White <kwhite@gnu.org> wrote:

Sorry, I thought it was attached.

[-- Attachment #2: Type: text/html, Size: 7014 bytes --]

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH] Allow irc networks in erc-autojoin-channels-alist
  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
  1 sibling, 1 reply; 14+ messages in thread
From: Stefan Monnier @ 2015-03-11 13:49 UTC (permalink / raw)
  To: Kelvin White; +Cc: Kevin Brubeck Unhammer, Emacs development discussions

>> Sorry, can't find the patch, can someone resend it?
> Sorry, I thought it was attached.

Thanks.

> ---
>  lisp/erc/erc-join.el | 48 ++++++++++++++++++++++++++++++++++--------------
>  1 file changed, 34 insertions(+), 14 deletions(-)

I think it's just borderline: we should ask for his copyright paperwork
but we can install it in the mean time.


        Stefan



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] Allow irc networks in erc-autojoin-channels-alist
  2015-03-11 13:49         ` Stefan Monnier
@ 2015-03-11 14:58           ` Kevin Brubeck Unhammer
  2015-03-11 15:13             ` Kelvin White
  0 siblings, 1 reply; 14+ messages in thread
From: Kevin Brubeck Unhammer @ 2015-03-11 14:58 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Kelvin White, Emacs development discussions

[-- Attachment #1: Type: text/plain, Size: 505 bytes --]

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>>> Sorry, can't find the patch, can someone resend it?
>> Sorry, I thought it was attached.
>
> Thanks.
>
>> ---
>>  lisp/erc/erc-join.el | 48 ++++++++++++++++++++++++++++++++++--------------
>>  1 file changed, 34 insertions(+), 14 deletions(-)
>
> I think it's just borderline: we should ask for his copyright paperwork
> but we can install it in the mean time.

Where do I sign? :-)

-- 
Kevin Brubeck Unhammer

GPG: 0x766AC60C


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 818 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] Allow irc networks in erc-autojoin-channels-alist
  2015-03-11 14:58           ` Kevin Brubeck Unhammer
@ 2015-03-11 15:13             ` Kelvin White
  0 siblings, 0 replies; 14+ messages in thread
From: Kelvin White @ 2015-03-11 15:13 UTC (permalink / raw)
  To: Kevin Brubeck Unhammer; +Cc: Stefan Monnier, Emacs development discussions

> Where do I sign? :-)

Please email the following information to assign@gnu.org, and we
will send you the assignment form for your past and future changes.

Please use your full legal name (in ASCII characters) as the subject
line of the message.
----------------------------------------------------------------------
REQUEST: SEND FORM FOR PAST AND FUTURE CHANGES

[What is the name of the program or package you're contributing to?]
Emacs

[Did you copy any files or text written by someone else in these changes?
Even if that material is free software, we need to know about it.]


[Do you have an employer who might have a basis to claim to own
your changes?  Do you attend a school which might make such a claim?]


[For the copyright registration, what country are you a citizen of?]


[What year were you born?]


[Please write your email address here.]


[Please write your postal address here.]





[Which files have you changed so far, and which new files have you written
so far?]



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] Allow irc networks in erc-autojoin-channels-alist
  2015-03-04 11:06 [PATCH] Allow irc networks in erc-autojoin-channels-alist Kevin Brubeck Unhammer
  2015-03-05 14:54 ` Kelvin White
@ 2018-02-22 10:16 ` Kevin Brubeck Unhammer
  2018-06-17 21:45   ` Amin Bandali
  1 sibling, 1 reply; 14+ messages in thread
From: Kevin Brubeck Unhammer @ 2018-02-22 10:16 UTC (permalink / raw)
  To: emacs-devel


[-- 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 --]

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH] Allow irc networks in erc-autojoin-channels-alist
  2018-02-22 10:16 ` Kevin Brubeck Unhammer
@ 2018-06-17 21:45   ` Amin Bandali
  0 siblings, 0 replies; 14+ messages in thread
From: Amin Bandali @ 2018-06-17 21:45 UTC (permalink / raw)
  To: Kevin Brubeck Unhammer, emacs-devel

Hi all,

Is there anything stopping this being merged?

https://lists.gnu.org/archive/html/emacs-devel/2018-02/msg00664.html
https://lists.gnu.org/archive/html/emacs-devel/2015-03/msg00195.html

Best,
-amin



^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2018-06-17 21:45 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).