Emacs:如何设置边距以在分屏时自动调整?

时间:2016-08-22 15:12:50

标签: emacs margins

我是一位试图配置Emacs以有效撰写学术论文的历史学家。考虑到这一点,我决定将边距添加到Emacs缓冲区。最终结果看起来像this,并且使用以下代码实现:

;; Margins function

(defun my-set-margins ()
  "Set margins in current buffer."
  (setq left-margin-width 26)
  (setq right-margin-width 26))

;; Add margins by default to a mode

(add-hook 'org-mode-hook 'my-set-margins)

问题在于,当我垂直拆分屏幕时,边距会使文字无法读取。因此,我得出的结论是,有必要(1)让Emacs在垂直分割屏幕中自动删除边距,并在单屏幕中将它们放回去;或(2)创建键盘快捷键以切换边距。任何关于如何做的elips想法?提前谢谢!

1 个答案:

答案 0 :(得分:0)

文档指出,设置left-margin-widthright-margin-width不会立即影响窗口。在窗口中显示新缓冲区时,将检查这些变量。因此,您可以通过调用set-window-buffer使更改生效。 https://www.gnu.org/software/emacs/manual/html_node/elisp/Display-Margins.html

以下功能检查边距是否大于0,并根据此切换打开或关闭。我使用global-map键将交互式功能绑定到f5

  
(defun my-toggle-margins ()
"Set margins in current buffer."
(interactive)
  (if (or (> left-margin-width 0) (> right-margin-width 0))
    (progn
      (setq left-margin-width 0)
      (setq right-margin-width 0)
      (set-window-buffer (selected-window) (current-buffer)))
    (setq left-margin-width 26)
    (setq right-margin-width 26)
    (set-window-buffer (selected-window) (current-buffer))))

(global-set-key [f5] 'my-toggle-margins)