72

I have setup my windows in a certain way. How do I save this setting to be invoked later?

hekevintran
  • 22,822
  • 32
  • 111
  • 180

5 Answers5

74

I sometimes still use C-x r w <register> to store a window configuration in a register, and C-x r j <register> (where <register> is a single character) to jump back to it.

While this is a nice way for storing a few window configurations which you want to go back to after some time, I find winner-mode to be more convenient in a few regards. (For example, you won't have to bother naming the configurations).

Just put (winner-mode 1) in your .emacs, bind winner-undo and winner-redo to convenient shortcuts (or use the IMHO awkward C-c <left> and C-c <right> predefined ones), and you'll be able to switch back to previous window configurations.

See also: M-: (info "(emacs) Window Convenience") and M-: (info "(emacs) RegConfig")

danlei
  • 14,121
  • 5
  • 58
  • 82
  • how about naming window layouts in winner mode so you don't have to cycle through many levels of undo/redo to get back to what you want? – johnbakers May 23 '14 at 02:28
  • @OpenLearner Hm, if you want to name layouts, what would be the benefit of using winner mode over plain registers? – danlei May 23 '14 at 23:35
31

I know you allready accepted an answer, however because I understand your question in another way (concerning layout) and this question showed up for me when I was in search for something to persist my emacs window layout, I would like to mention:

workgroups.el

which purpose is to save and restore the way, emacs windows are layed out and many more.

einSelbst
  • 2,099
  • 22
  • 24
  • This was what I was looking for when google drove me to this answer. Thanks a lot! – Paul Dec 19 '11 at 09:37
  • workgroups.el is awesome, but it doesn't play nice (at all) with ECB :(... So I'm still using Escreen. – jimeh Apr 10 '12 at 15:20
27

Check out emacs desktop. I have no emacs available but I believe it's part of the standard lisp packages you get when you install emacs.

Use the desktop library to save the state of Emacs from one session to another. Once you save the Emacs desktop—the buffers, their file names, major modes, buffer positions, and so on—then subsequent Emacs sessions reload the saved desktop.

Nifle
  • 11,745
  • 10
  • 75
  • 100
  • 2
    I use desktop-save-mode to store the buffers and use workgroups to store the arrangement of my frames and windows. https://github.com/tlh/workgroups.el. – hekevintran Aug 25 '12 at 05:37
  • 4
    This answer may be misleading for some, I believe the author is confusing "frames" with "windows". The linked *desktop* package only supports restoring of frames (which outside of the emacs universe are called windows), but actual emacs windows are not persisted. Also downvoted because author doesn't appear to have actually tried it out. – robert Oct 11 '17 at 10:24
  • 1
    Downvoted, the author should have used it before recommending a library as a solution. – Indicator Jan 03 '19 at 02:04
  • I can confirm that it doesn't work as quite described in the quote above! It restores all of the buffers, but not the window layout. The problem seems to be, at least in part, that the windows are themselves populated with "computed" contents" (like Org Agenda with various settings)! — So, in order to actually restore what I had before, it would have to either recompute everything, or write the buffer contents to disk. Since it doesn't seem to do either of those things, it's of limited use as a true "checkpointing" mechanism. – Joe Corneli May 07 '21 at 13:20
2

Give Layout Restore a try if you just want to restore the window layout later.

Michael Mrozek
  • 169,610
  • 28
  • 168
  • 175
tangxinfa
  • 1,410
  • 13
  • 12
1

If you want to persist a layout in your hard-drive, desktop-save is the option.

If you need to store multiple layouts during emacs' process lifetime (e.g. you connect to a long-running emacs daemon using emacsclient), you can use C-x r f <register> to store the frame layout in some register and C-x r j <register> for restore.

Since I now and then remotely connect to the work station to do sth, disconnect for a while and later reconnect, restoring layout helps me continue stuff seamlessly (note in this case window layouts stored by C-x r w would be gone).

ShellayLee
  • 327
  • 2
  • 6