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