On Feb 14, 2005, at 9:01 PM, Jarkko Laine wrote:
On 14.2.2005, at 20:11, James Edward Gray II wrote:
I'm really digging into snippets (and loving them, by the way). One question though, I see $0s used in places and I'm not sure what it does. Could someone explain it to me? Thanks.
$0 is the place where the cursor is placed after the snippet has been run.
Really? I thought that was $1. Then you can tab to $2, $3, etc.
Maybe I didn't ask my question right. Let me try again. I understand $1 through $9, but I didn't know there was a $0 zero and in playing around it seems to behave slightly different from the others. My question is, how does $0 relate to $1 through $9?
Thanks.
James Edward Gray II
On Feb 15, 2005, at 5:08, James Edward Gray II wrote:
$0 is the place where the cursor is placed after the snippet has been run.
Really? I thought that was $1. Then you can tab to $2, $3, etc.
By run I think he means “tabbed to the end”, i.e. gone through all the placeholders.
By default an implicit $0 is placed after your snippet, so e.g. if you write a snippet like: “foo $1 bar $2 fud” the caret starts at $1, you can tab to $2, but you can do a second tab to “leave” the snippet, and you end up just after “fud”, so in fact the snippet is: “foo $1 bar $2 fud$3”.
Sometimes this is not desired, take this snippet:
\begin{$1} $2 \end{$1}
Here we want to end between begin/end, but due to the implicit placeholder at the end of the snippet, a tab will take us outside this block. So instead we make it:
\begin{$1} $0 \end{$1}
Then TextMate knows that you do not want the implicit tab position after the snippet, because you used $0.
Hope that clarifies it...