Update copyright year to 2015
[emacs.git] / doc / emacs / maintaining.texi
blob9074cdfb883b1e6d238a8efb6b16b4660e843cb9
1 @c This is part of the Emacs manual., Abbrevs, This is part of the Emacs manual., Top
2 @c Copyright (C) 1985-1987, 1993-1995, 1997, 1999-2015 Free Software
3 @c Foundation, Inc.
4 @c See file emacs.texi for copying conditions.
5 @node Maintaining
6 @chapter Maintaining Large Programs
8   This chapter describes Emacs features for maintaining large
9 programs.  If you are maintaining a large Lisp program, then in
10 addition to the features described here, you may find
11 the @file{ERT} (``Emacs Lisp Regression Testing'') library useful
12 (@pxref{Top,,ERT,ert, Emacs Lisp Regression Testing}).
14 @menu
15 * Version Control::     Using version control systems.
16 * Change Log::          Maintaining a change history for your program.
17 * Tags::                Go directly to any function in your program in one
18                           command.  Tags remembers which file it is in.
19 * EDE::                 An integrated development environment for Emacs.
20 @ifnottex
21 * Emerge::              A convenient way of merging two versions of a program.
22 @end ifnottex
23 @end menu
25 @node Version Control
26 @section Version Control
27 @cindex version control
29   A @dfn{version control system} is a program that can record multiple
30 versions of a source file, storing information such as the creation
31 time of each version, who made it, and a description of what was
32 changed.
34   The Emacs version control interface is called @dfn{VC}@.  VC
35 commands work with several different version control systems;
36 currently, it supports Bazaar, CVS, Git, Mercurial, Monotone, RCS,
37 SCCS/CSSC, and Subversion.  Of these, the GNU project distributes CVS,
38 RCS, and Bazaar.
40   VC is enabled automatically whenever you visit a file governed by a
41 version control system.  To disable VC entirely, set the customizable
42 variable @code{vc-handled-backends} to @code{nil}
43 @iftex
44 (@pxref{Customizing VC,,,emacs-xtra, Specialized Emacs Features}).
45 @end iftex
46 @ifnottex
47 (@pxref{Customizing VC}).
48 @end ifnottex
50 @menu
51 * Introduction to VC::  How version control works in general.
52 * VC Mode Line::        How the mode line shows version control status.
53 * Basic VC Editing::    How to edit a file under version control.
54 * Log Buffer::          Features available in log entry buffers.
55 * Registering::         Putting a file under version control.
56 * Old Revisions::       Examining and comparing old versions.
57 * VC Change Log::       Viewing the VC Change Log.
58 * VC Undo::             Canceling changes before or after committing.
59 * VC Ignore::           Ignore files under version control system.
60 * VC Directory Mode::   Listing files managed by version control.
61 * Branches::            Multiple lines of development.
62 @ifnottex
63 * Miscellaneous VC::    Various other commands and features of VC.
64 * Customizing VC::      Variables that change VC's behavior.
65 @end ifnottex
66 @end menu
68 @node Introduction to VC
69 @subsection Introduction to Version Control
71   VC allows you to use a version control system from within Emacs,
72 integrating the version control operations smoothly with editing.  It
73 provides a uniform interface for common operations in many version
74 control operations.
76   Some uncommon or intricate version control operations, such as
77 altering repository settings, are not supported in VC@.  You should
78 perform such tasks outside Emacs, e.g., via the command line.
80   This section provides a general overview of version control, and
81 describes the version control systems that VC supports.  You can skip
82 this section if you are already familiar with the version control system
83 you want to use.
85 @menu
86 * Why Version Control?::    Understanding the problems it addresses.
87 * Version Control Systems:: Supported version control back-end systems.
88 * VCS Concepts::            Words and concepts related to version control.
89 * VCS Merging::             How file conflicts are handled.
90 * VCS Changesets::          How changes are grouped.
91 * VCS Repositories::        Where version control repositories are stored.
92 * Types of Log File::       The VCS log in contrast to the ChangeLog.
93 @end menu
95 @node Why Version Control?
96 @subsubsection Understanding the problems it addresses
98   Version control systems provide you with three important
99 capabilities:
101 @itemize @bullet
102 @item
103 @dfn{Reversibility}: the ability to back up to a previous state if you
104 discover that some modification you did was a mistake or a bad idea.
106 @item
107 @dfn{Concurrency}: the ability to have many people modifying the same
108 collection of files knowing that conflicting modifications can be
109 detected and resolved.
111 @item
112 @dfn{History}: the ability to attach historical data to your data,
113 such as explanatory comments about the intention behind each change to
114 it.  Even for a programmer working solo, change histories are an
115 important aid to memory; for a multi-person project, they are a
116 vitally important form of communication among developers.
117 @end itemize
119 @node Version Control Systems
120 @subsubsection Supported Version Control Systems
122 @cindex back end (version control)
123   VC currently works with many different version control systems,
124 which it refers to as @dfn{back ends}:
126 @itemize @bullet
128 @cindex SCCS
129 @item
130 SCCS was the first version control system ever built, and was long ago
131 superseded by more advanced ones.  VC compensates for certain features
132 missing in SCCS (e.g., tag names for releases) by implementing them
133 itself.  Other VC features, such as multiple branches, are simply
134 unavailable.  Since SCCS is non-free, we recommend avoiding it.
136 @cindex CSSC
137 @item
138 CSSC is a free replacement for SCCS@.  You should use CSSC only if, for
139 some reason, you cannot use a more recent and better-designed version
140 control system.
142 @cindex RCS
143 @item
144 RCS is the free version control system around which VC was initially
145 built.  It is relatively primitive: it cannot be used over the
146 network, and works at the level of individual files.  Almost
147 everything you can do with RCS can be done through VC.
149 @cindex CVS
150 @item
151 CVS is the free version control system that was, until recently (circa
152 2008), used by the majority of free software projects.  Nowadays, it
153 is slowly being superseded by newer systems.  CVS allows concurrent
154 multi-user development either locally or over the network.  Unlike
155 newer systems, it lacks support for atomic commits and file
156 moving/renaming.  VC supports all basic editing operations under CVS.
158 @cindex SVN
159 @cindex Subversion
160 @item
161 Subversion (svn) is a free version control system designed to be
162 similar to CVS but without its problems (e.g., it supports atomic
163 commits of filesets, and versioning of directories, symbolic links,
164 meta-data, renames, copies, and deletes).
166 @cindex git
167 @item
168 Git is a decentralized version control system originally invented by
169 Linus Torvalds to support development of Linux (his kernel).  VC
170 supports many common Git operations, but others, such as repository
171 syncing, must be done from the command line.
173 @cindex hg
174 @cindex Mercurial
175 @item
176 Mercurial (hg) is a decentralized version control system broadly
177 resembling Git.  VC supports most Mercurial commands, with the
178 exception of repository sync operations.
180 @cindex bzr
181 @cindex Bazaar
182 @item
183 Bazaar (bzr) is a decentralized version control system that supports
184 both repository-based and decentralized versioning.  VC supports most
185 basic editing operations under Bazaar.
187 @cindex SRC
188 @cindex src
189 @item
190 SRC (src) is RCS, reloaded - a specialized version-control system
191 designed for single-file projects worked on by only one person. It
192 allows multiple files with independent version-control histories to
193 exist in one directory, and is thus particularly well suited for
194 maintaining small documents, scripts, and dotfiles.  While it uses RCS
195 for revision storage, it presents a modern user interface featuring
196 lockless operation and integer sequential version numbers.  VC
197 supports almost all SRC operations.
198 @end itemize
200 @node VCS Concepts
201 @subsubsection Concepts of Version Control
203 @cindex repository
204 @cindex registered file
205    When a file is under version control, we say that it is
206 @dfn{registered} in the version control system.  The system has a
207 @dfn{repository} which stores both the file's present state and its
208 change history---enough to reconstruct the current version or any
209 earlier version.  The repository also contains other information, such
210 as @dfn{log entries} that describe the changes made to each file.
212 @cindex work file
213 @cindex checking out files
214   The copy of a version-controlled file that you actually edit is
215 called the @dfn{work file}.  You can change each work file as you
216 would an ordinary file.  After you are done with a set of changes, you
217 may @dfn{commit} (or @dfn{check in}) the changes; this records the
218 changes in the repository, along with a descriptive log entry.
220 @cindex working tree
221   A directory tree of work files is called a @dfn{working tree}.
223 @cindex revision
224 @cindex revision ID
225   Each commit creates a new @dfn{revision} in the repository.  The
226 version control system keeps track of all past revisions and the
227 changes that were made in each revision.  Each revision is named by a
228 @dfn{revision ID}, whose format depends on the version control system;
229 in the simplest case, it is just an integer.
231   To go beyond these basic concepts, you will need to understand three
232 aspects in which version control systems differ.  As explained in the
233 next three sections, they can be lock-based or merge-based; file-based
234 or changeset-based; and centralized or decentralized.  VC handles all
235 these modes of operation, but it cannot hide the differences.
237 @node VCS Merging
238 @subsubsection Merge-based vs lock-based Version Control
240   A version control system typically has some mechanism to coordinate
241 between users who want to change the same file.  There are two ways to
242 do this: merging and locking.
244 @cindex merging-based version
245   In a version control system that uses merging, each user may modify
246 a work file at any time.  The system lets you @dfn{merge} your work
247 file, which may contain changes that have not been committed, with the
248 latest changes that others have committed.
250 @cindex locking-based version
251   Older version control systems use a @dfn{locking} scheme instead.
252 Here, work files are normally read-only.  To edit a file, you ask the
253 version control system to make it writable for you by @dfn{locking}
254 it; only one user can lock a given file at any given time.  This
255 procedure is analogous to, but different from, the locking that Emacs
256 uses to detect simultaneous editing of ordinary files
257 (@pxref{Interlocking}).  When you commit your changes, that unlocks
258 the file, and the work file becomes read-only again.  Other users may
259 then lock the file to make their own changes.
261   Both locking and merging systems can have problems when multiple
262 users try to modify the same file at the same time.  Locking systems
263 have @dfn{lock conflicts}; a user may try to check a file out and be
264 unable to because it is locked.  In merging systems, @dfn{merge
265 conflicts} happen when you commit a change to a file that conflicts
266 with a change committed by someone else after your checkout.  Both
267 kinds of conflict have to be resolved by human judgment and
268 communication.  Experience has shown that merging is superior to
269 locking, both in convenience to developers and in minimizing the
270 number and severity of conflicts that actually occur.
272   SCCS always uses locking.  RCS is lock-based by default but can be
273 told to operate in a merging style.  CVS and Subversion are
274 merge-based by default but can be told to operate in a locking mode.
275 Decentralized version control systems, such as Git and Mercurial, are
276 exclusively merging-based.
278   VC mode supports both locking and merging version control.  The
279 terms ``commit'' and ``update'' are used in newer version control
280 systems; older lock-based systems use the terms ``check in'' and
281 ``check out''.  VC hides the differences between them as much as
282 possible.
284 @node VCS Changesets
285 @subsubsection Changeset-based vs File-based Version Control
287 @cindex file-based version control
288   On SCCS, RCS, CVS, and other early version control systems, version
289 control operations are @dfn{file-based}: each file has its own comment
290 and revision history separate from that of all other files.  Newer
291 systems, beginning with Subversion, are @dfn{changeset-based}: a
292 commit may include changes to several files, and the entire set of
293 changes is handled as a unit.  Any comment associated with the change
294 does not belong to a single file, but to the changeset itself.
296 @cindex changeset-based version control
297   Changeset-based version control is more flexible and powerful than
298 file-based version control; usually, when a change to multiple files
299 has to be reversed, it's good to be able to easily identify and remove
300 all of it.
302 @node VCS Repositories
303 @subsubsection Decentralized vs Centralized Repositories
305 @cindex centralized version control
306 @cindex decentralized version control
307 @cindex distributed version control
308   Early version control systems were designed around a
309 @dfn{centralized} model in which each project has only one repository
310 used by all developers.  SCCS, RCS, CVS, and Subversion share this
311 kind of model.  One of its drawbacks is that the repository is a choke
312 point for reliability and efficiency.
314   GNU Arch pioneered the concept of @dfn{distributed} or
315 @dfn{decentralized} version control, later implemented in Git,
316 Mercurial, and Bazaar.  A project may have several different
317 repositories, and these systems support a sort of super-merge between
318 repositories that tries to reconcile their change histories.  In
319 effect, there is one repository for each developer, and repository
320 merges take the place of commit operations.
322   VC helps you manage the traffic between your personal workfiles and
323 a repository.  Whether the repository is a single master, or one of a
324 network of peer repositories, is not something VC has to care about.
326 @node Types of Log File
327 @subsubsection Types of Log File
328 @cindex types of log file
329 @cindex log File, types of
330 @cindex version control log
332   Projects that use a version control system can have two types of log
333 for changes.  One is the log maintained by the version control system:
334 each time you commit a change, you fill out a @dfn{log entry} for the
335 change (@pxref{Log Buffer}).  This is called the @dfn{version control
336 log}.
338   The other kind of log is the file @file{ChangeLog} (@pxref{Change
339 Log}).  It provides a chronological record of all changes to a large
340 portion of a program---typically one directory and its subdirectories.
341 A small program would use one @file{ChangeLog} file; a large program
342 may have a @file{ChangeLog} file in each major directory.
343 @xref{Change Log}.  Programmers have used change logs since long
344 before version control systems.
346   Changeset-based version systems typically maintain a changeset-based
347 modification log for the entire system, which makes change log files
348 somewhat redundant.  One advantage that they retain is that it is
349 sometimes useful to be able to view the transaction history of a
350 single directory separately from those of other directories.  Another
351 advantage is that commit logs can't be fixed in many version control
352 systems.
354   A project maintained with version control can use just the version
355 control log, or it can use both kinds of logs.  It can handle some
356 files one way and some files the other way.  Each project has its
357 policy, which you should follow.
359   When the policy is to use both, you typically want to write an entry
360 for each change just once, then put it into both logs.  You can write
361 the entry in @file{ChangeLog}, then copy it to the log buffer with
362 @kbd{C-c C-a} when committing the change (@pxref{Log Buffer}).  Or you
363 can write the entry in the log buffer while committing the change, and
364 later use the @kbd{C-x v a} command to copy it to @file{ChangeLog}
365 @iftex
366 (@pxref{Change Logs and VC,,,emacs-xtra, Specialized Emacs Features}).
367 @end iftex
368 @ifnottex
369 (@pxref{Change Logs and VC}).
370 @end ifnottex
372 @node VC Mode Line
373 @subsection Version Control and the Mode Line
374 @cindex VC mode line indicator
376   When you visit a file that is under version control, Emacs indicates
377 this on the mode line.  For example, @samp{Bzr-1223} says that Bazaar
378 is used for that file, and the current revision ID is 1223.
380 @cindex version control status
381   The character between the back-end name and the revision ID
382 indicates the @dfn{version control status} of the work file.  In a
383 merge-based version control system, a @samp{-} character indicates
384 that the work file is unmodified, and @samp{:} indicates that it has
385 been modified.  @samp{!} indicates that the file contains conflicts as
386 result of a recent merge operation (@pxref{Merging}), or that the file
387 was removed from the version control.  Finally, @samp{?} means that
388 the file is under version control, but is missing from the working
389 tree.
391   In a lock-based system, @samp{-} indicates an unlocked file, and
392 @samp{:} a locked file; if the file is locked by another user (for
393 instance, @samp{jim}), that is displayed as @samp{RCS:jim:1.3}.
394 @samp{@@} means that the file was locally added, but not yet committed
395 to the master repository.
397   On a graphical display, you can move the mouse over this mode line
398 indicator to pop up a ``tool-tip'', which displays a more verbose
399 description of the version control status.  Pressing @kbd{Mouse-1}
400 over the indicator pops up a menu of VC commands, identical to
401 @samp{Tools / Version Control} on the menu bar.
403 @vindex auto-revert-check-vc-info
404   When Auto Revert mode (@pxref{Reverting}) reverts a buffer that is
405 under version control, it updates the version control information in
406 the mode line.  However, Auto Revert mode may not properly update this
407 information if the version control status changes without changes to
408 the work file, from outside the current Emacs session.  If you set
409 @code{auto-revert-check-vc-info} to @code{t}, Auto Revert mode updates
410 the version control status information every
411 @code{auto-revert-interval} seconds, even if the work file itself is
412 unchanged.  The resulting CPU usage depends on the version control
413 system, but is usually not excessive.
415 @node Basic VC Editing
416 @subsection Basic Editing under Version Control
418 @cindex filesets, VC
419 @cindex VC filesets
420    Most VC commands operate on @dfn{VC filesets}.  A VC fileset is a
421 collection of one or more files that a VC operation acts on.  When you
422 type VC commands in a buffer visiting a version-controlled file, the
423 VC fileset is simply that one file.  When you type them in a VC
424 Directory buffer, and some files in it are marked, the VC fileset
425 consists of the marked files (@pxref{VC Directory Mode}).
427   On modern changeset-based version control systems (@pxref{VCS
428 Changesets}), VC commands handle multi-file VC filesets as a group.
429 For example, committing a multi-file VC fileset generates a single
430 revision, containing the changes to all those files.  On older
431 file-based version control systems like CVS, each file in a multi-file
432 VC fileset is handled individually; for example, a commit generates
433 one revision for each changed file.
435 @table @kbd
436 @item C-x v v
437 Perform the next appropriate version control operation on the current
438 VC fileset.
439 @end table
441 @findex vc-next-action
442 @kindex C-x v v
443   The principal VC command is a multi-purpose command, @kbd{C-x v v}
444 (@code{vc-next-action}), which performs the ``most appropriate''
445 action on the current VC fileset: either registering it with a version
446 control system, or committing it, or unlocking it, or merging changes
447 into it.  The precise actions are described in detail in the following
448 subsections.  You can use @kbd{C-x v v} either in a file-visiting
449 buffer or in a VC Directory buffer.
451   Note that VC filesets are distinct from the ``named filesets'' used
452 for viewing and visiting files in functional groups
453 (@pxref{Filesets}).  Unlike named filesets, VC filesets are not named
454 and don't persist across sessions.
456 @menu
457 * VC With A Merging VCS::  Without locking: default mode for CVS.
458 * VC With A Locking VCS::  RCS in its default mode, SCCS, and optionally CVS.
459 * Advanced C-x v v::       Advanced features available with a prefix argument.
460 @end menu
462 @node VC With A Merging VCS
463 @subsubsection Basic Version Control with Merging
465   On a merging-based version control system (i.e., most modern ones;
466 @pxref{VCS Merging}), @kbd{C-x v v} does the following:
468 @itemize @bullet
469 @item
470 If there is more than one file in the VC fileset and the files have
471 inconsistent version control statuses, signal an error.  (Note,
472 however, that a fileset is allowed to include both ``newly-added''
473 files and ``modified'' files; @pxref{Registering}.)
475 @item
476 If none of the files in the VC fileset are registered with a version
477 control system, register the VC fileset, i.e., place it under version
478 control.  @xref{Registering}.  If Emacs cannot find a system to
479 register under, it prompts for a repository type, creates a new
480 repository, and registers the VC fileset with it.
482 @item
483 If every work file in the VC fileset is unchanged, do nothing.
485 @item
486 If every work file in the VC fileset has been modified, commit the
487 changes.  To do this, Emacs pops up a @file{*vc-log*} buffer; type the
488 desired log entry for the new revision, followed by @kbd{C-c C-c} to
489 commit.  @xref{Log Buffer}.
491 If committing to a shared repository, the commit may fail if the
492 repository that has been changed since your last update.  In that
493 case, you must perform an update before trying again.  On a
494 decentralized version control system, use @kbd{C-x v +} (@pxref{VC
495 Pull}) or @kbd{C-x v m} (@pxref{Merging}).  On a centralized version
496 control system, type @kbd{C-x v v} again to merge in the repository
497 changes.
499 @item
500 Finally, if you are using a centralized version control system, check
501 if each work file in the VC fileset is up-to-date.  If any file has
502 been changed in the repository, offer to update it.
503 @end itemize
505   These rules also apply when you use RCS in its ``non-locking'' mode,
506 except that changes are not automatically merged from the repository.
507 Nothing informs you if another user has committed changes in the same
508 file since you began editing it; when you commit your revision, his
509 changes are removed (however, they remain in the repository and are
510 thus not irrevocably lost).  Therefore, you must verify that the
511 current revision is unchanged before committing your changes.  In
512 addition, locking is possible with RCS even in this mode: @kbd{C-x v
513 v} with an unmodified file locks the file, just as it does with RCS in
514 its normal locking mode (@pxref{VC With A Locking VCS}).
516 @node VC With A Locking VCS
517 @subsubsection Basic Version Control with Locking
519   On a locking-based version control system (such as SCCS, and RCS in
520 its default mode), @kbd{C-x v v} does the following:
522 @itemize @bullet
523 @item
524 If there is more than one file in the VC fileset and the files have
525 inconsistent version control statuses, signal an error.
527 @item
528 If each file in the VC fileset is not registered with a version
529 control system, register the VC fileset.  @xref{Registering}.  If
530 Emacs cannot find a system to register under, it prompts for a
531 repository type, creates a new repository, and registers the VC
532 fileset with it.
534 @item
535 If each file is registered and unlocked, lock it and make it writable,
536 so that you can begin to edit it.
538 @item
539 If each file is locked by you and contains changes, commit the
540 changes.  To do this, Emacs pops up a @file{*vc-log*} buffer; type the
541 desired log entry for the new revision, followed by @kbd{C-c C-c} to
542 commit (@pxref{Log Buffer}).
544 @item
545 If each file is locked by you, but you have not changed it, release
546 the lock and make the file read-only again.
548 @item
549 If each file is locked by another user, ask whether you want to
550 ``steal the lock''.  If you say yes, the file becomes locked by you,
551 and a warning message is sent to the user who had formerly locked the
552 file.
553 @end itemize
555   These rules also apply when you use CVS in locking mode, except
556 that CVS does not support stealing locks.
558 @node Advanced C-x v v
559 @subsubsection Advanced Control in @kbd{C-x v v}
561 @cindex revision ID in version control
562   When you give a prefix argument to @code{vc-next-action} (@kbd{C-u
563 C-x v v}), it still performs the next logical version control
564 operation, but accepts additional arguments to specify precisely how
565 to do the operation.
567 @itemize @bullet
568 @item
569 @cindex specific version control system
570 You can specify the name of a version control system.  This is useful
571 if the fileset can be managed by more than one version control system,
572 and Emacs fails to detect the correct one.
574 @item
575 Otherwise, if using CVS or RCS, you can specify a revision ID.
577 If the fileset is modified (or locked), this makes Emacs commit with
578 that revision ID@.  You can create a new branch by supplying an
579 appropriate revision ID (@pxref{Branches}).
581 If the fileset is unmodified (and unlocked), this checks the specified
582 revision into the working tree.  You can also specify a revision on
583 another branch by giving its revision or branch ID (@pxref{Switching
584 Branches}).  An empty argument (i.e., @kbd{C-u C-x v v @key{RET}})
585 checks out the latest (``head'') revision on the current branch.
587 This signals an error on a decentralized version control system.
588 Those systems do not let you specify your own revision IDs, nor do
589 they use the concept of ``checking out'' individual files.
590 @end itemize
592 @node Log Buffer
593 @subsection Features of the Log Entry Buffer
595 @cindex C-c C-c @r{(Log Edit mode)}
596 @findex log-edit-done
597   When you tell VC to commit a change, it pops up a buffer named
598 @file{*vc-log*}.  In this buffer, you should write a @dfn{log entry}
599 describing the changes you have made (@pxref{Why Version Control?}).
600 After you are done, type @kbd{C-c C-c} (@code{log-edit-done}) to exit
601 the buffer and commit the change, together with your log entry.
603 @cindex Log Edit mode
604 @cindex mode, Log Edit
605 @vindex vc-log-mode-hook
606 @c FIXME: Mention log-edit-mode-hook here?  --xfq
607   The major mode for the @file{*vc-log*} buffer is Log Edit mode, a
608 variant of Text mode (@pxref{Text Mode}).  On entering Log Edit mode,
609 Emacs runs the hooks @code{text-mode-hook} and @code{vc-log-mode-hook}
610 (@pxref{Hooks}).
612   In the @file{*vc-log*} buffer, you can write one or more @dfn{header
613 lines}, specifying additional information to be supplied to the
614 version control system.  Each header line must occupy a single line at
615 the top of the buffer; the first line that is not a header line is
616 treated as the start of the log entry.  For example, the following
617 header line states that the present change was not written by you, but
618 by another developer:
620 @smallexample
621 Author: J. R. Hacker <jrh@@example.com>
622 @end smallexample
624 @noindent
625 Apart from the @samp{Author} header, Emacs recognizes the headers
626 @samp{Date} (a manually-specified commit time) and @samp{Fixes} (a
627 reference to a bug fixed by the change).  Not all version control
628 systems recognize all headers: Bazaar recognizes all three headers,
629 while Git, Mercurial, and Monotone recognize only @samp{Author} and
630 @samp{Date}.  If you specify a header for a system that does not
631 support it, the header is treated as part of the log entry.
633 @kindex C-c C-f @r{(Log Edit mode)}
634 @findex log-edit-show-files
635 @kindex C-c C-d @r{(Log Edit mode)}
636 @findex log-edit-show-diff
637   While in the @file{*vc-log*} buffer, the ``current VC fileset'' is
638 considered to be the fileset that will be committed if you type
639 @w{@kbd{C-c C-c}}.  To view a list of the files in the VC fileset,
640 type @w{@kbd{C-c C-f}} (@code{log-edit-show-files}).  To view a diff
641 of changes between the VC fileset and the version from which you
642 started editing (@pxref{Old Revisions}), type @kbd{C-c C-d}
643 (@code{log-edit-show-diff}).
645 @kindex C-c C-a @r{(Log Edit mode)}
646 @findex log-edit-insert-changelog
647   If the VC fileset includes one or more @file{ChangeLog} files
648 (@pxref{Change Log}), type @kbd{C-c C-a}
649 (@code{log-edit-insert-changelog}) to pull the relevant entries into
650 the @file{*vc-log*} buffer.  If the topmost item in each
651 @file{ChangeLog} was made under your user name on the current date,
652 this command searches that item for entries matching the file(s) to be
653 committed, and inserts them.
654 @ifnottex
655 If you are using CVS or RCS, see @ref{Change Logs and VC}, for the
656 opposite way of working---generating ChangeLog entries from the Log
657 Edit buffer.
658 @end ifnottex
660   To abort a commit, just @emph{don't} type @kbd{C-c C-c} in that
661 buffer.  You can switch buffers and do other editing.  As long as you
662 don't try to make another commit, the entry you were editing remains
663 in the @file{*vc-log*} buffer, and you can go back to that buffer at
664 any time to complete the commit.
666 @kindex M-n @r{(Log Edit mode)}
667 @kindex M-p @r{(Log Edit mode)}
668 @kindex M-s @r{(Log Edit mode)}
669 @kindex M-r @r{(Log Edit mode)}
670   You can also browse the history of previous log entries to duplicate
671 a commit comment.  This can be useful when you want to make several
672 commits with similar comments.  The commands @kbd{M-n}, @kbd{M-p},
673 @kbd{M-s} and @kbd{M-r} for doing this work just like the minibuffer
674 history commands (@pxref{Minibuffer History}), except that they are
675 used outside the minibuffer.
677 @node Registering
678 @subsection Registering a File for Version Control
680 @table @kbd
681 @item C-x v i
682 Register the visited file for version control.
683 @end table
685 @kindex C-x v i
686 @findex vc-register
687   The command @kbd{C-x v i} (@code{vc-register}) @dfn{registers} each
688 file in the current VC fileset, placing it under version control.
689 This is essentially equivalent to the action of @kbd{C-x v v} on an
690 unregistered VC fileset (@pxref{Basic VC Editing}), except that if the
691 VC fileset is already registered, @kbd{C-x v i} signals an error
692 whereas @kbd{C-x v v} performs some other action.
694   To register a file, Emacs must choose a version control system.  For
695 a multi-file VC fileset, the VC Directory buffer specifies the system
696 to use (@pxref{VC Directory Mode}).  For a single-file VC fileset, if
697 the file's directory already contains files registered in a version
698 control system, or if the directory is part of a directory tree
699 controlled by a version control system, Emacs chooses that system.  In
700 the event that more than one version control system is applicable,
701 Emacs uses the one that appears first in the variable
702 @iftex
703 @code{vc-handled-backends}.
704 @end iftex
705 @ifnottex
706 @code{vc-handled-backends} (@pxref{Customizing VC}).
707 @end ifnottex
708 If Emacs cannot find a version control system to register the file
709 under, it prompts for a repository type, creates a new repository, and
710 registers the file into that repository.
712   On most version control systems, registering a file with @kbd{C-x v
713 i} or @kbd{C-x v v} adds it to the ``working tree'' but not to the
714 repository.  Such files are labeled as @samp{added} in the VC
715 Directory buffer, and show a revision ID of @samp{@@@@} in the mode
716 line.  To make the registration take effect in the repository, you
717 must perform a commit (@pxref{Basic VC Editing}).  Note that a single
718 commit can include both file additions and edits to existing files.
720   On a locking-based version control system (@pxref{VCS Merging}),
721 registering a file leaves it unlocked and read-only.  Type @kbd{C-x v
722 v} to start editing it.
724 @node Old Revisions
725 @subsection Examining And Comparing Old Revisions
727 @table @kbd
728 @item C-x v =
729 Compare the work files in the current VC fileset with the versions you
730 started from (@code{vc-diff}).  With a prefix argument, prompt for two
731 revisions of the current VC fileset and compare them.  You can also
732 call this command from a Dired buffer (@pxref{Dired}).
734 @ifnottex
735 @item M-x vc-ediff
736 Like @kbd{C-x v =}, but using Ediff.  @xref{Top,, Ediff, ediff, The
737 Ediff Manual}.
738 @end ifnottex
740 @item C-x v D
741 Compare the entire working tree to the revision you started from
742 (@code{vc-root-diff}).  With a prefix argument, prompt for two
743 revisions and compare their trees.
745 @item C-x v ~
746 Prompt for a revision of the current file, and visit it in a separate
747 buffer (@code{vc-revision-other-window}).
749 @item C-x v g
750 Display an annotated version of the current file: for each line, show
751 the latest revision in which it was modified (@code{vc-annotate}).
752 @end table
754 @findex vc-diff
755 @kindex C-x v =
756   @kbd{C-x v =} (@code{vc-diff}) displays a @dfn{diff} which compares
757 each work file in the current VC fileset to the version(s) from which
758 you started editing.  The diff is displayed in another window, in a
759 Diff mode buffer (@pxref{Diff Mode}) named @file{*vc-diff*}.  The
760 usual Diff mode commands are available in this buffer.  In particular,
761 the @kbd{g} (@code{revert-buffer}) command performs the file
762 comparison again, generating a new diff.
764 @kindex C-u C-x v =
765   To compare two arbitrary revisions of the current VC fileset, call
766 @code{vc-diff} with a prefix argument: @kbd{C-u C-x v =}.  This
767 prompts for two revision IDs (@pxref{VCS Concepts}), and displays a
768 diff between those versions of the fileset.  This will not work
769 reliably for multi-file VC filesets, if the version control system is
770 file-based rather than changeset-based (e.g., CVS), since then
771 revision IDs for different files would not be related in any
772 meaningful way.
774   Instead of the revision ID, some version control systems let you
775 specify revisions in other formats.  For instance, under Bazaar you
776 can enter @samp{date:yesterday} for the argument to @kbd{C-u C-x v =}
777 (and related commands) to specify the first revision committed after
778 yesterday.  See the documentation of the version control system for
779 details.
781   If you invoke @kbd{C-x v =} or @kbd{C-u C-x v =} from a Dired buffer
782 (@pxref{Dired}), the file listed on the current line is treated as the
783 current VC fileset.
785 @ifnottex
786 @findex vc-ediff
787   @kbd{M-x vc-ediff} works like @kbd{C-x v =}, except that it uses an
788 Ediff session.  @xref{Top,, Ediff, ediff, The Ediff Manual}.
789 @end ifnottex
791 @findex vc-root-diff
792 @kindex C-x v D
793   @kbd{C-x v D} (@code{vc-root-diff}) is similar to @kbd{C-x v =}, but
794 it displays the changes in the entire current working tree (i.e., the
795 working tree containing the current VC fileset).  If you invoke this
796 command from a Dired buffer, it applies to the working tree containing
797 the directory.
799 @vindex vc-diff-switches
800   You can customize the @command{diff} options that @kbd{C-x v =} and
801 @kbd{C-x v D} use for generating diffs.  The options used are taken
802 from the first non-@code{nil} value amongst the variables
803 @code{vc-@var{backend}-diff-switches}, @code{vc-diff-switches}, and
804 @code{diff-switches} (@pxref{Comparing Files}), in that order.  Here,
805 @var{backend} stands for the relevant version control system,
806 e.g., @code{bzr} for Bazaar.  Since @code{nil} means to check the
807 next variable in the sequence, either of the first two may use the
808 value @code{t} to mean no switches at all.  Most of the
809 @code{vc-@var{backend}-diff-switches} variables default to @code{nil},
810 but some default to @code{t}; these are for version control systems
811 whose @code{diff} implementations do not accept common diff options,
812 such as Subversion.
814 @findex vc-revision-other-window
815 @kindex C-x v ~
816   To directly examine an older version of a file, visit the work file
817 and type @kbd{C-x v ~ @var{revision} @key{RET}}
818 (@code{vc-revision-other-window}).  This retrieves the file version
819 corresponding to @var{revision}, saves it to
820 @file{@var{filename}.~@var{revision}~}, and visits it in a separate
821 window.
823 @findex vc-annotate
824 @kindex C-x v g
825   Many version control systems allow you to view files @dfn{annotated}
826 with per-line revision information, by typing @kbd{C-x v g}
827 (@code{vc-annotate}).  This creates a new buffer (the ``annotate
828 buffer'') displaying the file's text, with each line colored to show
829 how old it is.  Red text is new, blue is old, and intermediate colors
830 indicate intermediate ages.  By default, the color is scaled over the
831 full range of ages, such that the oldest changes are blue, and the
832 newest changes are red.
834   When you give a prefix argument to this command, Emacs reads two
835 arguments using the minibuffer: the revision to display and annotate
836 (instead of the current file contents), and the time span in days the
837 color range should cover.
839   From the annotate buffer, these and other color scaling options are
840 available from the @samp{VC-Annotate} menu.  In this buffer, you can
841 also use the following keys to browse the annotations of past revisions,
842 view diffs, or view log entries:
844 @table @kbd
845 @item p
846 Annotate the previous revision, i.e., the revision before the one
847 currently annotated.  A numeric prefix argument is a repeat count, so
848 @kbd{C-u 10 p} would take you back 10 revisions.
850 @item n
851 Annotate the next revision, i.e., the revision after the one
852 currently annotated.  A numeric prefix argument is a repeat count.
854 @item j
855 Annotate the revision indicated by the current line.
857 @item a
858 Annotate the revision before the one indicated by the current line.
859 This is useful to see the state the file was in before the change on
860 the current line was made.
862 @item f
863 Show in a buffer the file revision indicated by the current line.
865 @item d
866 Display the diff between the current line's revision and the previous
867 revision.  This is useful to see what the current line's revision
868 actually changed in the file.
870 @item D
871 Display the diff between the current line's revision and the previous
872 revision for all files in the changeset (for VC systems that support
873 changesets).  This is useful to see what the current line's revision
874 actually changed in the tree.
876 @item l
877 Show the log of the current line's revision.  This is useful to see
878 the author's description of the changes in the revision on the current
879 line.
881 @item w
882 Annotate the working revision--the one you are editing.  If you used
883 @kbd{p} and @kbd{n} to browse to other revisions, use this key to
884 return to your working revision.
886 @item v
887 Toggle the annotation visibility.  This is useful for looking just at
888 the file contents without distraction from the annotations.
889 @end table
891 @node VC Change Log
892 @subsection VC Change Log
894 @table @kbd
895 @item C-x v l
896 Display the change history for the current fileset
897 (@code{vc-print-log}).
899 @item C-x v L
900 Display the change history for the current repository
901 (@code{vc-print-root-log}).
903 @item C-x v I
904 Display the changes that a pull operation will retrieve
905 (@code{vc-log-incoming}).
907 @item C-x v O
908 Display the changes that will be sent by the next push operation
909 (@code{vc-log-outgoing}).
910 @end table
912 @kindex C-x v l
913 @findex vc-print-log
914   @kbd{C-x v l} (@code{vc-print-log}) displays a buffer named
915 @file{*vc-change-log*}, showing the history of changes made to the
916 current file, including who made the changes, the dates, and the log
917 entry for each change (these are the same log entries you would enter
918 via the @file{*vc-log*} buffer; @pxref{Log Buffer}).  Point is
919 centered at the revision of the file currently being visited.  With a
920 prefix argument, the command prompts for the revision to center on,
921 and the maximum number of revisions to display.
923   If you call @kbd{C-x v l} from a VC Directory buffer (@pxref{VC
924 Directory Mode}) or a Dired buffer (@pxref{Dired}), it applies to the
925 file listed on the current line.
927 @findex vc-print-root-log
928 @findex log-view-toggle-entry-display
929   @kbd{C-x v L} (@code{vc-print-root-log}) displays a
930 @file{*vc-change-log*} buffer showing the history of the entire
931 version-controlled directory tree (RCS, SCCS, and CVS do not support
932 this feature).  With a prefix argument, the command prompts for the
933 maximum number of revisions to display.
935   The @kbd{C-x v L} history is shown in a compact form, usually
936 showing only the first line of each log entry.  However, you can type
937 @key{RET} (@code{log-view-toggle-entry-display}) in the
938 @file{*vc-change-log*} buffer to reveal the entire log entry for the
939 revision at point.  A second @key{RET} hides it again.
941   On a decentralized version control system, the @kbd{C-x v I}
942 (@code{vc-log-incoming}) command displays a log buffer showing the
943 changes that will be applied, the next time you run the version
944 control system's ``pull'' command to get new revisions from another
945 repository (@pxref{VC Pull}).  This other repository is the default
946 one from which changes are pulled, as defined by the version control
947 system; with a prefix argument, @code{vc-log-incoming} prompts for a
948 specific repository.  Similarly, @kbd{C-x v O}
949 (@code{vc-log-outgoing}) shows the changes that will be sent to
950 another repository, the next time you run the ``push'' command; with a
951 prefix argument, it prompts for a specific destination repository.
953   In the @file{*vc-change-log*} buffer, you can use the following keys
954 to move between the logs of revisions and of files, and to examine and
955 compare past revisions (@pxref{Old Revisions}):
957 @table @kbd
958 @item p
959 Move to the previous revision entry.  (Revision entries in the log
960 buffer are usually in reverse-chronological order, so the previous
961 revision-item usually corresponds to a newer revision.)  A numeric
962 prefix argument is a repeat count.
964 @item n
965 Move to the next revision entry.  A numeric prefix argument is a
966 repeat count.
968 @item P
969 Move to the log of the previous file, if showing logs for a multi-file
970 VC fileset.  Otherwise, just move to the beginning of the log.  A
971 numeric prefix argument is a repeat count.
973 @item N
974 Move to the log of the next file, if showing logs for a multi-file VC
975 fileset.  A numeric prefix argument is a repeat count.
977 @item a
978 Annotate the revision on the current line (@pxref{Old Revisions}).
980 @item e
981 Modify the change comment displayed at point.  Note that not all VC
982 systems support modifying change comments.
984 @item f
985 Visit the revision indicated at the current line.
987 @item d
988 Display a diff between the revision at point and the next earlier
989 revision, for the specific file.
991 @item D
992 Display the changeset diff between the revision at point and the next
993 earlier revision.  This shows the changes to all files made in that
994 revision.
996 @item @key{RET}
997 In a compact-style log buffer (e.g., the one created by @kbd{C-x v
998 L}), toggle between showing and hiding the full log entry for the
999 revision at point.
1000 @end table
1002 @vindex vc-log-show-limit
1003 Because fetching many log entries can be slow, the
1004 @file{*vc-change-log*} buffer displays no more than 2000 revisions by
1005 default.  The variable @code{vc-log-show-limit} specifies this limit;
1006 if you set the value to zero, that removes the limit.  You can also
1007 increase the number of revisions shown in an existing
1008 @file{*vc-change-log*} buffer by clicking on the @samp{Show 2X
1009 entries} or @samp{Show unlimited entries} buttons at the end of the
1010 buffer.  However, RCS, SCCS, and CVS do not support this feature.
1012 @node VC Undo
1013 @subsection Undoing Version Control Actions
1015 @table @kbd
1016 @item C-x v u
1017 Revert the work file(s) in the current VC fileset to the last revision
1018 (@code{vc-revert}).
1019 @end table
1021 @kindex C-x v u
1022 @findex vc-revert
1023 @vindex vc-revert-show-diff
1024   If you want to discard all the changes you have made to the current
1025 VC fileset, type @kbd{C-x v u} (@code{vc-revert-buffer}).  This shows
1026 you a diff between the work file(s) and the revision from which you
1027 started editing, and asks for confirmation for discarding the changes.
1028 If you agree, the fileset is reverted.  If you don't want @kbd{C-x v
1029 u} to show a diff, set the variable @code{vc-revert-show-diff} to
1030 @code{nil} (you can still view the diff directly with @kbd{C-x v =};
1031 @pxref{Old Revisions}).  Note that @kbd{C-x v u} cannot be reversed
1032 with the usual undo commands (@pxref{Undo}), so use it with care.
1034   On locking-based version control systems, @kbd{C-x v u} leaves files
1035 unlocked; you must lock again to resume editing.  You can also use
1036 @kbd{C-x v u} to unlock a file if you lock it and then decide not to
1037 change it.
1039 @node VC Ignore
1040 @subsection Ignore Version Control Files
1042 @table @kbd
1043 @item C-x v G
1044 Ignore a file under current version control system.  (@code{vc-ignore}).
1045 @end table
1047 @kindex C-x v G
1048 @findex vc-ignore
1049   Many source trees contain some files that do not need to be
1050 versioned, such as editor backups, object or bytecode files, and built
1051 programs.  You can simply not add them, but then they'll always crop
1052 up as unknown files.  You can also tell the version control system to
1053 ignore these files by adding them to the ignore file at the top of the
1054 tree.  @kbd{C-x v G} (@code{vc-ignore}) can help you do this.  When
1055 called with a prefix argument, you can remove a file from the ignored
1056 file list.
1058 @node VC Directory Mode
1059 @subsection VC Directory Mode
1061 @cindex VC Directory buffer
1062   The @dfn{VC Directory buffer} is a specialized buffer for viewing
1063 the version control statuses of the files in a directory tree, and
1064 performing version control operations on those files.  In particular,
1065 it is used to specify multi-file VC filesets for commands like
1066 @w{@kbd{C-x v v}} to act on (@pxref{VC Directory Commands}).
1068 @kindex C-x v d
1069 @findex vc-dir
1070   To use the VC Directory buffer, type @kbd{C-x v d} (@code{vc-dir}).
1071 This reads a directory name using the minibuffer, and switches to a VC
1072 Directory buffer for that directory.  By default, the buffer is named
1073 @file{*vc-dir*}.  Its contents are described
1074 @iftex
1075 below.
1076 @end iftex
1077 @ifnottex
1078 in @ref{VC Directory Buffer}.
1079 @end ifnottex
1081   The @code{vc-dir} command automatically detects the version control
1082 system to be used in the specified directory.  In the event that more
1083 than one system is being used in the directory, you should invoke the
1084 command with a prefix argument, @kbd{C-u C-x v d}; this prompts for
1085 the version control system which the VC Directory buffer should use.
1087 @ifnottex
1088 @cindex PCL-CVS
1089 @pindex cvs
1090 @cindex CVS directory mode
1091   In addition to the VC Directory buffer, Emacs has a similar facility
1092 called PCL-CVS which is specialized for CVS@.  @xref{Top, , About
1093 PCL-CVS, pcl-cvs, PCL-CVS---The Emacs Front-End to CVS}.
1094 @end ifnottex
1096 @menu
1097 * Buffer: VC Directory Buffer.      What the buffer looks like and means.
1098 * Commands: VC Directory Commands.  Commands to use in a VC directory buffer.
1099 @end menu
1101 @node VC Directory Buffer
1102 @subsubsection The VC Directory Buffer
1104   The VC Directory buffer contains a list of version-controlled files
1105 and their version control statuses.  It lists files in the current
1106 directory (the one specified when you called @kbd{C-x v d}) and its
1107 subdirectories, but only those with a ``noteworthy'' status.  Files
1108 that are up-to-date (i.e., the same as in the repository) are
1109 omitted.  If all the files in a subdirectory are up-to-date, the
1110 subdirectory is not listed either.  As an exception, if a file has
1111 become up-to-date as a direct result of a VC command, it is listed.
1113   Here is an example of a VC Directory buffer listing:
1115 @smallexample
1116 @group
1117                      ./
1118     edited           configure.ac
1119 *   added            README
1120     unregistered     temp.txt
1121                      src/
1122 *   edited           src/main.c
1123 @end group
1124 @end smallexample
1126 @noindent
1127 Two work files have been modified but not committed:
1128 @file{configure.ac} in the current directory, and @file{foo.c} in the
1129 @file{src/} subdirectory.  The file named @file{README} has been added
1130 but is not yet committed, while @file{temp.txt} is not under version
1131 control (@pxref{Registering}).
1133 The @samp{*} characters next to the entries for @file{README} and
1134 @file{src/main.c} indicate that the user has marked out these files as
1135 the current VC fileset
1136 @iftex
1137 (see below).
1138 @end iftex
1139 @ifnottex
1140 (@pxref{VC Directory Commands}).
1141 @end ifnottex
1143   The above example is typical for a decentralized version control
1144 system like Bazaar, Git, or Mercurial.  Other systems can show other
1145 statuses.  For instance, CVS shows the @samp{needs-update} status if
1146 the repository has changes that have not been applied to the work
1147 file.  RCS and SCCS show the name of the user locking a file as its
1148 status.
1150 @ifnottex
1151 @vindex vc-stay-local
1152 @vindex vc-cvs-stay-local
1153   On CVS and Subversion, the @code{vc-dir} command normally contacts
1154 the repository, which may be on a remote machine, to check for
1155 updates.  If you change the variable @code{vc-stay-local} or
1156 @code{vc-cvs-stay-local} (for CVS) to @code{nil} (@pxref{CVS
1157 Options}), then Emacs avoids contacting a remote repository when
1158 generating the VC Directory buffer (it will still contact it when
1159 necessary, e.g., when doing a commit).  This may be desirable if you
1160 are working offline or the network is slow.
1161 @end ifnottex
1163 @vindex vc-directory-exclusion-list
1164   The VC Directory buffer omits subdirectories listed in the variable
1165 @code{vc-directory-exclusion-list}.  Its default value contains
1166 directories that are used internally by version control systems.
1168 @node VC Directory Commands
1169 @subsubsection VC Directory Commands
1171   Emacs provides several commands for navigating the VC Directory
1172 buffer, and for ``marking'' files as belonging to the current VC
1173 fileset.
1175 @table @kbd
1176 @item n
1177 @itemx @key{SPC}
1178 Move point to the next entry (@code{vc-dir-next-line}).
1180 @item p
1181 Move point to the previous entry (@code{vc-dir-previous-line}).
1183 @item @key{TAB}
1184 Move to the next directory entry (@code{vc-dir-next-directory}).
1186 @item S-@key{TAB}
1187 Move to the previous directory entry
1188 (@code{vc-dir-previous-directory}).
1190 @item @key{RET}
1191 @itemx f
1192 Visit the file or directory listed on the current line
1193 (@code{vc-dir-find-file}).
1195 @item o
1196 Visit the file or directory on the current line, in a separate window
1197 (@code{vc-dir-find-file-other-window}).
1199 @item m
1200 Mark the file or directory on the current line (@code{vc-dir-mark}),
1201 putting it in the current VC fileset.  If the region is active, mark
1202 all files in the region.
1204 A file cannot be marked with this command if it is already in a marked
1205 directory, or one of its subdirectories.  Similarly, a directory
1206 cannot be marked with this command if any file in its tree is marked.
1208 @item M
1209 If point is on a file entry, mark all files with the same status; if
1210 point is on a directory entry, mark all files in that directory tree
1211 (@code{vc-dir-mark-all-files}).  With a prefix argument, mark all
1212 listed files and directories.
1214 @item q
1215 Quit the VC Directory buffer, and bury it (@code{quit-window}).
1217 @item u
1218 Unmark the file or directory on the current line.  If the region is
1219 active, unmark all the files in the region (@code{vc-dir-unmark}).
1221 @item U
1222 If point is on a file entry, unmark all files with the same status; if
1223 point is on a directory entry, unmark all files in that directory tree
1224 (@code{vc-dir-unmark-all-files}).  With a prefix argument, unmark all
1225 files and directories.
1227 @item x
1228 Hide files with @samp{up-to-date} status
1229 (@code{vc-dir-hide-up-to-date}).  With a prefix argument, hide items
1230 whose state is that of the item at point.
1231 @end table
1233 @findex vc-dir-mark
1234 @findex vc-dir-mark-all-files
1235   While in the VC Directory buffer, all the files that you mark with
1236 @kbd{m} (@code{vc-dir-mark}) or @kbd{M} (@code{vc-dir-mark}) are in
1237 the current VC fileset.  If you mark a directory entry with @kbd{m},
1238 all the listed files in that directory tree are in the current VC
1239 fileset.  The files and directories that belong to the current VC
1240 fileset are indicated with a @samp{*} character in the VC Directory
1241 buffer, next to their VC status.  In this way, you can set up a
1242 multi-file VC fileset to be acted on by VC commands like @w{@kbd{C-x v
1243 v}} (@pxref{Basic VC Editing}), @w{@kbd{C-x v =}} (@pxref{Old
1244 Revisions}), and @w{@kbd{C-x v u}} (@pxref{VC Undo}).
1246   The VC Directory buffer also defines some single-key shortcuts for
1247 VC commands with the @kbd{C-x v} prefix: @kbd{=}, @kbd{+}, @kbd{l},
1248 @kbd{i}, @kbd{D}, @kbd{L}, @kbd{G}, @kbd{I} and @kbd{v}.
1250   For example, you can commit a set of edited files by opening a VC
1251 Directory buffer, where the files are listed with the @samp{edited}
1252 status; marking the files; and typing @kbd{v} or @kbd{C-x v v}
1253 (@code{vc-next-action}).  If the version control system is
1254 changeset-based, Emacs will commit the files in a single revision.
1256   While in the VC Directory buffer, you can also perform search and
1257 replace on the current VC fileset, with the following commands:
1259 @table @kbd
1260 @item S
1261 Search the fileset (@code{vc-dir-search}).
1263 @item Q
1264 Do a regular expression query replace on the fileset
1265 (@code{vc-dir-query-replace-regexp}).
1267 @item M-s a C-s
1268 Do an incremental search on the fileset (@code{vc-dir-isearch}).
1270 @item M-s a C-M-s
1271 Do an incremental regular expression search on the fileset
1272 (@code{vc-dir-isearch-regexp}).
1273 @end table
1275 @noindent
1276 Apart from acting on multiple files, these commands behave much like
1277 their single-buffer counterparts (@pxref{Search}).
1279 @cindex stashes in version control
1280 @cindex shelves in version control
1281   The above commands are also available via the menu bar, and via a
1282 context menu invoked by @kbd{Mouse-2}.  Furthermore, some VC backends
1283 use the menu to provide extra backend-specific commands.  For example,
1284 Git and Bazaar allow you to manipulate @dfn{stashes} and @dfn{shelves}
1285 (where are a way to temporarily put aside uncommitted changes, and
1286 bring them back at a later time).
1288 @node Branches
1289 @subsection Version Control Branches
1290 @cindex branch (version control)
1292   One use of version control is to support multiple independent lines
1293 of development, which are called @dfn{branches}.  Amongst other
1294 things, branches can be used for maintaining separate ``stable'' and
1295 ``development'' versions of a program, and for developing unrelated
1296 features in isolation from one another.
1298   VC's support for branch operations is currently fairly limited.  For
1299 decentralized version control systems, it provides commands for
1300 @dfn{updating} one branch with the contents of another, and for
1301 @dfn{merging} the changes made to two different branches
1302 (@pxref{Merging}).  For centralized version control systems, it
1303 supports checking out different branches and committing into new or
1304 different branches.
1306 @menu
1307 * Switching Branches::    How to get to another existing branch.
1308 * VC Pull::               Updating the contents of a branch.
1309 * Merging::               Transferring changes between branches.
1310 * Creating Branches::     How to start a new branch.
1311 @end menu
1313 @node Switching Branches
1314 @subsubsection Switching between Branches
1316   The various version control systems differ in how branches are
1317 implemented, and these differences cannot be entirely concealed by VC.
1319   On some decentralized version control systems, including Bazaar and
1320 Mercurial in its normal mode of operation, each branch has its own
1321 working directory tree, so switching between branches just involves
1322 switching directories.  On Git, branches are normally @dfn{co-located}
1323 in the same directory, and switching between branches is done using
1324 the @command{git checkout} command, which changes the contents of the
1325 working tree to match the branch you switch to.  Bazaar also supports
1326 co-located branches, in which case the @command{bzr switch} command
1327 will switch branches in the current directory.  With Subversion, you
1328 switch to another branch using the @command{svn switch} command.
1330   The VC command to switch to another branch in the current directory
1331 is @kbd{C-x v r @var{branch-name} @key{RET}} (@code{vc-retrieve-tag}).
1333   On centralized version control systems, you can also switch between
1334 branches by typing @kbd{C-u C-x v v} in an up-to-date work file
1335 (@pxref{Advanced C-x v v}), and entering the revision ID for a
1336 revision on another branch.  On CVS, for instance, revisions on the
1337 @dfn{trunk} (the main line of development) normally have IDs of the
1338 form 1.1, 1.2, 1.3, @dots{}, while the first branch created from (say)
1339 revision 1.2 has revision IDs 1.2.1.1, 1.2.1.2, @dots{}, the second
1340 branch created from revision 1.2 has revision IDs 1.2.2.1, 1.2.2.2,
1341 @dots{}, and so forth.  You can also specify the @dfn{branch ID},
1342 which is a branch revision ID omitting its final component
1343 (e.g., 1.2.1), to switch to the latest revision on that branch.
1345   On a locking-based system, switching to a different branch also
1346 unlocks (write-protects) the working tree.
1348   Once you have switched to a branch, VC commands will apply to that
1349 branch until you switch away; for instance, any VC filesets that you
1350 commit will be committed to that specific branch.
1352 @node VC Pull
1353 @subsubsection Pulling Changes into a Branch
1355 @table @kbd
1356 @item C-x v +
1357 On a decentralized version control system, update the current branch
1358 by ``pulling in'' changes from another location.
1360 On a centralized version control system, update the current VC
1361 fileset.
1362 @end table
1364 @kindex C-x v +
1365 @findex vc-pull
1366   On a decentralized version control system, the command @kbd{C-x v +}
1367 (@code{vc-pull}) updates the current branch and working tree.  It is
1368 typically used to update a copy of a remote branch.  If you supply a
1369 prefix argument, the command prompts for the exact version control
1370 command to use, which lets you specify where to pull changes from.
1371 Otherwise, it pulls from a default location determined by the version
1372 control system.
1374   Amongst decentralized version control systems, @kbd{C-x v +} is
1375 currently supported only by Bazaar, Git, and Mercurial.  On Bazaar, it
1376 calls @command{bzr pull} for ordinary branches (to pull from a master
1377 branch into a mirroring branch), and @command{bzr update} for a bound
1378 branch (to pull from a central repository).  On Git, it calls
1379 @command{git pull} to fetch changes from a remote repository and merge
1380 it into the current branch.  On Mercurial, it calls @command{hg pull
1381 -u} to fetch changesets from the default remote repository and update
1382 the working directory.
1384   Prior to pulling, you can use @kbd{C-x v I} (@code{vc-log-incoming})
1385 to view a log buffer of the changes to be applied.  @xref{VC Change
1386 Log}.
1388   On a centralized version control system like CVS, @kbd{C-x v +}
1389 updates the current VC fileset from the repository.
1391 @node Merging
1392 @subsubsection Merging Branches
1393 @cindex merging changes
1395 @table @kbd
1396 @item C-x v m
1397 On a decentralized version control system, merge changes from another
1398 branch into the current one.
1400 On a centralized version control system, merge changes from another
1401 branch into the current VC fileset.
1402 @end table
1404   While developing a branch, you may sometimes need to @dfn{merge} in
1405 changes that have already been made in another branch.  This is not a
1406 trivial operation, as overlapping changes may have been made to the
1407 two branches.
1409   On a decentralized version control system, merging is done with the
1410 command @kbd{C-x v m} (@code{vc-merge}).  On Bazaar, this prompts for
1411 the exact arguments to pass to @command{bzr merge}, offering a
1412 sensible default if possible.  On Git, this prompts for the name of a
1413 branch to merge from, with completion (based on the branch names known
1414 to the current repository).  The output from running the merge command
1415 is shown in a separate buffer.
1417   On a centralized version control system like CVS, @kbd{C-x v m}
1418 prompts for a branch ID, or a pair of revision IDs (@pxref{Switching
1419 Branches}); then it finds the changes from that branch, or the changes
1420 between the two revisions you specified, and merges those changes into
1421 the current VC fileset.  If you just type @key{RET}, Emacs simply
1422 merges any changes that were made on the same branch since you checked
1423 the file out.
1425 @cindex conflicts
1426 @cindex resolving conflicts
1427   Immediately after performing a merge, only the working tree is
1428 modified, and you can review the changes produced by the merge with
1429 @kbd{C-x v D} and related commands (@pxref{Old Revisions}).  If the
1430 two branches contained overlapping changes, merging produces a
1431 @dfn{conflict}; a warning appears in the output of the merge command,
1432 and @dfn{conflict markers} are inserted into each affected work file,
1433 surrounding the two sets of conflicting changes.  You must then
1434 resolve the conflict by editing the conflicted files.  Once you are
1435 done, the modified files must be committed in the usual way for the
1436 merge to take effect (@pxref{Basic VC Editing}).
1438 @node Creating Branches
1439 @subsubsection Creating New Branches
1441   On centralized version control systems like CVS, Emacs supports
1442 creating new branches as part of a commit operation.  When committing
1443 a modified VC fileset, type @kbd{C-u C-x v v} (@code{vc-next-action}
1444 with a prefix argument; @pxref{Advanced C-x v v}).  Then Emacs prompts
1445 for a revision ID for the new revision.  You should specify a suitable
1446 branch ID for a branch starting at the current revision.  For example,
1447 if the current revision is 2.5, the branch ID should be 2.5.1, 2.5.2,
1448 and so on, depending on the number of existing branches at that point.
1450   To create a new branch at an older revision (one that is no longer
1451 the head of a branch), first select that revision (@pxref{Switching
1452 Branches}).  Your procedure will then differ depending on whether you
1453 are using a locking or merging-based VCS.
1455   On a locking VCS, you will need to lock the old revision branch with
1456 @kbd{C-x v v}.  You'll be asked to confirm, when you lock the old
1457 revision, that you really mean to create a new branch---if you say no,
1458 you'll be offered a chance to lock the latest revision instead.  On a
1459 merging-based VCS you will skip this step.
1461   Then make your changes and type @kbd{C-x v v} again to commit a new
1462 revision.  This creates a new branch starting from the selected
1463 revision.
1465   After the branch is created, subsequent commits create new revisions
1466 on that branch.  To leave the branch, you must explicitly select a
1467 different revision with @kbd{C-u C-x v v}.
1469 @ifnottex
1470 @include vc1-xtra.texi
1471 @end ifnottex
1473 @node Change Log
1474 @section Change Logs
1476 @cindex change log
1477   Many software projects keep a @dfn{change log}.  This is a file,
1478 normally named @file{ChangeLog}, containing a chronological record of
1479 when and how the program was changed.  Sometimes, these files are
1480 automatically generated from the change log entries stored in version
1481 control systems, or are used to generate these change log entries.
1482 Sometimes, there are several change log files, each recording the
1483 changes in one directory or directory tree.
1485 @menu
1486 * Change Log Commands:: Commands for editing change log files.
1487 * Format of ChangeLog:: What the change log file looks like.
1488 @end menu
1490 @node Change Log Commands
1491 @subsection Change Log Commands
1493 @kindex C-x 4 a
1494 @findex add-change-log-entry-other-window
1495   The Emacs command @kbd{C-x 4 a} adds a new entry to the change log
1496 file for the file you are editing
1497 (@code{add-change-log-entry-other-window}).  If that file is actually
1498 a backup file, it makes an entry appropriate for the file's
1499 parent---that is useful for making log entries for functions that
1500 have been deleted in the current version.
1502   @kbd{C-x 4 a} visits the change log file and creates a new entry
1503 unless the most recent entry is for today's date and your name.  It
1504 also creates a new item for the current file.  For many languages, it
1505 can even guess the name of the function or other object that was
1506 changed.
1508 @vindex add-log-keep-changes-together
1509   When the variable @code{add-log-keep-changes-together} is
1510 non-@code{nil}, @kbd{C-x 4 a} adds to any existing item for the file
1511 rather than starting a new item.
1513 You can combine multiple changes of the same nature.  If you don't
1514 enter any text after the initial @kbd{C-x 4 a}, any subsequent
1515 @kbd{C-x 4 a} adds another symbol to the change log entry.
1517 @vindex add-log-always-start-new-record
1518   If @code{add-log-always-start-new-record} is non-@code{nil},
1519 @kbd{C-x 4 a} always makes a new entry, even if the last entry
1520 was made by you and on the same date.
1522 @vindex change-log-version-info-enabled
1523 @vindex change-log-version-number-regexp-list
1524 @cindex file version in change log entries
1525   If the value of the variable @code{change-log-version-info-enabled}
1526 is non-@code{nil}, @kbd{C-x 4 a} adds the file's version number to the
1527 change log entry.  It finds the version number by searching the first
1528 ten percent of the file, using regular expressions from the variable
1529 @code{change-log-version-number-regexp-list}.
1531 @cindex Change Log mode
1532 @findex change-log-mode
1533   The change log file is visited in Change Log mode.  In this major
1534 mode, each bunch of grouped items counts as one paragraph, and each
1535 entry is considered a page.  This facilitates editing the entries.
1536 @kbd{C-j} and auto-fill indent each new line like the previous line;
1537 this is convenient for entering the contents of an entry.
1539 You can use the @code{next-error} command (by default bound to
1540 @kbd{C-x `}) to move between entries in the Change Log, when Change
1541 Log mode is on.  You will jump to the actual site in the file that was
1542 changed, not just to the next Change Log entry.  You can also use
1543 @code{previous-error} to move back in the same list.
1545 @findex change-log-merge
1546   You can use the command @kbd{M-x change-log-merge} to merge other
1547 log files into a buffer in Change Log Mode, preserving the date
1548 ordering of entries.
1550   Version control systems are another way to keep track of changes in
1551 your program and keep a change log.  In the VC log buffer, typing
1552 @kbd{C-c C-a} (@code{log-edit-insert-changelog}) inserts the relevant
1553 Change Log entry, if one exists.  @xref{Log Buffer}.
1555 @node Format of ChangeLog
1556 @subsection Format of ChangeLog
1558   A change log entry starts with a header line that contains the
1559 current date, your name (taken from the variable
1560 @code{add-log-full-name}), and your email address (taken from the
1561 variable @code{add-log-mailing-address}).  Aside from these header
1562 lines, every line in the change log starts with a space or a tab.  The
1563 bulk of the entry consists of @dfn{items}, each of which starts with a
1564 line starting with whitespace and a star.  Here are two entries, both
1565 dated in May 1993, with two items and one item respectively.
1567 @iftex
1568 @medbreak
1569 @end iftex
1570 @smallexample
1571 1993-05-25  Richard Stallman  <rms@@gnu.org>
1573         * man.el: Rename symbols `man-*' to `Man-*'.
1574         (manual-entry): Make prompt string clearer.
1576         * simple.el (blink-matching-paren-distance):
1577         Change default to 12,000.
1579 1993-05-24  Richard Stallman  <rms@@gnu.org>
1581         * vc.el (minor-mode-map-alist): Don't use it if it's void.
1582         (vc-cancel-version): Doc fix.
1583 @end smallexample
1585   One entry can describe several changes; each change should have its
1586 own item, or its own line in an item.  Normally there should be a
1587 blank line between items.  When items are related (parts of the same
1588 change, in different places), group them by leaving no blank line
1589 between them.
1591   You should put a copyright notice and permission notice at the
1592 end of the change log file.  Here is an example:
1594 @smallexample
1595 Copyright 1997, 1998 Free Software Foundation, Inc.
1596 Copying and distribution of this file, with or without modification, are
1597 permitted provided the copyright notice and this notice are preserved.
1598 @end smallexample
1600 @noindent
1601 Of course, you should substitute the proper years and copyright holder.
1603 @node Tags
1604 @section Tags Tables
1605 @cindex tags and tag tables
1607   A @dfn{tag} is a reference to a subunit in a program or in a
1608 document.  In source code, tags reference syntactic elements of the
1609 program: functions, subroutines, data types, macros, etc.  In a
1610 document, tags reference chapters, sections, appendices, etc.  Each
1611 tag specifies the name of the file where the corresponding subunit is
1612 defined, and the position of the subunit's definition in that file.
1614   A @dfn{tags table} records the tags extracted by scanning the source
1615 code of a certain program or a certain document.  Tags extracted from
1616 generated files reference the original files, rather than the
1617 generated files that were scanned during tag extraction.  Examples of
1618 generated files include C files generated from Cweb source files, from
1619 a Yacc parser, or from Lex scanner definitions; @file{.i} preprocessed
1620 C files; and Fortran files produced by preprocessing @file{.fpp}
1621 source files.
1623 @cindex etags
1624   To produce a tags table, you run the @command{etags} shell command
1625 on a document or the source code file.  The @samp{etags} program
1626 writes the tags to a @dfn{tags table file}, or @dfn{tags file} in
1627 short.  The conventional name for a tags file is @file{TAGS}@.
1628 @xref{Create Tags Table}.
1630   Emacs provides many commands for searching and replacing using the
1631 information recorded in tags tables.  For instance, the @kbd{M-.}
1632 (@code{find-tag}) jumps to the location of a specified function
1633 definition in its source file.  @xref{Find Tag}.
1635 @cindex C++ class browser, tags
1636 @cindex tags, C++
1637 @cindex class browser, C++
1638 @cindex Ebrowse
1639   The Ebrowse facility is similar to @command{etags} but specifically
1640 tailored for C++.  @xref{Top,, Ebrowse, ebrowse, Ebrowse User's
1641 Manual}.  The Semantic package provides another way to generate and
1642 use tags, separate from the @command{etags} facility.
1643 @xref{Semantic}.
1645 @menu
1646 * Tag Syntax::          Tag syntax for various types of code and text files.
1647 * Create Tags Table::   Creating a tags table with @command{etags}.
1648 * Etags Regexps::       Create arbitrary tags using regular expressions.
1649 * Select Tags Table::   How to visit a tags table.
1650 * Find Tag::            Commands to find the definition of a specific tag.
1651 * Tags Search::         Using a tags table for searching and replacing.
1652 * List Tags::           Using tags for completion, and listing them.
1653 @end menu
1655 @node Tag Syntax
1656 @subsection Source File Tag Syntax
1658   Here is how tag syntax is defined for the most popular languages:
1660 @itemize @bullet
1661 @item
1662 In C code, any C function or typedef is a tag, and so are definitions of
1663 @code{struct}, @code{union} and @code{enum}.
1664 @code{#define} macro definitions, @code{#undef} and @code{enum}
1665 constants are also
1666 tags, unless you specify @samp{--no-defines} when making the tags table.
1667 Similarly, global variables are tags, unless you specify
1668 @samp{--no-globals}, and so are struct members, unless you specify
1669 @samp{--no-members}.  Use of @samp{--no-globals}, @samp{--no-defines}
1670 and @samp{--no-members} can make the tags table file much smaller.
1672 You can tag function declarations and external variables in addition
1673 to function definitions by giving the @samp{--declarations} option to
1674 @command{etags}.
1676 @item
1677 In C++ code, in addition to all the tag constructs of C code, member
1678 functions are also recognized; member variables are also recognized,
1679 unless you use the @samp{--no-members} option.  Tags for variables and
1680 functions in classes are named @samp{@var{class}::@var{variable}} and
1681 @samp{@var{class}::@var{function}}.  @code{operator} definitions have
1682 tag names like @samp{operator+}.
1684 @item
1685 In Java code, tags include all the constructs recognized in C++, plus
1686 the @code{interface}, @code{extends} and @code{implements} constructs.
1687 Tags for variables and functions in classes are named
1688 @samp{@var{class}.@var{variable}} and @samp{@var{class}.@var{function}}.
1690 @item
1691 In @LaTeX{} documents, the arguments for @code{\chapter},
1692 @code{\section}, @code{\subsection}, @code{\subsubsection},
1693 @code{\eqno}, @code{\label}, @code{\ref}, @code{\cite},
1694 @code{\bibitem}, @code{\part}, @code{\appendix}, @code{\entry},
1695 @code{\index}, @code{\def}, @code{\newcommand}, @code{\renewcommand},
1696 @code{\newenvironment} and @code{\renewenvironment} are tags.
1698 Other commands can make tags as well, if you specify them in the
1699 environment variable @env{TEXTAGS} before invoking @command{etags}.  The
1700 value of this environment variable should be a colon-separated list of
1701 command names.  For example,
1703 @example
1704 TEXTAGS="mycommand:myothercommand"
1705 export TEXTAGS
1706 @end example
1708 @noindent
1709 specifies (using Bourne shell syntax) that the commands
1710 @samp{\mycommand} and @samp{\myothercommand} also define tags.
1712 @item
1713 In Lisp code, any function defined with @code{defun}, any variable
1714 defined with @code{defvar} or @code{defconst}, and in general the
1715 first argument of any expression that starts with @samp{(def} in
1716 column zero is a tag.  As an exception, expressions of the form
1717 @code{(defvar @var{foo})} are treated as declarations, and are only
1718 tagged if the @samp{--declarations} option is given.
1720 @item
1721 In Scheme code, tags include anything defined with @code{def} or with a
1722 construct whose name starts with @samp{def}.  They also include variables
1723 set with @code{set!} at top level in the file.
1724 @end itemize
1726   Several other languages are also supported:
1728 @itemize @bullet
1730 @item
1731 In Ada code, functions, procedures, packages, tasks and types are
1732 tags.  Use the @samp{--packages-only} option to create tags for
1733 packages only.
1735 In Ada, the same name can be used for different kinds of entity
1736 (e.g., for a procedure and for a function).  Also, for things like
1737 packages, procedures and functions, there is the spec (i.e., the
1738 interface) and the body (i.e., the implementation).  To make it
1739 easier to pick the definition you want, Ada tag name have suffixes
1740 indicating the type of entity:
1742 @table @samp
1743 @item /b
1744 package body.
1745 @item /f
1746 function.
1747 @item /k
1748 task.
1749 @item /p
1750 procedure.
1751 @item /s
1752 package spec.
1753 @item /t
1754 type.
1755 @end table
1757   Thus, @kbd{M-x find-tag @key{RET} bidule/b @key{RET}} will go
1758 directly to the body of the package @code{bidule}, while @kbd{M-x
1759 find-tag @key{RET} bidule @key{RET}} will just search for any tag
1760 @code{bidule}.
1762 @item
1763 In assembler code, labels appearing at the start of a line,
1764 followed by a colon, are tags.
1766 @item
1767 In Bison or Yacc input files, each rule defines as a tag the nonterminal
1768 it constructs.  The portions of the file that contain C code are parsed
1769 as C code.
1771 @item
1772 In Cobol code, tags are paragraph names; that is, any word starting in
1773 column 8 and followed by a period.
1775 @item
1776 In Erlang code, the tags are the functions, records and macros defined
1777 in the file.
1779 @item
1780 In Fortran code, functions, subroutines and block data are tags.
1782 @item
1783 In HTML input files, the tags are the @code{title} and the @code{h1},
1784 @code{h2}, @code{h3} headers.  Also, tags are @code{name=} in anchors
1785 and all occurrences of @code{id=}.
1787 @item
1788 In Lua input files, all functions are tags.
1790 @item
1791 In makefiles, targets are tags; additionally, variables are tags
1792 unless you specify @samp{--no-globals}.
1794 @item
1795 In Objective C code, tags include Objective C definitions for classes,
1796 class categories, methods and protocols.  Tags for variables and
1797 functions in classes are named @samp{@var{class}::@var{variable}} and
1798 @samp{@var{class}::@var{function}}.
1800 @item
1801 In Pascal code, the tags are the functions and procedures defined in
1802 the file.
1804 @item
1805 In Perl code, the tags are the packages, subroutines and variables
1806 defined by the @code{package}, @code{sub}, @code{use constant},
1807 @code{my}, and @code{local} keywords.  Use @samp{--globals} if you
1808 want to tag global variables.  Tags for subroutines are named
1809 @samp{@var{package}::@var{sub}}.  The name for subroutines defined in
1810 the default package is @samp{main::@var{sub}}.
1812 @item
1813 In PHP code, tags are functions, classes and defines.  Vars are tags
1814 too, unless you use the @samp{--no-members} option.
1816 @item
1817 In PostScript code, the tags are the functions.
1819 @item
1820 In Prolog code, tags are predicates and rules at the beginning of
1821 line.
1823 @item
1824 In Python code, @code{def} or @code{class} at the beginning of a line
1825 generate a tag.
1826 @end itemize
1828   You can also generate tags based on regexp matching (@pxref{Etags
1829 Regexps}) to handle other formats and languages.
1831 @node Create Tags Table
1832 @subsection Creating Tags Tables
1833 @cindex @command{etags} program
1835   The @command{etags} program is used to create a tags table file.  It knows
1836 the syntax of several languages, as described in
1837 @iftex
1838 the previous section.
1839 @end iftex
1840 @ifnottex
1841 @ref{Tag Syntax}.
1842 @end ifnottex
1843 Here is how to run @command{etags}:
1845 @example
1846 etags @var{inputfiles}@dots{}
1847 @end example
1849 @noindent
1850 The @command{etags} program reads the specified files, and writes a tags
1851 table named @file{TAGS} in the current working directory.  You can
1852 optionally specify a different file name for the tags table by using the
1853 @samp{--output=@var{file}} option; specifying @file{-} as a file name
1854 prints the tags table to standard output.
1856   If the specified files don't exist, @command{etags} looks for
1857 compressed versions of them and uncompresses them to read them.  Under
1858 MS-DOS, @command{etags} also looks for file names like @file{mycode.cgz}
1859 if it is given @samp{mycode.c} on the command line and @file{mycode.c}
1860 does not exist.
1862   If the tags table becomes outdated due to changes in the files
1863 described in it, you can update it by running the @command{etags}
1864 program again.  If the tags table does not record a tag, or records it
1865 for the wrong file, then Emacs will not be able to find that
1866 definition until you update the tags table.  But if the position
1867 recorded in the tags table becomes a little bit wrong (due to other
1868 editing), Emacs will still be able to find the right position, with a
1869 slight delay.
1871    Thus, there is no need to update the tags table after each edit.
1872 You should update a tags table when you define new tags that you want
1873 to have listed, or when you move tag definitions from one file to
1874 another, or when changes become substantial.
1876   You can make a tags table @dfn{include} another tags table, by
1877 passing the @samp{--include=@var{file}} option to @command{etags}.  It
1878 then covers all the files covered by the included tags file, as well
1879 as its own.
1881   If you specify the source files with relative file names when you run
1882 @command{etags}, the tags file will contain file names relative to the
1883 directory where the tags file was initially written.  This way, you can
1884 move an entire directory tree containing both the tags file and the
1885 source files, and the tags file will still refer correctly to the source
1886 files.  If the tags file is @file{-} or is in the @file{/dev} directory,
1887 however, the file names are
1888 made relative to the current working directory.  This is useful, for
1889 example, when writing the tags to @file{/dev/stdout}.
1891   When using a relative file name, it should not be a symbolic link
1892 pointing to a tags file in a different directory, because this would
1893 generally render the file names invalid.
1895   If you specify absolute file names as arguments to @command{etags}, then
1896 the tags file will contain absolute file names.  This way, the tags file
1897 will still refer to the same files even if you move it, as long as the
1898 source files remain in the same place.  Absolute file names start with
1899 @samp{/}, or with @samp{@var{device}:/} on MS-DOS and MS-Windows.
1901    When you want to make a tags table from a great number of files,
1902 you may have problems listing them on the command line, because some
1903 systems have a limit on its length.  You can circumvent this limit by
1904 telling @command{etags} to read the file names from its standard
1905 input, by typing a dash in place of the file names, like this:
1907 @smallexample
1908 find . -name "*.[chCH]" -print | etags -
1909 @end smallexample
1911   @command{etags} recognizes the language used in an input file based
1912 on its file name and contents.  You can specify the language
1913 explicitly with the @samp{--language=@var{name}} option.  You can
1914 intermix these options with file names; each one applies to the file
1915 names that follow it.  Specify @samp{--language=auto} to tell
1916 @command{etags} to resume guessing the language from the file names
1917 and file contents.  Specify @samp{--language=none} to turn off
1918 language-specific processing entirely; then @command{etags} recognizes
1919 tags by regexp matching alone (@pxref{Etags Regexps}).
1921   The option @samp{--parse-stdin=@var{file}} is mostly useful when
1922 calling @command{etags} from programs.  It can be used (only once) in
1923 place of a file name on the command line.  @command{etags} will read from
1924 standard input and mark the produced tags as belonging to the file
1925 @var{file}.
1927   @samp{etags --help} outputs the list of the languages @command{etags}
1928 knows, and the file name rules for guessing the language.  It also prints
1929 a list of all the available @command{etags} options, together with a short
1930 explanation.  If followed by one or more @samp{--language=@var{lang}}
1931 options, it outputs detailed information about how tags are generated for
1932 @var{lang}.
1934 @node Etags Regexps
1935 @subsection Etags Regexps
1937   The @samp{--regex} option to @command{etags} allows tags to be
1938 recognized by regular expression matching.  You can intermix this
1939 option with file names; each one applies to the source files that
1940 follow it.  If you specify multiple @samp{--regex} options, all of
1941 them are used in parallel.  The syntax is:
1943 @smallexample
1944 --regex=[@var{@{language@}}]/@var{tagregexp}/[@var{nameregexp}/]@var{modifiers}
1945 @end smallexample
1947 @noindent
1948 The essential part of the option value is @var{tagregexp}, the regexp
1949 for matching tags.  It is always used anchored, that is, it only
1950 matches at the beginning of a line.  If you want to allow indented
1951 tags, use a regexp that matches initial whitespace; start it with
1952 @samp{[ \t]*}.
1954   In these regular expressions, @samp{\} quotes the next character, and
1955 all the GCC character escape sequences are supported (@samp{\a} for
1956 bell, @samp{\b} for back space, @samp{\d} for delete, @samp{\e} for
1957 escape, @samp{\f} for formfeed, @samp{\n} for newline, @samp{\r} for
1958 carriage return, @samp{\t} for tab, and @samp{\v} for vertical tab).
1960   Ideally, @var{tagregexp} should not match more characters than are
1961 needed to recognize what you want to tag.  If the syntax requires you
1962 to write @var{tagregexp} so it matches more characters beyond the tag
1963 itself, you should add a @var{nameregexp}, to pick out just the tag.
1964 This will enable Emacs to find tags more accurately and to do
1965 completion on tag names more reliably.  You can find some examples
1966 below.
1968   The @var{modifiers} are a sequence of zero or more characters that
1969 modify the way @command{etags} does the matching.  A regexp with no
1970 modifiers is applied sequentially to each line of the input file, in a
1971 case-sensitive way.  The modifiers and their meanings are:
1973 @table @samp
1974 @item i
1975 Ignore case when matching this regexp.
1976 @item m
1977 Match this regular expression against the whole file, so that
1978 multi-line matches are possible.
1979 @item s
1980 Match this regular expression against the whole file, and allow
1981 @samp{.} in @var{tagregexp} to match newlines.
1982 @end table
1984   The @samp{-R} option cancels all the regexps defined by preceding
1985 @samp{--regex} options.  It too applies to the file names following
1986 it.  Here's an example:
1988 @smallexample
1989 etags --regex=/@var{reg1}/i voo.doo --regex=/@var{reg2}/m \
1990     bar.ber -R --lang=lisp los.er
1991 @end smallexample
1993 @noindent
1994 Here @command{etags} chooses the parsing language for @file{voo.doo} and
1995 @file{bar.ber} according to their contents.  @command{etags} also uses
1996 @var{reg1} to recognize additional tags in @file{voo.doo}, and both
1997 @var{reg1} and @var{reg2} to recognize additional tags in
1998 @file{bar.ber}.  @var{reg1} is checked against each line of
1999 @file{voo.doo} and @file{bar.ber}, in a case-insensitive way, while
2000 @var{reg2} is checked against the whole @file{bar.ber} file,
2001 permitting multi-line matches, in a case-sensitive way.  @command{etags}
2002 uses only the Lisp tags rules, with no user-specified regexp matching,
2003 to recognize tags in @file{los.er}.
2005   You can restrict a @samp{--regex} option to match only files of a
2006 given language by using the optional prefix @var{@{language@}}.
2007 (@samp{etags --help} prints the list of languages recognized by
2008 @command{etags}.)  This is particularly useful when storing many
2009 predefined regular expressions for @command{etags} in a file.  The
2010 following example tags the @code{DEFVAR} macros in the Emacs source
2011 files, for the C language only:
2013 @smallexample
2014 --regex='@{c@}/[ \t]*DEFVAR_[A-Z_ \t(]+"\([^"]+\)"/'
2015 @end smallexample
2017 @noindent
2018 When you have complex regular expressions, you can store the list of
2019 them in a file.  The following option syntax instructs @command{etags} to
2020 read two files of regular expressions.  The regular expressions
2021 contained in the second file are matched without regard to case.
2023 @smallexample
2024 --regex=@@@var{case-sensitive-file} --ignore-case-regex=@@@var{ignore-case-file}
2025 @end smallexample
2027 @noindent
2028 A regex file for @command{etags} contains one regular expression per
2029 line.  Empty lines, and lines beginning with space or tab are ignored.
2030 When the first character in a line is @samp{@@}, @command{etags} assumes
2031 that the rest of the line is the name of another file of regular
2032 expressions; thus, one such file can include another file.  All the
2033 other lines are taken to be regular expressions.  If the first
2034 non-whitespace text on the line is @samp{--}, that line is a comment.
2036   For example, we can create a file called @samp{emacs.tags} with the
2037 following contents:
2039 @smallexample
2040         -- This is for GNU Emacs C source files
2041 @{c@}/[ \t]*DEFVAR_[A-Z_ \t(]+"\([^"]+\)"/\1/
2042 @end smallexample
2044 @noindent
2045 and then use it like this:
2047 @smallexample
2048 etags --regex=@@emacs.tags *.[ch] */*.[ch]
2049 @end smallexample
2051   Here are some more examples.  The regexps are quoted to protect them
2052 from shell interpretation.
2054 @itemize @bullet
2056 @item
2057 Tag Octave files:
2059 @smallexample
2060 etags --language=none \
2061       --regex='/[ \t]*function.*=[ \t]*\([^ \t]*\)[ \t]*(/\1/' \
2062       --regex='/###key \(.*\)/\1/' \
2063       --regex='/[ \t]*global[ \t].*/' \
2064       *.m
2065 @end smallexample
2067 @noindent
2068 Note that tags are not generated for scripts, so that you have to add
2069 a line by yourself of the form @samp{###key @var{scriptname}} if you
2070 want to jump to it.
2072 @item
2073 Tag Tcl files:
2075 @smallexample
2076 etags --language=none --regex='/proc[ \t]+\([^ \t]+\)/\1/' *.tcl
2077 @end smallexample
2079 @item
2080 Tag VHDL files:
2082 @smallexample
2083 etags --language=none \
2084   --regex='/[ \t]*\(ARCHITECTURE\|CONFIGURATION\) +[^ ]* +OF/' \
2085   --regex='/[ \t]*\(ATTRIBUTE\|ENTITY\|FUNCTION\|PACKAGE\
2086   \( BODY\)?\|PROCEDURE\|PROCESS\|TYPE\)[ \t]+\([^ \t(]+\)/\3/'
2087 @end smallexample
2088 @end itemize
2090 @node Select Tags Table
2091 @subsection Selecting a Tags Table
2093 @findex visit-tags-table
2094   Emacs has at any time one @dfn{selected} tags table.  All the
2095 commands for working with tags tables use the selected one.  To select
2096 a tags table, type @kbd{M-x visit-tags-table}, which reads the tags
2097 table file name as an argument, with @file{TAGS} in the default
2098 directory as the default.
2100 @vindex tags-file-name
2101   Emacs does not actually read in the tags table contents until you
2102 try to use them; all @code{visit-tags-table} does is store the file
2103 name in the variable @code{tags-file-name}, and setting the variable
2104 yourself is just as good.  The variable's initial value is @code{nil};
2105 that value tells all the commands for working with tags tables that
2106 they must ask for a tags table file name to use.
2108   Using @code{visit-tags-table} when a tags table is already loaded
2109 gives you a choice: you can add the new tags table to the current list
2110 of tags tables, or start a new list.  The tags commands use all the tags
2111 tables in the current list.  If you start a new list, the new tags table
2112 is used @emph{instead} of others.  If you add the new table to the
2113 current list, it is used @emph{as well as} the others.
2115 @vindex tags-table-list
2116   You can specify a precise list of tags tables by setting the variable
2117 @code{tags-table-list} to a list of strings, like this:
2119 @c keep this on two lines for formatting in smallbook
2120 @example
2121 @group
2122 (setq tags-table-list
2123       '("~/emacs" "/usr/local/lib/emacs/src"))
2124 @end group
2125 @end example
2127 @noindent
2128 This tells the tags commands to look at the @file{TAGS} files in your
2129 @file{~/emacs} directory and in the @file{/usr/local/lib/emacs/src}
2130 directory.  The order depends on which file you are in and which tags
2131 table mentions that file, as explained above.
2133   Do not set both @code{tags-file-name} and @code{tags-table-list}.
2135 @node Find Tag
2136 @subsection Finding a Tag
2138   The most important thing that a tags table enables you to do is to find
2139 the definition of a specific tag.
2141 @table @kbd
2142 @item M-.@: @var{tag} @key{RET}
2143 Find first definition of @var{tag} (@code{find-tag}).
2144 @item C-u M-.
2145 Find next alternate definition of last tag specified.
2146 @item C-u - M-.
2147 Go back to previous tag found.
2148 @item C-M-. @var{pattern} @key{RET}
2149 Find a tag whose name matches @var{pattern} (@code{find-tag-regexp}).
2150 @item C-u C-M-.
2151 Find the next tag whose name matches the last pattern used.
2152 @item C-x 4 .@: @var{tag} @key{RET}
2153 Find first definition of @var{tag}, but display it in another window
2154 (@code{find-tag-other-window}).
2155 @item C-x 5 .@: @var{tag} @key{RET}
2156 Find first definition of @var{tag}, and create a new frame to select the
2157 buffer (@code{find-tag-other-frame}).
2158 @item M-*
2159 Pop back to where you previously invoked @kbd{M-.} and friends.
2160 @end table
2162 @kindex M-.
2163 @findex find-tag
2164   @kbd{M-.}@: (@code{find-tag}) prompts for a tag name and jumps to
2165 its source definition.  It works by searching through the tags table
2166 for that tag's file and approximate character position, visiting that
2167 file, and searching for the tag definition at ever-increasing
2168 distances away from the recorded approximate position.
2170   When entering the tag argument to @kbd{M-.}, the usual minibuffer
2171 completion commands can be used (@pxref{Completion}), with the tag
2172 names in the selected tags table as completion candidates.  If you
2173 specify an empty argument, the balanced expression in the buffer
2174 before or around point is the default argument.  @xref{Expressions}.
2176   You don't need to give @kbd{M-.} the full name of the tag; a part
2177 will do.  @kbd{M-.} finds tags which contain that argument as a
2178 substring.  However, it prefers an exact match to a substring match.
2179 To find other tags that match the same substring, give @code{find-tag}
2180 a numeric argument, as in @kbd{C-u M-.}  or @kbd{M-0 M-.}; this does
2181 not read a tag name, but continues searching the tags table's text for
2182 another tag containing the same substring last used.
2184 @kindex C-x 4 .
2185 @findex find-tag-other-window
2186 @kindex C-x 5 .
2187 @findex find-tag-other-frame
2188   Like most commands that can switch buffers, @code{find-tag} has a
2189 variant that displays the new buffer in another window, and one that
2190 makes a new frame for it.  The former is @w{@kbd{C-x 4 .}}
2191 (@code{find-tag-other-window}), and the latter is @w{@kbd{C-x 5 .}}
2192 (@code{find-tag-other-frame}).
2194   To move back to previous tag definitions, use @kbd{C-u - M-.}; more
2195 generally, @kbd{M-.} with a negative numeric argument.  Similarly,
2196 @w{@kbd{C-x 4 .}} with a negative argument finds the previous tag
2197 location in another window.
2199 @kindex M-*
2200 @findex pop-tag-mark
2201 @vindex find-tag-marker-ring-length
2202   As well as going back to places you've found tags recently, you can
2203 go back to places @emph{from where} you found them, using @kbd{M-*}
2204 (@code{pop-tag-mark}).  Thus you can find and examine the definition
2205 of something with @kbd{M-.} and then return to where you were with
2206 @kbd{M-*}.
2208   Both @kbd{C-u - M-.} and @kbd{M-*} allow you to retrace your steps to
2209 a depth determined by the variable @code{find-tag-marker-ring-length}.
2211 @findex find-tag-regexp
2212 @kindex C-M-.
2213   The command @kbd{C-M-.} (@code{find-tag-regexp}) visits the tags that
2214 match a specified regular expression.  It is just like @kbd{M-.} except
2215 that it does regexp matching instead of substring matching.
2217 @node Tags Search
2218 @subsection Searching and Replacing with Tags Tables
2219 @cindex search and replace in multiple files
2220 @cindex multiple-file search and replace
2222   The commands in this section visit and search all the files listed
2223 in the selected tags table, one by one.  For these commands, the tags
2224 table serves only to specify a sequence of files to search.  These
2225 commands scan the list of tags tables starting with the first tags
2226 table (if any) that describes the current file, proceed from there to
2227 the end of the list, and then scan from the beginning of the list
2228 until they have covered all the tables in the list.
2230 @table @kbd
2231 @item M-x tags-search @key{RET} @var{regexp} @key{RET}
2232 Search for @var{regexp} through the files in the selected tags
2233 table.
2234 @item M-x tags-query-replace @key{RET} @var{regexp} @key{RET} @var{replacement} @key{RET}
2235 Perform a @code{query-replace-regexp} on each file in the selected tags table.
2236 @item M-,
2237 Restart one of the commands above, from the current location of point
2238 (@code{tags-loop-continue}).
2239 @end table
2241 @findex tags-search
2242   @kbd{M-x tags-search} reads a regexp using the minibuffer, then
2243 searches for matches in all the files in the selected tags table, one
2244 file at a time.  It displays the name of the file being searched so you
2245 can follow its progress.  As soon as it finds an occurrence,
2246 @code{tags-search} returns.
2248 @kindex M-,
2249 @findex tags-loop-continue
2250   Having found one match, you probably want to find all the rest.
2251 Type @kbd{M-,} (@code{tags-loop-continue}) to resume the
2252 @code{tags-search}, finding one more match.  This searches the rest of
2253 the current buffer, followed by the remaining files of the tags table.
2255 @findex tags-query-replace
2256   @kbd{M-x tags-query-replace} performs a single
2257 @code{query-replace-regexp} through all the files in the tags table.  It
2258 reads a regexp to search for and a string to replace with, just like
2259 ordinary @kbd{M-x query-replace-regexp}.  It searches much like @kbd{M-x
2260 tags-search}, but repeatedly, processing matches according to your
2261 input.  @xref{Query Replace}, for more information on query replace.
2263 @vindex tags-case-fold-search
2264 @cindex case-sensitivity and tags search
2265   You can control the case-sensitivity of tags search commands by
2266 customizing the value of the variable @code{tags-case-fold-search}.  The
2267 default is to use the same setting as the value of
2268 @code{case-fold-search} (@pxref{Search Case}).
2270   It is possible to get through all the files in the tags table with a
2271 single invocation of @kbd{M-x tags-query-replace}.  But often it is
2272 useful to exit temporarily, which you can do with any input event that
2273 has no special query replace meaning.  You can resume the query
2274 replace subsequently by typing @kbd{M-,}; this command resumes the
2275 last tags search or replace command that you did.  For instance, to
2276 skip the rest of the current file, you can type @kbd{M-> M-,}.
2278   The commands in this section carry out much broader searches than the
2279 @code{find-tag} family.  The @code{find-tag} commands search only for
2280 definitions of tags that match your substring or regexp.  The commands
2281 @code{tags-search} and @code{tags-query-replace} find every occurrence
2282 of the regexp, as ordinary search commands and replace commands do in
2283 the current buffer.
2285   These commands create buffers only temporarily for the files that they
2286 have to search (those which are not already visited in Emacs buffers).
2287 Buffers in which no match is found are quickly killed; the others
2288 continue to exist.
2290   As an alternative to @code{tags-search}, you can run @command{grep}
2291 as a subprocess and have Emacs show you the matching lines one by one.
2292 @xref{Grep Searching}.
2294 @node List Tags
2295 @subsection Tags Table Inquiries
2297 @table @kbd
2298 @item C-M-i
2299 @itemx M-@key{TAB}
2300 Perform completion on the text around point, using the selected tags
2301 table if one is loaded (@code{completion-at-point}).
2302 @item M-x list-tags @key{RET} @var{file} @key{RET}
2303 Display a list of the tags defined in the program file @var{file}.
2304 @item M-x tags-apropos @key{RET} @var{regexp} @key{RET}
2305 Display a list of all tags matching @var{regexp}.
2306 @end table
2308 @cindex completion (symbol names)
2309   In most programming language modes, you can type @kbd{C-M-i} or
2310 @kbd{M-@key{TAB}} (@code{completion-at-point}) to complete the symbol
2311 at point.  If there is a selected tags table, this command can use it
2312 to generate completion candidates.  @xref{Symbol Completion}.
2314 @findex list-tags
2315   @kbd{M-x list-tags} reads the name of one of the files covered by
2316 the selected tags table, and displays a list of tags defined in that
2317 file.  Do not include a directory as part of the file name unless the
2318 file name recorded in the tags table includes a directory.
2320 @findex tags-apropos
2321 @vindex tags-apropos-verbose
2322 @vindex tags-tag-face
2323 @vindex tags-apropos-additional-actions
2324   @kbd{M-x tags-apropos} is like @code{apropos} for tags
2325 (@pxref{Apropos}).  It displays a list of tags in the selected tags
2326 table whose entries match @var{regexp}.  If the variable
2327 @code{tags-apropos-verbose} is non-@code{nil}, it displays the names
2328 of the tags files together with the tag names.  You can customize the
2329 appearance of the output by setting the variable @code{tags-tag-face}
2330 to a face.  You can display additional output by customizing the
2331 variable @code{tags-apropos-additional-actions}; see its documentation
2332 for details.
2334 @findex next-file
2335   @kbd{M-x next-file} visits files covered by the selected tags table.
2336 The first time it is called, it visits the first file covered by the
2337 table.  Each subsequent call visits the next covered file, unless a
2338 prefix argument is supplied, in which case it returns to the first
2339 file.
2341 @node EDE
2342 @section Emacs Development Environment
2343 @cindex EDE (Emacs Development Environment)
2344 @cindex Emacs Development Environment
2345 @cindex Integrated development environment
2347 EDE (@dfn{Emacs Development Environment}) is a package that simplifies
2348 the task of creating, building, and debugging large programs with
2349 Emacs.  It provides some of the features of an IDE, or @dfn{Integrated
2350 Development Environment}, in Emacs.
2352 This section provides a brief description of EDE usage.
2353 @ifnottex
2354 For full details, see @ref{Top, EDE,, ede, Emacs Development Environment}.
2355 @end ifnottex
2356 @iftex
2357 For full details on Ede, type @kbd{C-h i} and then select the EDE
2358 manual.
2359 @end iftex
2361   EDE is implemented as a global minor mode (@pxref{Minor Modes}).  To
2362 enable it, type @kbd{M-x global-ede-mode} or click on the
2363 @samp{Project Support (EDE)} item in the @samp{Tools} menu.  You can
2364 also enable EDE each time you start Emacs, by adding the following
2365 line to your initialization file:
2367 @smallexample
2368 (global-ede-mode t)
2369 @end smallexample
2371 @noindent
2372 Activating EDE adds a menu named @samp{Development} to the menu bar.
2373 Many EDE commands, including the ones described below, can be invoked
2374 from this menu.
2376   EDE organizes files into @dfn{projects}, which correspond to
2377 directory trees.  The @dfn{project root} is the topmost directory of a
2378 project.  To define a new project, visit a file in the desired project
2379 root and type @kbd{M-x ede-new}.  This command prompts for a
2380 @dfn{project type}, which refers to the underlying method that EDE
2381 will use to manage the project (@pxref{Creating a project, EDE,, ede,
2382 Emacs Development Environment}).  The most common project types are
2383 @samp{Make}, which uses Makefiles, and @samp{Automake}, which uses GNU
2384 Automake (@pxref{Top, Automake,, automake, Automake}).  In both cases,
2385 EDE also creates a file named @file{Project.ede}, which stores
2386 information about the project.
2388   A project may contain one or more @dfn{targets}.  A target can be an
2389 object file, executable program, or some other type of file, which is
2390 ``built'' from one or more of the files in the project.
2392   To add a new @dfn{target} to a project, type @kbd{C-c . t}
2393 (@code{M-x ede-new-target}).  This command also asks if you wish to
2394 ``add'' the current file to that target, which means that the target
2395 is to be built from that file.  After you have defined a target, you
2396 can add more files to it by typing @kbd{C-c . a}
2397 (@code{ede-add-file}).
2399   To build a target, type @kbd{C-c . c} (@code{ede-compile-target}).
2400 To build all the targets in the project, type @kbd{C-c . C}
2401 (@code{ede-compile-project}).  EDE uses the file types to guess how
2402 the target should be built.
2404 @ifnottex
2405 @include emerge-xtra.texi
2406 @end ifnottex