Re: Syntax Colouring
Re: Syntax Colouring
- Subject: Re: Syntax Colouring
- From: Chris Boot <email@hidden>
- Date: Tue, 29 Jul 2003 16:25:00 +0100
Hi,
On Tuesday, Jul 29, 2003, at 15:36 Europe/London, M. Uli Kusterer wrote:
At 13:12 Uhr +0100 29.07.2003, Chris Boot wrote:
I ended up using NSText's textDidChange: delegate method and and
NSMutableAttributesString's addAttributes:range: methods to do the
colouring, which works quite well except for the fact that it slows
to a crawl with any large quantity of text. I am already making sure
that I only colour things that the user could have changed, but
running an NSScanner or regular expression engine over 400K of text
takes a good few seconds. Any suggestions on speeding it up a bit?
I took a similar approach. Several speed-ups I've implemented (or am
planning to implement once I have time to spend on Workbench again)
are:
-> Do the recalc from a timer that is pushed forward while the user is
typing. This means that, as long as the user is typing, syntax
coloring doesn't happen, making it fast. As soon as the user has
stopped typing for a second or three, the timer fires and updates the
syntax coloring.
I've got a timer that I push forward just as you mention, but for a
different task. What I've found in this case though is that if the
colouring takes its time, the user's typing will be delayed until the
timer is over, just as with doing it live. In addition, my application
calls for live colouring; I can't have it done this way. :-(
-> Add a second syntax coloring scheme that locally recolors. E.g.
only recolors the current line, starting at the location where the
user is currently writing, and then moving on to the left and right,
only recoloring more lines when necessary. To aid in that, you can
mark special ranges in the NSAttributedString with your own "style".
E.g. to turn off all syntax coloring if the user is currently inside a
comment, you'd just check whether the style at the insertion mark is
"MyMultiLineComment" or whatever.
NSScanner or OFCharacterScanner can't scan backwards as far as I can
see, so I'd have to roll my own scanner code for this. While I don't
mind doing that, it just seems like there must be a better way of doing
this. I might end up going this route if I can't find anything.
As for setting a custom attribute, I've also tried this, but
NSTextStorage seems to be very slow when setting and retrieving the
attribute for some reason. It slows down my colouring method tenfold
it seems (I have made no exact measurement, just by how it "feels").
BTW -- I'd be willing to share my code and collaborate on a more
generic syntax-coloring solution. This seems to come up a lot in Cocoa
applications.
This certainly would be a handy thing for everybody.
--
Chris Boot
email@hidden
http://www.bootc.net/
"Unix is simple. It just takes a genius to understand its simplicity."
- Dennis Ritchie
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.