如何在Emacs中撤销自动分段?

16

我有一个非常长的文本文件。有没有简单的方法可以“撤消”一个曾经写过和保存了一段时间的M-q(填充段落)操作?

例如,我想将这个:

They're coming to take me away, ha-haaa!!
They're coming to take me away, ho-ho, hee-hee, ha-haaa

To the funny farm. Where life is beautiful all the time and I'll
be happy to see those nice young men in their clean white
coats and they're coming to take me away, ha-haaa!!!!!

变成这个:

They're coming to take me away, ha-haaa!! They're coming to take me away, ho-ho, hee-hee, ha-haaa

To the funny farm. Where life is beautiful all the time and I'll be happy to see those nice young men in their clean white coats and they're coming to take me away, ha-haaa!!!!!

4个回答

22

我从我的 .emacs 文件中使用以下内容:

(defun unfill-paragraph ()
  (interactive)
  (let ((fill-column (point-max)))
    (fill-paragraph nil)))

(defun unfill-region ()
  (interactive)
  (let ((fill-column (point-max)))
    (fill-region (region-beginning) (region-end) nil)))

我不能取得功劳,这是我多年前在Google上搜索到的。


11

你可以将 fill-column 设置为一个非常大的数字,然后进行填充。

C-u 10000 C-x f M-x fill-individual-paragraphs

或者您可以使用一个简单的自定义函数:

(defun refill-paragraphs-to-be-one-line ()
  "fill individual paragraphs with large fill column"
  (interactive)
  (let ((fill-column 100000))
    (fill-individual-paragraphs (point-min) (point-max))))

谢谢您的回复,但我有一个评论:您的函数似乎不能处理以符号(如破折号“-”或星号“*”)开头的段落,而Doug Harris提供的函数可以。也许自从您8年前发布这篇文章以来发生了一些变化。 - mark999

2

当我在 Emacs 24.4.1 中询问 M-Q(而不是 M-q)的帮助时,我得到了以下回复:

M-Q (translated from <escape> Q) runs the command unfill-paragraph, which is an
interactive Lisp function in `init-util.el'.

It is bound to M-Q.

(unfill-paragraph &optional REGION)

Takes a multi-line paragraph and makes it into a single line of text.

这可能是因为您将此页面的代码添加到了您的Emacs配置中。 - fagerbua
不是。我在modules/init-util.el文件中找到了它。 - mpersico
2
该文件不包含在原始的GNU Emacs中。可能是来自于您的发行版或您安装的软件包。 - fagerbua
我不建议将该键绑定给在 macOS 中使用 Command 作为元键的用户:Cmd-Q 代表退出所有应用程序并注销 :) 在您的回答中是否值得一提? - dcorking
@dcorking - 你的修改请求被有权机构拒绝了。你的评论将需要作为唯一的警告。 - mpersico
感谢您的尝试;(没有权力进行编辑审查,只有其他用户) - dcorking

1
C-x f 100000 M-q

这是一个填充了一段文字的段落。

说明:

  1. C-x f 数字: 将列的字符数设置为较大的数值(100,000)。
  2. M-q: 调用 fill-paragraph 命令。(适用于多个段落的替代方法:M-x fill-individual-paragraphs

之后,请不要忘记将列宽恢复回以前的值(这里是 78)。

C-x f 78

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接