Setting default Emacs window margins

5,455

Do this in your init file (~/.emacs) -- use whatever values you want in place of 10 and 8:

 (setq-default left-margin-width 10 right-margin-width 8) ; Define new widths.
 (set-window-buffer nil (current-buffer)) ; Use them now.
Share:
5,455

Related videos on Youtube

Rajesh Kanna
Author by

Rajesh Kanna

Updated on September 18, 2022

Comments

  • Rajesh Kanna
    Rajesh Kanna over 1 year

    I'm trying to emulate some behavior of the darkroom-mode Emacs mode -- specifically the margins setup.

    I've figured out one piece of the puzzle -- specifically, to change window margins, I can eval (set-window-margins nil <left margin> <right margin>).

    Which is fine, but I'm noticing that the changes only occur in the current window, and will actually go back to the default margin if I switch to a different buffer using C-x left or right arrow key.

    I'd like to figure out how to do the following:

    • Set it so that all buffers get the same window-margin settings.
    • Set it so that the margin settings persist after changing windows.

    I know that it might involve using hooks, but I'm not exactly sure which hooks to use.

    • Alvin De Castro
      Alvin De Castro almost 13 years
      To whom might be tempted to close-vote: Emacs falls into the "software tools commonly used by programmers" so according to the FAQ it's on topic.
    • Rajesh Kanna
      Rajesh Kanna almost 13 years
      @cosmin-prund Also, the solution would probably involve programming, specifically coding in Elisp. Had it not I'd have gone to Super User.
  • nisetama
    nisetama over 2 years
    How would I modify this to make the maximum width of a window 120 characters, so that if I have two windows open side by side, the margin is not added to them if the width of the frame is 240 characters or less?