4

所以在 Emacs 中,自动换行称为填充,由M-qor完成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和 enter做同样的事情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会这样以及是否可以修改它。

4

1 回答 1

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列表中。

于 2013-10-30T14:29:28.907 回答