Emacs中的边距宽度切换?

时间:2011-11-09 12:26:41

标签: emacs elisp margins

我正在使用以下代码段为Emacs缓冲区(thanks to zev!)的两个边设置1个字符的边距:

(add-hook 'window-configuration-change-hook
      (lambda ()
        (set-window-margins (car (get-buffer-window-list (current-buffer) nil t)) 1 1)))

但是,我还想要另一种配置,它给我非常宽的左右边距(比如30个字符)。我怎样才能指定一个热键来切换这两种状态,可能覆盖所有缓冲区

我尝试了以下内容:

(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))))

但得到了这个错误:

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)

我哪里错了?谢谢你的任何解释。干杯!

修改

我很清楚darkroom-mode提供了如此广泛的利润。但它似乎在我的XP上完美无缺。

1 个答案:

答案 0 :(得分:2)

这应该让你前进:

(global-set-key [C-f10]
     (lambda ()
     (interactive)
     (set-window-margins (car (get-buffer-window-list (current-buffer) nil t)) 30 30)))

您的示例不起作用,因为global-set-key期望第二个参数为command,因此出错。你的关键定义也有点奇怪。

征求意见:

(walk-windows (lambda (window) (set-window-margins window 30 30)) nil t)