因此,在Emacs中,自动换行称为填充,由M-q
或M-x fill-paragraph
完成。有没有办法修改此函数以尊重应该不破坏的空格?例如,如果我们有以下句子:
This is a black sentence with a yellow word at the end.
并告诉Emacs在第50号填写段落,它包装如下:
This is a black sentence with a yellow word at the
end.
但是,如果我对C-u M-x shell-command-on-region
执行相同操作并输入fold -sw 50
,我会得到以下(正确)输出:
This is a black sentence with a yellow word at
the end.
当句子的末尾后跟括号中的某些内容时会发生类似的问题:
This is a black sentence with a yellow word here. (This is something in parens)
上述句子用M-q
包裹在标记50处,方式如下:
This is a black sentence with a yellow word
here. (This is something in parens)
但是,fold -sw 50
正确包装它:
This is a black sentence with a yellow word here.
(This is something in parens)
我知道我可以编写一个使用fold
的函数并使用它,但我很好奇为什么fill-paragraph
的行为如此以及是否可以修改。
答案 0 :(得分:5)
我不确定你对“非破坏性”空间的定义是什么。
但是,您可以通过以下方式在示例中实现所需:
(add-to-list 'fill-nobreak-predicate 'fill-single-word-nobreak-p)
(setq sentence-end-double-space nil)
fill-single-word-nobreak-p
的文档(和评论)说:
"Don't break a line after the first or before the last word of a sentence."
;; Actually, allow breaking before the last word of a sentence, so long as
;; it's not the last word of the paragraph.
您可以将自己的谓词添加到fill-nobreak-predicate
列表中。