Improve documentation of etags
[emacs.git] / doc / emacs / maintaining.texi
blob0846440d1de036e228178c76a7b44a76896cb4cc
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-2018 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 @kindex C-x v h
1054 @findex vc-region-history
1055 A useful variant of examining changes is provided by the command
1056 @kbd{vc-region-history} (by default bound to @kbd{C-x v h}), which shows
1057 a @file{*VC-history*} buffer with the history of changes to the region
1058 of the current file between point and the mark (@pxref{Mark}).  The
1059 history of changes includes the commit log messages and also the
1060 changes themselves in the Diff format.
1062 Invoke this command after marking the region of the current file in
1063 whose changes you are interested.  In the @file{*VC-history*} buffer
1064 it pops up, you can use all of the commands available in the
1065 @file{*vc-change-log*} buffer described above, and also the commands
1066 defined by Diff mode (@pxref{Diff Mode}).
1068 This command is currently available only with Git.
1070 @node VC Undo
1071 @subsection Undoing Version Control Actions
1073 @table @kbd
1074 @item C-x v u
1075 Revert the work file(s) in the current VC fileset to the last revision
1076 (@code{vc-revert}).
1077 @end table
1079 @kindex C-x v u
1080 @findex vc-revert
1081 @vindex vc-revert-show-diff
1082   If you want to discard all the changes you have made to the current
1083 VC fileset, type @kbd{C-x v u} (@code{vc-revert-buffer}).  This shows
1084 you a diff between the work file(s) and the revision from which you
1085 started editing, and asks for confirmation for discarding the changes.
1086 If you agree, the fileset is reverted.  If you don't want @kbd{C-x v
1087 u} to show a diff, set the variable @code{vc-revert-show-diff} to
1088 @code{nil} (you can still view the diff directly with @kbd{C-x v =};
1089 @pxref{Old Revisions}).  Note that @kbd{C-x v u} cannot be reversed
1090 with the usual undo commands (@pxref{Undo}), so use it with care.
1092   On locking-based version control systems, @kbd{C-x v u} leaves files
1093 unlocked; you must lock again to resume editing.  You can also use
1094 @kbd{C-x v u} to unlock a file if you lock it and then decide not to
1095 change it.
1097 @node VC Ignore
1098 @subsection Ignore Version Control Files
1100 @table @kbd
1101 @item C-x v G
1102 Ignore a file under current version control system.  (@code{vc-ignore}).
1103 @end table
1105 @kindex C-x v G
1106 @findex vc-ignore
1107   Many source trees contain some files that do not need to be
1108 versioned, such as editor backups, object or bytecode files, and built
1109 programs.  You can simply not add them, but then they'll always crop
1110 up as unknown files.  You can also tell the version control system to
1111 ignore these files by adding them to the ignore file at the top of the
1112 tree.  @kbd{C-x v G} (@code{vc-ignore}) can help you do this.  When
1113 called with a prefix argument, you can remove a file from the ignored
1114 file list.
1116 @node VC Directory Mode
1117 @subsection VC Directory Mode
1119 @cindex VC Directory buffer
1120   The @dfn{VC Directory buffer} is a specialized buffer for viewing
1121 the version control statuses of the files in a directory tree, and
1122 performing version control operations on those files.  In particular,
1123 it is used to specify multi-file VC filesets for commands like
1124 @w{@kbd{C-x v v}} to act on (@pxref{VC Directory Commands}).
1126 @kindex C-x v d
1127 @findex vc-dir
1128   To use the VC Directory buffer, type @kbd{C-x v d} (@code{vc-dir}).
1129 This reads a directory's name using the minibuffer, and switches to a VC
1130 Directory buffer for that directory.  By default, the buffer is named
1131 @file{*vc-dir*}.  Its contents are described
1132 @iftex
1133 below.
1134 @end iftex
1135 @ifnottex
1136 in @ref{VC Directory Buffer}.
1137 @end ifnottex
1139   The @code{vc-dir} command automatically detects the version control
1140 system to be used in the specified directory.  In the event that more
1141 than one system is being used in the directory, you should invoke the
1142 command with a prefix argument, @kbd{C-u C-x v d}; this prompts for
1143 the version control system which the VC Directory buffer should use.
1145 @ifnottex
1146 @cindex PCL-CVS
1147 @pindex cvs
1148 @cindex CVS directory mode
1149   In addition to the VC Directory buffer, Emacs has a similar facility
1150 called PCL-CVS which is specialized for CVS@.  @xref{Top, , About
1151 PCL-CVS, pcl-cvs, PCL-CVS---The Emacs Front-End to CVS}.
1152 @end ifnottex
1154 @menu
1155 * Buffer: VC Directory Buffer.      What the buffer looks like and means.
1156 * Commands: VC Directory Commands.  Commands to use in a VC directory buffer.
1157 @end menu
1159 @node VC Directory Buffer
1160 @subsubsection The VC Directory Buffer
1162   The VC Directory buffer contains a list of version-controlled files
1163 and their version control statuses.  It lists files in the current
1164 directory (the one specified when you called @kbd{C-x v d}) and its
1165 subdirectories, but only those with a noteworthy status.  Files
1166 that are up-to-date (i.e., the same as in the repository) are
1167 omitted.  If all the files in a subdirectory are up-to-date, the
1168 subdirectory is not listed either.  As an exception, if a file has
1169 become up-to-date as a direct result of a VC command, it is listed.
1171   Here is an example of a VC Directory buffer listing:
1173 @smallexample
1174 @group
1175                      ./
1176     edited           configure.ac
1177 *   added            README
1178     unregistered     temp.txt
1179                      src/
1180 *   edited           src/main.c
1181 @end group
1182 @end smallexample
1184 @noindent
1185 Two work files have been modified but not committed:
1186 @file{configure.ac} in the current directory, and @file{foo.c} in the
1187 @file{src/} subdirectory.  The file named @file{README} has been added
1188 but is not yet committed, while @file{temp.txt} is not under version
1189 control (@pxref{Registering}).
1191 The @samp{*} characters next to the entries for @file{README} and
1192 @file{src/main.c} indicate that the user has marked out these files as
1193 the current VC fileset
1194 @iftex
1195 (see below).
1196 @end iftex
1197 @ifnottex
1198 (@pxref{VC Directory Commands}).
1199 @end ifnottex
1201   The above example is typical for a decentralized version control
1202 system like Bazaar, Git, or Mercurial.  Other systems can show other
1203 statuses.  For instance, CVS shows the @samp{needs-update} status if
1204 the repository has changes that have not been applied to the work
1205 file.  RCS and SCCS show the name of the user locking a file as its
1206 status.
1208 @ifnottex
1209 @vindex vc-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 @vindex xref-prompt-for-identifier
1824   @kbd{M-.}@: (@code{xref-find-definitions}) shows the definitions of
1825 the identifier at point.  With a prefix argument, or if there's no
1826 identifier at point, it prompts for the identifier.  (If you want it
1827 to always prompt, customize @code{xref-prompt-for-identifier} to
1828 @code{t}.)
1830 If the specified identifier has only one definition, the command jumps
1831 to it.  If the identifier has more than one possible definition (e.g.,
1832 in an object-oriented language, or if there's a function and a
1833 variable by the same name), the command shows the candidate
1834 definitions in a @file{*xref*} buffer, together with the files in
1835 which these definitions are found.  Selecting one of these candidates
1836 by typing @kbd{@key{RET}} or clicking @kbd{mouse-2} will pop a buffer
1837 showing the corresponding definition.
1839   When entering the identifier argument to @kbd{M-.}, the usual
1840 minibuffer completion commands can be used (@pxref{Completion}), with
1841 the known identifier names as completion candidates.
1843 @kindex C-x 4 .
1844 @findex xref-find-definitions-other-window
1845 @kindex C-x 5 .
1846 @findex xref-find-definitions-other-frame
1847   Like most commands that can switch buffers,
1848 @code{xref-find-definitions} has a variant that displays the new
1849 buffer in another window, and one that makes a new frame for it.  The
1850 former is @w{@kbd{C-x 4 .}}
1851 (@code{xref-find-definitions-other-window}), and the latter is
1852 @w{@kbd{C-x 5 .}}  (@code{xref-find-definitions-other-frame}).
1854 @findex xref-find-apropos
1855 @kindex C-M-.
1856   The command @kbd{C-M-.} (@code{xref-find-apropos}) finds the
1857 definitions of one or more identifiers that match a specified regular
1858 expression.  It is just like @kbd{M-.} except that it does regexp
1859 matching of identifiers instead of matching symbol names as fixed
1860 strings.
1862   When any of the above commands finds more than one definition, it
1863 presents the @file{*xref*} buffer showing the definition candidates.
1864 In that buffer, you have several specialized commands, described in
1865 @ref{Xref Commands}.
1867 @kindex M-,
1868 @findex xref-pop-marker-stack
1869 @vindex xref-marker-ring-length
1870   To go back to places @emph{from where} you found the definition,
1871 use @kbd{M-,} (@code{xref-pop-marker-stack}).  It jumps back to the
1872 point of the last invocation of @kbd{M-.}.  Thus you can find and
1873 examine the definition of something with @kbd{M-.} and then return to
1874 where you were with @kbd{M-,}.  @kbd{M-,} allows you to retrace your
1875 steps to a depth determined by the variable
1876 @code{xref-marker-ring-length}, which defaults to 16.
1878 @node Xref Commands
1879 @subsubsection Commands Available in the @file{*xref*} Buffer
1880 @cindex commands in @file{*xref*} buffers
1881 @cindex XREF mode
1883   The following commands are provided in the @file{*xref*} buffer by
1884 the special XREF mode:
1886 @table @kbd
1887 @item @key{RET}
1888 @itemx mouse-2
1889 Display the reference on the current line.
1890 @item n
1891 @itemx .
1892 @findex xref-next-line
1893 Move to the next reference and display it in the other window
1894 (@code{xref-next-line}).
1895 @item p
1896 @itemx ,
1897 @findex xref-prev-line
1898 Move to the previous reference and display it in the other window
1899 (@code{xref-prev-line}).
1900 @item C-o
1901 @findex xref-show-location-at-point
1902 Display the reference on the current line in the other window
1903 (@code{xref-show-location-at-point}).
1904 @item TAB
1905 @findex xref-quit-and-goto-xref
1906 Display the reference on the current line and bury the @file{*xref*}
1907 buffer (@code{xref-quit-and-goto-xref}).
1908 @item r @var{pattern} @key{RET} @var{replacement} @key{RET}
1909 Perform interactive query-replace on references that match
1910 @var{pattern} (@code{xref-query-replace-in-results}), replacing
1911 the match with @var{replacement}.  @xref{Identifier Search}.
1912 @findex xref-quit
1913 @item q
1914 Quit the window showing the @file{*xref*} buffer (@code{xref-quit}).
1915 @end table
1917 In addition, the usual navigation commands, such as the arrow keys,
1918 @kbd{C-n}, and @kbd{C-p} are available for moving around the buffer
1919 without displaying the references.
1921 @node Identifier Search
1922 @subsubsection Searching and Replacing with Identifiers
1923 @cindex search and replace in multiple source files
1924 @cindex multiple source file search and replace
1926   The commands in this section perform various search and replace
1927 operations either on identifiers themselves or on files that reference
1928 them.
1930 @table @kbd
1931 @item M-?
1932 Find all the references for the identifier at point.
1933 @item M-x xref-query-replace-in-results @key{RET} @var{regexp} @key{RET} @var{replacement} @key{RET}
1934 Interactively replace @var{regexp} with @var{replacement} in the names
1935 of all the identifiers shown in the @file{*xref*} buffer.
1936 @item M-x tags-search @key{RET} @var{regexp} @key{RET}
1937 Search for @var{regexp} through the files in the selected tags
1938 table.
1939 @item M-x tags-query-replace @key{RET} @var{regexp} @key{RET} @var{replacement} @key{RET}
1940 Perform a @code{query-replace-regexp} on each file in the selected tags table.
1941 @item M-x tags-loop-continue
1942 Restart one of the last 2 commands above, from the current location of point.
1943 @end table
1945 @kindex M-?
1946 @findex xref-find-references
1947   @kbd{M-?} finds all the references for the identifier at point.  If
1948 there's no identifier at point, or when invoked with a prefix
1949 argument, the command prompts for the identifier, with completion.  It
1950 then presents a @file{*xref*} buffer with all the references to the
1951 identifier, showing the file name and the line where the identifier is
1952 referenced.  The XREF mode commands are available in this buffer, see
1953 @ref{Xref Commands}.
1955 @findex xref-query-replace-in-results
1956   @kbd{M-x xref-query-replace-in-results} reads a regexp to match identifier
1957 names and a replacement string, just like ordinary @kbd{M-x
1958 query-replace-regexp}.  It then performs the specified replacement in
1959 the names of the matching identifiers in all the places in all the
1960 files where these identifiers are referenced.  This is useful when you
1961 rename your identifiers as part of refactoring.  This command should
1962 be invoked in the @file{*xref*} buffer generated by @code{M-?}.
1964 @findex tags-search
1965   @kbd{M-x tags-search} reads a regexp using the minibuffer, then
1966 searches for matches in all the files in the selected tags table, one
1967 file at a time.  It displays the name of the file being searched so
1968 you can follow its progress.  As soon as it finds an occurrence,
1969 @code{tags-search} returns.  This command requires tags tables to be
1970 available (@pxref{Tags Tables}).
1972 @findex tags-loop-continue
1973   Having found one match with @code{tags-search}, you probably want to
1974 find all the rest.  Type @kbd{M-x tags-loop-continue} to resume the
1975 @code{tags-search}, finding one more match.  This searches the rest of
1976 the current buffer, followed by the remaining files of the tags table.
1978 @findex tags-query-replace
1979   @kbd{M-x tags-query-replace} performs a single
1980 @code{query-replace-regexp} through all the files in the tags table.  It
1981 reads a regexp to search for and a string to replace with, just like
1982 ordinary @kbd{M-x query-replace-regexp}.  It searches much like @kbd{M-x
1983 tags-search}, but repeatedly, processing matches according to your
1984 input.  @xref{Query Replace}, for more information on query replace.
1986 @vindex tags-case-fold-search
1987 @cindex case-sensitivity and tags search
1988   You can control the case-sensitivity of tags search commands by
1989 customizing the value of the variable @code{tags-case-fold-search}.  The
1990 default is to use the same setting as the value of
1991 @code{case-fold-search} (@pxref{Lax Search}).
1993   It is possible to get through all the files in the tags table with a
1994 single invocation of @kbd{M-x tags-query-replace}.  But often it is
1995 useful to exit temporarily, which you can do with any input event that
1996 has no special query replace meaning.  You can resume the query
1997 replace subsequently by typing @kbd{M-x tags-loop-continue}; this
1998 command resumes the last tags search or replace command that you did.
1999 For instance, to skip the rest of the current file, you can type
2000 @w{@kbd{M-> M-x tags-loop-continue}}.
2002   Note that the commands described above carry out much broader
2003 searches than the @code{xref-find-definitions} family.  The
2004 @code{xref-find-definitions} commands search only for definitions of
2005 identifiers that match your string or regexp.  The commands
2006 @code{xref-find-references}, @code{tags-search}, and
2007 @code{tags-query-replace} find every occurrence of the identifier or
2008 regexp, as ordinary search commands and replace commands do in the
2009 current buffer.
2011   As an alternative to @code{xref-find-references} and
2012 @code{tags-search}, you can run @command{grep} as a subprocess and
2013 have Emacs show you the matching lines one by one.  @xref{Grep
2014 Searching}.
2016 @node List Identifiers
2017 @subsubsection Identifier Inquiries
2019 @table @kbd
2020 @item C-M-i
2021 @itemx M-@key{TAB}
2022 Perform completion on the text around point, possibly using the
2023 selected tags table if one is loaded (@code{completion-at-point}).
2024 @item M-x xref-find-apropos @key{RET} @var{regexp} @key{RET}
2025 Display a list of all known identifiers matching @var{regexp}.
2026 @item M-x list-tags @key{RET} @var{file} @key{RET}
2027 Display a list of the identifiers defined in the program file
2028 @var{file}.
2029 @item M-x next-file
2030 Visit files recorded in the selected tags table.
2031 @end table
2033   In most programming language modes, you can type @kbd{C-M-i} or
2034 @kbd{M-@key{TAB}} (@code{completion-at-point}) to complete the symbol
2035 at point.  Some modes provide specialized completion for this command
2036 tailored to the mode; for those that don't, if there is a tags table
2037 loaded, this command can use it to generate completion candidates.
2038 @xref{Symbol Completion}.
2040 @findex list-tags
2041   @kbd{M-x list-tags} reads the name of one of the files covered by
2042 the selected tags table, and displays a list of tags defined in that
2043 file.  Do not include a directory as part of the file name unless the
2044 file name recorded in the tags table includes a directory.  This
2045 command works only with the etags backend, and requires a tags table
2046 for the project to be available.  @xref{Tags Tables}.
2048 @c Sadly, the new-and-improved Xref feature doesn't provide anything
2049 @c close to the described below features of the now-obsoleted
2050 @c tags-apropos.  I'm leaving this here to encourage enhancements to
2051 @c xref.el.
2052 @ignore
2053 @findex tags-apropos
2054 @vindex tags-apropos-verbose
2055 @vindex tags-tag-face
2056 @vindex tags-apropos-additional-actions
2057   @kbd{M-x tags-apropos} is like @code{apropos} for tags
2058 (@pxref{Apropos}).  It displays a list of tags in the selected tags
2059 table whose entries match @var{regexp}.  If the variable
2060 @code{tags-apropos-verbose} is non-@code{nil}, it displays the names
2061 of the tags files together with the tag names.  You can customize the
2062 appearance of the output by setting the variable @code{tags-tag-face}
2063 to a face.  You can display additional output by customizing the
2064 variable @code{tags-apropos-additional-actions}; see its documentation
2065 for details.
2066 @end ignore
2068 @findex next-file
2069   @kbd{M-x next-file} visits files covered by the selected tags table.
2070 The first time it is called, it visits the first file covered by the
2071 table.  Each subsequent call visits the next covered file, unless a
2072 prefix argument is supplied, in which case it returns to the first
2073 file.  This command requires a tags table to be selected.
2075 @node Tags Tables
2076 @subsection Tags Tables
2077 @cindex tags and tag tables
2079   A @dfn{tags table} records the tags@footnote{
2080 A @dfn{tag} is a synonym for identifier reference.  Commands and
2081 features based on the @code{etags} package traditionally use ``tag''
2082 with this meaning, and this subsection follows that tradition.
2083 } extracted by scanning the source code of a certain program or a
2084 certain document.  Tags extracted from generated files reference the
2085 original files, rather than the generated files that were scanned
2086 during tag extraction.  Examples of generated files include C files
2087 generated from Cweb source files, from a Yacc parser, or from Lex
2088 scanner definitions; @file{.i} preprocessed C files; and Fortran files
2089 produced by preprocessing @file{.fpp} source files.
2091 @cindex etags
2092   To produce a tags table, you run the @command{etags} shell command
2093 on a document or the source code file.  The @samp{etags} program
2094 writes the tags to a @dfn{tags table file}, or @dfn{tags file} in
2095 short.  The conventional name for a tags file is @file{TAGS}@.
2096 @xref{Create Tags Table}.  (It is also possible to create a tags table
2097 by using one of the commands from other packages that can produce such
2098 tables in the same format.)
2100   Emacs uses the tags tables via the @code{etags} package as one of
2101 the supported backends for @code{xref}.  Because tags tables are
2102 produced by the @command{etags} command that is part of an Emacs
2103 distribution, we describe tags tables in more detail here.
2105 @cindex C++ class browser, tags
2106 @cindex tags, C++
2107 @cindex class browser, C++
2108 @cindex Ebrowse
2109   The Ebrowse facility is similar to @command{etags} but specifically
2110 tailored for C++.  @xref{Top,, Ebrowse, ebrowse, Ebrowse User's
2111 Manual}.  The Semantic package provides another way to generate and
2112 use tags, separate from the @command{etags} facility.
2113 @xref{Semantic}.
2115 @menu
2116 * Tag Syntax::          Tag syntax for various types of code and text files.
2117 * Create Tags Table::   Creating a tags table with @command{etags}.
2118 * Etags Regexps::       Create arbitrary tags using regular expressions.
2119 @end menu
2121 @node Tag Syntax
2122 @subsubsection Source File Tag Syntax
2124   Here is how tag syntax is defined for the most popular languages:
2126 @itemize @bullet
2127 @item
2128 In C code, any C function or typedef is a tag, and so are definitions of
2129 @code{struct}, @code{union} and @code{enum}.
2130 @code{#define} macro definitions, @code{#undef} and @code{enum}
2131 constants are also
2132 tags, unless you specify @samp{--no-defines} when making the tags table.
2133 Similarly, global variables are tags, unless you specify
2134 @samp{--no-globals}, and so are struct members, unless you specify
2135 @samp{--no-members}.  Use of @samp{--no-globals}, @samp{--no-defines}
2136 and @samp{--no-members} can make the tags table file much smaller.
2138 You can tag function declarations and external variables in addition
2139 to function definitions by giving the @samp{--declarations} option to
2140 @command{etags}.
2142 @item
2143 In C++ code, in addition to all the tag constructs of C code, member
2144 functions are also recognized; member variables are also recognized,
2145 unless you use the @samp{--no-members} option.  @code{operator}
2146 definitions have tag names like @samp{operator+}.  If you specify the
2147 @samp{--class-qualify} option, tags for variables and functions in
2148 classes are named @samp{@var{class}::@var{variable}} and
2149 @samp{@var{class}::@var{function}}.  By default, class methods and
2150 members are not class-qualified, which allows to identify their names in
2151 the sources more accurately.
2153 @item
2154 In Java code, tags include all the constructs recognized in C++, plus
2155 the @code{interface}, @code{extends} and @code{implements} constructs.
2156 Tags for variables and functions in classes are named
2157 @samp{@var{class}.@var{variable}} and @samp{@var{class}.@var{function}}.
2159 @item
2160 In @LaTeX{} documents, the arguments for @code{\chapter},
2161 @code{\section}, @code{\subsection}, @code{\subsubsection},
2162 @code{\eqno}, @code{\label}, @code{\ref}, @code{\cite},
2163 @code{\bibitem}, @code{\part}, @code{\appendix}, @code{\entry},
2164 @code{\index}, @code{\def}, @code{\newcommand}, @code{\renewcommand},
2165 @code{\newenvironment} and @code{\renewenvironment} are tags.
2167 Other commands can make tags as well, if you specify them in the
2168 environment variable @env{TEXTAGS} before invoking @command{etags}.  The
2169 value of this environment variable should be a colon-separated list of
2170 command names.  For example,
2172 @example
2173 TEXTAGS="mycommand:myothercommand"
2174 export TEXTAGS
2175 @end example
2177 @noindent
2178 specifies (using Bourne shell syntax) that the commands
2179 @samp{\mycommand} and @samp{\myothercommand} also define tags.
2181 @item
2182 In Lisp code, any function defined with @code{defun}, any variable
2183 defined with @code{defvar} or @code{defconst}, and in general the
2184 first argument of any expression that starts with @samp{(def} in
2185 column zero is a tag.  As an exception, expressions of the form
2186 @code{(defvar @var{foo})} are treated as declarations, and are only
2187 tagged if the @samp{--declarations} option is given.
2189 @item
2190 In Scheme code, tags include anything defined with @code{def} or with a
2191 construct whose name starts with @samp{def}.  They also include variables
2192 set with @code{set!} at top level in the file.
2193 @end itemize
2195   Several other languages are also supported:
2197 @itemize @bullet
2199 @item
2200 In Ada code, functions, procedures, packages, tasks and types are
2201 tags.  Use the @samp{--packages-only} option to create tags for
2202 packages only.
2204 In Ada, the same name can be used for different kinds of entity
2205 (e.g., for a procedure and for a function).  Also, for things like
2206 packages, procedures and functions, there is the spec (i.e., the
2207 interface) and the body (i.e., the implementation).  To make it
2208 easier to pick the definition you want, Ada tag name have suffixes
2209 indicating the type of entity:
2211 @table @samp
2212 @item /b
2213 package body.
2214 @item /f
2215 function.
2216 @item /k
2217 task.
2218 @item /p
2219 procedure.
2220 @item /s
2221 package spec.
2222 @item /t
2223 type.
2224 @end table
2226   Thus, @kbd{M-x find-tag @key{RET} bidule/b @key{RET}} will go
2227 directly to the body of the package @code{bidule}, while @kbd{M-x
2228 find-tag @key{RET} bidule @key{RET}} will just search for any tag
2229 @code{bidule}.
2231 @item
2232 In assembler code, labels appearing at the start of a line,
2233 followed by a colon, are tags.
2235 @item
2236 In Bison or Yacc input files, each rule defines as a tag the nonterminal
2237 it constructs.  The portions of the file that contain C code are parsed
2238 as C code.
2240 @item
2241 In Cobol code, tags are paragraph names; that is, any word starting in
2242 column 8 and followed by a period.
2244 @item
2245 In Erlang code, the tags are the functions, records and macros defined
2246 in the file.
2248 @item
2249 In Fortran code, functions, subroutines and block data are tags.
2251 @item
2252 In Go code, packages, functions, and types are tags.
2254 @item
2255 In HTML input files, the tags are the @code{title} and the @code{h1},
2256 @code{h2}, @code{h3} headers.  Also, tags are @code{name=} in anchors
2257 and all occurrences of @code{id=}.
2259 @item
2260 In Lua input files, all functions are tags.
2262 @item
2263 In makefiles, targets are tags; additionally, variables are tags
2264 unless you specify @samp{--no-globals}.
2266 @item
2267 In Objective C code, tags include Objective C definitions for classes,
2268 class categories, methods and protocols.  Tags for variables and
2269 functions in classes are named @samp{@var{class}::@var{variable}} and
2270 @samp{@var{class}::@var{function}}.
2272 @item
2273 In Pascal code, the tags are the functions and procedures defined in
2274 the file.
2276 @item
2277 In Perl code, the tags are the packages, subroutines and variables
2278 defined by the @code{package}, @code{sub}, @code{use constant},
2279 @code{my}, and @code{local} keywords.  Use @samp{--globals} if you
2280 want to tag global variables.  Tags for subroutines are named
2281 @samp{@var{package}::@var{sub}}.  The name for subroutines defined in
2282 the default package is @samp{main::@var{sub}}.
2284 @item
2285 In PHP code, tags are functions, classes and defines.  Vars are tags
2286 too, unless you use the @samp{--no-members} option.
2288 @item
2289 In PostScript code, the tags are the functions.
2291 @item
2292 In Prolog code, tags are predicates and rules at the beginning of
2293 line.
2295 @item
2296 In Python code, @code{def} or @code{class} at the beginning of a line
2297 generate a tag.
2299 @item
2300 In Ruby code, @code{def} or @code{class} or @code{module} at the
2301 beginning of a line generate a tag.  Constants also generate tags.
2302 @end itemize
2304   You can also generate tags based on regexp matching (@pxref{Etags
2305 Regexps}) to handle other formats and languages.
2307 @node Create Tags Table
2308 @subsubsection Creating Tags Tables
2309 @cindex @command{etags} program
2311   The @command{etags} program is used to create a tags table file.  It knows
2312 the syntax of several languages, as described in
2313 @iftex
2314 the previous section.
2315 @end iftex
2316 @ifnottex
2317 @ref{Tag Syntax}.
2318 @end ifnottex
2319 Here is how to run @command{etags}:
2321 @example
2322 etags @var{inputfiles}@dots{}
2323 @end example
2325 @noindent
2326 The @command{etags} program reads the specified files, and writes a tags
2327 table named @file{TAGS} in the current working directory.  You can
2328 optionally specify a different file name for the tags table by using the
2329 @samp{--output=@var{file}} option; specifying @file{-} as a file name
2330 prints the tags table to standard output.  You can also append the
2331 newly created tags table to an existing file by using the @samp{--append}
2332 option.
2334   If the specified files don't exist, @command{etags} looks for
2335 compressed versions of them and uncompresses them to read them.  Under
2336 MS-DOS, @command{etags} also looks for file names like @file{mycode.cgz}
2337 if it is given @samp{mycode.c} on the command line and @file{mycode.c}
2338 does not exist.
2340   If the tags table becomes outdated due to changes in the files
2341 described in it, you can update it by running the @command{etags}
2342 program again.  If the tags table does not record a tag, or records it
2343 for the wrong file, then Emacs will not be able to find that
2344 definition until you update the tags table.  But if the position
2345 recorded in the tags table becomes a little bit wrong (due to other
2346 editing), Emacs will still be able to find the right position, with a
2347 slight delay.
2349    Thus, there is no need to update the tags table after each edit.
2350 You should update a tags table when you define new tags that you want
2351 to have listed, or when you move tag definitions from one file to
2352 another, or when changes become substantial.
2354   You can make a tags table @dfn{include} another tags table, by
2355 passing the @samp{--include=@var{file}} option to @command{etags}.  It
2356 then covers all the files covered by the included tags file, as well
2357 as its own.
2359   If you specify the source files with relative file names when you run
2360 @command{etags}, the tags file will contain file names relative to the
2361 directory where the tags file was initially written.  This way, you can
2362 move an entire directory tree containing both the tags file and the
2363 source files, and the tags file will still refer correctly to the source
2364 files.  If the tags file is @file{-} or is in the @file{/dev} directory,
2365 however, the file names are
2366 made relative to the current working directory.  This is useful, for
2367 example, when writing the tags to the standard output.
2369   When using a relative file name, it should not be a symbolic link
2370 pointing to a tags file in a different directory, because this would
2371 generally render the file names invalid.
2373   If you specify absolute file names as arguments to @command{etags}, then
2374 the tags file will contain absolute file names.  This way, the tags file
2375 will still refer to the same files even if you move it, as long as the
2376 source files remain in the same place.  Absolute file names start with
2377 @samp{/}, or with @samp{@var{device}:/} on MS-DOS and MS-Windows.
2379    When you want to make a tags table from a great number of files,
2380 you may have problems listing them on the command line, because some
2381 systems have a limit on its length.  You can circumvent this limit by
2382 telling @command{etags} to read the file names from its standard
2383 input, by typing a dash in place of the file names, like this:
2385 @smallexample
2386 find . -name "*.[chCH]" -print | etags -
2387 @end smallexample
2389   @command{etags} recognizes the language used in an input file based on
2390 its file name and contents.  It first tries to match the file's name and
2391 extension to the ones commonly used with certain languages.  Some
2392 languages have interpreters with known names (e.g., @command{perl} for
2393 Perl or @command{pl} for Prolog), so @command{etags} next looks for an
2394 interpreter specification of the form @samp{#!@var{interp}} on the first
2395 line of an input file, and matches that against known interpreters.  If
2396 none of that works, or if you want to override the automatic detection of
2397 the language, you can specify the language explicitly with the
2398 @samp{--language=@var{name}} option.  You can intermix these options with
2399 file names; each one applies to the file names that follow it.  Specify
2400 @samp{--language=auto} to tell @command{etags} to resume guessing the
2401 language from the file names and file contents.  Specify
2402 @samp{--language=none} to turn off language-specific processing entirely;
2403 then @command{etags} recognizes tags by regexp matching alone
2404 (@pxref{Etags Regexps}).  This comes in handy when an input file uses a
2405 language not yet supported by @command{etags}, and you want to avoid
2406 having @command{etags} fall back on Fortran and C as the default
2407 languages.
2409   The option @samp{--parse-stdin=@var{file}} is mostly useful when
2410 calling @command{etags} from programs.  It can be used (only once) in
2411 place of a file name on the command line.  @command{etags} will read from
2412 standard input and mark the produced tags as belonging to the file
2413 @var{file}.
2415   @samp{etags --help} outputs the list of the languages @command{etags}
2416 knows, and the file name rules for guessing the language.  It also prints
2417 a list of all the available @command{etags} options, together with a short
2418 explanation.  If followed by one or more @samp{--language=@var{lang}}
2419 options, it outputs detailed information about how tags are generated for
2420 @var{lang}.
2422 @node Etags Regexps
2423 @subsubsection Etags Regexps
2425   The @samp{--regex} option to @command{etags} allows tags to be
2426 recognized by regular expression matching.  You can intermix this
2427 option with file names; each one applies to the source files that
2428 follow it.  If you specify multiple @samp{--regex} options, all of
2429 them are used in parallel.  The syntax is:
2431 @smallexample
2432 --regex=[@var{@{language@}}]/@var{tagregexp}/[@var{nameregexp}/]@var{modifiers}
2433 @end smallexample
2435 @noindent
2436 The essential part of the option value is @var{tagregexp}, the regexp
2437 for matching tags.  It is always used anchored, that is, it only
2438 matches at the beginning of a line.  If you want to allow indented
2439 tags, use a regexp that matches initial whitespace; start it with
2440 @samp{[ \t]*}.
2442   In these regular expressions, @samp{\} quotes the next character, and
2443 all the GCC character escape sequences are supported (@samp{\a} for
2444 bell, @samp{\b} for back space, @samp{\d} for delete, @samp{\e} for
2445 escape, @samp{\f} for formfeed, @samp{\n} for newline, @samp{\r} for
2446 carriage return, @samp{\t} for tab, and @samp{\v} for vertical tab).
2448   Ideally, @var{tagregexp} should not match more characters than are
2449 needed to recognize what you want to tag.  If the syntax requires you
2450 to write @var{tagregexp} so it matches more characters beyond the tag
2451 itself, you should add a @var{nameregexp}, to pick out just the tag.
2452 This will enable Emacs to find tags more accurately and to do
2453 completion on tag names more reliably.  In @var{nameregexp}, it is
2454 frequently convenient to use ``back references'' (@pxref{Regexp
2455 Backslash}) to parenthesized groupings @w{@samp{\( @dots{} \)}} in
2456 @var{tagregexp}.  For example, @samp{\1} refers to the first such
2457 parenthesized grouping.  You can find some examples of this below.
2459   The @var{modifiers} are a sequence of zero or more characters that
2460 modify the way @command{etags} does the matching.  A regexp with no
2461 modifiers is applied sequentially to each line of the input file, in a
2462 case-sensitive way.  The modifiers and their meanings are:
2464 @table @samp
2465 @item i
2466 Ignore case when matching this regexp.
2467 @item m
2468 Match this regular expression against the whole file, so that
2469 multi-line matches are possible.
2470 @item s
2471 Match this regular expression against the whole file, and allow
2472 @samp{.} in @var{tagregexp} to match newlines.
2473 @end table
2475   The @samp{-R} option cancels all the regexps defined by preceding
2476 @samp{--regex} options.  It too applies to the file names following
2477 it.  Here's an example:
2479 @smallexample
2480 etags --regex=/@var{reg1}/i voo.doo --regex=/@var{reg2}/m \
2481     bar.ber -R --lang=lisp los.er
2482 @end smallexample
2484 @noindent
2485 Here @command{etags} chooses the parsing language for @file{voo.doo} and
2486 @file{bar.ber} according to their contents.  @command{etags} also uses
2487 @var{reg1} to recognize additional tags in @file{voo.doo}, and both
2488 @var{reg1} and @var{reg2} to recognize additional tags in
2489 @file{bar.ber}.  @var{reg1} is checked against each line of
2490 @file{voo.doo} and @file{bar.ber}, in a case-insensitive way, while
2491 @var{reg2} is checked against the whole @file{bar.ber} file,
2492 permitting multi-line matches, in a case-sensitive way.  @command{etags}
2493 uses only the Lisp tags rules, with no user-specified regexp matching,
2494 to recognize tags in @file{los.er}.
2496   You can restrict a @samp{--regex} option to match only files of a
2497 given language by using the optional prefix @var{@{language@}}.
2498 (@samp{etags --help} prints the list of languages recognized by
2499 @command{etags}.)  This is particularly useful when storing many
2500 predefined regular expressions for @command{etags} in a file.  The
2501 following example tags the @code{DEFVAR} macros in the Emacs source
2502 files, for the C language only:
2504 @smallexample
2505 --regex='@{c@}/[ \t]*DEFVAR_[A-Z_ \t(]+"\([^"]+\)"/\1/'
2506 @end smallexample
2508 @noindent
2509 When you have complex regular expressions, you can store the list of
2510 them in a file.  The following option syntax instructs @command{etags} to
2511 read two files of regular expressions.  The regular expressions
2512 contained in the second file are matched without regard to case.
2514 @smallexample
2515 --regex=@@@var{case-sensitive-file} --ignore-case-regex=@@@var{ignore-case-file}
2516 @end smallexample
2518 @noindent
2519 A regex file for @command{etags} contains one regular expression per
2520 line.  Empty lines, and lines beginning with space or tab are ignored.
2521 When the first character in a line is @samp{@@}, @command{etags} assumes
2522 that the rest of the line is the name of another file of regular
2523 expressions; thus, one such file can include another file.  All the
2524 other lines are taken to be regular expressions.  If the first
2525 non-whitespace text on the line is @samp{--}, that line is a comment.
2527   For example, we can create a file called @samp{emacs.tags} with the
2528 following contents:
2530 @smallexample
2531         -- This is for GNU Emacs C source files
2532 @{c@}/[ \t]*DEFVAR_[A-Z_ \t(]+"\([^"]+\)"/\1/
2533 @end smallexample
2535 @noindent
2536 and then use it like this:
2538 @smallexample
2539 etags --regex=@@emacs.tags *.[ch] */*.[ch]
2540 @end smallexample
2542   Here are some more examples.  The regexps are quoted to protect them
2543 from shell interpretation.
2545 @itemize @bullet
2547 @item
2548 Tag Octave files:
2550 @smallexample
2551 etags --language=none \
2552       --regex='/[ \t]*function.*=[ \t]*\([^ \t]*\)[ \t]*(/\1/' \
2553       --regex='/###key \(.*\)/\1/' \
2554       --regex='/[ \t]*global[ \t].*/' \
2555       *.m
2556 @end smallexample
2558 @noindent
2559 Note that tags are not generated for scripts, so that you have to add
2560 a line by yourself of the form @samp{###key @var{scriptname}} if you
2561 want to jump to it.
2563 @item
2564 Tag Tcl files:
2566 @smallexample
2567 etags --language=none --regex='/proc[ \t]+\([^ \t]+\)/\1/' *.tcl
2568 @end smallexample
2570 @item
2571 Tag VHDL files:
2573 @smallexample
2574 etags --language=none \
2575   --regex='/[ \t]*\(ARCHITECTURE\|CONFIGURATION\) +[^ ]* +OF/' \
2576   --regex='/[ \t]*\(ATTRIBUTE\|ENTITY\|FUNCTION\|PACKAGE\
2577   \( BODY\)?\|PROCEDURE\|PROCESS\|TYPE\)[ \t]+\([^ \t(]+\)/\3/'
2578 @end smallexample
2579 @end itemize
2581 @node Select Tags Table
2582 @subsection Selecting a Tags Table
2584 @findex visit-tags-table
2585   Emacs has at any time at most one @dfn{selected} tags table.  All the
2586 commands for working with tags tables use the selected one.  To select
2587 a tags table, type @kbd{M-x visit-tags-table}, which reads the tags
2588 table file name as an argument, with @file{TAGS} in the default
2589 directory as the default.
2591 @vindex tags-file-name
2592   Emacs does not actually read in the tags table contents until you
2593 try to use them; all @code{visit-tags-table} does is store the file
2594 name in the variable @code{tags-file-name}, and not much more.  The
2595 variable's initial value is @code{nil}; that value tells all the
2596 commands for working with tags tables that they must ask for a tags
2597 table file name to use.
2599   Using @code{visit-tags-table} when a tags table is already loaded
2600 gives you a choice: you can add the new tags table to the current list
2601 of tags tables, or start a new list.  The tags commands use all the tags
2602 tables in the current list.  If you start a new list, the new tags table
2603 is used @emph{instead} of others.  If you add the new table to the
2604 current list, it is used @emph{as well as} the others.
2606 @vindex tags-table-list
2607   You can specify a precise list of tags tables by setting the variable
2608 @code{tags-table-list} to a list of strings, like this:
2610 @c keep this on two lines for formatting in smallbook
2611 @example
2612 @group
2613 (setq tags-table-list
2614       '("~/emacs" "/usr/local/lib/emacs/src"))
2615 @end group
2616 @end example
2618 @noindent
2619 This tells the tags commands to look at the @file{TAGS} files in your
2620 @file{~/emacs} directory and in the @file{/usr/local/lib/emacs/src}
2621 directory.  The order depends on which file you are in and which tags
2622 table mentions that file.
2624   Do not set both @code{tags-file-name} and @code{tags-table-list}.
2626 @node EDE
2627 @section Emacs Development Environment
2628 @cindex EDE (Emacs Development Environment)
2629 @cindex Emacs Development Environment
2630 @cindex Integrated development environment
2632 EDE (@dfn{Emacs Development Environment}) is a package that simplifies
2633 the task of creating, building, and debugging large programs with
2634 Emacs.  It provides some of the features of an IDE, or @dfn{Integrated
2635 Development Environment}, in Emacs.
2637 This section provides a brief description of EDE usage.
2638 @ifnottex
2639 For full details, see @ref{Top, EDE,, ede, Emacs Development Environment}.
2640 @end ifnottex
2641 @iftex
2642 For full details on Ede, type @kbd{C-h i} and then select the EDE
2643 manual.
2644 @end iftex
2646   EDE is implemented as a global minor mode (@pxref{Minor Modes}).  To
2647 enable it, type @kbd{M-x global-ede-mode} or click on the
2648 @samp{Project Support (EDE)} item in the @samp{Tools} menu.  You can
2649 also enable EDE each time you start Emacs, by adding the following
2650 line to your initialization file:
2652 @smallexample
2653 (global-ede-mode t)
2654 @end smallexample
2656 @noindent
2657 Activating EDE adds a menu named @samp{Development} to the menu bar.
2658 Many EDE commands, including the ones described below, can be invoked
2659 from this menu.
2661   EDE organizes files into @dfn{projects}, which correspond to
2662 directory trees.  The @dfn{project root} is the topmost directory of a
2663 project.  To define a new project, visit a file in the desired project
2664 root and type @kbd{M-x ede-new}.  This command prompts for a
2665 @dfn{project type}, which refers to the underlying method that EDE
2666 will use to manage the project (@pxref{Creating a project, EDE,, ede,
2667 Emacs Development Environment}).  The most common project types are
2668 @samp{Make}, which uses Makefiles, and @samp{Automake}, which uses GNU
2669 Automake (@pxref{Top, Automake,, automake, Automake}).  In both cases,
2670 EDE also creates a file named @file{Project.ede}, which stores
2671 information about the project.
2673   A project may contain one or more @dfn{targets}.  A target can be an
2674 object file, executable program, or some other type of file, which is
2675 built from one or more of the files in the project.
2677   To add a new @dfn{target} to a project, type @kbd{C-c . t}
2678 (@code{M-x ede-new-target}).  This command also asks if you wish to
2679 add the current file to that target, which means that the target
2680 is to be built from that file.  After you have defined a target, you
2681 can add more files to it by typing @kbd{C-c . a}
2682 (@code{ede-add-file}).
2684   To build a target, type @kbd{C-c . c} (@code{ede-compile-target}).
2685 To build all the targets in the project, type @kbd{C-c . C}
2686 (@code{ede-compile-project}).  EDE uses the file types to guess how
2687 the target should be built.
2689 @ifnottex
2690 @include emerge-xtra.texi
2691 @end ifnottex