[TxMt] Intelligent Tag Macro
marios
tmtxpstuff at consking.com
Fri Oct 27 18:10:09 UTC 2006
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
marios wrote:
> 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"
>
Ok, wrong thinking, since there isn't such and example in HTML.
This version has attributes, and ommitts the first tab stop which isn't
necessary anyway. So it looks like this now:
dtag="permlink"
tag="${TM_CURRENT_WORD:-$TM_SELECTED_TEXT}"
ctag="${tag:-$dtag}"
tags="<txp:$ctag\${1: insert=\"\${2:0}\"}\${3: />}\$4\${3/
\/>|(.+)/(?1:<\/txp\:$ctag> )/}"
ptags="<txp:$ctag\${1: />}\$2\${1/ \/>|(.+)/(?1:<\/txp\:$ctag> )/}"
if [[ $ctag = "permlink" ]]; then
echo "$ptags"
else echo "$tags"
fi
Even better though, it now handles three different initial cases:
1)The tag name was typed, but there was no selection.
2)The tag name was typed and selected
3)There was no selection and nothing was typed,
Then in the latter case, this will insert a TXP Permlink Tag and once
again it is possible to decide, whether one wants to insert a wrapper or
a single tag.
The Macro on top of the command was necessary in this case, to ged rid
of the Current word, that was typed.
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
iD8DBQFFQkuA8tSzPOYuZvQRAn2VAJ9LWBopewAmZTUkttg1osZZvBJ6kgCdHbFH
MwHQ7YHCMDfVYR6lZ/R2xz8=
=wMsL
-----END PGP SIGNATURE-----
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Archive.zip
Type: application/zip
Size: 837 bytes
Desc: not available
URL: <http://lists.macromates.com/textmate/attachments/20061027/85558608/attachment.zip>
More information about the textmate
mailing list