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