Re: [code] Feature request: snippet._insert should allow replacing the selection

From: Pedro Andres Aranda Gutierrez <>
Date: Mon, 17 Apr 2017 09:11:02 +0200

Happy Easter to everybody!

I have been giving this issue a thought and I think that we may need to
split treatments depending on whether it is the Tab key or not that calls
the function. Something like:

When tab is pressed, we execute the following function

get the word before the cursor and try to find a snippet
if found:
   kill the word before the trigger
   execute the snippet associated to the word
   insert a tab

When we bind a key to a snippet, then we only execute the snippet
associated to the word we indicate in the code

Would that kill recursive snippets?

Best, /PA

On 9 April 2017 at 23:06, cryo shock <> wrote:

> I just wanted to add, that this not only happens when the whole line is
> selected.
> It happens to me even on single words. Point is, that it's not happening
> all the time, only sometimes. Which makes it very difficult to recreate.
> I noticed that it happened to me when I used line wrapping / folding. I
> will try without code folding in the next few days to see whether I am
> mistaken.
> Furthermore I can imagine trouble with code folding, difference between
> selecting text with mouse and keyboard, multiple snippets within a single
> line (code folding), multiple snippets in a specific time or order (kind of
> a buffer problem)...
> I really hope that we can locate and eliminate this "bug". It's really
> annoying to notice in the output that there is a duplicate text.
> Cheers, Sebastian
> 2017-04-07 18:26 GMT+02:00 Mitchell <>:
>> Hi Pedro,
>> On Fri, 7 Apr 2017, Pedro Andres Aranda Gutierrez wrote:
>> In my limited understanding, the main problem is that the code currently
>>> doesn't distinguish between snippet triggered with the '\t' key and
>>> snippet
>>> triggered from the menu or from calling textadept.snippets._insert() in
>>> some Lua code. My main limitation is that I'm not proficient enough in
>>> Lua
>>> to understand the implementation and propose fixes... still learning...
>> Every time you press a key, `core/keys.lua` sees if there's a function
>> assigned to that key. If so, that function is run, and the key is generally
>> not handled any further. With regard to snippets, '\t' is bound to
>> `textadept.snippets._insert()`, so it really is indistinguishable from a
>> menu or user call to `textadept.snippets._insert()`. (The only
>> difference is that `core/keys.lua` is the one calling that function, as
>> opposed to the menu or user code).
>> I have a suspicion that the snippet sentinel is not being set properly
>> (or is being overwritten) only when the entire line is selected.
>> Cheers,
>> Mitchell
>> --
>> You are subscribed to
>> To change subscription settings, send an e-mail to
>> To unsubscribe, send an e-mail to

Fragen sind nicht da um beantwortet zu werden,
Fragen sind da um gestellet zu werden
Georg Kreisler
You are subscribed to
To change subscription settings, send an e-mail to
To unsubscribe, send an e-mail to
Received on Mon 17 Apr 2017 - 03:11:02 EDT

This archive was generated by hypermail 2.2.0 : Mon 17 Apr 2017 - 06:53:38 EDT