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

From: Mitchell <>
Date: Sat, 6 May 2017 18:42:10 -0400 (EDT)

Hi Sebastian,

On Wed, 3 May 2017, cryo shock wrote:

> X Hi Mitchell, I found a way to recreate the strange behaviour where
> TA deletes the first symbol in the first line of a document, when a certain
> placeholder is manually deleted BEFORE using TAB-key to switch from
> placeholder
> to placeholder. I will upload this document as *.txt in case it is
> necessary.
> First, notice that this text starts with "X Hi". I will come back to this.
> The snippet in my init.lua is
> snippets.trow = '\\NC %1 \\NC %2 \\NC %3 \\NC\\NR'
> (Note that I didn't use the %0 placeholder, so the last one is %3, which
> should be the final position naturally.
> Yet after testing I can say that %0 and %n seem to behave the same)
> When I type the keyword "trow" and TAB-key to place the snippet in a
> document, then the result looks like this:
> \NC \NC \NC \NC\NR
> [Note at this point, that placeholders are not saved (in textfiles only?),
> when you reopen this textfile.

Right, placeholders are not saved as file contents. They go away if you
re-open the file.

> If so, place your cursor at the line above anyway: notice the space at the
> end of the line?
> It is not specified in the snippet code.]

Yes, this is a sentinel in order for Textadept's snippet system to know
where the end of a snippet is. It will be removed in the end.

> Visually you can see two of three placeholder rectangles, as after
> insertion the cursor was placed in the first placeholder,
> so that its rectangle disappeared. But in fact there are four placeholders
> when a the snippet is pasted:
> Insert the snippet. While remaining the text in this state, place your
> cursor at the very end of the pasted snippet.
> Notice that there is another placeholder (without visible rectangle). Now
> delete this placeholder
> and press TAB-key: TA jumps to the first line of the document and deletes
> the "X".

When you start deleting placeholders out of order, weird things can
happen, as you've discovered.

> Another easter egg I found is: place the snippet two times, delete the very
> last placeholder at the end of the second
> line and see what happens; I get a message:
> D:\textadept/modules/textadept\snippets.lua:552: attempt to index a nil
> value (local 'ph')
> This "fourth" placeholder remains until all placeholders within the snippet
> have been switched through with TAB.
> I know now how to circumvent this, but if this were somehow fixable, I
> would enjoy your work even more once again.

Generally, if you try to break the snippet system, you will succeed. I
don't know how to make it work all the time. It was designed for inserting
placeholders in order, and allowing most use-cases of nested snippets. I
don't think yours is a common use case. Sorry if I'm misunderstanding


You are subscribed to
To change subscription settings, send an e-mail to
To unsubscribe, send an e-mail to
Received on Sat 06 May 2017 - 18:42:10 EDT

This archive was generated by hypermail 2.2.0 : Sun 07 May 2017 - 06:38:26 EDT