To explain the use of register, let's look at the normal cut-copy-pasting of text first. When you have cut or copied some text, it lives in a place we call the clipboard, from with you can then paste it. But in most programs, if you copy/cut text again, it replaces what was already on the clip board.
Now, what about registers? In emacs, we have a special clipboard with multiple places to store things, each named by a single number or letter. We call these places registers. Thus, you can save some text to register A, some other text to register B, and later paste the contents of register A or B. The key bindings (shortcuts) for this are good to remember:
C-x r s R | save region (selection) into register R |
C-x r i R | insert the contents of register R |
(Note: the clipboard that emacs uses for 'normal' cut/copy/paste, the 'kill-ring', allows for multiple (but unnamed) entries as well - but we'll discuss the kill-ring in some other entry.)
viewing register contents
One obvious problem with registers is that for most people it's very hard to remember what went into which register, if you use more than two or three registers. There is M-x view-register, but that's only marginally useful. It would be much nicer if we could get a list of all registers in use and a preview of their contents. To do that, we can use the list-register.el package (see installing packages). The package adds a function list-registers (and some others). I use a key binding C-x r v for that, which somewhat logically follows the other ones:C-x r v | view registers |
(require 'list-register) (global-set-key (kbd "C-x r v") 'list-register)An alternative would be to use C-x r l (for list registers), but that one has already been taken by bookmark-bmenu-list, which shows a list of your bookmarks -- to be discussed some other time).
I would vote for including the list-registers functionality in emacs. Having registers without a way to view them, makes them much less useful.
more than words
Personally, I seldomly use registers for anything but text; however, you can store other things in registers as well (see the Emacs Manual registers section for details):object | store | retrieve | notes |
rectangle | C-x r r R | C-x r i R | save rectangle into register R (see working with rectangular selections, and insert it); |
buffer/position | C-x r <SPC> R | C-x r j R | save buffer/position in register R, and jump back to it |
window | C-x r w R | C-x r j R | save window configuration in register R, and jump back to it. Note that what emacs calls a window is called a window pane elsewhere, see emacs terminology) |
frame | C-x r f R | C-x r j R | save frame configuration in register R, and jump back to it. Note that what emacs calls a frame is called a window elsewhere, see emacs terminology |
While registers are quite useful, I think they would be easier to use if they were integrated with the normal cut-copy-paste (the 'kill-ring'). Another issue is that you cannot access your registers from other programs. Actually, recent MS-Office versions do this in a bit nicer way...
8 comments:
"Another issue is that you cannot access your registers from other programs."
What do you mean "other programs"? :)
hi djcb, I like your site very much, It's very helpful for me.
For some reason this function didn't work for me :
(global-set-key (kbd "C-x r v") 'list-registers)
I copied package list-register.el into ...xemacs-packages\lisp\list-registers
directory and now I'm able to list registers by M-x list-register but when I do "C-x r v" it failed with the error:
Debugger entered--Lisp error: (void-function list-registers)
Where could be the problem?
Thanks
@susja: ah; you should put
'list-register
instead of
'list-registers
thanks, it works !!
hi,
how to insert content of say 'R' register into the clipboard ?
so that the 'other' programs can also make use of the register content outside emacs ( ex: a document writer etc.,)
Hi, found a broken link:
http://emacs-fu.blogspot.com/2000/12/installing-packages.html
And I would like to read that post ;-)
@vvoody: fixed, thanks.
Same sentiment about wanting to view register contents, +1! The provided function doesn't handle newlines in register contents very nicely, but is still useful (as is your blog in general), thanks!
Post a Comment