0
|
1
|
|
2 @iftex
|
|
3 @chapter Killing and Moving Text
|
|
4
|
|
5 @dfn{Killing} means erasing text and copying it into the @dfn{kill ring},
|
|
6 from which it can be retrieved by @dfn{yanking} it. Some other systems
|
|
7 that have recently become popular use the terms ``cutting'' and ``pasting''
|
|
8 for these operations.
|
|
9
|
|
10 The most common way of moving or copying text with Emacs is to kill it
|
|
11 and later yank it in one or more places. This is safe because all the
|
|
12 text killed recently is stored in the kill ring, and it is versatile,
|
|
13 because you can use the same commands for killing syntactic units and
|
|
14 for moving those units. There are other ways of copying text for
|
|
15 special purposes.
|
|
16
|
|
17 Emacs has only one kill ring, so you can kill text in one buffer and yank
|
|
18 it in another buffer. If you are using XEmacs under X, you can
|
|
19 also use the X selection mechanism to copy text from one buffer to
|
|
20 another, or between applications. @xref{Using X Selections}.
|
|
21
|
|
22 @end iftex
|
|
23
|
|
24 @node Killing, Yanking, Additional Mouse Operations, Top
|
|
25 @section Deletion and Killing
|
|
26 @findex delete-char
|
|
27 @findex delete-backward-char
|
|
28
|
|
29 @cindex killing
|
|
30 @cindex cutting
|
|
31 @cindex deletion
|
|
32 @kindex C-d
|
|
33 @kindex DEL
|
|
34 Most commands that erase text from the buffer save it. You can get
|
|
35 the text back if you change your mind, or you can move or copy it to
|
|
36 other parts of the buffer. Commands which erase text and save it in the
|
|
37 kill ring are known as @dfn{kill} commands. Some other commands erase
|
|
38 text but do not save it; they are known as @dfn{delete} commands. (This
|
|
39 distinction is made only for erasing text in the buffer.)
|
|
40
|
|
41 The commands' names and individual descriptions use the words
|
|
42 @samp{kill} and @samp{delete} to indicate what they do. If you perform
|
|
43 a kill or delete command by mistake, use the @kbd{C-x u} (@code{undo})
|
|
44 command to undo it (@pxref{Undo}). The delete commands include @kbd{C-d}
|
|
45 (@code{delete-char}) and @key{DEL} (@code{delete-backward-char}), which
|
|
46 delete only one character at a time, and those commands that delete only
|
|
47 spaces or newlines. Commands that can destroy significant amounts of
|
|
48 nontrivial data usually kill.@refill
|
|
49
|
|
50 @subsection Deletion
|
|
51
|
|
52 @table @kbd
|
|
53 @item C-d
|
|
54 Delete next character (@code{delete-char}).
|
|
55 @item @key{DEL}
|
|
56 Delete previous character (@code{delete-backward-char}).
|
|
57 @item M-\
|
|
58 Delete spaces and tabs around point (@code{delete-horizontal-space}).
|
|
59 @item M-@key{SPC}
|
|
60 Delete spaces and tabs around point, leaving one space
|
|
61 (@code{just-one-space}).
|
|
62 @item C-x C-o
|
|
63 Delete blank lines around the current line (@code{delete-blank-lines}).
|
|
64 @item M-^
|
|
65 Join two lines by deleting the intervening newline, and any indentation
|
|
66 following it (@code{delete-indentation}).
|
|
67 @end table
|
|
68
|
|
69 The most basic delete commands are @kbd{C-d} (@code{delete-char}) and
|
|
70 @key{DEL} (@code{delete-backward-char}). @kbd{C-d} deletes the
|
|
71 character after point, the one the cursor is ``on top of''. Point
|
|
72 doesn't move. @key{DEL} deletes the character before the cursor, and
|
|
73 moves point back. You can delete newlines like any other characters in
|
|
74 the buffer; deleting a newline joins two lines. Actually, @kbd{C-d} and
|
|
75 @key{DEL} aren't always delete commands; if you give them an argument,
|
|
76 they kill instead, since they can erase more than one character this
|
|
77 way.
|
|
78
|
|
79 @kindex M-\
|
|
80 @findex delete-horizontal-space
|
|
81 @kindex M-SPC
|
|
82 @findex just-one-space
|
|
83 @kindex C-x C-o
|
|
84 @findex delete-blank-lines
|
|
85 @kindex M-^
|
|
86 @findex delete-indentation
|
|
87 The other delete commands delete only formatting characters: spaces,
|
|
88 tabs and newlines. @kbd{M-\} (@code{delete-horizontal-space}) deletes
|
|
89 all spaces and tab characters before and after point.
|
|
90 @kbd{M-@key{SPC}} (@code{just-one-space}) does the same but leaves a
|
|
91 single space after point, regardless of the number of spaces that
|
|
92 existed previously (even zero).
|
|
93
|
|
94 @kbd{C-x C-o} (@code{delete-blank-lines}) deletes all blank lines after
|
|
95 the current line. If the current line is blank, it deletes all blank lines
|
|
96 preceding the current line as well as leaving one blank line, the current
|
|
97 line. @kbd{M-^} (@code{delete-indentation}) joins the current line and
|
|
98 the previous line, or, if given an argument, joins the current line and
|
|
99 the next line by deleting a newline and all surrounding spaces, possibly
|
|
100 leaving a single space. @xref{Indentation,M-^}.
|
|
101
|
|
102 @subsection Killing by Lines
|
|
103
|
|
104 @table @kbd
|
|
105 @item C-k
|
|
106 Kill rest of line or one or more lines (@code{kill-line}).
|
|
107 @end table
|
|
108
|
|
109 @kindex C-k
|
|
110 @findex kill-line
|
|
111 The simplest kill command is @kbd{C-k}. If given at the beginning of
|
|
112 a line, it kills all the text on the line, leaving the line blank. If
|
|
113 given on a blank line, the blank line disappears. As a consequence, a
|
|
114 line disappears completely if you go to the front of a non-blank line
|
|
115 and type @kbd{C-k} twice.
|
|
116
|
|
117 More generally, @kbd{C-k} kills from point up to the end of the line,
|
|
118 unless it is at the end of a line. In that case, it kills the newline
|
|
119 following the line, thus merging the next line into the current one.
|
|
120 Emacs ignores invisible spaces and tabs at the end of the line when deciding
|
|
121 which case applies: if point appears to be at the end of the line, you
|
|
122 can be sure the newline will be killed.
|
|
123
|
|
124 If you give @kbd{C-k} a positive argument, it kills that many lines
|
|
125 and the newlines that follow them (however, text on the current line
|
|
126 before point is not killed). With a negative argument, @kbd{C-k} kills
|
|
127 back to a number of line beginnings. An argument of @minus{}2 means
|
|
128 kill back to the second line beginning. If point is at the beginning of
|
|
129 a line, that line beginning doesn't count, so @kbd{C-u - 2 C-k} with
|
|
130 point at the front of a line kills the two previous lines.
|
|
131
|
|
132 @kbd{C-k} with an argument of zero kills all the text before point on the
|
|
133 current line.
|
|
134
|
|
135 @subsection Other Kill Commands
|
|
136 @findex kill-region
|
|
137 @findex kill-word
|
|
138 @findex backward-kill-word
|
|
139 @findex kill-sexp
|
|
140 @findex kill-sentence
|
|
141 @findex backward-kill-sentence
|
|
142 @kindex M-d
|
|
143 @kindex M-DEL
|
|
144 @kindex C-M-k
|
|
145 @kindex C-x DEL
|
|
146 @kindex M-k
|
|
147 @kindex C-w
|
|
148
|
|
149 @c DoubleWideCommands
|
|
150 @table @kbd
|
|
151 @item C-w
|
|
152 Kill region (from point to the mark) (@code{kill-region}).
|
|
153 @xref{Words}.
|
|
154 @item M-d
|
|
155 Kill word (@code{kill-word}).
|
|
156 @item M-@key{DEL}
|
|
157 Kill word backwards (@code{backward-kill-word}).
|
|
158 @item C-x @key{DEL}
|
|
159 Kill back to beginning of sentence (@code{backward-kill-sentence}).
|
|
160 @xref{Sentences}.
|
|
161 @item M-k
|
|
162 Kill to end of sentence (@code{kill-sentence}).
|
|
163 @item C-M-k
|
|
164 Kill sexp (@code{kill-sexp}). @xref{Lists}.
|
|
165 @item M-z @var{char}
|
|
166 Kill up to next occurrence of @var{char} (@code{zap-to-char}).
|
|
167 @end table
|
|
168
|
|
169 @kbd{C-w} (@code{kill-region}) is a very general kill command; it
|
|
170 kills everything between point and the mark. You can use this command to
|
|
171 kill any contiguous sequence of characters by first setting the mark at
|
|
172 one end of a sequence of characters, then going to the other end and
|
|
173 typing @kbd{C-w}.
|
|
174
|
|
175 @kindex M-z
|
|
176 @findex zap-to-char
|
|
177 A convenient way of killing is combined with searching: @kbd{M-z}
|
|
178 (@code{zap-to-char}) reads a character and kills from point up to (but not
|
|
179 including) the next occurrence of that character in the buffer. If there
|
|
180 is no next occurrence, killing goes to the end of the buffer. A numeric
|
|
181 argument acts as a repeat count. A negative argument means to search
|
|
182 backward and kill text before point.
|
|
183
|
|
184 Other syntactic units can be killed: words, with @kbd{M-@key{DEL}} and
|
|
185 @kbd{M-d} (@pxref{Words}); sexps, with @kbd{C-M-k} (@pxref{Lists}); and
|
|
186 sentences, with @kbd{C-x @key{DEL}} and @kbd{M-k}
|
|
187 (@pxref{Sentences}).@refill
|
|
188
|
|
189 @node Yanking, Using X Selections, Killing, Top
|
|
190 @section Yanking
|
|
191 @cindex moving text
|
|
192 @cindex copying text
|
|
193 @cindex kill ring
|
|
194 @cindex yanking
|
|
195 @cindex pasting
|
|
196
|
|
197 @dfn{Yanking} means getting back text which was killed. Some systems
|
|
198 call this ``pasting''. The usual way to move or copy text is to kill it
|
|
199 and then yank it one or more times.
|
|
200
|
|
201 @table @kbd
|
|
202 @item C-y
|
|
203 Yank last killed text (@code{yank}).
|
|
204 @item M-y
|
|
205 Replace re-inserted killed text with the previously killed text
|
|
206 (@code{yank-pop}).
|
|
207 @item M-w
|
|
208 Save region as last killed text without actually killing it
|
|
209 (@code{copy-region-as-kill}).
|
|
210 @item C-M-w
|
|
211 Append next kill to last batch of killed text (@code{append-next-kill}).
|
|
212 @end table
|
|
213
|
|
214 @menu
|
|
215 * Kill Ring:: Where killed text is stored. Basic yanking.
|
|
216 * Appending Kills:: Several kills in a row all yank together.
|
|
217 * Earlier Kills:: Yanking something killed some time ago.
|
|
218 @end menu
|
|
219
|
|
220 @node Kill Ring, Appending Kills, Yanking, Yanking
|
|
221 @subsection The Kill Ring
|
|
222
|
|
223 @kindex C-y
|
|
224 @findex Yank
|
|
225 All killed text is recorded in the @dfn{kill ring}, a list of blocks of
|
|
226 text that have been killed. There is only one kill ring, used in all
|
|
227 buffers, so you can kill text in one buffer and yank it in another buffer.
|
|
228 This is the usual way to move text from one file to another.
|
|
229 (@xref{Accumulating Text}, for some other ways.)
|
|
230
|
|
231 If you have two separate Emacs processes, you cannot use the kill ring
|
|
232 to move text. If you are using XEmacs under X, however, you can
|
|
233 use the X selection mechanism to move text from one to another.
|
|
234
|
|
235 If you are using XEmacs under X and have one Emacs process with
|
|
236 multiple frames, they do share the same kill ring. You can kill or
|
|
237 copy text in one Emacs frame, then yank it in the other frame
|
|
238 belonging to the same process.
|
|
239
|
|
240 The command @kbd{C-y} (@code{yank}) reinserts the text of the most recent
|
|
241 kill. It leaves the cursor at the end of the text and sets the mark at
|
|
242 the beginning of the text. @xref{Mark}.
|
|
243
|
|
244 @kbd{C-u C-y} yanks the text, leaves the cursor in front of the text,
|
|
245 and sets the mark after it, if the argument is with just a @kbd{C-u}.
|
|
246 Any other argument, including @kbd{C-u} and digits, has different
|
|
247 results, described below, under ``Yanking Earlier Kills''.
|
|
248
|
|
249 @kindex M-w
|
|
250 @findex copy-region-as-kill
|
|
251 To copy a block of text, you can also use @kbd{M-w}
|
|
252 (@code{copy-region-as-kill}), which copies the region into the kill ring
|
|
253 without removing it from the buffer. @kbd{M-w} is similar to @kbd{C-w}
|
|
254 followed by @kbd{C-y} but does not mark the buffer as ``modified'' and
|
|
255 does not actually cut anything.
|
|
256
|
|
257 @node Appending Kills, Earlier Kills, Kill Ring, Yanking
|
|
258 @subsection Appending Kills
|
|
259
|
|
260 @cindex television
|
|
261 Normally, each kill command pushes a new block onto the kill ring.
|
|
262 However, two or more kill commands in a row combine their text into a
|
|
263 single entry, so that a single @kbd{C-y} yanks it all back. This means
|
|
264 you don't have to kill all the text you want to yank in one command; you
|
|
265 can kill line after line, or word after word, until you have killed what
|
|
266 you want, then get it all back at once using @kbd{C-y}. (Thus we join
|
|
267 television in leading people to kill thoughtlessly.)
|
|
268
|
|
269 Commands that kill forward from point add onto the end of the previous
|
|
270 killed text. Commands that kill backward from point add onto the
|
|
271 beginning. This way, any sequence of mixed forward and backward kill
|
|
272 commands puts all the killed text into one entry without rearrangement.
|
|
273 Numeric arguments do not break the sequence of appending kills. For
|
|
274 example, suppose the buffer contains:
|
|
275
|
|
276 @example
|
|
277 This is the first
|
|
278 line of sample text
|
|
279 and here is the third.
|
|
280 @end example
|
|
281
|
|
282 @noindent
|
|
283 with point at the beginning of the second line. If you type @kbd{C-k C-u 2
|
|
284 M-@key{DEL} C-k}, the first @kbd{C-k} kills the text @samp{line of sample
|
|
285 text}, @kbd{C-u 2 M-@key{DEL}} kills @samp{the first} with the newline that
|
|
286 followed it, and the second @kbd{C-k} kills the newline after the second
|
|
287 line. The result is that the buffer contains @samp{This is and here is the
|
|
288 third.} and a single kill entry contains @samp{the first@key{RET}line of
|
|
289 sample text@key{RET}}---all the killed text, in its original order.
|
|
290
|
|
291 @kindex C-M-w
|
|
292 @findex append-next-kill
|
|
293 If a kill command is separated from the last kill command by other
|
|
294 commands (not just numeric arguments), it starts a new entry on the kill
|
|
295 ring. To force a kill command to append, first type the command @kbd{C-M-w}
|
|
296 (@code{append-next-kill}). @kbd{C-M-w} tells the following command,
|
|
297 if it is a kill command, to append the text it kills to the last killed
|
|
298 text, instead of starting a new entry. With @kbd{C-M-w}, you can kill
|
|
299 several separated pieces of text and accumulate them to be yanked back
|
|
300 in one place.@refill
|
|
301
|
|
302 @node Earlier Kills,, Appending Kills, Yanking
|
|
303 @subsection Yanking Earlier Kills
|
|
304
|
|
305 @kindex M-y
|
|
306 @findex yank-pop
|
|
307 To recover killed text that is no longer the most recent kill, you need
|
|
308 the @kbd{Meta-y} (@code{yank-pop}) command. You can use @kbd{M-y} only
|
|
309 after a @kbd{C-y} or another @kbd{M-y}. It takes the text previously
|
|
310 yanked and replaces it with the text from an earlier kill. To recover
|
|
311 the text of the next-to-the-last kill, first use @kbd{C-y} to recover
|
|
312 the last kill, then @kbd{M-y} to replace it with the previous
|
|
313 kill.@refill
|
|
314
|
|
315 You can think in terms of a ``last yank'' pointer which points at an item
|
|
316 in the kill ring. Each time you kill, the ``last yank'' pointer moves to
|
|
317 the new item at the front of the ring. @kbd{C-y} yanks the item
|
|
318 which the ``last yank'' pointer points to. @kbd{M-y} moves the ``last
|
|
319 yank'' pointer to a different item, and the text in the buffer changes to
|
|
320 match. Enough @kbd{M-y} commands can move the pointer to any item in the
|
|
321 ring, so you can get any item into the buffer. Eventually the pointer
|
|
322 reaches the end of the ring; the next @kbd{M-y} moves it to the first item
|
|
323 again.
|
|
324
|
|
325 Yanking moves the ``last yank'' pointer around the ring, but does not
|
|
326 change the order of the entries in the ring, which always runs from the
|
|
327 most recent kill at the front to the oldest one still remembered.
|
|
328
|
|
329 Use @kbd{M-y} with a numeric argument to advance the ``last
|
|
330 yank'' pointer by the specified number of items. A negative argument
|
|
331 moves the pointer toward the front of the ring; from the front of the
|
|
332 ring, it moves to the last entry and starts moving forward from there.
|
|
333
|
|
334 Once the text you are looking for is brought into the buffer, you can
|
|
335 stop doing @kbd{M-y} commands and the text will stay there. Since the
|
|
336 text is just a copy of the kill ring item, editing it in the buffer does
|
|
337 not change what's in the ring. As long you don't kill additional text,
|
|
338 the ``last yank'' pointer remains at the same place in the kill ring:
|
|
339 repeating @kbd{C-y} will yank another copy of the same old kill.
|
|
340
|
|
341 If you know how many @kbd{M-y} commands it would take to find the
|
|
342 text you want, you can yank that text in one step using @kbd{C-y} with
|
|
343 a numeric argument. @kbd{C-y} with an argument greater than one
|
|
344 restores the text the specified number of entries back in the kill
|
|
345 ring. Thus, @kbd{C-u 2 C-y} gets the next to the last block of killed
|
|
346 text. It is equivalent to @kbd{C-y M-y}. @kbd{C-y} with a numeric
|
|
347 argument starts counting from the ``last yank'' pointer, and sets the
|
|
348 ``last yank'' pointer to the entry that it yanks.
|
|
349
|
|
350 @vindex kill-ring-max
|
|
351 The variable @code{kill-ring-max} controls the length of the kill
|
|
352 ring; no more than that many blocks of killed text are saved.
|
|
353
|
|
354 @node Using X Selections, Accumulating Text, Yanking, Top
|
|
355 @section Using X Selections
|
|
356 @comment node-name, next, previous, up
|
|
357
|
|
358 In the X window system, mouse selections provide a simple mechanism for
|
|
359 text transfer between different applications. In a typical X
|
|
360 application, you can select text by pressing the left mouse button and
|
|
361 dragging the cursor over the text you want to copy. The text becomes the
|
|
362 primary X selection and is highlighted. The highlighted region is also
|
|
363 the Emacs selected region.
|
|
364
|
|
365 @itemize @bullet
|
|
366 @item
|
|
367 Since the region is the primary X selection, you can go to a different X
|
|
368 application and click the middle mouse button: the text that you selected in
|
|
369 the previous application is pasted into the current application.
|
|
370 @item
|
|
371 Since the region is the Emacs selected region, you can use all region
|
|
372 commands (@kbd{C-w, M-w} etc.) as well as the options of the @b{Edit}
|
|
373 menu to manipulate the selected text.
|
|
374 @end itemize
|
|
375
|
|
376 @menu
|
|
377 * X Clipboard Selection:: Pasting to the X clipboard.
|
|
378 * X Selection Commands:: Other operations on the selection.
|
|
379 * X Cut Buffers:: X cut buffers are available for compatibility.
|
|
380 * Active Regions:: Using zmacs-style highlighting of the
|
|
381 selected region.
|
|
382 @end menu
|
|
383
|
|
384 @node X Clipboard Selection, X Selection Commands, Using X Selections, Using X Selections
|
|
385 @comment node-name, next, previous, up
|
|
386 @subsection The Clipboard Selection
|
|
387 @cindex clipboard selections
|
|
388
|
|
389 There are other kinds of X selections besides the @b{Primary} selection; one
|
|
390 common one is the @b{Clipboard} selection. Some applications prefer to
|
|
391 transfer data using this selection in preference to the @b{Primary}.
|
|
392 One can transfer text from the @b{Primary} selection to the @b{Clipboard}
|
|
393 selection with the @b{Copy} command under the @b{Edit} menu in the menubar.
|
|
394
|
|
395 Usually, the clipboard selection is not visible. However, if you run the
|
|
396 @file{xclipboard} application, the text most recently copied to the clipboard
|
|
397 (with the @b{Copy} command) is displayed in a window. Any time new text is
|
|
398 thus copied, the @file{xclipboard} application makes a copy of it and displays
|
|
399 it in its window. The value of the clipboard can survive the lifetime of the
|
|
400 running Emacs process. The @code{xclipboard} man page provides more details.
|
|
401
|
|
402 Warning: If you use the @file{xclipboard} application, remember that it
|
|
403 maintains a list of all things that have been pasted to the clipboard (that
|
|
404 is, copied with the @b{Copy} command). If you don't manually delete elements
|
|
405 from this list by clicking on the @b{Delete} button in the @code{xclipboard}
|
|
406 window, the clipboard will eventually consume a lot of memory.
|
|
407
|
|
408 In summary, some X applications (such as @file{xterm}) allow one to paste
|
|
409 text in them from XEmacs in the following way:
|
|
410
|
|
411 @itemize @bullet
|
|
412 @item
|
|
413 Drag out a region of text in Emacs with the left mouse button,
|
|
414 making that text be the @b{Primary} selection.
|
|
415
|
|
416 @item
|
|
417 Click the middle button in the other application, pasting the @b{Primary}
|
|
418 selection.
|
|
419 @end itemize
|
|
420
|
|
421 With some other applications (notably, the OpenWindows and Motif tools) you
|
|
422 must use this method instead:
|
|
423
|
|
424 @itemize @bullet
|
|
425 @item
|
|
426 Drag out a region of text in Emacs with the left mouse button,
|
|
427 making that text be the @b{Primary} selection.
|
|
428
|
|
429 @item
|
|
430 Copy the selected text to the @b{Clipboard} selection by selecting the
|
|
431 @b{Copy} menu item from the @b{Edit} menu, or by hitting the @b{Copy}
|
|
432 key on your keyboard.
|
|
433
|
|
434 @item
|
|
435 Paste the text in the other application by selecting @b{Paste} from its
|
|
436 menu, or by hitting the @b{Paste} key on your keyboard.
|
|
437 @end itemize
|
|
438
|
|
439
|
|
440 @node X Selection Commands, X Cut Buffers, X Clipboard Selection, Using X Selections
|
|
441 @subsection Miscellaneous X Selection Commands
|
|
442 @comment node-name, next, previous, up
|
|
443 @cindex cut buffers
|
|
444 @cindex primary selections
|
|
445
|
|
446 @findex x-copy-primary-selection
|
|
447 @findex x-delete-primary-selection
|
|
448 @findex x-insert-selection
|
|
449 @findex x-kill-primary-selection
|
|
450 @findex x-mouse-kill
|
|
451 @findex x-own-secondary-selection
|
|
452 @findex x-own-selection
|
|
453 @findex x-set-point-and-insert-selection
|
|
454 @table @kbd
|
|
455 @item M-x x-copy-primary-selection
|
|
456 Copy the primary selection to both the kill ring and the Clipboard.
|
|
457 @item M-x x-insert-selection
|
|
458 Insert the current selection into the buffer at point.
|
|
459 @item M-x x-delete-primary-selection
|
|
460 Deletes the text in the primary selection without copying it to the kill
|
|
461 ring or the Clipboard.
|
|
462 @item M-x x-kill-primary-selection
|
|
463 Deletes the text in the primary selection and copies it to
|
|
464 both the kill ring and the Clipboard.
|
|
465 @item M-x x-mouse-kill
|
|
466 Kill the text between point and the mouse and copy it to
|
|
467 the clipboard and to the cut buffer.
|
|
468 @item M-x x-own-secondary-selection
|
|
469 Make a secondary X selection of the given argument.
|
|
470 @item M-x x-own-selection
|
|
471 Make a primary X selection of the given argument.
|
|
472 @item M-x x-set-point-and-insert-selection
|
|
473 Set point where clicked and insert the primary selection or the
|
|
474 cut buffer.
|
|
475 @end table
|
|
476
|
|
477 @node X Cut Buffers, Active Regions, X Selection Commands, Using X Selections
|
|
478 @subsection X Cut Buffers
|
|
479 @comment node-name, next, previous, up
|
|
480
|
|
481 X cut buffers are a different, older way of transferring text between
|
|
482 applications. XEmacs supports cut buffers for compatibility
|
|
483 with older programs, even though selections are now the preferred way of
|
|
484 transferring text.
|
|
485
|
|
486 X has a concept of applications "owning" selections. When you select
|
|
487 text by clicking and dragging inside an application, the application
|
|
488 tells the X server that it owns the selection. When another
|
|
489 application asks the X server for the value of the selection, the X
|
|
490 server requests the information from the owner. When you use
|
|
491 selections, the selection data is not actually transferred unless
|
|
492 someone wants it; the act of making a selection doesn't transfer data.
|
|
493 Cut buffers are different: when you "own" a cut buffer, the data is
|
|
494 actually transferred to the X server immediately, and survives the
|
|
495 lifetime of the application.
|
|
496
|
|
497 Any time a region of text becomes the primary selection in Emacs,
|
|
498 Emacs also copies that text to the cut buffer. This makes it possible
|
|
499 to copy text from an XEmacs buffer and paste it into an older,
|
|
500 non-selection-based application (such as Emacs 18).
|
|
501
|
|
502 Note: Older versions of Emacs could not access the X selections, only
|
|
503 the X cut buffers.
|
|
504
|
|
505 @node Active Regions, , X Cut Buffers, Using X Selections
|
|
506 @subsection Active Regions
|
|
507 @comment node-name, next, previous, up
|
|
508 @cindex active regions
|
|
509
|
|
510 By default, both the text you select in an Emacs buffer using the
|
|
511 click-and-drag mechanism and text you select by setting point and the
|
|
512 mark is highlighted. You can use Emacs region commands as well as the
|
|
513 @b{Cut} and @b{Copy} commands on the highlighted region you selected
|
|
514 with the mouse.
|
|
515
|
|
516 If you prefer, you can make a distinction between text selected with the
|
|
517 mouse and text selected with point and the mark by setting the variable
|
|
518 @code{zmacs-regions} to @code{nil}. In that case:
|
|
519
|
|
520 @itemize @bullet
|
|
521 @item
|
|
522 The text selected with the mouse becomes both the X selection and the
|
|
523 Emacs selected region. You can use menu-bar commands as well as Emacs
|
|
524 region commands on it.
|
|
525 @item
|
|
526 The text selected with point and the mark is not highlighted. You can
|
|
527 only use Emacs region commands on it, not the menu-bar items.
|
|
528 @end itemize
|
|
529
|
|
530 Active regions originally come from Zmacs, the Lisp Machine editor.
|
|
531 The idea behind them is that commands can only operate on a region when
|
|
532 the region is in an "active" state. Put simply, you can only operate on
|
|
533 a region that is highlighted.
|
|
534
|
|
535 @vindex zmacs-regions
|
|
536 The variable @code{zmacs-regions} checks whether LISPM-style active
|
|
537 regions should be used. This means that commands that operate on the
|
|
538 region (the area between point and the mark) only work while
|
|
539 the region is in the active state, which is indicated by highlighting.
|
|
540 Most commands causes the region to not be in the active state;
|
|
541 for example, @kbd{C-w} only works immediately after activating the
|
|
542 region.
|
|
543
|
|
544 More specifically:
|
|
545 @itemize @bullet
|
|
546 @item
|
|
547 Commands that operate on the region only work if the region is active.
|
|
548 @item
|
|
549 Only a very small set of commands causes the region to become active---
|
|
550 those commands whose semantics are to mark an area, such as @code{mark-defun}.
|
|
551 @item
|
|
552 The region is deactivated after each command that is executed, except that
|
|
553 motion commands do not change whether the region is active or not.
|
|
554 @end itemize
|
|
555
|
|
556 @code{set-mark-command} (@kbd{C-SPC}) pushes a mark and activates the
|
|
557 region. Moving the cursor with normal motion commands (@kbd{C-n},
|
|
558 @kbd{C-p}, etc.) will cause the region between point and the
|
|
559 recently-pushed mark to be highlighted. It will remain highlighted
|
108
|
560 until some non-motion command is executed.
|
0
|
561
|
|
562 @code{exchange-point-and-mark} (@kbd{C-x C-x}) activates the region.
|
|
563 So if you mark a region and execute a command that operates on it, you
|
|
564 can reactivate the same region with @kbd{C-x C-x} (or perhaps @kbd{C-x
|
|
565 C-x C-x C-x}) to operate on it again.
|
|
566
|
|
567 Generally, commands that push marks as a means of navigation, such as
|
|
568 @code{beginning-of-buffer} (@kbd{M-<}) and @code{end-of-buffer}
|
|
569 (@kbd{M->}), do not activate the region. However, commands that push
|
|
570 marks as a means of marking an area of text, such as @code{mark-defun}
|
|
571 (@kbd{M-C-h}), @code{mark-word} (@kbd{M-@@}), and @code{mark-whole-buffer}
|
|
572 (@kbd{C-x h}), do activate the region.
|
|
573
|
|
574 When @code{zmacs-regions} is @code{t}, there is no distinction between
|
|
575 the primary X selection and the active region selected by point and the
|
|
576 mark. To see this, set the mark (@key{C-SPC}) and move the cursor
|
|
577 with any cursor-motion command: the region between point and mark is
|
|
578 highlighted, and you can watch it grow and shrink as you move the
|
|
579 cursor.
|
|
580
|
|
581 Any other commands besides cursor-motion commands (such as inserting or
|
|
582 deleting text) will cause the region to no longer be active; it will no
|
|
583 longer be highlighted, and will no longer be the primary selection.
|
280
|
584 Region can be explicitly deactivated with @kbd{C-g}.
|
0
|
585
|
|
586 Commands that require a region (such as @kbd{C-w}) signal an error if
|
|
587 the region is not active. Certain commands cause the region to be in
|
|
588 its active state. The most common ones are @code{push-mark}
|
|
589 (@key{C-SPC}) and @code{exchange-point-and-mark} (@kbd{C-x C-x}).
|
|
590
|
|
591 @vindex zmacs-region-stays
|
|
592 When @code{zmacs-regions} is @code{t}, programs can be non-intrusive
|
|
593 on the state of the region by setting the variable @code{zmacs-region-stays}
|
|
594 to a non-@code{nil} value. If you are writing a new Emacs command that
|
|
595 is conceptually a ``motion'' command and should not interfere with the
|
|
596 current highlightedness of the region, then you may set this variable.
|
|
597 It is reset to @code{nil} after each user command is executed.
|
|
598
|
|
599 @findex zmacs-activate-region
|
|
600 When @code{zmacs-regions} is @code{t}, programs can make the region between
|
|
601 point and mark go into the active (highlighted) state by using the
|
|
602 function @code{zmacs-activate-region}. Only a small number of commands
|
|
603 should ever do this.
|
|
604
|
|
605 @findex zmacs-deactivate-region
|
|
606 When @code{zmacs-regions} is @code{t}, programs can deactivate the region
|
|
607 between point and the mark by using @code{zmacs-deactivate-region}.
|
|
608 Note: you should not have to call this function; the command loop calls
|
|
609 it when appropriate.
|
|
610
|
|
611 @node Accumulating Text, Rectangles, Using X Selections, Top
|
|
612 @section Accumulating Text
|
|
613 @findex append-to-buffer
|
|
614 @findex prepend-to-buffer
|
|
615 @findex copy-to-buffer
|
|
616 @findex append-to-file
|
|
617 @cindex copying text
|
|
618 @cindex accumulating text
|
|
619
|
|
620 Usually you copy or move text by killing it and yanking it, but there are
|
|
621 other ways that are useful for copying one block of text in many places, or
|
|
622 for copying many scattered blocks of text into one place.
|
|
623
|
|
624 If you like, you can accumulate blocks of text from scattered
|
|
625 locations either into a buffer or into a file. The relevant commands
|
|
626 are described here. You can also use Emacs registers for storing and
|
|
627 accumulating text. @xref{Registers}.
|
|
628
|
|
629 @table @kbd
|
|
630 @item M-x append-to-buffer
|
|
631 Append region to contents of specified buffer (@code{append-to-buffer}).
|
|
632 @item M-x prepend-to-buffer
|
|
633 Prepend region to contents of specified buffer.
|
|
634 @item M-x copy-to-buffer
|
|
635 Copy region into specified buffer, deleting that buffer's old contents.
|
|
636 @item M-x insert-buffer
|
|
637 Insert contents of specified buffer into current buffer at point.
|
|
638 @item M-x append-to-file
|
|
639 Append region to the end of the contents of specified file.
|
|
640 @end table
|
|
641
|
|
642 To accumulate text into a buffer, use the command @kbd{M-x
|
|
643 append-to-buffer}, which inserts a copy of the region into the buffer
|
|
644 @var{buffername}, at the location of point in that buffer. If there is
|
|
645 no buffer with the given name, one is created.
|
|
646
|
|
647 If you append text to a buffer that has been used for editing, the
|
|
648 copied text goes to the place where point is. Point in that buffer is
|
|
649 left at the end of the copied text, so successive uses of
|
|
650 @code{append-to-buffer} accumulate the text in the specified buffer in
|
|
651 the same order as they were copied. Strictly speaking, this command does
|
|
652 not always append to the text already in the buffer; but if this command
|
|
653 is the only command used to alter a buffer, it does always append to the
|
|
654 existing text because point is always at the end.
|
|
655
|
|
656 @kbd{M-x prepend-to-buffer} is similar to @code{append-to-buffer}, but
|
|
657 point in the other buffer is left before the copied text, so successive
|
|
658 prependings add text in reverse order. @kbd{M-x copy-to-buffer} is
|
|
659 similar, except that any existing text in the other buffer is deleted,
|
|
660 so the buffer is left containing just the text newly copied into it.
|
|
661
|
|
662 You can retrieve the accumulated text from that buffer with @kbd{M-x
|
|
663 insert-buffer}, which takes @var{buffername} as an argument. It inserts
|
|
664 a copy of the text in buffer @var{buffername} into the selected buffer.
|
|
665 You could alternatively select the other buffer for editing, perhaps moving
|
|
666 text from it by killing or with @code{append-to-buffer}. @xref{Buffers}, for
|
|
667 background information on buffers.
|
|
668
|
|
669 Instead of accumulating text within Emacs in a buffer, you can append
|
|
670 text directly into a file with @kbd{M-x append-to-file}, which takes
|
|
671 @var{file-name} as an argument. It adds the text of the region to the
|
|
672 end of the specified file. The file is changed immediately on disk.
|
|
673 This command is normally used with files that are @i{not} being visited
|
|
674 in Emacs. Using it on a file that Emacs is visiting can produce
|
|
675 confusing results, because the file's text inside Emacs does not change
|
|
676 while the file itself changes.
|
|
677
|
|
678 @node Rectangles, Registers, Accumulating Text, Top
|
|
679 @section Rectangles
|
|
680 @cindex rectangles
|
|
681
|
|
682 The rectangle commands affect rectangular areas of text: all
|
|
683 characters between a certain pair of columns, in a certain range of lines.
|
|
684 Commands are provided to kill rectangles, yank killed rectangles, clear
|
|
685 them out, or delete them. Rectangle commands are useful with text in
|
|
686 multicolumnar formats, like code with comments at the right,
|
|
687 or for changing text into or out of such formats.
|
|
688
|
|
689 To specify the rectangle a command should work on, put the mark at one
|
|
690 corner and point at the opposite corner. The specified rectangle is
|
|
691 called the @dfn{region-rectangle} because it is controlled about the
|
|
692 same way the region is controlled. Remember that a given
|
|
693 combination of point and mark values can be interpreted either as
|
|
694 specifying a region or as specifying a rectangle; it is up to the
|
|
695 command that uses them to choose the interpretation.
|
|
696
|
|
697 @table @kbd
|
|
698 @item M-x delete-rectangle
|
|
699 Delete the text of the region-rectangle, moving any following text on
|
|
700 each line leftward to the left edge of the region-rectangle.
|
|
701 @item M-x kill-rectangle
|
|
702 Similar, but also save the contents of the region-rectangle as the
|
|
703 ``last killed rectangle''.
|
|
704 @item M-x yank-rectangle
|
|
705 Yank the last killed rectangle with its upper left corner at point.
|
|
706 @item M-x open-rectangle
|
|
707 Insert blank space to fill the space of the region-rectangle.
|
|
708 The previous contents of the region-rectangle are pushed rightward.
|
|
709 @item M-x clear-rectangle
|
|
710 Clear the region-rectangle by replacing its contents with spaces.
|
|
711 @end table
|
|
712
|
|
713 The rectangle operations fall into two classes: commands deleting and
|
|
714 moving rectangles, and commands for blank rectangles.
|
|
715
|
|
716 @findex delete-rectangle
|
|
717 @findex kill-rectangle
|
|
718 There are two ways to get rid of the text in a rectangle: you can discard
|
|
719 the text (delete it) or save it as the ``last killed'' rectangle. The
|
|
720 commands for these two ways are @kbd{M-x delete-rectangle} and @kbd{M-x
|
|
721 kill-rectangle}. In either case, the portion of each line that falls inside
|
|
722 the rectangle's boundaries is deleted, causing following text (if any) on
|
|
723 the line to move left.
|
|
724
|
|
725 Note that ``killing'' a rectangle is not killing in the usual sense; the
|
|
726 rectangle is not stored in the kill ring, but in a special place that
|
|
727 only records the most recently killed rectangle (that is, does not
|
|
728 append to a killed rectangle). Different yank commands
|
|
729 have to be used and only one rectangle is stored, because yanking
|
|
730 a rectangle is quite different from yanking linear text and yank-popping
|
|
731 commands are difficult to make sense of.
|
|
732
|
|
733 Inserting a rectangle is the opposite of deleting one. You specify
|
|
734 where to put the upper left corner by putting point there. The
|
|
735 rectangle's first line is inserted at point, the rectangle's second line
|
|
736 is inserted at a point one line vertically down, and so on. The number
|
|
737 of lines affected is determined by the height of the saved rectangle.
|
|
738
|
|
739 @findex yank-rectangle
|
|
740 To insert the last killed rectangle, type @kbd{M-x yank-rectangle}.
|
|
741 This can be used to convert single-column lists into double-column
|
|
742 lists; kill the second half of the list as a rectangle and then
|
|
743 yank it beside the first line of the list.
|
|
744
|
|
745 @findex open-rectangle
|
|
746 @findex clear-rectangle
|
|
747 There are two commands for working with blank rectangles: @kbd{M-x
|
|
748 clear-rectangle} erases existing text, and @kbd{M-x open-rectangle}
|
|
749 inserts a blank rectangle. Clearing a rectangle is equivalent to
|
|
750 deleting it and then inserting a blank rectangle of the same size.
|
|
751
|
|
752 Rectangles can also be copied into and out of registers.
|
|
753 @xref{RegRect,,Rectangle Registers}.
|