So what we´d need is a dtd interpreter? Implementing bbedit cmd-m style inserting should be fairly easy to implement given two new features in the Commands implementation;
1. "TM_CURRENT_BLOCK" environment variable. (TextMate must know this already to handle folding.)
and
2. "Select value from list, and insert at caret" Standard output, for commands.
this way, using Commands, we can pass '<div>', '<ul id="menu">','div' or whatever from my hypothetical TM_CURRENT_BLOCK variable to an external script and make that return newline separated valid tags for that context.
"Select value from list.." output would then present the result in a list, and allow you to insert your choice at the caret.
This said, what i´d REALLY love would be a SketchUp style ruby API for extending the editor. (http://sketchup.com/forum/list.php?f=6)
hp.