[TxMt] Intelligent Tag Macro

marios tmtxpstuff at consking.com
Fri Oct 27 12:54:48 UTC 2006


-----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
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (Darwin)
Comment: This might change in the future
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFQgGY8tSzPOYuZvQRApgJAKDRs0Z31MkhBxxLxrsfgvmm738T+wCgiwLz
AdkkOl7b6eB+vv2CozbK220=
=ZtwD
-----END PGP SIGNATURE-----
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Archive.zip
Type: application/zip
Size: 783 bytes
Desc: not available
URL: <http://lists.macromates.com/textmate/attachments/20061027/42bb8df9/attachment.zip>


More information about the textmate mailing list