aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/erc
diff options
context:
space:
mode:
authorKevin Brubeck Unhammer2021-09-16 15:48:28 +0200
committerLars Ingebrigtsen2021-09-16 15:50:14 +0200
commit9bb8d90cddf11df3aecdc6c04e762773dfa0cb92 (patch)
treee17ad2482c796cece189bfa568ae402695e2d835 /lisp/erc
parentcfae83adacf0dd5309d20eb383e51a7ae48514b0 (diff)
downloademacs-9bb8d90cddf11df3aecdc6c04e762773dfa0cb92.tar.gz
emacs-9bb8d90cddf11df3aecdc6c04e762773dfa0cb92.zip
Allow irc network symbols in erc-autojoin-channels-alist
* lisp/erc/erc-join.el (erc-autojoin-channels-alist): Explain the extension. (erc-autojoin-server-match): New function. (erc-autojoin-channels): Use it. (erc-autojoin-current-server): New function. (erc-autojoin-add): Use it. (erc-autojoin-remove): Ditto. 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'.
Diffstat (limited to 'lisp/erc')
-rw-r--r--lisp/erc/erc-join.el53
1 files changed, 37 insertions, 16 deletions
diff --git a/lisp/erc/erc-join.el b/lisp/erc/erc-join.el
index 2ad9c8bd941..a4986918b62 100644
--- a/lisp/erc/erc-join.el
+++ b/lisp/erc/erc-join.el
@@ -34,6 +34,7 @@
34 34
35(require 'erc) 35(require 'erc)
36(require 'auth-source) 36(require 'auth-source)
37(require 'erc-networks)
37 38
38(defgroup erc-autojoin nil 39(defgroup erc-autojoin nil
39 "Enable autojoining." 40 "Enable autojoining."
@@ -54,8 +55,12 @@
54(defcustom erc-autojoin-channels-alist nil 55(defcustom erc-autojoin-channels-alist nil
55 "Alist of channels to autojoin on IRC networks. 56 "Alist of channels to autojoin on IRC networks.
56Every element in the alist has the form (SERVER . CHANNELS). 57Every element in the alist has the form (SERVER . CHANNELS).
57SERVER is a regexp matching the server, and channels is the 58SERVER is a regexp matching the server, and channels is the list
58list of channels to join. 59of channels to join. SERVER can also be a symbol, in which case
60it is matched against the value of `erc-network' instead of
61`erc-server-announced-name' or `erc-session-server' (this can be
62useful when connecting to an IRC proxy that relays several
63networks under the same server).
59 64
60If the channel(s) require channel keys for joining, the passwords 65If the channel(s) require channel keys for joining, the passwords
61are found via auth-source. For instance, if you use ~/.authinfo 66are found via auth-source. For instance, if you use ~/.authinfo
@@ -117,6 +122,15 @@ This is called from a timer set up by `erc-autojoin-channels'."
117 (erc-log "Delayed autojoin started (no ident success detected yet)") 122 (erc-log "Delayed autojoin started (no ident success detected yet)")
118 (erc-autojoin-channels server nick)))) 123 (erc-autojoin-channels server nick))))
119 124
125(defun erc-autojoin-server-match (candidate)
126 "Match the current network or server against CANDIDATE
127This should be a key from `erc-autojoin-channels-alist'."
128 (or (eq candidate (erc-network))
129 (and (stringp candidate)
130 (string-match-p candidate
131 (or erc-server-announced-name
132 erc-session-server)))))
133
120(defun erc-autojoin-after-ident (_network _nick) 134(defun erc-autojoin-after-ident (_network _nick)
121 "Autojoin channels in `erc-autojoin-channels-alist'. 135 "Autojoin channels in `erc-autojoin-channels-alist'.
122This function is run from `erc-nickserv-identified-hook'." 136This function is run from `erc-nickserv-identified-hook'."
@@ -131,7 +145,7 @@ This function is run from `erc-nickserv-identified-hook'."
131 ;; We may already be in these channels, e.g. because the 145 ;; We may already be in these channels, e.g. because the
132 ;; autojoin timer went off. 146 ;; autojoin timer went off.
133 (dolist (l erc-autojoin-channels-alist) 147 (dolist (l erc-autojoin-channels-alist)
134 (when (string-match (car l) server) 148 (when (erc-autojoin-server-match (car l))
135 (dolist (chan (cdr l)) 149 (dolist (chan (cdr l))
136 (unless (erc-member-ignore-case chan joined) 150 (unless (erc-member-ignore-case chan joined)
137 (erc-server-join-channel server chan))))))) 151 (erc-server-join-channel server chan)))))))
@@ -150,15 +164,14 @@ This function is run from `erc-nickserv-identified-hook'."
150 ;; `erc-autojoin-timing' is `connect': 164 ;; `erc-autojoin-timing' is `connect':
151 (let ((server (or erc-session-server erc-server-announced-name))) 165 (let ((server (or erc-session-server erc-server-announced-name)))
152 (dolist (l erc-autojoin-channels-alist) 166 (dolist (l erc-autojoin-channels-alist)
153 (when (string-match-p (car l) server) 167 (when (erc-autojoin-server-match (car l))
154 (dolist (chan (cdr l)) 168 (dolist (chan (cdr l))
155 (let ((buffer 169 (let ((buffer
156 (car (erc-buffer-filter 170 (car (erc-buffer-filter
157 (lambda () 171 (lambda ()
158 (let ((current (erc-default-target))) 172 (let ((current (erc-default-target)))
159 (and (stringp current) 173 (and (stringp current)
160 (string-match-p (car l) 174 (erc-autojoin-server-match (car l))
161 (or erc-session-server erc-server-announced-name))
162 (string-equal (erc-downcase chan) 175 (string-equal (erc-downcase chan)
163 (erc-downcase current))))))))) 176 (erc-downcase current)))))))))
164 (when (or (not buffer) 177 (when (or (not buffer)
@@ -168,20 +181,30 @@ This function is run from `erc-nickserv-identified-hook'."
168 ;; Return nil to avoid stomping on any other hook funcs. 181 ;; Return nil to avoid stomping on any other hook funcs.
169 nil) 182 nil)
170 183
184(defun erc-autojoin-current-server ()
185 "Compute the current server for lookup in `erc-autojoin-channels-alist'.
186Respects `erc-autojoin-domain-only'."
187 (let ((server (or erc-server-announced-name erc-session-server)))
188 (if (and erc-autojoin-domain-only
189 (string-match "[^.\n]+\\.\\([^.\n]+\\.[^.\n]+\\)$" server))
190 (match-string 1 server)
191 server)))
192
171(defun erc-autojoin-add (proc parsed) 193(defun erc-autojoin-add (proc parsed)
172 "Add the channel being joined to `erc-autojoin-channels-alist'." 194 "Add the channel being joined to `erc-autojoin-channels-alist'."
173 (let* ((chnl (erc-response.contents parsed)) 195 (let* ((chnl (erc-response.contents parsed))
174 (nick (car (erc-parse-user (erc-response.sender parsed)))) 196 (nick (car (erc-parse-user (erc-response.sender parsed))))
175 (server (with-current-buffer (process-buffer proc) 197 (server (with-current-buffer (process-buffer proc)
176 (or erc-session-server erc-server-announced-name)))) 198 (erc-autojoin-current-server))))
177 (when (erc-current-nick-p nick) 199 (when (erc-current-nick-p nick)
178 (when (and erc-autojoin-domain-only 200 (let ((elem (or (assoc (erc-network) erc-autojoin-channels-alist)
179 (string-match "[^.\n]+\\.\\([^.\n]+\\.[^.\n]+\\)$" server)) 201 (assoc server erc-autojoin-channels-alist))))
180 (setq server (match-string 1 server)))
181 (let ((elem (assoc server erc-autojoin-channels-alist)))
182 (if elem 202 (if elem
183 (unless (member chnl (cdr elem)) 203 (unless (member chnl (cdr elem))
184 (setcdr elem (cons chnl (cdr elem)))) 204 (setcdr elem (cons chnl (cdr elem))))
205 ;; This always keys on server, not network -- user can
206 ;; override by simply adding a network to
207 ;; `erc-autojoin-channels-alist'
185 (setq erc-autojoin-channels-alist 208 (setq erc-autojoin-channels-alist
186 (cons (list server chnl) 209 (cons (list server chnl)
187 erc-autojoin-channels-alist)))))) 210 erc-autojoin-channels-alist))))))
@@ -196,12 +219,10 @@ This function is run from `erc-nickserv-identified-hook'."
196 (let* ((chnl (car (erc-response.command-args parsed))) 219 (let* ((chnl (car (erc-response.command-args parsed)))
197 (nick (car (erc-parse-user (erc-response.sender parsed)))) 220 (nick (car (erc-parse-user (erc-response.sender parsed))))
198 (server (with-current-buffer (process-buffer proc) 221 (server (with-current-buffer (process-buffer proc)
199 (or erc-session-server erc-server-announced-name)))) 222 (erc-autojoin-current-server))))
200 (when (erc-current-nick-p nick) 223 (when (erc-current-nick-p nick)
201 (when (and erc-autojoin-domain-only 224 (let ((elem (or (assoc (erc-network) erc-autojoin-channels-alist)
202 (string-match "[^.\n]+\\.\\([^.\n]+\\.[^.\n]+\\)$" server)) 225 (assoc server erc-autojoin-channels-alist))))
203 (setq server (match-string 1 server)))
204 (let ((elem (assoc server erc-autojoin-channels-alist)))
205 (when elem 226 (when elem
206 (setcdr elem (delete chnl (cdr elem))) 227 (setcdr elem (delete chnl (cdr elem)))
207 (unless (cdr elem) 228 (unless (cdr elem)