diff --git a/extras/textmate_import.rb b/extras/textmate_import.rb index d5438e0..71f641d 100755 --- a/extras/textmate_import.rb +++ b/extras/textmate_import.rb @@ -103,7 +103,8 @@ class TmSnippet def initialize(file,info=nil) @file = file @info = info - @snippet = Plist::parse_xml(file) + @snippet = TmSnippet::read_plist(file) + raise RuntimeError.new("Cannot convert this snippet #{file}!") unless @snippet; end def name @@ -177,12 +178,27 @@ class TmSnippet File.join(basedir,canonicalize(@file[0, @file.length-File.extname(@file).length]) + ".yasnippet") end + def self.read_plist(xml_or_binary) + begin + parsed = Plist::parse_xml(xml_or_binary) + return parsed if parsed; + raise RuntimeError.new "Probably in binary format and parse_xml is very quiet..." + rescue RuntimeError => e + if (system "plutil -convert xml1 '#{xml_or_binary}' -o /tmp/textmate_import") + return Plist::parse_xml("/tmp/textmate_import") + else + raise RuntimeError.new "plutil failed miserably, check if you have it..." + end + end + end + end -if $0 == __FILE__ - info_plist = Plist::parse_xml(Choice.choices.info_plist) if Choice.choices.info_plist +if $0 == __FILE__ + + info_plist = TmSnippet::read_plist(Choice.choices.info_plist) if Choice.choices.info_plist; if Choice.choices.output_dir FileUtils.mkdir_p Choice.choices.output_dir @@ -217,7 +233,7 @@ if $0 == __FILE__ puts "\n\n" end rescue Exception => e - $stderr.puts "Oops... #{e.class}:#{e.message}" + $stderr.puts "Oops... #{e.class}:#{e.message}\n#{e.backtrace.join("\n")}" end end end