更改emacs文本模式的边距
我发现,在不让事情变得滑稽的情况下,根据自己的喜好改变emacs中的利润率的唯一方法是:更改emacs文本模式的边距,emacs,elisp,hook,margins,Emacs,Elisp,Hook,Margins,我发现,在不让事情变得滑稽的情况下,根据自己的喜好改变emacs中的利润率的唯一方法是: (add-hook 'window-configuration-change-hook (lambda () (set-window-margins (car (get-buffer-window-list (current-buffer) nil t)) 24 24))) 我希望此设置仅在文本模式下调用,并在切换到其他模式时更改回。我有点天真地尝试了这个: (
(add-hook 'window-configuration-change-hook
(lambda ()
(set-window-margins (car (get-buffer-window-list (current-buffer) nil t)) 24 24)))
我希望此设置仅在文本模式下调用,并在切换到其他模式时更改回。我有点天真地尝试了这个:
(add-hook 'text-mode-hook
(lambda ()
(set-window-margins (car (get-buffer-window-list (current-buffer) nil t)) 24 24)))
但它不起作用。在文本模式下,什么样的代码可以只更改缓冲区的边距?这样的代码怎么样?您的问题可能源于许多主要模式继承了
文本模式
。您可以消除窗口配置更改挂钩
,也可以使用新功能主桥
——就我个人而言,我只是将文本模式挂钩
与主桥
功能一起使用
(添加钩子的文本模式钩子(lambda()
(布里格斯少校)
如果需要,插入其他内容
))
(德芬·布里格斯少校()
(当(均衡器主模式“文本模式”)
(设置窗口边距)
(car(获取缓冲区窗口列表(当前缓冲区)nil t)24)
即使您可以使用设置窗口边距设置边距,但只要您以任何方式更改窗口,边距就会丢失。更好的解决方案是设置变量左边距宽度
和右边距宽度
。例如:
(defun my-set-margins ()
"Set margins in current buffer."
(setq left-margin-width 24)
(setq right-margin-width 24))
(add-hook 'text-mode-hook 'my-set-margins)
下面是一些代码,可以将标记和文本文件集中在80个字符以内。这会自动调整所有帧的边距
;; Add left and right margins, when file is markdown or text.
(defun center-window (window) ""
(let* ((current-extension (file-name-extension (or (buffer-file-name) "foo.unknown")))
(max-text-width 80)
(margin (max 0 (/ (- (window-width window) max-text-width) 2))))
(if (and (not (string= current-extension "md"))
(not (string= current-extension "txt")))
;; Do nothing if this isn't an .md or .txt file.
()
(set-window-margins window margin margin))))
;; Adjust margins of all windows.
(defun center-windows () ""
(walk-windows (lambda (window) (center-window window)) nil 1))
;; Listen to window changes.
(add-hook 'window-configuration-change-hook 'center-windows)
使用以下代码:
(defvar-local my-text-width nil
"Text area width for current buffer, or nil if no attention needed.")
(put 'my-text-width 'safe-local-variable #'integerp)
(defun my--margin-setup ()
"Handle settings of `my-text-width'."
(walk-windows
(lambda (window)
(with-current-buffer (window-buffer window)
(let ((margin (and my-text-width
(/ (max 0 (- (window-total-width)
my-text-width))
2))))
(when (or (not (equal margin left-margin-width))
(not (equal margin right-margin-width)))
(setq left-margin-width margin)
(setq right-margin-width margin)
(set-window-buffer window (current-buffer))))))))
(add-hook 'window-configuration-change-hook #'my--margin-setup)
您可以在文件本地或目录本地变量中设置my text width
,Emacs将自动相应地设置边距以获得该文本宽度。即使在调整帧大小或引入拆分时,它也可以工作