emacs 字符串插入矩形数字向量? [英] emacs string-insert-rectangle vector of numbers?

查看:21
本文介绍了emacs 字符串插入矩形数字向量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 emacs 字符串插入矩形操作将数字向量添加到一系列行中?例如,我的 emacs 缓冲区中有一堆文本条目的缩短版本:

How can I use emacs string-insert-rectangle operation to add a vector of numbers to a series of lines? For example, I've got this shortened version of a bunch of text entries in my emacs buffer:

element01   8   111111111011010000100000001100101000001111101111011111111000
element01   8   111101101010101001111111111000111110111111011110100101010111
element01   8   111111011001001110111010111111100111010110101011111010110011
element01   8   111111111111111111111111010111101101011101011111000001100000
element01   8   111100111111011111100110110000001011110101000011111011111101
element01   8   111001001011000000011100000101001001100101101011101101011011
element01   8   111011111101101111111111111101101010111110111011111101011011
element01   8   101101111101101111000110111101111010111011101111001101001011
element02   6   110101110101100101100101000111010101110111001001101111111011
element02   6   111001011001001011101110111100111101101011111111111011111101
element02   6   101111100111010111111010010101111101111111101101111011111011
element02   6   111101111111111100111110110111101011111001001101101100111111
element02   6   111111010111101111010011110111001100001000101010111111111101
element02   6   111110111001101111111100111011110000011011100100100111111010
element03   13  110011011111111111101011100111111110011111110100111010011111
element03   13  100011101000111110101101000000000001110110110011110110111101
element03   13  101100011100011111110111110110101101111111110110110100101111
element03   13  111111011110101110101011010111110000010111111011100100011111
element03   13  011100110110110111100101110101111110111100101110010111110011
element03   13  100111111111100100111110110110111111111101011101110110110111
element03   13  101111111111110101110110111011111110111101110110111111111111
element03   13  111110010111110110101111110110111111111110101111111101110011
element03   13  100111111101110110110110111110111010111110110011111111110111
element03   13  110100110111110110110100111010110100110110110110110101111111
element03   13  011111011010111101101001011100111110010111111011111101011010
element03   13  011101111110010000111000000101101010111110100010110110110110
element03   13  110100110110110010101010100011100011000000110011011100110100
element03   13  010101101010110010111100101001001010111001100111110000011011
[...]

我想在第二列和第三列之间添加一列,如下所示:

And I want to add a column between the second and third column that will look like this:

element01   8   id1 111111111011010000100000001100101000001111101111011111111000
element01   8   id2 111101101010101001111111111000111110111111011110100101010111
element01   8   id3 111111011001001110111010111111100111010110101011111010110011
element01   8   id4 111111111111111111111111010111101101011101011111000001100000
element01   8   id5 111100111111011111100110110000001011110101000011111011111101
element01   8   id6 111001001011000000011100000101001001100101101011101101011011
element01   8   id7 111011111101101111111111111101101010111110111011111101011011
element01   8   id8 101101111101101111000110111101111010111011101111001101001011
element02   6   id9 110101110101100101100101000111010101110111001001101111111011
element02   6   id10    111001011001001011101110111100111101101011111111111011111101
element02   6   id11    101111100111010111111010010101111101111111101101111011111011
element02   6   id12    111101111111111100111110110111101011111001001101101100111111
element02   6   id13    111111010111101111010011110111001100001000101010111111111101
element02   6   id14    111110111001101111111100111011110000011011100100100111111010
element03   13  id15    110011011111111111101011100111111110011111110100111010011111
element03   13  id16    100011101000111110101101000000000001110110110011110110111101
element03   13  id17    101100011100011111110111110110101101111111110110110100101111
element03   13  id18    111111011110101110101011010111110000010111111011100100011111
element03   13  id19    011100110110110111100101110101111110111100101110010111110011
element03   13  id20    100111111111100100111110110110111111111101011101110110110111
element03   13  id21    101111111111110101110110111011111110111101110110111111111111
element03   13  id22    111110010111110110101111110110111111111110101111111101110011
element03   13  id23    100111111101110110110110111110111010111110110011111111110111
element03   13  id24    110100110111110110110100111010110100110110110110110101111111
element03   13  id25    011111011010111101101001011100111110010111111011111101011010
element03   13  id26    011101111110010000111000000101101010111110100010110110110110
element03   13  id27    110100110110110010101010100011100011000000110011011100110100
element03   13  id28    010101101010110010111100101001001010111001100111110000011011
[...]

如何在 emacs 中使用类似 string-insert-rectangle 之类的东西来添加这个新的第三列,并增加数量?

How can I use something like string-insert-rectangle in emacs to add this new third column with increasing number count?

PS:我知道我可以用 bash/perl/python/etc 脚本来做到这一点,在这个问题中,我问这是否可以用 emacs 轻松完成.

PS: I know I could do this with a bash/perl/python/etc script, in this question I am asking if this can be easily done with emacs.

推荐答案

我觉得最简单的解决办法是在第一行标记原第三列的第一个字符,将点移到最后一行的同一个字符上,然后然后输入:

I think the simplest solution is to mark the first character of the original third column in the first line, move point to the same character of the last line, and then type:

CuCxrNRET id%d RET

rectangle-number-lines 是一个交互式编译的 Lisp 函数`rect.el'.

rectangle-number-lines is an interactive compiled Lisp function in `rect.el'.

它绑定到 C-x r N.

It is bound to C-x r N.

(rectangle-number-lines START END START-AT &optional FORMAT)

(rectangle-number-lines START END START-AT &optional FORMAT)

在区域矩形前插入数字.

Insert numbers in front of the region-rectangle.

START-AT,如果非零,应该是一个开始的数字数数.FORMAT,如果非零,应该是要传递的格式字符串与行数一起格式化".交互调用时带前缀参数,提示 START-AT 和 FORMAT.

START-AT, if non-nil, should be a number from which to begin counting. FORMAT, if non-nil, should be a format string to pass to `format' along with the line count. When called interactively with a prefix argument, prompt for START-AT and FORMAT.

regexp-replace 和宏技术都是需要了解的极好的通用工具,但矩形数字线几乎是为这个问题定制的.

The regexp-replace and macro techniques are both superb general-purpose tools to know, but rectangle-number-lines is pretty much custom-built for this very question.

编辑:当时我没有注意到,但事实证明这是 Emacs 24 中的一个新功能.早期版本的 Emacs 会将这个序列转换为 Cx rn(小写 n)运行一个完全不同的函数.

Edit: I hadn't noticed at the time, but it turns out that this is a new feature in Emacs 24. Earlier versions of Emacs will translate that sequence to C-x r n (lower-case n) which runs an entirely different function.

这篇关于emacs 字符串插入矩形数字向量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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