what is called ring in emacs?
Asked Answered
C

5

6

Unlike windows style self explanatory copy/cut/paste commands, I could not understand ring concept in emacs.

Since I don't program very often in emacs, I could have not realized the value of ring feature. Can you tell me what is called ring in emacs and how to use it?

Cryosurgery answered 15/10, 2010 at 15:23 Comment(5)
I don't think this question is off-topic here. It is a computer technology question on how clipboard is implemented in Emacs.Relive
Whenever somebody says some piece of computer technology is "self explanatory", I think that really just means they've learned it so long ago they forgot about the time when they didn't understand it. :-)Tritheism
the emacs ring is not a simple clipboard, and certainly not self explanatory. as usual, when emacs does something, it does it in a super featureful, complex to understand way that is super powerful to the few users for whom investing the time to learn it is worth it.Infracostal
Further ring functions, FYI: <emacswiki.org/emacs/ring%2b.el>Peeved
My mom doesn't find cut/copy/paste self-explanatory.Unquiet
M
12

Well, let me try in simple words. Each time you copy (M-w) or cut (C-w), the selection is inserted into a top of so called ring (which is just like a closed ended list).

The interesting part comes after. Now, if you paste with C-y then the most recently pasted region (which is now the front element of the ring) is inserted in the buffer. If you continue pressing M-y, then the text is replaced successively with older and older elements from the ring, so to say, the ring is rotated and the older text is designated as front element each time. This gives you an access to older cut/copied text.

The useful part does not end here. If you cut/copy some other text, it will be inserted at the top of the ring, and the ring will be rotated again such that the top is now the front. And you can start the C-y M-y sequence again, with the newly inserted text designated as front.

So, to conclude:

  • the top of the ring is the place where the newly copied/cut (M-w/C-w) text is inserted. When that happens, the top element becomes the front element.
  • the front element of the ring is the place on which paste (aka yank) commands C-y and M-y operate, by inserting it into the buffer. M-y also rotates the ring, such that older text in the ring becomes the front.

You can visualize it by imagining the circle with the front fixed at 12 hours position, but not part of the ring. The top is part of the ring instead, so when some command rotates the ring the top is also rotated.

alt text

Mob answered 15/10, 2010 at 21:6 Comment(0)
I
4

Every time you copy or cut something to the clipboard in windows, you lose whatever was on your clipboard before. (Though some programs will store previous clipboard contents for you) The emacs "ring" will store old clipboard contents even after you copy/yank/cut/kill things. It can be handy if you get used to it because it lets you store more than one thing in the clipboard at once, and reduces the chances of accidentally overwriting something that you cut to the clipboard like you could in Windows.

Infracostal answered 15/10, 2010 at 15:36 Comment(0)
H
3

A ring is a circular buffer. Think of a rolodex.

If you are killing/yanking to a ring, then you can walk forward and backwards in your history.

Hypercritical answered 15/10, 2010 at 15:34 Comment(0)
P
2

On Ubuntu, with the emacs-goodies-el package installed:

Press C-( M-x browse-kill-ring RET C-)

This defines a temporary keyboard macro which calls browse-kill-ring when you press C-x e.

Now you don't have to just read about the kill ring, you can actually see what's in it.

Experiment with C-w (cut), M-w (copy), C-y (yank) and C-y M-y (yank next in ring), and press C-x e to see the effect on the kill ring.

Panelist answered 30/10, 2010 at 16:20 Comment(3)
Is browse-kill-ring a standard library function? I cannot find it.Relive
@Török Gábor: Oops, I didn't realize it is not a standard library function. It is provided by the emacs-goodies-el package on Ubuntu. The code can be found here: fan.gr.jp/~ring/doc/misc/browse-kill-ring.elPanelist
<emacswiki.org/emacs/browse-kill-ring.el>, <emacswiki.org/emacs/browse-kill-ring%2b.el>Peeved
T
1

From the Emacs manual: "A ring is a fixed-size data structure that supports insertion, deletion, rotation, and modulo-indexed reference and traversal." In other words, it's a circular queue.

Tuggle answered 15/10, 2010 at 15:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.