Subject: bug#15382: desktop restores buffers in wrong order

From: Juri Linkov <[email-masked]>
Date: Wed, 05 Feb 2014 10:07:27 +0200

>> Maybe buffers should be saved in the desktop in reverse order?
>> This will restore the original order of the global buffer list.
>
> You could try it with and without desktop-restore-frames and report back.

I tried to replace

  (dolist (l (mapcar 'desktop-buffer-info (buffer-list)))

with

  (dolist (l (mapcar 'desktop-buffer-info (nreverse (buffer-list))))

but it breaks the desktop saving by inserting the desktop file
to the current buffer.  Then I tried to replace it with

  (dolist (l (nreverse (mapcar 'desktop-buffer-info (buffer-list))))

and it saves the desktop in the natural order that could be replayed back
when restoring the desktop to get the buffer list in the same order.
But more code prevents from restoring in the same order, e.g.

	;; Restore buffer list order with new buffer at end. Don't change
	;; the order for old desktop files (old desktop module behavior).
	(unless (< desktop-file-version 206)
	  (mapc 'bury-buffer buffer-list)
	  (when result (bury-buffer result)))

I'm afraid that changing the order of buffers in the desktop file
might require incrementing the version number in desktop-file-version.