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