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