]> code.delx.au - gnu-emacs/blob - doc/emacs/maintaining.texi
Handle Bug#23186
[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 @vindex add-log-keep-changes-together
1594 When the variable @code{add-log-keep-changes-together} is
1595 non-@code{nil}, @kbd{C-x 4 a} adds to any existing item for the file
1596 rather than starting a new item.
1597
1598 You can combine multiple changes of the same nature. If you don't
1599 enter any text after the initial @kbd{C-x 4 a}, any subsequent
1600 @kbd{C-x 4 a} adds another symbol to the change log entry.
1601
1602 @vindex add-log-always-start-new-record
1603 If @code{add-log-always-start-new-record} is non-@code{nil},
1604 @kbd{C-x 4 a} always makes a new entry, even if the last entry
1605 was made by you and on the same date.
1606
1607 @vindex change-log-version-info-enabled
1608 @vindex change-log-version-number-regexp-list
1609 @cindex file version in change log entries
1610 If the value of the variable @code{change-log-version-info-enabled}
1611 is non-@code{nil}, @kbd{C-x 4 a} adds the file's version number to the
1612 change log entry. It finds the version number by searching the first
1613 ten percent of the file, using regular expressions from the variable
1614 @code{change-log-version-number-regexp-list}.
1615
1616 @cindex Change Log mode
1617 @findex change-log-mode
1618 The change log file is visited in Change Log mode. In this major
1619 mode, each bunch of grouped items counts as one paragraph, and each
1620 entry is considered a page. This facilitates editing the entries.
1621 @kbd{C-j} and auto-fill indent each new line like the previous line;
1622 this is convenient for entering the contents of an entry.
1623
1624 You can use the @code{next-error} command (by default bound to
1625 @kbd{C-x `}) to move between entries in the Change Log, when Change
1626 Log mode is on. You will jump to the actual site in the file that was
1627 changed, not just to the next Change Log entry. You can also use
1628 @code{previous-error} to move back in the same list.
1629
1630 @findex change-log-merge
1631 You can use the command @kbd{M-x change-log-merge} to merge other
1632 log files into a buffer in Change Log Mode, preserving the date
1633 ordering of entries.
1634
1635 Version control systems are another way to keep track of changes in
1636 your program and keep a change log. In the VC log buffer, typing
1637 @kbd{C-c C-a} (@code{log-edit-insert-changelog}) inserts the relevant
1638 Change Log entry, if one exists. @xref{Log Buffer}.
1639
1640 @node Format of ChangeLog
1641 @subsection Format of ChangeLog
1642
1643 A change log entry starts with a header line that contains the
1644 current date, your name (taken from the variable
1645 @code{add-log-full-name}), and your email address (taken from the
1646 variable @code{add-log-mailing-address}). Aside from these header
1647 lines, every line in the change log starts with a space or a tab. The
1648 bulk of the entry consists of @dfn{items}, each of which starts with a
1649 line starting with whitespace and a star. Here are two entries, both
1650 dated in May 1993, with two items and one item respectively.
1651
1652 @iftex
1653 @medbreak
1654 @end iftex
1655 @smallexample
1656 1993-05-25 Richard Stallman <rms@@gnu.org>
1657
1658 * man.el: Rename symbols 'man-*' to 'Man-*'.
1659 (manual-entry): Make prompt string clearer.
1660
1661 * simple.el (blink-matching-paren-distance):
1662 Change default to 12,000.
1663
1664 1993-05-24 Richard Stallman <rms@@gnu.org>
1665
1666 * vc.el (minor-mode-map-alist): Don't use it if it's void.
1667 (vc-cancel-version): Doc fix.
1668 @end smallexample
1669
1670 One entry can describe several changes; each change should have its
1671 own item, or its own line in an item. Normally there should be a
1672 blank line between items. When items are related (parts of the same
1673 change, in different places), group them by leaving no blank line
1674 between them.
1675
1676 You should put a copyright notice and permission notice at the
1677 end of the change log file. Here is an example:
1678
1679 @smallexample
1680 Copyright 1997, 1998 Free Software Foundation, Inc.
1681 Copying and distribution of this file, with or without modification, are
1682 permitted provided the copyright notice and this notice are preserved.
1683 @end smallexample
1684
1685 @noindent
1686 Of course, you should substitute the proper years and copyright holder.
1687
1688 @node Xref
1689 @section Find Identifier References
1690 @cindex xref
1691
1692 An @dfn{identifier} is a name of a syntactical subunit of the
1693 program: a function, a subroutine, a method, a class, a data type, a
1694 macro, etc. In a programming language, each identifier is a symbol in
1695 the language's syntax. Program development and maintenance requires
1696 capabilities to quickly find where each identifier was defined and
1697 referenced, to rename identifiers across the entire project, etc.
1698
1699 These capabilities are also useful for finding references in major
1700 modes other than those defined to support programming languages. For
1701 example, chapters, sections, appendices, etc.@: of a text or a @TeX{}
1702 document can be treated as subunits as well, and their names can be
1703 used as identifiers. In this chapter, we use the term ``identifiers''
1704 to collectively refer to the names of any kind of subunits, in program
1705 source and in other kinds of text alike.
1706
1707 Emacs provides a unified interface to these capabilities, called
1708 @samp{xref}.
1709
1710 @cindex xref backend
1711 To do its job, @code{xref} needs to make use of information and to
1712 employ methods specific to the major mode. What files to search for
1713 identifiers, how to find references to identifiers, how to complete on
1714 identifiers---all this and more is mode-specific knowledge.
1715 @code{xref} delegates the mode-specific parts of its job to a
1716 @dfn{backend} provided by the mode; it also includes defaults for some
1717 of its commands, for those modes that don't provide their own.
1718
1719 A backend can implement its capabilities in a variety of ways. Here
1720 are a few examples:
1721
1722 @enumerate a
1723 @item
1724 Some major modes provide built-in means for looking up the language
1725 symbols. For example, Emacs Lisp symbols can be identified by
1726 searching the package load history, maintained by the Emacs Lisp
1727 interpreter, and by consulting the built-in documentation strings; the
1728 Emacs Lisp mode uses these facilities in its backend to allow finding
1729 definitions of symbols. (One disadvantage of this kind of backend is
1730 that it only knows about subunits that were loaded into the
1731 interpreter.)
1732
1733 @item
1734 An external program can extract references by scanning the relevant
1735 files, and build a database of these references. A backend can then
1736 access this database whenever it needs to list or look up references.
1737 The Emacs distribution includes @command{etags}, a command for tagging
1738 identifier definitions in programs, which supports many programming
1739 languages and other major modes, such as HTML, by extracting
1740 references into @dfn{tags tables}. @xref{Create Tags Table}. Major
1741 modes for languages supported by @command{etags} can use tags tables
1742 as basis for their backend. (One disadvantage of this kind of backend
1743 is that tags tables need to be kept reasonably up to date, by
1744 rebuilding them from time to time.)
1745 @end enumerate
1746
1747 @menu
1748 * Find Identifiers:: Commands to find where an identifier is defined
1749 or referenced, to list identifiers, etc.
1750 * Tags Tables:: Tags table records which file defines a symbol.
1751 * Select Tags Table:: How to visit a specific tags table.
1752 @end menu
1753
1754 @node Find Identifiers
1755 @subsection Find Identifiers
1756
1757 This subsection describes the commands that find references to
1758 identifiers and perform various queries about identifiers. Each such
1759 reference could @emph{define} an identifier, e.g., provide the
1760 implementation of a program subunit or the text of a document section;
1761 or it could @emph{use} the identifier, e.g., call a function or a
1762 method, assign a value to a variable, mention a chapter in a
1763 cross-reference, etc.
1764
1765 @menu
1766 * Looking Up Identifiers:: Commands to find the definition of an identifier.
1767 * Xref Commands:: Commands in the @file{*xref*} buffer.
1768 * Identifier Search:: Searching and replacing identifiers.
1769 * List Identifiers:: Listing identifiers and completing on them.
1770 @end menu
1771
1772 @node Looking Up Identifiers
1773 @subsubsection Looking Up Identifiers
1774 @cindex find definition of symbols
1775 @cindex identifier, finding definition of
1776 @cindex find references to symbols
1777
1778 The most important thing that @code{xref} enables you to do is to find
1779 the definition of a specific identifier.
1780
1781 @table @kbd
1782 @item M-.@:
1783 Find definitions of an identifier (@code{xref-find-definitions}).
1784 @item C-M-. @var{pattern} @key{RET}
1785 Find all identifiers whose name matches @var{pattern}
1786 (@code{xref-find-apropos}).
1787 @item C-x 4 .@: @key{RET}
1788 Find definitions of identifier, but display it in another window
1789 (@code{xref-find-definitions-other-window}).
1790 @item C-x 5 .@: @key{RET}
1791 Find definition of identifier, and display it in a new frame
1792 (@code{xref-find-definitions-other-frame}).
1793 @item M-,
1794 Go back to where you previously invoked @kbd{M-.} and friends
1795 (@code{xref-pop-marker-stack}).
1796 @end table
1797
1798 @kindex M-.
1799 @findex xref-find-definitions
1800 @kbd{M-.}@: (@code{xref-find-definitions}) shows the definitions of
1801 the identifier at point. With a prefix argument, or if there's no
1802 identifier at point, it prompts for the identifier. If the
1803 identifier has only one definition, the command jumps to it. If the
1804 identifier has more than one possible definition (e.g., in an
1805 object-oriented language, or if there's a function and a variable by
1806 the same name), the command shows the candidate definitions in a
1807 @file{*xref*} buffer, together with the files in which these
1808 definitions are found. Selecting one of these candidates by typing
1809 @kbd{@key{RET}} or clicking @kbd{Mouse-2} will pop a buffer showing
1810 the corresponding definition.
1811
1812 When entering the identifier argument to @kbd{M-.}, the usual
1813 minibuffer completion commands can be used (@pxref{Completion}), with
1814 the known identifier names as completion candidates.
1815
1816 @kindex C-x 4 .
1817 @findex xref-find-definitions-other-window
1818 @kindex C-x 5 .
1819 @findex xref-find-definitions-other-frame
1820 Like most commands that can switch buffers,
1821 @code{xref-find-definitions} has a variant that displays the new
1822 buffer in another window, and one that makes a new frame for it. The
1823 former is @w{@kbd{C-x 4 .}}
1824 (@code{xref-find-definitions-other-window}), and the latter is
1825 @w{@kbd{C-x 5 .}} (@code{xref-find-definitions-other-frame}).
1826
1827 @findex xref-find-apropos
1828 @kindex C-M-.
1829 The command @kbd{C-M-.} (@code{xref-find-apropos}) finds the
1830 definitions of one or more identifiers that match a specified regular
1831 expression. It is just like @kbd{M-.} except that it does regexp
1832 matching of identifiers instead of matching symbol names as fixed
1833 strings.
1834
1835 When any of the above commands finds more than one definition, it
1836 presents the @file{*xref*} buffer showing the definition candidates.
1837 In that buffer, you have several specialized commands, described in
1838 @ref{Xref Commands}.
1839
1840 @kindex M-,
1841 @findex xref-pop-marker-stack
1842 @vindex xref-marker-ring-length
1843 To go back to places @emph{from where} you found the definition,
1844 use @kbd{M-,} (@code{xref-pop-marker-stack}). It jumps back to the
1845 point of the last invocation of @kbd{M-.}. Thus you can find and
1846 examine the definition of something with @kbd{M-.} and then return to
1847 where you were with @kbd{M-,}. @kbd{M-,} allows you to retrace your
1848 steps to a depth determined by the variable
1849 @code{xref-marker-ring-length}, which defaults to 16.
1850
1851 @node Xref Commands
1852 @subsubsection Commands Available in the @file{*xref*} Buffer
1853 @cindex commands in @file{*xref*} buffers
1854 @cindex XREF mode
1855
1856 The following commands are provided in the @file{*xref*} buffer by
1857 the special XREF mode:
1858
1859 @table @kbd
1860 @item @key{RET}
1861 @itemx Mouse-2
1862 Display the reference on the current line and bury the @file{*xref*}
1863 buffer.
1864 @item n
1865 @itemx .
1866 @findex xref-next-line
1867 Move to the next reference and display it in the other window
1868 (@code{xref-next-line}).
1869 @item p
1870 @itemx ,
1871 @findex xref-prev-line
1872 Move to the previous reference and display it in the other window
1873 (@code{xref-prev-line}).
1874 @item C-o
1875 @findex xref-show-location-at-point
1876 Display the reference on the current line in the other window
1877 (@code{xref-show-location-at-point}).
1878 @findex xref-query-replace-in-results
1879 @item r @var{pattern} @key{RET} @var{replacement} @key{RET}
1880 Perform interactive query-replace on references that match
1881 @var{pattern} (@code{xref-query-replace-in-results}), replacing
1882 the match with @var{replacement}. @xref{Identifier Search}.
1883 @findex xref-quit
1884 @item q
1885 Quit the window showing the @file{*xref*} buffer (@code{xref-quit}).
1886 @end table
1887
1888 In addition, the usual navigation commands, such as the arrow keys,
1889 @kbd{C-n}, and @kbd{C-p} are available for moving around the buffer
1890 without displaying the references.
1891
1892 @node Identifier Search
1893 @subsubsection Searching and Replacing with Identifiers
1894 @cindex search and replace in multiple files
1895 @cindex multiple-file search and replace
1896
1897 The commands in this section perform various search and replace
1898 operations either on identifiers themselves or on files that reference
1899 them.
1900
1901 @table @kbd
1902 @item M-?
1903 Find all the references for the identifier at point.
1904 @item M-x xref-query-replace-in-results @key{RET} @var{regexp} @key{RET} @var{replacement} @key{RET}
1905 Interactively replace @var{regexp} with @var{replacement} in the names
1906 of all the identifiers shown in the @file{*xref*} buffer.
1907 @item M-x tags-search @key{RET} @var{regexp} @key{RET}
1908 Search for @var{regexp} through the files in the selected tags
1909 table.
1910 @item M-x tags-query-replace @key{RET} @var{regexp} @key{RET} @var{replacement} @key{RET}
1911 Perform a @code{query-replace-regexp} on each file in the selected tags table.
1912 @item M-x tags-loop-continue
1913 Restart one of the last 2 commands above, from the current location of point.
1914 @end table
1915
1916 @kindex M-?
1917 @findex xref-find-references
1918 @kbd{M-?} finds all the references for the identifier at point. If
1919 there's no identifier at point, or when invoked with a prefix
1920 argument, the command prompts for the identifier, with completion. It
1921 then presents a @file{*xref*} buffer with all the references to the
1922 identifier, showing the file name and the line where the identifier is
1923 referenced. The XREF mode commands are available in this buffer, see
1924 @ref{Xref Commands}.
1925
1926 @findex xref-query-replace-in-results
1927 @kbd{M-x xref-query-replace-in-results} reads a regexp to match identifier
1928 names and a replacement string, just like ordinary @kbd{M-x
1929 query-replace-regexp}. It then performs the specified replacement in
1930 the names of the matching identifiers in all the places in all the
1931 files where these identifiers are referenced. This is useful when you
1932 rename your identifiers as part of refactoring. This command should
1933 be invoked in the @file{*xref*} buffer generated by @code{M-?}.
1934
1935 @findex tags-search
1936 @kbd{M-x tags-search} reads a regexp using the minibuffer, then
1937 searches for matches in all the files in the selected tags table, one
1938 file at a time. It displays the name of the file being searched so
1939 you can follow its progress. As soon as it finds an occurrence,
1940 @code{tags-search} returns. This command requires tags tables to be
1941 available (@pxref{Tags Tables}).
1942
1943 @findex tags-loop-continue
1944 Having found one match with @code{tags-search}, you probably want to
1945 find all the rest. Type @kbd{M-x tags-loop-continue} to resume the
1946 @code{tags-search}, finding one more match. This searches the rest of
1947 the current buffer, followed by the remaining files of the tags table.
1948
1949 @findex tags-query-replace
1950 @kbd{M-x tags-query-replace} performs a single
1951 @code{query-replace-regexp} through all the files in the tags table. It
1952 reads a regexp to search for and a string to replace with, just like
1953 ordinary @kbd{M-x query-replace-regexp}. It searches much like @kbd{M-x
1954 tags-search}, but repeatedly, processing matches according to your
1955 input. @xref{Query Replace}, for more information on query replace.
1956
1957 @vindex tags-case-fold-search
1958 @cindex case-sensitivity and tags search
1959 You can control the case-sensitivity of tags search commands by
1960 customizing the value of the variable @code{tags-case-fold-search}. The
1961 default is to use the same setting as the value of
1962 @code{case-fold-search} (@pxref{Lax Search}).
1963
1964 It is possible to get through all the files in the tags table with a
1965 single invocation of @kbd{M-x tags-query-replace}. But often it is
1966 useful to exit temporarily, which you can do with any input event that
1967 has no special query replace meaning. You can resume the query
1968 replace subsequently by typing @kbd{M-x tags-loop-continue}; this
1969 command resumes the last tags search or replace command that you did.
1970 For instance, to skip the rest of the current file, you can type
1971 @w{@kbd{M-> M-x tags-loop-continue}}.
1972
1973 Note that the commands described above carry out much broader
1974 searches than the @code{xref-find-definitions} family. The
1975 @code{xref-find-definitions} commands search only for definitions of
1976 identifiers that match your string or regexp. The commands
1977 @code{xref-find-references}, @code{tags-search}, and
1978 @code{tags-query-replace} find every occurrence of the identifier or
1979 regexp, as ordinary search commands and replace commands do in the
1980 current buffer.
1981
1982 As an alternative to @code{xref-find-references} and
1983 @code{tags-search}, you can run @command{grep} as a subprocess and
1984 have Emacs show you the matching lines one by one. @xref{Grep
1985 Searching}.
1986
1987 @node List Identifiers
1988 @subsubsection Identifier Inquiries
1989
1990 @table @kbd
1991 @item C-M-i
1992 @itemx M-@key{TAB}
1993 Perform completion on the text around point, possibly using the
1994 selected tags table if one is loaded (@code{completion-at-point}).
1995 @item M-x xref-find-apropos @key{RET} @var{regexp} @key{RET}
1996 Display a list of all known identifiers matching @var{regexp}.
1997 @item M-x list-tags @key{RET} @var{file} @key{RET}
1998 Display a list of the identifiers defined in the program file
1999 @var{file}.
2000 @item M-x next-file
2001 Visit files recorded in the selected tags table.
2002 @end table
2003
2004 @cindex completion (symbol names)
2005 In most programming language modes, you can type @kbd{C-M-i} or
2006 @kbd{M-@key{TAB}} (@code{completion-at-point}) to complete the symbol
2007 at point. Some modes provide specialized completion for this command
2008 tailored to the mode; for those that don't, if there is a tags table
2009 loaded, this command can use it to generate completion candidates.
2010 @xref{Symbol Completion}.
2011
2012 @findex list-tags
2013 @kbd{M-x list-tags} reads the name of one of the files covered by
2014 the selected tags table, and displays a list of tags defined in that
2015 file. Do not include a directory as part of the file name unless the
2016 file name recorded in the tags table includes a directory. This
2017 command works only with the etags backend, and requires a tags table
2018 for the project to be available. @xref{Tags Tables}.
2019
2020 @c Sadly, the new-and-improved Xref feature doesn't provide anything
2021 @c close to the described below features of the now-obsoleted
2022 @c tags-apropos. I'm leaving this here to encourage enhancements to
2023 @c xref.el.
2024 @ignore
2025 @findex tags-apropos
2026 @vindex tags-apropos-verbose
2027 @vindex tags-tag-face
2028 @vindex tags-apropos-additional-actions
2029 @kbd{M-x tags-apropos} is like @code{apropos} for tags
2030 (@pxref{Apropos}). It displays a list of tags in the selected tags
2031 table whose entries match @var{regexp}. If the variable
2032 @code{tags-apropos-verbose} is non-@code{nil}, it displays the names
2033 of the tags files together with the tag names. You can customize the
2034 appearance of the output by setting the variable @code{tags-tag-face}
2035 to a face. You can display additional output by customizing the
2036 variable @code{tags-apropos-additional-actions}; see its documentation
2037 for details.
2038 @end ignore
2039
2040 @findex next-file
2041 @kbd{M-x next-file} visits files covered by the selected tags table.
2042 The first time it is called, it visits the first file covered by the
2043 table. Each subsequent call visits the next covered file, unless a
2044 prefix argument is supplied, in which case it returns to the first
2045 file. This command requires a tags table to be selected.
2046
2047 @node Tags Tables
2048 @subsection Tags Tables
2049 @cindex tags and tag tables
2050
2051 A @dfn{tags table} records the tags@footnote{
2052 A @dfn{tag} is a synonym for identifier reference. Commands and
2053 features based on the @code{etags} package traditionally use ``tag''
2054 with this meaning, and this subsection follows that tradition.
2055 } extracted by scanning the source code of a certain program or a
2056 certain document. Tags extracted from generated files reference the
2057 original files, rather than the generated files that were scanned
2058 during tag extraction. Examples of generated files include C files
2059 generated from Cweb source files, from a Yacc parser, or from Lex
2060 scanner definitions; @file{.i} preprocessed C files; and Fortran files
2061 produced by preprocessing @file{.fpp} source files.
2062
2063 @cindex etags
2064 To produce a tags table, you run the @command{etags} shell command
2065 on a document or the source code file. The @samp{etags} program
2066 writes the tags to a @dfn{tags table file}, or @dfn{tags file} in
2067 short. The conventional name for a tags file is @file{TAGS}@.
2068 @xref{Create Tags Table}. (It is also possible to create a tags table
2069 by using one of the commands from other packages that can produce such
2070 tables in the same format.)
2071
2072 Emacs uses the tags tables via the @code{etags} package as one of
2073 the supported backends for @code{xref}. Because tags tables are
2074 produced by the @command{etags} command that is part of an Emacs
2075 distribution, we describe tags tables in more detail here.
2076
2077 @cindex C++ class browser, tags
2078 @cindex tags, C++
2079 @cindex class browser, C++
2080 @cindex Ebrowse
2081 The Ebrowse facility is similar to @command{etags} but specifically
2082 tailored for C++. @xref{Top,, Ebrowse, ebrowse, Ebrowse User's
2083 Manual}. The Semantic package provides another way to generate and
2084 use tags, separate from the @command{etags} facility.
2085 @xref{Semantic}.
2086
2087 @menu
2088 * Tag Syntax:: Tag syntax for various types of code and text files.
2089 * Create Tags Table:: Creating a tags table with @command{etags}.
2090 * Etags Regexps:: Create arbitrary tags using regular expressions.
2091 @end menu
2092
2093 @node Tag Syntax
2094 @subsubsection Source File Tag Syntax
2095
2096 Here is how tag syntax is defined for the most popular languages:
2097
2098 @itemize @bullet
2099 @item
2100 In C code, any C function or typedef is a tag, and so are definitions of
2101 @code{struct}, @code{union} and @code{enum}.
2102 @code{#define} macro definitions, @code{#undef} and @code{enum}
2103 constants are also
2104 tags, unless you specify @samp{--no-defines} when making the tags table.
2105 Similarly, global variables are tags, unless you specify
2106 @samp{--no-globals}, and so are struct members, unless you specify
2107 @samp{--no-members}. Use of @samp{--no-globals}, @samp{--no-defines}
2108 and @samp{--no-members} can make the tags table file much smaller.
2109
2110 You can tag function declarations and external variables in addition
2111 to function definitions by giving the @samp{--declarations} option to
2112 @command{etags}.
2113
2114 @item
2115 In C++ code, in addition to all the tag constructs of C code, member
2116 functions are also recognized; member variables are also recognized,
2117 unless you use the @samp{--no-members} option. Tags for variables and
2118 functions in classes are named @samp{@var{class}::@var{variable}} and
2119 @samp{@var{class}::@var{function}}. @code{operator} definitions have
2120 tag names like @samp{operator+}.
2121
2122 @item
2123 In Java code, tags include all the constructs recognized in C++, plus
2124 the @code{interface}, @code{extends} and @code{implements} constructs.
2125 Tags for variables and functions in classes are named
2126 @samp{@var{class}.@var{variable}} and @samp{@var{class}.@var{function}}.
2127
2128 @item
2129 In @LaTeX{} documents, the arguments for @code{\chapter},
2130 @code{\section}, @code{\subsection}, @code{\subsubsection},
2131 @code{\eqno}, @code{\label}, @code{\ref}, @code{\cite},
2132 @code{\bibitem}, @code{\part}, @code{\appendix}, @code{\entry},
2133 @code{\index}, @code{\def}, @code{\newcommand}, @code{\renewcommand},
2134 @code{\newenvironment} and @code{\renewenvironment} are tags.
2135
2136 Other commands can make tags as well, if you specify them in the
2137 environment variable @env{TEXTAGS} before invoking @command{etags}. The
2138 value of this environment variable should be a colon-separated list of
2139 command names. For example,
2140
2141 @example
2142 TEXTAGS="mycommand:myothercommand"
2143 export TEXTAGS
2144 @end example
2145
2146 @noindent
2147 specifies (using Bourne shell syntax) that the commands
2148 @samp{\mycommand} and @samp{\myothercommand} also define tags.
2149
2150 @item
2151 In Lisp code, any function defined with @code{defun}, any variable
2152 defined with @code{defvar} or @code{defconst}, and in general the
2153 first argument of any expression that starts with @samp{(def} in
2154 column zero is a tag. As an exception, expressions of the form
2155 @code{(defvar @var{foo})} are treated as declarations, and are only
2156 tagged if the @samp{--declarations} option is given.
2157
2158 @item
2159 In Scheme code, tags include anything defined with @code{def} or with a
2160 construct whose name starts with @samp{def}. They also include variables
2161 set with @code{set!} at top level in the file.
2162 @end itemize
2163
2164 Several other languages are also supported:
2165
2166 @itemize @bullet
2167
2168 @item
2169 In Ada code, functions, procedures, packages, tasks and types are
2170 tags. Use the @samp{--packages-only} option to create tags for
2171 packages only.
2172
2173 In Ada, the same name can be used for different kinds of entity
2174 (e.g., for a procedure and for a function). Also, for things like
2175 packages, procedures and functions, there is the spec (i.e., the
2176 interface) and the body (i.e., the implementation). To make it
2177 easier to pick the definition you want, Ada tag name have suffixes
2178 indicating the type of entity:
2179
2180 @table @samp
2181 @item /b
2182 package body.
2183 @item /f
2184 function.
2185 @item /k
2186 task.
2187 @item /p
2188 procedure.
2189 @item /s
2190 package spec.
2191 @item /t
2192 type.
2193 @end table
2194
2195 Thus, @kbd{M-x find-tag @key{RET} bidule/b @key{RET}} will go
2196 directly to the body of the package @code{bidule}, while @kbd{M-x
2197 find-tag @key{RET} bidule @key{RET}} will just search for any tag
2198 @code{bidule}.
2199
2200 @item
2201 In assembler code, labels appearing at the start of a line,
2202 followed by a colon, are tags.
2203
2204 @item
2205 In Bison or Yacc input files, each rule defines as a tag the nonterminal
2206 it constructs. The portions of the file that contain C code are parsed
2207 as C code.
2208
2209 @item
2210 In Cobol code, tags are paragraph names; that is, any word starting in
2211 column 8 and followed by a period.
2212
2213 @item
2214 In Erlang code, the tags are the functions, records and macros defined
2215 in the file.
2216
2217 @item
2218 In Fortran code, functions, subroutines and block data are tags.
2219
2220 @item
2221 In Go code, packages, functions, and types are tags.
2222
2223 @item
2224 In HTML input files, the tags are the @code{title} and the @code{h1},
2225 @code{h2}, @code{h3} headers. Also, tags are @code{name=} in anchors
2226 and all occurrences of @code{id=}.
2227
2228 @item
2229 In Lua input files, all functions are tags.
2230
2231 @item
2232 In makefiles, targets are tags; additionally, variables are tags
2233 unless you specify @samp{--no-globals}.
2234
2235 @item
2236 In Objective C code, tags include Objective C definitions for classes,
2237 class categories, methods and protocols. Tags for variables and
2238 functions in classes are named @samp{@var{class}::@var{variable}} and
2239 @samp{@var{class}::@var{function}}.
2240
2241 @item
2242 In Pascal code, the tags are the functions and procedures defined in
2243 the file.
2244
2245 @item
2246 In Perl code, the tags are the packages, subroutines and variables
2247 defined by the @code{package}, @code{sub}, @code{use constant},
2248 @code{my}, and @code{local} keywords. Use @samp{--globals} if you
2249 want to tag global variables. Tags for subroutines are named
2250 @samp{@var{package}::@var{sub}}. The name for subroutines defined in
2251 the default package is @samp{main::@var{sub}}.
2252
2253 @item
2254 In PHP code, tags are functions, classes and defines. Vars are tags
2255 too, unless you use the @samp{--no-members} option.
2256
2257 @item
2258 In PostScript code, the tags are the functions.
2259
2260 @item
2261 In Prolog code, tags are predicates and rules at the beginning of
2262 line.
2263
2264 @item
2265 In Python code, @code{def} or @code{class} at the beginning of a line
2266 generate a tag.
2267
2268 @item
2269 In Ruby code, @code{def} or @code{class} or @code{module} at the
2270 beginning of a line generate a tag. Constants also generate tags.
2271 @end itemize
2272
2273 You can also generate tags based on regexp matching (@pxref{Etags
2274 Regexps}) to handle other formats and languages.
2275
2276 @node Create Tags Table
2277 @subsubsection Creating Tags Tables
2278 @cindex @command{etags} program
2279
2280 The @command{etags} program is used to create a tags table file. It knows
2281 the syntax of several languages, as described in
2282 @iftex
2283 the previous section.
2284 @end iftex
2285 @ifnottex
2286 @ref{Tag Syntax}.
2287 @end ifnottex
2288 Here is how to run @command{etags}:
2289
2290 @example
2291 etags @var{inputfiles}@dots{}
2292 @end example
2293
2294 @noindent
2295 The @command{etags} program reads the specified files, and writes a tags
2296 table named @file{TAGS} in the current working directory. You can
2297 optionally specify a different file name for the tags table by using the
2298 @samp{--output=@var{file}} option; specifying @file{-} as a file name
2299 prints the tags table to standard output.
2300
2301 If the specified files don't exist, @command{etags} looks for
2302 compressed versions of them and uncompresses them to read them. Under
2303 MS-DOS, @command{etags} also looks for file names like @file{mycode.cgz}
2304 if it is given @samp{mycode.c} on the command line and @file{mycode.c}
2305 does not exist.
2306
2307 If the tags table becomes outdated due to changes in the files
2308 described in it, you can update it by running the @command{etags}
2309 program again. If the tags table does not record a tag, or records it
2310 for the wrong file, then Emacs will not be able to find that
2311 definition until you update the tags table. But if the position
2312 recorded in the tags table becomes a little bit wrong (due to other
2313 editing), Emacs will still be able to find the right position, with a
2314 slight delay.
2315
2316 Thus, there is no need to update the tags table after each edit.
2317 You should update a tags table when you define new tags that you want
2318 to have listed, or when you move tag definitions from one file to
2319 another, or when changes become substantial.
2320
2321 You can make a tags table @dfn{include} another tags table, by
2322 passing the @samp{--include=@var{file}} option to @command{etags}. It
2323 then covers all the files covered by the included tags file, as well
2324 as its own.
2325
2326 If you specify the source files with relative file names when you run
2327 @command{etags}, the tags file will contain file names relative to the
2328 directory where the tags file was initially written. This way, you can
2329 move an entire directory tree containing both the tags file and the
2330 source files, and the tags file will still refer correctly to the source
2331 files. If the tags file is @file{-} or is in the @file{/dev} directory,
2332 however, the file names are
2333 made relative to the current working directory. This is useful, for
2334 example, when writing the tags to the standard output.
2335
2336 When using a relative file name, it should not be a symbolic link
2337 pointing to a tags file in a different directory, because this would
2338 generally render the file names invalid.
2339
2340 If you specify absolute file names as arguments to @command{etags}, then
2341 the tags file will contain absolute file names. This way, the tags file
2342 will still refer to the same files even if you move it, as long as the
2343 source files remain in the same place. Absolute file names start with
2344 @samp{/}, or with @samp{@var{device}:/} on MS-DOS and MS-Windows.
2345
2346 When you want to make a tags table from a great number of files,
2347 you may have problems listing them on the command line, because some
2348 systems have a limit on its length. You can circumvent this limit by
2349 telling @command{etags} to read the file names from its standard
2350 input, by typing a dash in place of the file names, like this:
2351
2352 @smallexample
2353 find . -name "*.[chCH]" -print | etags -
2354 @end smallexample
2355
2356 @command{etags} recognizes the language used in an input file based
2357 on its file name and contents. You can specify the language
2358 explicitly with the @samp{--language=@var{name}} option. You can
2359 intermix these options with file names; each one applies to the file
2360 names that follow it. Specify @samp{--language=auto} to tell
2361 @command{etags} to resume guessing the language from the file names
2362 and file contents. Specify @samp{--language=none} to turn off
2363 language-specific processing entirely; then @command{etags} recognizes
2364 tags by regexp matching alone (@pxref{Etags Regexps}).
2365
2366 The option @samp{--parse-stdin=@var{file}} is mostly useful when
2367 calling @command{etags} from programs. It can be used (only once) in
2368 place of a file name on the command line. @command{etags} will read from
2369 standard input and mark the produced tags as belonging to the file
2370 @var{file}.
2371
2372 @samp{etags --help} outputs the list of the languages @command{etags}
2373 knows, and the file name rules for guessing the language. It also prints
2374 a list of all the available @command{etags} options, together with a short
2375 explanation. If followed by one or more @samp{--language=@var{lang}}
2376 options, it outputs detailed information about how tags are generated for
2377 @var{lang}.
2378
2379 @node Etags Regexps
2380 @subsubsection Etags Regexps
2381
2382 The @samp{--regex} option to @command{etags} allows tags to be
2383 recognized by regular expression matching. You can intermix this
2384 option with file names; each one applies to the source files that
2385 follow it. If you specify multiple @samp{--regex} options, all of
2386 them are used in parallel. The syntax is:
2387
2388 @smallexample
2389 --regex=[@var{@{language@}}]/@var{tagregexp}/[@var{nameregexp}/]@var{modifiers}
2390 @end smallexample
2391
2392 @noindent
2393 The essential part of the option value is @var{tagregexp}, the regexp
2394 for matching tags. It is always used anchored, that is, it only
2395 matches at the beginning of a line. If you want to allow indented
2396 tags, use a regexp that matches initial whitespace; start it with
2397 @samp{[ \t]*}.
2398
2399 In these regular expressions, @samp{\} quotes the next character, and
2400 all the GCC character escape sequences are supported (@samp{\a} for
2401 bell, @samp{\b} for back space, @samp{\d} for delete, @samp{\e} for
2402 escape, @samp{\f} for formfeed, @samp{\n} for newline, @samp{\r} for
2403 carriage return, @samp{\t} for tab, and @samp{\v} for vertical tab).
2404
2405 Ideally, @var{tagregexp} should not match more characters than are
2406 needed to recognize what you want to tag. If the syntax requires you
2407 to write @var{tagregexp} so it matches more characters beyond the tag
2408 itself, you should add a @var{nameregexp}, to pick out just the tag.
2409 This will enable Emacs to find tags more accurately and to do
2410 completion on tag names more reliably. You can find some examples
2411 below.
2412
2413 The @var{modifiers} are a sequence of zero or more characters that
2414 modify the way @command{etags} does the matching. A regexp with no
2415 modifiers is applied sequentially to each line of the input file, in a
2416 case-sensitive way. The modifiers and their meanings are:
2417
2418 @table @samp
2419 @item i
2420 Ignore case when matching this regexp.
2421 @item m
2422 Match this regular expression against the whole file, so that
2423 multi-line matches are possible.
2424 @item s
2425 Match this regular expression against the whole file, and allow
2426 @samp{.} in @var{tagregexp} to match newlines.
2427 @end table
2428
2429 The @samp{-R} option cancels all the regexps defined by preceding
2430 @samp{--regex} options. It too applies to the file names following
2431 it. Here's an example:
2432
2433 @smallexample
2434 etags --regex=/@var{reg1}/i voo.doo --regex=/@var{reg2}/m \
2435 bar.ber -R --lang=lisp los.er
2436 @end smallexample
2437
2438 @noindent
2439 Here @command{etags} chooses the parsing language for @file{voo.doo} and
2440 @file{bar.ber} according to their contents. @command{etags} also uses
2441 @var{reg1} to recognize additional tags in @file{voo.doo}, and both
2442 @var{reg1} and @var{reg2} to recognize additional tags in
2443 @file{bar.ber}. @var{reg1} is checked against each line of
2444 @file{voo.doo} and @file{bar.ber}, in a case-insensitive way, while
2445 @var{reg2} is checked against the whole @file{bar.ber} file,
2446 permitting multi-line matches, in a case-sensitive way. @command{etags}
2447 uses only the Lisp tags rules, with no user-specified regexp matching,
2448 to recognize tags in @file{los.er}.
2449
2450 You can restrict a @samp{--regex} option to match only files of a
2451 given language by using the optional prefix @var{@{language@}}.
2452 (@samp{etags --help} prints the list of languages recognized by
2453 @command{etags}.) This is particularly useful when storing many
2454 predefined regular expressions for @command{etags} in a file. The
2455 following example tags the @code{DEFVAR} macros in the Emacs source
2456 files, for the C language only:
2457
2458 @smallexample
2459 --regex='@{c@}/[ \t]*DEFVAR_[A-Z_ \t(]+"\([^"]+\)"/'
2460 @end smallexample
2461
2462 @noindent
2463 When you have complex regular expressions, you can store the list of
2464 them in a file. The following option syntax instructs @command{etags} to
2465 read two files of regular expressions. The regular expressions
2466 contained in the second file are matched without regard to case.
2467
2468 @smallexample
2469 --regex=@@@var{case-sensitive-file} --ignore-case-regex=@@@var{ignore-case-file}
2470 @end smallexample
2471
2472 @noindent
2473 A regex file for @command{etags} contains one regular expression per
2474 line. Empty lines, and lines beginning with space or tab are ignored.
2475 When the first character in a line is @samp{@@}, @command{etags} assumes
2476 that the rest of the line is the name of another file of regular
2477 expressions; thus, one such file can include another file. All the
2478 other lines are taken to be regular expressions. If the first
2479 non-whitespace text on the line is @samp{--}, that line is a comment.
2480
2481 For example, we can create a file called @samp{emacs.tags} with the
2482 following contents:
2483
2484 @smallexample
2485 -- This is for GNU Emacs C source files
2486 @{c@}/[ \t]*DEFVAR_[A-Z_ \t(]+"\([^"]+\)"/\1/
2487 @end smallexample
2488
2489 @noindent
2490 and then use it like this:
2491
2492 @smallexample
2493 etags --regex=@@emacs.tags *.[ch] */*.[ch]
2494 @end smallexample
2495
2496 Here are some more examples. The regexps are quoted to protect them
2497 from shell interpretation.
2498
2499 @itemize @bullet
2500
2501 @item
2502 Tag Octave files:
2503
2504 @smallexample
2505 etags --language=none \
2506 --regex='/[ \t]*function.*=[ \t]*\([^ \t]*\)[ \t]*(/\1/' \
2507 --regex='/###key \(.*\)/\1/' \
2508 --regex='/[ \t]*global[ \t].*/' \
2509 *.m
2510 @end smallexample
2511
2512 @noindent
2513 Note that tags are not generated for scripts, so that you have to add
2514 a line by yourself of the form @samp{###key @var{scriptname}} if you
2515 want to jump to it.
2516
2517 @item
2518 Tag Tcl files:
2519
2520 @smallexample
2521 etags --language=none --regex='/proc[ \t]+\([^ \t]+\)/\1/' *.tcl
2522 @end smallexample
2523
2524 @item
2525 Tag VHDL files:
2526
2527 @smallexample
2528 etags --language=none \
2529 --regex='/[ \t]*\(ARCHITECTURE\|CONFIGURATION\) +[^ ]* +OF/' \
2530 --regex='/[ \t]*\(ATTRIBUTE\|ENTITY\|FUNCTION\|PACKAGE\
2531 \( BODY\)?\|PROCEDURE\|PROCESS\|TYPE\)[ \t]+\([^ \t(]+\)/\3/'
2532 @end smallexample
2533 @end itemize
2534
2535 @node Select Tags Table
2536 @subsection Selecting a Tags Table
2537
2538 @findex visit-tags-table
2539 Emacs has at any time at most one @dfn{selected} tags table. All the
2540 commands for working with tags tables use the selected one. To select
2541 a tags table, type @kbd{M-x visit-tags-table}, which reads the tags
2542 table file name as an argument, with @file{TAGS} in the default
2543 directory as the default.
2544
2545 @vindex tags-file-name
2546 Emacs does not actually read in the tags table contents until you
2547 try to use them; all @code{visit-tags-table} does is store the file
2548 name in the variable @code{tags-file-name}, and setting the variable
2549 yourself is just as good. The variable's initial value is @code{nil};
2550 that value tells all the commands for working with tags tables that
2551 they must ask for a tags table file name to use.
2552
2553 Using @code{visit-tags-table} when a tags table is already loaded
2554 gives you a choice: you can add the new tags table to the current list
2555 of tags tables, or start a new list. The tags commands use all the tags
2556 tables in the current list. If you start a new list, the new tags table
2557 is used @emph{instead} of others. If you add the new table to the
2558 current list, it is used @emph{as well as} the others.
2559
2560 @vindex tags-table-list
2561 You can specify a precise list of tags tables by setting the variable
2562 @code{tags-table-list} to a list of strings, like this:
2563
2564 @c keep this on two lines for formatting in smallbook
2565 @example
2566 @group
2567 (setq tags-table-list
2568 '("~/emacs" "/usr/local/lib/emacs/src"))
2569 @end group
2570 @end example
2571
2572 @noindent
2573 This tells the tags commands to look at the @file{TAGS} files in your
2574 @file{~/emacs} directory and in the @file{/usr/local/lib/emacs/src}
2575 directory. The order depends on which file you are in and which tags
2576 table mentions that file, as explained above.
2577
2578 Do not set both @code{tags-file-name} and @code{tags-table-list}.
2579
2580 @node EDE
2581 @section Emacs Development Environment
2582 @cindex EDE (Emacs Development Environment)
2583 @cindex Emacs Development Environment
2584 @cindex Integrated development environment
2585
2586 EDE (@dfn{Emacs Development Environment}) is a package that simplifies
2587 the task of creating, building, and debugging large programs with
2588 Emacs. It provides some of the features of an IDE, or @dfn{Integrated
2589 Development Environment}, in Emacs.
2590
2591 This section provides a brief description of EDE usage.
2592 @ifnottex
2593 For full details, see @ref{Top, EDE,, ede, Emacs Development Environment}.
2594 @end ifnottex
2595 @iftex
2596 For full details on Ede, type @kbd{C-h i} and then select the EDE
2597 manual.
2598 @end iftex
2599
2600 EDE is implemented as a global minor mode (@pxref{Minor Modes}). To
2601 enable it, type @kbd{M-x global-ede-mode} or click on the
2602 @samp{Project Support (EDE)} item in the @samp{Tools} menu. You can
2603 also enable EDE each time you start Emacs, by adding the following
2604 line to your initialization file:
2605
2606 @smallexample
2607 (global-ede-mode t)
2608 @end smallexample
2609
2610 @noindent
2611 Activating EDE adds a menu named @samp{Development} to the menu bar.
2612 Many EDE commands, including the ones described below, can be invoked
2613 from this menu.
2614
2615 EDE organizes files into @dfn{projects}, which correspond to
2616 directory trees. The @dfn{project root} is the topmost directory of a
2617 project. To define a new project, visit a file in the desired project
2618 root and type @kbd{M-x ede-new}. This command prompts for a
2619 @dfn{project type}, which refers to the underlying method that EDE
2620 will use to manage the project (@pxref{Creating a project, EDE,, ede,
2621 Emacs Development Environment}). The most common project types are
2622 @samp{Make}, which uses Makefiles, and @samp{Automake}, which uses GNU
2623 Automake (@pxref{Top, Automake,, automake, Automake}). In both cases,
2624 EDE also creates a file named @file{Project.ede}, which stores
2625 information about the project.
2626
2627 A project may contain one or more @dfn{targets}. A target can be an
2628 object file, executable program, or some other type of file, which is
2629 built from one or more of the files in the project.
2630
2631 To add a new @dfn{target} to a project, type @kbd{C-c . t}
2632 (@code{M-x ede-new-target}). This command also asks if you wish to
2633 add the current file to that target, which means that the target
2634 is to be built from that file. After you have defined a target, you
2635 can add more files to it by typing @kbd{C-c . a}
2636 (@code{ede-add-file}).
2637
2638 To build a target, type @kbd{C-c . c} (@code{ede-compile-target}).
2639 To build all the targets in the project, type @kbd{C-c . C}
2640 (@code{ede-compile-project}). EDE uses the file types to guess how
2641 the target should be built.
2642
2643 @ifnottex
2644 @include emerge-xtra.texi
2645 @end ifnottex