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?
Modified 14 days ago
Viewed 30 times
Add a comment |
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)
1that is awesome, thank you so much, what is the "add-hook" for?– DavidMar 17 at 10:32
add-hookare 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-hookis 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-widthchanges by window splitting or frame resizing. Mar 17 at 14:46