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