changeset 112270:cc0887b67703

Merge from emacs-23 branch, up to r100382. Note: emacs-23 r100373 is rendered unnecessary by pre-existing 2010-05-20 trunk change.
author Glenn Morris <rgm@gnu.org>
date Sat, 15 Jan 2011 12:38:27 -0800
parents 4f72b1e43644 (current diff) 0534ddfdceeb (diff)
children 8f641c1fc9cc
files doc/emacs/ChangeLog doc/emacs/building.texi doc/emacs/files.texi etc/NEWS.23 lisp/ChangeLog lisp/files.el lisp/gnus/ChangeLog lisp/gnus/message.el lisp/mail/rmailmm.el lisp/subr.el src/ChangeLog src/window.c
diffstat 12 files changed, 305 insertions(+), 151 deletions(-) [+]
line wrap: on
line diff
--- a/doc/emacs/ChangeLog	Sat Jan 15 12:03:38 2011 -0800
+++ b/doc/emacs/ChangeLog	Sat Jan 15 12:38:27 2011 -0800
@@ -1,5 +1,11 @@
 2011-01-15  Chong Yidong  <cyd@stupidchicken.com>
 
+	* building.texi (Compilation): Improve instructions for running two
+	compilations (Bug#7573).
+
+	* files.texi (Backup Names): Document the new location of the
+	last-resort backup file.
+
 	* files.texi (File Aliases): Move directory-abbrev-alist doc from Lisp
 	manual.  Explain why directory-abbrev-alist elements should be anchored
 	(Bug#7777).
--- a/doc/emacs/building.texi	Sat Jan 15 12:03:38 2011 -0800
+++ b/doc/emacs/building.texi	Sat Jan 15 12:38:27 2011 -0800
@@ -122,10 +122,10 @@
 You can also kill the compilation process with @kbd{M-x
 kill-compilation}.
 
-  If you want to run two compilations at once, you should start the
-first one, then rename the @samp{*compilation*} buffer (perhaps using
-@code{rename-uniquely}; @pxref{Misc Buffer}), and start the other
-compilation.  That will create a new @samp{*compilation*} buffer.
+  To run two compilations at once, start the first one, then rename
+the @samp{*compilation*} buffer (perhaps using @code{rename-uniquely};
+@pxref{Misc Buffer}), then switch buffers and start the other
+compilation.  This will create a new @samp{*compilation*} buffer.
 
   Emacs does not expect a compiler process to launch asynchronous
 subprocesses; if it does, and they keep running after the main
--- a/doc/emacs/files.texi	Sat Jan 15 12:03:38 2011 -0800
+++ b/doc/emacs/files.texi	Sat Jan 15 12:38:27 2011 -0800
@@ -568,10 +568,10 @@
 appending @samp{~} to the file name being edited; thus, the backup
 file for @file{eval.c} would be @file{eval.c~}.
 
-  If access control stops Emacs from writing backup files under the usual
-names, it writes the backup file as @file{%backup%~} in your home
-directory.  Only one such file can exist, so only the most recently
-made such backup is available.
+  If access control stops Emacs from writing backup files under the
+usual names, it writes the backup file as @file{~/.emacs.d/%backup%~}.
+Only one such file can exist, so only the most recently made such
+backup is available.
 
   Emacs can also make @dfn{numbered backup files}.  Numbered backup
 file names contain @samp{.~}, the number, and another @samp{~} after
--- a/etc/NEWS.23	Sat Jan 15 12:03:38 2011 -0800
+++ b/etc/NEWS.23	Sat Jan 15 12:38:27 2011 -0800
@@ -21,6 +21,10 @@
 
 * Changes in Emacs 23.3
 
++++
+** The last-resort backup file `%backup%~' is now written to
+`user-emacs-directory', instead of the user's home directory.
+
 
 * Editing Changes in Emacs 23.3
 
--- a/lisp/ChangeLog	Sat Jan 15 12:03:38 2011 -0800
+++ b/lisp/ChangeLog	Sat Jan 15 12:38:27 2011 -0800
@@ -1,3 +1,65 @@
+2011-01-15  Mark Diekhans  <markd@soe.ucsc.edu>
+
+	* files.el (backup-buffer): Make last-resort backup file in
+	.emacs.d (Bug#6953).
+
+	* subr.el (locate-user-emacs-file): If .emacs.d does not exist,
+	make it with permission 700.
+
+2011-01-15  Kenichi Handa  <handa@m17n.org>
+
+	* mail/rmailmm.el (rmail-mime-insert-header): Set
+	rmail-mime-coding-system to a cons whose car is the last coding
+	system used to decode the header.
+	(rmail-mime-find-header-encoding): New function.
+	(rmail-mime-insert-decoded-text): Override
+	rmail-mime-coding-system if it is a cons.
+	(rmail-show-mime): If only a header part was decoded, find the
+	coding system while ignoring mm-charset-override-alist.
+
+2011-01-15  Chong Yidong  <cyd@stupidchicken.com>
+
+	* subr.el (event-start, event-end): Doc fix (Bug#7826).
+
+2011-01-15  Kenichi Handa  <handa@m17n.org>
+
+	* mail/rmailmm.el (rmail-mime-next-item)
+	(rmail-mime-previous-item): Delete them.
+	(rmail-mime-shown-mode): Recursively call for children.
+	(rmail-mime-hidden-mode): Delete the 2nd arg TOP.  Callers
+	changed.
+	(rmail-mime-raw-mode): Recursively call for children.
+	(rmail-mode-map): Change mapping of tab and backtab to
+	forward-button and backward-button respectively.
+	(rmail-mime-insert-tagline): Always insert "Hide" or "Show"
+	button.
+	(rmail-mime-update-tagline): New function.
+	(rmail-mime-insert-text): Call rmail-mime-update-tagline if the
+	body display is changed.
+	(rmail-mime-toggle-button): Renamed from rmail-mime-image.
+	(rmail-mime-image): Delete this button type.
+	(rmail-mime-toggle): New button type.
+	(rmail-mime-insert-bulk): Call rmail-mime-update-tagline if the
+	body display is changed.  Change the save button label to "Save".
+	Don't process show/hide button here.
+	(rmail-mime-insert-multipart): Call rmail-mime-update-tagline if
+	the body display is changed.  Unconditionally call
+	rmail-mime-insert for children.
+	(rmail-mime-handle): Update `display' vector of the just inserted
+	entity.
+	(rmail-mime-process): If mail-header-parse-content-type returns
+	nil, use "text/plain" as the fallback type.
+	(rmail-mime-insert): For raw-mode, recursively call
+	rmail-mim-insert for children.
+	(rmail-mime): Handle the case that the current buffer is not rmail
+	buffer (e.g. in summary buffer).
+
+2011-01-15  Kenichi Handa  <handa@m17n.org>
+
+	* mail/rmailmm.el (rmail-mime-next-item)
+	(rmail-mime-previous-item): Skip the body of a non-multipart
+	entity if a tagline is shown.
+
 2011-01-15  Stefan Monnier  <monnier@iro.umontreal.ca>
 
 	* tmm.el (tmm-get-keymap): Skip bindings without labels (bug#7721).
--- a/lisp/files.el	Sat Jan 15 12:03:38 2011 -0800
+++ b/lisp/files.el	Sat Jan 15 12:38:27 2011 -0800
@@ -3778,10 +3778,9 @@
 			(rename-file real-file-name backupname t)
 			(setq setmodes (list modes context backupname)))
 		    (file-error
-		     ;; If trouble writing the backup, write it in ~.
-		     (setq backupname (expand-file-name
-				       (convert-standard-filename
-					"~/%backup%~")))
+		     ;; If trouble writing the backup, write it in
+		     ;; .emacs.d/%backup%.
+		     (setq backupname (locate-user-emacs-file "%backup%~"))
 		     (message "Cannot write backup file; backing up in %s"
 			      backupname)
 		     (sleep-for 1)
--- a/lisp/gnus/ChangeLog	Sat Jan 15 12:03:38 2011 -0800
+++ b/lisp/gnus/ChangeLog	Sat Jan 15 12:38:27 2011 -0800
@@ -1,3 +1,8 @@
+2011-01-15  Glenn Morris  <rgm@gnu.org>
+
+	* message.el (message-mail): A compose-mail function should
+	accept headers as strings.
+
 2011-01-13  Chong Yidong  <cyd@stupidchicken.com>
 
 	* message.el (message-tool-bar-gnome): Tweak tool-bar items.  Add
--- a/lisp/gnus/message.el	Sat Jan 15 12:03:38 2011 -0800
+++ b/lisp/gnus/message.el	Sat Jan 15 12:38:27 2011 -0800
@@ -6512,7 +6512,13 @@
     (message-setup
      (nconc
       `((To . ,(or to "")) (Subject . ,(or subject "")))
-      (when other-headers other-headers))
+      ;; C-h f compose-mail says that headers should be specified as
+      ;; (string . value); however all the rest of message expects
+      ;; headers to be symbols, not strings (eg message-header-format-alist).
+      ;; http://lists.gnu.org/archive/html/emacs-devel/2011-01/msg00337.html
+      ;; We need to convert any string input, eg from rmail-start-mail.
+      (dolist (h other-headers other-headers)
+ 	(if (stringp (car h)) (setcar h (intern (capitalize (car h)))))))
      yank-action send-actions continue switch-function
      return-action)
     ;; FIXME: Should return nil if failure.
--- a/lisp/mail/rmailmm.el	Sat Jan 15 12:03:38 2011 -0800
+++ b/lisp/mail/rmailmm.el	Sat Jan 15 12:38:27 2011 -0800
@@ -274,11 +274,11 @@
   "Return a vector describing the displayed region of a MIME-entity at POS.
 Optional 2nd argument ENTITY is the MIME-entity at POS.
 The value is a vector [ INDEX HEADER TAGLINE BODY END], where
+  INDEX: index into the returned vector indicating where POS is (1..3).
   HEADER: the position of the beginning of a header
   TAGLINE: the position of the beginning of a tagline
   BODY: the position of the beginning of a body
-  END: the position of the end of the entity.
-  INDEX: index into the returned vector indicating where POS is."
+  END: the position of the end of the entity."
   (save-excursion
     (or entity
 	(setq entity (get-text-property pos 'rmail-mime-entity)))
@@ -319,74 +319,32 @@
 	  (setq end body-beg))
 	(vector index beg tagline-beg body-beg end)))))
 
-(defun rmail-mime-next-item ()
-  "Move point to the next displayed item of the current MIME entity.
-A MIME entity has three items; header, tagline, and body.
-If we are in the last item of the entity, move point to the first
-item of the next entity.  If we reach the end of buffer, move
-point to the first item of the first entity (i.e. the beginning
-of buffer)."
-  (interactive)
-  (if (rmail-mime-message-p)
-      (let* ((segment (rmail-mime-entity-segment (point)))
-	     (next-pos (aref segment (1+ (aref segment 0))))
-	     (button (next-button (point))))
-	(goto-char (if (and button (< (button-start button) next-pos))
-		       (button-start button)
-		     next-pos))
-	(if (eobp)
-	    (goto-char (point-min))))))
-
-(defun rmail-mime-previous-item ()
-  "Move point to the previous displayed item of the current MIME message.
-A MIME entity has three items; header, tagline, and body.
-If we are at the beginning of the first item of the entity, move
-point to the last item of the previous entity.  If we reach the
-beginning of buffer, move point to the last item of the last
-entity."
-  (interactive)
-  (when (rmail-mime-message-p)
-    (if (bobp)
-	(goto-char (point-max)))
-    (let* ((segment (rmail-mime-entity-segment (1- (point))))
-	   (prev-pos (aref segment (aref segment 0)))
-	   (button (previous-button (point))))
-      (goto-char (if (and button (> (button-start button) prev-pos))
-		     (button-start button)
-		   prev-pos)))))
-
 (defun rmail-mime-shown-mode (entity)
   "Make MIME-entity ENTITY displayed by the default way."
   (let ((new (aref (rmail-mime-entity-display entity) 1)))
     (aset new 0 (aref (rmail-mime-entity-header entity) 2))
     (aset new 1 (aref (rmail-mime-entity-tagline entity) 2))
-    (aset new 2 (aref (rmail-mime-entity-body entity) 2))))
+    (aset new 2 (aref (rmail-mime-entity-body entity) 2)))
+  (dolist (child (rmail-mime-entity-children entity))
+    (rmail-mime-shown-mode child)))
 
-(defun rmail-mime-hidden-mode (entity top)
-  "Make MIME-entity ENTITY displayed in the hidden mode.
-If TOP is non-nil, display ENTITY only by the tagline.
-Otherwise, don't display ENTITY."
-  (if top
-      (let ((new (aref (rmail-mime-entity-display entity) 1)))
-	(aset new 0 nil)
-	(aset new 1 top)
-	(aset new 2 nil)
-	(aset (rmail-mime-entity-body entity) 2 nil))
-    (let ((current (aref (rmail-mime-entity-display entity) 0)))
-      (aset current 0 nil)
-      (aset current 1 nil)
-      (aset current 2 nil)))
+(defun rmail-mime-hidden-mode (entity)
+  "Make MIME-entity ENTITY displayed in the hidden mode."
+  (let ((new (aref (rmail-mime-entity-display entity) 1)))
+    (aset new 0 nil)
+    (aset new 1 t)
+    (aset new 2 nil))
   (dolist (child (rmail-mime-entity-children entity))
-    (rmail-mime-hidden-mode child nil)))
+    (rmail-mime-hidden-mode child)))
 
 (defun rmail-mime-raw-mode (entity)
   "Make MIME-entity ENTITY displayed in the raw mode."
   (let ((new (aref (rmail-mime-entity-display entity) 1)))
     (aset new 0 'raw)
     (aset new 1 nil)
-    (aset new 2 'raw)
-    (dolist (child (rmail-mime-entity-children entity))
-      (rmail-mime-hidden-mode child nil))))
+    (aset new 2 'raw))
+  (dolist (child (rmail-mime-entity-children entity))
+    (rmail-mime-raw-mode child)))
 
 (defun rmail-mime-toggle-raw (entity)
   "Toggle on and off the raw display mode of MIME-entity ENTITY."
@@ -407,7 +365,7 @@
 	(restore-buffer-modified-p modified)))))
 
 (defun rmail-mime-toggle-hidden ()
-  "Toggle on and off the hidden display mode of MIME-entity ENTITY."
+  "Hide or show the body of MIME-entity at point."
   (interactive)
   (when (rmail-mime-message-p)
     (let* ((rmail-mime-mbox-buffer rmail-view-buffer)
@@ -420,18 +378,19 @@
 	  ;; Enter the hidden mode.
 	  (progn
 	    ;; If point is in the body part, move it to the tagline
-	    ;; (or the header if headline is not displayed).
+	    ;; (or the header if tagline is not displayed).
 	    (if (= (aref segment 0) 3)
 		(goto-char (aref segment 2)))
-	    (rmail-mime-hidden-mode entity t)
+	    (rmail-mime-hidden-mode entity)
 	    ;; If the current entity is the topmost one, display the
 	    ;; header.
 	    (if (and rmail-mime-mbox-buffer (= (aref segment 1) (point-min)))
 		(let ((new (aref (rmail-mime-entity-display entity) 1)))
 		  (aset new 0 t))))
 	;; Enter the shown mode.
-	(aset (rmail-mime-entity-body entity) 2 t)
-	(rmail-mime-shown-mode entity))
+	(rmail-mime-shown-mode entity)
+	;; Force this body shown.
+	(aset (aref (rmail-mime-entity-display entity) 1) 2 t))
       (let ((inhibit-read-only t)
 	    (modified (buffer-modified-p))
 	    (rmail-mime-mbox-buffer rmail-view-buffer)
@@ -441,8 +400,8 @@
 	  (rmail-mime-insert entity)
 	  (restore-buffer-modified-p modified))))))
 
-(define-key rmail-mode-map "\t" 'rmail-mime-next-item)
-(define-key rmail-mode-map [backtab] 'rmail-mime-previous-item)
+(define-key rmail-mode-map "\t" 'forward-button)
+(define-key rmail-mode-map [backtab] 'backward-button)
 (define-key rmail-mode-map "\r" 'rmail-mime-toggle-hidden)
 
 ;;; Handlers
@@ -454,7 +413,11 @@
   (insert "[")
   (let ((tag (aref (rmail-mime-entity-tagline entity) 0)))
     (if (> (length tag) 0) (insert (substring tag 1) ":")))
-  (insert (car (rmail-mime-entity-type entity)))
+  (insert (car (rmail-mime-entity-type entity)) " ")
+  (insert-button (let ((new (aref (rmail-mime-entity-display entity) 1)))
+		   (if (aref new 2) "Hide" "Show"))
+		 :type 'rmail-mime-toggle
+		 'help-echo "mouse-2, RET: Toggle show/hide")
   (dolist (item item-list)
     (when item
       (if (stringp item)
@@ -462,6 +425,26 @@
 	(apply 'insert-button item))))
   (insert "]\n"))
 
+(defun rmail-mime-update-tagline (entity)
+  "Update the current tag line for MIME-entity ENTITY."
+  (let ((inhibit-read-only t)
+	(modified (buffer-modified-p))
+	;; If we are going to show the body, the new button label is
+	;; "Hide".  Otherwise, it's "Show".
+	(label (if (aref (aref (rmail-mime-entity-display entity) 1) 2) "Hide"
+		 "Show"))
+	(button (next-button (point))))
+    ;; Go to the second character of the button "Show" or "Hide".
+    (goto-char (1+ (button-start button)))
+    (setq button (button-at (point)))
+    (save-excursion
+      (insert label)
+      (delete-region (point) (button-end button)))
+    (delete-region (button-start button) (point))
+    (put-text-property (point) (button-end button) 'rmail-mime-entity entity)
+    (restore-buffer-modified-p modified)
+    (forward-line 1)))
+
 (defun rmail-mime-insert-header (header)
   "Decode and insert a MIME-entity header HEADER in the current buffer.
 HEADER is a vector [BEG END DEFAULT-STATUS].
@@ -478,12 +461,27 @@
 	    (rmail-copy-headers (point) (aref header 1)))))
       (rfc2047-decode-region pos (point))
       (if (and last-coding-system-used (not rmail-mime-coding-system))
-	  (setq rmail-mime-coding-system last-coding-system-used))
+	  (setq rmail-mime-coding-system (cons last-coding-system-used nil)))
       (goto-char (point-min))
       (rmail-highlight-headers)
       (goto-char (point-max))
       (insert "\n"))))
 
+(defun rmail-mime-find-header-encoding (header)
+  "Retun the last coding system used to decode HEADER.
+HEADER is a header component of a MIME-entity object (see
+`rmail-mime-entity')."
+  (with-temp-buffer
+    (let ((last-coding-system-used nil))
+      (with-current-buffer rmail-mime-mbox-buffer
+	(let ((rmail-buffer rmail-mime-mbox-buffer)
+	      (rmail-view-buffer rmail-mime-view-buffer))
+	  (save-excursion
+	    (goto-char (aref header 0))
+	    (rmail-copy-headers (point) (aref header 1)))))
+      (rfc2047-decode-region (point-min) (point-max))
+      last-coding-system-used)))
+
 (defun rmail-mime-text-handler (content-type
 				content-disposition
 				content-transfer-encoding)
@@ -516,7 +514,7 @@
 	      ((string= transfer-encoding "quoted-printable")
 	       (quoted-printable-decode-region pos (point))))))
     (decode-coding-region pos (point) coding-system)
-    (or rmail-mime-coding-system
+    (if (or (not rmail-mime-coding-system) (consp rmail-mime-coding-system))
 	(setq rmail-mime-coding-system coding-system))
     (or (bolp) (insert "\n"))))
 
@@ -544,7 +542,10 @@
 	  (rmail-mime-insert-header header)))
     ;; tagline
     (if (eq (aref current 1) (aref new 1))
-	(forward-char (- (aref segment 3) (aref segment 2)))
+	(if (or (not (aref current 1))
+		(eq (aref current 2) (aref new 2)))
+	    (forward-char (- (aref segment 3) (aref segment 2)))
+	  (rmail-mime-update-tagline entity))
       (if (aref current 1)
 	  (delete-char (- (aref segment 3) (aref segment 2))))
       (if (aref new 1)
@@ -599,13 +600,13 @@
     (insert-image (create-image data (cdr bulk-data) t))
     (insert "\n")))
 
-(defun rmail-mime-image (button)
-  "Display the image associated with BUTTON."
+(defun rmail-mime-toggle-button (button)
+  "Hide or show the body of the MIME-entity associated with BUTTON."
   (save-excursion
-    (goto-char (button-end button))
+    (goto-char (button-start button))
     (rmail-mime-toggle-hidden)))
 
-(define-button-type 'rmail-mime-image 'action 'rmail-mime-image)
+(define-button-type 'rmail-mime-toggle 'action 'rmail-mime-toggle-button)
 
 
 (defun rmail-mime-bulk-handler (content-type
@@ -628,7 +629,7 @@
 	(size (cdr (assq 'size (cdr (rmail-mime-entity-disposition entity)))))
 	(bulk-data (aref (rmail-mime-entity-tagline entity) 1))
 	(body (rmail-mime-entity-body entity))
-	size type to-show)
+	type to-show)
     (cond (size
 	   (setq size (string-to-number size)))
 	  ((stringp (aref body 0))
@@ -662,7 +663,6 @@
 
 (defun rmail-mime-insert-bulk (entity)
   "Presentation handler for an attachment MIME entity."
-  ;; Find the default directory for this media type.
   (let* ((content-type (rmail-mime-entity-type entity))
 	 (content-disposition (rmail-mime-entity-disposition entity))
 	 (current (aref (rmail-mime-entity-display entity) 0))
@@ -671,6 +671,7 @@
 	 (tagline (rmail-mime-entity-tagline entity))
 	 (bulk-data (aref tagline 1))
 	 (body (rmail-mime-entity-body entity))
+	 ;; Find the default directory for this media type.
 	 (directory (catch 'directory
 		      (dolist (entry rmail-mime-attachment-dirs-alist)
 			(when (string-match (car entry) (car content-type))
@@ -711,13 +712,16 @@
 
     ;; tagline
     (if (eq (aref current 1) (aref new 1))
-	(forward-char (- (aref segment 3) (aref segment 2)))
+	(if (or (not (aref current 1))
+		(eq (aref current 2) (aref new 2)))
+	    (forward-char (- (aref segment 3) (aref segment 2)))
+	  (rmail-mime-update-tagline entity))
       (if (aref current 1)
 	  (delete-char (- (aref segment 3) (aref segment 2))))
       (if (aref new 1)
 	  (rmail-mime-insert-tagline
 	   entity
-	   " file:"
+	   " Save:"
 	   (list filename
 		 :type 'rmail-mime-save
 		 'help-echo "mouse-2, RET: Save attachment"
@@ -725,14 +729,17 @@
 		 'directory (file-name-as-directory directory)
 		 'data data)
 	   (format " (%.0f%s)" size (car units))
-	   (if (cdr bulk-data)
-	       " ")
-	   (if (cdr bulk-data)
-	       (list "Toggle show/hide"
-		     :type 'rmail-mime-image
-		     'help-echo "mouse-2, RET: Toggle show/hide"
-		     'image-type (cdr bulk-data)
-		     'image-data data)))))
+	   ;; We don't need this button because the "type" string of a
+	   ;; tagline is the button to do this.
+	   ;; (if (cdr bulk-data)
+	   ;;     " ")
+	   ;; (if (cdr bulk-data)
+	   ;;     (list "Toggle show/hide"
+	   ;; 	     :type 'rmail-mime-image
+	   ;; 	     'help-echo "mouse-2, RET: Toggle show/hide"
+	   ;; 	     'image-type (cdr bulk-data)
+	   ;; 	     'image-data data))
+	   )))
     ;; body
     (if (eq (aref current 2) (aref new 2))
 	(forward-char (- (aref segment 4) (aref segment 3)))
@@ -883,8 +890,9 @@
 			(setq second child)))))
 	    (or best (not second) (setq best second))
 	    (dolist (child entities)
-	      (or (eq best child)
-		  (rmail-mime-hidden-mode child t)))))
+	      (unless (eq best child)
+		(aset (rmail-mime-entity-body child) 2 nil)
+		(rmail-mime-hidden-mode child)))))
       entities)))
 
 (defun test-rmail-mime-multipart-handler ()
@@ -936,21 +944,23 @@
 	  (rmail-mime-insert-header header)))
     ;; tagline
     (if (eq (aref current 1) (aref new 1))
-	(forward-char (- (aref segment 3) (aref segment 2)))
+	(if (or (not (aref current 1))
+		(eq (aref current 2) (aref new 2)))
+	    (forward-char (- (aref segment 3) (aref segment 2)))
+	  (rmail-mime-update-tagline entity))
       (if (aref current 1)
 	  (delete-char (- (aref segment 3) (aref segment 2))))
       (if (aref new 1)
 	  (rmail-mime-insert-tagline entity)))
 
     (put-text-property beg (point) 'rmail-mime-entity entity)
+
     ;; body
     (if (eq (aref current 2) (aref new 2))
 	(forward-char (- (aref segment 4) (aref segment 3)))
-      (if (aref current 2)
-	  (delete-char (- (aref segment 4) (aref segment 3))))
-      (if (aref new 2)
-	  (dolist (child (rmail-mime-entity-children entity))
-	    (rmail-mime-insert child))))))
+      (dolist (child (rmail-mime-entity-children entity))
+	(rmail-mime-insert child)))
+    entity))
 
 ;;; Main code
 
@@ -1011,7 +1021,16 @@
     ;; Everything else is an attachment.
     (rmail-mime-bulk-handler content-type
 		       content-disposition
-		       content-transfer-encoding)))
+		       content-transfer-encoding))
+  (save-restriction
+    (widen)
+    (let ((entity (get-text-property (1- (point)) 'rmail-mime-entity))
+	  current new)
+      (when entity
+	(setq current (aref (rmail-mime-entity-display entity) 0)
+	      new (aref (rmail-mime-entity-display entity) 1))
+	(dotimes (i 3)
+	  (aset current i (aref new i)))))))
 
 (defun rmail-mime-show (&optional show-headers)
   "Handle the current buffer as a MIME message.
@@ -1056,7 +1075,8 @@
 	(setq content-transfer-encoding (downcase content-transfer-encoding)))
     (setq content-type
 	  (if content-type
-	      (mail-header-parse-content-type content-type)
+	      (or (mail-header-parse-content-type content-type)
+		  '("text/plain"))
 	    (or default-content-type '("text/plain"))))
     (setq content-disposition
 	  (if content-disposition
@@ -1184,13 +1204,20 @@
 	(if (aref current 1)
 	    (delete-char (- (aref segment 3) (aref segment 2))))
 	;; body
-	(if (eq (aref current 2) (aref new 2))
-	    (forward-char (- (aref segment 4) (aref segment 3)))
-	  (if (aref current 2)
-	      (delete-char (- (aref segment 4) (aref segment 3))))
-	  (insert-buffer-substring rmail-mime-mbox-buffer
-				   (aref body 0) (aref body 1)))
-	(put-text-property beg (point) 'rmail-mime-entity entity)))
+	(let ((children (rmail-mime-entity-children entity)))
+	  (if children
+	      (progn
+		(put-text-property beg (point) 'rmail-mime-entity entity)
+		(dolist (child children)
+		  (rmail-mime-insert child)))
+	    (if (eq (aref current 2) (aref new 2))
+		(forward-char (- (aref segment 4) (aref segment 3)))
+	      (if (aref current 2)
+		(delete-char (- (aref segment 4) (aref segment 3))))
+	      (insert-buffer-substring rmail-mime-mbox-buffer
+				       (aref body 0) (aref body 1))
+	      (or (bolp) (insert "\n")))
+	    (put-text-property beg (point) 'rmail-mime-entity entity)))))
     (dotimes (i 3)
       (aset current i (aref new i)))))
 
@@ -1218,17 +1245,18 @@
 attachments as specfied by `rmail-mime-attachment-dirs-alist'."
   (interactive "P")
   (if rmail-enable-mime
-      (if (rmail-mime-message-p)
-	  (let ((rmail-mime-mbox-buffer rmail-view-buffer)
-		(rmail-mime-view-buffer rmail-buffer)
-		(entity (get-text-property (point) 'rmail-mime-entity)))
-	    (if arg
-		(if entity
-		    (rmail-mime-toggle-raw entity))
-	      (goto-char (point-min))
-	      (rmail-mime-toggle-raw
-	       (get-text-property (point) 'rmail-mime-entity))))
-	(message "Not a MIME message"))
+      (with-current-buffer rmail-buffer
+	(if (rmail-mime-message-p)
+	    (let ((rmail-mime-mbox-buffer rmail-view-buffer)
+		  (rmail-mime-view-buffer rmail-buffer)
+		  (entity (get-text-property (point) 'rmail-mime-entity)))
+	      (if arg
+		  (if entity
+		      (rmail-mime-toggle-raw entity))
+		(goto-char (point-min))
+		(rmail-mime-toggle-raw
+		 (get-text-property (point) 'rmail-mime-entity))))
+	  (message "Not a MIME message")))
     (let* ((data (rmail-apply-in-message rmail-current-message 'buffer-string))
 	   (buf (get-buffer-create "*RMAIL*"))
 	   (rmail-mime-mbox-buffer rmail-view-buffer)
@@ -1262,8 +1290,19 @@
 	(with-current-buffer rmail-mime-view-buffer
 	  (erase-buffer)
 	  (rmail-mime-insert entity)
-	  (if rmail-mime-coding-system
-	      (set-buffer-file-coding-system rmail-mime-coding-system t t)))
+	  (if (consp rmail-mime-coding-system)
+	      ;; Decoding is done by rfc2047-decode-region only for a
+	      ;; header.  But, as the used coding system may have been
+	      ;; overriden by mm-charset-override-alist, we can't
+	      ;; trust (car rmail-mime-coding-system).  So, here we
+	      ;; try the decoding again with mm-charset-override-alist
+	      ;; bound to nil.
+	      (let ((mm-charset-override-alist nil))
+		(setq rmail-mime-coding-system
+		      (rmail-mime-find-header-encoding
+		       (rmail-mime-entity-header entity)))))
+	  (set-buffer-file-coding-system
+	   (coding-system-base rmail-mime-coding-system) t t))
       ;; Decoding failed.  ENTITY is an error message.  Insert the
       ;; original message body as is, and show warning.
       (let ((region (with-current-buffer rmail-mime-mbox-buffer
--- a/lisp/subr.el	Sat Jan 15 12:03:38 2011 -0800
+++ b/lisp/subr.el	Sat Jan 15 12:38:27 2011 -0800
@@ -853,24 +853,37 @@
 
 (defsubst event-start (event)
   "Return the starting position of EVENT.
-If EVENT is a mouse or key press or a mouse click, this returns the location
-of the event.
-If EVENT is a drag, this returns the drag's starting position.
-The return value is of the form
+EVENT should be a click, drag, or key press event.
+If it is a key press event, the return value has the form
+    (WINDOW POS (0 . 0) 0)
+If it is a click or drag event, it has the form
    (WINDOW AREA-OR-POS (X . Y) TIMESTAMP OBJECT POS (COL . ROW)
     IMAGE (DX . DY) (WIDTH . HEIGHT))
-The `posn-' functions access elements of such lists."
+The `posn-' functions access elements of such lists.
+For more information, see Info node `(elisp)Click Events'.
+
+If EVENT is a mouse or key press or a mouse click, this is the
+position of the event.  If EVENT is a drag, this is the starting
+position of the drag."
   (if (consp event) (nth 1 event)
     (list (selected-window) (point) '(0 . 0) 0)))
 
 (defsubst event-end (event)
   "Return the ending location of EVENT.
 EVENT should be a click, drag, or key press event.
-If EVENT is a click event, this function is the same as `event-start'.
-The return value is of the form
+If EVENT is a key press event, the return value has the form
+    (WINDOW POS (0 . 0) 0)
+If EVENT is a click event, this function is the same as
+`event-start'.  For click and drag events, the return value has
+the form
    (WINDOW AREA-OR-POS (X . Y) TIMESTAMP OBJECT POS (COL . ROW)
     IMAGE (DX . DY) (WIDTH . HEIGHT))
-The `posn-' functions access elements of such lists."
+The `posn-' functions access elements of such lists.
+For more information, see Info node `(elisp)Click Events'.
+
+If EVENT is a mouse or key press or a mouse click, this is the
+position of the event.  If EVENT is a drag, this is the starting
+position of the drag."
   (if (consp event) (nth (if (consp (nth 2 event)) 2 1) event)
     (list (selected-window) (point) '(0 . 0) 0)))
 
@@ -2364,11 +2377,16 @@
        ;; unless we're in batch mode or dumping Emacs
        (or noninteractive
 	   purify-flag
-	   (file-accessible-directory-p (directory-file-name user-emacs-directory))
-	   (make-directory user-emacs-directory))
+	   (file-accessible-directory-p
+	    (directory-file-name user-emacs-directory))
+	   (let ((umask (default-file-modes)))
+	     (unwind-protect
+		 (progn
+		   (set-default-file-modes ?\700)
+		   (make-directory user-emacs-directory))
+	       (set-default-file-modes umask))))
        (abbreviate-file-name
         (expand-file-name new-name user-emacs-directory))))))
-
 
 ;;;; Misc. useful functions.
 
--- a/src/ChangeLog	Sat Jan 15 12:03:38 2011 -0800
+++ b/src/ChangeLog	Sat Jan 15 12:38:27 2011 -0800
@@ -1,3 +1,11 @@
+2011-01-15  Martin Rudalics  <rudalics@gmx.at>
+
+	* window.c (inhibit_point_swap): New variable.
+	(Fselect_window): If inhibit_point_swap is nonzero, avoid swapping
+	point this time.
+	(Fset_window_configuration): Set inhibit_point_swap to 1 instead
+	of setting selected_window to nil (Bug#7728).
+
 2011-01-11  Tassilo Horn  <tassilo@member.fsf.org>
 
 	* image.c (imagemagick_load_image, Finit_image_library): Free
--- a/src/window.c	Sat Jan 15 12:03:38 2011 -0800
+++ b/src/window.c	Sat Jan 15 12:38:27 2011 -0800
@@ -158,6 +158,11 @@
 
 static int window_initialized;
 
+/* Set in `set-window-configuration' to prevent "swapping out point"
+   in the old selected window.  */
+
+static int inhibit_point_swap;
+
 /* Hook to run when window config changes.  */
 
 static Lisp_Object Qwindow_configuration_change_hook;
@@ -191,6 +196,10 @@
 static int inhibit_frame_unsplittable;
 #endif /* 0 */
 
+extern EMACS_INT scroll_margin;
+
+extern Lisp_Object Qwindow_scroll_functions, Vwindow_scroll_functions;
+
 /* If non-nil, then the `recenter' command with a nil argument
    the entire frame to be redrawn; the special value `tty' causes the
    frame to be redrawn only if it is a tty frame.  */
@@ -3594,7 +3603,9 @@
   /* Store the current buffer's actual point into the
      old selected window.  It belongs to that window,
      and when the window is not selected, must be in the window.  */
-  if (!NILP (selected_window))
+  if (inhibit_point_swap)
+    inhibit_point_swap = 0;
+  else
     {
       ow = XWINDOW (selected_window);
       if (! NILP (ow->buffer))
@@ -5767,7 +5778,7 @@
     /* This test is needed to make sure PT/PT_BYTE make sense in w->buffer
        when passed below to set_marker_both.  */
     error ("move-to-window-line called from unrelated buffer");
-  
+
   window = selected_window;
   start = marker_position (w->start);
   if (start < BEGV || start > ZV)
@@ -6144,10 +6155,6 @@
 	}
 
       FRAME_ROOT_WINDOW (f) = data->root_window;
-      /* Prevent "swapping out point" in the old selected window
-	 using the buffer that has been restored into it.
-	 We already swapped out point that from that window's old buffer.  */
-      selected_window = Qnil;
 
       /* Arrange *not* to restore point in the buffer that was
 	 current when the window configuration was saved.  */
@@ -6156,6 +6163,11 @@
 			       make_number (old_point),
 			       XWINDOW (data->current_window)->buffer);
 
+      /* In the following call to `select-window, prevent "swapping
+	 out point" in the old selected window using the buffer that
+	 has been restored into it.  We already swapped out that point
+	 from that window's old buffer.  */
+      inhibit_point_swap = 1;
       Fselect_window (data->current_window, Qnil);
       XBUFFER (XWINDOW (selected_window)->buffer)->last_selected_window
 	= selected_window;
@@ -6165,13 +6177,6 @@
 	      && FRAME_LIVE_P (XFRAME (data->focus_frame))))
 	Fredirect_frame_focus (frame, data->focus_frame);
 
-#if 0 /* I don't understand why this is needed, and it causes problems
-         when the frame's old selected window has been deleted.  */
-      if (f != selected_frame && FRAME_WINDOW_P (f))
-	do_switch_frame (WINDOW_FRAME (XWINDOW (data->root_window)),
-			 0, 0, Qnil);
-#endif
-
       /* Set the screen height to the value it had before this function.  */
       if (previous_frame_lines != FRAME_LINES (f)
 	  || previous_frame_cols != FRAME_COLS (f))
@@ -7094,6 +7099,8 @@
   window_scroll_preserve_hpos = -1;
   window_scroll_preserve_vpos = -1;
 
+  inhibit_point_swap = 0;
+
   DEFVAR_LISP ("temp-buffer-show-function", &Vtemp_buffer_show_function,
 	       doc: /* Non-nil means call as function to display a help buffer.
 The function is called with one argument, the buffer to be displayed.