Hi, I have done a macro which uses a snippet and a command. The snippet adds the line:
std::cout << "" << std::endl;
And the command checks if iostream is included (using scopeHandler) and if not it includes it. For this to work I have to first run the command and after that insert the snippet. The problem is that if the command inserts the #include <iostream> , the caret moves to the previous line, inserting the snippet there. I have tried with this line at the end of the command (which is in Ruby):
`/usr/local/bin/mate "$TM_FILEPATH" -l $CARET'`
but it makes TextMate freeze.
Anyone knows how to do this? Thanks in advance
José Manuel Polytechnical University of Valencia Spain
On 21/4/2006, at 17:26, José Manuel wrote:
[...] I have tried with this line at the end of the command (which is in Ruby):
`/usr/local/bin/mate "$TM_FILEPATH" -l $CARET'`
but it makes TextMate freeze.
I assume $CARET is the new line number? Try instead this (I wrapped $CARET as I think you meant it to be):
`/usr/local/bin/mate "$TM_FILEPATH" -l #{$CARET} 2>/dev/null &`
An alternative approach is the “replace document with snippet” as recently discussed [1].
Inspired by this letter, I put a macro in the C bundle which inserts missing includes in the top of the document. The key equivalent is ctrl-# -- it’s not perfect, but it’s a good start :)
[1] http://lists.macromates.com/pipermail/textmate/2006-April/ 009742.html
Wow, thank you very much, the new macro should be really usefull. I think I may have a problem with the installation of TextMate, because running /usr/local/bin/mate inside the command makes TextMate freeze. This is the whole command:
#!/usr/bin/env ruby require '/Library/Scripts/scopeHandler.rb' handler = ScopeHandler.new(STDIN)
caret = ENV['TM_LINE_NUMBER'].to_i found = false line = 0 notIncludes = true; for classNode in handler.find_all{|n| (n.scopeName == "string.quoted.lt-gt.include.c") && (n.parent.scopeName == "other.preprocessor.c.include")} notIncludes = false; txt = classNode.data txt = txt.gsub(%r{\A<|>\z},"") if (txt == "iostream") found = true end line = classNode.coords[0] end
if (!found) if (notIncludes) print "#include <iostream>\n" caret +=1 end for textNode in handler.find_all{|n| n.text?} print textNode.data.unescapeScope if ((textNode.coords[0]==line)&& (textNode.data.unescapeScope[-1,1]=="\n")) print "#include <iostream>\n\n" caret +=1 end end else for textNode in handler.find_all{|n| n.text?} print textNode.data.unescapeScope end end
print caret
ENV['CARET'] = caret.to_s
`/usr/local/bin/mate "$TM_FILEPATH" 2>/dev/null &`
This is probably not the best way to do it, but I'm new to this, so feel free to correct me.
José Manuel Sánchez Polytechnical University of Valencia Spain
El 22/04/2006, a las 2:05, Allan Odgaard escribió:
On 21/4/2006, at 17:26, José Manuel wrote:
[...] I have tried with this line at the end of the command (which is in Ruby):
`/usr/local/bin/mate "$TM_FILEPATH" -l $CARET'`
but it makes TextMate freeze.
I assume $CARET is the new line number? Try instead this (I wrapped $CARET as I think you meant it to be):
`/usr/local/bin/mate "$TM_FILEPATH" -l #{$CARET} 2>/dev/null &`
An alternative approach is the “replace document with snippet” as recently discussed [1].
Inspired by this letter, I put a macro in the C bundle which inserts missing includes in the top of the document. The key equivalent is ctrl-# -- it’s not perfect, but it’s a good start :)
[1] http://lists.macromates.com/pipermail/textmate/2006-April/ 009742.html
For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate
On 22/4/2006, at 22:07, José Manuel wrote:
I think I may have a problem with the installation of TextMate, because running /usr/local/bin/mate inside the command makes TextMate freeze. This is the whole command:
Well, running ‘mate’ will make synchronous commands (which are all but those with HTML output) freeze, unless a sub-process is spawned to call ‘mate’.
I tried the following command here, which works for me:
#!/usr/bin/env ruby %x{ mate '#{ENV['TM_FILEPATH']}' -l70 &>/dev/null & }
So try that, and see if it works.