5

I use Emacs 24.5.1 on OS X in terminal mode.

I intend to use desktop-save-mode to save and restore window layout (i.e. positions of buffer windows) upon exiting and starting Emacs.

From this answer and its comments, people suggest that recent versions of Emacs does save and restore window layout when desktop-save-mode is enabled. However, when I exit Emacs with two side-by-side windows each containing a file buffer, only the last active buffer (the one where the cursor last rested at) is restored upon restarting Emacs.

My relevant configurations are:

(setq desktop-auto-save-timeout nil
      desktop-save 'ask-if-new
      desktop-dirname "./"
      desktop-path (list desktop-dirname)
      desktop-load-locked-desktop nil)
(desktop-save-mode 1)

I've checked the value of variable desktop-restore-frames, and Emacs reports "Its value is t", and its description says "When non-nil, save and restore the frame and window configuration".

I also use perspective.el, but I am not sure if it is related to the problem.

I wonder if the problem is caused by some conflict with other package/settings, and if possible, how do I detect and resolve such conflict.

  • If you don't get a reasonable explanation and solution here, consider filing an Emacs bug: M-x report-emacs-bug. – Drew Jan 1 '16 at 0:38
  • 1
    desktop-save-mode saves the window layout only on Emacs version 24.4 and higher, and not in terminal mode. – Dunatotatos Jul 17 '18 at 17:23
2

In order for desktop-read (the function used to restore your desktop from a file) to restore the frameset that was saved in the desktop, it must call desktop-restoring-frameset-p (i.e., "should I restore the saved frameset?"), which in turn checks the function display-graphic-p (i.e., "is this a GUI or a TTY?"). This essentially means that, even though restoring the frameset works on the TTY (providing desktop-restore-forces-onscreen is NIL), it NEVER runs. So we get the full desktop, but none of the frames.

I patched this up in my .emacs file by adding the following (to a function that runs when in a TTY):

(setq desktop-restore-forces-onscreen nil)
(add-hook 'desktop-after-read-hook
 (lambda ()
   (frameset-restore
    desktop-saved-frameset
    :reuse-frames (eq desktop-restore-reuses-frames t)
    :cleanup-frames (not (eq desktop-restore-reuses-frames 'keep))
    :force-display desktop-restore-in-current-display
    :force-onscreen desktop-restore-forces-onscreen)))

This explicitly loads the saved frameset from desktop-saved-frameset, which desktop only defines while desktop-read is happening.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.