Re: Re: [code] [textadept] I want to contribute

From: Mitchell <m.att.foicica.com>
Date: Fri, 6 Mar 2015 15:38:08 -0500 (EST)

Hi Alejandro,

On Tue, 3 Mar 2015, code wrote:

>> [snip]
>>
>> * While snippets are being expanded, the placeholders are shown in the
>> snippet text (%n and friends). This is done for the sake of simplicity, but
>> there may be a way to hide them using by cleverly using indicators and a
>> table that keeps track of placeholders, positions, and text. I'm not sure
>> this is possible right now, but if you'd like to attempt it, I can give you
>> some more information.
>
> Entirely possible. If you haven't checked out Qt Creator, they have gone
> about and done exactly what you are referring to. Yeah, definitely throw this
> one at me too. Due to my extensive use of the snippets on Textadept, I have
> been eking to do a patch on snippets for a while now anyhow.

Here's some info to help with snippets:

Right now, snippets are inserted as pretty much raw text, including %
placeholders. I use an invisible indicator to mark the current end
position of the snippet for bookkeeping purposes. By using raw text, I am
able to easily move to the next placeholder (on Tab keypress) by searching
for the next "%n", where n is the next placeholder number. Similarly, if I
want to move backwards through placeholders, I can simply restore a saved
text "snapshot".

Your task involves removing the % placeholders from text. That means you
need to parse the snippet text and store placeholders, positions (?), and
metadata (placeholder, default text, is it shell or Lua code?, etc.) in a
table. You'll probably want to use invisible indicators to track
placeholder positions as the user enters placeholder text. One thing to
note is that should only use only ONE indicator for ALL placeholder
indicators. (You don't want to be allocating new indicators for each
placeholder in a snippet.) Instead, you'll differentiate placeholder
indicators from one another with the undocumented
`buffer.indicator_value`[1] property. This allows individual indicators of
the same type to be differentiated, allowing you to create a one-to-one
mapping of indicator instances with metadata or other placeholder
information you created when parsing the snippet text.

Now you'll be able to find the next %n to go to by first searching for the
next indicator, and then using the undocumented
`buffer:indicator_value_at()`[2] with your one-to-one mapping to determine
whether or not that indicator's n is the n you're looking for. If not,
search for the next indicator and repeat the process. (Once you've found
the right indicator, you can repeat the process to set additional carets
for mirrors.)

One part I haven't thought much about is moving backwards through
placeholders. As I mentioned earlier Textadept just keeps a set of
"snapshots" of raw text it can revert to (which makes things easy). I'm
not sure how you're going to do this since indicators do not behave the
same way. Perhaps keeping "snapshots" of indicator positions would be
sufficient.

I hope this is clear and gives you an idea of the direction to take in
tackling this problem. Let me know if you have any questions.

Cheers,
Mitchell

[1]: http://scintilla.org/ScintillaDoc.html#SCI_SETINDICATORVALUE
[2]: http://scintilla.org/ScintillaDoc.html#SCI_INDICATORVALUEAT

-- 
You are subscribed to code.att.foicica.com.
To change subscription settings, send an e-mail to code+help.att.foicica.com.
To unsubscribe, send an e-mail to code+unsubscribe.att.foicica.com.
Received on Fri 06 Mar 2015 - 15:38:08 EST

This archive was generated by hypermail 2.2.0 : Sat 07 Mar 2015 - 06:46:49 EST