Let’s wrap up custom user snippet support in TKE by talking about snippet transforms. Transforms allow the snippet writer to make adjustments to text added at tabstops in mirrored tabstops or adjustments to snippet variables. Transformations have the following syntax in snippet text:
${tabstop/regexp/format/opts} OR ${variable/regexp/format/opts}
The tabstop is a mirrored tabstop numerical identifier. When the user enters the original value at the matching tabstop, its value will be parsed and transformed at this location.
The variable is any snippet variable (i.e., CLIPBOARD, DIRECTORY, FILENAME, etc.). The transform will parse the value of the variable and insert the new value in its place.
The regexp value is any legal Tcl regular expression. If parenthesis are used in the regular expression, their matching content will be stored in variables 1, 2 and so on which can be used in the format portion of the transformation.
The format contains information about how to transform the text that matches in the regular expression. With the format value, you can perform the following replacements on the matched text:
${1/<img src="(.*?)">/<img src="$1" alt="$1">/}
<img src="some value">
it will be replaced with <img src="some value" alt="some value">
${1/(-)?(\d+)/(?1:minus:plus) $2/}
${1/(-)?(\d+)/(?1:minus )$2/}
The opts value is an option list of characters that can control the transformation behavior. The only opts value that is supported by TKE is g which will match all occurrences of the regular expression in the value, causing transformations to occur on all matching text.
Now that you are up-to-snuff on how to transform snippet text, consider yourself a snippet power-user and go make the world a better place!