All Manuals > LispWorks IDE User Guide > 12 The Editor

12.11 Cutting, copying and pasting using the kill ring

The Editor provides a sophisticated range of commands for cutting or copying text onto a special kind of clipboard, known as the kill ring, and then pasting that text back into your Editor later on. There are three steps in the process, as follows:

12.11.1 Marking the region

First of all, you need to mark a region of text in the current buffer which you want to transfer into the kill ring. There are two ways that you can do this:

Because the Editor does not highlight the marked region when you use keyboard commands, a useful Emacs key to remember is Ctrl+X Ctrl+X. Pressing this exchanges the current cursor position with the start of the marked region and highlights the region. Press Ctrl+X Ctrl+X a second time to return the cursor to its original position and leave the region marked.

Press Ctrl+G (or Esc in KDE/Gnome emulation) to remove the highlighting in a region.

12.11.2 Cutting or copying text

Once you have marked the region, you need to transfer the text to the kill ring by either cutting or copying it.

Cutting text moves it from the current buffer into the kill ring, and deletes it from the current buffer, whereas copying just places a copy of the text in the kill ring.

Notice that these commands transfer the selected text to the LispWorks IDE clipboard as well as the kill ring. This is so that the selected text can be transferred into other tools, or even into other applications.

The selected text is also transferred to the system clipboard.

12.11.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.

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 Kill ring with three items, the kill ring contains three items; the words factorial, function and macro respectively.

Kill ring with three items

First, the word factorial was cut from the current buffer (this would remove it from the buffer). Next, the word function was copied (which would leave it in the buffer but add a copy of it to the kill ring), and lastly, the word macro 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 word macro 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.

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 Emacs key to do this is Alt+Y or Esc 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 Pasting from the kill ring, the word macro would be replaced with the word function.

You can use Alt+Y as many times as you like. For instance, if you actually wanted to paste the word factorial in the document, pressing Alt+Y would replace the word function with the word factorial.

Rotating the kill ring

If you pressed Alt+Y a third time, the kill ring would have rotated completely, and macro would have been the current item once again.

Note: You can never use Alt+Y without having used Ctrl+Y immediately beforehand.

Here is a summary of the way Ctrl+Y and Alt+Y work:


LispWorks IDE User Guide (Unix version) - 01 Dec 2021 19:37:11