[MonoDevelop] XML Entity Completion Patch

Michael Hutchinson m.j.hutchinson at gmail.com
Sun Dec 14 19:18:18 EST 2008

On Sun, Dec 14, 2008 at 11:13 AM, David A Knight
<david at ritter.demon.co.uk> wrote:
> The attached patch is a first shot at implementing auto completion of
> entities in xml documents.

Thanks for looking at this! I've been wondering about strategies for
entity completion for a while, but never got around to hacking on

FWIW, I'd call your approach "autoconversion" rather than "completion".

> 1) Typing "&" will result in "&;" being inserted and the cursor being
> placed between the two chars.

Why insert the semicolon? This means the user has to use the cursor
keys to get past it.

There are 2 possible solutions for this:
a) if the user types a semicolon before an entity's semicolon,
interpret this as a move rightwards. This way it doesn't affect typing
b) only insert the semicolon when autocompleting the contents of the entity

> 2) If the cursor is between "&;" and the pressed key isn't a control
> character, or a "#" then the entity will be expanded automatically, e.g.
> typing € will result in the text becoming "&#8364;"
> The default setting is for this to be turned off.

With some tweaks, I think it could be on by default.

For example, user types "&" then "<". MD replaces the "<" with "lt;"
and moves the cursor after the semicolon. Since &< isn't a valid thing
to have in XML, this won't interfere with valid typing.

> To be more robust it probably should be checking if it is in a CDATA
> section or <% %> etc.

Definitely, and this will be much easier when the XML editor is ported
to the new BaseXmlEditorExtension that the HTML, ASP.NET completion
extensions subclass. They maintain a "context engine" that can tell
you what context you're in, so you'd just handle entity completion
when in the "free" or attributevalue" contexts. Right now, your patch
doesn't do anything for the editors that use the newer system anyway.

This port is on my queue for 2.2, unless you want to do it before then :)

> There is a downside with html documents.  If you want to type &quot; for
> example you will end up with &#113; if q is typed.  A possible solution
> for this would be to only do the auto insertion if the character value
> is > 127 or if it is a special char, <,>,",', &

I think that's a must. Completion should never interfere with normal typing.

It would also be nice to have a completion list for named entities
from external DTDs.

> There is no auto mapping to the standard xml named entities, e.g. <
> doesn't become &lt; etc.

I imagine that's not hard to special-case for the common ones. Using
entities from DTDs probably isn't worth the effort at this point.
Since the common ones are... common... I think it's important that
the're supported in the first pass.

Another possible activation for entity completion would be to convert
invalid characters directly into entities automatically. This would be
very convenient for the characters that have no valid use, but
wouldn't work for things like ampersands, so we'd still need to
implement the other kinds of completion/conversion.

Michael Hutchinson

More information about the Monodevelop-list mailing list