This is a gigantic feature request, but I’d argue it’s worth the effort to implement.
Since 1.x, TextMate has supported snippet “transformations” (see section 7.7) that allow certain tab stops to run a regex substitution on their contents before being put into the buffer. It's an awesome feature and one of the things I dearly miss, since there's no easy way to replicate the functionality.
Examples
Make HTML tag pair
Given a snippet:
<${1:p}>$0</${1/\s.*//}>
I can expand this snippet, type div class='row', and end up with
<div class='row'></div>
because the transformation in the latter tab stop replaces the first space and everything after it with an empty string.
Make Markdown banner
Given a snippet:
${1:banner}
${1/./=/}
I can expand this snippet, type Lorem Ipsum, and end up with
Lorem Ipsum
===========
because the transformation in the latter tab stop replaces each character I type with a = character.
Challenges
Based on how snippets are currently implemented, I think this would be quite hard. While a snippet is “active,” the snippets package appears to react only to the Tab key, and doesn’t exert control over how text is inserted. If a numbered tab stop appears in more than one place (“mirroring” in TextMate snippet parlance), the package supports this by creating multiple selections. It would be surprising for a user to see this…
…and then, after some typing, find out that those two selections may not be identical.
So to implement this would probably involve hooking into TextEditor#onDidChange rather than treating transformed tab-stop content as a selection.
I’d be willing to take a stab at this, but I’m opening this issue to test the waters first. It’s possible I might be the only person on earth who cares about this feature.
This is a gigantic feature request, but I’d argue it’s worth the effort to implement.
Since 1.x, TextMate has supported snippet “transformations” (see section 7.7) that allow certain tab stops to run a regex substitution on their contents before being put into the buffer. It's an awesome feature and one of the things I dearly miss, since there's no easy way to replicate the functionality.
Examples
Make HTML tag pair
Given a snippet:
I can expand this snippet, type
div class='row'
, and end up withbecause the transformation in the latter tab stop replaces the first space and everything after it with an empty string.
Make Markdown banner
Given a snippet:
I can expand this snippet, type
Lorem Ipsum
, and end up withbecause the transformation in the latter tab stop replaces each character I type with a
=
character.Challenges
Based on how snippets are currently implemented, I think this would be quite hard. While a snippet is “active,” the snippets package appears to react only to the Tab key, and doesn’t exert control over how text is inserted. If a numbered tab stop appears in more than one place (“mirroring” in TextMate snippet parlance), the package supports this by creating multiple selections. It would be surprising for a user to see this…
…and then, after some typing, find out that those two selections may not be identical.
So to implement this would probably involve hooking into
TextEditor#onDidChange
rather than treating transformed tab-stop content as a selection.I’d be willing to take a stab at this, but I’m opening this issue to test the waters first. It’s possible I might be the only person on earth who cares about this feature.