Hiya. My current project is an XML editor using the Tkinter.Text widget. Using the parsing tools from xml.parsers.expat, I've managed to implement a nice system of syntax highlighting when the document is first loaded. However, I want the user to be able to edit the text, and have the highlightling automatically update to conform to whatever is added or deleted. I can easily do this for single-line tags (those that start and end on the same line), because then I can just read in that one line and use the parser to re-highlight it. But for multiple-line tags, like comments or CDATA sections, it's not so easy.

The problem is that the exact location where the user inserts/removes text, will determine how the highlighting changes. For example, a comment block is delimeted by <!-- and --> Now, if the user types new text BETWEEN those two tags, nothing changes; the new text gets the existing "comment" highlighting that's already there. If they type new text on the same line as one of the delimeters, but outside their range, it gets no tags at all. But if the new text is INSIDE one of the delimeters themselves (making them no longer syntactically valid), then the whole comment block needs to get re-highlighted. And I don't know how to do that without re-highlighting the WHOLE document all over again. When that happens with every single keystroke, it adds up to a whole lot of highlighting. There's got to be a better way, but I can't think of one. Can anyone help?

And by the way, I already know about the xmltools package from logilab, and it might be exactly what I need. However, I'm working on this project at my office, not at home; so I have to rely on the sysadmins to install new packages. And the xmltools package will require a LOT of dependancies, so it doesn't look like it'll be done any time in the near future. :-(


P.S. On a totally unrelated note, how do I reply to messages on this board and get them to appear in "nested thread" format? Every time I reply, it always appears as a new top-level thread!
_______________________________________________
Tkinter-discuss mailing list
[email protected]
http://mail.python.org/mailman/listinfo/tkinter-discuss

Reply via email to