Node:Completion, Next:Inserting end-tags, Previous:Top, Up:Top
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.
The traditional GNU Emacs key combination for completion in a buffer is M-<TAB>. However, many window systems and window managers use this key combination themselves (typically for switching between windows) and do not pass it to applications. It's hard to find key combinations in GNU Emacs that are both easy to type and not taken by something else. C-<RET> (i.e. pressing the Enter or Return key, while the Ctrl key is held down) is available. It won't be available on a traditional terminal (because it is indistinguishable from Return), but it will work with a window system. Therefore we adopt the following solution by default: use C-<RET> when there's a window system and M-<TAB> when there's not. In the following, I will assume that a window system is being used and will therefore refer to C-<RET>.
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-<RET>, what happens depends on what the set of possible completions are.
<html xmlns="http://www.w3.org/1999/xhtml"> <-!-
C-<RET> will yield
<html xmlns="http://www.w3.org/1999/xhtml"> <head-!-
<html x-!-
The symbol to be completed is x
. The possible completions
are xmlns
and xml:lang
. These share a
common prefix of xml
. Thus, C-<RET>
will yield:
<html xml-!-
Typically, you would do C-<RET> again, which would have the result described in the next item.
<html xml-!-
Emacs will prompt you in the minibuffer with
Attribute: xml-!-
and the buffer showing possible completions will contain
Possible completions are: xml:lang xmlns
If you input xmlns, the result will be:
<html xmlns="-!-
(If you do C-<RET> again, the namespace URI will be inserted. Should that happen automatically?)