[TxMt] Re: Placeholders within transformations in snippets

Allan Odgaard mailinglist at textmate.org
Tue Dec 2 12:58:31 UTC 2014


On 2 Dec 2014, at 1:47, Nigel Chapman wrote:

> I’m trying to write a snippet to insert operator declarations in 
> Swift.
> […] I assume this is because in that context $3 and $4 refer to 
> captures from the regular expression. Is that so? Is there any way 
> round this?

Correct. A snippet can’t insert new placeholders via the format 
string.

An approximation would be something like this:

	${1|infix,prefix,postfix|} operator ${2:name} 
{${1/(infix)|.*/${1:+\n\tassociativity 
}/}${3:${1/(infix)|.*/${1:+left}/}}${1/(infix)|.*/${1:+\n\tprecedence 
}/}${4:${1/(infix)|.*/${1:+level}/}}${1/(infix)|.*/${1:+\n}/}$0}

Or somewhat pretty-printed:

	${1|infix,prefix,postfix|} operator ${2:name} {
		${1/(infix)|.*/${1:+\n\tassociativity }/}
		${3:${1/(infix)|.*/${1:+left}/}}
		${1/(infix)|.*/${1:+\n\tprecedence }/}
		${4:${1/(infix)|.*/${1:+level}/}}
		${1/(infix)|.*/${1:+\n}/}
	$0}


More information about the textmate mailing list