[TxMt] Braces inside placeholders
Charilaos Skiadas
cskiadas at uchicago.edu
Wed Oct 26 19:30:54 UTC 2005
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
More information about the textmate
mailing list