I’m using the following snippet to set a 1-character margin to both edges of an Emacs buffer (thanks to zev!):
(add-hook 'window-configuration-change-hook
(lambda ()
(set-window-margins (car (get-buffer-window-list (current-buffer) nil t)) 1 1)))
However, I’d also like to have another configuration that gives me very wide left and right margins (say, 30 chars). How could I assign a hotkey for toggling between these two states, possibly over all buffers?
I tried the following:
(global-set-key [(control f10)]
(add-hook 'window-configuration-change-hook
(lambda ()
(set-window-margins (car (get-buffer-window-list (current-buffer) nil t)) 30 30))))
But got this error:
Wrong type argument: commandp, ((lambda nil (set-window-margins (car (get-buffer-window-list (current-buffer) nil t)) 30 30)) (lambda nil (set-window-margins (car (get-buffer-window-list (current-buffer) nil t)) 1 1)) frame-local-variables-check)
Where am I wrong? Thanks for any explanations. Cheers!
EDIT:
I am well aware of darkroom-mode that provides such wide margins. But it doesn’t seem to work flawlessly on my XP.
This should get you going:
Your example does not work as the global-set-key is expecting the second argument to be a
command, hence the error. Also your key definiton is a little odd.For your comment: