-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
I had a specific need for a snippet, that would have current word (with fall back to selected text) to generate either a container tag or a single tag, depending on whether the ending forward slash was removed in the tab stop variable or not. I use this for the TXP bundle to generate a plugin tag, since those tags
would not get matched by the insert open/close tag command, (ctrl shift <) since it is impossible to know about all of them.
It uses the following snippet(with capture register 1 to decide weather the closing container tag should be inserted or not :
tag="${TM_CURRENT_WORD:-TM_SELECTED_TEXT}" tags="<txp:${1:$tag}${2: />}$3${2/ />|(.+)/(?1:</txp:$tag> )/}" echo "$tags"
The macro then selects the current word, triggers the command, which has output set as "Insert as Snippet" and tabs over the second tab stop variable.
Not knowing right now where to put it, I assigned it to :( ctrl shift > ) and named it simply: Tag/s
Here is how to use it:
write the tag name, trigger the macro, which will insert a single tag. If that is intended, then pressing one more time tab will leave the caret at the end of the single tag. When the tag is no single tag, the you just type : > and it will mirror itself inserting the corresponding closing tag,leaving a tab stop variable in between.
This is perfect, since I can then just press return and it will do the special HTML return behavior.
You can easily adapt this to your needs, for HTML or anything else. (I forgot to encounter for attributes though)
regards, marios