1 ;;; erc-join.el --- autojoin channels on connect and reconnects
3 ;; Copyright (C) 2002, 2003, 2004, 2006, 2007 Free Software Foundation, Inc.
5 ;; Author: Alex Schroeder <alex@gnu.org>
7 ;; URL: http://www.emacswiki.org/cgi-bin/wiki.pl?ErcAutoJoin
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 3, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
28 ;; This allows us to customize an `erc-autojoin-channels-alist'. As
29 ;; we /JOIN and /PART channels, this alist is updated to reflect our
30 ;; current setup, so that when we reconnect, we rejoin the same
31 ;; channels. The alist can be customized, so that the customized
32 ;; value will be used when we reconnect in our next Emacs session.
37 (eval-when-compile (require 'cl
))
39 (defgroup erc-autojoin nil
43 ;;;###autoload (autoload 'erc-autojoin-mode "erc-join" nil t)
44 (define-erc-module autojoin nil
45 "Makes ERC autojoin on connects and reconnects."
46 ((add-hook 'erc-after-connect
'erc-autojoin-channels
)
47 (add-hook 'erc-server-JOIN-functions
'erc-autojoin-add
)
48 (add-hook 'erc-server-PART-functions
'erc-autojoin-remove
))
49 ((remove-hook 'erc-after-connect
'erc-autojoin-channels
)
50 (remove-hook 'erc-server-JOIN-functions
'erc-autojoin-add
)
51 (remove-hook 'erc-server-PART-functions
'erc-autojoin-remove
)))
53 (defcustom erc-autojoin-channels-alist nil
54 "Alist of channels to autojoin on IRC networks.
55 Every element in the alist has the form (SERVER . CHANNELS).
56 SERVER is a regexp matching the server, and channels is the
57 list of channels to join.
59 Customize this variable to set the value for your first connect.
60 Once you are connected and join and part channels, this alist
61 keeps track of what channels you are on, and will join them
62 again when you get disconnected. When you restart Emacs, however,
63 those changes are lost, and the customization you saved the last
66 :type
'(repeat (cons :tag
"Server"
68 (repeat :tag
"Channels"
69 (string :tag
"Name")))))
71 (defcustom erc-autojoin-domain-only t
72 "Truncate host name to the domain name when joining a server.
73 If non-nil, and a channel on the server a.b.c is joined, then
74 only b.c is used as the server for `erc-autojoin-channels-alist'.
75 This is important for networks that redirect you to other
76 servers, presumably in the same domain."
80 (defun erc-autojoin-channels (server nick
)
81 "Autojoin channels in `erc-autojoin-channels-alist'."
82 (dolist (l erc-autojoin-channels-alist
)
83 (when (string-match (car l
) server
)
84 (dolist (chan (cdr l
))
85 (erc-server-send (concat "join " chan
))))))
87 (defun erc-autojoin-add (proc parsed
)
88 "Add the channel being joined to `erc-autojoin-channels-alist'."
89 (let* ((chnl (erc-response.contents parsed
))
90 (nick (car (erc-parse-user (erc-response.sender parsed
))))
91 (server (with-current-buffer (process-buffer proc
)
92 (or erc-server-announced-name erc-session-server
))))
93 (when (erc-current-nick-p nick
)
94 (when (and erc-autojoin-domain-only
95 (string-match "[^.\n]+\\.\\([^.\n]+\\.[^.\n]+\\)$" server
))
96 (setq server
(match-string 1 server
)))
97 (let ((elem (assoc server erc-autojoin-channels-alist
)))
99 (unless (member chnl
(cdr elem
))
100 (setcdr elem
(cons chnl
(cdr elem
))))
101 (setq erc-autojoin-channels-alist
102 (cons (list server chnl
)
103 erc-autojoin-channels-alist
))))))
104 ;; We must return nil to tell ERC to continue running the other
108 ;; (erc-parse-user "kensanata!~user@dclient217-162-233-228.hispeed.ch")
110 (defun erc-autojoin-remove (proc parsed
)
111 "Remove the channel being left from `erc-autojoin-channels-alist'."
112 (let* ((chnl (car (erc-response.command-args parsed
)))
113 (nick (car (erc-parse-user (erc-response.sender parsed
))))
114 (server (with-current-buffer (process-buffer proc
)
115 (or erc-server-announced-name erc-session-server
))))
116 (when (erc-current-nick-p nick
)
117 (when (and erc-autojoin-domain-only
118 (string-match "[^.\n]+\\.\\([^.\n]+\\.[^.\n]+\\)$" server
))
119 (setq server
(match-string 1 server
)))
120 (let ((elem (assoc server erc-autojoin-channels-alist
)))
122 (setcdr elem
(delete chnl
(cdr elem
)))
124 (setq erc-autojoin-channels-alist
125 (delete elem erc-autojoin-channels-alist
)))))))
126 ;; We must return nil to tell ERC to continue running the other
132 ;;; erc-join.el ends here
135 ;; indent-tabs-mode: t
139 ;; arch-tag: d62d8b15-8e31-49d6-8a73-12f11e717414