Completion for Symbol Names
Completion is normally done in the minibuffer (see Completion), but you can also complete symbol names in ordinary Emacs buffers.
In most programming language modes, C-M-i (or M-TAB[1]) invokes the command completion-at-point, which generates the list of possible completions for the symbol at point. This command uses the available support facilities to come up with the completion candidates:
- If Eglot is activated for the current buffer’s project (see Working with Projects) and the current buffer’s major mode, the command tries to use the corresponding language server for producing the list of completion candidates. See Eglot Features in Eglot: The Emacs LSP Client.
- If Semantic mode is enabled (see Semantic), the command tries to use the Semantic parser data for completion.
- If Semantic mode is not enabled or fails at performing completion, the command tries to complete using the selected tags table (see Tags Tables); you need to visit the tags table with M-x visit-tags-table for that to work.
- In Emacs Lisp mode, the command performs completion using the function, variable, or property names defined in the current Emacs session.
In all other respects, in-buffer symbol completion behaves like minibuffer completion. For instance, if Emacs cannot complete to a unique symbol, it displays a list of completion alternatives in another window. Then you can use the keys M-DOWN and M-UP to navigate through the completions displayed in the completions buffer without leaving the original buffer, and the key M-RET to insert the currently highlighted completion to the buffer. See Completion.
In Text mode and related modes, M-TAB completes words based on the spell-checker’s dictionary. See Checking and Correcting Spelling.
Completion Preview mode is a minor mode that shows completion suggestions as you type. You can enable it for the current buffer with M-x completion-preview-mode, or globally with M-x global-completion-preview-mode. When Completion Preview mode is on, Emacs automatically displays the suggested completion for text around point as an in-line preview right after point; type TAB to accept the suggestion.
On graphical displays, the M-TAB key is usually reserved by the window manager for switching graphical windows, so you should type C-M-i or ESC TAB instead. ↩︎