all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Vivek Dasmohapatra <vivek@etla.org>
To: 5563@debbugs.gnu.org
Subject: bug#5563: zealously reacquiring orphaned erc buffers
Date: Sat, 13 Feb 2010 02:06:54 +0000 (GMT)	[thread overview]
Message-ID: <alpine.DEB.2.00.1002130200290.12837@octopus.pepperfish.net> (raw)
In-Reply-To: <m3d40bu2q8.fsf@fleche.redhat.com>

[-- Attachment #1: Type: TEXT/PLAIN, Size: 246 bytes --]

Tags: patch

This patch should address the case you are seeing - you'll still get
orphaned buffers if you connect to the same server on different ports,
but the patch is trivially extendable to cover that case, should we
decide we care about it.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: TEXT/x-diff; name=0001-Be-smarter-about-reacquiring-orphaned-erc-buffers.patch, Size: 2584 bytes --]

diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el
--- a/lisp/erc/erc.el
+++ b/lisp/erc/erc.el
@@ -1566,26 +1566,33 @@ symbol, it may have these values:
 (defun erc-generate-new-buffer-name (server port target &optional proc)
   "Create a new buffer name based on the arguments."
   (when (numberp port) (setq port (number-to-string port)))
-  (let* ((buf-name (or target
-		       (or (let ((name (concat server ":" port)))
-			     (when (> (length name) 1)
-			       name))
-			   ; This fallback should in fact never happen
-			   "*erc-server-buffer*"))))
+  (let ((buf-name (or target
+                      (or (let ((name (concat server ":" port)))
+                            (when (> (length name) 1)
+                              name))
+                          ;; This fallback should in fact never happen
+                          "*erc-server-buffer*")))
+        buffer-name)
     ;; Reuse existing buffers, but not if the buffer is a connected server
     ;; buffer and not if its associated with a different server than the
     ;; current ERC buffer.
-    (if (and erc-reuse-buffers
-	     (get-buffer buf-name)
-	     (or target
-		 (with-current-buffer (get-buffer buf-name)
-		   (and (erc-server-buffer-p)
-			(not (erc-server-process-alive)))))
-	     (with-current-buffer (get-buffer buf-name)
-	       (and (string= erc-session-server server)
-		    (erc-port-equal erc-session-port port))))
-	buf-name
-      (generate-new-buffer-name buf-name))))
+    ;; if buf-name is taken by a different connection (or by something !erc)
+    ;; then see if "buf-name/server" meets the same criteria
+    (dolist (candidate (list buf-name (concat buf-name "/" server))) 
+      (if (and (not buffer-name)
+               erc-reuse-buffers
+               (get-buffer candidate)
+               (or target
+                   (with-current-buffer (get-buffer candidate)
+                     (and (erc-server-buffer-p)
+                          (not (erc-server-process-alive)))))
+               (with-current-buffer (get-buffer candidate)
+                 (and (string= erc-session-server server)
+                      (erc-port-equal erc-session-port port))))
+          (setq buffer-name candidate)))
+    ;; if buffer-name is unset, neither candidate worked out for us,
+    ;; fallback to the old <N> uniquification method:
+    (or buffer-name (generate-new-buffer-name buf-name)) ))
 
 (defun erc-get-buffer-create (server port target &optional proc)
   "Create a new buffer based on the arguments."



  reply	other threads:[~2010-02-13  2:06 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-11 17:00 bug#5563: 23.1; erc reconnection should reuse existing buffers Tom Tromey
2010-02-13  2:06 ` Vivek Dasmohapatra [this message]
2011-07-03 19:44   ` bug#5563: zealously reacquiring orphaned erc buffers Lars Magne Ingebrigtsen
2011-07-04 13:01     ` Vivek Dasmohapatra
2011-07-04 13:23       ` Lars Magne Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.DEB.2.00.1002130200290.12837@octopus.pepperfish.net \
    --to=vivek@etla.org \
    --cc=5563@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.