Skip to main content

4.5.2 Completion and Confirmation

Many Magit commands ask the user to select from a list of possible things to act on, while offering the most likely choice as the default. For many of these commands the default is the thing at point, provided that it actually is a valid thing to act on. For many commands that act on a branch, the current branch serves as the default if there is no branch at point.

These commands combine asking for confirmation and asking for a target to act on into a single action. The user can confirm the default target using RET or abort using C-g. This is similar to a y-or-n-p prompt, but the keys to confirm or abort differ.

At the same time the user is also given the opportunity to select another target, which is useful because for some commands and/or in some situations you might want to select the action before selecting the target by moving to it.

However you might find that for some commands you always want to use the default target, if any, or even that you want the command to act on the default without requiring any confirmation at all. The option magit-dwim-selection can be used to configure certain commands to that effect.

Note that when the region is active then many commands act on the things that are selected using a mechanism based on the region, in many cases after asking for confirmation. This region-based mechanism is called the "selection" and is described in detail in the next section. When a selection exists that is valid for the invoked command, then that command never offers to act on something else, and whether it asks for confirmation is not controlled by this option.

Also note that Magit asks for confirmation of certain actions that are not coupled with completion (or the selection). Such dialogs are also not affected by this option and are described in the previous section.

user option magit-dwim-selection

This option can be used to tell certain commands to use the thing at point instead of asking the user to select a candidate to act on, with or without confirmation.

The value has the form ((COMMAND nil|PROMPT DEFAULT)...).

  • COMMAND is the command that should not prompt for a choice. To have an effect, the command has to use the function magit-completing-read or a utility function which in turn uses that function.
  • If the command uses magit-completing-read multiple times, then PROMPT can be used to only affect one of these uses. PROMPT, if non-nil, is a regular expression that is used to match against the PROMPT argument passed to magit-completing-read.
  • DEFAULT specifies how to use the default. If it is t, then the DEFAULT argument passed to magit-completing-read is used without confirmation. If it is ask, then the user is given a chance to abort. DEFAULT can also be nil, in which case the entry has no effect.