Emacs宏加入行? [英] Emacs macro to join lines?

查看:126
本文介绍了Emacs宏加入行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几千行分隔数据。不幸的是,我的一些数据包裹到一个新的行。如何搜索不包含我的分米的所有行,然后加入上一行,跳到下一行然后继续,直到缓冲区结束?



缓冲区之前



1243 |这是全部

line

1235 |这适合一行。

43223 |由于某些原因,此行包裹了




之后的缓冲区

1243 |这是一条线

1235 |这适合一行。

43223 |这一行由于某种原因而包装。

解决方案

这是一个很好的键盘宏。尝试这样的东西:

  Cx(
Mx isearch-forward-regexp RET
^ [^ | ] * $ RET
M- ^
Cx)

其中
Cx(开始录制键盘宏,由
组成Mx isearch-forward-正则表达式RET使用正则表达式向前搜索
^ [^ |] * $表示不包含|字符的行,然后
M ^ ^将当前行加入前一行,
Cx)结束键盘宏定义。

这个宏可以用Cx e(kmacro-end-and-call-macro ),或者您可以将其另存为函数,并以编程方式调用它,如 http://www.emacswiki .org / emacs / KeyboardMacrosTricks


I have several thousand lines of delimited data. Unfortunately some of my data wrapped to a new line. How can I search for all lines that do not contain my delimeter then join with the prior line, skip to the next line then continue until the end of the buffer?

Buffer before

1243|This is all one
line
1235|This fits on one line.
43223|This line wraps
for some reason.

Buffer after

1243|This is all one line
1235|This fits on one line.
43223|This line wraps for some reason.

解决方案

This is a good job for keyboard macros. Try something like this:

C-x (
M-x isearch-forward-regexp RET
^[^|]*$ RET
M-^
C-x )

where
  C-x (                            begins recording a keyboard macro, which consists of
  M-x isearch-forward-regexp RET   searching forward using a regular expression
  ^[^|]*$                          representing a line containing no | characters, then
  M-^                              joining the current line to the previous line and
  C-x )                            ending the keyboard macro definition.

This macro can be invoked manually multiple times with C-x e (kmacro-end-and-call-macro), or you could save it as a function and call it programmatically as described at http://www.emacswiki.org/emacs/KeyboardMacrosTricks.

这篇关于Emacs宏加入行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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