20.6 Completion
Completion is a feature that fills in the rest of a name starting from an abbreviation for it. Completion works by comparing the user’s input against a list of valid names and determining how much of the name is determined uniquely by what the user has typed. For example, when you type C-x b
(switch-to-buffer
) and then type the first few letters of the name of the buffer to which you wish to switch, and then type TAB
(minibuffer-complete
), Emacs extends the name as far as it can.
Standard Emacs commands offer completion for names of symbols, files, buffers, and processes; with the functions in this section, you can implement completion for other kinds of names.
The try-completion
function is the basic primitive for completion: it returns the longest determined completion of a given initial string, with a given set of strings to match against.
The function completing-read
provides a higher-level interface for completion. A call to completing-read
specifies how to determine the list of valid names. The function then activates the minibuffer with a local keymap that binds a few keys to commands useful for completion. Other functions provide convenient simple interfaces for reading certain kinds of names with completion.
• Basic Completion | Low-level functions for completing strings. | |
• Minibuffer Completion | Invoking the minibuffer with completion. | |
• Completion Commands | Minibuffer commands that do completion. | |
• High-Level Completion | Convenient special cases of completion (reading buffer names, variable names, etc.). | |
• Reading File Names | Using completion to read file names and shell commands. | |
• Completion Variables | Variables controlling completion behavior. | |
• Programmed Completion | Writing your own completion function. | |
• Completion in Buffers | Completing text in ordinary buffers. |