8.10 Cutting, copying and pasting using the kill ring

8.10.3 Pasting text

Once you have an item in the kill ring, you can paste it back into a buffer as many times as you like.

Note that you must use the keyboard command if you wish to paste the item that is in the kill ring (as opposed to the item in the Common LispWorks clipboard).

With many editors you can only do this with one item at a time. The clipboard is only able to contain one item, and so it is the only one available for pasting back into the text.

However, the kill ring allows you to keep many items. Any of these items can be pasted back into your document at any time. Every time you cut or copy something, it is added to the kill ring, so you accumulate more items in the kill ring as your session progresses.

Consider the following example. In Figure 8.7, the kill ring contains three items; the wordsfactorial,function andmacro respectively.

Figure 8.7 Kill ring with three items

First, the wordfactorial was cut from the current buffer (this would remove it from the buffer). Next, the wordfunction was copied (which would leave it in the buffer but add a copy of it to the kill ring), and lastly, the wordmacro was cut.

Note the concept of the kill ring rotating (this is why it is known as a ring). Every time a new item is added (at the top, in these figures), the others are all shunted around in a counter-clockwise direction.

Whenever you perform a paste, the current item in the kill ring -- the wordmacro in this case -- is copied back into the buffer wherever the cursor currently is. Note that the current item is not removed from the kill ring.

Figure 8.8 Pasting from the kill ring

What you have seen so far does exactly the same thing as the standard clipboard. True, all three items have been kept in the kill ring, but they are of no use if you cannot actually get at them.

The command to do this isMeta-Y. This rotates the kill ring in the opposite direction -- thus making the previous item the current one -- and pastes it into the buffer in place of the item just pasted. In Figure 8.8, the wordmacro would be replaced with the wordfunction.

You can useMeta-Y as many times as you like. For instance, if you actually wanted to paste the wordfactorial in the document, pressingMeta-Y would replace the wordfunction with the wordfactorial.

Figure 8.9 Rotating the kill ring

If you pressedMeta-Y a third time, the kill ring would have rotated completely, andmacro would have been the current item once again.

Note: You can never useMeta-Y without having usedCtrl-Y immediately beforehand.

Here is a summary of the wayCtrl-Y andMeta-Y work:


Common LispWorks User Guide, Liquid Common Lisp Version 5.0 - 18 OCT 1996

Generated with Harlequin WebMaker