如何让 Emacs 填充句子而不是段落? [英] How do I get Emacs to fill sentences, but not paragraphs?

查看:22
本文介绍了如何让 Emacs 填充句子而不是段落?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看过至少两个建议在 StackOverflow 上编辑 LaTeX 文档时在句子之间插入换行符.原因是这种做法有利于源代码控制、diffing 和协作编辑.

I've seen at least two recommendations on StackOverflow to insert newlines between sentences when editing LaTeX documents. The reason being that the practice facilitates source control, diffing, and collaborative editing.

我基本相信,但我很懒,不想去想.

I'm basically convinced, but I'm lazy, and I don't want to have to think about it.

所以我正在寻找一些 emacs 咒语来为我处理它.可能是次要模式,可能是一组需要设置的变量.

So I'm searching for some emacs incantation to handle it for me. Could be a minor mode, could be a set of variables that need to be set.

我认为我想要的是

  • 文本的软包装(比如使用 longlines(设置 long-lines-auto-wrap 't)).这是因为我不想对我的合作者的编辑强加要求,而且有时会使用其他 unix 工具来检查这些文件.
  • Soft wrapping of text (say using the longlines and (set long-lines-auto-wrap 't)). This is because I don't want to impose requirements on my collaborators' editors, and I sometimes use other unix tools to examine these files.

我认为我想要的是

  • 对于 fill-paragraph 用于在看起来像标记句子结尾的换行符之间进行填充.
  • 适用于 auto-fill-mode 的解决方案将是一个奖励.
  • For fill-paragraph to fill between newlines that look like they mark the end of a sentence.
  • A solution that works with auto-fill-mode would be a bonus.

即:

聊天聊天聊天.
一个新的句子
带有需要修复的错误包装.
嘟嘟嘟嘟

chat chat chat.
A new sentence
with goofed up wrapping that needs to be fixed.
Mumble mumble

转换为:

聊天聊天聊天.
一个新的句子,带有需要修复的错误包装.
嘟嘟嘟嘟

chat chat chat.
A new sentence with goofed up wrapping that needs to be fixed.
Mumble mumble

感谢您的意见和建议.

Jouni K. Seppänen 向我指出 LaTeX-fill-break-at-separators,这表明 emacs 几乎已经知道如何做到这一点.无论如何,我要去读一些代码,然后回来报告.再次感谢.

The suggestion by Jouni K. Seppänen pointed me at LaTeX-fill-break-at-separators, which suggests that emacs almost knows how to do this already. Anyway, I'm off to read some code, and will report back. Thanks again.

同一问题的更一般版本:编辑对决:在句子的末尾保持换行.谢谢,dreeves.

More general version of the same question: Editor showdown: Maintain newlines at the ends of sentences. Thanks, dreeves.

推荐答案

这里是 我使用的内容,主要来自Luca de Alfaro:

(defun fill-sentence ()
  (interactive)
  (save-excursion
    (or (eq (point) (point-max)) (forward-char))
    (forward-sentence -1)
    (indent-relative t)
    (let ((beg (point))
          (ix (string-match "LaTeX" mode-name)))
      (forward-sentence)
      (if (and ix (equal "LaTeX" (substring mode-name ix)))
          (LaTeX-fill-region-as-paragraph beg (point))
        (fill-region-as-paragraph beg (point))))))

我用

(global-set-key (kbd "M-j") 'fill-sentence)

"LaTeX" 的引用是为了 AUCTeX 支持.如果不使用AUCTeX,let可以简化为

The references to "LaTeX" are for AUCTeX support. If you don't use AUCTeX, the let can be simplified to

(let (beg (point))
  (forward-sentence)
  (fill-region-as-paragraph beg (point)))

这篇关于如何让 Emacs 填充句子而不是段落?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆