I was just wondering the following was possible, and I found out it is, but in case other people are wondering, you can include braces in the snippet placeholder text, if you escape the right brace. Why would I want to do that? Suppose I want to use nested placeholders, to allow for optional arguments. For instance imagine a snippet like:
\foo${1:(${2:0},${3:0})}
then this will show up as \foo(0,0) with the entire (0,0) highlighted, so if I don't want it to be there then I can just press delete and continue, or if I want it I can press tab and move to editing each of the two zeros.
This works great in this case, but suppose I want *braces* instead of parentheses (as in most LaTeX commands):
\foo${1:{${2:0},${3:0}}}
As it stands, the second to last brace is matched as closing the placeholder ${1, which leaves the wrong thing highlighted . The trick is to escape it, like so:
\foo${1:{${2:0},${3:0}}}
Very nifty and useful, and not documented I think. My first impulse was to escape the corresponding left brace as well, but it doesn't need (and in fact won't accept) escaping. No sure how I feel about that, it looks asymmetric to me. But hey, it works!
I am now very tempted to change most of the sectioning commands in the LaTeX bundle to make adding labels optional, and combine the stared versions of environment with the non-stared ones.
Haris
On 26/10/2005, at 21.30, Charilaos Skiadas wrote:
As it stands, the second to last brace is matched as closing the placeholder ${1, which leaves the wrong thing highlighted . The trick is to escape it, like so:
\foo${1:{${2:0},${3:0}}}
Very nifty and useful, and not documented I think.
It actually is mentioned in my blog-entry on the subject of snippets (linked to from the TextMate Help Book):
The default value can itself contain variables or shell code. If you want the default text to contain a }, you need to escape it. But all other characters are verbatim.
My first impulse was to escape the corresponding left brace as well, but it doesn't need (and in fact won't accept) escaping. No sure how I feel about that, it looks asymmetric to me. But hey, it works!
The problem is, if I accept arbitrary escapes, \ will have to be \, and these are used e.g. in regexp's (in snippets) -- not to mention regexps matching literal \ in snippets, which would then be \\ -- so for this reason, snippets use very conservative escaping.
On Oct 26, 2005, at 3:54 PM, Allan Odgaard wrote:
It actually is mentioned in my blog-entry on the subject of snippets (linked to from the TextMate Help Book):
The default value can itself contain variables or shell code. If you want the default text to contain a }, you need to escape it. But all other characters are verbatim.
Ah, this indicates I should read the blog more often... sorry.
My first impulse was to escape the corresponding left brace as well, but it doesn't need (and in fact won't accept) escaping. No sure how I feel about that, it looks asymmetric to me. But hey, it works!
The problem is, if I accept arbitrary escapes, \ will have to be \ , and these are used e.g. in regexp's (in snippets) -- not to mention regexps matching literal \ in snippets, which would then be \\ -- so for this reason, snippets use very conservative escaping.
That makes sense. As I said, it works just wonderfully. And the nesting of placeholders is awesome.
Haris