ErgoEmacsEmacsLispBlogEmacsLispBuy Tutorial
Web Hosting by 1&1

20.6.6 Completion Styles

A completion style is a set of rules for generating completions. The user option completion-styles stores a list of completion styles, which are represented by symbols.

— User Option: completion-styles

This is a list of completion style symbols to use for performing completion. Each completion style in this list must be defined in completion-styles-alist.

— Variable: completion-styles-alist

This variable stores a list of available completion styles. Each element in the list must have the form ‘(name try-completion all-completions)’. Here, name is the name of the completion style (a symbol), which may be used in completion-styles-alist to refer to this style.

try-completion is the function that does the completion, and all-completions is the function that lists the completions. These functions should accept four arguments: string, collection, predicate, and point. The string, collection, and predicate arguments have the same meanings as in try-completion (see Basic Completion), and the point argument is the position of point within string. Each function should return a non-nil value if it performed its job, and nil if it did not (⁖, if there is no way to complete string according to the completion style).

When the user calls a completion command, such as minibuffer-complete (see Completion Commands), Emacs looks for the first style listed in completion-styles and calls its try-completion function. If this function returns nil, Emacs moves to the next completion style listed in completion-styles and calls its try-completion function, and so on until one of the try-completion functions successfully performs completion and returns a non-nil value. A similar procedure is used for listing completions, via the all-completions functions.

By default, completion-styles-alist contains five pre-defined completion styles: basic, a basic completion style; partial-completion, which does partial completion (completing each word in the input separately); emacs22, which performs completion according to the rules used in Emacs 22; emacs21, which performs completion according to the rules used in Emacs 21; and initials, which completes acronyms and initialisms.

blog comments powered by Disqus