0

I have Emacs set up to open an initial org mode buffer on startup by

(setq initial-buffer-choice "~/Directory/Subdirectory/inital_buffer1.org")

Ideally on start up, I would like to open 2 buffers in different windows separated vertically, however. Is there a way to do this? And is there some way of customizing the width of each of these initial buffers?

2
  • Opening Two Buffers on Startup

You could add a function to emacs-startup-hook which switches to the first buffer you want, splits the window, moves to the next window, and switches the second buffer (this is exactly what the function below does). You didn't specify whether the buffers you wanted to display were file buffers or already existing buffers. Here they are created if they don't exist. If you want file buffers use find-file instead of get-buffer-create.

(defun my-setup-initial-window-setup ()
  "Do what I want for initial window setup.
In my case I want to start with 2 windows split side by side."
  (interactive)
  (switch-to-buffer (get-buffer-create "one"))
  (split-window-horizontally)
  (other-window 1)
  (switch-to-buffer (get-buffer-create "two")))

(add-hook 'emacs-startup-hook #'my-setup-initial-window-setup)

This is the easiest way. You'd just ignore initial-buffer-choice. If you want to be very efficient you could make initial buffer choice a function returning to the first buffer you want to see on startup and then use a slightly modified version of the function above.

  • Window Width

Your question on buffer width is a separate question. There are already detailed answers online on how to change window width.

  • Excellent! Thanks so much for the tip! – kozina_adjacent Aug 30 at 13:34
  • Hey - quick follow up question you might be able to help with. So I'm using set-frame-size to get my frame the size I want it. I see that by default it sizes by characters/lines. Try as I might I've put (setq frame-resize-pixelwise t) before it but it continues to set the frame size by characters and lines and not by pixel size. Have you run into this problem? – kozina_adjacent Aug 30 at 14:58
  • I never resize my frame other than making it fullscreen, because I only ever use windows so I'm not very familiar with this issue. However, a quick google search pointed me to this link: emacs.stackexchange.com/questions/16961/…. It looks promising. – Aquaactress Aug 30 at 15:05
  • Mmmmmm, I saw this thread and worked through it but, try as I might, despite adding setq frame-resize-pixelwise to non-nil it continues to adjust my frame by character/lines..... to further complicate the matters, I can only get this to work in GNU Emacs and not on Aquamacs and I'm not sure why. At any rate, thank you very much for the help :) – kozina_adjacent Aug 30 at 15:09

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.