You'd need to wire up your table with the after-insert and
after-delete methods, invalidating the appropriate parts. The behavior
you seem to want below is simple calls into the data/enumerate library
and more interesting invalidation is possible if you wish it.

And you want to look at text%, not editor<%>. Some of the mixins in
the framework may also be interesting to you.

You can do all the same fancyness if you have the data structure
parallel to the snip%s, of course. And it means you don't have to deal
with saving the information in files, which what snips are designed
for.

Robby


On Wed, Dec 9, 2015 at 2:18 PM, David Christiansen
<da...@davidchristiansen.dk> wrote:
> Thanks for a fast answer, and for the recommendation!
>
> Right, it's all from the compiler. When the user opens a file, it is
> normal text; type checking turns it into an angry fruit salad of
> semantic information.
>
> Is there a way to automatically keep these things updated as the user
> edits the text? Ideally, if I edit the text "Nat", its semantic
> highlight should disappear, but all of the others should remain valid
> until the user type-checks the buffer again or edits them. In Emacs, I
> implement this kind of thing with overlays and markers, which stay
> synchronized with buffer positions as text is edited, but I don't see
> any way to mark a position in an `editor%' such that it moves according
> to insertions. Type checking an Idris module is fairly heavy, so I don't
> want to do it without the user asking for it, but the display should
> still look as nice as possible underway. This is why I was turning to a
> custom snip. A custom snip also seems to let the display be a bit more
> fancy, e.g. lighting up when the mouse goes over a semantic tag.
>
> Thanks!
>
> /David
>
> On 09/12/15 21:08, Robby Findler wrote:
>> My experience with this kind of thing suggests that keeping separate
>> tables on the side that map ranges in the editor to whatever
>> information you want is simpler and better. (Eg, check syntax.) Check
>> out data/interval-map.
>>
>> You don't want to save this information when the user saves, right?
>> That is, the user doesn't edit the file to insert this information;
>> it's all generated by the compiler, right?
>>
>> Robby
>>
>> On Wed, Dec 9, 2015 at 1:59 PM, David Christiansen
>> <da...@davidchristiansen.dk> wrote:
>>> Hi all,
>>>
>>> Summary:
>>>
>>> Do I need to do anything over and above defining `get-count' and
>>> `partial-offset' in a custom snip that has multiple items in order to
>>> have it work properly in an editor derived from `text%'?
>>>
>>> Details:
>>>
>>> I'm in the process of making a library to interface Racket with the
>>> Idris compiler, so that I can use the Racket slideshow language to make
>>> nifty interactive presentations that feature live Idris demos. As a part
>>> of doing this, I'm developing editors for Idris code and Idris REPLs.
>>>
>>> This library uses Idris's machine-readable REPL syntax, just like the
>>> Emacs and Atom modes. This will sometimes send strings to be shown to
>>> the user along with a list of offset-length-metadata triples that give
>>> additional information about the contents of the string (for example,
>>> that a certain three-character region refers to the qualified name
>>> "Prelude.Nat" with type "Type" and documentation summary "Unary natural
>>> numbers", and that the referent of this name is itself a type).
>>>
>>> What I want to do is to highlight some of these substrings by replacing
>>> them with a custom snip class that has a particular display, along with
>>> easy access to things like additional commands from the Idris compiler.
>>> Basically, they'll get a fancy UI, but most of the fanciness will be not
>>> immediately visible. When a user modifies the items (= characters) in
>>> the snip, it should revert back to an ordinary `string-snip%'.
>>>
>>> My problem is that, once I've replaced a portion of an editor with my
>>> custom snip class, the inserted snip is only considered to be one item
>>> long for purposes of calculating positions later in the editor. I've
>>> overridden get-count and partial-offset according to the instructions,
>>> and I believe that they are correct. Because this snip class simply has
>>> a field that is the string being highlighted, it has a field
>>> `display-name' that is the string to show. My `get-count' simply returns
>>> the length of this string, and I believe that `partial-offset' is
>>> correct because moving the caret over the new snip precisely highlights
>>> the width of the first character in blue.
>>>
>>> Do I need to do anything more to register this snip as containing
>>> multiple items, and to have its count taken into consideration when
>>> calculating positions and moving the caret?
>>>
>>> Thanks in advance!
>>> /David
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups 
>>> "Racket Users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send an 
>>> email to racket-users+unsubscr...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to