Merge from gnulib
[emacs.git] / doc / emacs / maintaining.texi
blob80a4467f63993e3a965ac39df7483f406c43c4d0
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-2017 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 medium- to
9 large-size programs and packages.  These features include:
11 @itemize @minus
12 @item
13 Unified interface to Support for Version Control Systems
14 (@acronym{VCS}) that record the history of changes to source files.
16 @item
17 A specialized mode for maintaining @file{ChangeLog} files that provide
18 a chronological log of program changes.
20 @item
21 @acronym{Xref}, a set of commands for displaying definitions of
22 symbols (a.k.a.@: ``identifiers'') and their references.
24 @item
25 @acronym{EDE}, the Emacs's own IDE.
27 @ifnottex
28 @item
29 A mode for merging changes to program sources made on separate
30 branches of development.
31 @end ifnottex
32 @end itemize
34 If you are maintaining a large Lisp program, then in addition to the
35 features described here, you may find the Emacs Lisp Regression
36 Testing (@acronym{ERT}) library useful (@pxref{Top,,ERT,ert, Emacs
37 Lisp Regression Testing}).
39 @menu
40 * Version Control::     Using version control systems.
41 * Change Log::          Maintaining a change history for your program.
42 * Xref::                Find definitions and references of any function,
43                           method, struct, macro, @dots{} in your program.
44 * EDE::                 An integrated development environment for Emacs.
45 @ifnottex
46 * Emerge::              A convenient way of merging two versions of a program.
47 @end ifnottex
48 @end menu
50 @node Version Control
51 @section Version Control
52 @cindex version control
54   A @dfn{version control system} is a program that can record multiple
55 versions of a source file, storing information such as the creation
56 time of each version, who made it, and a description of what was
57 changed.
59   The Emacs version control interface is called @dfn{VC}@.  VC
60 commands work with several different version control systems;
61 currently, it supports Bazaar, CVS, Git, Mercurial, Monotone, RCS,
62 SCCS/CSSC, and Subversion.  Of these, the GNU project distributes CVS,
63 RCS, and Bazaar.
65   VC is enabled automatically whenever you visit a file governed by a
66 version control system.  To disable VC entirely, set the customizable
67 variable @code{vc-handled-backends} to @code{nil}
68 @iftex
69 (@pxref{Customizing VC,,,emacs-xtra, Specialized Emacs Features}).
70 @end iftex
71 @ifnottex
72 (@pxref{Customizing VC}).
73 @end ifnottex
75 @findex vc-refresh-state
76 @findex vc-state-refresh
77   To update the VC state information for the file visited in the
78 current buffer, use the command @code{vc-refresh-state}.  This command
79 is useful when you perform version control commands outside Emacs
80 (e.g., from the shell prompt), or if you put the buffer's file under a
81 different version control system, or remove it from version control
82 entirely.  A companion command @code{vc-state-refresh} does the same,
83 but does not consider switching the version control system or removal
84 from VC.
86 @menu
87 * Introduction to VC::  How version control works in general.
88 * VC Mode Line::        How the mode line shows version control status.
89 * Basic VC Editing::    How to edit a file under version control.
90 * Log Buffer::          Features available in log entry buffers.
91 * Registering::         Putting a file under version control.
92 * Old Revisions::       Examining and comparing old versions.
93 * VC Change Log::       Viewing the VC Change Log.
94 * VC Undo::             Canceling changes before or after committing.
95 * VC Ignore::           Ignore files under version control system.
96 * VC Directory Mode::   Listing files managed by version control.
97 * Branches::            Multiple lines of development.
98 @ifnottex
99 * Miscellaneous VC::    Various other commands and features of VC.
100 * Customizing VC::      Variables that change VC's behavior.
101 @end ifnottex
102 @end menu
104 @node Introduction to VC
105 @subsection Introduction to Version Control
107   VC allows you to use a version control system from within Emacs,
108 integrating the version control operations smoothly with editing.  It
109 provides a uniform interface for common operations in many version
110 control operations.
112   Some uncommon or intricate version control operations, such as
113 altering repository settings, are not supported in VC@.  You should
114 perform such tasks outside Emacs, e.g., via the command line.
116   This section provides a general overview of version control, and
117 describes the version control systems that VC supports.  You can skip
118 this section if you are already familiar with the version control system
119 you want to use.
121 @menu
122 * Why Version Control?::    Understanding the problems it addresses.
123 * Version Control Systems:: Supported version control back-end systems.
124 * VCS Concepts::            Words and concepts related to version control.
125 * VCS Merging::             How file conflicts are handled.
126 * VCS Changesets::          How changes are grouped.
127 * VCS Repositories::        Where version control repositories are stored.
128 * Types of Log File::       The VCS log in contrast to the ChangeLog.
129 @end menu
131 @node Why Version Control?
132 @subsubsection Understanding the problems it addresses
134   Version control systems provide you with three important
135 capabilities:
137 @itemize @bullet
138 @item
139 @dfn{Reversibility}: the ability to back up to a previous state if you
140 discover that some modification you did was a mistake or a bad idea.
142 @item
143 @dfn{Concurrency}: the ability to have many people modifying the same
144 collection of files knowing that conflicting modifications can be
145 detected and resolved.
147 @item
148 @dfn{History}: the ability to attach historical data to your data,
149 such as explanatory comments about the intention behind each change to
150 it.  Even for a programmer working solo, change histories are an
151 important aid to memory; for a multi-person project, they are a
152 vitally important form of communication among developers.
153 @end itemize
155 @node Version Control Systems
156 @subsubsection Supported Version Control Systems
158 @cindex back end (version control)
159   VC currently works with many different version control systems,
160 which it refers to as @dfn{back ends}:
162 @itemize @bullet
164 @cindex SCCS
165 @item
166 SCCS was the first version control system ever built, and was long ago
167 superseded by more advanced ones.  VC compensates for certain features
168 missing in SCCS (e.g., tag names for releases) by implementing them
169 itself.  Other VC features, such as multiple branches, are simply
170 unavailable.  Since SCCS is non-free, we recommend avoiding it.
172 @cindex CSSC
173 @item
174 CSSC is a free replacement for SCCS@.  You should use CSSC only if, for
175 some reason, you cannot use a more recent and better-designed version
176 control system.
178 @cindex RCS
179 @item
180 RCS is the free version control system around which VC was initially
181 built.  It is relatively primitive: it cannot be used over the
182 network, and works at the level of individual files.  Almost
183 everything you can do with RCS can be done through VC.
185 @cindex CVS
186 @item
187 CVS is the free version control system that was, until recently (circa
188 2008), used by the majority of free software projects.  Nowadays, it
189 is slowly being superseded by newer systems.  CVS allows concurrent
190 multi-user development either locally or over the network.  Unlike
191 newer systems, it lacks support for atomic commits and file
192 moving/renaming.  VC supports all basic editing operations under CVS.
194 @cindex SVN
195 @cindex Subversion
196 @item
197 Subversion (svn) is a free version control system designed to be
198 similar to CVS but without its problems (e.g., it supports atomic
199 commits of filesets, and versioning of directories, symbolic links,
200 meta-data, renames, copies, and deletes).
202 @cindex git
203 @item
204 Git is a decentralized version control system originally invented by
205 Linus Torvalds to support development of Linux (his kernel).  VC
206 supports many common Git operations, but others, such as repository
207 syncing, must be done from the command line.
209 @cindex hg
210 @cindex Mercurial
211 @item
212 Mercurial (hg) is a decentralized version control system broadly
213 resembling Git.  VC supports most Mercurial commands, with the
214 exception of repository sync operations.
216 @cindex bzr
217 @cindex Bazaar
218 @item
219 Bazaar (bzr) is a decentralized version control system that supports
220 both repository-based and decentralized versioning.  VC supports most
221 basic editing operations under Bazaar.
223 @cindex SRC
224 @cindex src
225 @item
226 SRC (src) is RCS, reloaded---a specialized version-control system
227 designed for single-file projects worked on by only one person.  It
228 allows multiple files with independent version-control histories to
229 exist in one directory, and is thus particularly well suited for
230 maintaining small documents, scripts, and dotfiles.  While it uses RCS
231 for revision storage, it presents a modern user interface featuring
232 lockless operation and integer sequential version numbers.  VC
233 supports almost all SRC operations.
234 @end itemize
236 @node VCS Concepts
237 @subsubsection Concepts of Version Control
239 @cindex repository
240 @cindex registered file
241    When a file is under version control, we say that it is
242 @dfn{registered} in the version control system.  The system has a
243 @dfn{repository} which stores both the file's present state and its
244 change history---enough to reconstruct the current version or any
245 earlier version.  The repository also contains other information, such
246 as @dfn{log entries} that describe the changes made to each file.
248 @cindex work file
249 @cindex checking out files
250   The copy of a version-controlled file that you actually edit is
251 called the @dfn{work file}.  You can change each work file as you
252 would an ordinary file.  After you are done with a set of changes, you
253 may @dfn{commit} (or @dfn{check in}) the changes; this records the
254 changes in the repository, along with a descriptive log entry.
256 @cindex working tree
257   A directory tree of work files is called a @dfn{working tree}.
259 @cindex revision
260 @cindex revision ID
261   Each commit creates a new @dfn{revision} in the repository.  The
262 version control system keeps track of all past revisions and the
263 changes that were made in each revision.  Each revision is named by a
264 @dfn{revision ID}, whose format depends on the version control system;
265 in the simplest case, it is just an integer.
267   To go beyond these basic concepts, you will need to understand three
268 aspects in which version control systems differ.  As explained in the
269 next three sections, they can be lock-based or merge-based; file-based
270 or changeset-based; and centralized or decentralized.  VC handles all
271 these modes of operation, but it cannot hide the differences.
273 @node VCS Merging
274 @subsubsection Merge-based vs lock-based Version Control
276   A version control system typically has some mechanism to coordinate
277 between users who want to change the same file.  There are two ways to
278 do this: merging and locking.
280 @cindex merging-based version
281   In a version control system that uses merging, each user may modify
282 a work file at any time.  The system lets you @dfn{merge} your work
283 file, which may contain changes that have not been committed, with the
284 latest changes that others have committed.
286 @cindex locking-based version
287   Older version control systems use a @dfn{locking} scheme instead.
288 Here, work files are normally read-only.  To edit a file, you ask the
289 version control system to make it writable for you by @dfn{locking}
290 it; only one user can lock a given file at any given time.  This
291 procedure is analogous to, but different from, the locking that Emacs
292 uses to detect simultaneous editing of ordinary files
293 (@pxref{Interlocking}).  When you commit your changes, that unlocks
294 the file, and the work file becomes read-only again.  Other users may
295 then lock the file to make their own changes.
297   Both locking and merging systems can have problems when multiple
298 users try to modify the same file at the same time.  Locking systems
299 have @dfn{lock conflicts}; a user may try to check a file out and be
300 unable to because it is locked.  In merging systems, @dfn{merge
301 conflicts} happen when you commit a change to a file that conflicts
302 with a change committed by someone else after your checkout.  Both
303 kinds of conflict have to be resolved by human judgment and
304 communication.  Experience has shown that merging is superior to
305 locking, both in convenience to developers and in minimizing the
306 number and severity of conflicts that actually occur.
308   SCCS always uses locking.  RCS is lock-based by default but can be
309 told to operate in a merging style.  CVS and Subversion are
310 merge-based by default but can be told to operate in a locking mode.
311 Decentralized version control systems, such as Git and Mercurial, are
312 exclusively merging-based.
314   VC mode supports both locking and merging version control.  The
315 terms ``commit'' and ``update'' are used in newer version control
316 systems; older lock-based systems use the terms ``check in'' and
317 ``check out''.  VC hides the differences between them as much as
318 possible.
320 @node VCS Changesets
321 @subsubsection Changeset-based vs File-based Version Control
323 @cindex file-based version control
324   On SCCS, RCS, CVS, and other early version control systems, version
325 control operations are @dfn{file-based}: each file has its own comment
326 and revision history separate from that of all other files.  Newer
327 systems, beginning with Subversion, are @dfn{changeset-based}: a
328 commit may include changes to several files, and the entire set of
329 changes is handled as a unit.  Any comment associated with the change
330 does not belong to a single file, but to the changeset itself.
332 @cindex changeset-based version control
333   Changeset-based version control is more flexible and powerful than
334 file-based version control; usually, when a change to multiple files
335 has to be reversed, it's good to be able to easily identify and remove
336 all of it.
338 @node VCS Repositories
339 @subsubsection Decentralized vs Centralized Repositories
341 @cindex centralized version control
342 @cindex decentralized version control
343 @cindex distributed version control
344   Early version control systems were designed around a
345 @dfn{centralized} model in which each project has only one repository
346 used by all developers.  SCCS, RCS, CVS, and Subversion share this
347 kind of model.  One of its drawbacks is that the repository is a choke
348 point for reliability and efficiency.
350   GNU Arch pioneered the concept of @dfn{distributed} or
351 @dfn{decentralized} version control, later implemented in Git,
352 Mercurial, and Bazaar.  A project may have several different
353 repositories, and these systems support a sort of super-merge between
354 repositories that tries to reconcile their change histories.  In
355 effect, there is one repository for each developer, and repository
356 merges take the place of commit operations.
358   VC helps you manage the traffic between your personal workfiles and
359 a repository.  Whether the repository is a single master, or one of a
360 network of peer repositories, is not something VC has to care about.
362 @node Types of Log File
363 @subsubsection Types of Log File
364 @cindex types of log file
365 @cindex log File, types of
366 @cindex version control log
368   Projects that use a version control system can have two types of log
369 for changes.  One is the log maintained by the version control system:
370 each time you commit a change, you fill out a @dfn{log entry} for the
371 change (@pxref{Log Buffer}).  This is called the @dfn{version control
372 log}.
374   The other kind of log is the file @file{ChangeLog} (@pxref{Change
375 Log}).  It provides a chronological record of all changes to a large
376 portion of a program---typically one directory and its subdirectories.
377 A small program would use one @file{ChangeLog} file; a large program
378 may have a @file{ChangeLog} file in each major directory.
379 @xref{Change Log}.  Programmers have used change logs since long
380 before version control systems.
382   Changeset-based version systems typically maintain a changeset-based
383 modification log for the entire system, which makes change log files
384 somewhat redundant.  One advantage that they retain is that it is
385 sometimes useful to be able to view the transaction history of a
386 single directory separately from those of other directories.  Another
387 advantage is that commit logs can't be fixed in many version control
388 systems.
390   A project maintained with version control can use just the version
391 control log, or it can use both kinds of logs.  It can handle some
392 files one way and some files the other way.  Each project has its
393 policy, which you should follow.
395   When the policy is to use both, you typically want to write an entry
396 for each change just once, then put it into both logs.  You can write
397 the entry in @file{ChangeLog}, then copy it to the log buffer with
398 @kbd{C-c C-a} when committing the change (@pxref{Log Buffer}).  Or you
399 can write the entry in the log buffer while committing the change, and
400 later use the @kbd{C-x v a} command to copy it to @file{ChangeLog}
401 @iftex
402 (@pxref{Change Logs and VC,,,emacs-xtra, Specialized Emacs Features}).
403 @end iftex
404 @ifnottex
405 (@pxref{Change Logs and VC}).
406 @end ifnottex
408 @node VC Mode Line
409 @subsection Version Control and the Mode Line
410 @cindex VC mode line indicator
412   When you visit a file that is under version control, Emacs indicates
413 this on the mode line.  For example, @samp{Bzr-1223} says that Bazaar
414 is used for that file, and the current revision ID is 1223.
416 @cindex version control status
417   The character between the back-end name and the revision ID
418 indicates the @dfn{version control status} of the work file.  In a
419 merge-based version control system, a @samp{-} character indicates
420 that the work file is unmodified, and @samp{:} indicates that it has
421 been modified.  @samp{!} indicates that the file contains conflicts as
422 result of a recent merge operation (@pxref{Merging}), or that the file
423 was removed from the version control.  Finally, @samp{?} means that
424 the file is under version control, but is missing from the working
425 tree.
427   In a lock-based system, @samp{-} indicates an unlocked file, and
428 @samp{:} a locked file; if the file is locked by another user (for
429 instance, @samp{jim}), that is displayed as @samp{RCS:jim:1.3}.
430 @samp{@@} means that the file was locally added, but not yet committed
431 to the master repository.
433   On a graphical display, you can move the mouse over this mode line
434 indicator to pop up a tool-tip, which displays a more verbose
435 description of the version control status.  Pressing @kbd{mouse-1}
436 over the indicator pops up a menu of VC commands, identical to
437 @samp{Tools / Version Control} on the menu bar.
439 @vindex auto-revert-check-vc-info
440   When Auto Revert mode (@pxref{Reverting}) reverts a buffer that is
441 under version control, it updates the version control information in
442 the mode line.  However, Auto Revert mode may not properly update this
443 information if the version control status changes without changes to
444 the work file, from outside the current Emacs session.  If you set
445 @code{auto-revert-check-vc-info} to @code{t}, Auto Revert mode updates
446 the version control status information every
447 @code{auto-revert-interval} seconds, even if the work file itself is
448 unchanged.  The resulting CPU usage depends on the version control
449 system, but is usually not excessive.
451 @node Basic VC Editing
452 @subsection Basic Editing under Version Control
454 @cindex filesets, VC
455 @cindex VC filesets
456    Most VC commands operate on @dfn{VC filesets}.  A VC fileset is a
457 collection of one or more files that a VC operation acts on.  When you
458 type VC commands in a buffer visiting a version-controlled file, the
459 VC fileset is simply that one file.  When you type them in a VC
460 Directory buffer, and some files in it are marked, the VC fileset
461 consists of the marked files (@pxref{VC Directory Mode}).
463   On modern changeset-based version control systems (@pxref{VCS
464 Changesets}), VC commands handle multi-file VC filesets as a group.
465 For example, committing a multi-file VC fileset generates a single
466 revision, containing the changes to all those files.  On older
467 file-based version control systems like CVS, each file in a multi-file
468 VC fileset is handled individually; for example, a commit generates
469 one revision for each changed file.
471 @table @kbd
472 @item C-x v v
473 Perform the next appropriate version control operation on the current
474 VC fileset.
475 @end table
477 @findex vc-next-action
478 @kindex C-x v v
479   The principal VC command is a multi-purpose command, @kbd{C-x v v}
480 (@code{vc-next-action}), which performs the most appropriate
481 action on the current VC fileset: either registering it with a version
482 control system, or committing it, or unlocking it, or merging changes
483 into it.  The precise actions are described in detail in the following
484 subsections.  You can use @kbd{C-x v v} either in a file-visiting
485 buffer or in a VC Directory buffer.
487   Note that VC filesets are distinct from the named filesets used
488 for viewing and visiting files in functional groups
489 (@pxref{Filesets}).  Unlike named filesets, VC filesets are not named
490 and don't persist across sessions.
492 @menu
493 * VC With A Merging VCS::  Without locking: default mode for CVS.
494 * VC With A Locking VCS::  RCS in its default mode, SCCS, and optionally CVS.
495 * Advanced C-x v v::       Advanced features available with a prefix argument.
496 @end menu
498 @node VC With A Merging VCS
499 @subsubsection Basic Version Control with Merging
501   On a merging-based version control system (i.e., most modern ones;
502 @pxref{VCS Merging}), @kbd{C-x v v} does the following:
504 @itemize @bullet
505 @item
506 If there is more than one file in the VC fileset and the files have
507 inconsistent version control statuses, signal an error.  (Note,
508 however, that a fileset is allowed to include both newly-added
509 files and modified files; @pxref{Registering}.)
511 @item
512 If none of the files in the VC fileset are registered with a version
513 control system, register the VC fileset, i.e., place it under version
514 control.  @xref{Registering}.  If Emacs cannot find a system to
515 register under, it prompts for a repository type, creates a new
516 repository, and registers the VC fileset with it.
518 @item
519 If every work file in the VC fileset is unchanged, do nothing.
521 @item
522 If every work file in the VC fileset has been modified, commit the
523 changes.  To do this, Emacs pops up a @file{*vc-log*} buffer; type the
524 desired log entry for the new revision, followed by @kbd{C-c C-c} to
525 commit.  @xref{Log Buffer}.
527 If committing to a shared repository, the commit may fail if the
528 repository that has been changed since your last update.  In that
529 case, you must perform an update before trying again.  On a
530 decentralized version control system, use @kbd{C-x v +}
531 (@pxref{Pulling / Pushing}) or @kbd{C-x v m} (@pxref{Merging}).
532 On a centralized version control system, type @kbd{C-x v v} again to
533 merge in the repository changes.
535 @item
536 Finally, if you are using a centralized version control system, check
537 if each work file in the VC fileset is up-to-date.  If any file has
538 been changed in the repository, offer to update it.
539 @end itemize
541   These rules also apply when you use RCS in its non-locking mode,
542 except that changes are not automatically merged from the repository.
543 Nothing informs you if another user has committed changes in the same
544 file since you began editing it; when you commit your revision, his
545 changes are removed (however, they remain in the repository and are
546 thus not irrevocably lost).  Therefore, you must verify that the
547 current revision is unchanged before committing your changes.  In
548 addition, locking is possible with RCS even in this mode: @kbd{C-x v
549 v} with an unmodified file locks the file, just as it does with RCS in
550 its normal locking mode (@pxref{VC With A Locking VCS}).
552 @node VC With A Locking VCS
553 @subsubsection Basic Version Control with Locking
555   On a locking-based version control system (such as SCCS, and RCS in
556 its default mode), @kbd{C-x v v} does the following:
558 @itemize @bullet
559 @item
560 If there is more than one file in the VC fileset and the files have
561 inconsistent version control statuses, signal an error.
563 @item
564 If each file in the VC fileset is not registered with a version
565 control system, register the VC fileset.  @xref{Registering}.  If
566 Emacs cannot find a system to register under, it prompts for a
567 repository type, creates a new repository, and registers the VC
568 fileset with it.
570 @item
571 If each file is registered and unlocked, lock it and make it writable,
572 so that you can begin to edit it.
574 @item
575 If each file is locked by you and contains changes, commit the
576 changes.  To do this, Emacs pops up a @file{*vc-log*} buffer; type the
577 desired log entry for the new revision, followed by @kbd{C-c C-c} to
578 commit (@pxref{Log Buffer}).
580 @item
581 If each file is locked by you, but you have not changed it, release
582 the lock and make the file read-only again.
584 @item
585 If each file is locked by another user, ask whether you want to
586 steal the lock.  If you say yes, the file becomes locked by you,
587 and a warning message is sent to the user who had formerly locked the
588 file.
589 @end itemize
591   These rules also apply when you use CVS in locking mode, except
592 that CVS does not support stealing locks.
594 @node Advanced C-x v v
595 @subsubsection Advanced Control in @kbd{C-x v v}
597 @cindex revision ID in version control
598   When you give a prefix argument to @code{vc-next-action} (@kbd{C-u
599 C-x v v}), it still performs the next logical version control
600 operation, but accepts additional arguments to specify precisely how
601 to do the operation.
603 @itemize @bullet
604 @item
605 @cindex specific version control system
606 You can specify the name of a version control system.  This is useful
607 if the fileset can be managed by more than one version control system,
608 and Emacs fails to detect the correct one.
610 @item
611 Otherwise, if using CVS or RCS, you can specify a revision ID.
613 If the fileset is modified (or locked), this makes Emacs commit with
614 that revision ID@.  You can create a new branch by supplying an
615 appropriate revision ID (@pxref{Branches}).
617 If the fileset is unmodified (and unlocked), this checks the specified
618 revision into the working tree.  You can also specify a revision on
619 another branch by giving its revision or branch ID (@pxref{Switching
620 Branches}).  An empty argument (i.e., @kbd{C-u C-x v v @key{RET}})
621 checks out the latest (head) revision on the current branch.
623 This is silently ignored on a decentralized version control system.
624 Those systems do not let you specify your own revision IDs, nor do
625 they use the concept of checking out individual files.
626 @end itemize
628 @node Log Buffer
629 @subsection Features of the Log Entry Buffer
631 @cindex C-c C-c @r{(Log Edit mode)}
632 @findex log-edit-done
633   When you tell VC to commit a change, it pops up a buffer named
634 @file{*vc-log*}.  In this buffer, you should write a @dfn{log entry}
635 describing the changes you have made (@pxref{Why Version Control?}).
636 After you are done, type @kbd{C-c C-c} (@code{log-edit-done}) to exit
637 the buffer and commit the change, together with your log entry.
639 @cindex Log Edit mode
640 @cindex mode, Log Edit
641 @vindex vc-log-mode-hook
642 @c FIXME: Mention log-edit-mode-hook here?  --xfq
643   The major mode for the @file{*vc-log*} buffer is Log Edit mode, a
644 variant of Text mode (@pxref{Text Mode}).  On entering Log Edit mode,
645 Emacs runs the hooks @code{text-mode-hook} and @code{vc-log-mode-hook}
646 (@pxref{Hooks}).
648   In the @file{*vc-log*} buffer, you can write one or more @dfn{header
649 lines}, specifying additional information to be supplied to the
650 version control system.  Each header line must occupy a single line at
651 the top of the buffer; the first line that is not a header line is
652 treated as the start of the log entry.  For example, the following
653 header line states that the present change was not written by you, but
654 by another developer:
656 @smallexample
657 Author: J. R. Hacker <jrh@@example.com>
658 @end smallexample
660 @noindent
661 Apart from the @samp{Author} header, Emacs recognizes the headers
662 @samp{Date} (a manually-specified commit time) and @samp{Fixes} (a
663 reference to a bug fixed by the change).  Not all version control
664 systems recognize all headers: Bazaar recognizes all three headers,
665 while Git, Mercurial, and Monotone recognize only @samp{Author} and
666 @samp{Date}.  If you specify a header for a system that does not
667 support it, the header is treated as part of the log entry.
669 @kindex C-c C-f @r{(Log Edit mode)}
670 @findex log-edit-show-files
671 @kindex C-c C-d @r{(Log Edit mode)}
672 @findex log-edit-show-diff
673   While in the @file{*vc-log*} buffer, the current VC fileset is
674 considered to be the fileset that will be committed if you type
675 @w{@kbd{C-c C-c}}.  To view a list of the files in the VC fileset,
676 type @w{@kbd{C-c C-f}} (@code{log-edit-show-files}).  To view a diff
677 of changes between the VC fileset and the version from which you
678 started editing (@pxref{Old Revisions}), type @kbd{C-c C-d}
679 (@code{log-edit-show-diff}).
681 @kindex C-c C-a @r{(Log Edit mode)}
682 @findex log-edit-insert-changelog
683   If the VC fileset includes one or more @file{ChangeLog} files
684 (@pxref{Change Log}), type @kbd{C-c C-a}
685 (@code{log-edit-insert-changelog}) to pull the relevant entries into
686 the @file{*vc-log*} buffer.  If the topmost item in each
687 @file{ChangeLog} was made under your user name on the current date,
688 this command searches that item for entries matching the file(s) to be
689 committed, and inserts them.
690 @ifnottex
691 If you are using CVS or RCS, see @ref{Change Logs and VC}, for the
692 opposite way of working---generating ChangeLog entries from the Log
693 Edit buffer.
694 @end ifnottex
696   To abort a commit, just @emph{don't} type @kbd{C-c C-c} in that
697 buffer.  You can switch buffers and do other editing.  As long as you
698 don't try to make another commit, the entry you were editing remains
699 in the @file{*vc-log*} buffer, and you can go back to that buffer at
700 any time to complete the commit.
702 @kindex M-n @r{(Log Edit mode)}
703 @kindex M-p @r{(Log Edit mode)}
704 @kindex M-s @r{(Log Edit mode)}
705 @kindex M-r @r{(Log Edit mode)}
706   You can also browse the history of previous log entries to duplicate
707 a commit comment.  This can be useful when you want to make several
708 commits with similar comments.  The commands @kbd{M-n}, @kbd{M-p},
709 @kbd{M-s} and @kbd{M-r} for doing this work just like the minibuffer
710 history commands (@pxref{Minibuffer History}), except that they are
711 used outside the minibuffer.
713 @node Registering
714 @subsection Registering a File for Version Control
716 @table @kbd
717 @item C-x v i
718 Register the visited file for version control.
719 @end table
721 @kindex C-x v i
722 @findex vc-register
723   The command @kbd{C-x v i} (@code{vc-register}) @dfn{registers} each
724 file in the current VC fileset, placing it under version control.
725 This is essentially equivalent to the action of @kbd{C-x v v} on an
726 unregistered VC fileset (@pxref{Basic VC Editing}), except that if the
727 VC fileset is already registered, @kbd{C-x v i} signals an error
728 whereas @kbd{C-x v v} performs some other action.
730   To register a file, Emacs must choose a version control system.  For
731 a multi-file VC fileset, the VC Directory buffer specifies the system
732 to use (@pxref{VC Directory Mode}).  For a single-file VC fileset, if
733 the file's directory already contains files registered in a version
734 control system, or if the directory is part of a directory tree
735 controlled by a version control system, Emacs chooses that system.  In
736 the event that more than one version control system is applicable,
737 Emacs uses the one that appears first in the variable
738 @iftex
739 @code{vc-handled-backends}.
740 @end iftex
741 @ifnottex
742 @code{vc-handled-backends} (@pxref{Customizing VC}).
743 @end ifnottex
744 If Emacs cannot find a version control system to register the file
745 under, it prompts for a repository type, creates a new repository, and
746 registers the file into that repository.
748   On most version control systems, registering a file with @kbd{C-x v
749 i} or @kbd{C-x v v} adds it to the working tree but not to the
750 repository.  Such files are labeled as @samp{added} in the VC
751 Directory buffer, and show a revision ID of @samp{@@@@} in the mode
752 line.  To make the registration take effect in the repository, you
753 must perform a commit (@pxref{Basic VC Editing}).  Note that a single
754 commit can include both file additions and edits to existing files.
756   On a locking-based version control system (@pxref{VCS Merging}),
757 registering a file leaves it unlocked and read-only.  Type @kbd{C-x v
758 v} to start editing it.
760 @node Old Revisions
761 @subsection Examining And Comparing Old Revisions
763 @table @kbd
764 @item C-x v =
765 Compare the work files in the current VC fileset with the versions you
766 started from (@code{vc-diff}).  With a prefix argument, prompt for two
767 revisions of the current VC fileset and compare them.  You can also
768 call this command from a Dired buffer (@pxref{Dired}).
770 @ifnottex
771 @item M-x vc-ediff
772 Like @kbd{C-x v =}, but using Ediff.  @xref{Top,, Ediff, ediff, The
773 Ediff Manual}.
774 @end ifnottex
776 @item C-x v D
777 Compare the entire working tree to the revision you started from
778 (@code{vc-root-diff}).  With a prefix argument, prompt for two
779 revisions and compare their trees.
781 @item C-x v ~
782 Prompt for a revision of the current file, and visit it in a separate
783 buffer (@code{vc-revision-other-window}).
785 @item C-x v g
786 Display an annotated version of the current file: for each line, show
787 the latest revision in which it was modified (@code{vc-annotate}).
788 @end table
790 @findex vc-diff
791 @kindex C-x v =
792   @kbd{C-x v =} (@code{vc-diff}) displays a @dfn{diff} which compares
793 each work file in the current VC fileset to the version(s) from which
794 you started editing.  The diff is displayed in another window, in a
795 Diff mode buffer (@pxref{Diff Mode}) named @file{*vc-diff*}.  The
796 usual Diff mode commands are available in this buffer.  In particular,
797 the @kbd{g} (@code{revert-buffer}) command performs the file
798 comparison again, generating a new diff.
800 @kindex C-u C-x v =
801   To compare two arbitrary revisions of the current VC fileset, call
802 @code{vc-diff} with a prefix argument: @kbd{C-u C-x v =}.  This
803 prompts for two revision IDs (@pxref{VCS Concepts}), and displays a
804 diff between those versions of the fileset.  This will not work
805 reliably for multi-file VC filesets, if the version control system is
806 file-based rather than changeset-based (e.g., CVS), since then
807 revision IDs for different files would not be related in any
808 meaningful way.
810   Instead of the revision ID, some version control systems let you
811 specify revisions in other formats.  For instance, under Bazaar you
812 can enter @samp{date:yesterday} for the argument to @kbd{C-u C-x v =}
813 (and related commands) to specify the first revision committed after
814 yesterday.  See the documentation of the version control system for
815 details.
817   If you invoke @kbd{C-x v =} or @kbd{C-u C-x v =} from a Dired buffer
818 (@pxref{Dired}), the file listed on the current line is treated as the
819 current VC fileset.
821 @ifnottex
822 @findex vc-ediff
823   @kbd{M-x vc-ediff} works like @kbd{C-x v =}, except that it uses an
824 Ediff session.  @xref{Top,, Ediff, ediff, The Ediff Manual}.
825 @end ifnottex
827 @findex vc-root-diff
828 @kindex C-x v D
829   @kbd{C-x v D} (@code{vc-root-diff}) is similar to @kbd{C-x v =}, but
830 it displays the changes in the entire current working tree (i.e., the
831 working tree containing the current VC fileset).  If you invoke this
832 command from a Dired buffer, it applies to the working tree containing
833 the directory.
835 @vindex vc-diff-switches
836   You can customize the @command{diff} options that @kbd{C-x v =} and
837 @kbd{C-x v D} use for generating diffs.  The options used are taken
838 from the first non-@code{nil} value amongst the variables
839 @code{vc-@var{backend}-diff-switches}, @code{vc-diff-switches}, and
840 @code{diff-switches} (@pxref{Comparing Files}), in that order.  Here,
841 @var{backend} stands for the relevant version control system,
842 e.g., @code{bzr} for Bazaar.  Since @code{nil} means to check the
843 next variable in the sequence, either of the first two may use the
844 value @code{t} to mean no switches at all.  Most of the
845 @code{vc-@var{backend}-diff-switches} variables default to @code{nil},
846 but some default to @code{t}; these are for version control systems
847 whose @code{diff} implementations do not accept common diff options,
848 such as Subversion.
850 @findex vc-revision-other-window
851 @kindex C-x v ~
852   To directly examine an older version of a file, visit the work file
853 and type @kbd{C-x v ~ @var{revision} @key{RET}}
854 (@code{vc-revision-other-window}).  This retrieves the file version
855 corresponding to @var{revision}, saves it to
856 @file{@var{filename}.~@var{revision}~}, and visits it in a separate
857 window.
859 @findex vc-annotate
860 @vindex vc-annotate-background-mode
861 @kindex C-x v g
862   Many version control systems allow you to view files @dfn{annotated}
863 with per-line revision information, by typing @kbd{C-x v g}
864 (@code{vc-annotate}).  This creates a new ``annotate'' buffer
865 displaying the file's text, with each line colored to show how old it
866 is.  Red text is new, blue is old, and intermediate colors indicate
867 intermediate ages.  By default, the color is scaled over the full
868 range of ages, such that the oldest changes are blue, and the newest
869 changes are red.  If the variable @code{vc-annotate-background-mode}
870 is non-@code{nil}, the colors expressing the age of each line are
871 applied to the background color, leaving the foreground at its default
872 color.
874   When you give a prefix argument to this command, Emacs reads two
875 arguments using the minibuffer: the revision to display and annotate
876 (instead of the current file contents), and the time span in days the
877 color range should cover.
879   From the ``annotate'' buffer, these and other color scaling options are
880 available from the @samp{VC-Annotate} menu.  In this buffer, you can
881 also use the following keys to browse the annotations of past revisions,
882 view diffs, or view log entries:
884 @table @kbd
885 @item p
886 Annotate the previous revision, i.e., the revision before the one
887 currently annotated.  A numeric prefix argument is a repeat count, so
888 @kbd{C-u 10 p} would take you back 10 revisions.
890 @item n
891 Annotate the next revision, i.e., the revision after the one
892 currently annotated.  A numeric prefix argument is a repeat count.
894 @item j
895 Annotate the revision indicated by the current line.
897 @item a
898 Annotate the revision before the one indicated by the current line.
899 This is useful to see the state the file was in before the change on
900 the current line was made.
902 @item f
903 Show in a buffer the file revision indicated by the current line.
905 @item d
906 Display the diff between the current line's revision and the previous
907 revision.  This is useful to see what the current line's revision
908 actually changed in the file.
910 @item D
911 Display the diff between the current line's revision and the previous
912 revision for all files in the changeset (for VC systems that support
913 changesets).  This is useful to see what the current line's revision
914 actually changed in the tree.
916 @item l
917 Show the log of the current line's revision.  This is useful to see
918 the author's description of the changes in the revision on the current
919 line.
921 @item w
922 Annotate the working revision--the one you are editing.  If you used
923 @kbd{p} and @kbd{n} to browse to other revisions, use this key to
924 return to your working revision.
926 @item v
927 Toggle the annotation visibility.  This is useful for looking just at
928 the file contents without distraction from the annotations.
929 @end table
931 @node VC Change Log
932 @subsection VC Change Log
934 @table @kbd
935 @item C-x v l
936 Display the change history for the current fileset
937 (@code{vc-print-log}).
939 @item C-x v L
940 Display the change history for the current repository
941 (@code{vc-print-root-log}).
943 @item C-x v I
944 Display the changes that a ``pull'' operation will retrieve
945 (@code{vc-log-incoming}).
947 @item C-x v O
948 Display the changes that will be sent by the next ``push'' operation
949 (@code{vc-log-outgoing}).
950 @end table
952 @kindex C-x v l
953 @findex vc-print-log
954   @kbd{C-x v l} (@code{vc-print-log}) displays a buffer named
955 @file{*vc-change-log*}, showing the history of changes made to the
956 current file, including who made the changes, the dates, and the log
957 entry for each change (these are the same log entries you would enter
958 via the @file{*vc-log*} buffer; @pxref{Log Buffer}).  Point is
959 centered at the revision of the file currently being visited.  With a
960 prefix argument, the command prompts for the revision to center on,
961 and the maximum number of revisions to display.
963   If you call @kbd{C-x v l} from a VC Directory buffer (@pxref{VC
964 Directory Mode}) or a Dired buffer (@pxref{Dired}), it applies to the
965 file listed on the current line.
967 @findex vc-print-root-log
968 @findex log-view-toggle-entry-display
969   @kbd{C-x v L} (@code{vc-print-root-log}) displays a
970 @file{*vc-change-log*} buffer showing the history of the entire
971 version-controlled directory tree (RCS, SCCS, and CVS do not support
972 this feature).  With a prefix argument, the command prompts for the
973 maximum number of revisions to display.
975   The @kbd{C-x v L} history is shown in a compact form, usually
976 showing only the first line of each log entry.  However, you can type
977 @key{RET} (@code{log-view-toggle-entry-display}) in the
978 @file{*vc-change-log*} buffer to reveal the entire log entry for the
979 revision at point.  A second @key{RET} hides it again.
981   On a decentralized version control system, the @kbd{C-x v I}
982 (@code{vc-log-incoming}) command displays a log buffer showing the
983 changes that will be applied, the next time you run the version
984 control system's pull command to get new revisions from another
985 repository (@pxref{Pulling / Pushing}).  This other repository is the default
986 one from which changes are pulled, as defined by the version control
987 system; with a prefix argument, @code{vc-log-incoming} prompts for a
988 specific repository.  Similarly, @kbd{C-x v O}
989 (@code{vc-log-outgoing}) shows the changes that will be sent to
990 another repository, the next time you run the push command; with a
991 prefix argument, it prompts for a specific destination repository.
993   In the @file{*vc-change-log*} buffer, you can use the following keys
994 to move between the logs of revisions and of files, and to examine and
995 compare past revisions (@pxref{Old Revisions}):
997 @table @kbd
998 @item p
999 Move to the previous revision entry.  (Revision entries in the log
1000 buffer are usually in reverse-chronological order, so the previous
1001 revision-item usually corresponds to a newer revision.)  A numeric
1002 prefix argument is a repeat count.
1004 @item n
1005 Move to the next revision entry.  A numeric prefix argument is a
1006 repeat count.
1008 @item P
1009 Move to the log of the previous file, if showing logs for a multi-file
1010 VC fileset.  Otherwise, just move to the beginning of the log.  A
1011 numeric prefix argument is a repeat count.
1013 @item N
1014 Move to the log of the next file, if showing logs for a multi-file VC
1015 fileset.  A numeric prefix argument is a repeat count.
1017 @item a
1018 Annotate the revision on the current line (@pxref{Old Revisions}).
1020 @item e
1021 Modify the change comment displayed at point.  Note that not all VC
1022 systems support modifying change comments.
1024 @item f
1025 Visit the revision indicated at the current line.
1027 @item d
1028 Display a diff between the revision at point and the next earlier
1029 revision, for the specific file.
1031 @item D
1032 Display the changeset diff between the revision at point and the next
1033 earlier revision.  This shows the changes to all files made in that
1034 revision.
1036 @item @key{RET}
1037 In a compact-style log buffer (e.g., the one created by @kbd{C-x v
1038 L}), toggle between showing and hiding the full log entry for the
1039 revision at point.
1040 @end table
1042 @vindex vc-log-show-limit
1043 Because fetching many log entries can be slow, the
1044 @file{*vc-change-log*} buffer displays no more than 2000 revisions by
1045 default.  The variable @code{vc-log-show-limit} specifies this limit;
1046 if you set the value to zero, that removes the limit.  You can also
1047 increase the number of revisions shown in an existing
1048 @file{*vc-change-log*} buffer by clicking on the @samp{Show 2X
1049 entries} or @samp{Show unlimited entries} buttons at the end of the
1050 buffer.  However, RCS, SCCS, and CVS do not support this feature.
1052 @findex vc-region-history
1053 A useful variant of examining changes is provided by the command
1054 @kbd{vc-region-history}, which shows a @file{*VC-history*} buffer with
1055 the history of changes to the region of the current file between point
1056 and the mark (@pxref{Mark}).  The history of changes includes the
1057 commit log messages and also the changes themselves in the Diff
1058 format.
1060 Invoke this command after marking the region of the current file in
1061 whose changes you are interested.  In the @file{*VC-history*} buffer
1062 it pops up, you can use all of the commands available in the
1063 @file{*vc-change-log*} buffer described above, and also the commands
1064 defined by Diff mode (@pxref{Diff Mode}).
1066 This command is currently available only with Git.
1068 @node VC Undo
1069 @subsection Undoing Version Control Actions
1071 @table @kbd
1072 @item C-x v u
1073 Revert the work file(s) in the current VC fileset to the last revision
1074 (@code{vc-revert}).
1075 @end table
1077 @kindex C-x v u
1078 @findex vc-revert
1079 @vindex vc-revert-show-diff
1080   If you want to discard all the changes you have made to the current
1081 VC fileset, type @kbd{C-x v u} (@code{vc-revert-buffer}).  This shows
1082 you a diff between the work file(s) and the revision from which you
1083 started editing, and asks for confirmation for discarding the changes.
1084 If you agree, the fileset is reverted.  If you don't want @kbd{C-x v
1085 u} to show a diff, set the variable @code{vc-revert-show-diff} to
1086 @code{nil} (you can still view the diff directly with @kbd{C-x v =};
1087 @pxref{Old Revisions}).  Note that @kbd{C-x v u} cannot be reversed
1088 with the usual undo commands (@pxref{Undo}), so use it with care.
1090   On locking-based version control systems, @kbd{C-x v u} leaves files
1091 unlocked; you must lock again to resume editing.  You can also use
1092 @kbd{C-x v u} to unlock a file if you lock it and then decide not to
1093 change it.
1095 @node VC Ignore
1096 @subsection Ignore Version Control Files
1098 @table @kbd
1099 @item C-x v G
1100 Ignore a file under current version control system.  (@code{vc-ignore}).
1101 @end table
1103 @kindex C-x v G
1104 @findex vc-ignore
1105   Many source trees contain some files that do not need to be
1106 versioned, such as editor backups, object or bytecode files, and built
1107 programs.  You can simply not add them, but then they'll always crop
1108 up as unknown files.  You can also tell the version control system to
1109 ignore these files by adding them to the ignore file at the top of the
1110 tree.  @kbd{C-x v G} (@code{vc-ignore}) can help you do this.  When
1111 called with a prefix argument, you can remove a file from the ignored
1112 file list.
1114 @node VC Directory Mode
1115 @subsection VC Directory Mode
1117 @cindex VC Directory buffer
1118   The @dfn{VC Directory buffer} is a specialized buffer for viewing
1119 the version control statuses of the files in a directory tree, and
1120 performing version control operations on those files.  In particular,
1121 it is used to specify multi-file VC filesets for commands like
1122 @w{@kbd{C-x v v}} to act on (@pxref{VC Directory Commands}).
1124 @kindex C-x v d
1125 @findex vc-dir
1126   To use the VC Directory buffer, type @kbd{C-x v d} (@code{vc-dir}).
1127 This reads a directory name using the minibuffer, and switches to a VC
1128 Directory buffer for that directory.  By default, the buffer is named
1129 @file{*vc-dir*}.  Its contents are described
1130 @iftex
1131 below.
1132 @end iftex
1133 @ifnottex
1134 in @ref{VC Directory Buffer}.
1135 @end ifnottex
1137   The @code{vc-dir} command automatically detects the version control
1138 system to be used in the specified directory.  In the event that more
1139 than one system is being used in the directory, you should invoke the
1140 command with a prefix argument, @kbd{C-u C-x v d}; this prompts for
1141 the version control system which the VC Directory buffer should use.
1143 @ifnottex
1144 @cindex PCL-CVS
1145 @pindex cvs
1146 @cindex CVS directory mode
1147   In addition to the VC Directory buffer, Emacs has a similar facility
1148 called PCL-CVS which is specialized for CVS@.  @xref{Top, , About
1149 PCL-CVS, pcl-cvs, PCL-CVS---The Emacs Front-End to CVS}.
1150 @end ifnottex
1152 @menu
1153 * Buffer: VC Directory Buffer.      What the buffer looks like and means.
1154 * Commands: VC Directory Commands.  Commands to use in a VC directory buffer.
1155 @end menu
1157 @node VC Directory Buffer
1158 @subsubsection The VC Directory Buffer
1160   The VC Directory buffer contains a list of version-controlled files
1161 and their version control statuses.  It lists files in the current
1162 directory (the one specified when you called @kbd{C-x v d}) and its
1163 subdirectories, but only those with a noteworthy status.  Files
1164 that are up-to-date (i.e., the same as in the repository) are
1165 omitted.  If all the files in a subdirectory are up-to-date, the
1166 subdirectory is not listed either.  As an exception, if a file has
1167 become up-to-date as a direct result of a VC command, it is listed.
1169   Here is an example of a VC Directory buffer listing:
1171 @smallexample
1172 @group
1173                      ./
1174     edited           configure.ac
1175 *   added            README
1176     unregistered     temp.txt
1177                      src/
1178 *   edited           src/main.c
1179 @end group
1180 @end smallexample
1182 @noindent
1183 Two work files have been modified but not committed:
1184 @file{configure.ac} in the current directory, and @file{foo.c} in the
1185 @file{src/} subdirectory.  The file named @file{README} has been added
1186 but is not yet committed, while @file{temp.txt} is not under version
1187 control (@pxref{Registering}).
1189 The @samp{*} characters next to the entries for @file{README} and
1190 @file{src/main.c} indicate that the user has marked out these files as
1191 the current VC fileset
1192 @iftex
1193 (see below).
1194 @end iftex
1195 @ifnottex
1196 (@pxref{VC Directory Commands}).
1197 @end ifnottex
1199   The above example is typical for a decentralized version control
1200 system like Bazaar, Git, or Mercurial.  Other systems can show other
1201 statuses.  For instance, CVS shows the @samp{needs-update} status if
1202 the repository has changes that have not been applied to the work
1203 file.  RCS and SCCS show the name of the user locking a file as its
1204 status.
1206 @ifnottex
1207 @vindex vc-stay-local
1208 @vindex vc-cvs-stay-local
1209   On CVS and Subversion, the @code{vc-dir} command normally contacts
1210 the repository, which may be on a remote machine, to check for
1211 updates.  If you change the variable @code{vc-stay-local} or
1212 @code{vc-cvs-stay-local} (for CVS) to @code{nil} (@pxref{CVS
1213 Options}), then Emacs avoids contacting a remote repository when
1214 generating the VC Directory buffer (it will still contact it when
1215 necessary, e.g., when doing a commit).  This may be desirable if you
1216 are working offline or the network is slow.
1217 @end ifnottex
1219 @vindex vc-directory-exclusion-list
1220   The VC Directory buffer omits subdirectories listed in the variable
1221 @code{vc-directory-exclusion-list}.  Its default value contains
1222 directories that are used internally by version control systems.
1224 @node VC Directory Commands
1225 @subsubsection VC Directory Commands
1227   Emacs provides several commands for navigating the VC Directory
1228 buffer, and for marking files as belonging to the current VC
1229 fileset.
1231 @table @kbd
1232 @item n
1233 @itemx @key{SPC}
1234 Move point to the next entry (@code{vc-dir-next-line}).
1236 @item p
1237 Move point to the previous entry (@code{vc-dir-previous-line}).
1239 @item @key{TAB}
1240 Move to the next directory entry (@code{vc-dir-next-directory}).
1242 @item S-@key{TAB}
1243 Move to the previous directory entry
1244 (@code{vc-dir-previous-directory}).
1246 @item @key{RET}
1247 @itemx f
1248 Visit the file or directory listed on the current line
1249 (@code{vc-dir-find-file}).
1251 @item o
1252 Visit the file or directory on the current line, in a separate window
1253 (@code{vc-dir-find-file-other-window}).
1255 @item m
1256 Mark the file or directory on the current line (@code{vc-dir-mark}),
1257 putting it in the current VC fileset.  If the region is active, mark
1258 all files in the region.
1260 A file cannot be marked with this command if it is already in a marked
1261 directory, or one of its subdirectories.  Similarly, a directory
1262 cannot be marked with this command if any file in its tree is marked.
1264 @item M
1265 If point is on a file entry, mark all files with the same status; if
1266 point is on a directory entry, mark all files in that directory tree
1267 (@code{vc-dir-mark-all-files}).  With a prefix argument, mark all
1268 listed files and directories.
1270 @item q
1271 Quit the VC Directory buffer, and bury it (@code{quit-window}).
1273 @item u
1274 Unmark the file or directory on the current line.  If the region is
1275 active, unmark all the files in the region (@code{vc-dir-unmark}).
1277 @item U
1278 If point is on a file entry, unmark all files with the same status; if
1279 point is on a directory entry, unmark all files in that directory tree
1280 (@code{vc-dir-unmark-all-files}).  With a prefix argument, unmark all
1281 files and directories.
1283 @item x
1284 Hide files with @samp{up-to-date} status
1285 (@code{vc-dir-hide-up-to-date}).  With a prefix argument, hide items
1286 whose state is that of the item at point.
1287 @end table
1289 @findex vc-dir-mark
1290 @findex vc-dir-mark-all-files
1291   While in the VC Directory buffer, all the files that you mark with
1292 @kbd{m} (@code{vc-dir-mark}) or @kbd{M} (@code{vc-dir-mark-all-files})
1293 are in the current VC fileset.  If you mark a directory entry with
1294 @kbd{m}, all the listed files in that directory tree are in the
1295 current VC fileset.  The files and directories that belong to the
1296 current VC fileset are indicated with a @samp{*} character in the VC
1297 Directory buffer, next to their VC status.  In this way, you can set
1298 up a multi-file VC fileset to be acted on by VC commands like
1299 @w{@kbd{C-x v v}} (@pxref{Basic VC Editing}), @w{@kbd{C-x v =}}
1300 (@pxref{Old Revisions}), and @w{@kbd{C-x v u}} (@pxref{VC Undo}).
1302   The VC Directory buffer also defines some single-key shortcuts for
1303 VC commands with the @kbd{C-x v} prefix: @kbd{=}, @kbd{+}, @kbd{l},
1304 @kbd{i}, @kbd{D}, @kbd{L}, @kbd{G}, @kbd{I}, @kbd{O}, and @kbd{v}.
1306   For example, you can commit a set of edited files by opening a VC
1307 Directory buffer, where the files are listed with the @samp{edited}
1308 status; marking the files; and typing @kbd{v} or @kbd{C-x v v}
1309 (@code{vc-next-action}).  If the version control system is
1310 changeset-based, Emacs will commit the files in a single revision.
1312   While in the VC Directory buffer, you can also perform search and
1313 replace on the current VC fileset, with the following commands:
1315 @table @kbd
1316 @item S
1317 Search the fileset (@code{vc-dir-search}).
1319 @item Q
1320 Do a regular expression query replace on the fileset
1321 (@code{vc-dir-query-replace-regexp}).
1323 @item M-s a C-s
1324 Do an incremental search on the fileset (@code{vc-dir-isearch}).
1326 @item M-s a C-M-s
1327 Do an incremental regular expression search on the fileset
1328 (@code{vc-dir-isearch-regexp}).
1329 @end table
1331 @noindent
1332 Apart from acting on multiple files, these commands behave much like
1333 their single-buffer counterparts (@pxref{Search}).
1335   The VC Directory buffer additionally defines some branch-related
1336 commands starting with the prefix @kbd{B}:
1338 @table @kbd
1339 @item B c
1340 Create a new branch (@code{vc-create-tag}).
1342 @item B l
1343 Prompt for the name of a branch and display the change history of that
1344 branch (@code{vc-print-branch-log}).
1346 @item B s
1347 Switch to a branch (@code{vc-retrieve-tag}).  @xref{Switching Branches}.
1348 @end table
1350 @cindex stashes in version control
1351 @cindex shelves in version control
1352   The above commands are also available via the menu bar, and via a
1353 context menu invoked by @kbd{mouse-2}.  Furthermore, some VC backends
1354 use the menu to provide extra backend-specific commands.  For example,
1355 Git and Bazaar allow you to manipulate @dfn{stashes} and @dfn{shelves}
1356 (where are a way to temporarily put aside uncommitted changes, and
1357 bring them back at a later time).
1359 @node Branches
1360 @subsection Version Control Branches
1361 @cindex branch (version control)
1363   One use of version control is to support multiple independent lines
1364 of development, which are called @dfn{branches}.  Amongst other
1365 things, branches can be used for maintaining separate stable and
1366 development versions of a program, and for developing unrelated
1367 features in isolation from one another.
1369   VC's support for branch operations is currently fairly limited.  For
1370 decentralized version control systems, it provides commands for
1371 @dfn{updating} one branch with the contents of another, and for
1372 @dfn{merging} the changes made to two different branches
1373 (@pxref{Merging}).  For centralized version control systems, it
1374 supports checking out different branches and committing into new or
1375 different branches.
1377 @menu
1378 * Switching Branches::    How to get to another existing branch.
1379 * Pulling / Pushing::     Receiving/sending changes from/to elsewhere.
1380 * Merging::               Transferring changes between branches.
1381 * Creating Branches::     How to start a new branch.
1382 @end menu
1384 @node Switching Branches
1385 @subsubsection Switching between Branches
1387   The various version control systems differ in how branches are
1388 implemented, and these differences cannot be entirely concealed by VC.
1390   On some decentralized version control systems, including Bazaar and
1391 Mercurial in its normal mode of operation, each branch has its own
1392 working directory tree, so switching between branches just involves
1393 switching directories.  On Git, branches are normally @dfn{co-located}
1394 in the same directory, and switching between branches is done using
1395 the @command{git checkout} command, which changes the contents of the
1396 working tree to match the branch you switch to.  Bazaar also supports
1397 co-located branches, in which case the @command{bzr switch} command
1398 will switch branches in the current directory.  With Subversion, you
1399 switch to another branch using the @command{svn switch} command.
1401   The VC command to switch to another branch in the current directory
1402 is @kbd{C-x v r @var{branch-name} @key{RET}} (@code{vc-retrieve-tag}).
1404   On centralized version control systems, you can also switch between
1405 branches by typing @kbd{C-u C-x v v} in an up-to-date work file
1406 (@pxref{Advanced C-x v v}), and entering the revision ID for a
1407 revision on another branch.  On CVS, for instance, revisions on the
1408 @dfn{trunk} (the main line of development) normally have IDs of the
1409 form 1.1, 1.2, 1.3, @dots{}, while the first branch created from (say)
1410 revision 1.2 has revision IDs 1.2.1.1, 1.2.1.2, @dots{}, the second
1411 branch created from revision 1.2 has revision IDs 1.2.2.1, 1.2.2.2,
1412 @dots{}, and so forth.  You can also specify the @dfn{branch ID},
1413 which is a branch revision ID omitting its final component
1414 (e.g., 1.2.1), to switch to the latest revision on that branch.
1416   On a locking-based system, switching to a different branch also
1417 unlocks (write-protects) the working tree.
1419   Once you have switched to a branch, VC commands will apply to that
1420 branch until you switch away; for instance, any VC filesets that you
1421 commit will be committed to that specific branch.
1423 @node Pulling / Pushing
1424 @subsubsection Pulling/Pushing Changes into/from a Branch
1426 @table @kbd
1427 @item C-x v P
1428 On a decentralized version control system, update another location
1429 with changes from the current branch (a.k.a. ``push'' changes).  This
1430 concept does not exist for centralized version control systems
1432 @item C-x v +
1433 On a decentralized version control system, update the current branch
1434 by ``pulling in'' changes from another location.
1436 On a centralized version control system, update the current VC
1437 fileset.
1438 @end table
1440 @kindex C-x v P
1441 @findex vc-push
1442 On a decentralized version control system, the command @kbd{C-x v P}
1443 (@code{vc-push}) updates another location with changes from the
1444 current branch.  With a prefix argument, it prompts for the exact
1445 version control command to run, which lets you specify where to push
1446 changes; the default is @command{bzr push} with Bazaar, @command{git
1447 push} with Git, and @command{hg push} with Mercurial.  The default
1448 commands always push to a default location determined by the version
1449 control system from your branch configuration.
1451 Prior to pushing, you can use @kbd{C-x v O} (@code{vc-log-outgoing})
1452 to view a log buffer of the changes to be sent.  @xref{VC Change Log}.
1454 @cindex bound branch (Bazaar VCS)
1455 This command is currently supported only by Bazaar, Git, and Mercurial.
1456 The concept of ``pushing'' does not exist for centralized version
1457 control systems, where this operation is a part of committing a
1458 changeset, so invoking this command on a centralized VCS signals an
1459 error.  This command also signals an error when attempted in a Bazaar
1460 @dfn{bound branch}, where committing a changeset automatically pushes
1461 the changes to the remote repository to which the local branch is
1462 bound.
1464 @kindex C-x v +
1465 @findex vc-pull
1466   On a decentralized version control system, the command @kbd{C-x v +}
1467 (@code{vc-pull}) updates the current branch and working tree.  It is
1468 typically used to update a copy of a remote branch.  If you supply a
1469 prefix argument, the command prompts for the exact version control
1470 command to use, which lets you specify where to pull changes from.
1471 Otherwise, it pulls from a default location determined by the version
1472 control system.
1474   Amongst decentralized version control systems, @kbd{C-x v +} is
1475 currently supported only by Bazaar, Git, and Mercurial.  With Bazaar,
1476 it calls @command{bzr pull} for ordinary branches (to pull from a
1477 master branch into a mirroring branch), and @command{bzr update} for a
1478 bound branch (to pull from a central repository).  With Git, it calls
1479 @command{git pull} to fetch changes from a remote repository and merge
1480 it into the current branch.  With Mercurial, it calls @command{hg pull
1481 -u} to fetch changesets from the default remote repository and update
1482 the working directory.
1484   Prior to pulling, you can use @kbd{C-x v I} (@code{vc-log-incoming})
1485 to view a log buffer of the changes to be applied.  @xref{VC Change
1486 Log}.
1488   On a centralized version control system like CVS, @kbd{C-x v +}
1489 updates the current VC fileset from the repository.
1491 @node Merging
1492 @subsubsection Merging Branches
1493 @cindex merging changes
1495 @table @kbd
1496 @item C-x v m
1497 On a decentralized version control system, merge changes from another
1498 branch into the current one.
1500 On a centralized version control system, merge changes from another
1501 branch into the current VC fileset.
1502 @end table
1504   While developing a branch, you may sometimes need to @dfn{merge} in
1505 changes that have already been made in another branch.  This is not a
1506 trivial operation, as overlapping changes may have been made to the
1507 two branches.
1509   On a decentralized version control system, merging is done with the
1510 command @kbd{C-x v m} (@code{vc-merge}).  On Bazaar, this prompts for
1511 the exact arguments to pass to @command{bzr merge}, offering a
1512 sensible default if possible.  On Git, this prompts for the name of a
1513 branch to merge from, with completion (based on the branch names known
1514 to the current repository).  The output from running the merge command
1515 is shown in a separate buffer.
1517   On a centralized version control system like CVS, @kbd{C-x v m}
1518 prompts for a branch ID, or a pair of revision IDs (@pxref{Switching
1519 Branches}); then it finds the changes from that branch, or the changes
1520 between the two revisions you specified, and merges those changes into
1521 the current VC fileset.  If you just type @key{RET}, Emacs simply
1522 merges any changes that were made on the same branch since you checked
1523 the file out.
1525 @cindex conflicts
1526 @cindex resolving conflicts
1527   Immediately after performing a merge, only the working tree is
1528 modified, and you can review the changes produced by the merge with
1529 @kbd{C-x v D} and related commands (@pxref{Old Revisions}).  If the
1530 two branches contained overlapping changes, merging produces a
1531 @dfn{conflict}; a warning appears in the output of the merge command,
1532 and @dfn{conflict markers} are inserted into each affected work file,
1533 surrounding the two sets of conflicting changes.  You must then
1534 resolve the conflict by editing the conflicted files.  Once you are
1535 done, the modified files must be committed in the usual way for the
1536 merge to take effect (@pxref{Basic VC Editing}).
1538 @node Creating Branches
1539 @subsubsection Creating New Branches
1541   On centralized version control systems like CVS, Emacs supports
1542 creating new branches as part of a commit operation.  When committing
1543 a modified VC fileset, type @kbd{C-u C-x v v} (@code{vc-next-action}
1544 with a prefix argument; @pxref{Advanced C-x v v}).  Then Emacs prompts
1545 for a revision ID for the new revision.  You should specify a suitable
1546 branch ID for a branch starting at the current revision.  For example,
1547 if the current revision is 2.5, the branch ID should be 2.5.1, 2.5.2,
1548 and so on, depending on the number of existing branches at that point.
1550   To create a new branch at an older revision (one that is no longer
1551 the head of a branch), first select that revision (@pxref{Switching
1552 Branches}).  Your procedure will then differ depending on whether you
1553 are using a locking or merging-based VCS.
1555   On a locking VCS, you will need to lock the old revision branch with
1556 @kbd{C-x v v}.  You'll be asked to confirm, when you lock the old
1557 revision, that you really mean to create a new branch---if you say no,
1558 you'll be offered a chance to lock the latest revision instead.  On a
1559 merging-based VCS you will skip this step.
1561   Then make your changes and type @kbd{C-x v v} again to commit a new
1562 revision.  This creates a new branch starting from the selected
1563 revision.
1565   After the branch is created, subsequent commits create new revisions
1566 on that branch.  To leave the branch, you must explicitly select a
1567 different revision with @kbd{C-u C-x v v}.
1569 @ifnottex
1570 @include vc1-xtra.texi
1571 @end ifnottex
1573 @node Change Log
1574 @section Change Logs
1576 @cindex change log
1577   Many software projects keep a @dfn{change log}.  This is a file,
1578 normally named @file{ChangeLog}, containing a chronological record of
1579 when and how the program was changed.  Sometimes, these files are
1580 automatically generated from the change log entries stored in version
1581 control systems, or are used to generate these change log entries.
1582 Sometimes, there are several change log files, each recording the
1583 changes in one directory or directory tree.
1585 @menu
1586 * Change Log Commands:: Commands for editing change log files.
1587 * Format of ChangeLog:: What the change log file looks like.
1588 @end menu
1590 @node Change Log Commands
1591 @subsection Change Log Commands
1593 @kindex C-x 4 a
1594 @findex add-change-log-entry-other-window
1595   The Emacs command @kbd{C-x 4 a} adds a new entry to the change log
1596 file for the file you are editing
1597 (@code{add-change-log-entry-other-window}).  If that file is actually
1598 a backup file, it makes an entry appropriate for the file's
1599 parent---that is useful for making log entries for functions that
1600 have been deleted in the current version.
1602   @kbd{C-x 4 a} visits the change log file and creates a new entry
1603 unless the most recent entry is for today's date and your name.  It
1604 also creates a new item for the current file.  For many languages, it
1605 can even guess the name of the function or other object that was
1606 changed.
1608 @c Not worth it.
1609 @c @vindex change-log-directory-files
1610 To find the change log file, Emacs searches up the directory tree from
1611 the file you are editing.  By default, it stops if it finds a
1612 directory that seems to be the root of a version-control repository.
1613 To change this, customize @code{change-log-directory-files}.
1615 @vindex add-log-keep-changes-together
1616   When the variable @code{add-log-keep-changes-together} is
1617 non-@code{nil}, @kbd{C-x 4 a} adds to any existing item for the file
1618 rather than starting a new item.
1620 You can combine multiple changes of the same nature.  If you don't
1621 enter any text after the initial @kbd{C-x 4 a}, any subsequent
1622 @kbd{C-x 4 a} adds another symbol to the change log entry.
1624 @vindex add-log-always-start-new-record
1625   If @code{add-log-always-start-new-record} is non-@code{nil},
1626 @kbd{C-x 4 a} always makes a new entry, even if the last entry
1627 was made by you and on the same date.
1629 @vindex change-log-version-info-enabled
1630 @vindex change-log-version-number-regexp-list
1631 @cindex file version in change log entries
1632   If the value of the variable @code{change-log-version-info-enabled}
1633 is non-@code{nil}, @kbd{C-x 4 a} adds the file's version number to the
1634 change log entry.  It finds the version number by searching the first
1635 ten percent of the file, using regular expressions from the variable
1636 @code{change-log-version-number-regexp-list}.
1638 @cindex Change Log mode
1639 @findex change-log-mode
1640   The change log file is visited in Change Log mode.  In this major
1641 mode, each bunch of grouped items counts as one paragraph, and each
1642 entry is considered a page.  This facilitates editing the entries.
1643 @kbd{C-j} and auto-fill indent each new line like the previous line;
1644 this is convenient for entering the contents of an entry.
1646 You can use the @code{next-error} command (by default bound to
1647 @kbd{C-x `}) to move between entries in the Change Log, when Change
1648 Log mode is on.  You will jump to the actual site in the file that was
1649 changed, not just to the next Change Log entry.  You can also use
1650 @code{previous-error} to move back in the same list.
1652 @findex change-log-merge
1653   You can use the command @kbd{M-x change-log-merge} to merge other
1654 log files into a buffer in Change Log Mode, preserving the date
1655 ordering of entries.
1657   Version control systems are another way to keep track of changes in
1658 your program and keep a change log.  In the VC log buffer, typing
1659 @kbd{C-c C-a} (@code{log-edit-insert-changelog}) inserts the relevant
1660 Change Log entry, if one exists.  @xref{Log Buffer}.
1662 @node Format of ChangeLog
1663 @subsection Format of ChangeLog
1665   A change log entry starts with a header line that contains the
1666 current date, your name (taken from the variable
1667 @code{add-log-full-name}), and your email address (taken from the
1668 variable @code{add-log-mailing-address}).  Aside from these header
1669 lines, every line in the change log starts with a space or a tab.  The
1670 bulk of the entry consists of @dfn{items}, each of which starts with a
1671 line starting with whitespace and a star.  Here are two entries, both
1672 dated in May 1993, with two items and one item respectively.
1674 @iftex
1675 @medbreak
1676 @end iftex
1677 @smallexample
1678 1993-05-25  Richard Stallman  <rms@@gnu.org>
1680         * man.el: Rename symbols 'man-*' to 'Man-*'.
1681         (manual-entry): Make prompt string clearer.
1683         * simple.el (blink-matching-paren-distance):
1684         Change default to 12,000.
1686 1993-05-24  Richard Stallman  <rms@@gnu.org>
1688         * vc.el (minor-mode-map-alist): Don't use it if it's void.
1689         (vc-cancel-version): Doc fix.
1690 @end smallexample
1692   One entry can describe several changes; each change should have its
1693 own item, or its own line in an item.  Normally there should be a
1694 blank line between items.  When items are related (parts of the same
1695 change, in different places), group them by leaving no blank line
1696 between them.
1698   You should put a copyright notice and permission notice at the
1699 end of the change log file.  Here is an example:
1701 @smallexample
1702 Copyright 1997, 1998 Free Software Foundation, Inc.
1703 Copying and distribution of this file, with or without modification, are
1704 permitted provided the copyright notice and this notice are preserved.
1705 @end smallexample
1707 @noindent
1708 Of course, you should substitute the proper years and copyright holder.
1710 @node Xref
1711 @section Find Identifier References
1712 @cindex xref
1714   An @dfn{identifier} is a name of a syntactical subunit of the
1715 program: a function, a subroutine, a method, a class, a data type, a
1716 macro, etc.  In a programming language, each identifier is a symbol in
1717 the language's syntax.  Program development and maintenance requires
1718 capabilities to quickly find where each identifier was defined and
1719 referenced, to rename identifiers across the entire project, etc.
1721 These capabilities are also useful for finding references in major
1722 modes other than those defined to support programming languages.  For
1723 example, chapters, sections, appendices, etc.@: of a text or a @TeX{}
1724 document can be treated as subunits as well, and their names can be
1725 used as identifiers.  In this chapter, we use the term ``identifiers''
1726 to collectively refer to the names of any kind of subunits, in program
1727 source and in other kinds of text alike.
1729 Emacs provides a unified interface to these capabilities, called
1730 @samp{xref}.
1732 @cindex xref backend
1733 To do its job, @code{xref} needs to make use of information and to
1734 employ methods specific to the major mode.  What files to search for
1735 identifiers, how to find references to identifiers, how to complete on
1736 identifiers---all this and more is mode-specific knowledge.
1737 @code{xref} delegates the mode-specific parts of its job to a
1738 @dfn{backend} provided by the mode; it also includes defaults for some
1739 of its commands, for those modes that don't provide their own.
1741 A backend can implement its capabilities in a variety of ways.  Here
1742 are a few examples:
1744 @enumerate a
1745 @item
1746 Some major modes provide built-in means for looking up the language
1747 symbols.  For example, Emacs Lisp symbols can be identified by
1748 searching the package load history, maintained by the Emacs Lisp
1749 interpreter, and by consulting the built-in documentation strings; the
1750 Emacs Lisp mode uses these facilities in its backend to allow finding
1751 definitions of symbols.  (One disadvantage of this kind of backend is
1752 that it only knows about subunits that were loaded into the
1753 interpreter.)
1755 @item
1756 An external program can extract references by scanning the relevant
1757 files, and build a database of these references.  A backend can then
1758 access this database whenever it needs to list or look up references.
1759 The Emacs distribution includes @command{etags}, a command for tagging
1760 identifier definitions in programs, which supports many programming
1761 languages and other major modes, such as HTML, by extracting
1762 references into @dfn{tags tables}.  @xref{Create Tags Table}.  Major
1763 modes for languages supported by @command{etags} can use tags tables
1764 as basis for their backend.  (One disadvantage of this kind of backend
1765 is that tags tables need to be kept reasonably up to date, by
1766 rebuilding them from time to time.)
1767 @end enumerate
1769 @menu
1770 * Find Identifiers::    Commands to find where an identifier is defined
1771                           or referenced, to list identifiers, etc.
1772 * Tags Tables::         Tags table records which file defines a symbol.
1773 * Select Tags Table::   How to visit a specific tags table.
1774 @end menu
1776 @node Find Identifiers
1777 @subsection Find Identifiers
1779   This subsection describes the commands that find references to
1780 identifiers and perform various queries about identifiers.  Each such
1781 reference could @emph{define} an identifier, e.g., provide the
1782 implementation of a program subunit or the text of a document section;
1783 or it could @emph{use} the identifier, e.g., call a function or a
1784 method, assign a value to a variable, mention a chapter in a
1785 cross-reference, etc.
1787 @menu
1788 * Looking Up Identifiers:: Commands to find the definition of an identifier.
1789 * Xref Commands::          Commands in the @file{*xref*} buffer.
1790 * Identifier Search::      Searching and replacing identifiers.
1791 * List Identifiers::       Listing identifiers and completing on them.
1792 @end menu
1794 @node Looking Up Identifiers
1795 @subsubsection Looking Up Identifiers
1796 @cindex find definition of symbols
1797 @cindex identifier, finding definition of
1798 @cindex find references to symbols
1800   The most important thing that @code{xref} enables you to do is to find
1801 the definition of a specific identifier.
1803 @table @kbd
1804 @item M-.@:
1805 Find definitions of an identifier (@code{xref-find-definitions}).
1806 @item C-M-. @var{pattern} @key{RET}
1807 Find all identifiers whose name matches @var{pattern}
1808 (@code{xref-find-apropos}).
1809 @item C-x 4 .@: @key{RET}
1810 Find definitions of identifier, but display it in another window
1811 (@code{xref-find-definitions-other-window}).
1812 @item C-x 5 .@: @key{RET}
1813 Find definition of identifier, and display it in a new frame
1814 (@code{xref-find-definitions-other-frame}).
1815 @item M-,
1816 Go back to where you previously invoked @kbd{M-.} and friends
1817 (@code{xref-pop-marker-stack}).
1818 @end table
1820 @kindex M-.
1821 @findex xref-find-definitions
1822   @kbd{M-.}@: (@code{xref-find-definitions}) shows the definitions of
1823 the identifier at point.  With a prefix argument, or if there's no
1824 identifier at point, it prompts for the identifier.  If the
1825 identifier has only one definition, the command jumps to it.  If the
1826 identifier has more than one possible definition (e.g., in an
1827 object-oriented language, or if there's a function and a variable by
1828 the same name), the command shows the candidate definitions in a
1829 @file{*xref*} buffer, together with the files in which these
1830 definitions are found.  Selecting one of these candidates by typing
1831 @kbd{@key{RET}} or clicking @kbd{mouse-2} will pop a buffer showing
1832 the corresponding definition.
1834   When entering the identifier argument to @kbd{M-.}, the usual
1835 minibuffer completion commands can be used (@pxref{Completion}), with
1836 the known identifier names as completion candidates.
1838 @kindex C-x 4 .
1839 @findex xref-find-definitions-other-window
1840 @kindex C-x 5 .
1841 @findex xref-find-definitions-other-frame
1842   Like most commands that can switch buffers,
1843 @code{xref-find-definitions} has a variant that displays the new
1844 buffer in another window, and one that makes a new frame for it.  The
1845 former is @w{@kbd{C-x 4 .}}
1846 (@code{xref-find-definitions-other-window}), and the latter is
1847 @w{@kbd{C-x 5 .}}  (@code{xref-find-definitions-other-frame}).
1849 @findex xref-find-apropos
1850 @kindex C-M-.
1851   The command @kbd{C-M-.} (@code{xref-find-apropos}) finds the
1852 definitions of one or more identifiers that match a specified regular
1853 expression.  It is just like @kbd{M-.} except that it does regexp
1854 matching of identifiers instead of matching symbol names as fixed
1855 strings.
1857   When any of the above commands finds more than one definition, it
1858 presents the @file{*xref*} buffer showing the definition candidates.
1859 In that buffer, you have several specialized commands, described in
1860 @ref{Xref Commands}.
1862 @kindex M-,
1863 @findex xref-pop-marker-stack
1864 @vindex xref-marker-ring-length
1865   To go back to places @emph{from where} you found the definition,
1866 use @kbd{M-,} (@code{xref-pop-marker-stack}).  It jumps back to the
1867 point of the last invocation of @kbd{M-.}.  Thus you can find and
1868 examine the definition of something with @kbd{M-.} and then return to
1869 where you were with @kbd{M-,}.  @kbd{M-,} allows you to retrace your
1870 steps to a depth determined by the variable
1871 @code{xref-marker-ring-length}, which defaults to 16.
1873 @node Xref Commands
1874 @subsubsection Commands Available in the @file{*xref*} Buffer
1875 @cindex commands in @file{*xref*} buffers
1876 @cindex XREF mode
1878   The following commands are provided in the @file{*xref*} buffer by
1879 the special XREF mode:
1881 @table @kbd
1882 @item @key{RET}
1883 @itemx mouse-2
1884 Display the reference on the current line and bury the @file{*xref*}
1885 buffer.
1886 @item n
1887 @itemx .
1888 @findex xref-next-line
1889 Move to the next reference and display it in the other window
1890 (@code{xref-next-line}).
1891 @item p
1892 @itemx ,
1893 @findex xref-prev-line
1894 Move to the previous reference and display it in the other window
1895 (@code{xref-prev-line}).
1896 @item C-o
1897 @findex xref-show-location-at-point
1898 Display the reference on the current line in the other window
1899 (@code{xref-show-location-at-point}).
1900 @findex xref-query-replace-in-results
1901 @item r @var{pattern} @key{RET} @var{replacement} @key{RET}
1902 Perform interactive query-replace on references that match
1903 @var{pattern} (@code{xref-query-replace-in-results}), replacing
1904 the match with @var{replacement}.  @xref{Identifier Search}.
1905 @findex xref-quit
1906 @item q
1907 Quit the window showing the @file{*xref*} buffer (@code{xref-quit}).
1908 @end table
1910 In addition, the usual navigation commands, such as the arrow keys,
1911 @kbd{C-n}, and @kbd{C-p} are available for moving around the buffer
1912 without displaying the references.
1914 @node Identifier Search
1915 @subsubsection Searching and Replacing with Identifiers
1916 @cindex search and replace in multiple files
1917 @cindex multiple-file search and replace
1919   The commands in this section perform various search and replace
1920 operations either on identifiers themselves or on files that reference
1921 them.
1923 @table @kbd
1924 @item M-?
1925 Find all the references for the identifier at point.
1926 @item M-x xref-query-replace-in-results @key{RET} @var{regexp} @key{RET} @var{replacement} @key{RET}
1927 Interactively replace @var{regexp} with @var{replacement} in the names
1928 of all the identifiers shown in the @file{*xref*} buffer.
1929 @item M-x tags-search @key{RET} @var{regexp} @key{RET}
1930 Search for @var{regexp} through the files in the selected tags
1931 table.
1932 @item M-x tags-query-replace @key{RET} @var{regexp} @key{RET} @var{replacement} @key{RET}
1933 Perform a @code{query-replace-regexp} on each file in the selected tags table.
1934 @item M-x tags-loop-continue
1935 Restart one of the last 2 commands above, from the current location of point.
1936 @end table
1938 @kindex M-?
1939 @findex xref-find-references
1940   @kbd{M-?} finds all the references for the identifier at point.  If
1941 there's no identifier at point, or when invoked with a prefix
1942 argument, the command prompts for the identifier, with completion.  It
1943 then presents a @file{*xref*} buffer with all the references to the
1944 identifier, showing the file name and the line where the identifier is
1945 referenced.  The XREF mode commands are available in this buffer, see
1946 @ref{Xref Commands}.
1948 @findex xref-query-replace-in-results
1949   @kbd{M-x xref-query-replace-in-results} reads a regexp to match identifier
1950 names and a replacement string, just like ordinary @kbd{M-x
1951 query-replace-regexp}.  It then performs the specified replacement in
1952 the names of the matching identifiers in all the places in all the
1953 files where these identifiers are referenced.  This is useful when you
1954 rename your identifiers as part of refactoring.  This command should
1955 be invoked in the @file{*xref*} buffer generated by @code{M-?}.
1957 @findex tags-search
1958   @kbd{M-x tags-search} reads a regexp using the minibuffer, then
1959 searches for matches in all the files in the selected tags table, one
1960 file at a time.  It displays the name of the file being searched so
1961 you can follow its progress.  As soon as it finds an occurrence,
1962 @code{tags-search} returns.  This command requires tags tables to be
1963 available (@pxref{Tags Tables}).
1965 @findex tags-loop-continue
1966   Having found one match with @code{tags-search}, you probably want to
1967 find all the rest.  Type @kbd{M-x tags-loop-continue} to resume the
1968 @code{tags-search}, finding one more match.  This searches the rest of
1969 the current buffer, followed by the remaining files of the tags table.
1971 @findex tags-query-replace
1972   @kbd{M-x tags-query-replace} performs a single
1973 @code{query-replace-regexp} through all the files in the tags table.  It
1974 reads a regexp to search for and a string to replace with, just like
1975 ordinary @kbd{M-x query-replace-regexp}.  It searches much like @kbd{M-x
1976 tags-search}, but repeatedly, processing matches according to your
1977 input.  @xref{Query Replace}, for more information on query replace.
1979 @vindex tags-case-fold-search
1980 @cindex case-sensitivity and tags search
1981   You can control the case-sensitivity of tags search commands by
1982 customizing the value of the variable @code{tags-case-fold-search}.  The
1983 default is to use the same setting as the value of
1984 @code{case-fold-search} (@pxref{Lax Search}).
1986   It is possible to get through all the files in the tags table with a
1987 single invocation of @kbd{M-x tags-query-replace}.  But often it is
1988 useful to exit temporarily, which you can do with any input event that
1989 has no special query replace meaning.  You can resume the query
1990 replace subsequently by typing @kbd{M-x tags-loop-continue}; this
1991 command resumes the last tags search or replace command that you did.
1992 For instance, to skip the rest of the current file, you can type
1993 @w{@kbd{M-> M-x tags-loop-continue}}.
1995   Note that the commands described above carry out much broader
1996 searches than the @code{xref-find-definitions} family.  The
1997 @code{xref-find-definitions} commands search only for definitions of
1998 identifiers that match your string or regexp.  The commands
1999 @code{xref-find-references}, @code{tags-search}, and
2000 @code{tags-query-replace} find every occurrence of the identifier or
2001 regexp, as ordinary search commands and replace commands do in the
2002 current buffer.
2004   As an alternative to @code{xref-find-references} and
2005 @code{tags-search}, you can run @command{grep} as a subprocess and
2006 have Emacs show you the matching lines one by one.  @xref{Grep
2007 Searching}.
2009 @node List Identifiers
2010 @subsubsection Identifier Inquiries
2012 @table @kbd
2013 @item C-M-i
2014 @itemx M-@key{TAB}
2015 Perform completion on the text around point, possibly using the
2016 selected tags table if one is loaded (@code{completion-at-point}).
2017 @item M-x xref-find-apropos @key{RET} @var{regexp} @key{RET}
2018 Display a list of all known identifiers matching @var{regexp}.
2019 @item M-x list-tags @key{RET} @var{file} @key{RET}
2020 Display a list of the identifiers defined in the program file
2021 @var{file}.
2022 @item M-x next-file
2023 Visit files recorded in the selected tags table.
2024 @end table
2026 @cindex completion (symbol names)
2027   In most programming language modes, you can type @kbd{C-M-i} or
2028 @kbd{M-@key{TAB}} (@code{completion-at-point}) to complete the symbol
2029 at point.  Some modes provide specialized completion for this command
2030 tailored to the mode; for those that don't, if there is a tags table
2031 loaded, this command can use it to generate completion candidates.
2032 @xref{Symbol Completion}.
2034 @findex list-tags
2035   @kbd{M-x list-tags} reads the name of one of the files covered by
2036 the selected tags table, and displays a list of tags defined in that
2037 file.  Do not include a directory as part of the file name unless the
2038 file name recorded in the tags table includes a directory.  This
2039 command works only with the etags backend, and requires a tags table
2040 for the project to be available.  @xref{Tags Tables}.
2042 @c Sadly, the new-and-improved Xref feature doesn't provide anything
2043 @c close to the described below features of the now-obsoleted
2044 @c tags-apropos.  I'm leaving this here to encourage enhancements to
2045 @c xref.el.
2046 @ignore
2047 @findex tags-apropos
2048 @vindex tags-apropos-verbose
2049 @vindex tags-tag-face
2050 @vindex tags-apropos-additional-actions
2051   @kbd{M-x tags-apropos} is like @code{apropos} for tags
2052 (@pxref{Apropos}).  It displays a list of tags in the selected tags
2053 table whose entries match @var{regexp}.  If the variable
2054 @code{tags-apropos-verbose} is non-@code{nil}, it displays the names
2055 of the tags files together with the tag names.  You can customize the
2056 appearance of the output by setting the variable @code{tags-tag-face}
2057 to a face.  You can display additional output by customizing the
2058 variable @code{tags-apropos-additional-actions}; see its documentation
2059 for details.
2060 @end ignore
2062 @findex next-file
2063   @kbd{M-x next-file} visits files covered by the selected tags table.
2064 The first time it is called, it visits the first file covered by the
2065 table.  Each subsequent call visits the next covered file, unless a
2066 prefix argument is supplied, in which case it returns to the first
2067 file.  This command requires a tags table to be selected.
2069 @node Tags Tables
2070 @subsection Tags Tables
2071 @cindex tags and tag tables
2073   A @dfn{tags table} records the tags@footnote{
2074 A @dfn{tag} is a synonym for identifier reference.  Commands and
2075 features based on the @code{etags} package traditionally use ``tag''
2076 with this meaning, and this subsection follows that tradition.
2077 } extracted by scanning the source code of a certain program or a
2078 certain document.  Tags extracted from generated files reference the
2079 original files, rather than the generated files that were scanned
2080 during tag extraction.  Examples of generated files include C files
2081 generated from Cweb source files, from a Yacc parser, or from Lex
2082 scanner definitions; @file{.i} preprocessed C files; and Fortran files
2083 produced by preprocessing @file{.fpp} source files.
2085 @cindex etags
2086   To produce a tags table, you run the @command{etags} shell command
2087 on a document or the source code file.  The @samp{etags} program
2088 writes the tags to a @dfn{tags table file}, or @dfn{tags file} in
2089 short.  The conventional name for a tags file is @file{TAGS}@.
2090 @xref{Create Tags Table}.  (It is also possible to create a tags table
2091 by using one of the commands from other packages that can produce such
2092 tables in the same format.)
2094   Emacs uses the tags tables via the @code{etags} package as one of
2095 the supported backends for @code{xref}.  Because tags tables are
2096 produced by the @command{etags} command that is part of an Emacs
2097 distribution, we describe tags tables in more detail here.
2099 @cindex C++ class browser, tags
2100 @cindex tags, C++
2101 @cindex class browser, C++
2102 @cindex Ebrowse
2103   The Ebrowse facility is similar to @command{etags} but specifically
2104 tailored for C++.  @xref{Top,, Ebrowse, ebrowse, Ebrowse User's
2105 Manual}.  The Semantic package provides another way to generate and
2106 use tags, separate from the @command{etags} facility.
2107 @xref{Semantic}.
2109 @menu
2110 * Tag Syntax::          Tag syntax for various types of code and text files.
2111 * Create Tags Table::   Creating a tags table with @command{etags}.
2112 * Etags Regexps::       Create arbitrary tags using regular expressions.
2113 @end menu
2115 @node Tag Syntax
2116 @subsubsection Source File Tag Syntax
2118   Here is how tag syntax is defined for the most popular languages:
2120 @itemize @bullet
2121 @item
2122 In C code, any C function or typedef is a tag, and so are definitions of
2123 @code{struct}, @code{union} and @code{enum}.
2124 @code{#define} macro definitions, @code{#undef} and @code{enum}
2125 constants are also
2126 tags, unless you specify @samp{--no-defines} when making the tags table.
2127 Similarly, global variables are tags, unless you specify
2128 @samp{--no-globals}, and so are struct members, unless you specify
2129 @samp{--no-members}.  Use of @samp{--no-globals}, @samp{--no-defines}
2130 and @samp{--no-members} can make the tags table file much smaller.
2132 You can tag function declarations and external variables in addition
2133 to function definitions by giving the @samp{--declarations} option to
2134 @command{etags}.
2136 @item
2137 In C++ code, in addition to all the tag constructs of C code, member
2138 functions are also recognized; member variables are also recognized,
2139 unless you use the @samp{--no-members} option.  Tags for variables and
2140 functions in classes are named @samp{@var{class}::@var{variable}} and
2141 @samp{@var{class}::@var{function}}.  @code{operator} definitions have
2142 tag names like @samp{operator+}.
2144 @item
2145 In Java code, tags include all the constructs recognized in C++, plus
2146 the @code{interface}, @code{extends} and @code{implements} constructs.
2147 Tags for variables and functions in classes are named
2148 @samp{@var{class}.@var{variable}} and @samp{@var{class}.@var{function}}.
2150 @item
2151 In @LaTeX{} documents, the arguments for @code{\chapter},
2152 @code{\section}, @code{\subsection}, @code{\subsubsection},
2153 @code{\eqno}, @code{\label}, @code{\ref}, @code{\cite},
2154 @code{\bibitem}, @code{\part}, @code{\appendix}, @code{\entry},
2155 @code{\index}, @code{\def}, @code{\newcommand}, @code{\renewcommand},
2156 @code{\newenvironment} and @code{\renewenvironment} are tags.
2158 Other commands can make tags as well, if you specify them in the
2159 environment variable @env{TEXTAGS} before invoking @command{etags}.  The
2160 value of this environment variable should be a colon-separated list of
2161 command names.  For example,
2163 @example
2164 TEXTAGS="mycommand:myothercommand"
2165 export TEXTAGS
2166 @end example
2168 @noindent
2169 specifies (using Bourne shell syntax) that the commands
2170 @samp{\mycommand} and @samp{\myothercommand} also define tags.
2172 @item
2173 In Lisp code, any function defined with @code{defun}, any variable
2174 defined with @code{defvar} or @code{defconst}, and in general the
2175 first argument of any expression that starts with @samp{(def} in
2176 column zero is a tag.  As an exception, expressions of the form
2177 @code{(defvar @var{foo})} are treated as declarations, and are only
2178 tagged if the @samp{--declarations} option is given.
2180 @item
2181 In Scheme code, tags include anything defined with @code{def} or with a
2182 construct whose name starts with @samp{def}.  They also include variables
2183 set with @code{set!} at top level in the file.
2184 @end itemize
2186   Several other languages are also supported:
2188 @itemize @bullet
2190 @item
2191 In Ada code, functions, procedures, packages, tasks and types are
2192 tags.  Use the @samp{--packages-only} option to create tags for
2193 packages only.
2195 In Ada, the same name can be used for different kinds of entity
2196 (e.g., for a procedure and for a function).  Also, for things like
2197 packages, procedures and functions, there is the spec (i.e., the
2198 interface) and the body (i.e., the implementation).  To make it
2199 easier to pick the definition you want, Ada tag name have suffixes
2200 indicating the type of entity:
2202 @table @samp
2203 @item /b
2204 package body.
2205 @item /f
2206 function.
2207 @item /k
2208 task.
2209 @item /p
2210 procedure.
2211 @item /s
2212 package spec.
2213 @item /t
2214 type.
2215 @end table
2217   Thus, @kbd{M-x find-tag @key{RET} bidule/b @key{RET}} will go
2218 directly to the body of the package @code{bidule}, while @kbd{M-x
2219 find-tag @key{RET} bidule @key{RET}} will just search for any tag
2220 @code{bidule}.
2222 @item
2223 In assembler code, labels appearing at the start of a line,
2224 followed by a colon, are tags.
2226 @item
2227 In Bison or Yacc input files, each rule defines as a tag the nonterminal
2228 it constructs.  The portions of the file that contain C code are parsed
2229 as C code.
2231 @item
2232 In Cobol code, tags are paragraph names; that is, any word starting in
2233 column 8 and followed by a period.
2235 @item
2236 In Erlang code, the tags are the functions, records and macros defined
2237 in the file.
2239 @item
2240 In Fortran code, functions, subroutines and block data are tags.
2242 @item
2243 In Go code, packages, functions, and types are tags.
2245 @item
2246 In HTML input files, the tags are the @code{title} and the @code{h1},
2247 @code{h2}, @code{h3} headers.  Also, tags are @code{name=} in anchors
2248 and all occurrences of @code{id=}.
2250 @item
2251 In Lua input files, all functions are tags.
2253 @item
2254 In makefiles, targets are tags; additionally, variables are tags
2255 unless you specify @samp{--no-globals}.
2257 @item
2258 In Objective C code, tags include Objective C definitions for classes,
2259 class categories, methods and protocols.  Tags for variables and
2260 functions in classes are named @samp{@var{class}::@var{variable}} and
2261 @samp{@var{class}::@var{function}}.
2263 @item
2264 In Pascal code, the tags are the functions and procedures defined in
2265 the file.
2267 @item
2268 In Perl code, the tags are the packages, subroutines and variables
2269 defined by the @code{package}, @code{sub}, @code{use constant},
2270 @code{my}, and @code{local} keywords.  Use @samp{--globals} if you
2271 want to tag global variables.  Tags for subroutines are named
2272 @samp{@var{package}::@var{sub}}.  The name for subroutines defined in
2273 the default package is @samp{main::@var{sub}}.
2275 @item
2276 In PHP code, tags are functions, classes and defines.  Vars are tags
2277 too, unless you use the @samp{--no-members} option.
2279 @item
2280 In PostScript code, the tags are the functions.
2282 @item
2283 In Prolog code, tags are predicates and rules at the beginning of
2284 line.
2286 @item
2287 In Python code, @code{def} or @code{class} at the beginning of a line
2288 generate a tag.
2290 @item
2291 In Ruby code, @code{def} or @code{class} or @code{module} at the
2292 beginning of a line generate a tag.  Constants also generate tags.
2293 @end itemize
2295   You can also generate tags based on regexp matching (@pxref{Etags
2296 Regexps}) to handle other formats and languages.
2298 @node Create Tags Table
2299 @subsubsection Creating Tags Tables
2300 @cindex @command{etags} program
2302   The @command{etags} program is used to create a tags table file.  It knows
2303 the syntax of several languages, as described in
2304 @iftex
2305 the previous section.
2306 @end iftex
2307 @ifnottex
2308 @ref{Tag Syntax}.
2309 @end ifnottex
2310 Here is how to run @command{etags}:
2312 @example
2313 etags @var{inputfiles}@dots{}
2314 @end example
2316 @noindent
2317 The @command{etags} program reads the specified files, and writes a tags
2318 table named @file{TAGS} in the current working directory.  You can
2319 optionally specify a different file name for the tags table by using the
2320 @samp{--output=@var{file}} option; specifying @file{-} as a file name
2321 prints the tags table to standard output.
2323   If the specified files don't exist, @command{etags} looks for
2324 compressed versions of them and uncompresses them to read them.  Under
2325 MS-DOS, @command{etags} also looks for file names like @file{mycode.cgz}
2326 if it is given @samp{mycode.c} on the command line and @file{mycode.c}
2327 does not exist.
2329   If the tags table becomes outdated due to changes in the files
2330 described in it, you can update it by running the @command{etags}
2331 program again.  If the tags table does not record a tag, or records it
2332 for the wrong file, then Emacs will not be able to find that
2333 definition until you update the tags table.  But if the position
2334 recorded in the tags table becomes a little bit wrong (due to other
2335 editing), Emacs will still be able to find the right position, with a
2336 slight delay.
2338    Thus, there is no need to update the tags table after each edit.
2339 You should update a tags table when you define new tags that you want
2340 to have listed, or when you move tag definitions from one file to
2341 another, or when changes become substantial.
2343   You can make a tags table @dfn{include} another tags table, by
2344 passing the @samp{--include=@var{file}} option to @command{etags}.  It
2345 then covers all the files covered by the included tags file, as well
2346 as its own.
2348   If you specify the source files with relative file names when you run
2349 @command{etags}, the tags file will contain file names relative to the
2350 directory where the tags file was initially written.  This way, you can
2351 move an entire directory tree containing both the tags file and the
2352 source files, and the tags file will still refer correctly to the source
2353 files.  If the tags file is @file{-} or is in the @file{/dev} directory,
2354 however, the file names are
2355 made relative to the current working directory.  This is useful, for
2356 example, when writing the tags to the standard output.
2358   When using a relative file name, it should not be a symbolic link
2359 pointing to a tags file in a different directory, because this would
2360 generally render the file names invalid.
2362   If you specify absolute file names as arguments to @command{etags}, then
2363 the tags file will contain absolute file names.  This way, the tags file
2364 will still refer to the same files even if you move it, as long as the
2365 source files remain in the same place.  Absolute file names start with
2366 @samp{/}, or with @samp{@var{device}:/} on MS-DOS and MS-Windows.
2368    When you want to make a tags table from a great number of files,
2369 you may have problems listing them on the command line, because some
2370 systems have a limit on its length.  You can circumvent this limit by
2371 telling @command{etags} to read the file names from its standard
2372 input, by typing a dash in place of the file names, like this:
2374 @smallexample
2375 find . -name "*.[chCH]" -print | etags -
2376 @end smallexample
2378   @command{etags} recognizes the language used in an input file based
2379 on its file name and contents.  You can specify the language
2380 explicitly with the @samp{--language=@var{name}} option.  You can
2381 intermix these options with file names; each one applies to the file
2382 names that follow it.  Specify @samp{--language=auto} to tell
2383 @command{etags} to resume guessing the language from the file names
2384 and file contents.  Specify @samp{--language=none} to turn off
2385 language-specific processing entirely; then @command{etags} recognizes
2386 tags by regexp matching alone (@pxref{Etags Regexps}).
2388   The option @samp{--parse-stdin=@var{file}} is mostly useful when
2389 calling @command{etags} from programs.  It can be used (only once) in
2390 place of a file name on the command line.  @command{etags} will read from
2391 standard input and mark the produced tags as belonging to the file
2392 @var{file}.
2394   @samp{etags --help} outputs the list of the languages @command{etags}
2395 knows, and the file name rules for guessing the language.  It also prints
2396 a list of all the available @command{etags} options, together with a short
2397 explanation.  If followed by one or more @samp{--language=@var{lang}}
2398 options, it outputs detailed information about how tags are generated for
2399 @var{lang}.
2401 @node Etags Regexps
2402 @subsubsection Etags Regexps
2404   The @samp{--regex} option to @command{etags} allows tags to be
2405 recognized by regular expression matching.  You can intermix this
2406 option with file names; each one applies to the source files that
2407 follow it.  If you specify multiple @samp{--regex} options, all of
2408 them are used in parallel.  The syntax is:
2410 @smallexample
2411 --regex=[@var{@{language@}}]/@var{tagregexp}/[@var{nameregexp}/]@var{modifiers}
2412 @end smallexample
2414 @noindent
2415 The essential part of the option value is @var{tagregexp}, the regexp
2416 for matching tags.  It is always used anchored, that is, it only
2417 matches at the beginning of a line.  If you want to allow indented
2418 tags, use a regexp that matches initial whitespace; start it with
2419 @samp{[ \t]*}.
2421   In these regular expressions, @samp{\} quotes the next character, and
2422 all the GCC character escape sequences are supported (@samp{\a} for
2423 bell, @samp{\b} for back space, @samp{\d} for delete, @samp{\e} for
2424 escape, @samp{\f} for formfeed, @samp{\n} for newline, @samp{\r} for
2425 carriage return, @samp{\t} for tab, and @samp{\v} for vertical tab).
2427   Ideally, @var{tagregexp} should not match more characters than are
2428 needed to recognize what you want to tag.  If the syntax requires you
2429 to write @var{tagregexp} so it matches more characters beyond the tag
2430 itself, you should add a @var{nameregexp}, to pick out just the tag.
2431 This will enable Emacs to find tags more accurately and to do
2432 completion on tag names more reliably.  You can find some examples
2433 below.
2435   The @var{modifiers} are a sequence of zero or more characters that
2436 modify the way @command{etags} does the matching.  A regexp with no
2437 modifiers is applied sequentially to each line of the input file, in a
2438 case-sensitive way.  The modifiers and their meanings are:
2440 @table @samp
2441 @item i
2442 Ignore case when matching this regexp.
2443 @item m
2444 Match this regular expression against the whole file, so that
2445 multi-line matches are possible.
2446 @item s
2447 Match this regular expression against the whole file, and allow
2448 @samp{.} in @var{tagregexp} to match newlines.
2449 @end table
2451   The @samp{-R} option cancels all the regexps defined by preceding
2452 @samp{--regex} options.  It too applies to the file names following
2453 it.  Here's an example:
2455 @smallexample
2456 etags --regex=/@var{reg1}/i voo.doo --regex=/@var{reg2}/m \
2457     bar.ber -R --lang=lisp los.er
2458 @end smallexample
2460 @noindent
2461 Here @command{etags} chooses the parsing language for @file{voo.doo} and
2462 @file{bar.ber} according to their contents.  @command{etags} also uses
2463 @var{reg1} to recognize additional tags in @file{voo.doo}, and both
2464 @var{reg1} and @var{reg2} to recognize additional tags in
2465 @file{bar.ber}.  @var{reg1} is checked against each line of
2466 @file{voo.doo} and @file{bar.ber}, in a case-insensitive way, while
2467 @var{reg2} is checked against the whole @file{bar.ber} file,
2468 permitting multi-line matches, in a case-sensitive way.  @command{etags}
2469 uses only the Lisp tags rules, with no user-specified regexp matching,
2470 to recognize tags in @file{los.er}.
2472   You can restrict a @samp{--regex} option to match only files of a
2473 given language by using the optional prefix @var{@{language@}}.
2474 (@samp{etags --help} prints the list of languages recognized by
2475 @command{etags}.)  This is particularly useful when storing many
2476 predefined regular expressions for @command{etags} in a file.  The
2477 following example tags the @code{DEFVAR} macros in the Emacs source
2478 files, for the C language only:
2480 @smallexample
2481 --regex='@{c@}/[ \t]*DEFVAR_[A-Z_ \t(]+"\([^"]+\)"/'
2482 @end smallexample
2484 @noindent
2485 When you have complex regular expressions, you can store the list of
2486 them in a file.  The following option syntax instructs @command{etags} to
2487 read two files of regular expressions.  The regular expressions
2488 contained in the second file are matched without regard to case.
2490 @smallexample
2491 --regex=@@@var{case-sensitive-file} --ignore-case-regex=@@@var{ignore-case-file}
2492 @end smallexample
2494 @noindent
2495 A regex file for @command{etags} contains one regular expression per
2496 line.  Empty lines, and lines beginning with space or tab are ignored.
2497 When the first character in a line is @samp{@@}, @command{etags} assumes
2498 that the rest of the line is the name of another file of regular
2499 expressions; thus, one such file can include another file.  All the
2500 other lines are taken to be regular expressions.  If the first
2501 non-whitespace text on the line is @samp{--}, that line is a comment.
2503   For example, we can create a file called @samp{emacs.tags} with the
2504 following contents:
2506 @smallexample
2507         -- This is for GNU Emacs C source files
2508 @{c@}/[ \t]*DEFVAR_[A-Z_ \t(]+"\([^"]+\)"/\1/
2509 @end smallexample
2511 @noindent
2512 and then use it like this:
2514 @smallexample
2515 etags --regex=@@emacs.tags *.[ch] */*.[ch]
2516 @end smallexample
2518   Here are some more examples.  The regexps are quoted to protect them
2519 from shell interpretation.
2521 @itemize @bullet
2523 @item
2524 Tag Octave files:
2526 @smallexample
2527 etags --language=none \
2528       --regex='/[ \t]*function.*=[ \t]*\([^ \t]*\)[ \t]*(/\1/' \
2529       --regex='/###key \(.*\)/\1/' \
2530       --regex='/[ \t]*global[ \t].*/' \
2531       *.m
2532 @end smallexample
2534 @noindent
2535 Note that tags are not generated for scripts, so that you have to add
2536 a line by yourself of the form @samp{###key @var{scriptname}} if you
2537 want to jump to it.
2539 @item
2540 Tag Tcl files:
2542 @smallexample
2543 etags --language=none --regex='/proc[ \t]+\([^ \t]+\)/\1/' *.tcl
2544 @end smallexample
2546 @item
2547 Tag VHDL files:
2549 @smallexample
2550 etags --language=none \
2551   --regex='/[ \t]*\(ARCHITECTURE\|CONFIGURATION\) +[^ ]* +OF/' \
2552   --regex='/[ \t]*\(ATTRIBUTE\|ENTITY\|FUNCTION\|PACKAGE\
2553   \( BODY\)?\|PROCEDURE\|PROCESS\|TYPE\)[ \t]+\([^ \t(]+\)/\3/'
2554 @end smallexample
2555 @end itemize
2557 @node Select Tags Table
2558 @subsection Selecting a Tags Table
2560 @findex visit-tags-table
2561   Emacs has at any time at most one @dfn{selected} tags table.  All the
2562 commands for working with tags tables use the selected one.  To select
2563 a tags table, type @kbd{M-x visit-tags-table}, which reads the tags
2564 table file name as an argument, with @file{TAGS} in the default
2565 directory as the default.
2567 @vindex tags-file-name
2568   Emacs does not actually read in the tags table contents until you
2569 try to use them; all @code{visit-tags-table} does is store the file
2570 name in the variable @code{tags-file-name}, and not much more.  The
2571 variable's initial value is @code{nil}; that value tells all the
2572 commands for working with tags tables that they must ask for a tags
2573 table file name to use.
2575   Using @code{visit-tags-table} when a tags table is already loaded
2576 gives you a choice: you can add the new tags table to the current list
2577 of tags tables, or start a new list.  The tags commands use all the tags
2578 tables in the current list.  If you start a new list, the new tags table
2579 is used @emph{instead} of others.  If you add the new table to the
2580 current list, it is used @emph{as well as} the others.
2582 @vindex tags-table-list
2583   You can specify a precise list of tags tables by setting the variable
2584 @code{tags-table-list} to a list of strings, like this:
2586 @c keep this on two lines for formatting in smallbook
2587 @example
2588 @group
2589 (setq tags-table-list
2590       '("~/emacs" "/usr/local/lib/emacs/src"))
2591 @end group
2592 @end example
2594 @noindent
2595 This tells the tags commands to look at the @file{TAGS} files in your
2596 @file{~/emacs} directory and in the @file{/usr/local/lib/emacs/src}
2597 directory.  The order depends on which file you are in and which tags
2598 table mentions that file.
2600   Do not set both @code{tags-file-name} and @code{tags-table-list}.
2602 @node EDE
2603 @section Emacs Development Environment
2604 @cindex EDE (Emacs Development Environment)
2605 @cindex Emacs Development Environment
2606 @cindex Integrated development environment
2608 EDE (@dfn{Emacs Development Environment}) is a package that simplifies
2609 the task of creating, building, and debugging large programs with
2610 Emacs.  It provides some of the features of an IDE, or @dfn{Integrated
2611 Development Environment}, in Emacs.
2613 This section provides a brief description of EDE usage.
2614 @ifnottex
2615 For full details, see @ref{Top, EDE,, ede, Emacs Development Environment}.
2616 @end ifnottex
2617 @iftex
2618 For full details on Ede, type @kbd{C-h i} and then select the EDE
2619 manual.
2620 @end iftex
2622   EDE is implemented as a global minor mode (@pxref{Minor Modes}).  To
2623 enable it, type @kbd{M-x global-ede-mode} or click on the
2624 @samp{Project Support (EDE)} item in the @samp{Tools} menu.  You can
2625 also enable EDE each time you start Emacs, by adding the following
2626 line to your initialization file:
2628 @smallexample
2629 (global-ede-mode t)
2630 @end smallexample
2632 @noindent
2633 Activating EDE adds a menu named @samp{Development} to the menu bar.
2634 Many EDE commands, including the ones described below, can be invoked
2635 from this menu.
2637   EDE organizes files into @dfn{projects}, which correspond to
2638 directory trees.  The @dfn{project root} is the topmost directory of a
2639 project.  To define a new project, visit a file in the desired project
2640 root and type @kbd{M-x ede-new}.  This command prompts for a
2641 @dfn{project type}, which refers to the underlying method that EDE
2642 will use to manage the project (@pxref{Creating a project, EDE,, ede,
2643 Emacs Development Environment}).  The most common project types are
2644 @samp{Make}, which uses Makefiles, and @samp{Automake}, which uses GNU
2645 Automake (@pxref{Top, Automake,, automake, Automake}).  In both cases,
2646 EDE also creates a file named @file{Project.ede}, which stores
2647 information about the project.
2649   A project may contain one or more @dfn{targets}.  A target can be an
2650 object file, executable program, or some other type of file, which is
2651 built from one or more of the files in the project.
2653   To add a new @dfn{target} to a project, type @kbd{C-c . t}
2654 (@code{M-x ede-new-target}).  This command also asks if you wish to
2655 add the current file to that target, which means that the target
2656 is to be built from that file.  After you have defined a target, you
2657 can add more files to it by typing @kbd{C-c . a}
2658 (@code{ede-add-file}).
2660   To build a target, type @kbd{C-c . c} (@code{ede-compile-target}).
2661 To build all the targets in the project, type @kbd{C-c . C}
2662 (@code{ede-compile-project}).  EDE uses the file types to guess how
2663 the target should be built.
2665 @ifnottex
2666 @include emerge-xtra.texi
2667 @end ifnottex