1

If I change margin and evaluate the code, it will only change only in the new window, but I also want write it the have for the new buffer or even write it as a function. How do I activate it also for my current buffer, after I change the variable?

David
  • 291
  • 1
  • 9

1 Answers1

1

Maybe code like this might help?

(setq my-margin-left 10) ;; eval to change the left margin immediately.
(setq my-margin-right 5) ;; eval to change the right margin immediately.

(defun my-update-margins ()
  (set-window-margins (get-buffer-window) my-margin-left my-margin-right))

(add-hook 'window-configuration-change-hook 'my-update-margins)
(add-hook 'window-state-change-hook 'my-update-margins)
roomworoof
  • 394
  • 2
  • 9
  • 1
    that is awesome, thank you so much, what is the "add-hook" for? – David Mar 17 '23 at 10:32
  • 1
    These `add-hook` are only used as a trigger for the margin update function. In this case the margin is a fixed value, so it seems that only `window-state-change-hook` is enough, or maybe there is a more suitable hook. In my case I am changing the margin by percentage, so I needed these two hooks to detect `window-width` changes by window splitting or frame resizing. – roomworoof Mar 17 '23 at 14:46