[plt-scheme] How to store extra data in text% editor
> At Sat, 20 May 2006 15:07:17 +0200, "pascal.delcombel" wrote:
>> I'm trying to use MrEd to develop a little tool to store text, including
>> the
>> Hyperlinks facilities. As documented, I'd like to store text information
>> (with
>> the text% editore class), including some hyperlinks.
>> I tried to derive new classes from editor-data% and editor-data-class%,
>> then I
>> wrote a new class from the text% class, and tried to override the
>> set-region-
>> data and get-region-data methods.
>> Well, I'm puzzled, I don't know what is really the classes hierachy and
>> thefore I struggle in understanding when and where to store the hyperlink
>> (in
>> the write method from the editor-class? Elsewhere?)
>
> The docs were certainly unclear on the following two points:
>
> * The `set-snipclass' and `get-snipclass' methods are not meant to be
> overridden. The `set-snipclass' method stores the given class in a
> way that other editor objects access directly. So, you need to call
> the built-in method.
>
> * The `set-region-data' and `get-region-data' methods *are* meant to be
> overridden. The default `set-region-data' doesn't store anything.
> Instead these methods are called when content is unmarshaled or
> marshaled, respectively.
>
> Meanwhile, if you just need to store hyperlinks when the text is saved
> to a file, you'll need to record the data in a header or footer,
> instead of as region data. It turns out that the region-data methods
> are used for cut-and-paste, but they're not used for file saving and
> loading.
>
> I've improved the docs for the next build. Hopefully this information
> will help you make progress, but don't hesitate to ask more questions.
>
> Matthew
>
>
>
Thanks Matthew for your explanations. Your trick did the job and I did
actually success the write-footer and read-footer modules overriding,
following your recommendations, using a hyperlink class (simple, just 3
fields: tag-begin, tag-end and tag-text).
Now, here is where I'm troubled: imagine I want to add a snip (whatever,
text or picture) in a text with a hyperlink somewhere, then imagine I want
to add text (or picture), before this hyperlink: if the data is not stored
within the snip (or data region), my hyperlink references (begin and end
positions) won't be correct after the insert.
Alternatively, I should have coded the hyperlinks reference update using the
after-delete and after-insert events. Well, I'm forecasting a bad response
time for that solution, but I could be wrong.
Again, many thanks for your previous help.
Pascal