GNU Emacs
Emacs
Dashboard

8.4.1 Completion Example

A simple example may help here. M-x uses the minibuffer to read the name of a command, so completion works by matching the minibuffer text against the names of existing Emacs commands. Suppose you wish to run the command auto-fill-mode. You can do that by typing M-x auto-fill-mode RET, but it is easier to use completion.

If you type M-x a u TAB, the TAB looks for completion alternatives (in this case, command names) that start with ‘ au’. There are several, including auto-fill-mode and autoconf-mode, but they all begin with auto, so the ‘ au’ in the minibuffer completes to ‘ auto’. (More commands may be defined in your Emacs session. For example, if a command called authorize-me was defined, Emacs could only complete as far as ‘ aut’.)

If you type TAB again immediately, it cannot determine the next character; it could be ‘ -’, ‘ a’, or ‘ c’. So it does not add any characters; instead, TAB displays a list of all possible completions in another window.

Next, type -f. The minibuffer now contains ‘ auto-f’, and the only command name that starts with this is auto-fill-mode. If you now type TAB, completion fills in the rest of the argument ‘ auto-fill-mode’ into the minibuffer.

Hence, typing just a u TAB - f TAB allows you to enter ‘ auto-fill-mode’.