[Tkinter-discuss] Re: Here's a tough one -- dynamic, multi-line XML syntax highlighting

Martin Franklin mart.franklin at gmail.com
Sat Apr 2 17:52:01 CEST 2005

Jared Cohen wrote:
> 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. :-(


I've Been away so only just spotted this message have you looked at the
ColorDelagator class in idlelib?  It is very fast. I am don't know how
easy it would be to change it syntax rules, but I'm sure it beats
rolling your own colourizer...


More information about the Tkinter-discuss mailing list