mirror of
https://github.com/joaotavora/yasnippet.git
synced 2025-10-14 05:23:04 +00:00
* misc improvements
This commit is contained in:
parent
c59e4bb36f
commit
b57c33fe7b
@ -111,11 +111,15 @@ class TmSubmenu
|
|||||||
string += str + "\"" + submenu.name + "\""
|
string += str + "\"" + submenu.name + "\""
|
||||||
string += submenu.to_lisp(allsubmenus, deleteditems,
|
string += submenu.to_lisp(allsubmenus, deleteditems,
|
||||||
indent + str.length + thingy[0].length)
|
indent + str.length + thingy[0].length)
|
||||||
elsif TmSnippet::snippets_by_uid[uuid]
|
elsif snippet = TmSnippet::snippets_by_uid[uuid]
|
||||||
|
string += ";; " + snippet.name + "\n"
|
||||||
|
string += " " * (indent + thingy[0].length)
|
||||||
string += "(yas/item \"" + uuid + "\")"
|
string += "(yas/item \"" + uuid + "\")"
|
||||||
elsif (uuid =~ /---------------------/)
|
elsif (uuid =~ /---------------------/)
|
||||||
string += "(yas/separator)"
|
string += "(yas/separator)"
|
||||||
else
|
else
|
||||||
|
string += ";; An external, misterious item\n"
|
||||||
|
string += " " * (indent + thingy[0].length)
|
||||||
string += "(yas/external-item \"" + uuid + "\")"
|
string += "(yas/external-item \"" + uuid + "\")"
|
||||||
end
|
end
|
||||||
first = false;
|
first = false;
|
||||||
@ -139,9 +143,7 @@ class TmSubmenu
|
|||||||
|
|
||||||
closing = "\n '("
|
closing = "\n '("
|
||||||
closing+= mainmenu["excludedItems"].collect do |uuid|
|
closing+= mainmenu["excludedItems"].collect do |uuid|
|
||||||
snippet = TmSnippet::snippets_by_uid[uuid]
|
"\"" + uuid + "\""
|
||||||
|
|
||||||
"\"" + (snippet ? snippet.name : uuid) + "\""
|
|
||||||
end.join( "\n ") + "))"
|
end.join( "\n ") + "))"
|
||||||
|
|
||||||
str = "(yas/define-menu "
|
str = "(yas/define-menu "
|
||||||
@ -174,21 +176,24 @@ class TmSnippet
|
|||||||
"${0:$TM_SELECTED_TEXT}" => "${0:`yas/selected-text`" },
|
"${0:$TM_SELECTED_TEXT}" => "${0:`yas/selected-text`" },
|
||||||
"condition" => {
|
"condition" => {
|
||||||
/^source\..*$/ => "" },
|
/^source\..*$/ => "" },
|
||||||
"binding" => {}
|
"binding" => {},
|
||||||
|
"type" => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
def self.extra_substitutions; @@extra_substitutions; end
|
def self.extra_substitutions; @@extra_substitutions; end
|
||||||
@@extra_substitutions = {
|
@@extra_substitutions = {
|
||||||
"content" => {},
|
"content" => {},
|
||||||
"condition" => {},
|
"condition" => {},
|
||||||
"binding" => {}
|
"binding" => {},
|
||||||
|
"type" => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
def self.unknown_substitutions; @@unknown_substitutions; end
|
def self.unknown_substitutions; @@unknown_substitutions; end
|
||||||
@@unknown_substitutions = {
|
@@unknown_substitutions = {
|
||||||
"content" => {},
|
"content" => {},
|
||||||
"condition" => {},
|
"condition" => {},
|
||||||
"binding" => {}
|
"binding" => {},
|
||||||
|
"type" => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@snippets_by_uid={}
|
@@snippets_by_uid={}
|
||||||
@ -200,6 +205,7 @@ class TmSnippet
|
|||||||
@snippet = TmSnippet::read_plist(file)
|
@snippet = TmSnippet::read_plist(file)
|
||||||
@@snippets_by_uid[self.uuid] = self;
|
@@snippets_by_uid[self.uuid] = self;
|
||||||
raise SkipSnippet.new "not a snippet/command/macro." unless (@snippet["scope"] || @snippet["command"])
|
raise SkipSnippet.new "not a snippet/command/macro." unless (@snippet["scope"] || @snippet["command"])
|
||||||
|
raise SkipSnippet.new "looks like preferences."if @file =~ /Preferences\//
|
||||||
raise RuntimeError.new("Cannot convert this snippet #{file}!") unless @snippet;
|
raise RuntimeError.new("Cannot convert this snippet #{file}!") unless @snippet;
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -219,6 +225,10 @@ class TmSnippet
|
|||||||
yas_directive "condition"
|
yas_directive "condition"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def type
|
||||||
|
yas_directive "type"
|
||||||
|
end
|
||||||
|
|
||||||
def binding
|
def binding
|
||||||
yas_directive "binding"
|
yas_directive "binding"
|
||||||
end
|
end
|
||||||
@ -233,27 +243,26 @@ class TmSnippet
|
|||||||
@@known_substitutions["content"].
|
@@known_substitutions["content"].
|
||||||
merge(@@extra_substitutions["content"]).
|
merge(@@extra_substitutions["content"]).
|
||||||
each_pair do |k,v|
|
each_pair do |k,v|
|
||||||
if (k != uuid)
|
|
||||||
content.gsub!(k,v)
|
content.gsub!(k,v)
|
||||||
else
|
end
|
||||||
content = v
|
# the remaining stuff is an unknown substitution
|
||||||
|
#
|
||||||
|
[ %r'\$\{ [^/\}\{:]* / [^/]* / [^/]* / [^\}]*\}'x ,
|
||||||
|
%r'\$\{[^\d][^}]+\}'x ,
|
||||||
|
%r'`[^`]+`'
|
||||||
|
].each do |reg|
|
||||||
|
content.scan(reg) do |match|
|
||||||
|
@@unknown_substitutions["content"][match] = self
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
content.scan(%r'\$\{ [^/\}\{:]* /
|
return content
|
||||||
[^/]* /
|
|
||||||
[^/]* /
|
|
||||||
[^\}]*\}'x) do |match|
|
|
||||||
@@unknown_substitutions["content"][match] = self
|
|
||||||
end
|
|
||||||
else
|
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_yas
|
def to_yas
|
||||||
doc = "# -*- mode: snippet -*-\n"
|
doc = "# -*- mode: snippet -*-\n"
|
||||||
doc << "# type: command\n" unless self.content
|
doc << (self.type || "")
|
||||||
doc << "# uuid: #{self.uuid}\n"
|
doc << "# uuid: #{self.uuid}\n"
|
||||||
doc << "# key: #{self.key}\n" if self.key
|
doc << "# key: #{self.key}\n" if self.key
|
||||||
doc << "# contributor: Translated from TextMate Snippet\n"
|
doc << "# contributor: Translated from TextMate Snippet\n"
|
||||||
@ -296,31 +305,23 @@ class TmSnippet
|
|||||||
|
|
||||||
@@yas_to_tm_directives = {"condition" => "scope", "binding" => "keyEquivalent", "key" => "tabTrigger"}
|
@@yas_to_tm_directives = {"condition" => "scope", "binding" => "keyEquivalent", "key" => "tabTrigger"}
|
||||||
def yas_directive(yas_directive)
|
def yas_directive(yas_directive)
|
||||||
tm_directive = @@yas_to_tm_directives[yas_directive]
|
if direct = @@known_substitutions[yas_directive].
|
||||||
val = @snippet[tm_directive]
|
merge(@@extra_substitutions[yas_directive])[uuid]
|
||||||
found = false
|
return "# #{yas_directive}: "+ direct + "\n" unless direct.empty?
|
||||||
# puts "Looking for a substitution for #{val}"
|
else
|
||||||
if val and !val.delete(" ").empty?
|
tm_directive = @@yas_to_tm_directives[yas_directive]
|
||||||
@@known_substitutions[yas_directive].
|
val = tm_directive && @snippet[tm_directive]
|
||||||
merge(@@extra_substitutions[yas_directive]).
|
if val and !val.delete(" ").empty? then
|
||||||
each_pair do |k, v|
|
# puts "Looking for a substitution for #{val}"
|
||||||
if (k == uuid)
|
@@known_substitutions[yas_directive].
|
||||||
val = v
|
merge(@@extra_substitutions[yas_directive]).
|
||||||
found = true
|
each_pair do |k, v|
|
||||||
break
|
if val.gsub!(k,v)
|
||||||
elsif val.gsub!(k,v)
|
return "# #{yas_directive}: "+ val + "\n" unless val.empty?
|
||||||
# puts "#{@snippet[tm_directive]} matched #{k} so replacing with #{v}"
|
end
|
||||||
found = true
|
|
||||||
break
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
if found
|
|
||||||
# puts "found substitution for #{yas_directive} : #{val}"
|
|
||||||
"# #{yas_directive}: "+ val + "\n" unless val.empty?
|
|
||||||
else
|
|
||||||
# puts "found this unknown substitutions for #{yas_directive} : #{val}"
|
|
||||||
@@unknown_substitutions[yas_directive][val] = self
|
@@unknown_substitutions[yas_directive][val] = self
|
||||||
"## #{yas_directive}: \""+ val + "\n"
|
return "## #{yas_directive}: \""+ val + "\n"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -358,7 +359,7 @@ if $0 == __FILE__
|
|||||||
tail ||= ""
|
tail ||= ""
|
||||||
head ||= ""
|
head ||= ""
|
||||||
directive = nil
|
directive = nil
|
||||||
puts "get this head #{head}"
|
# puts "get this head #{head}"
|
||||||
head.each_line do |line|
|
head.each_line do |line|
|
||||||
case line
|
case line
|
||||||
when /^;; Substitutions for:(.*)$/
|
when /^;; Substitutions for:(.*)$/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user