开发者

Save the shape of a rectangular selection in an Emacs register

I need to repeatedly copy text from a fixed size rectangular region and I'd like to be able to save the shape of that rectangular region in a register so开发者_如何学Go I don't have to keep re-creating the same size.

  1. cua-set-rectangle-mark (<C-return>)

  2. Move point to create a region 8x16 (note: this is the step I want to remove)

  3. piture-clear-rectangle (C-c C-k)

  4. Move point to new location.

  5. picture-yank-rectangle (C-c C-y)

I'd like to replace steps 1 and 2 with a single 'paste rectangular region from register' command. Is this possible?


Wouldn't it be easier to simply use a keyboard macro for this?

E.g.:-

C-x C-(   [start recording kbd macro]
steps 1-2
C-x C-)   [end recording kbd macro]

Then

C-x e     [execute kbd macro]


You probably want to use copy-rectangle-to-register and insert-register:

C-x r r runs the command copy-rectangle-to-register, which is an interactive compiled Lisp function in `register.el'.

It is bound to C-x r r.

(copy-rectangle-to-register REGISTER START END &optional DELETE-FLAG)

Copy rectangular region into register REGISTER. With prefix arg, delete as well. To insert this register in the buffer, use C-x r g.

Called from a program, takes four args: REGISTER, START, END and DELETE-FLAG. START and END are buffer positions giving two corners of rectangle.

insert-register:

C-x r g runs the command insert-register, which is an interactive compiled Lisp function in `register.el'.

It is bound to C-x r g, C-x r i.

(insert-register REGISTER &optional ARG)

Insert contents of register REGISTER. (REGISTER is a character.) Normally puts point before and mark after the inserted text. If optional second arg is non-nil, puts mark before and point after. Interactively, second arg is non-nil if prefix arg is supplied.

See also:

C-xrc: clear-rectangle
C-xrd: delete-rectangle
C-xrk: kill-rectangle
C-xro: open-rectangle
C-xrr: copy-rectangle-to-register
C-xrt: string-rectangle
C-xry: yank-rectangle

EDIT:

Right, I completely misunderstood the question.

If you still particularly want to use registers, you could save and re-execute point movements with something like this:

(set-register ?a [right right right down down])
(command-execute (get-register ?a))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜