changeset 105396:7f82f9367cd1

(rmail-generate-viewer-buffer): Be more careful about reusing existing buffers, in case we happen to visit two files with the same basename. (Bug#4593)
author Glenn Morris <rgm@gnu.org>
date Sat, 03 Oct 2009 02:07:28 +0000
parents 175a7f7ac069
children 31fd98c59048
files lisp/ChangeLog lisp/mail/rmail.el
diffstat 2 files changed, 18 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Fri Oct 02 19:53:53 2009 +0000
+++ b/lisp/ChangeLog	Sat Oct 03 02:07:28 2009 +0000
@@ -1,3 +1,9 @@
+2009-10-03  Glenn Morris  <rgm@gnu.org>
+
+	* mail/rmail.el (rmail-generate-viewer-buffer): Be more careful about
+	reusing existing buffers, in case we happen to visit two files with the
+	same basename.  (Bug#4593)
+
 2009-10-02  Eli Zaretskii  <eliz@gnu.org>
 
 	* makefile.w32-in (update-subdirs-CMD): Add cedet to
--- a/lisp/mail/rmail.el	Fri Oct 02 19:53:53 2009 +0000
+++ b/lisp/mail/rmail.el	Sat Oct 03 02:07:28 2009 +0000
@@ -1294,11 +1294,15 @@
 (defun rmail-generate-viewer-buffer ()
   "Return a reusable buffer suitable for viewing messages.
 Create the buffer if necessary."
-  (let* ((suffix (file-name-nondirectory (or buffer-file-name (buffer-name))))
-	 (name (format " *message-viewer %s*" suffix))
-	 (buf (get-buffer name)))
-    (or buf
-	(generate-new-buffer name))))
+  ;; We want to reuse any existing view buffer, so as not to create an
+  ;; endless number of them.  But we must avoid clashes if we visit
+  ;; two different rmail files with the same basename (Bug#4593).
+  (if (and (local-variable-p 'rmail-view-buffer)
+	   (buffer-live-p rmail-view-buffer))
+      rmail-view-buffer
+    (generate-new-buffer
+     (format " *message-viewer %s*"
+	     (file-name-nondirectory (or buffer-file-name (buffer-name)))))))
 
 (defun rmail-swap-buffers ()
   "Swap text between current buffer and `rmail-view-buffer'.
@@ -1367,6 +1371,9 @@
   (set-buffer-multibyte nil)
   (with-current-buffer (setq rmail-view-buffer (rmail-generate-viewer-buffer))
     (setq buffer-undo-list t)
+    ;; Note that this does not erase the buffer.  Should it?
+    ;; It depends on how this is called.  If somehow called with the
+    ;; rmail buffers swapped, it would erase the message collection.
     (set (make-local-variable 'rmail-overlay-list) nil)
     (set-buffer-multibyte t)
     ;; Force C-x C-s write Unix EOLs.