Implemented better custom tag handling.

I needed to make it easier to handle scopes and define custom tags,
including context-sensitive tags.