2 Completion

Apart from real-time validation, the most important feature that nXML mode provides for assisting in document creation is "completion". Completion assists the user in inserting characters at point, based on knowledge of the schema and on the contents of the buffer before point.

nXML mode adapts the standard GNU Emacs command for completion in a buffer: completion-at-point, which is bound to C-M-i and M-TAB. Note that many window systems and window managers use M-TAB themselves (typically for switching between windows) and do not pass it to applications. In that case, you should type C-M-i or ESC TAB for completion, or bind completion-at-point to a key that is convenient for you. In the following, I will assume that you type C-M-i.

nXML mode completion works by examining the symbol preceding point. This is the symbol to be completed. The symbol to be completed may be the empty. Completion considers what symbols starting with the symbol to be completed would be valid replacements for the symbol to be completed, given the schema and the contents of the buffer before point. These symbols are the possible completions. An example may make this clearer. Suppose the buffer looks like this (where ∗ indicates point):

<html xmlns="http://www.w3.org/1999/xhtml">
<h∗

and the schema is XHTML. In this context, the symbol to be completed is ‘h’. The possible completions consist of just ‘head’. Another example, is

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<∗

In this case, the symbol to be completed is empty, and the possible completions are ‘base’, ‘isindex’, ‘link’, ‘meta’, ‘script’, ‘style’, ‘title’. Another example is:

<html xmlns="∗

In this case, the symbol to be completed is empty, and the possible completions are just ‘http://www.w3.org/1999/xhtml’.

When you type C-M-i, what happens depends on what the set of possible completions are.