]> code.delx.au - gnu-emacs/blob - doc/emacs/maintaining.texi
* building.texi (Watch Expressions): Fix typo.
[gnu-emacs] / doc / emacs / maintaining.texi
1 @c This is part of the Emacs manual.
2 @c Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1997, 1999, 2000,
3 @c 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
4 @c See file emacs.texi for copying conditions.
5 @node Maintaining, Abbrevs, Building, Top
6 @chapter Maintaining Large Programs
7
8 This chapter describes Emacs features for maintaining large
9 programs.
10
11 @menu
12 * Version Control:: Using version control systems.
13 * Change Log:: Maintaining a change history for your program.
14 * Tags:: Go directly to any function in your program in one
15 command. Tags remembers which file it is in.
16 @ifnottex
17 * Emerge:: A convenient way of merging two versions of a program.
18 @end ifnottex
19 @end menu
20
21 @node Version Control
22 @section Version Control
23 @cindex version control
24
25 A @dfn{version control system} is a package that can record multiple
26 versions of a source file, storing information such as the creation
27 time of each version, who created it, and a description of what was
28 changed in that version.
29
30 The Emacs version control interface is called VC. Its commands work
31 with several different version control systems; currently, it supports
32 GNU Arch, Bazaar, CVS, Git, Mercurial, Monotone, RCS, SCCS/CSSC, and
33 Subversion. Of these, the GNU project distributes CVS, GNU Arch, RCS,
34 and Bazaar.
35
36 VC is enabled automatically whenever you visit a file that is
37 governed by a version control system. To disable VC entirely, set the
38 customizable variable @code{vc-handled-backends} to @code{nil}
39 @iftex
40 (@pxref{Customizing VC,,,emacs-xtra, Specialized Emacs Features}).
41 @end iftex
42 @ifnottex
43 (@pxref{Customizing VC}).
44 @end ifnottex
45
46 @menu
47 * Introduction to VC:: How version control works in general.
48 * VC Mode Line:: How the mode line shows version control status.
49 * Basic VC Editing:: How to edit a file under version control.
50 * Old Revisions:: Examining and comparing old versions.
51 * Secondary VC Commands:: The commands used a little less frequently.
52 * VC Directory Mode:: Listing files managed by version control.
53 * Branches:: Multiple lines of development.
54 @ifnottex
55 * Remote Repositories:: Efficient access to remote CVS servers.
56 * Revision Tags:: Symbolic names for revisions
57 * Miscellaneous VC:: Various other commands and features of VC.
58 * Customizing VC:: Variables that change VC's behavior.
59 @end ifnottex
60 @end menu
61
62 @node Introduction to VC
63 @subsection Introduction to Version Control
64
65 VC allows you to use a version control system from within Emacs,
66 integrating the version control operations smoothly with editing.
67 Though VC cannot completely bridge the gaps between version control
68 systems with widely differing capabilities, it does provide a uniform
69 interface to many version control operations. Regardless of which
70 version control system is in use, you will be able to do basic
71 operations in much the same way.
72
73 This section provides a general overview of version control, and
74 describes the version control systems that VC supports. You can skip
75 this section if you are already familiar with the version control system
76 you want to use.
77
78 @menu
79 * Why Version Control?:: Understanding the problems it addresses
80 * Version Control Systems:: Supported version control back-end systems.
81 * VCS Concepts:: Words and concepts related to version control.
82 * Types of Log File:: The VCS log in contrast to the ChangeLog.
83 @end menu
84
85 @node Why Version Control?
86 @subsubsection Understanding the problems it addresses
87
88 Version control systems provide you with three important
89 capabilities:
90
91 @itemize @bullet
92 @item
93 @dfn{Reversibility}: the ability to back up to a previous state if you
94 discover that some modification you did was a mistake or a bad idea.
95
96 @item
97 @dfn{Concurrency}: the ability to have many people modifying the same
98 collection of files knowing that conflicting modifications can be
99 detected and resolved.
100
101 @item
102 @dfn{History}: the ability to attach historical data to your data,
103 such as explanatory comments about the intention behind each change to
104 it. Even for a programmer working solo, change histories are an
105 important aid to memory; for a multi-person project, they are a
106 vitally important form of communication among developers.
107 @end itemize
108
109 @node Version Control Systems
110 @subsubsection Supported Version Control Systems
111
112 @cindex back end (version control)
113 VC currently works with many different version control systems or
114 @dfn{back ends}:
115
116 @itemize @bullet
117
118 @cindex SCCS
119 @item
120 SCCS was the first version control system ever built, and was long ago
121 superseded by more advanced ones. VC compensates for certain features
122 missing in SCCS (e.g., tag names for releases) by implementing them
123 itself. Other VC features, such as multiple branches, are simply
124 unavailable. Since SCCS is non-free, we recommend avoiding it.
125
126 @cindex CSSC
127 @item
128 CSSC is a free replacement for SCCS. You should use CSSC only if, for
129 some reason, you cannot use a more recent and better-designed version
130 control system.
131
132 @cindex RCS
133 @item
134 RCS is the free version control system around which VC was initially
135 built. Almost everything you can do with RCS can be done through VC.
136 However, you cannot use RCS over the network, and it only works at the
137 level of individual files rather than projects.
138
139 @cindex CVS
140 @item
141 CVS is the free version control system that was, until recently (circa
142 2008), used by the majority of free software projects. Nowadays, it
143 is slowly being superseded by newer systems. CVS allows concurrent
144 multi-user development either locally or over the network. It lacks
145 support for atomic commits or file moving/renaming. VC supports all
146 basic editing operations under CVS. For some less common tasks, you
147 still need to call CVS from the command line. Note also that before
148 using CVS you must set up a repository, which is a subject too complex
149 to treat here.
150
151 @cindex SVN
152 @cindex Subversion
153 @item
154 Subversion (SVN) is a free version control system designed to be
155 similar to CVS but without its problems. It supports atomic commits
156 of filesets, and versioning of directories, symbolic links, meta-data,
157 renames, copies, and deletes.
158
159 @cindex GNU Arch
160 @cindex Arch
161 @item
162 GNU Arch is a version control system designed for distributed work.
163 It differs in many ways from older systems like CVS and RCS. It
164 provides different methods for interoperating between users, support
165 for offline operations, and good branching and merging features. It
166 also supports atomic commits of filesets and file moving/renaming. VC
167 does not support all operations provided by GNU Arch, so you must
168 sometimes invoke it from the command line.
169
170 @cindex git
171 @item
172 Git is a distributed version control system invented by Linus Torvalds to support
173 development of Linux (his kernel). It supports atomic commits of filesets and
174 file moving/renaming. One significant feature of git is that it
175 largely abolishes the notion of a single centralized repository;
176 instead, each working copy of a git project is its own repository and
177 coordination is done through repository-sync operations. VC supports
178 most git operations, with the exception of news merges and repository
179 syncing; these must be done from the command line.
180
181 @cindex hg
182 @cindex Mercurial
183 @item
184 Mercurial (hg) is a distributed version control system broadly
185 resembling GNU Arch and git, with atomic fileset commits and file
186 moving/renaming. Like git, it is fully decentralized. VC supports
187 most Mercurial commands, with the exception of repository sync
188 operations; this needs to be done from the command line.
189
190 @cindex bzr
191 @cindex Bazaar
192 @item
193 Bazaar (bzr) is a distributed version control system that supports both
194 repository-based and distributed versioning, with atomic fileset
195 commits and file moving/renaming. VC supports most basic editing
196 operations under Bazaar.
197 @end itemize
198
199 Previous versions of VC supported a version control system known as
200 Meta-CVS. This support has been dropped because of limited interest
201 from users and developers.
202
203 @node VCS Concepts
204 @subsubsection Concepts of Version Control
205
206 @cindex repository
207 @cindex registered file
208 When a file is under version control, we say that it is
209 @dfn{registered} in the version control system. The system has a
210 @dfn{repository} which stores both the file's present state and its
211 change history---enough to reconstruct the current version or any
212 earlier version. The repository also contains other information, such
213 as @dfn{log entries} that describe the changes made to each file.
214
215 @cindex work file
216 @cindex checking out files
217 A file @dfn{checked out} of a repository is called the @dfn{work
218 file}. You edit the work file and make changes in it, as you would
219 with an ordinary file. After you are done with a set of changes, you
220 @dfn{check in} or @dfn{commit} the file; this records the changes in
221 the repository, along with a log entry for those changes.
222
223 @cindex revision
224 @cindex revision ID
225 A copy of a file stored in a repository is called a @dfn{revision}.
226 The history of a file is a sequence of revisions. Each revisions is
227 named by a @dfn{revision ID}. The format of the revision ID depends
228 on the version control system; in the simplest case, it is just an
229 integer.
230
231 To go beyond these basic concepts, you will need to understand three
232 aspects in which version control systems differ.
233 They can be locking-based or merging-based; they can be file-based or
234 changeset-based; and they can be centralized or decentralized. VC
235 handles all these modes of operation, but it cannot hide the differences.
236
237 @cindex locking versus merging
238 A version control system typically has some mechanism to coordinate
239 between users who want to change the same file. There are two ways to
240 do this: merging and locking.
241
242 In a version control system that uses merging, each user may check
243 out and modify a work file at any time. The system lets you
244 @dfn{merge} your work file, which may contain changes that have not
245 been checked in, with the latest changes that others have checked into
246 the repository.
247
248 Older version control systems use a @dfn{locking} scheme instead.
249 Here, work files are normally read-only. To edit a file, you ask the
250 version control system to make it writable for you by @dfn{locking}
251 it; only one user can lock a given file at any given time. This
252 procedure is analogous to, but different from, the locking that Emacs
253 uses to detect simultaneous editing of ordinary files
254 (@pxref{Interlocking}). When you check in your changes, that unlocks
255 the file, and the work file becomes read-only again. Other users may
256 then lock the file to make their own changes.
257
258 Both locking and merging systems can have problems when multiple
259 users try to modify the same file at the same time. Locking systems
260 have @dfn{lock conflicts}; a user may try to check a file out and be
261 unable to because it is locked. In merging systems, @dfn{merge
262 conflicts} happen when you check in a change to a file that conflicts
263 with a change checked in by someone else after your checkout. Both
264 kinds of conflict have to be resolved by human judgment and
265 communication. Experience has shown that merging is superior to
266 locking, both in convenience to developers and in minimizing the
267 number and severity of conflicts that actually occur.
268
269 SCCS always uses locking. RCS is lock-based by default but can be
270 told to operate in a merging style. CVS and Subversion are
271 merge-based by default but can be told to operate in a locking mode.
272 Distributed version control systems, such as GNU Arch, git, and
273 Mercurial, are exclusively merging-based.
274
275 VC mode supports both locking and merging version control. The
276 terms ``checkin'' and ``checkout'' come from locking-based version
277 control systems; newer version control systems have slightly different
278 operations usually called ``commit'' and ``update'', but VC hides the
279 differences between them as much as possible.
280
281 @cindex files versus changesets.
282 On SCCS, RCS, CVS, and other early version control systems, version
283 control operations are @dfn{file-based}: each file has its own comment
284 and revision history separate from that of all other files in the
285 system. Later systems, beginning with Subversion, are
286 @dfn{changeset-based}: a checkin may include changes to several files,
287 and the entire set of changes is treated as a unit by the system. Any
288 comment associated with the change does not belong to a single file,
289 but to the changeset itself.
290
291 Changeset-based version control is more flexible and powerful than
292 file-based version control; usually, when a change to multiple files
293 has to be reversed, it's good to be able to easily identify and remove
294 all of it.
295
296 @cindex centralized vs. decentralized version control
297 Early version control systems were designed around a
298 @dfn{centralized} model in which each project has only one repository
299 used by all developers. SCCS, RCS, CVS, and Subversion share this
300 kind of model. One of its drawbacks is that the repository is a choke
301 point for reliability and efficiency.
302
303 GNU Arch pioneered the concept of @dfn{decentralized} version
304 control, later implemented in git, Mercurial, and Bazaar. A project
305 may have several different repositories, and these systems support a
306 sort of super-merge between repositories that tries to reconcile their
307 change histories. At the limit, each developer has his/her own
308 repository, and repository merges replace checkin/commit operations.
309
310 VC's job is to help you manage the traffic between your personal
311 workfiles and a repository. Whether that repository is a single
312 master or one of a network of peer repositories is not something VC
313 has to care about. Thus, the difference between a centralized and a
314 decentralized version control system is invisible to VC mode.
315
316 @node Types of Log File
317 @subsubsection Types of Log File
318 @cindex types of log file
319 @cindex log File, types of
320 @cindex version control log
321
322 Projects that use a version control system can have two types of log
323 for changes. One is the log maintained by the version control system:
324 each time you check in a change, you fill out a @dfn{log entry} for
325 the change (@pxref{Log Buffer}). This is called the @dfn{version
326 control log}.
327
328 The other kind of log is the file @file{ChangeLog} (@pxref{Change
329 Log}). It provides a chronological record of all changes to a large
330 portion of a program---typically one directory and its subdirectories.
331 A small program would use one @file{ChangeLog} file; a large program
332 may have a @file{ChangeLog} file in each major directory.
333 @xref{Change Log}. Programmers have used change logs since long
334 before version control systems.
335
336 Changeset-based version systems typically maintain a changeset-based
337 modification log for the entire system, which makes change log files
338 somewhat redundant. One advantage that they retain is that it is
339 sometimes useful to be able to view the transaction history of a
340 single directory separately from those of other directories.
341
342 A project maintained with version control can use just the version
343 control log, or it can use both kinds of logs. It can handle some
344 files one way and some files the other way. Each project has its
345 policy, which you should follow.
346
347 When the policy is to use both, you typically want to write an entry
348 for each change just once, then put it into both logs. You can write
349 the entry in @file{ChangeLog}, then copy it to the log buffer with
350 @kbd{C-c C-a} when checking in the change (@pxref{Log Buffer}). Or
351 you can write the entry in the log buffer while checking in the
352 change, and later use the @kbd{C-x v a} command to copy it to
353 @file{ChangeLog}
354 @iftex
355 (@pxref{Change Logs and VC,,,emacs-xtra, Specialized Emacs Features}).
356 @end iftex
357 @ifnottex
358 (@pxref{Change Logs and VC}).
359 @end ifnottex
360
361 @node VC Mode Line
362 @subsection Version Control and the Mode Line
363
364 When you visit a file that is under version control, Emacs indicates
365 this on the mode line. For example, @samp{RCS-1.3} says that RCS is
366 used for that file, and the current version is 1.3.
367
368 The character between the back-end name and the revision ID
369 indicates the version control status of the file. @samp{-} means that
370 the work file is not locked (if locking is in use), or not modified (if
371 locking is not in use). @samp{:} indicates that the file is locked, or
372 that it is modified. If the file is locked by some other user (for
373 instance, @samp{jim}), that is displayed as @samp{RCS:jim:1.3}.
374
375 On a graphical display, you can move the mouse over this mode line
376 indicator to pop up a ``tool-tip'', which displays a more verbose
377 description of the version control status. Pressing @kbd{Mouse-1}
378 over the indicator pops up a menu of VC commands. This menu is
379 identical to the @samp{Tools / Version Control} menu item.
380
381 @vindex auto-revert-check-vc-info
382 When Auto Revert mode (@pxref{Reverting}) reverts a buffer that is
383 under version control, it updates the version control information in
384 the mode line. However, Auto Revert mode may not properly update this
385 information if the version control status changes without changes to
386 the work file, from outside the current Emacs session. If you set
387 @code{auto-revert-check-vc-info} to @code{t}, Auto Revert mode updates
388 the version control status information every
389 @code{auto-revert-interval} seconds, even if the work file itself is
390 unchanged. The resulting CPU usage depends on the version control
391 system, but is usually not excessive.
392
393 @node Basic VC Editing
394 @subsection Basic Editing under Version Control
395
396 @cindex filesets, VC
397 Most VC commands operate on @dfn{VC filesets}. A VC fileset is a
398 collection of one or more files that a VC operation acts on. When you
399 type VC commands in a buffer visiting a version-controlled file, the
400 VC fileset is simply that one file. When you type them in a VC
401 Directory buffer, and some files in it are marked, the VC fileset
402 consists of the marked files (@pxref{VC Directory Mode}).
403
404 The principal VC command is an all-purpose command, @kbd{C-x v v}
405 (@code{vc-next-action}), that performs either locking, merging or a
406 check-in (depending on the situation) on the current VC fileset. You
407 can use @kbd{C-x v v} in a file-visiting buffer or in a VC Directory
408 buffer.
409
410 @table @kbd
411 @itemx C-x v v
412 Perform the appropriate next version control operation on the VC fileset.
413 @end table
414
415 @findex vc-next-action
416 @kindex C-x v v
417 The precise action of @kbd{C-x v v} depends on the state of the VC
418 fileset, and whether the version control system uses locking or
419 merging. This is described in detail in the subsequent sections.
420
421 VC filesets are the way that VC mode bridges the gap between
422 file-based and changeset-based version control systems. They are,
423 essentially, a way to pass multiple file arguments as a group to
424 version control commands. For example, on Subversion, a checkin with
425 a multi-file VC fileset becomes a joint commit, as though you had
426 typed @command{svn commit} with those file arguments at the shell
427 command line. All files in a VC fileset must be under the same
428 version control system; if they are not, Emacs signals an error when
429 you attempt to execute a command on the fileset.
430
431 Support for VC filesets and changeset-based version control systems
432 is the main improvement to VC in Emacs 23. When you mark multi-file
433 VC in a VC Directory buffer, VC operations treat them as a VC fileset,
434 and operate on them all at once if the version control system is
435 changeset-based. @xref{VC Directory Mode}.
436
437 VC filesets are distinct from the ``named filesets'' used for
438 viewing and visiting files in functional groups (@pxref{Filesets}).
439 Unlike named filesets, VC filesets are not named and don't persist
440 across sessions.
441
442 @menu
443 * VC With A Merging VCS:: Without locking: default mode for CVS.
444 * VC With A Locking VCS:: RCS in its default mode, SCCS, and optionally CVS.
445 * Advanced C-x v v:: Advanced features available with a prefix argument.
446 * Log Buffer:: Features available in log entry buffers.
447 @end menu
448
449 @node VC With A Merging VCS
450 @subsubsection Basic Version Control with Merging
451
452 When your version control system is merging-based (the default for
453 CVS and all newer version control systems), work files are always
454 writable; you need not do anything special to begin editing a file.
455 The status indicator on the mode line is @samp{-} if the file is
456 unmodified; it flips to @samp{:} as soon as you save any changes
457 (@pxref{VC Mode Line}).
458
459 Here is what @kbd{C-x v v} does when using a merging-based system:
460
461 @itemize @bullet
462 @item
463 If the work file is the same as in the repository, it does nothing.
464
465 @item
466 If you have not changed the work file, but some other user has checked
467 in changes to the repository, @kbd{C-x v v} merges those changes into
468 the work file.
469
470 @item
471 If you have made modifications to the work file, @kbd{C-x v v}
472 attempts to check in your changes. To do this, Emacs first reads the
473 log entry for the new revision (@pxref{Log Buffer}). If some other
474 user has checked in changes to the repository since you last checked
475 it out, the checkin fails. In that case, type @kbd{C-x v v} again to
476 merge those changes into your own work file; this puts the work file
477 into a ``conflicted'' state. Type @kbd{C-x v v} to clear the
478 ``conflicted'' state; VC then regards the file as up-to-date and
479 modified, and you can try to check it in again.
480
481 To pick up any recent changes from the repository @emph{without}
482 trying to commit your own changes, type @kbd{C-x v m @key{RET}}.
483 @xref{Merging}.
484 @end itemize
485
486 These rules also apply when you use RCS in its ``non-locking'' mode,
487 except that changes will not be automatically merged from the
488 repository. Nothing informs you if another user has checked in
489 changes in the same file since you began editing it; when you check in
490 your revision, his changes are removed (however, they remain in the
491 repository and are thus not irrevocably lost). Therefore, you must
492 verify that the current revision is unchanged before checking in your
493 changes. In addition, locking is possible with RCS even in this mode:
494 @kbd{C-x v v} with an unmodified file locks the file, just as it does
495 with RCS in its normal locking mode (@pxref{VC With A Locking VCS}).
496
497 @node VC With A Locking VCS
498 @subsubsection Basic Version Control with Locking
499
500 Under a locking-based version control system (such as SCCS, and RCS
501 in its default mode), @kbd{C-x v v} does the following:
502
503 @itemize @bullet
504 @item
505 If the file is not locked, @kbd{C-x v v} locks it, and makes it
506 writable so that you can change it.
507
508 @item
509 If the file is locked by you, and contains changes, @kbd{C-x v v}
510 checks in the changes. In order to do this, it first reads the log
511 entry for the new revision. @xref{Log Buffer}.
512
513 @item
514 If the file is locked by you, but you have not changed it since you
515 locked it, @kbd{C-x v v} releases the lock and makes the file
516 read-only again.
517
518 @item
519 If the file is locked by some other user, @kbd{C-x v v} asks you whether
520 you want to ``steal the lock'' from that user. If you say yes, the file
521 becomes locked by you, but a message is sent to the person who had
522 formerly locked the file, to inform him of what has happened.
523 @end itemize
524
525 These rules also apply when you use CVS in locking mode, except
526 that there is no such thing as stealing a lock.
527
528 @node Advanced C-x v v
529 @subsubsection Advanced Control in @kbd{C-x v v}
530
531 @cindex revision ID to check in/out
532 When you give a prefix argument to @code{vc-next-action} (@kbd{C-u
533 C-x v v}), it still performs the next logical version control
534 operation, but accepts additional arguments to specify precisely how
535 to do the operation.
536
537 @itemize @bullet
538 @item
539 If the file is modified (or locked), you can specify the revision ID
540 to use for the new version that you check in. This is one way
541 to create a new branch (@pxref{Branches}).
542
543 @item
544 If the file is not modified (and unlocked), you can specify the
545 revision to select; this lets you start working from an older
546 revision, or on another branch. If you do not enter any revision,
547 that takes you to the highest (``head'') revision on the current
548 branch; therefore @kbd{C-u C-x v v @key{RET}} is a convenient way to
549 get the latest version of a file from the repository.
550
551 @item
552 @cindex specific version control system
553 Instead of the revision ID, you can also specify the name of a
554 version control system. This is useful when one file is being managed
555 with two version control systems at the same time
556 @iftex
557 (@pxref{Local Version Control,,,emacs-xtra, Specialized Emacs
558 Features}).
559 @end iftex
560 @ifnottex
561 (@pxref{Local Version Control}).
562 @end ifnottex
563
564 @end itemize
565
566 @node Log Buffer
567 @subsubsection Features of the Log Entry Buffer
568
569 When you check in changes, Emacs pops up a buffer called
570 @samp{*VC-Log*} for you to enter a log entry.
571
572 After you have finished editing the log message, type @kbd{C-c C-c}
573 to exit the buffer and commit the change.
574
575 @findex log-edit-show-files
576 @findex log-edit-show-diff
577 In the @samp{*VC-Log*} buffer, typing @kbd{C-c C-f}
578 (@code{log-edit-show-files}) displays a list of files in the VC
579 fileset you are committing. If you called @kbd{C-x v v} directly from
580 a work file, the VC fileset consists of that single file, so this
581 command is not very useful. If you called @kbd{C-x v v} from a VC
582 directory buffer, the VC fileset may consist of multiple files
583 (@pxref{VC Directory Mode}).
584
585 @findex log-edit-insert-changelog
586 Type @kbd{C-c C-d} (@code{log-edit-show-diff}) to show a ``diff'' of
587 the changes you have made (i.e., the differences between the work file
588 and the repository revision from which you started editing the file).
589 The diff is displayed in a special buffer in another window.
590 @xref{Comparing Files}.
591
592 If you have written an entry in the @file{ChangeLog} (@pxref{Change
593 Log}), type @kbd{C-c C-a} (@code{log-edit-insert-changelog}) to pull
594 it into the @samp{*VC-Log*} buffer. If the topmost item in the
595 @file{ChangeLog} was made under your user name on the current date,
596 this command searches that item for entries that match the file(s) to
597 be committed; if found, these entries are inserted.
598 @iftex
599 @xref{Change Logs and VC,,,emacs-xtra, Specialized Emacs Features},
600 @end iftex
601 @ifnottex
602 @xref{Change Logs and VC},
603 @end ifnottex
604 for the opposite way of working---generating ChangeLog entries from
605 the revision control log.
606
607 To abort a check-in, just @strong{don't} type @kbd{C-c C-c} in that
608 buffer. You can switch buffers and do other editing. As long as you
609 don't try to check in another file, the entry you were editing remains
610 in the @samp{*VC-Log*} buffer, and you can go back to that buffer at
611 any time to complete the check-in.
612
613 If you change several source files for the same reason, it is often
614 convenient to specify the same log entry for many of the files. (This
615 is the normal way to do things on a changeset-oriented system, where
616 comments are attached to changesets rather than the history of
617 individual files.) The most convenient way to do this is to mark all
618 the files in VC Directory Mode and check in from there; the log buffer
619 will carry the fileset information with it and do a group commit when
620 you type @kbd{C-c C-c}.
621
622 You can also browse the history of previous log entries to duplicate
623 a checkin comment. This can be useful when you want several files to
624 have checkin comments that vary only slightly from each other. The
625 commands @kbd{M-n}, @kbd{M-p}, @kbd{M-s} and @kbd{M-r} for doing this
626 work just like the minibuffer history commands (except that these
627 versions are used outside the minibuffer).
628
629 @vindex vc-log-mode-hook
630 Each time you check in a change, the log entry buffer is put into VC
631 Log Edit mode, which involves running two hooks: @code{text-mode-hook}
632 and @code{vc-log-mode-hook}. @xref{Hooks}.
633
634 @node Old Revisions
635 @subsection Examining And Comparing Old Revisions
636
637 One of the convenient features of version control is the ability
638 to examine any revision of a file, or compare two revisions.
639
640 @table @kbd
641 @item C-x v ~ @var{revision} @key{RET}
642 Examine revision @var{revision} of the visited file, in a buffer of its
643 own.
644
645 @item C-x v =
646 Compare the buffer contents associated with the current
647 fileset with the working revision(s) from which you started editing.
648
649 @item C-u C-x v = @key{RET} @var{oldvers} @key{RET} @var{newvers} @key{RET}
650 Compare the specified two repository revisions of the current fileset.
651
652 @item C-x v g
653 Display an annotated version of the file: for each line, show the
654 latest revision in which it was modified.
655 @end table
656
657 @findex vc-revision-other-window
658 @kindex C-x v ~
659 To examine an old revision, visit the work file and type @kbd{C-x v
660 ~ @var{revision} @key{RET}} (@code{vc-revision-other-window}). Here,
661 @var{revision} is either the desired revision ID (@pxref{VCS
662 Concepts}), or the name of a tag or branch
663 @iftex
664 (@pxref{Tags,,,emacs-xtra, Specialized Emacs Features}).
665 @end iftex
666 @ifnottex
667 (@pxref{Tags}).
668 @end ifnottex
669 This command puts the text of the old revision in a file named
670 @file{@var{filename}.~@var{revision}~}, and visits it in its own
671 buffer in a separate window.
672
673 @findex vc-diff
674 @kindex C-x v =
675 @kbd{C-x v =} (@code{vc-diff}) compares the current buffer contents
676 of each file in the current VC fileset (saving them if necessary) with
677 the repository revision from which you started editing. Note that the
678 latter may or may not be the latest revision of the file(s). The diff
679 is displayed in a special buffer in another window. @xref{Comparing
680 Files}.
681
682 @findex vc-diff
683 @kindex C-u C-x v =
684 To compare two arbitrary revisions of the current VC fileset, call
685 @code{vc-diff} with a prefix argument: @kbd{C-u C-x v =}. This
686 prompts for two revision IDs, using the minibuffer, and displays the
687 diff in a special buffer in another window. Instead of providing a
688 revision ID, you can give an empty input, which specifies the current
689 contents of the work file; or a tag or branch name
690 @iftex
691 (@pxref{Tags,,,emacs-xtra, Specialized Emacs Features}).
692 @end iftex
693 @ifnottex
694 (@pxref{Tags}).
695 @end ifnottex
696 If your version control system is file-based (e.g. CVS) rather than
697 changeset-based (Subversion, GNU Arch, git, Mercurial), supplying a
698 revision ID for a multi-file fileset (as opposed to a symbolic tag
699 name) is unlikely to return diffs that are connected in any meaningful
700 way.
701
702 If you invoke @kbd{C-x v =} or @kbd{C-u C-x v =} from a buffer that
703 is neither visiting a version-controlled file nor a VC directory
704 buffer, these commands generate a diff of all registered files in the
705 current directory and its subdirectories.
706
707 @vindex vc-diff-switches
708 @vindex vc-rcs-diff-switches
709 @kbd{C-x v =} works by running a variant of the @code{diff} utility
710 designed to work with the version control system in use. When you
711 invoke @code{diff} this way, in addition to the options specified by
712 @code{diff-switches} (@pxref{Comparing Files}), it receives those
713 specified by @code{vc-diff-switches}, plus those specified for the
714 specific back end by @code{vc-@var{backend}-diff-switches}. For
715 instance, when the version control back end is CVS, @code{diff} uses
716 the options in @code{vc-cvs-diff-switches}. The
717 @samp{vc@dots{}diff-switches} variables are @code{nil} by default.
718
719 The buffer produced by @kbd{C-x v =} supports the commands of
720 Compilation mode (@pxref{Compilation Mode}), such as @kbd{C-x `} and
721 @kbd{C-c C-c}, in both the ``old'' and ``new'' text, and they always
722 find the corresponding locations in the current work file. (Older
723 revisions are not, in general, present as files on your disk.)
724
725 @findex vc-annotate
726 @kindex C-x v g
727 For some back ends, you can display the file @dfn{annotated} with
728 per-line revision information, by typing @kbd{C-x v g}
729 (@code{vc-annotate}). This creates a new buffer (the ``annotate
730 buffer'') displaying the file's text, with each part colored to show
731 how old it is. Text colored red is new, blue means old, and
732 intermediate colors indicate intermediate ages. By default, the color
733 is scaled over the full range of ages, such that the oldest changes
734 are blue, and the newest changes are red.
735
736 When you give a prefix argument to this command, Emacs reads two
737 arguments using the minibuffer: the ID of which revision to display and
738 annotate (instead of the current file contents), and the time span in
739 days the color range should cover.
740
741 From the annotate buffer, these and other color scaling options are
742 available from the @samp{VC-Annotate} menu. In this buffer, you can
743 also use the following keys to browse the annotations of past revisions,
744 view diffs, or view log entries:
745
746 @table @kbd
747 @item p
748 Annotate the previous revision, that is to say, the revision before
749 the one currently annotated. A numeric prefix argument is a repeat
750 count, so @kbd{C-u 10 p} would take you back 10 revisions.
751
752 @item n
753 Annotate the next revision---the one after the revision currently
754 annotated. A numeric prefix argument is a repeat count.
755
756 @item j
757 Annotate the revision indicated by the current line.
758
759 @item a
760 Annotate the revision before the one indicated by the current line.
761 This is useful to see the state the file was in before the change on
762 the current line was made.
763
764 @item f
765 Show in a buffer the file revision indicated by the current line.
766
767 @item d
768 Display the diff between the current line's revision and the previous
769 revision. This is useful to see what the current line's revision
770 actually changed in the file.
771
772 @item D
773 Display the diff between the current line's revision and the previous
774 revision for all files in the changeset (for VC systems that support
775 changesets). This is useful to see what the current line's revision
776 actually changed in the tree.
777
778 @item l
779 Show the log of the current line's revision. This is useful to see
780 the author's description of the changes in the revision on the current
781 line.
782
783 @item w
784 Annotate the working revision--the one you are editing. If you used
785 @kbd{p} and @kbd{n} to browse to other revisions, use this key to
786 return to your working revision.
787
788 @item v
789 Toggle the annotation visibility. This is useful for looking just at
790 the file contents without distraction from the annotations.
791 @end table
792
793 @node Secondary VC Commands
794 @subsection The Secondary Commands of VC
795
796 This section explains the secondary commands of VC.
797
798 @menu
799 * Registering:: Putting a file under version control.
800 * VC Status:: Viewing the VC status of files.
801 * VC Undo:: Canceling changes before or after check-in.
802 @end menu
803
804 @node Registering
805 @subsubsection Registering a File for Version Control
806
807 @kindex C-x v i
808 @findex vc-register
809 You can put any file under version control by simply visiting it, and
810 then typing @w{@kbd{C-x v i}} (@code{vc-register}).
811
812 @table @kbd
813 @item C-x v i
814 Register the visited file for version control.
815 @end table
816
817 To register the file, Emacs must choose which version control system
818 to use for it. If the file's directory already contains files
819 registered in a version control system, Emacs uses that system. If
820 there is more than one system in use for a directory, Emacs uses the
821 one that appears first in @code{vc-handled-backends}
822 @iftex
823 (@pxref{Customizing VC,,,emacs-xtra, Specialized Emacs Features}).
824 @end iftex
825 @ifnottex
826 (@pxref{Customizing VC}).
827 @end ifnottex
828 On the other hand, if there are no files already registered, Emacs uses
829 the first system from @code{vc-handled-backends} that could register
830 the file (for example, you cannot register a file under CVS if its
831 directory is not already part of a CVS tree); with the default value
832 of @code{vc-handled-backends}, this means that Emacs uses RCS in this
833 situation.
834
835 If locking is in use, @kbd{C-x v i} leaves the file unlocked and
836 read-only. Type @kbd{C-x v v} if you wish to start editing it. After
837 registering a file with CVS, you must subsequently commit the initial
838 revision by typing @kbd{C-x v v}. Until you do that, the revision ID
839 appears as @samp{@@@@} in the mode line.
840
841 @vindex vc-default-init-revision
842 @cindex initial revision ID to register
843 The default initial revision ID for a newly registered file
844 varies by what VCS you are using; normally it will be 1.1 on VCSes
845 that use dot-pair revision IDs and 1 on VCSes that use monotonic IDs.
846 You can specify a different default by setting the variable
847 @code{vc-default-init-revision}, or you can give @kbd{C-x v i} a
848 numeric argument; then it reads the initial revision ID for this
849 particular file using the minibuffer.
850
851 @vindex vc-initial-comment
852 If @code{vc-initial-comment} is non-@code{nil}, @kbd{C-x v i} reads an
853 initial comment to describe the purpose of this source file. Reading
854 the initial comment works like reading a log entry (@pxref{Log Buffer}).
855
856 @node VC Status
857 @subsubsection VC Status Commands
858
859 @table @kbd
860 @item C-x v l
861 Display revision control state and change history.
862 @end table
863
864 @kindex C-x v l
865 @findex vc-print-log
866 To view the detailed revision control status and history of a file,
867 type @kbd{C-x v l} (@code{vc-print-log}). This pops up a special
868 buffer named @samp{*vc-change-log*}, in a new window, that displays
869 the history of changes to the current file, including the text of the
870 log entries. The point is centered at the revision of the file that
871 is currently being visited.
872
873 In the @samp{*vc-change-log*} buffer, you can use the following keys
874 to move between the logs of revisions and of files, to view past
875 revisions, to modify change comments, to view annotations and to view
876 diffs:
877
878 @table @kbd
879 @item p
880 Move to the previous revision-item in the buffer. (Revision entries in the log
881 buffer are usually in reverse-chronological order, so the previous
882 revision-item usually corresponds to a newer revision.) A numeric
883 prefix argument is a repeat count.
884
885 @item n
886 Move to the next revision-item (which most often corresponds to the
887 previous revision of the file). A numeric prefix argument is a repeat
888 count.
889
890 @item P
891 Move to the log of the previous file, when the logs of multiple files
892 are in the log buffer (@pxref{VC Directory Mode}). Otherwise, just
893 move to the beginning of the log. A numeric prefix argument is a
894 repeat count, so @kbd{C-u 10 P} would move backward 10 files.
895
896 @item N
897 Move to the log of the next file, when the logs of multiple files are
898 in the log buffer (@pxref{VC Directory Mode}). It also takes a
899 numeric prefix argument as a repeat count.
900
901 @item a
902 Annotate the revision indicated by the current line.
903
904 @item e
905 Modify the change comment displayed at point. Note that not all VC
906 systems support modifying change comments.
907
908 @item f
909 Visit the revision indicated at the current line, like typing @kbd{C-x
910 v ~} and specifying this revision's ID (@pxref{Old Revisions}).
911
912 @item d
913 Display the diff (@pxref{Comparing Files}) between the revision
914 indicated at the current line and the next earlier revision. This is
915 useful to see what actually changed in the file when the revision
916 indicated on the current line was committed.
917
918 @item D
919 Display the changeset diff (@pxref{Comparing Files}) between the
920 revision indicated at the current line and the next earlier revision.
921 This is useful to see all the changes to all files that the revision
922 indicated on the current line did when it was committed.
923 @end table
924
925 @node VC Undo
926 @subsubsection Undoing Version Control Actions
927
928 @table @kbd
929 @item C-x v u
930 Revert the buffer and the file to the working revision from which you started
931 editing the file.
932
933 @item C-x v c
934 Remove the last-entered change from the master for the visited file.
935 This undoes your last check-in.
936 @end table
937
938 @kindex C-x v u
939 @findex vc-revert-buffer
940 If you want to discard your current set of changes and revert to the
941 working revision from which you started editing the file, use @kbd{C-x
942 v u} (@code{vc-revert-buffer}). If the version control system is
943 locking-based, this leaves the file unlocked, and you must lock it
944 again before making new changes. @kbd{C-x v u} requires confirmation,
945 unless it sees that you haven't made any changes with respect to the
946 master copy of the working revision.
947
948 @kbd{C-x v u} is also the command to unlock a file if you lock it and
949 then decide not to change it.
950
951 @kindex C-x v c
952 @findex vc-rollback
953 To cancel a change that you already checked in, use @kbd{C-x v c}
954 (@code{vc-rollback}). This command discards all record of the most
955 recent checked-in revision, but only if your work file corresponds to
956 that revision---you cannot use @kbd{C-x v c} to cancel a revision that
957 is not the latest on its branch. Note that many version control
958 systems do not support rollback at all; this command is something of a
959 historical relic.
960
961 @node VC Directory Mode
962 @subsection VC Directory Mode
963
964 @kindex C-x v d
965 @findex vc-dir
966 When you are working on a large program, it is often useful to find
967 out which files have changed within an entire directory tree, or to
968 view the status of all files under version control at once, and to
969 perform version control operations on collections of files. You can
970 use the command @kbd{C-x v d} (@code{vc-dir}) to make a directory
971 listing that includes only files relevant for version control. This
972 creates a @dfn{VC Directory buffer} and displays it in a separate
973 window.
974
975 @cindex PCL-CVS
976 @pindex cvs
977 @cindex CVS directory mode
978 The VC Directory buffer works with all the version control systems
979 that VC supports. For CVS, Emacs also offers a more powerful facility
980 called PCL-CVS. @xref{Top, , About PCL-CVS, pcl-cvs, PCL-CVS --- The
981 Emacs Front-End to CVS}.
982
983 @menu
984 * Buffer: VC Directory Buffer. What the buffer looks like and means.
985 * Commands: VC Directory Commands. Commands to use in a VC directory buffer.
986 @end menu
987
988 @node VC Directory Buffer
989 @subsubsection The VC Directory Buffer
990
991 The VC Directory buffer contains a list of version-controlled files
992 in the current directory and its subdirectories. Files which are
993 up-to-date (have no local differences from the repository copy) are
994 usually hidden; if all files in a subdirectory are up-to-date, the
995 subdirectory is hidden as well. There is an exception to this rule:
996 if VC mode detects that a file has changed to an up-to-date state
997 since you last looked at it, that file and its state are shown.
998
999 If a directory uses more that one version control system, you can
1000 select which system to use for the @code{vc-dir} command by invoking
1001 @code{vc-dir} with a prefix argument: @kbd{C-u C-x v d}.
1002
1003 The line for an individual file shows the version control state of
1004 the file. Under RCS and SCCS, the name of the user locking the file
1005 is shown; under CVS, an abbreviated version of the @samp{cvs status}
1006 output is used. Here is an example using CVS:
1007
1008 @smallexample
1009 @group
1010 ./
1011 modified file1.c
1012 needs-update file2.c
1013 needs-merge file3.c
1014 @end group
1015 @end smallexample
1016
1017 @noindent
1018 In this example, @samp{file1.c} is modified with respect to the
1019 repository, and @samp{file2.c} is not. @samp{file3.c} is modified,
1020 but other changes have also been checked in to the repository---you
1021 need to merge them with the work file before you can check it in.
1022
1023 @vindex vc-stay-local
1024 @vindex vc-cvs-stay-local
1025 In the above, if the repository were on a remote machine, VC only
1026 contacts it when the variable @code{vc-stay-local} (or
1027 @code{vc-cvs-stay-local}) is @code{nil} (@pxref{CVS Options}). This is
1028 because access to the repository may be slow, or you may be working
1029 offline and not have access to the repository at all. As a
1030 consequence, VC would not be able to tell you that @samp{file3.c} is
1031 in the ``merge'' state; you would learn that only when you try to
1032 check-in your modified copy of the file, or use a command such as
1033 @kbd{C-x v m}.
1034
1035 In practice, this is not a problem because CVS handles this case
1036 consistently whenever it arises. In VC, you'll simply get prompted to
1037 merge the remote changes into your work file first. The benefits of
1038 less network communication usually outweigh the disadvantage of not
1039 seeing remote changes immediately.
1040
1041 @vindex vc-directory-exclusion-list
1042 When a VC directory displays subdirectories it omits some that
1043 should never contain any files under version control. By default,
1044 this includes Version Control subdirectories such as @samp{RCS} and
1045 @samp{CVS}; you can customize this by setting the variable
1046 @code{vc-directory-exclusion-list}.
1047
1048 @node VC Directory Commands
1049 @subsubsection VC Directory Commands
1050
1051 VC Directory mode has a full set of navigation and marking commands
1052 for picking out filesets. Some of these are also available in a
1053 context menu invoked by the @kbd{mouse-2} button.
1054
1055 Up- and down-arrow keys move in the buffer; @kbd{n} and @kbd{p} also
1056 move vertically as in other list-browsing modes. @key{SPC} and
1057 @key{TAB} behave like down-arrow, and @key{BackTab} behaves like
1058 up-arrow.
1059
1060 Both @kbd{C-m} and @kbd{f} visit the file on the current
1061 line. @kbd{o} visits that file in another window. @kbd{q} dismisses
1062 the directory buffer.
1063
1064 @kbd{x} toggles hiding of up-to-date files.
1065
1066 @kbd{m} marks the file or directory on the current line. If the
1067 region is active, @kbd{m} marks all the files in the region. There
1068 are some restrictions when marking: a file cannot be marked if any of
1069 its parent directories are marked, and a directory cannot be marked if
1070 any files in it or in its child directories are marked.
1071
1072 @kbd{M} marks all the files with the same VC state as the current
1073 file if the cursor is on a file. If the cursor is on a directory, it
1074 marks all child files. With a prefix argument: marks all files and
1075 directories.
1076
1077 @kbd{u} unmarks the file or directory on the current line. If the
1078 region is active, it unmarks all the files in the region.
1079
1080 @kbd{U} marks all the files with the same VC state as the current file
1081 if the cursor is on a file. If the cursor is on a directory, it
1082 unmarks all child files. With a prefix argument: unmarks all marked
1083 files and directories.
1084
1085 It is possible to do search, search and replace, incremental search,
1086 and incremental regexp search on multiple files. These commands will
1087 work on all the marked files or the current file if nothing is marked.
1088 If a directory is marked, the files in that directory shown in the VC
1089 directory buffer will be used.
1090
1091 @kbd{S} searches the marked files.
1092
1093 @kbd{Q} does a query replace on the marked files.
1094
1095 @kbd{M-s a C-s} does an incremental search on the marked files.
1096
1097 @kbd{M-s a C-M-s} does an incremental search on the marked files.
1098
1099 Commands are also accessible from the VC-dir menu. Note that some VC
1100 backends use the VC-dir menu to make available extra backend specific
1101 commands.
1102
1103 Normal VC commands with the @kbd{C-x v} prefix work in VC directory
1104 buffers. Some single-key shortcuts are available as well; @kbd{=},
1105 @kbd{+}, @kbd{l}, @kbd{i}, and @kbd{v} behave as through prefixed with
1106 @kbd{C-x v}.
1107
1108 The command @kbd{C-x v v} (@code{vc-next-action}) operates on all the
1109 marked files, so that you can check in several files at once.
1110 If the underlying VC supports atomic commits of multiple-file
1111 changesets, @kbd{C-x v v} with a selected set of modified but not
1112 committed files will commit all of them at once as a single changeset.
1113
1114 When @kbd{C-x v v} (@code{vc-next-action}) operates on multiple
1115 files, all of those files must be either in the same state or in
1116 compatible states (added, modified and removed states are considered
1117 compatible). Otherwise it signals an error. This differs from the
1118 behavior of older versions of VC, which did not have fileset
1119 operations and simply did @code{vc-next-action} on each file
1120 individually.
1121
1122 If any files are in a state that calls for commit, @kbd{C-x v v} reads a
1123 single log entry and uses it for the changeset as a whole. If the
1124 underling VCS is file- rather than changeset-oriented, the log entry
1125 will be replicated into the history of each file.
1126
1127 @node Branches
1128 @subsection Multiple Branches of a File
1129 @cindex branch (version control)
1130 @cindex trunk (version control)
1131
1132 One use of version control is to maintain multiple ``current''
1133 revisions of a file. For example, you might have different revisions of a
1134 program in which you are gradually adding various unfinished new
1135 features. Each such independent line of development is called a
1136 @dfn{branch}. VC allows you to create branches, switch between
1137 different branches, and merge changes from one branch to another.
1138 Please note, however, that branches are not supported for SCCS.
1139
1140 A file's main line of development is usually called the @dfn{trunk}.
1141 You can create multiple branches from the trunk. How the difference
1142 between trunk and branch is made visible is dependent on whether the
1143 VCS uses dot-pair or monotonic version IDs.
1144
1145 In VCSes with dot-pair revision IDs, the revisions on the trunk are
1146 normally IDed 1.1, 1.2, 1.3, etc. At any such revision, you can
1147 start an independent branch. A branch starting at revision 1.2 would
1148 have revision ID 1.2.1.1, and consecutive revisions on this branch
1149 would have IDs 1.2.1.2, 1.2.1.3, 1.2.1.4, and so on. If there is
1150 a second branch also starting at revision 1.2, it would consist of
1151 revisions 1.2.2.1, 1.2.2.2, 1.2.2.3, etc.
1152
1153 In VCSes with monotonic revision IDs, trunk revisions are IDed as
1154 1, 2, 3, etc. A branch from (say) revision 2 might start with 2.1 and
1155 continue through 2.2, 2.3, etc. But naming conventions for branches
1156 and subbranches vary widely on these systems, and some (like
1157 Mercurial) never depart from the monotonic integer sequence at all.
1158 Consult the documentation of the VCS you are using.
1159
1160 @cindex head revision
1161 If you omit the final component of a dot-pair revision ID, that is called a
1162 @dfn{branch ID}. It refers to the highest existing revision on that
1163 branch---the @dfn{head revision} of that branch. The branches in the
1164 dot-pair example above have branch IDs 1.2.1 and 1.2.2.
1165
1166 @menu
1167 * Switching Branches:: How to get to another existing branch.
1168 * Creating Branches:: How to start a new branch.
1169 * Merging:: Transferring changes between branches.
1170 * Multi-User Branching:: Multiple users working at multiple branches
1171 in parallel.
1172 @end menu
1173
1174 @node Switching Branches
1175 @subsubsection Switching between Branches
1176
1177 To switch between branches, type @kbd{C-u C-x v v} and specify the
1178 revision ID you want to select. On a locking-based system, this
1179 version is then visited @emph{unlocked} (write-protected), so you can
1180 examine it before locking it. Switching branches in this way is allowed
1181 only when the file is not locked.
1182
1183 On a VCS with dot-pair IDs, you can omit the minor part, thus giving
1184 only the branch ID; this takes you to the head version on the
1185 chosen branch. If you only type @key{RET}, Emacs goes to the highest
1186 version on the trunk.
1187
1188 After you have switched to any branch (including the main branch), you
1189 stay on it for subsequent VC commands, until you explicitly select some
1190 other branch.
1191
1192 @node Creating Branches
1193 @subsubsection Creating New Branches
1194
1195 To create a new branch from a head revision (one that is the latest in
1196 the branch that contains it), first select that revision if necessary,
1197 lock it with @kbd{C-x v v}, and make whatever changes you want. Then,
1198 when you check in the changes, use @kbd{C-u C-x v v}. This lets you
1199 specify the revision ID for the new revision. You should specify a
1200 suitable branch ID for a branch starting at the current revision.
1201 For example, if the current revision is 2.5, the branch ID should be
1202 2.5.1, 2.5.2, and so on, depending on the number of existing branches at
1203 that point.
1204
1205 To create a new branch at an older revision (one that is no longer the
1206 head of a branch), first select that revision (@pxref{Switching
1207 Branches}). Your procedure will then differ depending on whether you
1208 are using a locking or merging-based VCS.
1209
1210 On a locking VCS, you will need to lock the old revision branch with
1211 @kbd{C-x v v}. You'll be asked to confirm, when you lock the old
1212 revision, that you really mean to create a new branch---if you say no,
1213 you'll be offered a chance to lock the latest revision instead. On
1214 a merging-based VCS you will skip this step.
1215
1216 Then make your changes and type @kbd{C-x v v} again to check in a new
1217 revision. This automatically creates a new branch starting from the
1218 selected revision. You need not specially request a new branch, because
1219 that's the only way to add a new revision at a point that is not the head
1220 of a branch.
1221
1222 After the branch is created, you ``stay'' on it. That means that
1223 subsequent check-ins create new revisions on that branch. To leave the
1224 branch, you must explicitly select a different revision with @kbd{C-u C-x
1225 v v}. To transfer changes from one branch to another, use the merge
1226 command, described in the next section.
1227
1228 @node Merging
1229 @subsubsection Merging Branches
1230
1231 @cindex merging changes
1232 When you have finished the changes on a certain branch, you will
1233 often want to incorporate them into the file's main line of development
1234 (the trunk). This is not a trivial operation, because development might
1235 also have proceeded on the trunk, so that you must @dfn{merge} the
1236 changes into a file that has already been changed otherwise. VC allows
1237 you to do this (and other things) with the @code{vc-merge} command.
1238
1239 @table @kbd
1240 @item C-x v m (vc-merge)
1241 Merge changes into the work file.
1242 @end table
1243
1244 @kindex C-x v m
1245 @findex vc-merge
1246 @kbd{C-x v m} (@code{vc-merge}) takes a set of changes and merges it
1247 into the current version of the work file. It firsts asks you in the
1248 minibuffer where the changes should come from. If you just type
1249 @key{RET}, Emacs merges any changes that were made on the same branch
1250 since you checked the file out (we call this @dfn{merging the news}).
1251 This is the common way to pick up recent changes from the repository,
1252 regardless of whether you have already changed the file yourself.
1253
1254 You can also enter a branch ID or a pair of revision IDs in
1255 the minibuffer. Then @kbd{C-x v m} finds the changes from that
1256 branch, or the differences between the two revisions you specified, and
1257 merges them into the current revision of the current file.
1258
1259 As an example, suppose that you have finished a certain feature on
1260 branch 1.3.1. In the meantime, development on the trunk has proceeded
1261 to revision 1.5. To merge the changes from the branch to the trunk,
1262 first go to the head revision of the trunk, by typing @kbd{C-u C-x v v
1263 @key{RET}}. Revision 1.5 is now current. If locking is used for the file,
1264 type @kbd{C-x v v} to lock revision 1.5 so that you can change it. Next,
1265 type @kbd{C-x v m 1.3.1 @key{RET}}. This takes the entire set of changes on
1266 branch 1.3.1 (relative to revision 1.3, where the branch started, up to
1267 the last revision on the branch) and merges it into the current revision
1268 of the work file. You can now check in the changed file, thus creating
1269 revision 1.6 containing the changes from the branch.
1270
1271 It is possible to do further editing after merging the branch, before
1272 the next check-in. But it is usually wiser to check in the merged
1273 revision, then lock it and make the further changes. This will keep
1274 a better record of the history of changes.
1275
1276 @cindex conflicts
1277 @cindex resolving conflicts
1278 When you merge changes into a file that has itself been modified, the
1279 changes might overlap. We call this situation a @dfn{conflict}, and
1280 reconciling the conflicting changes is called @dfn{resolving a
1281 conflict}.
1282
1283 Whenever conflicts occur during merging, VC detects them, tells you
1284 about them in the echo area, and asks whether you want help in merging.
1285 If you say yes, it starts an Ediff session (@pxref{Top,
1286 Ediff, Ediff, ediff, The Ediff Manual}).
1287
1288 If you say no, the conflicting changes are both inserted into the
1289 file, surrounded by @dfn{conflict markers}. The example below shows how
1290 a conflict region looks; the file is called @samp{name} and the current
1291 master file revision with user B's changes in it is 1.11.
1292
1293 @c @w here is so CVS won't think this is a conflict.
1294 @smallexample
1295 @group
1296 @w{<}<<<<<< name
1297 @var{User A's version}
1298 =======
1299 @var{User B's version}
1300 @w{>}>>>>>> 1.11
1301 @end group
1302 @end smallexample
1303
1304 @cindex vc-resolve-conflicts
1305 Then you can resolve the conflicts by editing the file manually. Or
1306 you can type @code{M-x vc-resolve-conflicts} after visiting the file.
1307 This starts an Ediff session, as described above. Don't forget to
1308 check in the merged version afterwards.
1309
1310 @node Multi-User Branching
1311 @subsubsection Multi-User Branching
1312
1313 It is often useful for multiple developers to work simultaneously on
1314 different branches of a file. CVS and later systems allow this by
1315 default; for RCS, it is possible if you create multiple source
1316 directories. Each source directory should have a link named
1317 @file{RCS} which points to a common directory of RCS master files.
1318 Then each source directory can have its own choice of selected
1319 revisions, but all share the same common RCS records.
1320
1321 This technique works reliably and automatically, provided that the
1322 source files contain RCS version headers
1323 @iftex
1324 (@pxref{Version Headers,,,emacs-xtra, Specialized Emacs Features}).
1325 @end iftex
1326 @ifnottex
1327 (@pxref{Version Headers}).
1328 @end ifnottex
1329 The headers enable Emacs to be sure, at all times, which revision
1330 ID is present in the work file.
1331
1332 If the files do not have version headers, you must instead tell Emacs
1333 explicitly in each session which branch you are working on. To do this,
1334 first find the file, then type @kbd{C-u C-x v v} and specify the correct
1335 branch ID. This ensures that Emacs knows which branch it is using
1336 during this particular editing session.
1337
1338 @ifnottex
1339 @include vc1-xtra.texi
1340 @end ifnottex
1341
1342 @node Change Log
1343 @section Change Logs
1344
1345 @cindex change log
1346 A change log file contains a chronological record of when and why you
1347 have changed a program, consisting of a sequence of entries describing
1348 individual changes. Normally it is kept in a file called
1349 @file{ChangeLog} in the same directory as the file you are editing, or
1350 one of its parent directories. A single @file{ChangeLog} file can
1351 record changes for all the files in its directory and all its
1352 subdirectories.
1353
1354 @menu
1355 * Change Log Commands:: Commands for editing change log files.
1356 * Format of ChangeLog:: What the change log file looks like.
1357 @end menu
1358
1359 @node Change Log Commands
1360 @subsection Change Log Commands
1361
1362 @kindex C-x 4 a
1363 @findex add-change-log-entry-other-window
1364 The Emacs command @kbd{C-x 4 a} adds a new entry to the change log
1365 file for the file you are editing
1366 (@code{add-change-log-entry-other-window}). If that file is actually
1367 a backup file, it makes an entry appropriate for the file's
1368 parent---that is useful for making log entries for functions that
1369 have been deleted in the current version.
1370
1371 @kbd{C-x 4 a} visits the change log file and creates a new entry
1372 unless the most recent entry is for today's date and your name. It
1373 also creates a new item for the current file. For many languages, it
1374 can even guess the name of the function or other object that was
1375 changed.
1376
1377 @vindex add-log-keep-changes-together
1378 When the variable @code{add-log-keep-changes-together} is
1379 non-@code{nil}, @kbd{C-x 4 a} adds to any existing item for the file
1380 rather than starting a new item.
1381
1382 @vindex add-log-always-start-new-record
1383 If @code{add-log-always-start-new-record} is non-@code{nil},
1384 @kbd{C-x 4 a} always makes a new entry, even if the last entry
1385 was made by you and on the same date.
1386
1387 @vindex change-log-version-info-enabled
1388 @vindex change-log-version-number-regexp-list
1389 @cindex file version in change log entries
1390 If the value of the variable @code{change-log-version-info-enabled}
1391 is non-@code{nil}, @kbd{C-x 4 a} adds the file's version number to the
1392 change log entry. It finds the version number by searching the first
1393 ten percent of the file, using regular expressions from the variable
1394 @code{change-log-version-number-regexp-list}.
1395
1396 @cindex Change Log mode
1397 @findex change-log-mode
1398 The change log file is visited in Change Log mode. In this major
1399 mode, each bunch of grouped items counts as one paragraph, and each
1400 entry is considered a page. This facilitates editing the entries.
1401 @kbd{C-j} and auto-fill indent each new line like the previous line;
1402 this is convenient for entering the contents of an entry.
1403
1404 You can use the @code{next-error} command (by default bound to
1405 @kbd{C-x `}) to move between entries in the Change Log, when Change
1406 Log mode is on. You will jump to the actual site in the file that was
1407 changed, not just to the next Change Log entry. You can also use
1408 @code{previous-error} to move back in the same list.
1409
1410 @findex change-log-merge
1411 You can use the command @kbd{M-x change-log-merge} to merge other
1412 log files into a buffer in Change Log Mode, preserving the date
1413 ordering of entries.
1414
1415 Version control systems are another way to keep track of changes in
1416 your program and keep a change log. In the VC log buffer, typing
1417 @kbd{C-c C-a} (@code{log-edit-insert-changelog}) inserts the relevant
1418 Change Log entry, if one exists (@pxref{Log Buffer}). You can also
1419 insert a VC log entry into a Change Log buffer by typing @kbd{C-x v a}
1420 (@code{vc-update-change-log}) in the Change Log buffer
1421 @iftex
1422 (@pxref{Change Logs and VC,,,emacs-xtra, Specialized Emacs Features}).
1423 @end iftex
1424 @ifnottex
1425 (@pxref{Change Logs and VC}).
1426 @end ifnottex
1427
1428 @node Format of ChangeLog
1429 @subsection Format of ChangeLog
1430
1431 A change log entry starts with a header line that contains the current
1432 date, your name, and your email address (taken from the variable
1433 @code{add-log-mailing-address}). Aside from these header lines, every
1434 line in the change log starts with a space or a tab. The bulk of the
1435 entry consists of @dfn{items}, each of which starts with a line starting
1436 with whitespace and a star. Here are two entries, both dated in May
1437 1993, with two items and one item respectively.
1438
1439 @iftex
1440 @medbreak
1441 @end iftex
1442 @smallexample
1443 1993-05-25 Richard Stallman <rms@@gnu.org>
1444
1445 * man.el: Rename symbols `man-*' to `Man-*'.
1446 (manual-entry): Make prompt string clearer.
1447
1448 * simple.el (blink-matching-paren-distance):
1449 Change default to 12,000.
1450
1451 1993-05-24 Richard Stallman <rms@@gnu.org>
1452
1453 * vc.el (minor-mode-map-alist): Don't use it if it's void.
1454 (vc-cancel-version): Doc fix.
1455 @end smallexample
1456
1457 One entry can describe several changes; each change should have its
1458 own item, or its own line in an item. Normally there should be a
1459 blank line between items. When items are related (parts of the same
1460 change, in different places), group them by leaving no blank line
1461 between them.
1462
1463 You should put a copyright notice and permission notice at the
1464 end of the change log file. Here is an example:
1465
1466 @smallexample
1467 Copyright 1997, 1998 Free Software Foundation, Inc.
1468 Copying and distribution of this file, with or without modification, are
1469 permitted provided the copyright notice and this notice are preserved.
1470 @end smallexample
1471
1472 @noindent
1473 Of course, you should substitute the proper years and copyright holder.
1474
1475 @node Tags
1476 @section Tags Tables
1477 @cindex tags and tag tables
1478
1479 A @dfn{tags table} is a description of how a multi-file program is
1480 broken up into files. It lists the names of the component files and the
1481 names and positions of the functions (or other named subunits) in each
1482 file. Grouping the related files makes it possible to search or replace
1483 through all the files with one command. Recording the function names
1484 and positions makes possible the @kbd{M-.} command which finds the
1485 definition of a function by looking up which of the files it is in.
1486
1487 Tags tables are stored in files called @dfn{tags table files}. The
1488 conventional name for a tags table file is @file{TAGS}.
1489
1490 Each entry in the tags table records the name of one tag, the name of the
1491 file that the tag is defined in (implicitly), and the position in that
1492 file of the tag's definition. When a file parsed by @code{etags} is
1493 generated from a different source file, like a C file generated from a
1494 Cweb source file, the tags of the parsed file reference the source
1495 file.
1496
1497 Just what names from the described files are recorded in the tags table
1498 depends on the programming language of the described file. They
1499 normally include all file names, functions and subroutines, and may
1500 also include global variables, data types, and anything else
1501 convenient. Each name recorded is called a @dfn{tag}.
1502
1503 @cindex C++ class browser, tags
1504 @cindex tags, C++
1505 @cindex class browser, C++
1506 @cindex Ebrowse
1507 See also the Ebrowse facility, which is tailored for C++.
1508 @xref{Top,, Ebrowse, ebrowse, Ebrowse User's Manual}.
1509
1510 @menu
1511 * Tag Syntax:: Tag syntax for various types of code and text files.
1512 * Create Tags Table:: Creating a tags table with @code{etags}.
1513 * Etags Regexps:: Create arbitrary tags using regular expressions.
1514 * Select Tags Table:: How to visit a tags table.
1515 * Find Tag:: Commands to find the definition of a specific tag.
1516 * Tags Search:: Using a tags table for searching and replacing.
1517 * List Tags:: Listing and finding tags defined in a file.
1518 @end menu
1519
1520 @node Tag Syntax
1521 @subsection Source File Tag Syntax
1522
1523 Here is how tag syntax is defined for the most popular languages:
1524
1525 @itemize @bullet
1526 @item
1527 In C code, any C function or typedef is a tag, and so are definitions of
1528 @code{struct}, @code{union} and @code{enum}.
1529 @code{#define} macro definitions, @code{#undef} and @code{enum}
1530 constants are also
1531 tags, unless you specify @samp{--no-defines} when making the tags table.
1532 Similarly, global variables are tags, unless you specify
1533 @samp{--no-globals}, and so are struct members, unless you specify
1534 @samp{--no-members}. Use of @samp{--no-globals}, @samp{--no-defines}
1535 and @samp{--no-members} can make the tags table file much smaller.
1536
1537 You can tag function declarations and external variables in addition
1538 to function definitions by giving the @samp{--declarations} option to
1539 @code{etags}.
1540
1541 @item
1542 In C++ code, in addition to all the tag constructs of C code, member
1543 functions are also recognized; member variables are also recognized,
1544 unless you use the @samp{--no-members} option. Tags for variables and
1545 functions in classes are named @samp{@var{class}::@var{variable}} and
1546 @samp{@var{class}::@var{function}}. @code{operator} definitions have
1547 tag names like @samp{operator+}.
1548
1549 @item
1550 In Java code, tags include all the constructs recognized in C++, plus
1551 the @code{interface}, @code{extends} and @code{implements} constructs.
1552 Tags for variables and functions in classes are named
1553 @samp{@var{class}.@var{variable}} and @samp{@var{class}.@var{function}}.
1554
1555 @item
1556 In La@TeX{} text, the argument of any of the commands @code{\chapter},
1557 @code{\section}, @code{\subsection}, @code{\subsubsection},
1558 @code{\eqno}, @code{\label}, @code{\ref}, @code{\cite},
1559 @code{\bibitem}, @code{\part}, @code{\appendix}, @code{\entry},
1560 @code{\index}, @code{\def}, @code{\newcommand}, @code{\renewcommand},
1561 @code{\newenvironment} or @code{\renewenvironment} is a tag.@refill
1562
1563 Other commands can make tags as well, if you specify them in the
1564 environment variable @env{TEXTAGS} before invoking @code{etags}. The
1565 value of this environment variable should be a colon-separated list of
1566 command names. For example,
1567
1568 @example
1569 TEXTAGS="mycommand:myothercommand"
1570 export TEXTAGS
1571 @end example
1572
1573 @noindent
1574 specifies (using Bourne shell syntax) that the commands
1575 @samp{\mycommand} and @samp{\myothercommand} also define tags.
1576
1577 @item
1578 In Lisp code, any function defined with @code{defun}, any variable
1579 defined with @code{defvar} or @code{defconst}, and in general the first
1580 argument of any expression that starts with @samp{(def} in column zero is
1581 a tag.
1582
1583 @item
1584 In Scheme code, tags include anything defined with @code{def} or with a
1585 construct whose name starts with @samp{def}. They also include variables
1586 set with @code{set!} at top level in the file.
1587 @end itemize
1588
1589 Several other languages are also supported:
1590
1591 @itemize @bullet
1592
1593 @item
1594 In Ada code, functions, procedures, packages, tasks and types are
1595 tags. Use the @samp{--packages-only} option to create tags for
1596 packages only.
1597
1598 In Ada, the same name can be used for different kinds of entity
1599 (e.g.@:, for a procedure and for a function). Also, for things like
1600 packages, procedures and functions, there is the spec (i.e.@: the
1601 interface) and the body (i.e.@: the implementation). To make it
1602 easier to pick the definition you want, Ada tag name have suffixes
1603 indicating the type of entity:
1604
1605 @table @samp
1606 @item /b
1607 package body.
1608 @item /f
1609 function.
1610 @item /k
1611 task.
1612 @item /p
1613 procedure.
1614 @item /s
1615 package spec.
1616 @item /t
1617 type.
1618 @end table
1619
1620 Thus, @kbd{M-x find-tag @key{RET} bidule/b @key{RET}} will go
1621 directly to the body of the package @code{bidule}, while @kbd{M-x
1622 find-tag @key{RET} bidule @key{RET}} will just search for any tag
1623 @code{bidule}.
1624
1625 @item
1626 In assembler code, labels appearing at the beginning of a line,
1627 followed by a colon, are tags.
1628
1629 @item
1630 In Bison or Yacc input files, each rule defines as a tag the nonterminal
1631 it constructs. The portions of the file that contain C code are parsed
1632 as C code.
1633
1634 @item
1635 In Cobol code, tags are paragraph names; that is, any word starting in
1636 column 8 and followed by a period.
1637
1638 @item
1639 In Erlang code, the tags are the functions, records and macros defined
1640 in the file.
1641
1642 @item
1643 In Fortran code, functions, subroutines and block data are tags.
1644
1645 @item
1646 In HTML input files, the tags are the @code{title} and the @code{h1},
1647 @code{h2}, @code{h3} headers. Also, tags are @code{name=} in anchors
1648 and all occurrences of @code{id=}.
1649
1650 @item
1651 In Lua input files, all functions are tags.
1652
1653 @item
1654 In makefiles, targets are tags; additionally, variables are tags
1655 unless you specify @samp{--no-globals}.
1656
1657 @item
1658 In Objective C code, tags include Objective C definitions for classes,
1659 class categories, methods and protocols. Tags for variables and
1660 functions in classes are named @samp{@var{class}::@var{variable}} and
1661 @samp{@var{class}::@var{function}}.
1662
1663 @item
1664 In Pascal code, the tags are the functions and procedures defined in
1665 the file.
1666
1667 @item
1668 In Perl code, the tags are the packages, subroutines and variables
1669 defined by the @code{package}, @code{sub}, @code{my} and @code{local}
1670 keywords. Use @samp{--globals} if you want to tag global variables.
1671 Tags for subroutines are named @samp{@var{package}::@var{sub}}. The
1672 name for subroutines defined in the default package is
1673 @samp{main::@var{sub}}.
1674
1675 @item
1676 In PHP code, tags are functions, classes and defines. Vars are tags
1677 too, unless you use the @samp{--no-members} option.
1678
1679 @item
1680 In PostScript code, the tags are the functions.
1681
1682 @item
1683 In Prolog code, tags are predicates and rules at the beginning of
1684 line.
1685
1686 @item
1687 In Python code, @code{def} or @code{class} at the beginning of a line
1688 generate a tag.
1689 @end itemize
1690
1691 You can also generate tags based on regexp matching (@pxref{Etags
1692 Regexps}) to handle other formats and languages.
1693
1694 @node Create Tags Table
1695 @subsection Creating Tags Tables
1696 @cindex @code{etags} program
1697
1698 The @code{etags} program is used to create a tags table file. It knows
1699 the syntax of several languages, as described in
1700 @iftex
1701 the previous section.
1702 @end iftex
1703 @ifnottex
1704 @ref{Tag Syntax}.
1705 @end ifnottex
1706 Here is how to run @code{etags}:
1707
1708 @example
1709 etags @var{inputfiles}@dots{}
1710 @end example
1711
1712 @noindent
1713 The @code{etags} program reads the specified files, and writes a tags
1714 table named @file{TAGS} in the current working directory. You can
1715 optionally specify a different file name for the tags table by using the
1716 @samp{--output=@var{file}} option; specifying @file{-} as a file name
1717 prints the tags table to standard output.
1718
1719 If the specified files don't exist, @code{etags} looks for
1720 compressed versions of them and uncompresses them to read them. Under
1721 MS-DOS, @code{etags} also looks for file names like @file{mycode.cgz}
1722 if it is given @samp{mycode.c} on the command line and @file{mycode.c}
1723 does not exist.
1724
1725 @code{etags} recognizes the language used in an input file based on
1726 its file name and contents. You can specify the language with the
1727 @samp{--language=@var{name}} option, described below.
1728
1729 If the tags table data become outdated due to changes in the files
1730 described in the table, the way to update the tags table is the same
1731 way it was made in the first place. If the tags table fails to record
1732 a tag, or records it for the wrong file, then Emacs cannot possibly
1733 find its definition until you update the tags table. However, if the
1734 position recorded in the tags table becomes a little bit wrong (due to
1735 other editing), the worst consequence is a slight delay in finding the
1736 tag. Even if the stored position is very far wrong, Emacs will still
1737 find the tag, after searching most of the file for it. That delay is
1738 hardly noticeable with today's computers.
1739
1740 Thus, there is no need to update the tags table after each edit.
1741 You should update a tags table when you define new tags that you want
1742 to have listed, or when you move tag definitions from one file to
1743 another, or when changes become substantial.
1744
1745 One tags table can virtually include another. Specify the included
1746 tags file name with the @samp{--include=@var{file}} option when
1747 creating the file that is to include it. The latter file then acts as
1748 if it covered all the source files specified in the included file, as
1749 well as the files it directly contains.
1750
1751 If you specify the source files with relative file names when you run
1752 @code{etags}, the tags file will contain file names relative to the
1753 directory where the tags file was initially written. This way, you can
1754 move an entire directory tree containing both the tags file and the
1755 source files, and the tags file will still refer correctly to the source
1756 files. If the tags file is @file{-} or is in the @file{/dev} directory,
1757 however, the file names are
1758 made relative to the current working directory. This is useful, for
1759 example, when writing the tags to @file{/dev/stdout}.
1760
1761 When using a relative file name, it should not be a symbolic link
1762 pointing to a tags file in a different directory, because this would
1763 generally render the file names invalid.
1764
1765 If you specify absolute file names as arguments to @code{etags}, then
1766 the tags file will contain absolute file names. This way, the tags file
1767 will still refer to the same files even if you move it, as long as the
1768 source files remain in the same place. Absolute file names start with
1769 @samp{/}, or with @samp{@var{device}:/} on MS-DOS and MS-Windows.
1770
1771 When you want to make a tags table from a great number of files, you
1772 may have problems listing them on the command line, because some systems
1773 have a limit on its length. The simplest way to circumvent this limit
1774 is to tell @code{etags} to read the file names from its standard input,
1775 by typing a dash in place of the file names, like this:
1776
1777 @smallexample
1778 find . -name "*.[chCH]" -print | etags -
1779 @end smallexample
1780
1781 Use the option @samp{--language=@var{name}} to specify the language
1782 explicitly. You can intermix these options with file names; each one
1783 applies to the file names that follow it. Specify
1784 @samp{--language=auto} to tell @code{etags} to resume guessing the
1785 language from the file names and file contents. Specify
1786 @samp{--language=none} to turn off language-specific processing
1787 entirely; then @code{etags} recognizes tags by regexp matching alone
1788 (@pxref{Etags Regexps}).
1789
1790 The option @samp{--parse-stdin=@var{file}} is mostly useful when
1791 calling @code{etags} from programs. It can be used (only once) in
1792 place of a file name on the command line. @code{Etags} will read from
1793 standard input and mark the produced tags as belonging to the file
1794 @var{file}.
1795
1796 @samp{etags --help} outputs the list of the languages @code{etags}
1797 knows, and the file name rules for guessing the language. It also prints
1798 a list of all the available @code{etags} options, together with a short
1799 explanation. If followed by one or more @samp{--language=@var{lang}}
1800 options, it outputs detailed information about how tags are generated for
1801 @var{lang}.
1802
1803 @node Etags Regexps
1804 @subsection Etags Regexps
1805
1806 The @samp{--regex} option provides a general way of recognizing tags
1807 based on regexp matching. You can freely intermix this option with
1808 file names, and each one applies to the source files that follow it.
1809 If you specify multiple @samp{--regex} options, all of them are used
1810 in parallel. The syntax is:
1811
1812 @smallexample
1813 --regex=[@var{@{language@}}]/@var{tagregexp}/[@var{nameregexp}/]@var{modifiers}
1814 @end smallexample
1815
1816 The essential part of the option value is @var{tagregexp}, the
1817 regexp for matching tags. It is always used anchored, that is, it
1818 only matches at the beginning of a line. If you want to allow
1819 indented tags, use a regexp that matches initial whitespace; start it
1820 with @samp{[ \t]*}.
1821
1822 In these regular expressions, @samp{\} quotes the next character, and
1823 all the GCC character escape sequences are supported (@samp{\a} for
1824 bell, @samp{\b} for back space, @samp{\d} for delete, @samp{\e} for
1825 escape, @samp{\f} for formfeed, @samp{\n} for newline, @samp{\r} for
1826 carriage return, @samp{\t} for tab, and @samp{\v} for vertical tab).
1827
1828 Ideally, @var{tagregexp} should not match more characters than are
1829 needed to recognize what you want to tag. If the syntax requires you
1830 to write @var{tagregexp} so it matches more characters beyond the tag
1831 itself, you should add a @var{nameregexp}, to pick out just the tag.
1832 This will enable Emacs to find tags more accurately and to do
1833 completion on tag names more reliably. You can find some examples
1834 below.
1835
1836 The @var{modifiers} are a sequence of zero or more characters that
1837 modify the way @code{etags} does the matching. A regexp with no
1838 modifiers is applied sequentially to each line of the input file, in a
1839 case-sensitive way. The modifiers and their meanings are:
1840
1841 @table @samp
1842 @item i
1843 Ignore case when matching this regexp.
1844 @item m
1845 Match this regular expression against the whole file, so that
1846 multi-line matches are possible.
1847 @item s
1848 Match this regular expression against the whole file, and allow
1849 @samp{.} in @var{tagregexp} to match newlines.
1850 @end table
1851
1852 The @samp{-R} option cancels all the regexps defined by preceding
1853 @samp{--regex} options. It too applies to the file names following
1854 it. Here's an example:
1855
1856 @smallexample
1857 etags --regex=/@var{reg1}/i voo.doo --regex=/@var{reg2}/m \
1858 bar.ber -R --lang=lisp los.er
1859 @end smallexample
1860
1861 @noindent
1862 Here @code{etags} chooses the parsing language for @file{voo.doo} and
1863 @file{bar.ber} according to their contents. @code{etags} also uses
1864 @var{reg1} to recognize additional tags in @file{voo.doo}, and both
1865 @var{reg1} and @var{reg2} to recognize additional tags in
1866 @file{bar.ber}. @var{reg1} is checked against each line of
1867 @file{voo.doo} and @file{bar.ber}, in a case-insensitive way, while
1868 @var{reg2} is checked against the whole @file{bar.ber} file,
1869 permitting multi-line matches, in a case-sensitive way. @code{etags}
1870 uses only the Lisp tags rules, with no user-specified regexp matching,
1871 to recognize tags in @file{los.er}.
1872
1873 You can restrict a @samp{--regex} option to match only files of a
1874 given language by using the optional prefix @var{@{language@}}.
1875 (@samp{etags --help} prints the list of languages recognized by
1876 @code{etags}.) This is particularly useful when storing many
1877 predefined regular expressions for @code{etags} in a file. The
1878 following example tags the @code{DEFVAR} macros in the Emacs source
1879 files, for the C language only:
1880
1881 @smallexample
1882 --regex='@{c@}/[ \t]*DEFVAR_[A-Z_ \t(]+"\([^"]+\)"/'
1883 @end smallexample
1884
1885 @noindent
1886 When you have complex regular expressions, you can store the list of
1887 them in a file. The following option syntax instructs @code{etags} to
1888 read two files of regular expressions. The regular expressions
1889 contained in the second file are matched without regard to case.
1890
1891 @smallexample
1892 --regex=@@@var{case-sensitive-file} --ignore-case-regex=@@@var{ignore-case-file}
1893 @end smallexample
1894
1895 @noindent
1896 A regex file for @code{etags} contains one regular expression per
1897 line. Empty lines, and lines beginning with space or tab are ignored.
1898 When the first character in a line is @samp{@@}, @code{etags} assumes
1899 that the rest of the line is the name of another file of regular
1900 expressions; thus, one such file can include another file. All the
1901 other lines are taken to be regular expressions. If the first
1902 non-whitespace text on the line is @samp{--}, that line is a comment.
1903
1904 For example, we can create a file called @samp{emacs.tags} with the
1905 following contents:
1906
1907 @smallexample
1908 -- This is for GNU Emacs C source files
1909 @{c@}/[ \t]*DEFVAR_[A-Z_ \t(]+"\([^"]+\)"/\1/
1910 @end smallexample
1911
1912 @noindent
1913 and then use it like this:
1914
1915 @smallexample
1916 etags --regex=@@emacs.tags *.[ch] */*.[ch]
1917 @end smallexample
1918
1919 Here are some more examples. The regexps are quoted to protect them
1920 from shell interpretation.
1921
1922 @itemize @bullet
1923
1924 @item
1925 Tag Octave files:
1926
1927 @smallexample
1928 etags --language=none \
1929 --regex='/[ \t]*function.*=[ \t]*\([^ \t]*\)[ \t]*(/\1/' \
1930 --regex='/###key \(.*\)/\1/' \
1931 --regex='/[ \t]*global[ \t].*/' \
1932 *.m
1933 @end smallexample
1934
1935 @noindent
1936 Note that tags are not generated for scripts, so that you have to add
1937 a line by yourself of the form @samp{###key @var{scriptname}} if you
1938 want to jump to it.
1939
1940 @item
1941 Tag Tcl files:
1942
1943 @smallexample
1944 etags --language=none --regex='/proc[ \t]+\([^ \t]+\)/\1/' *.tcl
1945 @end smallexample
1946
1947 @item
1948 Tag VHDL files:
1949
1950 @smallexample
1951 etags --language=none \
1952 --regex='/[ \t]*\(ARCHITECTURE\|CONFIGURATION\) +[^ ]* +OF/' \
1953 --regex='/[ \t]*\(ATTRIBUTE\|ENTITY\|FUNCTION\|PACKAGE\
1954 \( BODY\)?\|PROCEDURE\|PROCESS\|TYPE\)[ \t]+\([^ \t(]+\)/\3/'
1955 @end smallexample
1956 @end itemize
1957
1958 @node Select Tags Table
1959 @subsection Selecting a Tags Table
1960
1961 @vindex tags-file-name
1962 @findex visit-tags-table
1963 Emacs has at any time one @dfn{selected} tags table, and all the
1964 commands for working with tags tables use the selected one. To select
1965 a tags table, type @kbd{M-x visit-tags-table}, which reads the tags
1966 table file name as an argument, with @file{TAGS} in the default
1967 directory as the default.
1968
1969 Emacs does not actually read in the tags table contents until you
1970 try to use them; all @code{visit-tags-table} does is store the file
1971 name in the variable @code{tags-file-name}, and setting the variable
1972 yourself is just as good. The variable's initial value is @code{nil};
1973 that value tells all the commands for working with tags tables that
1974 they must ask for a tags table file name to use.
1975
1976 Using @code{visit-tags-table} when a tags table is already loaded
1977 gives you a choice: you can add the new tags table to the current list
1978 of tags tables, or start a new list. The tags commands use all the tags
1979 tables in the current list. If you start a new list, the new tags table
1980 is used @emph{instead} of others. If you add the new table to the
1981 current list, it is used @emph{as well as} the others.
1982
1983 @vindex tags-table-list
1984 You can specify a precise list of tags tables by setting the variable
1985 @code{tags-table-list} to a list of strings, like this:
1986
1987 @c keep this on two lines for formatting in smallbook
1988 @example
1989 @group
1990 (setq tags-table-list
1991 '("~/emacs" "/usr/local/lib/emacs/src"))
1992 @end group
1993 @end example
1994
1995 @noindent
1996 This tells the tags commands to look at the @file{TAGS} files in your
1997 @file{~/emacs} directory and in the @file{/usr/local/lib/emacs/src}
1998 directory. The order depends on which file you are in and which tags
1999 table mentions that file, as explained above.
2000
2001 Do not set both @code{tags-file-name} and @code{tags-table-list}.
2002
2003 @node Find Tag
2004 @subsection Finding a Tag
2005
2006 The most important thing that a tags table enables you to do is to find
2007 the definition of a specific tag.
2008
2009 @table @kbd
2010 @item M-.@: @var{tag} @key{RET}
2011 Find first definition of @var{tag} (@code{find-tag}).
2012 @item C-u M-.
2013 Find next alternate definition of last tag specified.
2014 @item C-u - M-.
2015 Go back to previous tag found.
2016 @item C-M-. @var{pattern} @key{RET}
2017 Find a tag whose name matches @var{pattern} (@code{find-tag-regexp}).
2018 @item C-u C-M-.
2019 Find the next tag whose name matches the last pattern used.
2020 @item C-x 4 .@: @var{tag} @key{RET}
2021 Find first definition of @var{tag}, but display it in another window
2022 (@code{find-tag-other-window}).
2023 @item C-x 5 .@: @var{tag} @key{RET}
2024 Find first definition of @var{tag}, and create a new frame to select the
2025 buffer (@code{find-tag-other-frame}).
2026 @item M-*
2027 Pop back to where you previously invoked @kbd{M-.} and friends.
2028 @end table
2029
2030 @kindex M-.
2031 @findex find-tag
2032 @kbd{M-.}@: (@code{find-tag}) is the command to find the definition of
2033 a specified tag. It searches through the tags table for that tag, as a
2034 string, and then uses the tags table info to determine the file that the
2035 definition is in and the approximate character position in the file of
2036 the definition. Then @code{find-tag} visits that file, moves point to
2037 the approximate character position, and searches ever-increasing
2038 distances away to find the tag definition.
2039
2040 If an empty argument is given (just type @key{RET}), the balanced
2041 expression in the buffer before or around point is used as the
2042 @var{tag} argument. @xref{Expressions}.
2043
2044 You don't need to give @kbd{M-.} the full name of the tag; a part
2045 will do. This is because @kbd{M-.} finds tags in the table which
2046 contain @var{tag} as a substring. However, it prefers an exact match
2047 to a substring match. To find other tags that match the same
2048 substring, give @code{find-tag} a numeric argument, as in @kbd{C-u
2049 M-.}; this does not read a tag name, but continues searching the tags
2050 table's text for another tag containing the same substring last used.
2051 If you have a real @key{META} key, @kbd{M-0 M-.}@: is an easier
2052 alternative to @kbd{C-u M-.}.
2053
2054 @kindex C-x 4 .
2055 @findex find-tag-other-window
2056 @kindex C-x 5 .
2057 @findex find-tag-other-frame
2058 Like most commands that can switch buffers, @code{find-tag} has a
2059 variant that displays the new buffer in another window, and one that
2060 makes a new frame for it. The former is @w{@kbd{C-x 4 .}}, which invokes
2061 the command @code{find-tag-other-window}. The latter is @w{@kbd{C-x 5 .}},
2062 which invokes @code{find-tag-other-frame}.
2063
2064 To move back to places you've found tags recently, use @kbd{C-u -
2065 M-.}; more generally, @kbd{M-.} with a negative numeric argument. This
2066 command can take you to another buffer. @w{@kbd{C-x 4 .}} with a negative
2067 argument finds the previous tag location in another window.
2068
2069 @kindex M-*
2070 @findex pop-tag-mark
2071 @vindex find-tag-marker-ring-length
2072 As well as going back to places you've found tags recently, you can go
2073 back to places @emph{from where} you found them. Use @kbd{M-*}, which
2074 invokes the command @code{pop-tag-mark}, for this. Typically you would
2075 find and study the definition of something with @kbd{M-.} and then
2076 return to where you were with @kbd{M-*}.
2077
2078 Both @kbd{C-u - M-.} and @kbd{M-*} allow you to retrace your steps to
2079 a depth determined by the variable @code{find-tag-marker-ring-length}.
2080
2081 @findex find-tag-regexp
2082 @kindex C-M-.
2083 The command @kbd{C-M-.} (@code{find-tag-regexp}) visits the tags that
2084 match a specified regular expression. It is just like @kbd{M-.} except
2085 that it does regexp matching instead of substring matching.
2086
2087 @node Tags Search
2088 @subsection Searching and Replacing with Tags Tables
2089 @cindex search and replace in multiple files
2090 @cindex multiple-file search and replace
2091
2092 The commands in this section visit and search all the files listed
2093 in the selected tags table, one by one. For these commands, the tags
2094 table serves only to specify a sequence of files to search. These
2095 commands scan the list of tags tables starting with the first tags
2096 table (if any) that describes the current file, proceed from there to
2097 the end of the list, and then scan from the beginning of the list
2098 until they have covered all the tables in the list.
2099
2100 @table @kbd
2101 @item M-x tags-search @key{RET} @var{regexp} @key{RET}
2102 Search for @var{regexp} through the files in the selected tags
2103 table.
2104 @item M-x tags-query-replace @key{RET} @var{regexp} @key{RET} @var{replacement} @key{RET}
2105 Perform a @code{query-replace-regexp} on each file in the selected tags table.
2106 @item M-,
2107 Restart one of the commands above, from the current location of point
2108 (@code{tags-loop-continue}).
2109 @end table
2110
2111 @findex tags-search
2112 @kbd{M-x tags-search} reads a regexp using the minibuffer, then
2113 searches for matches in all the files in the selected tags table, one
2114 file at a time. It displays the name of the file being searched so you
2115 can follow its progress. As soon as it finds an occurrence,
2116 @code{tags-search} returns.
2117
2118 @kindex M-,
2119 @findex tags-loop-continue
2120 Having found one match, you probably want to find all the rest. To find
2121 one more match, type @kbd{M-,} (@code{tags-loop-continue}) to resume the
2122 @code{tags-search}. This searches the rest of the current buffer, followed
2123 by the remaining files of the tags table.@refill
2124
2125 @findex tags-query-replace
2126 @kbd{M-x tags-query-replace} performs a single
2127 @code{query-replace-regexp} through all the files in the tags table. It
2128 reads a regexp to search for and a string to replace with, just like
2129 ordinary @kbd{M-x query-replace-regexp}. It searches much like @kbd{M-x
2130 tags-search}, but repeatedly, processing matches according to your
2131 input. @xref{Replace}, for more information on query replace.
2132
2133 @vindex tags-case-fold-search
2134 @cindex case-sensitivity and tags search
2135 You can control the case-sensitivity of tags search commands by
2136 customizing the value of the variable @code{tags-case-fold-search}. The
2137 default is to use the same setting as the value of
2138 @code{case-fold-search} (@pxref{Search Case}).
2139
2140 It is possible to get through all the files in the tags table with a
2141 single invocation of @kbd{M-x tags-query-replace}. But often it is
2142 useful to exit temporarily, which you can do with any input event that
2143 has no special query replace meaning. You can resume the query
2144 replace subsequently by typing @kbd{M-,}; this command resumes the
2145 last tags search or replace command that you did. For instance, to
2146 skip the rest of the current file, you can type @kbd{M-> M-,}.
2147
2148 The commands in this section carry out much broader searches than the
2149 @code{find-tag} family. The @code{find-tag} commands search only for
2150 definitions of tags that match your substring or regexp. The commands
2151 @code{tags-search} and @code{tags-query-replace} find every occurrence
2152 of the regexp, as ordinary search commands and replace commands do in
2153 the current buffer.
2154
2155 These commands create buffers only temporarily for the files that they
2156 have to search (those which are not already visited in Emacs buffers).
2157 Buffers in which no match is found are quickly killed; the others
2158 continue to exist.
2159
2160 It may have struck you that @code{tags-search} is a lot like
2161 @code{grep}. You can also run @code{grep} itself as an inferior of
2162 Emacs and have Emacs show you the matching lines one by one.
2163 @xref{Grep Searching}.
2164
2165 @node List Tags
2166 @subsection Tags Table Inquiries
2167
2168 @table @kbd
2169 @item M-x list-tags @key{RET} @var{file} @key{RET}
2170 Display a list of the tags defined in the program file @var{file}.
2171 @item M-x tags-apropos @key{RET} @var{regexp} @key{RET}
2172 Display a list of all tags matching @var{regexp}.
2173 @end table
2174
2175 @findex list-tags
2176 @kbd{M-x list-tags} reads the name of one of the files described by
2177 the selected tags table, and displays a list of all the tags defined in
2178 that file. The ``file name'' argument is really just a string to
2179 compare against the file names recorded in the tags table; it is read as
2180 a string rather than as a file name. Therefore, completion and
2181 defaulting are not available, and you must enter the file name the same
2182 way it appears in the tags table. Do not include a directory as part of
2183 the file name unless the file name recorded in the tags table includes a
2184 directory.
2185
2186 @findex tags-apropos
2187 @vindex tags-apropos-verbose
2188 @kbd{M-x tags-apropos} is like @code{apropos} for tags
2189 (@pxref{Apropos}). It finds all the tags in the selected tags table
2190 whose entries match @var{regexp}, and displays them. If the variable
2191 @code{tags-apropos-verbose} is non-@code{nil}, it displays the names
2192 of the tags files together with the tag names.
2193
2194 @vindex tags-tag-face
2195 @vindex tags-apropos-additional-actions
2196 You can customize the appearance of the output by setting the
2197 variable @code{tags-tag-face} to a face. You can display additional
2198 output with @kbd{M-x tags-apropos} by customizing the variable
2199 @code{tags-apropos-additional-actions}---see its documentation for
2200 details.
2201
2202 You can also use the collection of tag names to complete a symbol
2203 name in the buffer. @xref{Symbol Completion}.
2204
2205 @ifnottex
2206 @include emerge-xtra.texi
2207 @end ifnottex
2208
2209 @ignore
2210 arch-tag: b9d83dfb-82ea-4ff6-bab5-05a3617091fb
2211 @end ignore