Subject: bug#17351: Trunk emacs splats .emacs.desktop at startup

From: Juri Linkov <[email-masked]>
Date: Tue, 24 Jun 2014 01:57:52 +0300

>> This would keep the desktop file open all the time,
>> and users might not like to see it in the buffer list.
>
> So read it into an invisible buffer, set buffer-file-name, and enable
> auto-save-mode.

auto-save-mode doesn't seem necessary because the contents of the
desktop file buffer has to be generated at the given time interval
anyway, so at the end it can be saved as well like in this patch:

=== modified file 'lisp/desktop.el'
--- lisp/desktop.el	2014-06-06 23:38:40 +0000
+++ lisp/desktop.el	2014-06-23 22:45:20 +0000
@@ -1038,8 +1038,15 @@ (defun desktop-save (dirname &optional r
 			     (point))))
 		 (checksum (and beg (md5 (current-buffer) beg (point-max) 'emacs-mule))))
 	    (unless (and checksum (equal checksum desktop-file-checksum))
-	      (let ((coding-system-for-write 'emacs-mule))
-		(write-region (point-min) (point-max) (desktop-full-file-name) nil 'nomessage))
+	      (let ((coding-system-for-write 'emacs-mule)
+		    (buffer-string (buffer-string)))
+		(with-current-buffer (find-file-noselect (desktop-full-file-name))
+		  ;; Make the buffer invisible
+		  (unless (eq (aref (buffer-name) 0) ?\s)
+		    (rename-buffer (concat " " (buffer-name))))
+		  (erase-buffer)
+		  (insert buffer-string)
+		  (save-buffer)))
 	      (setq desktop-file-checksum checksum)
 	      ;; We remember when it was modified (which is presumably just now).
 	      (setq desktop-file-modtime (nth 5 (file-attributes (desktop-full-file-name)))))))))))