Hi,
is there any difference to insert something as snippet by using a normal tmSnippet and tmCommand which is set to the output 'Insert as Snippet' and input 'selected text or line'?
My problem:
I have a document containing the line:
build_cpu=`echo $ac_cv_build | sed 's/^([^-]*)-([^-]*)-(.*)$/ 1/'` ;
At the end of that line I'd like to insert a snippet '${1:Hallo} World'. If I do it via a tmSnippet it works perfectly. But if I write a tmCommand à la:
Command: in=$(cat) caret=$TM_COLUMN_NUMBER-1 lnhead=${in:0:$caret} lnend=${in:$caret} echo -en "$lnhead${1:Hallo}World$lnend"
Output: Insert as Snippet Input: sel. text or line
it crashes, meaning TM inserts: 'build_cpu= ; HalloWorld'.
Maybe TM has some problems while parsing the line? But as tmSnippet it works? If you change the output to 'Show as Tooltip' the command did the job correctly. I only can guess that if in the line occurs a '$' TM will have problems. And if this is true, what can I do? I already tried to escape all '$' in the variable 'in' but no success.
Any hint would be very helpful. The example as tmCommand I attached to this mail.
Thanks,
Hans
On Mar 31, 2007, at 4:20 PM, Hans-Jörg Bibiko wrote:
Hi,
is there any difference to insert something as snippet by using a normal tmSnippet and tmCommand which is set to the output 'Insert as Snippet' and input 'selected text or line'?
My problem:
I have a document containing the line:
build_cpu=`echo $ac_cv_build | sed 's/^([^-]*)-([^-]*)-(.*)$/ 1/'` ;
At the end of that line I'd like to insert a snippet '${1:Hallo} World'. If I do it via a tmSnippet it works perfectly. But if I write a tmCommand à la:
Command: in=$(cat) caret=$TM_COLUMN_NUMBER-1 lnhead=${in:0:$caret} lnend=${in:$caret} echo -en "$lnhead${1:Hallo}World$lnend"
Output: Insert as Snippet Input: sel. text or line
it crashes, meaning TM inserts: 'build_cpu= ; HalloWorld'.
Maybe TM has some problems while parsing the line? But as tmSnippet it works? If you change the output to 'Show as Tooltip' the command did the job correctly. I only can guess that if in the line occurs a '$' TM will have problems. And if this is true, what can I do? I already tried to escape all '$' in the variable 'in' but no success.
You are outputting the current line, and hence it gets interpreted as a snippet, which means that things like: `echo.....` will be executed as if it was a shell command. ( http://macromates.com/textmate/ manual/snippets#interpolated_shell_code )
Why do you need the command to receive as input Selected text or line? Just set it to selected text or nothing. Wouldn't that do it?
Otherwise, look at the escape.rb library in the global support directory, and its e_sn command.
Any hint would be very helpful. The example as tmCommand I attached to this mail.
Thanks,
Hans
Haris Skiadas Department of Mathematics and Computer Science Hanover College
On 31.03.2007, at 22:44, Charilaos Skiadas wrote:
On Mar 31, 2007, at 4:20 PM, Hans-Jörg Bibiko wrote:
Hi,
is there any difference to insert something as snippet by using a normal tmSnippet and tmCommand which is set to the output 'Insert as Snippet' and input 'selected text or line'?
Why do you need the command to receive as input Selected text or line? Just set it to selected text or nothing. Wouldn't that do it?
Oh my goodness. I didn't see the wood for trees. Thank you for the hint!! Of course, you've right. I thought too complicated.
TM offers you very often a simple solution ;)
Cheers,
Hans