From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Chong Yidong Newsgroups: gmane.emacs.bugs Subject: bug#5521: 23.1; erc - allow autojoin to be delayed till after services ident Date: Sat, 17 Jul 2010 19:37:16 -0400 Message-ID: <871vb1he8j.fsf@stupidchicken.com> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1279411257 28506 80.91.229.12 (18 Jul 2010 00:00:57 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 18 Jul 2010 00:00:57 +0000 (UTC) Cc: 5521@debbugs.gnu.org, Vivek Dasmohapatra To: Michael Olson Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Jul 18 02:00:55 2010 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1OaHJO-0002YY-Eb for geb-bug-gnu-emacs@m.gmane.org; Sun, 18 Jul 2010 02:00:54 +0200 Original-Received: from localhost ([127.0.0.1]:48302 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OaHJO-0005GE-1X for geb-bug-gnu-emacs@m.gmane.org; Sat, 17 Jul 2010 20:00:54 -0400 Original-Received: from [140.186.70.92] (port=56813 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OaHJ2-000583-OP for bug-gnu-emacs@gnu.org; Sat, 17 Jul 2010 20:00:33 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OaHJ1-0006UU-G3 for bug-gnu-emacs@gnu.org; Sat, 17 Jul 2010 20:00:32 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:56439) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OaHJ1-0006UQ-Ds for bug-gnu-emacs@gnu.org; Sat, 17 Jul 2010 20:00:31 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1OaGzD-00008G-Au; Sat, 17 Jul 2010 19:40:03 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: Resent-From: Chong Yidong Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 17 Jul 2010 23:40:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 5521 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 5521-submit@debbugs.gnu.org id=B5521.1279409948499 (code B ref 5521); Sat, 17 Jul 2010 23:40:03 +0000 Original-Received: (at 5521) by debbugs.gnu.org; 17 Jul 2010 23:39:08 +0000 Original-Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OaGyJ-000080-NY for submit@debbugs.gnu.org; Sat, 17 Jul 2010 19:39:08 -0400 Original-Received: from pantheon-po44.its.yale.edu ([130.132.50.78]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OaGyI-00007e-5G for 5521@debbugs.gnu.org; Sat, 17 Jul 2010 19:39:06 -0400 Original-Received: from furry (dhcp128036163030.central.yale.edu [128.36.163.30]) (authenticated bits=0) by pantheon-po44.its.yale.edu (8.12.11.20060308/8.12.11) with ESMTP id o6HNdKL0022986 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Sat, 17 Jul 2010 19:39:21 -0400 Original-Received: by furry (Postfix, from userid 1000) id 539ABC013; Sat, 17 Jul 2010 19:37:16 -0400 (EDT) X-YaleITSMailFilter: Version 1.2c (attachment(s) not renamed) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Sat, 17 Jul 2010 19:40:03 -0400 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:38648 Archived-At: > Some irc channels can only be joined by identified users, but since > identification may not happen until some time after a server > connection is established, autojoin currently happens too early for > these channels. > This patch allows the autojoin timing to be selected: > - on connect (as currently) > - after successful ident > If after-ident is chosen, there is also a customiseable timeout which > kicks in and starts autojoin anyway if an ident isn't received in the > alloted time. Hi Michael, Any objection to checking in this patch? (I did some cleanup of what Vivek originally sent). *** lisp/erc/erc-join.el 2010-01-13 08:35:10 +0000 --- lisp/erc/erc-join.el 2010-07-17 23:34:40 +0000 *************** *** 42,50 **** --- 42,52 ---- (define-erc-module autojoin nil "Makes ERC autojoin on connects and reconnects." ((add-hook 'erc-after-connect 'erc-autojoin-channels) + (add-hook 'erc-nickserv-identified-hook 'erc-autojoin-after-ident) (add-hook 'erc-server-JOIN-functions 'erc-autojoin-add) (add-hook 'erc-server-PART-functions 'erc-autojoin-remove)) ((remove-hook 'erc-after-connect 'erc-autojoin-channels) + (remove-hook 'erc-nickserv-identified-hook 'erc-autojoin-after-ident) (remove-hook 'erc-server-JOIN-functions 'erc-autojoin-add) (remove-hook 'erc-server-PART-functions 'erc-autojoin-remove))) *************** *** 66,71 **** --- 68,91 ---- (repeat :tag "Channels" (string :tag "Name"))))) + (defcustom erc-autojoin-timing :connect + "When ERC should attempt to autojoin a channel. + If the value is `:connect', autojoin immediately on connecting. + If the value is `:ident', autojoin after successful NickServ + identification, or after `erc-autojoin-delay' seconds. + Any other value means the same as `:connect'." + :group 'erc-autojoin + :type '(choice (const :tag "On Connection" :connect) + (const :tag "When Identified" :ident))) + + (defcustom erc-autojoin-delay 30 + "Number of seconds to wait before attempting to autojoin channels. + This only takes effect if `erc-autojoin-timing' is `:ident'. + If NickServ identification occurs before this delay expires, ERC + autojoins immediately at that time." + :group 'erc-autojoin + :type 'integer) + (defcustom erc-autojoin-domain-only t "Truncate host name to the domain name when joining a server. If non-nil, and a channel on the server a.b.c is joined, then *************** *** 75,86 **** :group 'erc-autojoin :type 'boolean) (defun erc-autojoin-channels (server nick) "Autojoin channels in `erc-autojoin-channels-alist'." ! (dolist (l erc-autojoin-channels-alist) ! (when (string-match (car l) server) ! (dolist (chan (cdr l)) ! (erc-server-send (concat "join " chan)))))) (defun erc-autojoin-add (proc parsed) "Add the channel being joined to `erc-autojoin-channels-alist'." --- 95,154 ---- :group 'erc-autojoin :type 'boolean) + (defvar erc-autojoin-timer nil) + (make-variable-buffer-local 'erc-autojoin-timer) + + (defun erc-autojoin-channels-delayed (server nick buffer) + "Attempt to autojoin channels. + This is called from a timer set up by `erc-autojoin-channels'." + (if erc-autojoin-timer + (setq erc-autojoin-timer + (erc-cancel-timer erc-autojoin-timer))) + (with-current-buffer buffer + ;; Don't kick of another delayed autojoin or try to wait for + ;; another ident response: + (let ((erc-autojoin-delay -1) + (erc-autojoin-timing :connect)) + (erc-log "Delayed autojoin started (no ident success detected yet)") + (erc-autojoin-channels server nick)))) + + (defun erc-autojoin-after-ident (network nick) + "Autojoin channels in `erc-autojoin-channels-alist'. + This function is run from `erc-nickserv-identified-hook'." + (if erc-autojoin-timer + (setq erc-autojoin-timer + (erc-cancel-timer erc-autojoin-timer))) + (when (eq erc-autojoin-timing :ident) + (let ((server (or erc-server-announced-name erc-session-server)) + (joined (mapcar (lambda (buf) + (with-current-buffer buf (erc-default-target))) + (erc-channel-list erc-server-process)))) + ;; 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) + (dolist (chan (cdr l)) + (unless (erc-member-ignore-case chan joined) + (erc-server-send (concat "join " chan)))))))) + nil) + (defun erc-autojoin-channels (server nick) "Autojoin channels in `erc-autojoin-channels-alist'." ! (if (eq erc-autojoin-timing :ident) ! ;; Prepare the delayed autojoin timer, in case ident doesn't ! ;; happen within the allotted time limit: ! (when (> erc-autojoin-delay 0) ! (setq erc-autojoin-timer ! (run-with-timer erc-autojoin-delay nil ! 'erc-autojoin-channels-delayed ! server nick (current-buffer)))) ! ;; `erc-autojoin-timing' is `:connect': ! (dolist (l erc-autojoin-channels-alist) ! (when (string-match (car l) server) ! (dolist (chan (cdr l)) ! (erc-server-send (concat "join " chan)))))) ! ;; Return nil to avoid stomping on any other hook funcs. ! nil) (defun erc-autojoin-add (proc parsed) "Add the channel being joined to `erc-autojoin-channels-alist'."