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, 2016 at 0:38
  • 1
    desktop-save-mode saves the window layout only on Emacs version 24.4 and higher, and not in terminal mode. Jul 17, 2018 at 17:23

1 Answer 1


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 ()
    :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.

  • Wow, I've spent hours and hours trying to figure out why desktop-mode didn't work for this in my setup (in terminal mode) over a period of a few years, and after another 10 hours or so of over the last couple days, and now I finally found this answer! Thank you! It doesn't seem to work in Emacs client/server mode, though. Do you know what would be necessary to make that work?
    – Carl
    Dec 28, 2019 at 2:51
  • It works like a charm! And works well with the new native tab-bar-mode! However the check for display-graphic-p appears to be a bad logic in the desktop package, and it avoid the load of frames as well as tabs-bars in terminal mode
    – campisano
    Aug 12, 2021 at 18:36
  • @cyberbisson Thank you so much. This works great.
    – may
    Dec 29, 2021 at 21:30
  • OMG, thank you so much: I couldn't suss this for the life of me!
    – aec
    Oct 28, 2022 at 3:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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