From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Julien Danjou Newsgroups: gmane.emacs.devel Subject: [PATCH] erc: check that buffer is alive in sentinel Date: Sat, 23 Oct 2010 14:43:00 +0200 Message-ID: <1287837780-14235-1-git-send-email-julien@danjou.info> NNTP-Posting-Host: lo.gmane.org X-Trace: dough.gmane.org 1287838481 26931 80.91.229.12 (23 Oct 2010 12:54:41 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 23 Oct 2010 12:54:41 +0000 (UTC) Cc: Julien Danjou To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Oct 23 14:54:40 2010 Return-path: Envelope-to: ged-emacs-devel@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 1P9dcN-0003CW-43 for ged-emacs-devel@m.gmane.org; Sat, 23 Oct 2010 14:54:39 +0200 Original-Received: from localhost ([127.0.0.1]:33254 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P9dcM-0007yt-DC for ged-emacs-devel@m.gmane.org; Sat, 23 Oct 2010 08:54:38 -0400 Original-Received: from [140.186.70.92] (port=50026 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P9dcA-0007WV-N9 for emacs-devel@gnu.org; Sat, 23 Oct 2010 08:54:28 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P9dRH-0007bL-8z for emacs-devel@gnu.org; Sat, 23 Oct 2010 08:43:12 -0400 Original-Received: from prometheus.naquadah.org ([212.85.154.174]:55631 helo=mx1.naquadah.org) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P9dRH-0007as-1c for emacs-devel@gnu.org; Sat, 23 Oct 2010 08:43:11 -0400 Original-Received: by mx1.naquadah.org (Postfix, from userid 8) id A76B95C185; Sat, 23 Oct 2010 14:43:07 +0200 (CEST) Original-Received: from keller.adm.naquadah.org (quark.naquadah.org [62.147.146.92]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.naquadah.org (Postfix) with ESMTPSA id ABDD15C09C; Sat, 23 Oct 2010 14:43:05 +0200 (CEST) Original-Received: from jd by keller.adm.naquadah.org with local (Exim 4.72) (envelope-from ) id 1P9dRA-0003iI-Ec; Sat, 23 Oct 2010 14:43:04 +0200 X-Mailer: git-send-email 1.7.2.3 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:132017 Archived-At: Signed-off-by: Julien Danjou --- lisp/erc/ChangeLog | 5 ++++ lisp/erc/erc-backend.el | 49 ++++++++++++++++++++++++----------------------- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/lisp/erc/ChangeLog b/lisp/erc/ChangeLog index 81bdf54..3443e3b 100644 --- a/lisp/erc/ChangeLog +++ b/lisp/erc/ChangeLog @@ -1,3 +1,8 @@ +2010-10-23 Julien Danjou + + * erc-backend.el (erc-process-sentinel): Check that buffer is + alive before setting it as current buffer. + 2010-10-14 Juanma Barranquero * erc-xdcc.el (erc-xdcc-help-text): Fix typo in docstring. diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el index 9a237d4..65d8ce1 100644 --- a/lisp/erc/erc-backend.el +++ b/lisp/erc/erc-backend.el @@ -653,30 +653,31 @@ Conditionally try to reconnect and take appropriate action." (defun erc-process-sentinel (cproc event) "Sentinel function for ERC process." - (with-current-buffer (process-buffer cproc) - (erc-log (format - "SENTINEL: proc: %S status: %S event: %S (quitting: %S)" - cproc (process-status cproc) event erc-server-quitting)) - (if (string-match "^open" event) - ;; newly opened connection (no wait) - (erc-login) - ;; assume event is 'failed - (let ((buf (process-buffer cproc))) - (erc-with-all-buffers-of-server cproc nil - (setq erc-server-connected nil)) - (when erc-server-ping-handler - (progn (erc-cancel-timer erc-server-ping-handler) - (setq erc-server-ping-handler nil))) - (run-hook-with-args 'erc-disconnected-hook - (erc-current-nick) (system-name) "") - ;; Remove the prompt - (goto-char (or (marker-position erc-input-marker) (point-max))) - (forward-line 0) - (erc-remove-text-properties-region (point) (point-max)) - (delete-region (point) (point-max)) - ;; Decide what to do with the buffer - ;; Restart if disconnected - (erc-process-sentinel-1 event buf))))) + (let ((buf (process-buffer cproc))) + (when (buffer-live-p buf) + (with-current-buffer buf + (erc-log (format + "SENTINEL: proc: %S status: %S event: %S (quitting: %S)" + cproc (process-status cproc) event erc-server-quitting)) + (if (string-match "^open" event) + ;; newly opened connection (no wait) + (erc-login) + ;; assume event is 'failed + (erc-with-all-buffers-of-server cproc nil + (setq erc-server-connected nil)) + (when erc-server-ping-handler + (progn (erc-cancel-timer erc-server-ping-handler) + (setq erc-server-ping-handler nil))) + (run-hook-with-args 'erc-disconnected-hook + (erc-current-nick) (system-name) "") + ;; Remove the prompt + (goto-char (or (marker-position erc-input-marker) (point-max))) + (forward-line 0) + (erc-remove-text-properties-region (point) (point-max)) + (delete-region (point) (point-max)) + ;; Decide what to do with the buffer + ;; Restart if disconnected + (erc-process-sentinel-1 event buf)))))) ;;;; Sending messages -- 1.7.2.3