[plt-scheme] Custom style ranges in text%

From: Philippe Meunier (meunier at ccs.neu.edu)
Date: Wed Feb 19 15:45:30 EST 2003

Erich Rast wrote:
>I need to associate arbitrary data with ranges of text in a text% 
>subclass, and those ranges ought to work analogous to normal text 
>styles, i.e. they should allow overlapping, automatically get adjusted 
>when a user edits text, etc. So they are sort of custom styles, though 
>not necessarily changing visible properties of the text. (They usually 
>would have a background color.) Additionally, I need to be able to get 
>all custom styles associated with a certain region, get the start and 
>end of a given a custom style found at a given snip position, and the 
>editor ought to save and load the custom styles to/from disk.
>
>So far, I'm unsure how to implement this, because I've still got 
>troubles understanding some of the concepts in text% editors. Could 
>somebody tell me which of the following approaches would work:
>
>1. Custom Styles: Put a new named style into the editor's style list, 
>use change-style to add it or a derived delta of it to a range. 
>Problem: How can I find all such styles at a given position? How would 
>I find the start and end of such a style from a given position within 
>the range---except for looping back and forth?

This doesn't directly solve your problem, but you might want to look
at a "snips and arrows" library I wrote.  There's a doc.txt file that
describes it (available from the help-desk).  You could create a data
structure "range" (refered to as "label" in the doc) corresponding to
a range, and different "snip types", one for each style you want to
apply, and if you give to the library the right functional interface
to your range data structures the library would then be able to do
some of the stuff you want to do.  The library is primeraly meant to
be used with terms (i.e. syntax objects or some other data structure
more or less related to terms) but you could try to coax it into
dealing with ranges covering several terms and have a good chance that
it works.

Things the library can do:
- colors ranges
- tells you which range corresponds to a given position (i.e. it does
the going back and forth for you)
- deals automatically with embedded sub-editors
- allows ranges to be resized through menus

Things it does not do:
- overlapped styles
- work with user edits (in fact, any direct user editing is forbidden)
- save/load from disk
It also assumes that all ranges are defined once for all before
everything is colored (adding new ranges on the fly might work, but I
wouldn't guarantee it and the way the coloring is done it would fairly
slow if you added new ranges very often)

So it's still quite far from what you want, but it might give you an
idea of how to go about doing that stuff and you might be able to
steal some of the code...

>3. Custom solution: Write my own handling of ranges, updating 
>dynamically upon edit operations. Problem: Looks too complicated and 
>error-prone for me.

Yes, error prone is the right expression :-)

Philippe



Posted on the users mailing list.