如何在 Emacs 中设置截断线的宽度

how to set width of truncate lines in Emacs

我知道 emacs 中的自动填充功能,这很棒,当我希望文本在特定宽度处有换行符时(例如编码时),我会使用它。但是,在编辑和阅读文本时,我不想重新格式化文本 (M-q) 并插入换行符,因为这在导出文本时看起来很奇怪,例如发送到电子邮件或 Microsoft Word。

emacs 'truncate lines' 是完成这项工作的工具吗?似乎是,但我不知道如何设置截断线的宽度,它似乎只能在屏幕宽度处截断 - 是否有针对此模式或其他模式的设置?

(我使用的是 spacemacs,但这应该没有太大关系)

我一般用

M 72 M-x set-fill-column

在 72 列处换行。不过,这仍然会妨碍您的 "don't muck up import to Word" 问题。如果您以特定格式保存文件(例如,使用 M-x xml-mode),那么我相信这会帮助您解决导入问题。

在 emacs 交换 here 中,有一个代码解决了截断小于 wincow 宽度的缓冲区的问题。 看看@JeanPierre 的回答。它使用 set-window-margins 请参阅 emacs 手册 here

它是一个交互函数,所以使用M-x my/change-window-width从头开始评估后调用它。

(defun my/change-window-width (width)
"Adjust margins so that window is centered"
  (interactive "NWindow width: ")
  (if (= 0 width)
      (set-window-margins nil 0 0)
    (let* ((cur-width (window-width))
           (cur-m (window-margins))
           (cur-l (if (and cur-m (car cur-m)) (car cur-m) 0))
           (cur-r (if (and cur-m (cdr cur-m)) (cdr cur-m) 0))
           (lr (- (+ cur-l cur-r cur-width) width))
           (left (/ lr 2))
           (right (if (= 0 (% lr 2)) left (1+ left))))
      (set-window-margins nil (max left 0) (max right 0)))))

它是 visual-line-mode 中函数的变体,请参阅文档 here

只截断缓冲区的一部分,看起来像fill-column