Initial git import
[sxemacs] / info / new-users-guide / region.texi
1 @comment  node-name,  next,  previous,  up
2 @node Select and Move, Search and Replace, Other Customizations, Top
3 @chapter Selecting and Moving Text
4 @cindex region
5 @cindex mark
6
7   Many Emacs commands operate on an arbitrary contiguous
8 part of the current buffer. You can select some part of the buffer and
9 edit only that part of the buffer. This selected buffer is called a
10 @dfn{region}. You can select text in two ways:
11
12 @itemize @bullet
13 @item
14 You use special keys to select text by defining a region between the
15 cursor and @dfn{the mark} (which you set). 
16 @item
17 If you are running SXEmacs under X, you can also select text
18 with the mouse. 
19 @end itemize
20
21 @comment  node-name,  next,  previous,  up
22 @menu
23 * Selecting Text::              Select a region of text by setting the Mark
24 * Mouse::                       Selecting Text with Mouse
25 * Region Operation::            Various ways to operate on a selected text
26 * Moving Text::                 Moving Text 
27 * Accumulating text::           Accumulating Text from several buffers
28 @end menu
29
30 @node Selecting Text, Mouse, Select and Move, Select and Move
31 @section Setting the Mark
32 @kindex C-SPC
33 @kindex C-x C-x
34 @kindex C-<
35 @kindex C->
36 @findex set-mark-command
37 @findex mark-beginning-of-buffer
38 @findex mark-end-of-buffer
39 @findex exchange-point-and-mark
40   To define a region you need to set @dfn{the mark} at one end of it and 
41 move the cursor to the other end. Once you set the mark, it remains
42 there until you set it again to some other place. Each buffer has its
43 own @dfn{mark ring} (a place where Emacs remembers 16 previous
44 locations of the mark). To set @dfn{the mark}, you can use the
45 following commands:
46
47 @table @kbd
48 @item C-@key{SPC}
49 This command will set @dfn{the mark} at the position of your cursor
50 (@code{set-mark-command}).  You can move your cursor around and @dfn{the
51 mark} will stay there. 
52 @item C-x C-x
53 Interchange mark and point (@code{exchange-point-and-mark}). Since Emacs
54 will have only one cursor, after you move the cursor it will be unable
55 to show you where you set the @dfn{the mark}. In order to see @dfn{the
56 mark} you can type the command @kbd{C-x C-x} which will put your cursor
57 on the position of your mark and your mark on the position of your
58 cursor. Use the command again to reset the positions of your cursor and
59 mark. 
60 @item C-<
61 This command will push the mark at the beginning of the buffer without
62 changing the position of your cursor.
63 @item C->
64 This command will push the mark at the end of the buffer without
65 changing the position of your cursor.
66 @end table
67 @noindent
68 You can also give arguments to @kbd{C-<} or @kbd{C->}. @xref{The Mark
69 and the Region,,,sxemacs,SXEmacs User's Manual}, for more information.
70
71 @comment  node-name,  next,  previous,  up
72 @node Mouse, Region Operation, Selecting Text, Select and Move
73 @section Selecting Text with Mouse
74 @cindex mouse selection
75 @cindex clipboard selection
76 @cindex primary selection
77 @cindex cursor shapes
78   If you are using SXEmacs under X, you can use the mouse to select
79 text. The selected text will always be highlighted, so just by looking
80 at the text you know what you have selected so far. To select a word
81 just double-click with the left-mouse-button on the word. To select a
82 whole line triple-click anywhere on the line with the
83 left-mouse-button. You can also use the @b{Copy} item from the @b{Edit}
84 menu on the menu-bar to select text. This kind of selection is called
85 @b{Clipboard} selection, @xref{X Clipboard Selection,,,sxemacs,SXEmacs User's
86 Manual}, for more information. To select an arbitrary region, follow
87 these steps:
88
89 @enumerate
90 @item
91 Move the mouse cursor over the character at the beginning of the region of
92 text you want to select.
93 @item
94 Press and hold the left mouse button. 
95 @item
96 While holding the left mouse button down, drag the cursor to the
97 character at the end of the region of text you want to select.
98 @item
99 Release the left mouse button.
100 @end enumerate
101 The selected region of text is highlighted.
102
103   @xref{Selecting Text with the Mouse,,,sxemacs,SXEmacs User's Manual}, for
104 more information regarding the Mouse and additional mouse operations.
105
106 @comment  node-name,  next,  previous,  up
107 @node Region Operation, Moving Text, Mouse, Select and Move
108 @section Operating on the Region
109   Once you have selected a region you can do a lot of things to the text
110 in the region:
111 @kindex C-w
112 @kindex C-x C-u
113 @kindex C-x C-l
114 @kindex C-SPC
115 @kindex C-x TAB
116 @kindex C-M-\
117 @findex print-region
118 @itemize @bullet
119 @item
120 Kill the text with @kbd{C-w}. For example if you want to kill a
121 paragraph, position the cursor to the beginning of the paragraph and
122 type @kbd{C-SPC}. Then go to the end of the paragraph and type
123 @kbd{C-w}. The entire paragraph will be deleted. You can also select the
124 text with a mouse and type @kbd{C-w} to kill the entire
125 region. @xref{Killing,,,sxemacs,SXEmacs User's Manual}, for more information.
126
127 @item
128 Save the text in a buffer or a file (@pxref{Accumulating
129 Text,,,sxemacs,SXEmacs User's Manual}).
130 @item
131 You can convert the case of the text with @kbd{C-x C-l} or @kbd{C-x C-u}
132 If you type @kbd{C-x C-u} the selected text will become all
133 upper-case. If you type @kbd{C-x C-l} the selected text will become all
134 lower-case. 
135 @item
136 Print hardcopy with @kbd{M-x
137 print-region}. @xref{Hardcopy,,,sxemacs,SXEmacs User's Manual}, for more
138 information. This command will print a hardcopy of only the selected
139 text.
140 @item
141 Indent it with @kbd{C-x @key{TAB}} or @kbd{C-M-\}
142 @xref{Indentation,,,sxemacs,SXEmacs User's Manual}, for more information.
143 @end itemize
144
145
146 @comment  node-name,  next,  previous,  up
147 @node Moving Text, Accumulating text, Region Operation, Select and Move
148 @section Moving Text
149 @cindex yanking
150 @cindex pasting
151 @findex yank
152 @cindex killing
153 @cindex kill ring
154 @cindex moving text
155 @kindex C-y
156   The most common way to move or copy text in Emacs is through
157 @dfn{killing} or @samp{cutting} it and then @dfn{yanking} or
158 @samp{pasting} it. You can also use the @b{Cut} or @b{Copy} option from
159 the @b{Edit} menu for killing and copying respectively. @xref{Edit menu}, 
160 for reviewing the commands for killing text. All the killed text
161 in Emacs is recorded in the @dfn{kill ring}. Since there is only one
162 kill ring in Emacs, you can kill text in one buffer and yank it in
163 another buffer. To @samp{paste} or 
164 @samp{yank} the killed text you can use the following commands:
165 @table @kbd
166 @item C-y
167 This command will yank or paste the last killed text (@code{yank}).
168 @item M-w
169 Save region as last killed text without actually killing it
170 (@code{copy-region-as-kill}). You can use this command to copy a
171 selected region and then yank (or paste) it without actually removing it
172 from the buffer.
173 @item C-M-w
174 Append next kill to last batch of killed text
175 (@code{append-next-kill}). This command will append whatever you killed
176 last to what you kill now. Then later you will be able to yank the
177 entire appended text from the @dfn{kill ring}. 
178 @end table
179
180 @comment  node-name,  next,  previous,  up
181 @node Accumulating text,  , Moving Text, Select and Move
182 @section Accumulating Text
183 @findex append-to-buffer
184 @findex prepend-to-buffer
185 @findex copy-to-buffer
186 @findex append-to-file
187 @cindex copying text
188 @cindex accumulating text
189 @cindex rectangle commands
190 @cindex registers
191 @cindex temporary storage
192
193   The following commands can be used for accumulating text from
194 different buffers into one place or for copying one region of text into
195 many buffers: 
196
197 @table @kbd
198 @item M-x append-to-buffer
199 Append region to contents of specified buffer
200 (@code{append-to-buffer}). After you type in this command and press
201 @key{RET}, Emacs will prompt you for a buffer name. You will see a
202 message in the echo area:
203 @example
204 Append to buffer: (default <buffer name>) 
205 @end example
206 @noindent
207 After you type in a buffer name, a copy of the region will be inserted
208 at the location of the cursor into that buffer. If there is no buffer
209 with the name given by you, Emacs will create a new buffer with that
210 name. By default the cursor's position in the <buffer name> is at the end.
211 @item M-x prepend-to-buffer
212 Prepend region to contents of specified buffer. This command is similar
213 to the above command except that the cursor in the buffer (by default)
214 is at the beginning rather than at the end.
215 @item M-x copy-to-buffer
216 Copy region into specified buffer, deleting that buffer's old
217 contents. This command will also prompt you for a buffer name.
218 @item M-x insert-buffer
219 Insert contents of specified buffer into current buffer at point. This
220 command will prompt you for a buffer name which you want to be copied
221 into the current buffer at the location of the cursor.
222 @item M-x append-to-file
223 This command will prompt you for a filename and append the region to
224 the end of the contents of the specified file.
225 @end table
226
227 @noindent
228 @xref{Accumulating Text,,,sxemacs,SXEmacs User's Manual}, for more
229 information regarding this topic.
230   
231   You can also use @dfn{rectangle commands} for operating on rectangular
232 areas of text. @xref{Rectangles,,,sxemacs,SXEmacs User's Manual}, for more
233 information regarding rectangle commands.
234
235   Emacs also provides @dfn{registers} which serve as temporary storage for
236 text or positions. Each register has a one character name and they can
237 store @dfn{regions}, a @dfn{rectangle}, or a @dfn{mark} i.e. a cursor
238 position. Whatever you store in register stays there until you store
239 something else in that register. To find out about commands which
240 manipulate registers @xref{Registers,,,sxemacs,SXEmacs User's Manual}. 
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258