1 @c This is part of the Emacs manual.
2 @c Copyright (C) 1985-1987, 1993-1995, 1997, 2001-2017 Free Software
4 @c See file emacs.texi for copying conditions.
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.
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}. You can also set a register in
19 non-alphanumeric characters, for instance @samp{*} or @samp{C-d}.
20 Note, it's not possible to set a register in @samp{C-g} or @samp{ESC},
21 because these keys are reserved to terminate interactive commands.
24 A register can store a position, a piece of text, a rectangle, a
25 number, a window configuration, or a file name, but only one thing at
26 any given time. Whatever you store in a register remains there until
27 you store something else in that register. To see what register
28 @var{r} contains, use @kbd{M-x view-register}:
31 @item M-x view-register @key{RET} @var{r}
32 Display a description of what register @var{r} contains.
35 @vindex register-preview-delay
36 @cindex preview of registers
37 All of the commands that prompt for a register will display a
38 preview window that lists the existing registers (if there are
39 any) after a short delay. To change the length of the delay,
40 customize @code{register-preview-delay}. To prevent this display, set
41 that option to @code{nil}. You can explicitly request a preview
42 window by pressing @kbd{C-h} or @key{F1}.
44 @dfn{Bookmarks} record files and positions in them, so you can
45 return to those positions when you look at the file again. Bookmarks
46 are similar in spirit to registers, so they are also documented in
50 * Position Registers:: Saving positions in registers.
51 * Text Registers:: Saving text in registers.
52 * Rectangle Registers:: Saving rectangles in registers.
53 * Configuration Registers:: Saving window configurations in registers.
54 * Number Registers:: Numbers in registers.
55 * File Registers:: File names in registers.
56 * Keyboard Macro Registers:: Keyboard macros in registers.
57 * Bookmarks:: Bookmarks are like registers, but persistent.
60 @node Position Registers
61 @section Saving Positions in Registers
62 @cindex saving position in a register
65 @item C-x r @key{SPC} @var{r}
66 Record the position of point and the current buffer in register
67 @var{r} (@code{point-to-register}).
69 Jump to the position and buffer saved in register @var{r}
70 (@code{jump-to-register}).
74 @findex point-to-register
75 Typing @kbd{C-x r @key{SPC}} (@code{point-to-register}), followed by
76 a character @kbd{@var{r}}, saves both the position of point and the
77 current buffer in register @var{r}. The register retains this
78 information until you store something else in it.
81 @findex jump-to-register
82 The command @kbd{C-x r j @var{r}} switches to the buffer recorded in
83 register @var{r}, and moves point to the recorded position. The
84 contents of the register are not changed, so you can jump to the saved
85 position any number of times.
87 If you use @kbd{C-x r j} to go to a saved position, but the buffer it
88 was saved from has been killed, @kbd{C-x r j} tries to create the buffer
89 again by visiting the same file. Of course, this works only for buffers
90 that were visiting files.
93 @section Saving Text in Registers
94 @cindex saving text in a register
96 When you want to insert a copy of the same piece of text several
97 times, it may be inconvenient to yank it from the kill ring, since each
98 subsequent kill moves that entry further down the ring. An alternative
99 is to store the text in a register and later retrieve it.
102 @item C-x r s @var{r}
103 Copy region into register @var{r} (@code{copy-to-register}).
104 @item C-x r i @var{r}
105 Insert text from register @var{r} (@code{insert-register}).
106 @item M-x append-to-register @key{RET} @var{r}
107 Append region to text in register @var{r}.
110 When register @var{r} contains text, you can use @kbd{C-x r +}
111 (@code{increment-register}) to append to that register. Note that
112 command @kbd{C-x r +} behaves differently if @var{r} contains a
113 number. @xref{Number Registers}.
115 @item M-x prepend-to-register @key{RET} @var{r}
116 Prepend region to text in register @var{r}.
120 @findex copy-to-register
121 @kbd{C-x r s @var{r}} stores a copy of the text of the region into
122 the register named @var{r}. If the mark is inactive, Emacs first
123 reactivates the mark where it was last set. The mark is deactivated
124 at the end of this command. @xref{Mark}. @kbd{C-u C-x r s @var{r}},
125 the same command with a prefix argument, copies the text into register
126 @var{r} and deletes the text from the buffer as well; you can think of
127 this as moving the region text into the register.
129 @findex append-to-register
130 @findex prepend-to-register
131 @kbd{M-x append-to-register @key{RET} @var{r}} appends the copy of
132 the text in the region to the text already stored in the register
133 named @var{r}. If invoked with a prefix argument, it deletes the
134 region after appending it to the register. The command
135 @code{prepend-to-register} is similar, except that it @emph{prepends}
136 the region text to the text in the register instead of
139 @vindex register-separator
140 When you are collecting text using @code{append-to-register} and
141 @code{prepend-to-register}, you may want to separate individual
142 collected pieces using a separator. In that case, configure a
143 @code{register-separator} and store the separator text in to that
144 register. For example, to get double newlines as text separator
145 during the collection process, you can use the following setting.
148 (setq register-separator ?+)
149 (set-register register-separator "\n\n")
153 @findex insert-register
154 @kbd{C-x r i @var{r}} inserts in the buffer the text from register
155 @var{r}. Normally it leaves point after the text and sets the mark
156 before, without activating it. With a numeric argument, it instead
157 puts point before the text and the mark after.
159 @node Rectangle Registers
160 @section Saving Rectangles in Registers
161 @cindex saving rectangle in a register
163 A register can contain a rectangle instead of linear text.
164 @xref{Rectangles}, for basic information on how to specify a rectangle
168 @findex copy-rectangle-to-register
170 @item C-x r r @var{r}
171 Copy the region-rectangle into register @var{r}
172 (@code{copy-rectangle-to-register}). With numeric argument, delete it as
174 @item C-x r i @var{r}
175 Insert the rectangle stored in register @var{r} (if it contains a
176 rectangle) (@code{insert-register}).
179 The @kbd{C-x r i @var{r}} (@code{insert-register}) command,
180 previously documented in @ref{Text Registers}, inserts a rectangle
181 rather than a text string, if the register contains a rectangle.
183 @node Configuration Registers
184 @section Saving Window Configurations in Registers
185 @cindex saving window configuration in a register
187 @findex window-configuration-to-register
188 @findex frameset-to-register
191 You can save the window configuration of the selected frame in a
192 register, or even the configuration of all windows in all frames, and
193 restore the configuration later. @xref{Windows}, for information
194 about window configurations.
197 @item C-x r w @var{r}
198 Save the state of the selected frame's windows in register @var{r}
199 (@code{window-configuration-to-register}).
200 @item C-x r f @var{r}
201 Save the state of all frames, including all their windows, in register
202 @var{r} (@code{frameset-to-register}).
205 Use @kbd{C-x r j @var{r}} to restore a window or frame configuration.
206 This is the same command used to restore a cursor position. When you
207 restore a frame configuration, any existing frames not included in the
208 configuration become invisible. If you wish to delete these frames
209 instead, use @kbd{C-u C-x r j @var{r}}.
211 @node Number Registers
212 @section Keeping Numbers in Registers
213 @cindex saving number in a register
215 There are commands to store a number in a register, to insert
216 the number in the buffer in decimal, and to increment it. These commands
217 can be useful in keyboard macros (@pxref{Keyboard Macros}).
220 @item C-u @var{number} C-x r n @var{r}
222 @findex number-to-register
223 Store @var{number} into register @var{r} (@code{number-to-register}).
224 @item C-u @var{number} C-x r + @var{r}
226 @findex increment-register
227 If @var{r} contains a number, increment the number in that register by
228 @var{number}. Note that command @kbd{C-x r +}
229 (@code{increment-register}) behaves differently if @var{r} contains
230 text. @xref{Text Registers}.
231 @item C-x r i @var{r}
232 Insert the number from register @var{r} into the buffer.
235 @kbd{C-x r i} is the same command used to insert any other sort of
236 register contents into the buffer. @kbd{C-x r +} with no numeric
237 argument increments the register value by 1; @kbd{C-x r n} with no
238 numeric argument stores zero in the register.
241 @section Keeping File Names in Registers
242 @cindex saving file name in a register
244 If you visit certain file names frequently, you can visit them more
245 conveniently if you put their names in registers. Here's the Lisp code
246 used to put a file @var{name} into register @var{r}:
249 (set-register @var{r} '(file . @var{name}))
257 (set-register ?z '(file . "/gd/gnu/emacs/19.0/src/ChangeLog"))
261 puts the file name shown in register @samp{z}.
263 To visit the file whose name is in register @var{r}, type @kbd{C-x r j
264 @var{r}}. (This is the same command used to jump to a position or
265 restore a frame configuration.)
267 @node Keyboard Macro Registers
268 @section Keyboard Macro Registers
269 @cindex saving keyboard macro in a register
270 @cindex keyboard macros, in registers
273 @findex kmacro-to-register
274 If you need to execute a keyboard macro (@pxref{Keyboard Macros})
275 frequently, it is more convenient to put it in a register or save it
276 (@pxref{Save Keyboard Macro}). @kbd{C-x C-k x @var{r}}
277 (@code{kmacro-to-register}) stores the last keyboard macro in register
280 To execute the keyboard macro in register @var{r}, type @kbd{C-x r j
281 @var{r}}. (This is the same command used to jump to a position or
288 @dfn{Bookmarks} are somewhat like registers in that they record
289 positions you can jump to. Unlike registers, they have long names, and
290 they persist automatically from one Emacs session to the next. The
291 prototypical use of bookmarks is to record where you were reading in
295 @item C-x r m @key{RET}
296 Set the bookmark for the visited file, at point.
298 @item C-x r m @var{bookmark} @key{RET}
299 Set the bookmark named @var{bookmark} at point (@code{bookmark-set}).
301 @item C-x r M @var{bookmark} @key{RET}
302 Like @kbd{C-x r m}, but don't overwrite an existing bookmark.
304 @item C-x r b @var{bookmark} @key{RET}
305 @findex bookmark-jump
306 Jump to the bookmark named @var{bookmark} (@code{bookmark-jump}).
309 @findex list-bookmarks
310 List all bookmarks (@code{list-bookmarks}).
312 @item M-x bookmark-save
313 @findex bookmark-save
314 Save all the current bookmark values in the default bookmark file.
320 @findex bookmark-jump
321 The prototypical use for bookmarks is to record one current position
322 in each of several files. So the command @kbd{C-x r m}, which sets a
323 bookmark, uses the visited file name as the default for the bookmark
324 name. If you name each bookmark after the file it points to, then you
325 can conveniently revisit any of those files with @kbd{C-x r b}, and move
326 to the position of the bookmark at the same time.
329 @findex bookmark-set-no-overwrite
330 The command @kbd{C-x r M} (@code{bookmark-set-no-overwrite}) works
331 like @kbd{C-x r m}, but it signals an error if the specified bookmark
332 already exists, instead of overwriting it.
335 To display a list of all your bookmarks in a separate buffer, type
336 @kbd{C-x r l} (@code{list-bookmarks}). If you switch to that buffer,
337 you can use it to edit your bookmark definitions or annotate the
338 bookmarks. Type @kbd{C-h m} in the bookmark buffer for more
339 information about its special editing commands.
341 When you kill Emacs, Emacs saves your bookmarks, if
342 you have changed any bookmark values. You can also save the bookmarks
343 at any time with the @kbd{M-x bookmark-save} command. Bookmarks are
344 saved to the file @file{~/.emacs.d/bookmarks} (for compatibility with
345 older versions of Emacs, if you have a file named @file{~/.emacs.bmk},
346 that is used instead). The bookmark commands load your default
347 bookmark file automatically. This saving and loading is how bookmarks
348 persist from one Emacs session to the next.
350 @vindex bookmark-save-flag
351 If you set the variable @code{bookmark-save-flag} to 1, each command
352 that sets a bookmark will also save your bookmarks; this way, you
353 don't lose any bookmark values even if Emacs crashes. The value, if
354 a number, says how many bookmark modifications should go by between
355 saving. If you set this variable to @code{nil}, Emacs only
356 saves bookmarks if you explicitly use @kbd{M-x bookmark-save}.
358 @vindex bookmark-default-file
359 The variable @code{bookmark-default-file} specifies the file in
360 which to save bookmarks by default.
362 @vindex bookmark-search-size
363 Bookmark position values are saved with surrounding context, so that
364 @code{bookmark-jump} can find the proper position even if the file is
365 modified slightly. The variable @code{bookmark-search-size} says how
366 many characters of context to record on each side of the bookmark's
369 Here are some additional commands for working with bookmarks:
372 @item M-x bookmark-load @key{RET} @var{filename} @key{RET}
373 @findex bookmark-load
374 Load a file named @var{filename} that contains a list of bookmark
375 values. You can use this command, as well as @code{bookmark-write}, to
376 work with other files of bookmark values in addition to your default
379 @item M-x bookmark-write @key{RET} @var{filename} @key{RET}
380 @findex bookmark-write
381 Save all the current bookmark values in the file @var{filename}.
383 @item M-x bookmark-delete @key{RET} @var{bookmark} @key{RET}
384 @findex bookmark-delete
385 Delete the bookmark named @var{bookmark}.
387 @item M-x bookmark-insert-location @key{RET} @var{bookmark} @key{RET}
388 @findex bookmark-insert-location
389 Insert in the buffer the name of the file that bookmark @var{bookmark}
392 @item M-x bookmark-insert @key{RET} @var{bookmark} @key{RET}
393 @findex bookmark-insert
394 Insert in the buffer the @emph{contents} of the file that bookmark
395 @var{bookmark} points to.