所以在 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
行为像这样,如果可以修改。
最佳答案
我不确定您对“不间断”空间的定义是什么。
但是,您可以通过执行以下操作来实现您想要的示例:
(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
列表。
关于Emacs 错误地使用填充段落包装文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19680479/