]> code.delx.au - gnu-emacs/blob - doc/emacs/regs.texi
Add 2012 to FSF copyright years for Emacs files
[gnu-emacs] / doc / emacs / regs.texi
1 @c This is part of the Emacs manual.
2 @c Copyright (C) 1985-1987, 1993-1995, 1997, 2001-2012
3 @c Free Software Foundation, Inc.
4 @c See file emacs.texi for copying conditions.
5 @node Registers, Display, Killing, Top
6 @chapter Registers
7 @cindex registers
8
9 Emacs @dfn{registers} are compartments where you can save text,
10 rectangles, positions, and other things for later use. Once you save
11 text or a rectangle in a register, you can copy it into the buffer
12 once, or many times; once you save a position in a register, you can
13 jump back to that position once, or many times.
14
15 Each register has a name that consists of a single character, which
16 we will denote by @var{r}; @var{r} can be a letter (such as @samp{a})
17 or a number (such as @samp{1}); case matters, so register @samp{a} is
18 not the same as register @samp{A}.
19
20 @findex view-register
21 A register can store a position, a piece of text, a rectangle, a
22 number, a window configuration, or a file name, but only one thing at
23 any given time. Whatever you store in a register remains there until
24 you store something else in that register. To see what register
25 @var{r} contains, use @kbd{M-x view-register}:
26
27 @table @kbd
28 @item M-x view-register @key{RET} @var{r}
29 Display a description of what register @var{r} contains.
30 @end table
31
32 @dfn{Bookmarks} record files and positions in them, so you can
33 return to those positions when you look at the file again. Bookmarks
34 are similar in spirit to registers, so they are also documented in
35 this chapter.
36
37 @menu
38 * Position Registers:: Saving positions in registers.
39 * Text Registers:: Saving text in registers.
40 * Rectangle Registers:: Saving rectangles in registers.
41 * Configuration Registers:: Saving window configurations in registers.
42 * Number Registers:: Numbers in registers.
43 * File Registers:: File names in registers.
44 * Bookmarks:: Bookmarks are like registers, but persistent.
45 @end menu
46
47 @node Position Registers
48 @section Saving Positions in Registers
49 @cindex saving position in a register
50
51 @table @kbd
52 @item C-x r @key{SPC} @var{r}
53 Record the position of point and the current buffer in register
54 @var{r} (@code{point-to-register}).
55 @item C-x r j @var{r}
56 Jump to the position and buffer saved in register @var{r}
57 (@code{jump-to-register}).
58 @end table
59
60 @kindex C-x r SPC
61 @findex point-to-register
62 Typing @kbd{C-x r @key{SPC}} (@code{point-to-register}), followed by
63 a character @kbd{@var{r}}, saves both the position of point and the
64 current buffer in register @var{r}. The register retains this
65 information until you store something else in it.
66
67 @kindex C-x r j
68 @findex jump-to-register
69 The command @kbd{C-x r j @var{r}} switches to the buffer recorded in
70 register @var{r}, and moves point to the recorded position. The
71 contents of the register are not changed, so you can jump to the saved
72 position any number of times.
73
74 If you use @kbd{C-x r j} to go to a saved position, but the buffer it
75 was saved from has been killed, @kbd{C-x r j} tries to create the buffer
76 again by visiting the same file. Of course, this works only for buffers
77 that were visiting files.
78
79 @node Text Registers
80 @section Saving Text in Registers
81 @cindex saving text in a register
82
83 When you want to insert a copy of the same piece of text several
84 times, it may be inconvenient to yank it from the kill ring, since each
85 subsequent kill moves that entry further down the ring. An alternative
86 is to store the text in a register and later retrieve it.
87
88 @table @kbd
89 @item C-x r s @var{r}
90 Copy region into register @var{r} (@code{copy-to-register}).
91 @item C-x r i @var{r}
92 Insert text from register @var{r} (@code{insert-register}).
93 @item M-x append-to-register @key{RET} @var{r}
94 Append region to text in register @var{r}.
95 @item M-x prepend-to-register @key{RET} @var{r}
96 Prepend region to text in register @var{r}.
97 @end table
98
99 @kindex C-x r s
100 @findex copy-to-register
101 @kbd{C-x r s @var{r}} stores a copy of the text of the region into
102 the register named @var{r}. If the mark is inactive, Emacs first
103 reactivates the mark where it was last set. The mark is deactivated
104 at the end of this command. @xref{Mark}. @kbd{C-u C-x r s @var{r}},
105 the same command with a prefix argument, copies the text into register
106 @var{r} and deletes the text from the buffer as well; you can think of
107 this as ``moving'' the region text into the register.
108
109 @findex append-to-register
110 @findex prepend-to-register
111 @kbd{M-x append-to-register @key{RET} @var{r}} appends the copy of
112 the text in the region to the text already stored in the register
113 named @var{r}. If invoked with a prefix argument, it deletes the
114 region after appending it to the register. The command
115 @code{prepend-to-register} is similar, except that it @emph{prepends}
116 the region text to the text in the register instead of
117 @emph{appending} it.
118
119 @kindex C-x r i
120 @findex insert-register
121 @kbd{C-x r i @var{r}} inserts in the buffer the text from register
122 @var{r}. Normally it leaves point before the text and sets the mark
123 after, without activating it. With a numeric argument, it instead
124 puts point after the text and the mark before.
125
126 @node Rectangle Registers
127 @section Saving Rectangles in Registers
128 @cindex saving rectangle in a register
129
130 A register can contain a rectangle instead of linear text.
131 @xref{Rectangles}, for basic information on how to specify a rectangle
132 in the buffer.
133
134 @table @kbd
135 @findex copy-rectangle-to-register
136 @kindex C-x r r
137 @item C-x r r @var{r}
138 Copy the region-rectangle into register @var{r}
139 (@code{copy-rectangle-to-register}). With numeric argument, delete it as
140 well.
141 @item C-x r i @var{r}
142 Insert the rectangle stored in register @var{r} (if it contains a
143 rectangle) (@code{insert-register}).
144 @end table
145
146 The @kbd{C-x r i @var{r}} (@code{insert-register}) command,
147 previously documented in @ref{Text Registers}, inserts a rectangle
148 rather than a text string, if the register contains a rectangle.
149
150 @node Configuration Registers
151 @section Saving Window Configurations in Registers
152 @cindex saving window configuration in a register
153
154 @findex window-configuration-to-register
155 @findex frame-configuration-to-register
156 @kindex C-x r w
157 @kindex C-x r f
158 You can save the window configuration of the selected frame in a
159 register, or even the configuration of all windows in all frames, and
160 restore the configuration later. @xref{Windows}, for information
161 about window configurations.
162
163 @table @kbd
164 @item C-x r w @var{r}
165 Save the state of the selected frame's windows in register @var{r}
166 (@code{window-configuration-to-register}).
167 @item C-x r f @var{r}
168 Save the state of all frames, including all their windows, in register
169 @var{r} (@code{frame-configuration-to-register}).
170 @end table
171
172 Use @kbd{C-x r j @var{r}} to restore a window or frame configuration.
173 This is the same command used to restore a cursor position. When you
174 restore a frame configuration, any existing frames not included in the
175 configuration become invisible. If you wish to delete these frames
176 instead, use @kbd{C-u C-x r j @var{r}}.
177
178 @node Number Registers
179 @section Keeping Numbers in Registers
180 @cindex saving number in a register
181
182 There are commands to store a number in a register, to insert
183 the number in the buffer in decimal, and to increment it. These commands
184 can be useful in keyboard macros (@pxref{Keyboard Macros}).
185
186 @table @kbd
187 @item C-u @var{number} C-x r n @var{r}
188 @kindex C-x r n
189 @findex number-to-register
190 Store @var{number} into register @var{r} (@code{number-to-register}).
191 @item C-u @var{number} C-x r + @var{r}
192 @kindex C-x r +
193 @findex increment-register
194 Increment the number in register @var{r} by @var{number}
195 (@code{increment-register}).
196 @item C-x r i @var{r}
197 Insert the number from register @var{r} into the buffer.
198 @end table
199
200 @kbd{C-x r i} is the same command used to insert any other sort of
201 register contents into the buffer. @kbd{C-x r +} with no numeric
202 argument increments the register value by 1; @kbd{C-x r n} with no
203 numeric argument stores zero in the register.
204
205 @node File Registers
206 @section Keeping File Names in Registers
207 @cindex saving file name in a register
208
209 If you visit certain file names frequently, you can visit them more
210 conveniently if you put their names in registers. Here's the Lisp code
211 used to put a file name in a register:
212
213 @smallexample
214 (set-register ?@var{r} '(file . @var{name}))
215 @end smallexample
216
217 @need 3000
218 @noindent
219 For example,
220
221 @smallexample
222 (set-register ?z '(file . "/gd/gnu/emacs/19.0/src/ChangeLog"))
223 @end smallexample
224
225 @noindent
226 puts the file name shown in register @samp{z}.
227
228 To visit the file whose name is in register @var{r}, type @kbd{C-x r j
229 @var{r}}. (This is the same command used to jump to a position or
230 restore a frame configuration.)
231
232 @node Bookmarks
233 @section Bookmarks
234 @cindex bookmarks
235
236 @dfn{Bookmarks} are somewhat like registers in that they record
237 positions you can jump to. Unlike registers, they have long names, and
238 they persist automatically from one Emacs session to the next. The
239 prototypical use of bookmarks is to record ``where you were reading'' in
240 various files.
241
242 @table @kbd
243 @item C-x r m @key{RET}
244 Set the bookmark for the visited file, at point.
245
246 @item C-x r m @var{bookmark} @key{RET}
247 @findex bookmark-set
248 Set the bookmark named @var{bookmark} at point (@code{bookmark-set}).
249
250 @item C-x r b @var{bookmark} @key{RET}
251 @findex bookmark-jump
252 Jump to the bookmark named @var{bookmark} (@code{bookmark-jump}).
253
254 @item C-x r l
255 @findex list-bookmarks
256 List all bookmarks (@code{list-bookmarks}).
257
258 @item M-x bookmark-save
259 @findex bookmark-save
260 Save all the current bookmark values in the default bookmark file.
261 @end table
262
263 @kindex C-x r m
264 @findex bookmark-set
265 @kindex C-x r b
266 @findex bookmark-jump
267 The prototypical use for bookmarks is to record one current position
268 in each of several files. So the command @kbd{C-x r m}, which sets a
269 bookmark, uses the visited file name as the default for the bookmark
270 name. If you name each bookmark after the file it points to, then you
271 can conveniently revisit any of those files with @kbd{C-x r b}, and move
272 to the position of the bookmark at the same time.
273
274 @kindex C-x r l
275 To display a list of all your bookmarks in a separate buffer, type
276 @kbd{C-x r l} (@code{list-bookmarks}). If you switch to that buffer,
277 you can use it to edit your bookmark definitions or annotate the
278 bookmarks. Type @kbd{C-h m} in the bookmark buffer for more
279 information about its special editing commands.
280
281 When you kill Emacs, Emacs saves your bookmarks, if
282 you have changed any bookmark values. You can also save the bookmarks
283 at any time with the @kbd{M-x bookmark-save} command. Bookmarks are
284 saved to the file @file{~/.emacs.d/bookmarks} (for compatibility with
285 older versions of Emacs, if you have a file named @file{~/.emacs.bmk},
286 that is used instead). The bookmark commands load your default
287 bookmark file automatically. This saving and loading is how bookmarks
288 persist from one Emacs session to the next.
289
290 @vindex bookmark-save-flag
291 If you set the variable @code{bookmark-save-flag} to 1, each command
292 that sets a bookmark will also save your bookmarks; this way, you
293 don't lose any bookmark values even if Emacs crashes. The value, if
294 a number, says how many bookmark modifications should go by between
295 saving. If you set this variable to @code{nil}, Emacs only
296 saves bookmarks if you explicitly use @kbd{M-x bookmark-save}.
297
298 @vindex bookmark-search-size
299 Bookmark position values are saved with surrounding context, so that
300 @code{bookmark-jump} can find the proper position even if the file is
301 modified slightly. The variable @code{bookmark-search-size} says how
302 many characters of context to record on each side of the bookmark's
303 position.
304
305 Here are some additional commands for working with bookmarks:
306
307 @table @kbd
308 @item M-x bookmark-load @key{RET} @var{filename} @key{RET}
309 @findex bookmark-load
310 Load a file named @var{filename} that contains a list of bookmark
311 values. You can use this command, as well as @code{bookmark-write}, to
312 work with other files of bookmark values in addition to your default
313 bookmark file.
314
315 @item M-x bookmark-write @key{RET} @var{filename} @key{RET}
316 @findex bookmark-write
317 Save all the current bookmark values in the file @var{filename}.
318
319 @item M-x bookmark-delete @key{RET} @var{bookmark} @key{RET}
320 @findex bookmark-delete
321 Delete the bookmark named @var{bookmark}.
322
323 @item M-x bookmark-insert-location @key{RET} @var{bookmark} @key{RET}
324 @findex bookmark-insert-location
325 Insert in the buffer the name of the file that bookmark @var{bookmark}
326 points to.
327
328 @item M-x bookmark-insert @key{RET} @var{bookmark} @key{RET}
329 @findex bookmark-insert
330 Insert in the buffer the @emph{contents} of the file that bookmark
331 @var{bookmark} points to.
332 @end table