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?
1 Answer
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)
-
1
-
1These
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 onlywindow-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 detectwindow-width
changes by window splitting or frame resizing. Mar 17 at 14:46