1

I have configured Emacs to save my desktop when I close it, so that when I open it next all my buffers are reopened.

However my init.el splits the frame into three windows at startup, so I can view three buffers on the screen at the same time. The first window already shows the buffer I was last editing, but I would like the other two windows to show the second and third last files I was editing too.

I thought this would be possible using something like this:

;; Split into three equally sized windows
(split-window-horizontally)
(split-window-horizontally)
(balance-windows)

;; Load some buffers into the new windows
(other-window 1)
(next-buffer)                ; Shows *Messages* in both windows
;(previous-buffer)           ; same
;(switch-to-buffer 'nil t)   ; Shows same buffer in both windows
(other-window 1)
(next-buffer)
(previous-multiframe-window)
(previous-multiframe-window)

Unfortunately I can't find a command to select the buffer I want in each window. If I manually type C-x b RET in each window then it selects exactly the buffers I want (and they are different in each window), but I can't figure out how to replicate that behaviour as a command in init.el.

What am I doing wrong?

Malvineous
  • 25,144
  • 16
  • 116
  • 151

1 Answers1

2

If the window is selected then you can use

  (set-window-buffer (selected-window) "name of buffer")
Tom
  • 7,515
  • 7
  • 38
  • 54
  • What do I put in "name of buffer" to make it select some buffer I had open previously, given that it will be different on each startup? – Malvineous Jan 15 '12 at 08:01
  • If you want to restore the exact windows and buffer state of emacs then [check out this question and answer](http://stackoverflow.com/questions/392314/saving-window-configurations-in-emacs). This way you don't have to split the windows yourself, select buffers and stuff, because there is a way to restore the previous window configuration. – Tom Jan 15 '12 at 08:44
  • This would work 99% of the time, but occasionally some command messes up the windows - Emacs seems to assume you will never have more than two - and I like the fact that I can always quit and restart to get back to a known good state. But thanks for the suggestion! – Malvineous Jan 16 '12 at 07:37
  • 1
    You don't have to restart for that. Just use [Winner mode](http://www.emacswiki.org/emacs/WinnerMode) which allows you to restore the previous windows configuration with a keypress if some command messes it up. – Tom Jan 16 '12 at 11:26
  • Ah, even better! But I still want my safety blanket :-) – Malvineous Jan 17 '12 at 05:12