[TxMt] Newbie Q- How to Auto Format Code?

AliAli ali at tombola.com
Fri Oct 19 08:36:34 UTC 2007


Hey Ale, thanks for your help and sorry it's taken so long for me to reply. I
have started putting some effort into using Textmate and am really enjoying
it. I've tried to get your 'Validate Syntax' snippet to work but I get an
error message:

/tmp/temp_textmate.dRzeHI:32: syntax error
if errors.empty? && warnings.empty?

I think it is probably down to me copying the code for the snippet
incorrectly but I'm not totally sure what I'm doing, I copied the code in
the string node (below)
If you could point out what I'm doing wrong I would be really grateful.
Cheers!
Ali

http://www.nabble.com/file/p13290317/validate%2Bsyntax.jpg 
#!/usr/bin/env ruby

require 'open3'
require ENV["TM_SUPPORT_PATH"] + "/lib/web_preview"
require ENV['TM_SUPPORT_PATH'] + "/lib/exit_codes"

filename = ENV['TM_FILEPATH']

cmd = "'#{ENV['TM_BUNDLE_SUPPORT']}/bin/mtasc' '#{filename}'"

stdin, stdout, stderr = Open3.popen3(cmd)

warnings = []
errors = []
while err = stderr.gets
if err[0, 10] == 'Warning : '
  warnings.push(err.chomp)
else
  m = /(.+):([0-9]+): characters ([0-9]+)-([0-9]+) : (.+)/.match(err)
  if m != nil
    if /^\//.match(m[1])
      real_path = m[1]
    else
      real_path = Dir.pwd + "/" + m[1]
    end
    a =
"txmt://open?url=file://#{real_path}&line=#{m[2]}&column=#{m[3].to_i
+ 1}"
    err = "<a href=\"#{a}\">#{File.basename(m[1])}, Line: #{m[2]}
Column: #{m[3].to_i + 1} - #{m[5]}</a>"
  end
  errors.push(err.chomp)
end
end
if errors.empty? && warnings.empty?
puts "Syntax Ok"
TextMate.exit_show_tool_tip
else
html_header("Validating Syntax for #{File.basename(filename)}","Validate
Syntax")
if !errors.empty?
  puts "<h2>Errors</h2>"
  puts errors
end
if !warnings.empty?
  puts "<h2>Warnings</h2>"
  puts warnings
end
html_footer
TextMate.exit_show_html
end

 

bomberstudios wrote:
> 
> On 9/10/07, Ale Muñoz <bomberstudios at gmail.com> wrote:
>>
>> Hmmm... there's no 'Check Syntax' command on the ActionScript
>> bundle... but now that you mention it, it looks like a good addition
>> to the arsenal...
>>
> 
> 
> Talk about good timing. I had to debug some stuff for a project, and
> thought this command would be *very* useful.
> 
> Thus, I've pushed a new "Validate Syntax" command to the repository.
> It's bound to Control + Shift + V, for consistency with other bundles.
> 
> Please try it and see if it works for you.
> 
> 
> -- 
> Ale Muñoz
> http://sofanaranja.com
> http://bomberstudios.com
> 
> 
> ______________________________________________________________________
> For new threads USE THIS: textmate at lists.macromates.com
> (threading gets destroyed and the universe will collapse if you don't)
> http://lists.macromates.com/mailman/listinfo/textmate
> 

-- 
View this message in context: http://www.nabble.com/Newbie-Q--How-to-Auto-Format-Code--tf4418296.html#a13290317
Sent from the textmate users mailing list archive at Nabble.com.




More information about the textmate mailing list