Maintaining Large Programs
This chapter describes Emacs features for maintaining medium- to large-size programs and packages. These features include:
- Unified interface to Support for Version Control Systems (VCS) that record the history of changes to source files.
- Commands for handling programming projects.
- A specialized mode for maintaining
ChangeLogfiles that provide a chronological log of program changes. - Xref, a set of commands for displaying definitions of symbols (a.k.a. "identifiers") and their references.
- EDE, alternative tools for managing programming projects, especially building and debugging.
- A mode for merging changes to program sources made on separate branches of development.
- A minor-mode for highlighting bug references and visiting the referenced bug reports in their issue tracker.
If you are maintaining a large Lisp program, then in addition to the features described here, you may find the Emacs Lisp Regression Testing (ERT) library useful (ERT).
Version Control
A version control system is a program that can record multiple versions of a source file, storing information such as the creation time of each version, who made it, and a description of what was changed. The Emacs version control interface is called VC. VC commands work with several different version control systems; currently, it supports Bazaar, CVS, Git, Mercurial, RCS, SRC, SCCS/CSSC, and Subversion. Of these, the GNU project distributes CVS, RCS, and Bazaar. VC is enabled automatically whenever you visit a file governed by a version control system. To disable VC entirely, set the customizable variable vc-handled-backends to nil (Customizing VC). To update the VC state information for the file visited in the current buffer, use the command vc-refresh-state. This command is useful when you perform version control commands outside Emacs (e.g., from the shell prompt), or if you put the buffer's file under a different version control system, or remove it from version control entirely. VC is also enabled automatically in Dired buffers (Dired) showing directories whose files are controlled by a VCS. All VC commands described in this section can be invoked from any Dired buffer showing a directory with VC-controlled files; any files that are marked in a Dired buffer (Marks vs Flags) are considered to belong to the current fileset, and VC commands operate on the files in this fileset. This allows you to construct VC filesets including any files you want, regardless of their VC state. (If no files are marked when a VC command is invoked from a Dired buffer, the file shown on the current line in the buffer is considered the only file in the fileset.)
Introduction to Version Control
VC allows you to use a version control system from within Emacs, integrating the version control operations smoothly with editing. It provides a uniform interface for common operations in many version control systems. Some uncommon or intricate version control operations, such as altering repository settings, are not supported in VC. You should perform such tasks outside VC, e.g., at the command line. This section provides a general overview of version control, and describes the version control systems that VC supports. You can skip this section if you are already familiar with the version control system you want to use.
Understanding the Problems it Addresses
Version control systems provide you with three important capabilities:
- Reversibility: the ability to back up to a previous state if you discover that some modification you did was a mistake or a bad idea.
- Concurrency: the ability to have many people modifying the same collection of files knowing that conflicting modifications can be detected and resolved.
- History: the ability to attach historical data to your data, such as explanatory comments about the intention behind each change. Even for a programmer working solo, change histories are an important aid to memory; for a multi-person project, they are a vitally important form of communication among developers.
Supported Version Control Systems
VC currently works with many different version control systems, which it refers to as backends:
- Git is a decentralized version control system originally invented by Linus Torvalds to support development of Linux (his kernel). VC supports all the common Git operations, but notably, Git rebases other than simply to edit a commit message must be done from the command line.
- CVS is the free version control system that was, until circa 2008, used by the majority of free software projects. Since then, it has been superseded by newer systems. CVS allows concurrent multi-user development either locally or over the network. Unlike newer systems, it lacks support for atomic commits and file moving/renaming. VC supports all basic editing operations under CVS.
- Subversion (svn) is a free version control system designed to be similar to CVS but without its problems (e.g., it supports atomic commits of filesets, and versioning of directories, symbolic links, meta-data, renames, copies, and deletes).
- SCCS was the first version control system ever built, and was long ago superseded by more advanced ones. VC compensates for certain features missing in SCCS (e.g., tag names for releases) by implementing them itself. Other VC features, such as multiple branches, are simply unavailable. Since SCCS is non-free, we recommend avoiding it.
- CSSC is a free replacement for SCCS. You should use CSSC only if, for some reason, you cannot use a more recent and better-designed version control system.
- RCS is the free version control system around which VC was initially built. It is relatively primitive: it cannot be used over the network, and works at the level of individual files. Almost everything you can do with RCS can be done through VC.
- Mercurial (hg) is a decentralized version control system broadly resembling Git. VC supports most Mercurial commands.
- Bazaar (bzr) is a decentralized version control system that supports both repository-based and decentralized versioning. VC supports most basic editing operations under Bazaar.
- SRC (src) is RCS, reloaded—a specialized version-control system designed for single-file projects worked on by only one person. It allows multiple files with independent version-control histories to exist in one directory, and is thus particularly well suited for maintaining small documents, scripts, and dotfiles. While it uses RCS for revision storage, it presents a modern user interface featuring lockless operation and integer sequential version numbers. VC supports almost all SRC operations.
Concepts of Version Control
When a file is under version control, we say that it is registered with the version control system. The system has a repository which stores both the file's present state and its change history—enough to reconstruct the current version or any earlier version. The repository also contains other information, such as log entries that describe the changes made to each file. The copy of a version-controlled file that you actually edit is called the work file. You can change each work file as you would an ordinary file. After you are done with a set of changes, you may commit (or check in) the changes; this records the changes in the repository, along with a descriptive log entry. A directory tree of work files is called a working tree. Each commit creates a new revision in the repository. The version control system keeps track of all past revisions and the changes that were made in each revision. Each revision is named by a revision ID, whose format depends on the version control system; in the simplest case, it is just an integer. To go beyond these basic concepts, you will need to understand three aspects in which version control systems differ. As explained in the next three sections, they can be lock-based or merge-based; file-based or changeset-based; and centralized or decentralized. VC handles all these modes of operation, but it cannot hide the differences.
Merge-based vs Lock-based Version Control
A version control system typically has some mechanism to coordinate between users who want to change the same file. There are two ways to do this: merging and locking. In a version control system that uses merging, each user may modify a work file at any time. The system lets you merge your work file, which may contain changes that have not been committed, with the latest changes that others have committed. Older version control systems use a locking scheme instead. Here, work files are normally read-only. To edit a file, you ask the version control system to make it writable for you by locking it; only one user can lock a given file at any given time. This procedure is analogous to, but different from, the locking that Emacs uses to detect simultaneous editing of ordinary files (Interlocking). When you commit your changes, that unlocks the file, and the work file becomes read-only again. Other users may then lock the file to make their own changes. Both locking and merging systems can have problems when multiple users try to modify the same file at the same time. Locking systems have lock conflicts; a user may try to check a file out and be unable to because it is locked. In merging systems, merge conflicts happen when you commit a change to a file that conflicts with a change committed by someone else after your checkout. Both kinds of conflict have to be resolved by human judgment and communication. Experience has shown that merging is superior to locking, both in convenience to developers and in minimizing the number and severity of conflicts that actually occur. SCCS always uses locking. RCS is lock-based by default but can be told to operate in a merging style. CVS and Subversion are merge-based by default but can be told to operate in a locking mode. Decentralized version control systems, such as Git and Mercurial, are exclusively merging-based. VC mode supports both locking and merging version control. The terms "commit" and "update" are used in newer version control systems; older lock-based systems use the terms "check in" and "check out". VC hides the differences between them as much as possible.
Changeset-based vs File-based Version Control
On SCCS, RCS, CVS, and other early version control systems (and also in SRC), version control operations are file-based: each file has its own comment and revision history separate from that of all other files. Newer systems, beginning with Subversion, are changeset-based: a commit may include changes to several files, and the entire set of changes is handled as a unit. Any comment associated with the change does not belong to a single file, but to the changeset itself. Changeset-based version control is more flexible and powerful than file-based version control; usually, when a change to multiple files has to be reversed, it's good to be able to easily identify and remove all of it.
Decentralized vs Centralized Repositories
Early version control systems were designed around a centralized model in which each project has only one repository used by all developers. SCCS, RCS, CVS, Subversion, and SRC share this kind of model. One of its drawbacks is that the repository is a choke point for reliability and efficiency. GNU Arch pioneered the concept of distributed or decentralized version control, later implemented in Git, Mercurial, and Bazaar. A project may have several different repositories, and these systems support a sort of super-merge between repositories that tries to reconcile their change histories. In effect, there is one repository for each developer, and repository merges take the place of commit operations. VC helps you manage the traffic between your personal workfiles and a repository. Whether the repository is a single master, or one of a network of peer repositories, is not something VC has to care about.
Types of Log File
Projects that use a version control system can have two types of log for changes. One is the log maintained by the version control system: each time you commit a change, you fill out a log entry for the change (Log Buffer). This is called the version control log. The other kind of log is the file ChangeLog (Change Log). It provides a chronological record of all changes to a large portion of a program—typically one directory and its subdirectories. A small program would use one ChangeLog file; a large program may have a ChangeLog file in each major directory. Change Log. Programmers have used change logs since long before version control systems. Changeset-based version systems typically maintain a changeset-based modification log for the entire system, which makes change log files somewhat redundant. One advantage that they retain is that it is sometimes useful to be able to view the transaction history of a single directory separately from those of other directories. Another advantage is that mistakes in commit logs can't be fixed in many version control systems. A project maintained with version control can use just the version control log, or it can use both kinds of logs. It can handle some files one way and some files the other way. Each project has its policy, which you should follow. When the policy is to use both, you typically want to write an entry for each change just once, then put it into both logs. You can write the entry in ChangeLog, then copy it to the log buffer with C-c C-a when committing the change (Log Buffer). Or you can write the entry in the log buffer while committing the change (with the help of C-c C-w), and later use the C-x v a command to copy it to ChangeLog (Change Logs and VC).
Version Control and the Mode Line
When you visit a file that is under version control, Emacs indicates this on the mode line. For example, Bzr-1223 says that Bazaar is used for that file, and the current revision ID is 1223. The character between the back-end name and the revision ID indicates the version control status of the work file. In a merge-based version control system, a - character indicates that the work file is unmodified, and : indicates that it has been modified. ! indicates that the file contains conflicts as result of a recent merge operation (Merging), or that the file was removed from the version control, or that it is versioned but also ignored, something that usually should not happen (VC Ignore). Finally, ? means that the file is under version control, but is missing from the working tree. In a lock-based system, - indicates an unlocked file, and : a locked file; if the file is locked by another user (for instance, jim), that is displayed as RCS:jim:1.3. @@ means that the file was locally added, but not yet committed to the master repository. On a graphical display, you can move the mouse over this mode line indicator to pop up a tool-tip, which displays a more verbose description of the version control status. Pressing mouse-1 over the indicator pops up a menu of VC commands, identical to Tools / Version Control on the menu bar. When Auto Revert mode (Reverting) reverts a buffer that is under version control, it updates the version control information in the mode line. However, Auto Revert mode may not properly update this information if the version control status changes without changes to the work file, from outside the current Emacs session. If you set auto-revert-check-vc-info to t, Auto Revert mode updates the version control status information every auto-revert-interval seconds, even if the work file itself is unchanged. The resulting CPU usage depends on the version control system, but is usually not excessive.
Basic Editing under Version Control
Most VC commands operate on VC filesets. A VC fileset is a collection of one or more files that a VC operation acts upon. When you type VC commands in a buffer visiting a version-controlled file, the VC fileset is simply that one file. When you type them in a VC Directory buffer, and some files in it are marked, the VC fileset consists of the marked files (VC Directory Mode). Likewise, when you invoke a VC command from a Dired buffer, the VC fileset consists of the marked files (Marks vs Flags), defaulting to the file shown on the current line if no files are marked. With modern changeset-based version control systems (VCS Changesets), such as Git, Mercurial, and Bazaar, VC commands handle multi-file VC filesets as a group. For example, committing a multi-file VC fileset generates a single revision, containing the changes to all those files. On older file-based version control systems like CVS, each file in a multi-file VC fileset is handled individually; thus, committing a fileset generates one revision for each changed file in the fileset.
-
C-x v v - Perform the next appropriate version control operation on the current VC fileset.
The principal VC command is a multi-purpose command, C-x v v (vc-next-action), which performs the most appropriate action on the current VC fileset: either registering it with a version control system, or committing it, or unlocking it, or merging changes into it. The precise actions for each situation are described in detail in the following subsections. You can use C-x v v either in a file-visiting buffer, in a Dired buffer, or in a VC Directory buffer; in the latter two cases the command operates on the fileset consisting of the marked files. You can also use C-x v v, in a buffer with patches under Diff mode (Diff Mode), in which case the command operates on the files whose diffs are shown in the buffer. Note that VC filesets are distinct from the named filesets used for viewing and visiting files in functional groups (Filesets). Unlike named filesets, VC filesets are not named and don't persist across sessions.
Basic Version Control with Merging
With a modern merging-based version control system (such as Git and Hg; VCS Merging), C-x v v does the following when invoked from a buffer that visits a version-controlled file or a VC Directory or Dired buffer:
- If there is more than one file in the VC fileset and the files have inconsistent version control statuses, signal an error. (Note, however, that a fileset is allowed to include both newly-added files, removed files and modified files; Registering.) Also signal an error if any files in the fileset are ignored by version control.
- If every file in the VC fileset is registered and unchanged with respect to the last revision, do nothing.
- If none of the files in the VC fileset are registered with a version control system, register the newly-added files in the VC fileset, i.e., place them under version control. Registering. If Emacs cannot find a system to register under, it prompts for a repository type, creates a new repository, and registers the VC fileset with it. You can also specify the system explicitly, see Advanced C-x v v. Note that registering the files doesn't commit them; you must invoke
C-x v vagain to commit; see the next point. - If every file in the VC fileset has been either newly-added or modified, commit the changed files. To do this, Emacs pops up a
*vc-log*buffer; type the desired log entry for the changes, followed byC-c C-cto commit. Log Buffer. IfC-x v vis invoked from a buffer under Diff mode, the command treats the buffer as holding a set of patches for one or more files. It then applies the changes to the respective files and commits the changes after popping up the*vc-log*buffer to allow you to type a suitable commit log message. Once you typeC-x v v, the fileset or patches cannot be changed without first canceling the commit by typingC-c C-kin the*vc-log*buffer. For example, if you change which files are marked in the*vc-dir*buffer after Emacs has already popped up the*vc-log*buffer, the old fileset will remain in effect for this commit. (This is in contrast to changes made to the contents of files in the fileset when not committing patches: all such changes will be included in the commit even if they are made after Emacs has popped up the*vc-log*buffer.) When you cancel a commit, Emacs saves your log message. This means that if you need to adjust the fileset or patches, it is easy to restart the commit operation again: typeC-c C-k C-x v v M-p. HereC-c C-kcancels the commit,C-x v vinitiates another with the new fileset or patches, and finallyM-precalls your previous log message. With modern decentralized version control systems (Git, Mercurial, etc.), the changes are committed locally and not automatically propagated to the upstream repository (which is usually on a remote host). In these cases, if the repository has been changed since your last update, the commit may fail. In that case, you must update from upstream and then try again. UseC-x v +(Pulling / Pushing) orC-x v m(Merging) for that. With a centralized version control system, if the commit fails due to upstream changes, typeC-x v vagain to merge in the upstream repository changes. - Finally, if you are using a centralized version control system, if any file in the VC fileset is outdated with respect to the upstream repository, offer to update the fileset from the repository.
These rules also apply when you use RCS in its non-locking mode, except that changes are not automatically merged from the repository. Nothing informs you if another user has committed changes in the same file since you began editing it; when you commit your revision, that other user's changes are removed (however, they remain in the repository and are thus not irrevocably lost). Therefore, you must verify that the current revision is unchanged before committing your changes. In addition, locking is possible with RCS even in this mode: C-x v v with an unmodified file locks the file, just as it does with RCS in its normal locking mode (VC With A Locking VCS).
Basic Version Control with Locking
With a locking-based version control system (such as SCCS, and RCS in its default mode), C-x v v does the following:
- If there is more than one file in the VC fileset and the files have inconsistent version control statuses, signal an error. Also signal an error if any files in the fileset are ignored by version control.
- If each file in the VC fileset is not registered with a version control system, register the newly-added files in the fileset. Registering. If Emacs cannot find a system to register under, it prompts for a repository type, creates a new repository, and registers the VC fileset with it. You can also specify the system explicitly, see Advanced C-x v v.
- If each file is registered and unlocked, check the files out: lock each one and make it writable, so that you can begin to edit it.
- If each file is locked by you and contains changes, commit (a.k.a. "check-in") the changes. To do this, Emacs pops up a
*vc-log*buffer; type the desired log entry for the new revision, followed byC-c C-cto commit (Log Buffer). - If each file is locked by you, but you have not changed it, release the lock and make the file read-only again. This undoes previous check-out operation for files that were not changed since the checkout.
- If each file is locked by another user, ask whether you want to steal the lock. If you say yes, the file becomes locked by you, and a warning message is sent to the user who had formerly locked the file.
- If files in the fileset are unlocked, but have changes with respect to their last revision, offer to claim the lock for each such file or to revert the file to the last checked-in revision. (This situation is exceptional and should not normally happen.)
These rules also apply when you use CVS in locking mode, except that CVS does not support stealing locks.
Advanced Control in C-x v v
When you give a prefix argument to vc-next-action (C-u C-x v v), it still performs the next logical version control operation, but accepts additional arguments to specify precisely how to do the operation.
- You can specify the name of a version control system. This is useful if the fileset can be managed by more than one version control system, and Emacs fails to detect the correct one.
- Otherwise, if using CVS, RCS or SRC, you can specify a revision ID. If the fileset is modified (or locked), this makes Emacs commit the files with that revision ID. You can create a new branch by supplying an appropriate revision ID (Branches). If the fileset is unmodified (and unlocked), this checks out the specified revision into the working tree. You can also specify a revision on another branch by giving its revision or branch ID (Switching Branches). An empty argument (i.e.,
C-u C-x v v =RET=) checks out the latest (a.k.a. "head") revision on the current branch. Specifying revision ID in this manner is silently ignored by a decentralized version control system. Those systems do not let you specify your own revision IDs, nor do they use the concept of checking out individual files.
Features of the Log Entry Buffer
When you tell VC to commit a change, it pops up a buffer named *vc-log*. In this buffer, you should write a log entry describing the changes you have made (Why Version Control?). After you are done, type C-c C-c (log-edit-done) to exit the buffer and commit the change, together with your log entry. The major mode for the *vc-log* buffer is Log Edit mode, a variant of Text mode (Text Mode). On entering Log Edit mode, Emacs runs the hooks text-mode-hook and vc-log-mode-hook (Hooks). In the *vc-log* buffer, you can write one or more header lines, specifying additional information to be supplied to the version control system. Each header line must occupy a single line at the top of the buffer; the first line that is not a header line is treated as the start of the log entry. For example, the following header line states that the present change was not written by you, but by another developer:
Author: J. R. Hacker <jrh@@example.com>
Apart from the Author header, Emacs recognizes the headers Summary (a one-line summary of the changeset), Date (a manually-specified commit time), and Fixes (a reference to a bug fixed by the change). Not all version control systems recognize all headers. If you specify a header for a system that does not support it, the header is treated as part of the log entry. While in the *vc-log* buffer, the current VC fileset is considered to be the fileset that will be committed if you type C-c C-c. To view a list of the files in the VC fileset, type C-c C-f (log-edit-show-files). To view a diff of changes between the VC fileset and the version from which you started editing (Old Revisions), type C-c C-d (log-edit-show-diff). To help generate ChangeLog entries, type C-c C-w (log-edit-generate-changelog-from-diff), to generate skeleton ChangeLog entries, listing all changed file and function names based on the diff of the VC fileset. Consecutive entries left empty will be combined by M-q (fill-paragraph). By default the skeleton will just include the file name, without any leading directories. If you wish to prepend the leading directories up to the VC root, customize diff-add-log-use-relative-names. If the VC fileset includes one or more ChangeLog files (Change Log), type C-c C-a (log-edit-insert-changelog) to pull the relevant entries into the *vc-log* buffer. If the topmost item in each ChangeLog was made under your user name on the current date, this command searches that item for entries matching the file(s) to be committed, and inserts them. If you are using CVS or RCS, see Change Logs and VC, for the opposite way of working—generating ChangeLog entries from the Log Edit buffer. To abort a commit, just don't type C-c C-c in that buffer. You can switch buffers and do other editing. As long as you don't try to make another commit, the entry you were editing remains in the *vc-log* buffer, and you can go back to that buffer at any time to complete the commit. You can also browse the history of previous log entries to duplicate a commit comment. This can be useful when you want to make several commits with similar comments. The commands M-n, M-p, M-s and M-r for doing this work just like the minibuffer history commands (Minibuffer History), except that they are used outside the minibuffer.
Registering a File for Version Control
-
C-x v i - Register the visited file for version control.
The command C-x v i (vc-register) registers each file in the current VC fileset, placing it under version control. This is essentially equivalent to the action of C-x v v on an unregistered VC fileset (Basic VC Editing), except that if the VC fileset is already registered, C-x v i signals an error whereas C-x v v performs some other action. To register a file, Emacs must choose a version control system. For a multi-file VC fileset, the VC Directory buffer specifies the system to use (VC Directory Mode). For a single-file VC fileset, if the file's directory already contains files registered in a version control system, or if the directory is part of a directory tree controlled by a version control system, Emacs chooses that system. In the event that more than one version control system is applicable, Emacs uses the one that appears first in the variable vc-handled-backends (Customizing VC). If Emacs cannot find a version control system to register the file under, it prompts for a repository type, creates a new repository, and registers the file into that repository. With most version control systems, registering a file with C-x v i or C-x v v adds it to the working tree, but does not commit it, i.e., doesn't add it to the repository. Such files are labeled as added in the VC Directory buffer, and the mode line of the buffers visiting such files shows a revision ID of @@@@. To make the registration take effect in the repository, you must commit the newly-added files (Basic VC Editing). Note that a single commit can include both file additions and edits to files already known to the VCS. With a locking-based version control system (VCS Merging), registering a file leaves it unlocked and read-only. Type C-x v v to check-out the file and start editing it.
Examining And Comparing Old Revisions
-
C-x v = - Compare the work files in the current VC fileset with the versions you started from (
vc-diff). With a prefix argument, prompt for two revisions of the current VC fileset and compare them. You can also call this command from a Dired buffer (Operating on Files). -
M-x vc-ediff - Like
C-x v =, but using Ediff. Ediff. -
C-x v D - Compare the entire working tree to the revision you started from (
vc-root-diff). With a prefix argument, prompt for two revisions and compare their trees. -
C-x v ~ - Prompt for a revision of the current file, and visit it in a separate buffer (
vc-revision-other-window). -
C-x v g - Display an annotated version of the current file: for each line, show the latest revision in which it was modified (
vc-annotate).
C-x v = (vc-diff) displays a diff which compares each work file in the current VC fileset to the version(s) from which you started editing. The diff is displayed in another window, in a Diff mode buffer (Diff Mode) named *vc-diff*. The usual Diff mode commands are available in this buffer. In particular, the g (revert-buffer) command performs the file comparison again, generating a new diff. To compare two arbitrary revisions of the current VC fileset, call vc-diff with a prefix argument: C-u C-x v =. This prompts for two revision IDs (VCS Concepts), and displays a diff between those versions of the fileset. This will not work reliably for multi-file VC filesets, if the version control system is file-based rather than changeset-based (e.g., CVS), since then revision IDs for different files would not be related in any meaningful way. Instead of the revision ID, some version control systems let you specify revisions in other formats. For instance, under Bazaar you can enter date:yesterday for the argument to C-u C-x v = (and related commands) to specify the first revision committed after yesterday. See the documentation of the version control system for details. If you invoke C-x v = or C-u C-x v = from a Dired buffer (Dired), the file listed on the current line is treated as the current VC fileset. The VC fileset can also include several marked files. M-x vc-ediff works like C-x v =, except that it uses an Ediff session. Ediff. C-x v D (vc-root-diff) is similar to C-x v =, but it displays the changes in the entire current working tree (i.e., the working tree containing the current VC fileset). If you invoke this command from a Dired buffer, it applies to the working tree containing the directory. To compare two arbitrary revisions of the whole trees, call vc-root-diff with a prefix argument: C-u C-x v D. This prompts for two revision IDs (VCS Concepts), and displays a diff between those versions of the entire version-controlled directory trees (RCS, SCCS, CVS, and SRC do not support this feature). You can customize the diff options that C-x v = and C-x v D use for generating diffs. The options used are taken from the first non-nil value amongst the variables vc-backend-diff-switches, vc-diff-switches, and diff-switches (Comparing Files), in that order. Here, backend stands for the relevant version control system, e.g., bzr for Bazaar. Since nil means to check the next variable in the sequence, either of the first two may use the value t to mean no switches at all. Most of the vc-backend-diff-switches variables default to nil, but some default to t; these are for version control systems whose diff implementations do not accept common diff options, such as Subversion. To directly examine an older version of a file, visit the work file and type C-x v ~ revision RET (vc-revision-other-window). This retrieves the file version corresponding to revision, saves it to filename.~revision~, and visits it in a separate window (Window Choice). Many version control systems allow you to view files annotated with per-line revision information, by typing C-x v g (vc-annotate). This creates a new "annotate" buffer displaying the file's text, with each line colored to show how old it is. Red text is new, blue is old, and intermediate colors indicate intermediate ages. By default, the color is scaled over the full range of ages, such that the oldest changes are blue, and the newest changes are red. If the variable vc-annotate-background-mode is non-nil, the colors expressing the age of each line are applied to the background color, leaving the foreground at its default color. You can customize the annotate options that C-x v g uses by customizing vc-backend-annotate-switches and vc-annotate-switches. They function similarly to vc-backend-diff-switches and vc-diff-switches, described above. When you give a prefix argument to C-x v g, Emacs reads two arguments using the minibuffer: the revision to display and annotate (instead of the current file contents), and the time span in days the color range should cover. From the "annotate" buffer, these and other color scaling options are available from the VC-Annotate menu. In this buffer, you can also use the following keys to browse the annotations of past revisions, view diffs, or view log entries:
-
p - Annotate the previous revision, i.e., the revision before the one currently annotated. A numeric prefix argument is a repeat count, so
C-u 10 pwould take you back 10 revisions. -
n - Annotate the next revision, i.e., the revision after the one currently annotated. A numeric prefix argument is a repeat count.
-
j - Annotate the revision indicated by the current line.
-
a - Annotate the revision before the one indicated by the current line. This is useful to see the state the file was in before the change on the current line was made.
-
f - Show in a buffer the file revision indicated by the current line.
-
d - Display the diff between the current line's revision and the previous revision. This is useful to see what the current line's revision actually changed in the file.
-
D - Display the diff between the current line's revision and the previous revision for all files in the changeset (for VC systems that support changesets). This is useful to see what the current line's revision actually changed in the tree.
-
l - Show the log of the current line's revision. This is useful to see the author's description of the changes in the revision on the current line.
-
w - Annotate the working revision—the one you are editing. If you used
pandnto browse to other revisions, use this key to return to your working revision. -
v - Toggle the annotation visibility. This is useful for looking just at the file contents without distraction from the annotations.
VC Change Log
-
C-x v l - Display the change history for the current fileset (
vc-print-log). -
C-x v L - Display the change history for the current repository (
vc-print-root-log). -
C-u 1 C-x v L revision RET - Display the log entry and changes (diffs) of a single revision (
vc-print-root-log). -
C-x v b l - Display the change history for the current fileset on another branch (
vc-print-fileset-branch-log). -
C-x v b L - Display the change history for the current repository on another branch (
vc-print-root-branch-log). -
C-x v I - Display log entries for the changes that a "pull" operation will retrieve (
vc-root-log-incoming). If you customizevc-use-incoming-outgoing-prefixesto non-nil,C-x v Ibecomes a prefix key, andvc-root-log-incomingbecomes bound toC-x v I L. -
M-x vc-root-diff-incoming - Display a diff of all changes that a pull operation will retrieve. If you customize
vc-use-incoming-outgoing-prefixesto non-nil, this command becomes available onC-x v I D. -
M-x vc-diff-incoming - Display a diff of changes that a pull operation will retrieve, but limited to the current fileset. If you customize
vc-use-incoming-outgoing-prefixesto non-nil, this command becomes available onC-x v I =. -
C-x v O - Display log entries for the changes that will be sent by the next "push" operation (
vc-root-log-outgoing). If you customizevc-use-incoming-outgoing-prefixesto non-nil,C-x v Obecomes a prefix key, andvc-root-log-outgoingbecomes bound toC-x v O L. -
M-x vc-root-diff-outgoing - Display a diff of all changes that will be sent by the next push operation. If you customize
vc-use-incoming-outgoing-prefixesto non-nil, this command is bound toC-x v O D. -
M-x vc-diff-outgoing - Display a diff of changes that will be sent by the next push operation, but limited to the current fileset. If you customize
vc-use-incoming-outgoing-prefixesto non-nil, this command becomes available onC-x v O =. -
C-x v E D - Display a combined diff of all changes that will be sent by the next push operation plus any uncommitted changes.
-
C-x v E = - Display a combined diff of all changes that will be sent by the next push operation plus any uncommitted changes, but limited to the current fileset.
-
C-x v h - Display the history of changes made in the region of file visited by the current buffer (
vc-region-history). -
M-x vc-log-search RET - Search the change history for a specified pattern.
C-x v l (vc-print-log) displays a buffer named *vc-change-log*, showing the history of changes made to the current fileset in the long form, including who made the changes, the dates, and the log entry for each change (these are the same log entries you would enter via the *vc-log* buffer; Log Buffer). If invoked from a buffer visiting a file, the current fileset consists of that single file, and point in the displayed *vc-change-log* buffer is centered at the revision of that file. If invoked from a VC Directory buffer (VC Directory Mode) or from a Dired buffer (Operating on Files), the fileset consists of all the marked files, defaulting to the file shown on the current line in the directory buffer if no file is marked. If the fileset includes one or more directories, the resulting *vc-change-log* buffer shows a short log of changes (one line for each change), if the VC backend supports that; otherwise it shows the log in the long form. With a prefix argument, the command prompts for the revision to center on in the *vc-change-log* buffer and for the maximum number of revisions to display. C-x v L (vc-print-root-log) displays a *vc-change-log* buffer showing the history of the entire version-controlled directory tree (RCS, SCCS, CVS, and SRC do not support this feature). With a prefix argument, the command prompts for the maximum number of revisions to display. A numeric prefix argument specifies the maximum number of revisions without prompting. If the numeric prefix argument is 1, as in C-1 C-x v L or C-u 1 C-x v L, the command prompts for the revision ID, and displays the log entry of that revision together with the changes (diffs) it introduced. (Some less capable version control systems, such as RCS and CVS, don't have commands to show a revision log with its diffs; for them the command displays only the log entry, and you can request to show the diffs by typing d or D, see below.) The C-x v L history is shown in a compact form, usually showing only the first line of each log entry. However, you can type RET (log-view-toggle-entry-display) in the *vc-change-log* buffer to reveal the entire log entry for the revision at point. A second RET hides it again. C-x v b l branch-name RET (vc-print-fileset-branch-log) displays a *vc-change-log* buffer showing the history of changes made to the current fileset in the long form, like vc-print-log does, but it shows the history of a branch other than the current one; it prompts for the name of the branch whose history you would like to see. C-x v b L /branch-name/ =RET= (vc-print-root-branch-log) is similar except that it shows the history of the version-controlled directory tree, like vc-print-root-log. For a version control system for which it makes sense, you can also specify a revision ID instead of the name of a branch as branch-name, and Emacs will print a log starting from that revision ID. You can also specify other names for specific revisions supported by the VCS, such as the names of tags (Revision Tags), or the remote branch references supported by Git. On a decentralized version control system, the C-x v I (vc-root-log-incoming) command displays a log buffer showing the changes that will be applied the next time you run the version control system's pull command to get new revisions from another remote location (Pulling / Pushing). This other remote location is the default one from which changes are pulled, as defined by the version control system; with a prefix argument, vc-root-log-incoming prompts for a particular remote location. Similarly, C-x v O (vc-root-log-outgoing) shows the changes that will be sent to another remote location, the next time you run the push command; with a prefix argument, it prompts for a particular destination that in case of some version control system can be a branch name. The closely related commands vc-root-diff-incoming and vc-root-diff-outgoing are the diff analogues of vc-root-log-incoming and vc-root-log-outgoing. These display diff buffers reporting the changes that would be pulled or pushed. You can use a prefix argument here too to specify a particular remote location. vc-root-diff-outgoing is useful as a way to preview your push and quickly check that all and only the changes you intended to include were committed and will be pushed. The commands vc-diff-incoming and vc-diff-outgoing are very similar. They also display changes that would be pulled or pushed. The difference is that the diffs reported are limited to the current fileset. Don't forget that actual pull and push operations always affect the whole working tree, not just the current fileset. Finally, there is also C-x v E D (vc-root-diff-outgoing-and-edited) which shows a combined diff of all changes that would be pushed plus any uncommitted changes. It is useful to show all work that's present only locally. There is also C-x v E = (vc-diff-outgoing-and-edited) which is the same but limited to the current fileset. In the *vc-change-log* buffer, you can use the following keys to move between the logs of revisions and of files, and to examine and compare past revisions (Old Revisions):
-
p - Move to the previous revision entry (
log-view-msg-prev). (Revision entries in the log buffer are usually in reverse-chronological order, so the previous revision-item usually corresponds to a newer revision.) A numeric prefix argument is a repeat count. -
n - Move to the next revision entry (
log-view-msg-next). A numeric prefix argument is a repeat count. -
a - Annotate the revision on the current line (
log-view-annotate-version; Old Revisions). -
e - Modify the change comment displayed at point (
log-view-modify-change-comment). Note that not all VC systems support modifying change comments. -
f - Visit the revision indicated at the current line (
log-view-find-revision). -
d - Display a diff between the revision at point and the next earlier revision, for the specific file (
log-view-diff). -
D - Display the changeset diff between the revision at point and the next earlier revision (
log-view-diff-changeset). This shows the changes to all files made in that revision. -
w - Copy to the kill ring (Kill Ring) the revision ID of the log entry at point, as if you had used
M-w(log-view-copy-revision-as-kill). If several revisions are marked, the command copies to the kill ring the IDs of all of them, separated by spaces. -
RET - In a compact-style log buffer (e.g., the one created by
C-x v L), toggle between showing and hiding the full log entry for the revision at point (log-view-toggle-entry-display). -
M-RET - Show the full log entry like
RETdoes, if relevant, and also display the diff likeDdoes, but without selecting the window showing the diff (log-view-display-entry-and-diff). Never hides the full log entry text if it is already shown. -
M-p - Like
pfollowed byM-RET: move to the previous entry, display it in full if relevant, and display its diff (log-view-msg-and-diff-prev). A numeric prefix argument is a repeat count for the movement part; at most one entry is displayed in full. -
M-n - Like
nfollowed byM-RET: move to the previous entry, display it in full if relevant, and display its diff (log-view-msg-and-diff-next). A numeric prefix argument is a repeat count for the movement part; at most one entry is displayed in full. -
m - Mark the entry at point (
log-view-mark-entry). -
u - Unmark the entry at point (
log-view-unmark-entry). -
U - Unmark all marked entries (
log-view-unmark-all-entries). -
C - Copy changes to a currently checked out branch; either the changes from the revision at point, or the changes from all marked revisions (
log-view-cherry-pick). -
R - Undo the effects of old revisions; either the revision at point, or all marked revisions (
log-view-revert-or-delete-revisions). -
x - Delete revisions newer than the revision at point from the current branch without touching the working tree (
log-view-uncommit-revisions-from-end). -
X - Delete revisions newer than the revision at point from the current branch (
log-view-delete-revisions-from-end).
Because fetching many log entries can be slow, the *vc-change-log* buffer displays no more than 2000 revisions by default. The variable vc-log-show-limit specifies this limit; if you set the value to zero, that removes the limit. You can also increase the number of revisions shown in an existing *vc-change-log* buffer by clicking on the Show 4X entries or Show unlimited entries buttons at the end of the buffer. However, RCS, SCCS, CVS, and SRC do not support this feature. A useful variant of examining history of changes is provided by the command vc-region-history (by default bound to C-x v h), which shows a *VC-history* buffer with the history of changes made in the region of the current buffer's file between point and the mark (Mark). The history of changes includes the commit log messages and also the changes themselves in the Diff format. Invoke this command after marking in the current buffer the region in whose changes you are interested. In the *VC-history* buffer it pops up, you can use all of the commands available in the *vc-change-log* buffer described above, and also the commands defined by Diff mode (Diff Mode). This command is currently available only with Git and Mercurial (hg). The command vc-log-search allows searching for a pattern in the log of changes. It prompts for a pattern (a regular expression), and displays all entries in the change history whose log messages match the pattern. When invoked with a prefix argument, the command will also prompt for a specific VCS shell command to run for this purpose.
Undoing Version Control Actions
-
C-x v u -
C-x v @@ - Revert the work file(s) in the current VC fileset to the last revision (
vc-revert). -
M-x vc-revert-or-delete-revision - Undo the effects of an older commit.
-
M-x vc-revert-revision - Make a new commit which undoes the changes made by an older one.
-
M-x vc-delete-revision - Delete an unpushed commit from the revision history.
If you want to discard all the changes you have made to the current VC fileset, type C-x v u or C-x v @@ (vc-revert). This will ask you for confirmation before discarding the changes. If you agree, the fileset is reverted. If vc-revert-show-diff is non-nil, this command will show you a diff between the work file(s) and the revision from which you started editing. Afterwards, the diff buffer will either be killed (if this variable is kill), or the buffer will be buried (any other non-nil value). If you don't want vc-revert to show you diffs, set this variable to nil (you can still view the diff directly with C-x v =; Old Revisions). On locking-based version control systems, vc-revert leaves files unlocked; you must lock again to resume editing. You can also use vc-revert to unlock a file if you lock it and then decide not to change it. To discard changes that have already been committed, by yourself or someone else, you can use M-x vc-revert-or-delete-revision. This is called reverting a commit. The command prompts for a revision to revert, and then the VC backend reverts it. Most backends implement this by making a new commit which undoes the changes made by the revision. For a distributed VCS, if the commit is one that you made and have not yet pushed, Emacs will offer to delete it entirely, instead. With a prefix argument, this command will only try to entirely delete the revision, failing if it has already been pushed. An alternative way to access this functionality is the log-view-revert-or-delete-revisions command, bound to R in Log View mode buffers (VC Change Log). Compared to using M-x vc-revision revert directly, this can make it easier to be sure you are reverting the revision you intend. More specific, specialized commands are M-x vc-revert-revision and M-x vc-delete-revision. The first of these prompts for a revision and then always makes a new commit which undoes the changes made by that revision, regardless of the VCS in use and whether or not the revision is pushed. The second command prompts for a revision and then always deletes it, though it will stop if the commit has been pushed. Usually vc-revert-or-delete-revision is sufficient, but vc-revert-revision and vc-delete-revision can sometimes be useful for constructing particular version control histories.
Ignore Version Control Files
-
C-x v G - Ignore a file under current version control system. (
vc-ignore).
Many source trees contain some files that do not need to be versioned, such as editor backups, object or bytecode files, and built programs. You can simply not add them, but then they'll always crop up as unknown files. You can also tell the version control system to ignore these files by adding them to the ignore file at the top of the tree. C-x v G (vc-ignore) can help you do this. When called with a prefix argument, you can remove a file from the ignored file list.
VC Directory Mode
The VC Directory buffer is a specialized buffer for viewing the version control statuses of the files in a directory tree, and performing version control operations on those files. In particular, it is used to specify multi-file VC filesets for commands like C-x v v to act on (VC Directory Commands). To use the VC Directory buffer, type C-x v d (vc-dir). This reads a directory's name using the minibuffer, and switches to a VC Directory buffer for that directory. By default, the buffer is named *vc-dir*. Its contents are described in VC Directory Buffer. The vc-dir command automatically detects the version control system to be used in the specified directory. In the event that more than one system is being used in the directory, you should invoke the command with a prefix argument, C-u C-x v d; this prompts for the version control system which the VC Directory buffer should use. In addition to the VC Directory buffer, Emacs has a similar facility called PCL-CVS which is specialized for CVS. About PCL-CVS. You can also invoke VC commands from Dired buffers (Dired). In that case, any VC command you invoke considers the marked files as the current fileset (Basic VC Editing), defaulting to the file on the current line if no files are marked.
The VC Directory Buffer
The VC Directory buffer contains a list of version-controlled files and their version control statuses. It lists files in the current directory (the one specified when you called C-x v d) and its subdirectories, but only those with a noteworthy status. Files that are up-to-date (i.e., the same as in the repository) or ignored are omitted. If all the files in a subdirectory are up-to-date, the subdirectory is not listed either. As an exception, if a file has become up-to-date as a direct result of a VC command, it is listed by default. Here is an example of a VC Directory buffer listing:
./
edited configure.ac
* added README
unregistered temp.txt
src/
* edited src/main.c
Two work files have been modified but not committed: configure.ac in the current directory, and main.c in the src/ subdirectory. The file named README has been added but is not yet committed, while temp.txt is not under version control (Registering). The * characters next to the entries for README and src/main.c indicate that the user has marked these files as the current VC fileset (VC Directory Commands). The above example is typical for a decentralized version control system like Bazaar, Git, or Mercurial (VCS Repositories). Other systems can show other statuses. For instance, CVS shows the needs-update status if the repository has changes that have not been applied to the work file. RCS and SCCS show the name of the user locking a file as its status. As mentioned above, by default files and directories which become up-to-date or ignored after the VC Directory buffer is first displayed stay displayed. To automatically remove such files from display, customize the variable vc-dir-auto-hide-up-to-date to the value t. You can also customize it to the value revert, in which case such files will be removed only when you refresh the VC Directory display, e.g., by typing g (VC Directory Commands). On CVS, the vc-dir command normally contacts the repository, which may be on a remote machine, to check for updates. If you change the variable vc-cvs-stay-local to nil (CVS Options), then Emacs avoids contacting a remote repository when generating the VC Directory buffer (it will still contact it when necessary, e.g., when doing a commit). This may be desirable if you are working offline or the network is slow. The VC Directory buffer omits subdirectories listed in the variable vc-directory-exclusion-list. Its default value contains directories that are used internally by version control systems. At the top of the buffer Emacs displays some information about the repository, such as the name of the backend in use and the working directory. In addition, for decentralized VCS, if you have outgoing commits (VC Change Log), Emacs displays a line "Outgoing : N unpushed revisions" where N is a number. You can click on this text to execute the vc-root-log-outgoing command (VC Change Log). Emacs tries to use cached information to determine the number of unpushed revisions, but for some backends this isn't possible. In these cases Emacs must occasionally fetch from the remote repository in order to determine the count. If your connection to the remote repository is slow then this may cause unacceptable slowdowns in refreshing the VC Directory buffer. If this affects you, you can customize vc-dir-show-outgoing-count to nil to disable the unpushed revisions count altogether. You can also set this on a per-repository basis using directory local variables (Directory Variables).
VC Directory Commands
Emacs provides several commands for navigating the VC Directory buffer, for marking files as belonging to the current VC fileset, and for operating on the VC fileset.
-
n,SPC - Move point to the next entry (
vc-dir-next-line). -
p - Move point to the previous entry (
vc-dir-previous-line). -
TAB - Move to the next directory entry (
vc-dir-next-directory). -
S-TAB - Move to the previous directory entry (
vc-dir-previous-directory). -
RET,f - Visit the file or directory listed on the current line (
vc-dir-find-file). -
o - Visit the file or directory on the current line, in a separate window (
vc-dir-find-file-other-window). -
m - Mark the file or directory on the current line (
vc-dir-mark), putting it in the current VC fileset. If the region is active, mark all files in the region. A file cannot be marked with this command if it is already in a marked directory, or one of its subdirectories. Similarly, a directory cannot be marked with this command if any file in its tree is marked. -
M - If point is on a file entry, mark all files with the same status; if point is on a directory entry, mark all files in that directory tree (
vc-dir-mark-all-files). With a prefix argument, mark all listed files and directories. -
% m,* % - You can use this command to mark files by regexp (
vc-dir-mark-by-regexp). If given a prefix, unmark files instead. -
* r - You can use this command to mark files that are in one of registered states, including edited, added or removed. (
vc-dir-mark-registered-files). -
G - Add the file under point to the list of files that the VC should ignore (
vc-dir-ignore). For instance, if the VC is Git, it will append this file to the.gitignorefile. If given a prefix, do this with all the marked files. -
@@ - Discard all the changes you have made to the current fileset (
vc-revert). -
V - Take the next logical version control operation on all files shown in the VC Directory buffer (
vc-dir-root-next-action). This is likeC-x v v(Basic VC Editing) except that it ignores any marks and the position of point. -
u - Unmark the file or directory on the current line. If the region is active, unmark all the files in the region (
vc-dir-unmark). -
U - If point is on a file entry, unmark all files with the same status; if point is on a directory entry, unmark all files in that directory tree (
vc-dir-unmark-all-files). With a prefix argument, unmark all files and directories. -
x - Hide files with
up-to-dateorignoredstatus (vc-dir-hide-up-to-date). With a prefix argument, hide items whose state is that of the item at point. -
g - Refresh the VC Directory buffer display (
revert-buffer). -
q - Quit the VC Directory buffer, and bury it (
quit-window).
While in the VC Directory buffer, all the files that you mark with m (vc-dir-mark) or M (vc-dir-mark-all-files) are in the current VC fileset. If you mark a directory entry with m, all the listed files in that directory tree are in the current VC fileset. The files and directories that belong to the current VC fileset are indicated with a * character in the VC Directory buffer, next to their VC status. In this way, you can set up a multi-file VC fileset to be acted on by VC commands like C-x v v (Basic VC Editing), C-x v = (Old Revisions), and C-x v u (VC Undo). The VC Directory buffer also defines some single-key shortcuts for VC commands with the C-x v prefix: =, +, l, i, D, L, G, I, O, and v. For example, you can commit a set of edited files by opening a VC Directory buffer, where the files are listed with the edited status; marking the files; and typing v or C-x v v (vc-next-action). If the version control system is changeset-based, Emacs will commit the files in a single revision. While in the VC Directory buffer, you can also perform search and replace on the current VC fileset, with the following commands:
-
S - Search the fileset (
vc-dir-search). -
Q - Do a regular expression query replace on the fileset (
vc-dir-query-replace-regexp). -
M-s a C-s - Do an incremental search on the fileset (
vc-dir-isearch). -
M-s a C-M-s - Do an incremental regular expression search on the fileset (
vc-dir-isearch-regexp).
Apart from acting on multiple files, these commands behave much like their single-buffer counterparts (Search). The VC Directory buffer additionally defines some branch-related commands starting with the prefix b:
-
b c - Create a new branch (
vc-create-branch). Creating Branches. -
b L - Prompt for the name of a branch and display the change history of that branch (
vc-print-root-branch-log). -
b s - Switch to a branch (
vc-switch-branch). Switching Branches. -
d - Delete the marked files, or the current file if no marks (
vc-dir-delete-file). If the files are registered, they will be marked as deleted in the version control system.
The above commands are also available via the menu bar, and via a context menu invoked by mouse-2. Furthermore, some VC backends use the menu to provide extra backend-specific commands. For example, Git and Bazaar allow you to manipulate stashes and shelves (which are a way to temporarily put aside uncommitted changes, and bring them back at a later time).
Version Control Branches
One use of version control is to support multiple independent lines of development, which are called branches. Amongst other things, branches can be used for maintaining separate stable and development versions of a program, and for developing unrelated features in isolation from one another. VC's support for branch operations is currently fairly limited. For decentralized version control systems, it provides commands for updating one branch with the contents of another, and for merging the changes made to two different branches (Merging). For centralized version control systems, it supports checking out different branches and committing into new or different branches.
Switching between Branches
The various version control systems differ in how branches are implemented, and these differences cannot be entirely concealed by VC. On some decentralized version control systems, including Bazaar and Mercurial in its normal mode of operation, each branch has its own working directory tree, so switching between branches just involves switching directories. On Git, branches are normally co-located in the same directory, and switching between branches is done using the git checkout command, which changes the contents of the working tree to match the branch you switch to. Bazaar also supports co-located branches, in which case the bzr switch command will switch branches in the current directory. With Subversion, you switch to another branch using the svn switch command. With Mercurial, command hg update is used to switch to another branch. The VC command to switch to another branch in the current directory is C-x v b s branch-name RET (vc-switch-branch). On centralized version control systems, you can also switch between branches by typing C-u C-x v v in an up-to-date work file (Advanced C-x v v), and entering the revision ID for a revision on another branch. On CVS, for instance, revisions on the trunk (the main line of development) normally have IDs of the form 1.1, 1.2, 1.3, …, while the first branch created from (say) revision 1.2 has revision IDs 1.2.1.1, 1.2.1.2, …, the second branch created from revision 1.2 has revision IDs 1.2.2.1, 1.2.2.2, …, and so forth. You can also specify the branch ID, which is a branch revision ID omitting its final component (e.g., 1.2.1), to switch to the latest revision on that branch. On a locking-based system, switching to a different branch also unlocks (write-protects) the working tree. Once you have switched to a branch, VC commands will apply to that branch until you switch away; for instance, any VC filesets that you commit will be committed to that specific branch.
Pulling/Pushing Changes into/from a Branch
-
C-x v P - With a decentralized version control system, update another repository with locally-committed changes from the current branch (a.k.a. push changes). This concept does not exist for centralized version control systems
-
C-x v + - With a decentralized version control system, update the current branch of the local repository by pulling in changes from another repository. With a centralized version control system, update the current VC fileset from the repository.
On a decentralized version control system, the command C-x v P (vc-push) updates another location, commonly known as the upstream repository, with locally-committed changes from the current branch. With a prefix argument, it prompts for the exact version control command to run, which lets you specify where to push changes; the default is bzr push with Bazaar, git push with Git, and hg push with Mercurial. The default commands always push to the repository in the default location determined by the version control system from your branch configuration. Prior to pushing, you can use C-x v O (vc-root-log-outgoing) to view a log buffer of the changes to be sent upstream. VC Change Log. This command is currently supported only by Bazaar, Git, and Mercurial. The concept of "pushing" does not exist for centralized version control systems, where this operation is a part of committing a changeset, so invoking this command on a centralized VCS signals an error. This command also signals an error when attempted in a Bazaar bound branch, where committing a changeset automatically pushes the changes to the remote repository to which the local branch is bound. With a decentralized version control system, the command C-x v + (vc-pull) updates the current branch of the local repository and it working tree with changes made in the upstream repository. It is typically used to update a copy (a.k.a. clone) of a remote branch. If you supply a prefix argument, the command prompts for the exact version control command to use, which lets you specify where to pull changes from. Otherwise, it pulls from the repository in the default location determined by the version control system from your branch configuration. Amongst decentralized version control systems, C-x v + is currently supported only by Bazaar, Git, and Mercurial. With Bazaar, it calls bzr pull for ordinary branches (to pull from a master branch into a mirroring branch), and bzr update for a bound branch (to pull from a central repository). With Git, it calls git pull to fetch changes from a remote repository and merge it into the current branch. With Mercurial, it calls hg pull -u to fetch changesets from the default remote repository and update the working directory. Prior to pulling, you can use C-x v I (vc-root-log-incoming) to view a log buffer of the changes to be applied. VC Change Log. With a centralized version control system like CVS, C-x v + updates the current VC fileset from the repository.
Merging Branches
-
C-x v m - With a decentralized version control system, merge changes from another branch into the current one. With a centralized version control system, merge changes from another branch into the current VC fileset.
While developing a branch, you may sometimes need to merge in changes that have already been made in another branch. This is not a trivial operation, as overlapping and conflicting changes may have been made to the two branches. With a decentralized version control system, you merge changes with the command C-x v m (vc-merge). With Bazaar, this prompts for the exact arguments to pass to the bzr merge command, offering a sensible default if possible. With Git, this prompts for the name of a branch to merge from, with completion (based on the branch names known to the current repository). With Mercurial, this prompts for argument to pass to hg merge. The output from running the merge command is shown in a separate buffer. With a centralized version control system like CVS, C-x v m prompts for a branch ID, or a pair of revision IDs (Switching Branches); then it finds the changes from that branch, or the changes between the two revisions you specified, and merges those changes into the current VC fileset. If you just type RET at the prompt, Emacs simply merges any changes that were made on the same branch since you checked the file out. Immediately after performing a merge, only the working tree is modified, and you can review the changes produced by the merge with C-x v D and related commands (Old Revisions). If the two branches contained overlapping changes, merging produces a conflict; a warning appears in the output of the merge command, and conflict markers are inserted into each affected work file, surrounding the two sets of conflicting changes. You must then resolve the conflict by editing the conflicted files; by default, Emacs will place buffers with VC conflicts in the special Smerge mode, which provides special commands for resolving the merge conflicts. Once you are done with resolving the conflicts and have saved the files with resolved conflicts, those files must be committed in the usual way for the merge to take effect (Basic VC Editing).
Creating New Branches
On centralized version control systems like CVS, Emacs supports creating new branches as part of a commit operation. When committing a modified VC fileset, type C-u C-x v v (vc-next-action with a prefix argument; Advanced C-x v v). Then Emacs prompts for a revision ID for the new revision. You should specify a suitable branch ID for a branch starting at the current revision. For example, if the current revision is 2.5, the branch ID should be 2.5.1, 2.5.2, and so on, depending on the number of existing branches at that point. This procedure will not work for distributed version control systems like Git or Mercurial. For those systems you should use the command vc-create-branch (C-x v b c branch-name RET) instead. To create a new branch at an older revision (one that is no longer the head of a branch), first select that revision (Switching Branches). Your procedure will then differ depending on whether you are using a locking or merging-based VCS. On a locking VCS, you will need to lock the old revision branch with C-x v v. You'll be asked to confirm, when you lock the old revision, that you really mean to create a new branch—if you say no, you'll be offered a chance to lock the latest revision instead. On a merging-based VCS you will skip this step. Then make your changes and type C-x v v again to commit a new revision. This creates a new branch starting from the selected revision. After the branch is created, subsequent commits create new revisions on that branch. To leave the branch, you must explicitly select a different revision with C-u C-x v v.
Copying Changes Made By Revisions Between Branches
-
M-x vc-cherry-pick - Copy a single revision to branch checked out in this working tree.
Sometimes it is useful to copy a revision from one branch to another. This means creating a new revision with the same changes, log message and authorship information as an existing revision that can be found on another branch. This is often called cherry-picking the revision from one branch to another. The most common case is copying a revision from a branch that won't be merged (Merging) into your current branch. For example, your project might have a feature-frozen branch that accepts only bug fixes. Someone (possibly you) fixes a bug on the main development branch. You can then cherry-pick that revision onto the feature-frozen branch in order to fix the bug there, too. This is called backporting the revision, or backporting the fix. You can use the command M-x vc-cherry-pick to cherry-pick revisions. It prompts for a revision to cherry-pick. It then pops up a buffer for you to edit the log message for the new revision. Normally the VC backend generates a log message including a reference to the revision you want to copy, so that the copy can be traced. If you wish, you can delete this reference before typing C-c C-c to conclude the cherry-pick. Alternatively you can invoke the command with a prefix argument, i.e. C-u M-x vc-cherry-pick. In this case the log message from the source revision is used unmodified, and the cherry-pick happens immediately, without popping up a buffer for log message edits. An alternative way to access this functionality is the log-view-cherry-pick command, bound to C in Log View mode buffers (VC Change Log). Compared to using M-x vc-cherry-pick directly, this can make it easier to be sure you are cherry-picking the revision you intend.
Miscellaneous Commands and Features of VC
This section explains the less-frequently-used features of VC.
Change Logs and VC
If you use RCS or CVS for a program with a ChangeLog file (Change Log), you can generate change log entries from the version control log entries of previous commits. Note that this only works with RCS or CVS. This procedure would be particularly incorrect on a modern changeset-based version control system, where changes to the ChangeLog file would normally be committed as part of a changeset. In that case, you should write the change log entries first, then pull them into the *vc-log* buffer when you commit (Log Buffer).
-
C-x v a - Visit the current directory's
ChangeLogfile and, for registered files in that directory, create new entries for versions committed since the most recent change log entry (vc-update-change-log). -
C-u C-x v a - As above, but only find entries for the current buffer's file.
For example, suppose the first line of ChangeLog is dated 1999-04-10, and that the only check-in since then was by Nathaniel Bowditch to rcs2log on 1999-05-22 with log entry Ignore log messages that start with '#'.. Then C-x v a inserts this ChangeLog entry:
1999-05-22 Nathaniel Bowditch <nat@@apn.org>
* rcs2log: Ignore log messages that start with '#'.
If the version control log entry specifies a function name (in parenthesis at the beginning of a line), that is reflected in the ChangeLog entry. For example, if a log entry for vc.el is (vc-do-command): Check call-process status., the ChangeLog entry is:
1999-05-06 Nathaniel Bowditch <nat@@apn.org>
* vc.el (vc-do-command): Check call-process status.
When C-x v a adds several change log entries at once, it groups related log entries together if they all are checked in by the same author at nearly the same time. If the log entries for several such files all have the same text, it coalesces them into a single entry.
Deleting and Renaming Version-Controlled Files
-
C-x v x - Prompt for a file name, delete the file from the working tree, and schedule the deletion for committing.
-
C-x v R - Prompt for two file names, old and new, rename them in the working tree, and schedule the renaming for committing. The old file defaults to the current buffer's file name if it is under VC.
If you wish to delete a version-controlled file, type C-x v x (vc-delete-file). This prompts for the file name, and deletes it via the version control system. The file is removed from the working tree, and in the VC Directory buffer (VC Directory Mode), it is displayed with the removed status. When you commit it, the deletion takes effect in the repository. To rename a version-controlled file, type C-x v R (vc-rename-file). This prompts for two arguments: the name of the file you wish to rename, and the new name; then it performs the renaming via the version control system. The renaming takes effect immediately in the working tree, and takes effect in the repository when you commit the renamed file. On modern version control systems that have built-in support for renaming, the renamed file retains the full change history of the original file. On CVS and older version control systems, the vc-rename-file command actually works by creating a copy of the old file under the new name, registering it, and deleting the old file. In this case, the change history is not preserved.
Merge Bases
-
C-x v M D - Report diffs of changes on a branch since it diverged from another (
vc-diff-mergebase). -
C-x v M L - Display log messages for revisions on a branch since it diverged from another (
vc-log-mergebase).
The merge base of two branches is the most recent revision that exists on both branches. If neither of the branches was ever merged into the other (Merging), then the merge base is the revision that the older of the two branches was at when the newer branch was created from it (Creating Branches). If one of the branches was ever merged into the other, then the merge base is the most recent merge point. The commands described in this section are currently implemented only for decentralized version control systems (VCS Repositories). Merge bases are useful to make certain comparisons between branches, and Emacs provides two commands for doing so. Each of C-x v M D (vc-diff-mergebase) and C-x v M L (vc-log-mergebase) prompts for two branches, finds their merge base, and then compares that merge base with the second of the two branches. The commands report diffs and display change history, respectively. The typical use case for these commands is when one of the branches was originally created from the other and you or a collaborator have made merges of one of the branches into the other at least once. Then you can use these commands to see what changes on one branch have not yet been merged into the other. Call the branch which has the changes you are interested in the "source branch" and the branch into which these changes have not yet been merged the "target branch". Specify the target branch when prompted for the "older revision" and the source branch when prompted for the "newer revision".(The concept of merge bases generalizes from branches to any two revisions. The merge base of two revisions is the most recent revision that can be found in the revision history of both of the two revisions. C-x v M D and C-x v M L accept any two revisions) Then C-x v M D shows you a preview of what would change on the target branch if you were to merge the source branch into it, and C-x v M L shows you a log of the changes on the source branch not yet merged into the target branch.
Commands to see all unintegrated changes
-
C-x v T = - Display diffs of changes to the VC fileset since the merge base of this branch and its upstream counterpart (
vc-diff-unintegrated). -
C-x v T D - Display a diff of all changes since the merge base of this branch and its upstream counterpart (
vc-root-diff-unintegrated). -
C-x v T l - Display log messages for changes to the VC fileset since the merge base of this branch and its upstream counterpart (
vc-log-unintegrated). -
C-x v T L - Display log messages for all changes since the merge base of this branch and its upstream counterpart (
vc-root-log-unintegrated). -
C-x v T R = - Display diffs of remote changes to the VC fileset since the merge base of this topic branch and its upstream counterpart (
vc-diff-remote-unintegrated). -
C-x v T R D - Display a diff of all remote changes since the merge base of this topic branch and its upstream counterpart (
vc-root-diff-remote-unintegrated). -
C-x v T R l - Display log messages for remote changes to the VC fileset since the merge base of this topic branch and its upstream counterpart (
vc-log-remote-unintegrated). -
C-x v T R L - Display log messages for all remote changes since the merge base of this topic branch and its upstream counterpart (
vc-root-log-remote-unintegrated).
For decentralized version control systems (VCS Repositories), these commands provide specialized versions of C-x v M L and C-x v M D (see Merge Bases) which also take into account the state of upstream repositories. These commands are useful both when working on a single branch and when developing features on a separate branch (Branches). These two cases are conceptually distinct, and so we will introduce them separately. First, consider working on a single branch. Unintegrated changes are those which you haven't yet pushed upstream. This includes both unpushed commits and uncommitted changes in your working tree. In many cases the reason these changes are not pushed yet is that they are not finished: the changes committed so far don't make sense in isolation. Type C-x v T D (vc-root-diff-unintegrated) to display a summary of all these changes, committed and uncommitted. This summary is in the form of a diff of what committing and pushing (Pulling / Pushing) all these changes would do to the upstream repository. You can use C-x v T = (vc-diff-unintegrated) instead to limit the display of changes to the current VC fileset. (The difference between C-x v T D and C-x v T = is like the difference between C-x v D and C-x v = (Old Revisions).)(Another point of comparison is that these commands are like C-x v O = (vc-fileset-diff-outgoing) and C-x v O D (vc-root-diff-outgoing) except that they include uncommitted changes in the reported diffs. Like those other commands) Type C-x v T L (vc-root-log-unintegrated) to display a summary of the same changes in the form of a revision log; this does not include uncommitted changes. You can use C-x v T l (vc-log-unintegrated) instead to limit the display of changes to the current VC fileset. Second, consider developing a feature on a separate branch. Call this the topic branch,(What we mean by a topic branch is any shorter-lived branch used for work which will later be merged into a longer-lived branch. Topic branches are sometimes called "feature branches". It is also common for the term "feature branch" to be reserved for a particular kind of topic branch) and call the branch from which the topic branch was originally created the trunk or development trunk. In this case, unintegrated changes is a more specific notion than just unpushed and uncommitted changes on the topic branch. You're not finished sharing changes with your collaborators until they have been merged into the trunk, and pushed. Therefore, in this example, unintegrated changes are those which haven't yet been included in the upstream repository's development trunk. That means committed changes on the topic branch that haven't yet been merged into the trunk, plus uncommitted changes. When the current branch is a topic branch and you type C-x v T D, Emacs displays a summary of all the changes that are outstanding against the trunk to which the current branch will be merged. This summary is in the form of a diff of what committing and pushing all the changes, and subsequently merging the topic branch, would do to the trunk. As above, you can use C-x v T = instead to limit the display of changes to the current VC fileset. C-x v T L and C-x v T l show the corresponding revision logs, excluding uncommitted changes as above. On topic branches, it is sometimes also useful to see the same information but for the remote repository's version of the topic branch. This is the outstanding work on the topic branch that has been pushed, but not yet merged. It is visible to your collaborators but is otherwise still unintegrated. We call such work remote unintegrated changes. There is a command corresponding to each of the four commands discussed so far but which operates on the remote repository's version of the current topic branch: C-x v R T = (vc-diff-remote-unintegrated), C-x v R T D (vc-root-diff-remote-unintegrated), C-x v R T l (vc-log-remote-unintegrated), and C-x v R T L (vc-root-log-remote-unintegrated). All this functionality relies on Emacs correctly detecting whether the current branch is a trunk or a topic branch, and in the latter case, correctly determining the branch to which the topic branch will eventually be merged. If the autodetection doesn't produce the right results, there are several options to tweak and override it. The variables vc-trunk-branch-regexps and vc-topic-branch-regexps contain lists of regular expressions matching the names of branches that should always be considered trunk and topic branches, respectively. You can also specify prefix arguments to C-x v T .... Here is a summary of how to use these controls:
- If the problem is that Emacs thinks your topic branch is a trunk, you can add either its name, or a regular expression matching its name (Regexps), to the
vc-topic-branch-regexpsvariable. There are a few special kinds of value to simplify common use cases: - If an element contains no characters that are special in regular expressions, then the regular expression is implictly anchored at both ends, i.e., it matches only a branch with exactly that name.
- If the first element of
vc-topic-branch-regexpsis the symbolnot, then the meaning ofvc-topic-branch-regexpsis inverted, in that Emacs treats all branches whose names don't match any element ofvc-topic-branch-regexpsto be topic branches. - If instead of a list of regular expressions the
vc-topic-branch-regexpsvariable has the special valuet, then Emacs treats as a topic branch any branch that thevc-trunk-branch-regexpsvariable doesn't positively identify as a trunk. Directory Variables, regarding how to specify values ofvc-topic-branch-regexpsandvc-trunk-branch-regexpsfor a single VC repository. - If the problem is that Emacs thinks your trunk is a topic branch, you can add either its name, or a regular expression matching its name, to the
vc-trunk-branch-regexpsvariable. This works just likevc-topic-branch-regexpswith the same special values we just described. E.g., if the value ofvc-trunk-branch-regexpsist, Emacs treats as a trunk any branch that thevc-topic-branch-regexpsvariable doesn't identify as a topic branch. - Supply a double prefix argument, i.e.
C-u C-u C-x v T ..., and Emacs will treat the current branch as a trunk, no matter what. This is useful when you simply want to obtain a diff of all outgoing changes (VC Change Log) plus uncommitted changes. - Finally, you can take full manual control by supplying a single prefix argument, i.e.
C-u C-x v T .... Emacs will prompt you for the outgoing base, which is the upstream location for which the changes are destined once they are no longer outstanding. To treat the current branch as a trunk specify a reference to the upstream version of the current branch, to which you and your collaborators push finished work. To treat the current branch as a topic branch specify a reference to the upstream version of the trunk to which the topic branch will later be merged. Exactly how to specify a reference to the upstream version of a branch depends on the version control system in use. For example, with Git, to refer to the upstream version of a branch foo, you would supplyorigin/foo. So if foo is the current branch then you would enter an outgoing base oforigin/footo treat foo as a trunk, or an outgoing base oforigin/barto treat foo as a topic branch which will later be merged into a trunk named bar. If there is a default option, it is what Emacs thinks you need to enter in order to treat the current branch as a topic branch. If there is no default, then entering nothing at the prompt means to treat the current branch as a trunk.
Multiple Working Trees for One Repository
Some VCS support more than one working tree with the same backing repository or revisions store. This means that you can have different revisions or branches (Branches) checked out simultaneously, in different working trees, but with all revision history, branches, tags and other metadata shared. Suppose your project has a trunk where you're developing the new version 3 of your software, and a stable release branch from which you make point releases of version 2. Someone sends you a patch fixing a bug that's present in version 2. Your main working tree has version 3 checked out, and you're in the middle of a big refactor that you don't want to disturb. So you type C-x v w c (see below) and create a new working tree, following the prompts to check out the version 2 branch there. You apply the patch to that working tree using C-x v w a (see below), build and test it. Satisfied, you use C-x v P (Pulling / Pushing) in the other working tree. In the course of testing the patch, you've realized that the bug exists in version 3 of the software, too. So you switch back to your first working tree, and use C-x v m (Merging) to merge the branch you have checked out in the other working tree. Now your version of the trunk has all of version 2's fixes merged into it, but you haven't pushed it yet because you're still refactoring. You'll use C-x v P later. Ordinary VC commands like C-x v v (Basic VC Editing) and C-x v d (VC Directory Mode) don't work any differently when there exist other working trees, except that the commits, branches and other VC artifacts they create will be visible from all working trees. Another way to put this is that any action taken in any working tree which creates new artifacts in the VCS backing store will be visible from other working trees, but actions which only affect workfiles won't be. So if you apply a patch to some workfiles in one working tree, that only affects that working tree. But if you commit the changes made by applying the patch, then that creates a new revision in the backing store, and so this action affects other working trees in the sense that their view of the repository's history will now have an additional commit in it. The following special commands let you switch between and modify different working trees. It is an error to use them other than from within a VC working tree; that is, from a buffer visiting a VCS-controlled file, or otherwise from a buffer whose default-directory (File Names) is within a VC working tree.
-
C-x v w c - Add a new working tree.
-
C-x v w w - Visit this file or directory in another working tree.
-
C-x v w k - Kill buffers visiting this file in other working trees.
-
C-x v w s - Invoke
C-x p p(project-switch-project) but limited to other working trees. -
C-x v w a - Copy or move fileset changes to another working tree.
-
C-x v w A - Copy or move all changes to another working tree.
-
C-x v w x - Delete a working tree you no longer need.
-
C-x v w R - Relocate a working tree to another file name.
You can start using multiple working trees by using the command C-x v w c (vc-add-working-tree) to create a new working tree. This prompts you to specify a destination directory, which identifies the working tree, and which will hold the new set of workfiles. Different VCS have different rules about what may and must be checked out in other working trees, so there may be additional prompts depending on the VCS in use. For example, Git requires that each branch be checked out in only one working tree at a time, so when using Git, Emacs will also prompt you for the name of the branch to be checked out in the new working tree. Once your repository has other working trees, you can use the command C-x v w w (vc-switch-working-tree) to switch between them. It tries to find the analogue of the current buffer's file or directory under another working tree. Typically the sets of workfiles under different working trees differ more in file contents than in which files do and do not exist. In other words, the file or directory the current buffer visits probably exists in other working trees too, and this command lets you switch to those versions of the file. C-x v w w also works in Diff mode (Diff Mode) and Log View mode (VC Change Log). Instead of switching to a different buffer, the command changes the default directory of the buffer to the corresponding directory under another working tree. This is particularly useful from Log View mode buffers generated by commands like C-x v L (VC Change Log). After using C-x v w w to change the default directory of the Log View buffer, you can move point to a revision of interest and type = (log-view-diff) to open a Diff mode buffer with that revision's changes. Then you can use standard Diff mode commands like C-c C-a (diff-apply-hunk) to apply hunks to the other working tree. After using C-x v w w in file-visiting buffers you will have multiple buffers visiting identically named files (Uniquify). You can kill all but one of these buffers by typing C-x v w k (vc-kill-other-working-tree-buffers). This command kills buffers visiting versions of the current buffer's file in other working trees, preserving the current buffer. It does not work in non-file-visiting buffers. An alternative way to switch between working trees is C-x v w s (vc-working-tree-switch-project). This prompts you to select a working tree, and then displays a menu of commands to operate on it. This is in fact just C-x p p (project-switch-project) (Switching Projects) but with the selection of projects limited to other working trees. The main difference between C-x v w w and C-x v w s is that the former looks for an analogue of the current buffer in the other working tree while the latter considers the other working tree as a whole, independent project. The command C-x v w a (vc-apply-to-other-working-tree) prompts you to select another working tree, then copies changes from the current working tree to that other working tree. With a prefix argument, it moves changes instead of just copying them. Usually the command operates on local (uncommitted) changes to the current VC fileset. When invoked in a buffer under Diff mode (Diff Mode), it operates on the changes specified by the contents of that buffer. The command stops and does nothing if any of the changes don't apply to the target working tree. C-x v w a is useful to copy changes to a temporary working tree in order to test them. It is also useful to copy fixes back to your main working tree for checking in. For example, you might hack away at a bug in a temporary working tree, and fix it. You'd then want to copy or move the fix back to your main working tree to check it in and push it. The command C-x v w A works similarly, except that it always copies or moves all local changes to the whole working tree, not just changes to the current VC fileset or changes represented by the contents of a Diff mode buffer. With two prefix arguments, this command shows a preview of changes to be copied, leaving you to apply them using standard Diff mode commands like C-c C-a and C-c <RET> a (Diff Mode). (C-u C-u C-x v w A is roughly equivalent to typing C-x v D followed by C-x v w w.) The commands C-x v w x (vc-delete-working-tree) and C-x v w R (vc-move-working-tree) are for performing maintenance tasks on other working trees, letting you delete, move and rename them. Deleting other working trees is particular useful because a common use for multiple working trees is to create throwaway copies of the repository to quickly test changes, without interfering with any work-in-progress you may have in your primary working trees.
Inserting Version Control Headers
On Subversion, CVS, RCS, and SCCS, you can put certain special strings called version headers into a work file. When the file is committed, the version control system automatically puts the revision number, the name of the user who made the commit, and other relevant information into the version header. VC does not normally use the information in the version headers. As an exception, when using RCS, Emacs uses the version header, if there is one, to determine the file version, since it is often more reliable than the RCS master file. To inhibit using the version header this way, change the variable vc-consult-headers to nil. VC then always uses the file permissions (if it is supposed to trust them), or else checks the master file. To insert a suitable header string into the current buffer, use the command M-x vc-insert-headers. This command works only on Subversion, CVS, RCS, and SCCS. The variable vc-backend-header contains the list of keywords to insert into the version header; for instance, CVS uses vc-cvs-header, whose default value is '("\$Id\$") (Keyword substitution). (The extra backslashes prevent the string constant from being interpreted as a header, if the Emacs Lisp file defining it is maintained with version control.) The vc-insert-headers command inserts each keyword in the list on a new line at point, surrounded by tabs, and inside comment delimiters if necessary. The variable vc-static-header-alist specifies further strings to add based on the name of the buffer. Its value should be a list of elements of the form (regexp . format). Whenever regexp matches the buffer name, format is also inserted as part of the version header. A %s in format is replaced with the file's version control type.
Editing VC Commands
You can use the C-x v ! (vc-edit-next-command) prefix command to edit the shell command line that VC is about to run. This is primarily intended to make it possible to add optional command-line arguments to VCS commands without unnecessary complications of the VC command set and its interfaces with the backend. For example, Git can produce logs of more than one branch, but C-x v b L (vc-print-root-branch-log) prompts for the name of just one branch. To obtain a log of more than one branch, you can type C-x v ! C-x v b L and then append the names of additional branches to the end of the git log command that VC is about to run.
Preparing Patches
When collaborating on projects it is common to send patches via email, to share changes. You can do this using VC with the vc-prepare-patch command. This will prompt you for the revisions you wish to share, and which destination email address(es) to use. Separate the revisions using the value of crm-separator, commas by default. The command will then prepare those revisions using your @abbr{MUA, Mail User Agent} for you to review and send. When invoked interactively in a Log View buffer with marked revisions, those marked revisions will be used. Depending on the value of the user option vc-prepare-patches-separately, vc-prepare-patch will generate one or more messages. The default value t means prepare and display a message for each revision, one after another. A value of nil means to generate a single message with all patches attached in the body. If you expect to contribute patches on a regular basis, you can set the user option vc-default-patch-addressee to the address(es) you wish to use. This will be used as the default value when invoking vc-prepare-patch. Project maintainers may consider setting this as a directory local variable (Directory Variables).
Auto-Reverting Buffers That Visit Tracked Files
When Emacs executes VCS operations that it knows may change the contents of tracked files, it reverts buffers visiting those files (Reverting). It does this in a VCS-aware fashion that retains the positions of point and the mark even when the VCS operation causes VCS keywords to be expanded (Version Headers). An important limitation of this feature is that Emacs won't know to revert buffers when you execute additional VCS operations outside of Emacs, such as at a shell prompt, or by means of scripts. If you regularly do this, and you don't use a VCS with keyword expansion (all modern VCS, absent special configuration), you may wish to enable vc-auto-revert-mode instead, by customizing that variable to a non-nil value. This mode is just like global-auto-revert-mode (Auto Revert) except limited to files visiting VCS-tracked files. It ensures that Emacs will always revert buffers when VCS operations change their contents, regardless of whether Emacs initiated those operations. VC Mode Line, for details regarding Auto Revert mode in buffers visiting tracked files (which is what vc-auto-revert-mode enables).
Rewinding Branches
-
M-x vc-delete-revisions-from-end - Delete revisions from the end of the current branch.
-
M-x vc-uncommit-revisions-from-end - Delete revisions from the end of the current branch without touching the working tree.
For decentralized version control systems (VCS Repositories), these commands provide ways to move the current branch back to an earlier revision. vc-delete-revisions-from-end prompts for a revision, then removes all revisions from the end of the branch up to but not including the specified revision. We say that the branch is rewound back to the specified revision. This command removes the changes made by the revisions from the working tree. Therefore, if there are any uncommitted changes, they must be reverted, first (VC Undo). This command will prompt you to do that if necessary. If you supply a prefix argument, Emacs will delete uncommitted changes without prompting. To "uncommit" a revision means to remove it from the revision history without removing its changes from the working tree. It is as though you had made the changes but had not yet checked them in. The command vc-uncommit-revisions-from-end prompts for a revision, and then uncommits all revisions from the end of the branch up to but not including the specified revision. The branch is rewound back to the specified revision but the changes are left behind in the working tree. When rewinding the current branch, if all the revisions deleted from the revision history are among those you have pulled or pushed, then these operations do not permanently delete anything: a simple C-x v + (Pulling / Pushing) will bring the revisions back. On the other hand, if there are new revisions on the end of the branch that have not yet been pushed, then these commands will delete them permanently. Emacs tries to detect this situation and ask you if you are sure you want to delete them. Alternative ways to access this functionality are the log-view-uncommit-revisions-from-end and log-view-delete-revisions-from-end commands, bound to x and X, respectively, in Log View mode buffers (VC Change Log). Compared to using the commands described here directly, the Log View mode commands can make it easier to be sure you are rewinding back to the revision you intend.
Customizing VC
The variable vc-handled-backends determines which version control systems VC should handle. The default value is (RCS CVS SVN SCCS SRC Bzr Git Hg), so it contains all the version systems that are currently supported. If you want VC to ignore one or more of these systems, exclude its name from the list. To disable VC entirely, set this variable to nil. The order of systems in the list is significant: when you visit a file registered in more than one system, VC uses the system that comes first in vc-handled-backends by default. The order is also significant when you register a file for the first time (Registering).
General Options
Emacs normally does not save backup files for source files that are maintained with version control. If you want to make backup files even for files that use version control, set the variable vc-make-backup-files to a non-nil value. Editing a version-controlled file through a symbolic link may cause unexpected results, if you are unaware that the underlying file is version-controlled. The variable vc-follow-symlinks controls what Emacs does if you try to visit a symbolic link pointing to a version-controlled file. If the value is ask (the default), Emacs asks for confirmation. If it is nil, Emacs just displays a warning message. If it is t, Emacs automatically follows the link and visits the real file instead. If vc-suppress-confirm is non-nil, then C-x v v and C-x v i can save the current buffer without asking, and C-x v u also operates without asking for confirmation. VC mode does much of its work by running the shell commands for the appropriate version control system. If vc-command-messages has the value log, VC logs messages to the *Messages* buffer to indicate which shell commands it runs, and logs additional messages when the commands finish. If the variable has any other non-nil value, Emacs both logs and displays these messages. VC mode runs certain shell commands asynchronously, allowing you to continue to use Emacs for other purposes while the command completes. This is mostly used for commands which access the network, such as pulling and pushing for distributed VCS (Pulling / Pushing). When the command starts, VC displays a buffer into which the commands output will be written. If vc-display-failed-async-commands is non-nil, VC will additionally ensure that this buffer is displayed when the command finishes running but failed. This means you can freely close the window displaying the command's buffer and know that it'll pop up again in the case that running the command failed. Normally checkin operations are done synchronously; that is, Emacs waits until the checkin has completed before doing anything else. This can be inconvenient for repositories in which the checkin operation is slow, such as Git repositories where you check in changes to very large files, or Mercurial repositories with a very large number of files. For those backends which support it, setting vc-async-checkin to non-nil switches to doing checkin operations asynchronously. This is particularly useful as a directory local variable in repositories where checkin operations are slow (Directory Local Variables). While an asynchronous checkin operation is in progress, if you use C-x C-s to save a buffer visiting any file within the current VC tree, then the operation reverts to a synchronous checkin and Emacs waits for it to complete before saving the buffer. This is to avoid nondeterminism regarding exactly what changes get checked in.
Options for RCS and SCCS
By default, RCS uses locking to coordinate the activities of several users, but there is a mode called non-strict locking in which you can check-in changes without locking the file first. Use rcs -U to switch to non-strict locking for a particular file, see the rcs manual page for details. When deducing the version control state of an RCS file, VC first looks for an RCS version header string in the file (Version Headers). If there is no header string, VC normally looks at the file permissions of the work file; this is fast. But there might be situations when the file permissions cannot be trusted. In this case the master file has to be consulted, which is rather expensive. Also the master file can only tell you if there's any lock on the file, but not whether your work file really contains that locked version. You can tell VC not to use version headers to determine the file status by setting vc-consult-headers to nil. VC then always uses the file permissions (if it is supposed to trust them), or else checks the master file. VC determines the version control state of files under SCCS much as with RCS. It does not consider SCCS version headers, though. Thus, the variable vc-consult-headers does not affect SCCS use.
Options specific for CVS
You can specify additional command line options to pass to all CVS operations in the variable vc-cvs-global-switches. These switches are inserted immediately after the cvs command, before the name of the operation to invoke. When using a CVS repository on a remote machine, VC can try keeping network interactions to a minimum. This is controlled by the variable vc-cvs-stay-local. If vc-cvs-stay-local is only-file (the default), VC determines the version control status of each file using only the entry in the local CVS subdirectory and the information returned by previous CVS commands. As a consequence, if you have modified a file and somebody else has checked in other changes, you will not be notified of the conflict until you try to commit. If you change vc-cvs-stay-local to nil, VC queries the remote repository before it decides what to do in vc-next-action (C-x v v), just as it does for local repositories. You can also set vc-cvs-stay-local to a regular expression that is matched against the repository host name; VC then stays local only for repositories from hosts that match the pattern. When using a remote repository, Emacs normally makes automatic version backups of the original versions of each edited file. These local backups are made whenever you save the first changes to a file, and they are removed after you commit your changes to the repository. (Note that these are not the same as ordinary Emacs backup files; Backup.) Commands like C-x v = and C-x v u make use of automatic version backups, if possible, to avoid having to access the network. Setting vc-cvs-stay-local to nil disables the making of automatic version backups. Automatic version backups have names of the form file.~version.~. This is similar to the name that C-x v ~ saves old versions to (Old Revisions), except for the additional dot (.) after the version. The relevant VC commands can use both kinds of version backups. The main difference is that the manual version backups made by C-x v ~ are not deleted automatically when you commit. CVS does not use locking by default, but there are ways to enable locking-like behavior using its CVSREAD or watch feature; see the CVS documentation for details. If that case, you can use C-x v v in Emacs to toggle locking, as you would for a locking-based version control system (VC With A Locking VCS).
Working with Projects
A project is a collection of files used for producing one or more programs. Files that belong to a project are typically stored in a hierarchy of directories; the top-level directory of the hierarchy is known as the project root. Whether a given directory is a root of some project is determined by the project-specific infrastructure, known as project backend. Emacs currently supports two such backends: VC-aware (Version Control), whereby a VCS repository is considered a project; and EDE (EDE). This is expected to be extended in the future to support additional types of projects. Which files do or don't belong to a project is also determined by the project backend. For example, the VC-aware backend doesn't consider "ignored" files (VC Ignore) to be part of the project. See its entry below for description and related options. @defopt project-mode-line If this user option is non-nil, Emacs displays the name of the current project (if any) on the mode line; clicking mouse-1 on the project name pops up the menu with the project-related commands. The default value is nil. If the value is non-remote, Emacs will show the name of the project only for local files; this comes in handy when updating the mode line for projects on remote systems is slow due to network latencies. @end defopt
Project Commands That Operate on Files
-
C-x p f - Visit a file that belongs to the current project (
project-find-file). -
C-x p g - Find matches for a regexp in all files that belong to the current project (
project-find-regexp). -
M-x project-search - Interactively search for regexp matches in all files that belong to the current project.
-
C-x p r - Perform query-replace for a regexp in all files that belong to the current project (
project-query-replace-regexp). -
C-x p D - Run Dired in the current project's root directory (
project-dired). -
C-x p v - Run
vc-dirin the current project's root directory (project-vc-dir). -
C-x p s - Start an inferior shell in the current project's root directory (
project-shell). -
C-x p e - Start Eshell in the current project's root directory (
project-eshell). -
C-x p c - Run compilation in the current project's root directory (
project-compile). -
C-x p ! - Run shell command in the current project's root directory (
project-shell-command). -
C-x p & - Run shell command asynchronously in the current project's root directory (
project-async-shell-command). -
C-x p o - Run the next command in the current project (
project-any-command).
Emacs provides commands for handling project files conveniently. This subsection describes these commands. All of the commands described here share the notion of the current project. The current project is determined by the default-directory (File Names) of the buffer that is the current buffer when the command is invoked. If that directory doesn't seem to belong to a recognizable project, these commands prompt you for the project directory. The command C-x p f (project-find-file) is a convenient way of visiting files (Visiting) that belong to the current project. Unlike C-x C-f, this command doesn't require typing the full file name of the file to visit, you can type only the file's base name (i.e., omit the leading directories). In addition, the completion candidates considered by the command include only the files belonging to the current project, and nothing else. If there's a file name at point, this command offers that file as the first element of the "future history". If given a prefix, include all files under the project root, except for VCS directories listed in vc-directory-exclusion-list. The command C-x p g (project-find-regexp) is similar to rgrep (Grep Searching), but it searches only the files that belong to the current project. The command prompts for the regular expression to search, and pops up an Xref mode buffer with the search results, where you can select a match using the Xref mode commands (Xref Commands). When invoked with a prefix argument, this command additionally prompts for the base directory from which to start the search; this allows, for example, to limit the search only to project files under a certain subdirectory of the project root. The way this command displays the matches is affected by the value of xref-auto-jump-to-first-xref (Identifier Search). M-x project-search is a sequential variant of project-find-regexp. It prompts for a regular expression to search in the current project's files, but instead of finding all the matches and displaying them, it stops when it finds a match and visits the matched file at the locus of the match, allowing you to edit the matched file. To find the rest of the matches, type M-x fileloop-continue =RET=. C-x p r (project-query-replace-regexp) is similar to project-search, but it prompts you for whether to replace each match it finds, like query-replace does (Query Replace), and continues to the next match after you respond. If your response causes Emacs to exit the query-replace loop, you can later continue with M-x fileloop-continue RET. The command C-x p d (project-find-dir) prompts you to choose a directory inside the current project, with completion. And opens a Dired buffer (Dired) listing the files in it. The command C-x p D (project-dired) opens a Dired buffer (Dired) listing the files in the current project's root directory. The command C-x p v (project-vc-dir) opens a VC Directory buffer (VC Directory Mode) listing the version control statuses of the files in a directory tree under the current project's root directory. The command C-x p s (project-shell) starts a shell session (Shell) in a new buffer with the current project's root as the working directory. The command C-x p e (project-eshell) starts an Eshell session in a new buffer with the current project's root as the working directory. Eshell. The command C-x p c (project-compile) runs compilation (Compilation) in the current project's root directory. The command C-x p ! (project-shell-command) runs shell-command in the current project's root directory. The command C-x p & (project-async-shell-command) runs async-shell-command in the current project's root directory. Finally, the command C-x p o (project-any-command) will run the next command you type, whether related to files or not, in the current project.
Project Commands That Operate on Buffers
-
C-x p b - Switch to another buffer belonging to the current project (
project-switch-to-buffer). -
C-x p C-b - List the project buffers (
project-list-buffers). -
C-x p k - Kill all live buffers that belong to the current project (
project-kill-buffers). -
C-x p o - Run the next command in the current project (
project-any-command).
Working on a project could potentially involve having many buffers visiting files that belong to the project, and also buffers that belong to the project, but don't visit any files (like the *compilation* buffer created by project-compile). The command C-x p b (project-switch-to-buffer) helps you switch between buffers that belong to the current project by prompting for a buffer to switch and considering only the current project's buffers as candidates for completion. Like the command list-buffers (List Buffers), the command C-x p C-b (project-list-buffers) displays a list of existing buffers, but only belonging to the current project. When you finish working on the project, you may wish to kill all the buffers that belong to the project, to keep your Emacs session smaller. The command C-x p k (project-kill-buffers) accomplishes that: it kills all the buffers that belong to the current project that satisfy any of project-kill-buffer-conditions. If project-kill-buffers-display-buffer-list is non-nil, the buffers to be killed will be displayed first. Finally, the command C-x p o (project-any-command) will run the next command you type, whether related to buffers or not, in the current project.
Switching Projects
-
C-x p p - Run an Emacs command for another project (
project-switch-project).
Commands that operate on project files (Project File Commands) will conveniently prompt you for a project directory when no project is current. When you are inside some project, but you want to operate on a different project, use the C-x p p command (project-switch-project). This command prompts you to choose a directory among known project roots, and then displays the menu of available commands to operate on the project you choose. The variable project-switch-commands controls which commands are available in the menu, and which key invokes each command. The variable project-list-file names the file in which Emacs records the list of known projects. It defaults to the file projects in user-emacs-directory (Find Init).
Managing the Project List File
-
M-x project-forget-project - Remove a known project from the
project-list-file.
Normally Emacs automatically adds and removes projects to and from the project-list-file, but sometimes you may want to manually edit the available projects. M-x project-forget-project prompts you to choose one of the available projects, and then removes it from the file. The user option project-list-exclude may be set to always ignore certain projects from being remembered and saved to project-list-file. It is a list of regular expressions and predicate functions for project roots and objects. The regexp is matched against the project root, and the predicate should take the project object as the only argument and return non-nil if the project should not be saved to project-list-file.
VC-Aware Project Backend
This backend is part of Emacs and is enabled by default. (Other backends may need installation of add-on packages and their proper configuration.) It determines the contents of the project based on the VCS repository's configuration (if any), excluding the "ignored" files from the output. It has some performance optimizations for listing the files with some of the popular VCS systems (currently Git and Mercurial). It also uses a time-based cache. If the mode line shows stale project information, you can type M-x project-remember-projects-under RET to refresh the stale cached info. @defopt project-vc-include-untracked By default, files which are neither registered with nor ignored by the VCS are considered part of the project. Customize this variable to nil to change that. @end defopt @defopt project-vc-ignores Using this variable you can add more ignore patterns to the project, to exclude more files from the project's file listing. The value is a list of glob strings. They can match both regular files and directories. To anchor an entry to the project root, start it with ./. To match directories only, end it with /. When this variable has directory-local value, it will only be applied to the corresponding directory subtree. @end defopt @defopt project-vc-name This variable allows you to change the automatically detected name of the project to a string of your choice. By default the name is the base name of its root directory. @end defopt @defopt project-vc-extra-root-markers This variable allows you to set up detection of non-VC projects in this backend, and also to have some subdirectories detected as separate projects. The value is a list. Each element is either a base file name or a glob pattern for such. Example values: .dir-locals.el, package.json, requirements.txt, *.gemspec. @end defopt
Change Logs
Many software projects keep a change log. This is a file, normally named ChangeLog, containing a chronological record of when and how the program was changed. Sometimes, these files are automatically generated from the change log entries stored in version control systems, or are used to generate these change log entries. Sometimes, there are several change log files, each recording the changes in one directory or directory tree.
Change Log Commands
The Emacs command C-x 4 a adds a new entry to the change log file for the file you are editing (add-change-log-entry-other-window). If that file is actually a backup file, it makes an entry appropriate for the file's parent—that is useful for making log entries for functions that have been deleted in the current version. C-x 4 a visits the change log file in a window other than the selected one (Window Choice) and creates a new entry unless the most recent entry is for today's date and your name. It also creates a new item for the current file. For many languages, it can even guess the name of the function or other object that was changed. To find the change log file, Emacs searches up the directory tree from the file you are editing. By default, it stops if it finds a directory that seems to be the root of a version-control repository. To change this, customize change-log-directory-files. When the variable add-log-keep-changes-together is non-nil, C-x 4 a adds to any existing item for the file, rather than starting a new item. You can combine multiple changes of the same nature. If you don't enter any text after the initial C-x 4 a, any subsequent C-x 4 a adds another symbol to the change log entry. If add-log-always-start-new-record is non-nil, C-x 4 a always makes a new entry, even if the last entry was made by you and on the same date. If the value of the variable change-log-version-info-enabled is non-nil, C-x 4 a adds the file's version number to the change log entry. It finds the version number by searching the first ten percent of the file, using regular expressions from the variable change-log-version-number-regexp-list. The change log file is visited in Change Log mode. In this major mode, each bunch of grouped items counts as one paragraph, and each entry is considered a page. This facilitates editing the entries. C-j and auto-fill indent each new line like the previous line; this is convenient for entering the contents of an entry. You can use the command change-log-goto-source (by default bound to C-c C-c) to go to the source location of the change log entry near point, when Change Log mode is on. Then subsequent invocations of the next-error command (by default bound to M-g M-n and C-x `) will move between entries in the change log. You will jump to the actual site in the file that was changed, not just to the next change log entry. You can also use previous-error to move back through the change log entries. You can use the command M-x change-log-merge to merge other log files into a buffer in Change Log Mode, preserving the date ordering of entries. Version control systems are another way to keep track of changes in your program and keep a change log. Many projects that use a VCS don't keep a separate versioned change log file nowadays, so you may wish to avoid having such a file in the repository. If the value of add-log-dont-create-changelog-file is non-nil, commands like C-x 4 a (add-change-log-entry-other-window) will record changes in a suitably named temporary buffer instead of a file, if such a file does not already exist. Whether you have a change log file or use a temporary buffer for change logs, you can type C-c C-a (log-edit-insert-changelog) in the VC Log buffer to insert the relevant change log entries, if they exist. Log Buffer.
Format of ChangeLog
A change log entry starts with a header line that contains the current date, your name (taken from the variable add-log-full-name), and your email address (taken from the variable add-log-mailing-address). Aside from these header lines, every line in the change log starts with a space or a tab. The bulk of the entry consists of items, each of which starts with a line starting with whitespace and a star. Here are two entries, both dated in May 1993, with two items and one item respectively.
1993-05-25 Richard Stallman <rms@@gnu.org>
* man.el: Rename symbols 'man-*' to 'Man-*'.
(manual-entry): Make prompt string clearer.
* simple.el (blink-matching-paren-distance):
Change default to 12,000.
1993-05-24 Richard Stallman <rms@@gnu.org>
* vc.el (minor-mode-map-alist): Don't use it if it's void.
(vc-cancel-version): Doc fix.
One entry can describe several changes; each change should have its own item, or its own line in an item. Normally there should be a blank line between items. When items are related (parts of the same change, in different places), group them by leaving no blank line between them. You should put a copyright notice and permission notice at the end of the change log file. Here is an example:
Copyright 1997--1998, 2025--2026 Free Software Foundation, Inc. Copying and distribution of this file, with or without modification, are permitted provided the copyright notice and this notice are preserved.
Of course, you should substitute the proper years and copyright holder.
Find Identifier References
An identifier is a name of a syntactical subunit of the program: a function, a subroutine, a method, a class, a data type, a macro, etc. In a programming language, each identifier is a symbol in the language's syntax. Identifiers are also known as tags. Program development and maintenance requires capabilities to quickly find where each identifier was defined and referenced, to rename identifiers across the entire project, etc. These capabilities are also useful for finding references in major modes other than those defined to support programming languages. For example, chapters, sections, appendices, etc. of a text or a TeX document can be treated as subunits as well, and their names can be used as identifiers. In this chapter, we use the term "identifiers" to collectively refer to the names of any kind of subunits, in program source and in other kinds of text alike. Emacs provides a unified interface to these capabilities, called xref. To do its job, xref needs to make use of information and to employ methods specific to the major mode. What files to search for identifiers, how to find references to identifiers, how to complete on identifiers—all this and more is mode-specific knowledge. xref delegates the mode-specific parts of its job to a backend provided by the mode; it also includes defaults for some of its commands, for those modes that don't provide their own. A backend can implement its capabilities in a variety of ways. Here are a few examples:
- Some major modes provide built-in means for looking up the language symbols. For example, Emacs Lisp symbols can be identified by searching the package load history, maintained by the Emacs Lisp interpreter, and by consulting the built-in documentation strings; the Emacs Lisp mode uses these facilities in its backend to allow finding definitions of symbols. (One disadvantage of this kind of backend is that it only knows about subunits that were loaded into the interpreter.)
- If Eglot is activated for the current buffer's project (Projects) and the current buffer's major mode, Eglot consults an external language server program and provides the data supplied by the server regarding the definitions of the identifiers in the project. Eglot Features.
- An external program can extract references by scanning the relevant files, and build a database of these references. A backend can then access this database whenever it needs to list or look up references. The Emacs distribution includes
etags, a command for tagging identifier definitions in programs, which supports many programming languages and other major modes, such as HTML, by extracting references into tags tables. Major modes for languages supported byetagscan use tags tables as basis for their backend. Enableetags-regen-modeto have tags tables generated across the current project for supported file types and updated automatically upon edit. Alternatively, you can build the table manually to control the set of files and when it is updated, see Create Tags Table.
Find Identifiers
This subsection describes the commands that find references to identifiers and perform various queries about identifiers. Each such reference could define an identifier, e.g., provide the implementation of a program subunit or the text of a document section; or it could use the identifier, e.g., call a function or a method, assign a value to a variable, mention a chapter in a cross-reference, etc.
Looking Up Identifiers
The most important thing that xref enables you to do is to find the definition of a specific identifier.
-
M-. - Find definitions of an identifier (
xref-find-definitions). -
C-M-. pattern RET - Find all identifiers whose name matches pattern (
xref-find-apropos). -
C-x 4 . RET - Find definitions of identifier, but display it in another window (
xref-find-definitions-other-window). -
C-x 5 . RET - Find definition of identifier, and display it in a new frame (
xref-find-definitions-other-frame). -
M-x xref-find-definitions-at-mouse - Find definition of identifier at mouse click.
-
M-, - Go back to where you previously invoked
M-.and friends (xref-go-back). -
C-M-, - Go forward to where you previously invoked
M-(xref-go-forward). -
M-x xref-etags-mode - Switch
xrefto use theetagsbackend.
M-. (xref-find-definitions) shows the definition of the identifier at point. With a prefix argument, or if there's no identifier at point, it prompts for the identifier. (If you want it to always prompt, customize xref-prompt-for-identifier to t.) When entering the identifier argument to M-., you can use the usual minibuffer completion commands (Completion), with the known identifier names being the completion candidates. It uses the current Xref backend, and will signal an error when there is none configured, with some recommendations. Like most commands that can switch buffers, xref-find-definitions has a variant that displays the new buffer in another window (Window Choice), and one that makes a new frame for it. The former is C-x 4 . (xref-find-definitions-other-window), and the latter is C-x 5 . (xref-find-definitions-other-frame). The command xref-find-definitions-at-mouse works like xref-find-definitions, but it looks for the identifier name at or around the place of a mouse event. The xref-mouse-mode minor mode binds the command to C-mouse-1. The command C-M-. (xref-find-apropos) is like apropos for tags (Apropos). It displays a list of identifiers in the selected tags table whose names match the specified regexp. This is just like M-., except that it does regexp matching of identifiers instead of matching symbol names as fixed strings. By default, the command pops up the *xref* buffer, like M-., but you can display additional output by customizing the variable tags-apropos-additional-actions; see its documentation for details. If any of the above commands finds more than one matching definition, it by default pops up the *xref* buffer showing the matching candidates and selects that buffer's window. (C-M-. always pops up the *xref* buffer if it finds at least one match.) Each candidate is normally shown in that buffer as the name of a file and the matching identifier(s) in that file. In that buffer, you can select any of the candidates for display, and you have several additional commands, described in Xref Commands. However, if the value of the variable xref-auto-jump-to-first-definition is move, Emacs automatically moves point to the first of these candidates in the *xref* buffer, so just typing RET will display the definition of that candidate. If the value of the variable is t or show, the first candidate is automatically shown in its own window; t also selects the window showing the first candidate's definition, while show leaves the window of the *xfer* buffer selected. The default value is nil, which just shows the candidates in the *xref* buffer, but neither selects any of them nor shows their definition, until you select a candidate in the *xref* buffer. If you switch away of the window showing the *xref* buffer which displays several candidates, you can move from one candidate to another using the commands M-g M-n (next-error) and M-g M-p (previous-error). Compilation Mode. To go back to places from where you've displayed the definition, use M- (xref-go-back). It jumps back to the point of the last invocation of M-.. Thus you can find and examine the definition of something with M-. and then return to where you were with M-. M- allows you to retrace the steps you made forward in the history of places, all the way to the first place in history, where you first invoked M-., or to any place in-between. If you previously went back too far with M-, or want to re-examine a place from which you went back, you can use C-M- (xref-go-forward) to go forward again. This is similar to using M-., except that you don't need on each step to move point to the identifier whose definition you want to look up. C-M- allows you to retrace all the steps you made back in the history of places, all the way to the last place in history, where you invoked M-, or to any place in-between. Some major modes install xref support facilities that might sometimes fail to find certain identifiers. For example, in Emacs Lisp mode (Lisp Eval) M-. will by default find only functions and variables from Lisp packages which are loaded into the current Emacs session or are auto-loaded (Autoload). If M-. fails to find some identifiers, you can try forcing xref to use the etags backend (Xref). To this end, turn on the Xref Etags minor mode with M-x xref-etags-mode, then invoke M-. again. (For this to work, be sure to run etags to create the tags table in the directory tree of the source files, see Create Tags Table.)
Commands Available in the *xref* Buffer
The following commands are provided in the *xref* buffer by the special Xref mode:
-
RET,mouse-1 - Display the reference on the current line (
xref-goto-xref). With prefix argument, also bury the*xref*buffer. -
mouse-2 - The same as
mouse-1, but make the window displaying the*xref*buffer the selected window (xref-select-and-show-xref). -
n,. - Move to the next reference and display it in the other window (
xref-next-line). -
N - Move to the first reference of the next reference group and display it in the other window (
xref-next-group). -
p,, - Move to the previous reference and display it in the other window (
xref-prev-line). -
P - Move to the first reference of the previous reference group and display it in the other window (
xref-prev-group). -
C-o - Display the reference on the current line in the other window (
xref-show-location-at-point). -
r pattern RET replacement RET - Perform interactive query-replace on references that match pattern (
xref-query-replace-in-results), replacing the match with replacement. This command can only be used in*xref*buffers that show all the matches for an identifier in all the relevant files. Identifier Search. -
g - Refresh the contents of the
*xref*buffer (revert-buffer). Reverting. -
M-, - Quit the window showing the
*xref*buffer, and then jump to the previous Xref stack location (xref-quit-and-pop-marker-stack). -
q - Quit the window showing the
*xref*buffer (xref-quit).
In addition, the usual navigation commands, such as the arrow keys, C-n, and C-p are available for moving around the buffer without displaying the references.
Searching and Replacing with Identifiers
The commands in this section perform various search and replace operations either on identifiers themselves or on files that reference them.
-
M-? - Find all the references for the identifier at point.
-
r,M-x xref-query-replace-in-results RET replacement RET,C-u M-x xref-query-replace-in-results RET regexp RET replacement RET - Interactively replace regexp with replacement in the names of all the identifiers shown in the
*xref*buffer. -
M-x xref-find-references-and-replace RET from RET to RET - Interactively rename all instances of the identifier from to the new name to.
-
M-x tags-search RET regexp RET - Search for regexp through the files in the selected tags table.
-
M-x tags-query-replace RET regexp RET replacement RET - Perform a
query-replace-regexpon each file in the selected tags table. -
M-x fileloop-continue - Restart one of the last 2 commands above, from the current location of point.
M-? finds all the references for the identifier at point, prompting for the identifier as needed, with completion. Depending on the current backend (Xref), the command may prompt even if it finds a valid identifier at point. When invoked with a prefix argument, it always prompts for the identifier. (If you want it to prompt always, customize the value of the variable xref-prompt-for-identifier to t; or set it to nil to prompt only if there's no usable identifier at point.) The command then presents the *xref* buffer with all the references to the identifier, showing the file name and the line where the identifier is referenced. The Xref mode commands are available in this buffer, see Xref Commands. When invoked in a buffer whose major mode uses the etags backend, M-? searches files and buffers whose major mode matches that of the original buffer. It guesses that mode from file extensions, so if M-? seems to be skipping relevant buffers or files, try customizing either the variable semantic-symref-filepattern-alist (if your buffer's major mode already has an entry in it), or auto-mode-alist (if not), thereby informing xref of the missing extensions (Choosing Modes). If the value of the variable xref-auto-jump-to-first-xref is t, xref-find-references automatically jumps to the first result in the *xref* buffer and selects the window where that reference is displayed; you can select the other results with M-g M-n (next-error) and M-g M-p (previous-error) (Compilation Mode). If the value is show, the first result is displayed, but the window showing the *xref* buffer is left selected. If the value is move, the first result is selected in the *xref* buffer, but is not displayed; you can then use RET to actually display the reference. The default value is nil, which just shows the results in the *xref* buffer, but doesn't select any of them, and doesn't display the reference itself. r (xref-query-replace-in-results) reads a replacement string, just like ordinary M-x query-replace-regexp. It then renames the identifiers shown in the *xref* buffer in all the places in all the files where these identifiers are referenced, such that their new name is replacement. This is useful when you rename your identifiers as part of refactoring. This command should be invoked in the *xref* buffer generated by M-?. By default, the command replaces the entire name of each identifier with replacement, but if invoked with a prefix argument, the command prompts for a regexp to match identifier names, and replaces only the matches of that regexp in the names of the identifiers with replacement. M-x xref-find-references-and-replace works similarly to xref-query-replace-in-results, but is more convenient when you want to rename a single identifier specified by its name from. Typing e in the *xref* buffer makes the buffer writable and enters the Xref Edit mode. Similar to Occur Edit mode (Other Repeating Search), you can edit the matching lines reported by Xref backend and have those changes reflected in the buffer visiting the originating file. Type C-c C-c to leave the Xref Edit mode and return to the Xref mode. M-x tags-search reads a regexp using the minibuffer, then searches for matches in all the files in the selected tags table, one file at a time. It displays the name of the file being searched so you can follow its progress. As soon as it finds an occurrence, tags-search returns. This command requires tags tables to be available (Tags Tables). Having found one match with tags-search, you probably want to find all the rest. M-x fileloop-continue resumes the tags-search, finding one more match. This searches the rest of the current buffer, followed by the remaining files of the tags table. M-x tags-query-replace performs a single query-replace-regexp through all the files in the tags table. It reads a regexp to search for and a string to replace with, just like ordinary M-x query-replace-regexp. It searches much like M-x tags-search, but repeatedly, processing matches according to your input. Query Replace, for more information on query replace. You can control the case-sensitivity of tags search commands by customizing the value of the variable tags-case-fold-search. The default is to use the same setting as the value of case-fold-search (Lax Search). It is possible to get through all the files in the tags table with a single invocation of M-x tags-query-replace. But often it is useful to exit temporarily, which you can do with any input event that has no special query replace meaning. You can resume the query replace subsequently by typing M-x fileloop-continue; this command resumes the last tags search or replace command that you did. For instance, to skip the rest of the current file, you can type M-> M-x fileloop-continue. Note that the commands described above carry out much broader searches than the xref-find-definitions family. The xref-find-definitions commands search only for definitions of identifiers that match your string or regexp. The commands xref-find-references, tags-search, and tags-query-replace find every occurrence of the identifier or regexp, as ordinary search commands and replace commands do in the current buffer. As an alternative to xref-find-references and tags-search, you can run grep as a subprocess and have Emacs show you the matching lines one by one. Grep Searching.
Identifier Inquiries
-
C-M-i,M-TAB - Perform completion on the text around point, possibly using the selected tags table if one is loaded (
completion-at-point). -
M-x list-tags RET file RET - Display a list of the identifiers defined in the program file file.
-
C-M-. regexp RET - Display a list of all identifiers matching regexp (
xref-find-apropos). Looking Up Identifiers. -
M-x tags-next-file - Visit files recorded in the selected tags table.
In most programming language modes, you can type C-M-i or M-TAB (completion-at-point) to complete the symbol at point. Some modes provide specialized completion for this command tailored to the mode; for those that don't, if there is a tags table loaded, this command can use it to generate completion candidates. Symbol Completion. M-x list-tags reads the name of one of the files covered by the selected tags table, with completion, and displays the list of tags defined in that file; it offers the current buffer's file name as the default file whose tags to list. Do not include a directory as part of the file name unless the file name recorded in the tags table includes a directory. This command works only with the etags backend, and requires a tags table for the project to be available. Tags Tables. M-x tags-next-file visits files covered by the selected tags table. The first time it is called, it visits the first file covered by the table. Each subsequent call visits the next covered file, unless a prefix argument is supplied, in which case it returns to the first file. This command requires a tags table to be selected.
Emacs Development Environment
EDE (Emacs Development Environment) is a package that simplifies the task of creating, building, and debugging large programs with Emacs. It provides some of the features of an IDE, or Integrated Development Environment, in Emacs. This section provides a brief description of EDE usage. For full details, see EDE. EDE is implemented as a global minor mode (Minor Modes). To enable it, type M-x global-ede-mode or click on the Project Support (EDE) item in the Tools menu. You can also enable EDE each time you start Emacs, by adding the following line to your initialization file:
(global-ede-mode t)
Activating EDE adds a menu named Development to the menu bar. Many EDE commands, including the ones described below, can be invoked from this menu. EDE organizes files into projects, which correspond to directory trees. The project root is the topmost directory of a project. To define a new project, visit a file in the desired project root and type M-x ede-new. This command prompts for a project type, which refers to the underlying method that EDE will use to manage the project (EDE). The most common project types are Make, which uses Makefiles, and Automake, which uses GNU Automake (Automake). In both cases, EDE also creates a file named Project.ede, which stores information about the project. A project may contain one or more targets. A target can be an object file, executable program, or some other type of file, which is built from one or more of the files in the project. To add a new target to a project, type C-c . t (M-x ede-new-target). This command also asks if you wish to add the current file to that target, which means that the target is to be built from that file. After you have defined a target, you can add more files to it by typing C-c . a (ede-add-file). To build a target, type C-c . c (ede-compile-target). To build all the targets in the project, type C-c . C (ede-compile-project). EDE uses the file types to guess how the target should be built.
Merging Files with Emerge
It's not unusual for programmers to get their signals crossed and modify the same program in two different directions. To recover from this confusion, you need to merge the two versions. Emerge makes this easier. For other ways to compare files, see Comparing Files, and Ediff.
Overview of Emerge
To start Emerge, run one of these four commands:
-
M-x emerge-files - Merge two specified files.
-
M-x emerge-files-with-ancestor - Merge two specified files, with reference to a common ancestor.
-
M-x emerge-buffers - Merge two buffers.
-
M-x emerge-buffers-with-ancestor - Merge two buffers with reference to a common ancestor in a third buffer.
The Emerge commands compare two files or buffers, and display the comparison in three buffers: one for each input text (the A buffer and the B buffer), and one (the merge buffer) where merging takes place. The merge buffer shows the full merged text, not just the differences. Wherever the two input texts differ, you can choose which one of them to include in the merge buffer. The Emerge commands that take input from existing buffers use only the accessible portions of those buffers, if they are narrowed. Narrowing. If a common ancestor version is available, from which the two texts to be merged were both derived, Emerge can use it to guess which alternative is right. Wherever one current version agrees with the ancestor, Emerge presumes that the other current version is a deliberate change which should be kept in the merged version. Use the with-ancestor commands if you want to specify a common ancestor text. These commands read three file or buffer names—variant A, variant B, and the common ancestor. After the comparison is done and the buffers are prepared, the interactive merging starts. You control the merging by typing special merge commands in the merge buffer (Merge Commands). For each run of differences between the input texts, you can choose which one of them to keep, or edit them both together. The merge buffer uses a special major mode, Emerge mode, with commands for making these choices. But you can also edit the buffer with ordinary Emacs commands. At any given time, the attention of Emerge is focused on one particular difference, called the selected difference. This difference is marked off in the three buffers like this:
vvvvvvvvvvvvvvvvvvvv
@var{text that differs}
^^^^^^^^^^^^^^^^^^^^
Emerge numbers all the differences sequentially and the mode line always shows the number of the selected difference. Normally, the merge buffer starts out with the A version of the text. But when the A version of a difference agrees with the common ancestor, then the B version is initially preferred for that difference. Emerge leaves the merged text in the merge buffer when you exit. At that point, you can save it in a file with C-x C-w. If you give a numeric argument to emerge-files or emerge-files-with-ancestor, it reads the name of the output file using the minibuffer. (This is the last file name those commands read.) Then exiting from Emerge saves the merged text in the output file. Normally, Emerge commands save the output buffer in its file when you exit. If you abort Emerge with C-], the Emerge command does not save the output buffer, but you can save it yourself if you wish.
Submodes of Emerge
You can choose between two modes for giving merge commands: Fast mode and Edit mode. In Fast mode, basic merge commands are single characters, but ordinary Emacs commands are disabled. This is convenient if you use only merge commands. In Edit mode, all merge commands start with the prefix key C-c C-c, and the normal Emacs commands are also available. This allows editing the merge buffer, but slows down Emerge operations. Use e to switch to Edit mode, and C-c C-c f to switch to Fast mode. The mode line indicates Edit and Fast modes with E and F. Emerge has two additional submodes that affect how particular merge commands work: Auto Advance mode and Skip Prefers mode. If Auto Advance mode is in effect, the a and b commands advance to the next difference. This lets you go through the merge faster as long as you simply choose one of the alternatives from the input. The mode line indicates Auto Advance mode with A. If Skip Prefers mode is in effect, the n and p commands skip over differences in states "prefer-A" and "prefer-B" (State of Difference). Thus you see only differences for which neither version is presumed correct. The mode line indicates Skip Prefers mode with S. This mode is only relevant when there is an ancestor. Use the command s a (emerge-auto-advance) to set or clear Auto Advance mode. Use s s (emerge-skip-prefers) to set or clear Skip Prefers mode. These commands turn on the mode with a positive argument, turn it off with a negative or zero argument, and toggle the mode with no argument.
State of a Difference
In the merge buffer, a difference is marked with lines of v and ^ characters. Each difference has one of these seven states:
- A
- The difference is showing the A version. The
acommand always produces this state; the mode line indicates it withA. - B
- The difference is showing the B version. The
bcommand always produces this state; the mode line indicates it withB. - default-A, default-B
- The difference is showing the A or the B state by default, because you haven't made a choice. All differences start in the default-A state (and thus the merge buffer is a copy of the A buffer), except those for which one alternative is preferred (see below). When you select a difference, its state changes from default-A or default-B to plain A or B. Thus, the selected difference never has state default-A or default-B, and these states are never displayed in the mode line. The command
d achooses default-A as the default state, andd bchooses default-B. This chosen default applies to all differences that you have never selected and for which no alternative is preferred. If you are moving through the merge sequentially, the differences you haven't selected are those following the selected one. Thus, while moving sequentially, you can effectively make the A version the default for some sections of the merge buffer and the B version the default for others by usingd aandd bbetween sections. - prefer-A, prefer-B
- The difference is showing the A or B state because it is preferred. This means that you haven't made an explicit choice, but one alternative seems likely to be right because the other alternative agrees with the common ancestor. Thus, where the A buffer agrees with the common ancestor, the B version is preferred, because chances are it is the one that was actually changed. These two states are displayed in the mode line as
A*andB*. - combined
- The difference is showing a combination of the A and B states, as a result of the
x corx Ccommands. Once a difference is in this state, theaandbcommands don't do anything to it unless you give them a numeric argument. The mode line displays this state ascomb.
Merge Commands
Here are the Merge commands for Fast mode; in Edit mode, precede them with C-c C-c:
-
p - Select the previous difference.
-
n - Select the next difference.
-
a - Choose the A version of this difference.
-
b - Choose the B version of this difference.
-
C-u n j - Select difference number n.
-
. - Select the difference containing point.
-
q - Quit—finish the merge.
-
C-] - Abort—exit merging and do not save the output.
-
f - Go into Fast mode. (In Edit mode, this is actually
C-c C-c f.) -
e - Go into Edit mode.
-
l - Recenter (like
C-l) all three windows. With an argument, reestablish the default three-window display. -
- - Specify part of a prefix numeric argument.
-
digit - Also specify part of a prefix numeric argument.
-
d a - Choose the A version as the default from here down in the merge buffer.
-
d b - Choose the B version as the default from here down in the merge buffer.
-
c a - Copy the A version of this difference into the kill ring.
-
c b - Copy the B version of this difference into the kill ring.
-
i a - Insert the A version of this difference at point.
-
i b - Insert the B version of this difference at point.
-
m - Put point and mark around the difference.
-
^ - Scroll all three windows down (like
M-v). -
v - Scroll all three windows up (like
C-v). -
< - Scroll all three windows left (like
C-x <). -
> - Scroll all three windows right (like
C-x >). -
| - Reset horizontal scroll on all three windows.
-
x 1 - Shrink the merge window to one line. (Use
C-u lto restore it to full size.) -
x c - Combine the two versions of this difference (Combining in Emerge).
-
x f - Show the names of the files/buffers Emerge is operating on, in a Help window. (Use
C-u lto restore windows.) -
x j - Join this difference with the following one. (
C-u x jjoins this difference with the previous one.) -
x s - Split this difference into two differences. Before you use this command, position point in each of the three buffers at the place where you want to split the difference.
-
x t - Trim identical lines off the top and bottom of the difference. Such lines occur when the A and B versions are identical but differ from the ancestor version.
Exiting Emerge
The q command (emerge-quit) finishes the merge, storing the results into the output file if you specified one. It restores the A and B buffers to their proper contents, or kills them if they were created by Emerge and you haven't changed them. It also disables the Emerge commands in the merge buffer, since executing them later could damage the contents of the various buffers. C-] aborts the merge. This means exiting without writing the output file. If you didn't specify an output file, then there is no real difference between aborting and finishing the merge. If the Emerge command was called from another Lisp program, then its return value is t for successful completion, or nil if you abort.
Combining the Two Versions
Sometimes you want to keep both alternatives for a particular difference. To do this, use x c, which edits the merge buffer like this:
#ifdef NEW
@var{version from B buffer}
#else /* not NEW */
@var{version from A buffer}
#endif /* not NEW */
While this example shows C preprocessor conditionals delimiting the two alternative versions, you can specify the strings to use by setting the variable emerge-combine-versions-template to a string of your choice. In the string, %a says where to put version A, and %b says where to put version B. The default setting, which produces the results shown above, looks like this:
"#ifdef NEW\n%b#else /* not NEW */\n%a#endif /* not NEW */\n"
Fine Points of Emerge
During the merge, you mustn't try to edit the A and B buffers yourself. Emerge modifies them temporarily, but ultimately puts them back the way they were. You can have any number of merges going at once—just don't use any one buffer as input to more than one merge at once, since the temporary changes made in these buffers would get in each other's way. Starting Emerge can take a long time because it needs to compare the files fully. Emacs can't do anything else until diff finishes. Perhaps in the future someone will change Emerge to do the comparison in the background when the input files are large—then you could keep on doing other things with Emacs until Emerge is ready to accept commands. After setting up the merge, Emerge runs the hook emerge-startup-hook. Hooks.
Bug Reference
Most projects with a certain amount of users track bug reports in some issue tracking software which assigns each report a unique and short number or identifier. Those are used to reference a given bug, e.g., in a source code comment above the code fixing some bug, in documentation files, or in discussions on some mailing list or IRC channel. The minor modes bug-reference-mode and bug-reference-prog-mode highlight such bug references and make it possible to follow them to the corresponding bug report on the project's issue tracker. bug-reference-prog-mode is a variant of bug-reference-mode which highlights bug references only inside source code comments and strings. For its working, bug reference mode needs to know the syntax of bug references (bug-reference-bug-regexp), and the URL of the tracker where bug reports can be looked up (bug-reference-url-format). Since those are typically different from project to project, it makes sense to specify them in Directory Variables or File Variables. For example, let's assume in our project, we usually write references to bug reports as bug#1234, or Bug-1234 and that this bug's page on the issue tracker is https://project.org/issues/1234, then these local variables section would do.
;; Local Variables: ;; bug-reference-bug-regexp: "\\([Bb]ug[#-]\\([0-9]+\\)\\)" ;; bug-reference-url-format: "https://project.org/issues/%s" ;; End:
The string captured by the first regexp group defines the bounds of the overlay bug-reference creates, i.e., the part which is highlighted and made clickable. The string captured by the second regexp group in bug-reference-bug-regexp is used to replace the %s template in the bug-reference-url-format. Note that bug-reference-url-format may also be a function in order to cater for more complex scenarios, e.g., when different parts of the bug reference have to be used to distinguish between issues and merge requests resulting in different URLs.
Automatic Setup
If bug-reference-mode is activated, bug-reference-mode-hook has been run, and either bug-reference-bug-regexp or bug-reference-url-format is still nil, the mode will try to automatically find a suitable value for these two variables by calling the functions in bug-reference-auto-setup-functions one by one until one succeeds. Right now, there are three types of setup functions.
- Setup for version-controlled files configurable by the variables
bug-reference-forge-alist, andbug-reference-setup-from-vc-alist. The defaults are able to set up GNU projects where https://debbugs.gnu.org is used as issue tracker and issues are usually referenced asbug#13(but many different notations are considered, too), as well as several other kinds of software forges such as GitLab, Gitea, SourceHut, and GitHub. If you deploy a self-hosted instance of such a forge, the easiest way to tell bug-reference about it is throughbug-reference-forge-alist. - Setup for email guessing from mail folder/mbox names, and mail header values configurable by the variable
bug-reference-setup-from-mail-alist. The built-in news- and mailreader Gnus and Rmail are supported. - Setup for IRC channels configurable by the variable
bug-reference-setup-from-irc-alist. The built-in IRC clients Rcirc, Rcirc, and ERC, ERC, are supported.
For almost all of those modes, it's enough to simply enable bug-reference-mode; only Rmail requires a slightly different setup.
;; Use VC-based setup if file is under version control. (add-hook 'prog-mode-hook #'bug-reference-prog-mode) ;; Gnus (summary & article buffers) (add-hook 'gnus-mode-hook #'bug-reference-mode) ;; Rmail (add-hook 'rmail-show-message-hook #'bug-reference-mode-force-auto-setup) ;; Rcirc (add-hook 'rcirc-mode-hook #'bug-reference-mode) ;; ERC (add-hook 'erc-mode-hook #'bug-reference-mode)
In the Rmail case, instead of the mode hook, the rmail-show-message-hook has to be used in combination with the function bug-reference-mode-force-auto-setup which activates bug-reference-mode and forces auto-setup. The reason is that with Rmail all messages reside in the same buffer but the setup needs to be performed whenever another messages is displayed.
Adding support for third-party packages
Adding support for bug-reference auto-setup is usually quite straightforward: write a setup function of zero arguments which gathers the required information (e.g., List-Id/To/From/Cc mail header values in the case of a MUA), and then calls one of the following helper functions:
bug-reference-maybe-setup-from-vc, which does the setup according tobug-reference-setup-from-vc-alist;bug-reference-maybe-setup-from-mail, which does the setup according tobug-reference-setup-from-mail-alist; andbug-reference-maybe-setup-from-irc, which does the setup according tobug-reference-setup-from-irc-alist.
A setup function should return non-nil if it could set up bug-reference mode, which is the case if the last thing the function does is call one of the helper functions above. Finally, the setup function has to be added to bug-reference-auto-setup-functions. Note that these auto-setup functions should check as a first step if they are applicable, e.g., by checking the value of major-mode.
Integration with the debbugs package
If your project's issues are tracked on the server https://debbugs.gnu.org, you can browse and reply to reports directly in Emacs using the debbugs package, which can be downloaded via the Package Menu (Packages). This package adds the minor mode debbugs-browse-mode, which can be activated on top of bug-reference-mode and bug-reference-prog-mode as follows:
(add-hook 'bug-reference-mode-hook 'debbugs-browse-mode) (add-hook 'bug-reference-prog-mode-hook 'debbugs-browse-mode)