Emacs 错误地使用填充段落包装文本

标签 emacs word-wrap

所以在 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/

相关文章:

Emacs Org-Mode TODO 列表缺失项

emacs - 如何在emacs中设置缓冲区局部变量

Emacs - 对 shell-command-on-region 的非交互式调用总是删除区域?

python - 有没有一种很好的方法来拆分(可能)长的字符串而不用 Python 中的单词拆分?

html - 为什么我的下拉导航菜单换行并放到第二行?

git - Emacs 使用 Git-Rebase 将缓冲区恢复到奇怪的先前状态

linux - 如何在 Wanderlust 中查看备用 mime 内容

css - 在 3 列中定位 CSS

css - 文字不会环绕图像