mirror of
https://github.com/joaotavora/yasnippet.git
synced 2025-10-13 21:13:04 +00:00
* Skips file that probably aren't snippets
* Does not allow quotes in generated file names * Remove some substitutions
This commit is contained in:
parent
4a8651f34f
commit
6b07c4b1d6
@ -16,6 +16,7 @@ require 'rubygems'
|
|||||||
require 'plist'
|
require 'plist'
|
||||||
require 'choice'
|
require 'choice'
|
||||||
require 'FileUtils'
|
require 'FileUtils'
|
||||||
|
require 'Shellwords' # String#shellescape
|
||||||
require 'ruby-debug' if $DEBUG
|
require 'ruby-debug' if $DEBUG
|
||||||
|
|
||||||
Choice.options do
|
Choice.options do
|
||||||
@ -49,7 +50,7 @@ Choice.options do
|
|||||||
end
|
end
|
||||||
|
|
||||||
option :quiet do
|
option :quiet do
|
||||||
short '-v'
|
short '-q'
|
||||||
long '--quiet'
|
long '--quiet'
|
||||||
desc 'Be quiet.'
|
desc 'Be quiet.'
|
||||||
end
|
end
|
||||||
@ -153,6 +154,7 @@ end
|
|||||||
# far.
|
# far.
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
class SkipSnippet < RuntimeError; end
|
||||||
class TmSnippet
|
class TmSnippet
|
||||||
@@known_substitutions=[
|
@@known_substitutions=[
|
||||||
{
|
{
|
||||||
@ -161,9 +163,12 @@ class TmSnippet
|
|||||||
"${TM_RAILS_TEMPLATE_START_RUBY_INLINE}" => "<% ",
|
"${TM_RAILS_TEMPLATE_START_RUBY_INLINE}" => "<% ",
|
||||||
"${TM_RAILS_TEMPLATE_END_RUBY_INLINE}" => " -%>",
|
"${TM_RAILS_TEMPLATE_END_RUBY_INLINE}" => " -%>",
|
||||||
"${TM_RAILS_TEMPLATE_END_RUBY_BLOCK}" => "end" ,
|
"${TM_RAILS_TEMPLATE_END_RUBY_BLOCK}" => "end" ,
|
||||||
"${0:$TM_SELECTED_TEXT}" => "$TM_SELECTED_TEXT$0",
|
"${0:$TM_SELECTED_TEXT}" => "${0:`yas/selected-text`",
|
||||||
},
|
},
|
||||||
{ "$TM_SELECTED_TEXT" => "`yas/selected-text`" }
|
{
|
||||||
|
#substitutions that have to take place
|
||||||
|
#after the first group
|
||||||
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
@@snippets_by_uid={}
|
@@snippets_by_uid={}
|
||||||
@ -174,7 +179,8 @@ class TmSnippet
|
|||||||
@info = info
|
@info = info
|
||||||
@snippet = TmSnippet::read_plist(file)
|
@snippet = TmSnippet::read_plist(file)
|
||||||
@@snippets_by_uid[self.uuid] = self;
|
@@snippets_by_uid[self.uuid] = self;
|
||||||
raise RuntimeError.new("Cannot convert this snippet #{file}!") unless @snippet;
|
raise SkipSnippet.new "not a snippet/command/macro." unless (scope || @snippet["command"])
|
||||||
|
raise RuntimeError.new("Cannot convert this snippet #{file}!") unless @snippet;
|
||||||
end
|
end
|
||||||
|
|
||||||
def name
|
def name
|
||||||
@ -234,8 +240,8 @@ class TmSnippet
|
|||||||
doc
|
doc
|
||||||
end
|
end
|
||||||
|
|
||||||
def canonicalize(filename)
|
def self.canonicalize(filename)
|
||||||
invalid_char = /[^ a-z_0-9.+=~(){}\/'"'"'`&#,-]/i
|
invalid_char = /[^ a-z_0-9.+=~(){}\/'`&#,-]/i
|
||||||
|
|
||||||
filename.
|
filename.
|
||||||
gsub(invalid_char, ''). # remove invalid characters
|
gsub(invalid_char, ''). # remove invalid characters
|
||||||
@ -245,7 +251,7 @@ class TmSnippet
|
|||||||
|
|
||||||
def yasnippet_file(basedir)
|
def yasnippet_file(basedir)
|
||||||
# files cannot end with dots (followed by spaces) on windows
|
# files cannot end with dots (followed by spaces) on windows
|
||||||
File.join(basedir,canonicalize(@file[0, @file.length-File.extname(@file).length]) + ".yasnippet")
|
File.join(basedir,TmSnippet::canonicalize(@file[0, @file.length-File.extname(@file).length]) + ".yasnippet")
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.read_plist(xml_or_binary)
|
def self.read_plist(xml_or_binary)
|
||||||
@ -254,8 +260,8 @@ class TmSnippet
|
|||||||
return parsed if parsed
|
return parsed if parsed
|
||||||
raise RuntimeError.new "Probably in binary format and parse_xml is very quiet..."
|
raise RuntimeError.new "Probably in binary format and parse_xml is very quiet..."
|
||||||
rescue RuntimeError => e
|
rescue RuntimeError => e
|
||||||
if (system "plutil -convert xml1 '#{xml_or_binary}' -o /tmp/textmate_import")
|
if (system "plutil -convert xml1 #{xml_or_binary.shellescape} -o /tmp/textmate_import.tmpxml")
|
||||||
return Plist::parse_xml("/tmp/textmate_import")
|
return Plist::parse_xml("/tmp/textmate_import.tmpxml")
|
||||||
else
|
else
|
||||||
raise RuntimeError.new "plutil failed miserably, check if you have it..."
|
raise RuntimeError.new "plutil failed miserably, check if you have it..."
|
||||||
end
|
end
|
||||||
@ -299,8 +305,11 @@ if $0 == __FILE__
|
|||||||
puts "--------------------------------------------\n\n"
|
puts "--------------------------------------------\n\n"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
rescue Exception => e
|
rescue SkipSnippet => e
|
||||||
$stderr.puts "Oops... #{e.class}:#{e.message}\n#{e.backtrace.join("\n")}"
|
$stdout.puts "Skipping \"#{file}\": #{e.message}"
|
||||||
|
rescue RuntimeError => e
|
||||||
|
$stderr.puts "Oops.... \"#{file}\": #{e.message}"
|
||||||
|
$strerr.puts "#{e.backtrace.join("\n")}" unless Choice.choices.quiet
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
# Attempt to decypher the menu
|
# Attempt to decypher the menu
|
||||||
|
Loading…
x
Reference in New Issue
Block a user