所以在Emacs中,word-wraping被称为填充,由M-q或完成M-x fill-paragraph.有没有办法修改此函数以尊重应该不破坏的空格?例如,如果我们有以下句子:
This is a black sentence with a yellow word at the end.
Run Code Online (Sandbox Code Playgroud)
并告诉Emacs在第50号填写段落,它包装如下:
This is a black sentence with a yellow word at the
end.
Run Code Online (Sandbox Code Playgroud)
但是,如果我使用C-u M-x shell-command-on-region和输入相同fold -sw 50,我得到以下(正确)输出:
This is a black sentence with a yellow word at
the end.
Run Code Online (Sandbox Code Playgroud)
当句子的末尾后跟括号中的某些内容时,会发生类似的问题:
This is a black sentence with a yellow word here. (This is something in parens)
Run Code Online (Sandbox Code Playgroud)
上述句子M-q以下列方式用标记50 包裹:
This is a black sentence with a yellow word
here. (This is something in parens)
Run Code Online (Sandbox Code Playgroud)
但是,fold -sw 50正确包装它:
This is a black sentence with a yellow word here.
(This is something in parens)
Run Code Online (Sandbox Code Playgroud)
我知道我可以编写一个使用fold和使用它的函数,但我很好奇为什么fill-paragraph会这样,如果可以修改它.
我不确定你对"非破坏性"空间的定义是什么.
但是,您可以通过执行以下操作来实现示例中所需的内容:
(add-to-list 'fill-nobreak-predicate 'fill-single-word-nobreak-p)
(setq sentence-end-double-space nil)
Run Code Online (Sandbox Code Playgroud)
文件(和评论)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.
Run Code Online (Sandbox Code Playgroud)
您可以将自己的谓词添加到fill-nobreak-predicate列表中.