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

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

问题描述

我已看到至少两个在编辑LaTeX文档时,在StackOverflow上建议在句子之间插入换行符。原因是这种做法有助于源代码管理, diff ing和协作编辑。



我基本上相信,但我很懒,我不想考虑。



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



我想我不想要的是 / p>


  • 文本的软包装(比如使用 longlines (设置long-line-auto-wrap't))。这是因为我不想对协作者的编辑施加要求,而且我有时候使用其他unix工具来检查这些文件。



我想我想要的是




  • 对于 fill-paragraph 填写看起来像标记句子结尾的换行符。

  • 适用于自动填充模式的解决方案将是一个奖励。



这是:


聊天聊天。

一个新的句子

与goofed up包装需要修复。

Mumble mumble


转换为:


聊天聊天。

需要修复的包含goofed up的新句子。
Mumble mumble


您的意见和建议不胜感激。






编辑: Jouni K.Seppänen指出我在 LaTeX-fill-break-in-separatorators ,这表明emacs几乎知道如何做到这一点。无论如何,我要阅读一些代码,并会回报。再次感谢






相同问题的一般版本:编辑者摊牌:在句子末尾维护换行符。谢谢, dreeves

解决方案

以下是我使用的,这主要是被禁止来自 Luca de Alfaro

 (defun fill-sentence()
(interactive)
(save-excursion
(或(eq(point)(point-max))
(前缀-1)
(indent-relative t)
(let((beg(point))
(ix(string-match) LaTeX模式名称)))
(转发句子)
(if(和ix(等于LaTeX(子串模式名ix)))
(LaTeX填充区域-a段落beg(point))
(fill-region-as-paragraph beg(point))))))

我将此绑定到 Mj

 (全球SET- key(kbdMj)'fill-sentence)

引用 LaTeX适用于 AUCTeX 支持。如果您不使用AUCTeX, let 可以简化为

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


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.

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.

I think what I don't want is

  • 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.

I think what I do want is

  • 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.

That is:

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

Transformed to:

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

Your comments and suggestions are appreciated.


Edit: 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.


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

解决方案

Here's what I use, which was mostly cribbed from 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))))))

I bind this to M-j with

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

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天全站免登陆