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