mirror of
https://github.com/joaotavora/yasnippet.git
synced 2025-10-14 05:23:04 +00:00
have to admit ruby is pretty amazing
This commit is contained in:
parent
92d0c45589
commit
faea0dfd7e
@ -162,9 +162,8 @@ end
|
||||
#
|
||||
class SkipSnippet < RuntimeError; end
|
||||
class TmSnippet
|
||||
# unix to the rescue
|
||||
#
|
||||
# ack -aho '\${\d/[^/]*/[^/]*/}' imported/ruby-mode/ | sort | uniq
|
||||
|
||||
def self.known_substitutions; @@known_substitutions; end
|
||||
@@known_substitutions ={
|
||||
"content" => [
|
||||
{
|
||||
@ -181,6 +180,12 @@ class TmSnippet
|
||||
} ],
|
||||
"binding" => [ {} ]
|
||||
}
|
||||
def self.unknown_substitutions; @@unknown_substitutions; end
|
||||
@@unknown_substitutions = {
|
||||
"content" => [],
|
||||
"condition" => [],
|
||||
"binding" => []
|
||||
}
|
||||
# now add some more substitutions
|
||||
# TODO: find a better way to add more substitutions
|
||||
#
|
||||
@ -240,8 +245,13 @@ class TmSnippet
|
||||
content.gsub!(k,v)
|
||||
end
|
||||
end
|
||||
content.scan(%r'\$\{ [^/\}\{:]* /
|
||||
[^/]* /
|
||||
[^/]* /
|
||||
[^\}]*\}'x) do |match|
|
||||
@@unknown_substitutions["content"].push [match, @file]
|
||||
end
|
||||
end
|
||||
content
|
||||
end
|
||||
|
||||
def condition
|
||||
@ -348,7 +358,7 @@ if $0 == __FILE__
|
||||
#
|
||||
modename = File.basename Choice.choices.output_dir || "major-mode-name"
|
||||
menustr = TmSubmenu::main_menu_to_lisp(info_plist, modename) if info_plist
|
||||
puts menustr unless !menustr or Choice.choices.quiet
|
||||
puts menustr if $DEBUG
|
||||
|
||||
# Write some basic .yas-* files
|
||||
#
|
||||
@ -357,14 +367,35 @@ if $0 == __FILE__
|
||||
FileUtils.mkdir_p Choice.choices.output_dir
|
||||
FileUtils.touch File.join(original_dir, Choice.choices.output_dir, ".yas-make-groups") unless menustr
|
||||
FileUtils.touch File.join(original_dir, Choice.choices.output_dir, ".yas-ignore-filenames-as-triggers")
|
||||
File.open(File.join(original_dir, Choice.choices.output_dir, ".yas-setup.el"), 'w') do |file|
|
||||
file.write ";; .yas-setup.el for #{modename}\n"
|
||||
file.write ";;\n"
|
||||
file.write ";; Automatically translated menu\n"
|
||||
file.write(menustr)
|
||||
file.write "\n;;\n"
|
||||
file.write ";; .yas-setup.el for #{modename} ends here\n"
|
||||
end
|
||||
yas_setup_el = File.join(original_dir, Choice.choices.output_dir, ".yas-setup.el")
|
||||
|
||||
existing = nil
|
||||
separator = ";; --**--"
|
||||
File.open yas_setup_el, 'r' do |file|
|
||||
existing = file.read.split( ";; --**--")
|
||||
existing = existing[0] || (";; .yas-setup.el for #{modename}\n" +
|
||||
";; \n")
|
||||
end
|
||||
|
||||
File.open yas_setup_el, 'w' do |file|
|
||||
file.puts existing
|
||||
file.puts separator
|
||||
file.puts ";; Automatically generated code - Translated menu"
|
||||
file.puts ";; "
|
||||
file.puts menustr
|
||||
file.puts
|
||||
file.puts ";; Unknown content substitutions:"
|
||||
file.puts ";; "
|
||||
TmSnippet::unknown_substitutions["content"].reduce([]) do |acc,e1|
|
||||
# if !acc.index {|e2| e2[0]==e[0]} then acc << e1 end
|
||||
acc.push e1 unless !acc || acc.index {|e2| e2[0]==e1[0]}
|
||||
acc
|
||||
end.each do |pair|
|
||||
file.puts ";; " + pair[0] + (" " * [1, 50-pair[0].length].max) + "as in '" + pair[1] + "'"
|
||||
end
|
||||
file.puts ";; "
|
||||
file.puts
|
||||
file.puts ";; .yas-setup.el for #{modename} ends here"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -15,28 +15,29 @@ class TmSnippet
|
||||
%q@${3/(^.*?\S.*)|.*/(?1:\()/}@ => '${3:$(and (string-match "[^\s\t]" yas/text) "(" )}',
|
||||
%q@${3/(^.*?\S.*)|.*/(?1:\))/}@ => '${3:$(and (string-match "[^\s\t]" yas/text) ")" )}',
|
||||
%q@${2/^\s*$|(.*\S.*)/(?1: )/}@ => '${2:$(and (string-match "[^\s\t]" yas/text) " " )}',
|
||||
%q@${3/^\s*$|(.*\S.*)/(?1: )/}@ => '${3:$(and (string-match "[^\s\t]" yas/text) " " )}',
|
||||
%q@${3/(^[rwab+]+$)|.*/(?1:")/}@ => '${}',
|
||||
%q@${3/(^[rwab+]+$)|.*/(?1:, ")/}@ => '${}',
|
||||
%q@${3/^\s*$|(.*\S.*)/(?1:, )/}@ => '${}',
|
||||
%q@${1:"${2:path/or/url/or/pipe}@ => '${}',
|
||||
%q@${2:${1/([\w&&[^_]]+)|./\u$1/g}@ => '${}',
|
||||
%q@${TM_SELECTED_TEXT/([\t ]*).*/$1/m}@ => '${}',
|
||||
%q@${1:"${2:path/to/file}"}${3/(^[rwab+]+$)|.*/(?1:, ")/}@ => '${}',
|
||||
%q@${3:${TM_SELECTED_TEXT/(\A.*)|(.+)|\n\z/(?1:$0:(?2:\t$0))/g}@ => '${}',
|
||||
%q@${1:${TM_FILENAME/(?:\A|_)([A-Za-z0-9]+)(?:\.rb)?/(?2::\u$1)/g}@ => '${}',
|
||||
%q@${1/(^(?<var>\s*[a-z_][a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:|)/}@ => '${}',
|
||||
%q@${1/(^(?<var>\s*[a-z_][a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1: |)/}@ => '${}',
|
||||
%q@${1/(^(?<var>\s*[a-z_][a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:| )/}@ => '${}',
|
||||
%q@${2/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:|)/}@ => '${}',
|
||||
%q@${1/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:|)/}@ => '${}',
|
||||
%q@${2/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:|)/}@ => '${}',
|
||||
%q@${1/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:|)/}@ => '${}',
|
||||
%q@${2/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:| )/}@ => '${}',
|
||||
%q@${1/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:| )/}@ => '${}',
|
||||
%q@${2/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:| )/}@ => '${}',
|
||||
%q@${1/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:| )/}@ => '${}',
|
||||
%q@${2/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:| )/}@ => '${}'
|
||||
%q@${3/^\s*$|(.*\S.*)/(?1: )/}@ => '${3:$(and (string-match "[^\s\t]" yas/text) " " )}'
|
||||
# %q@${3/(^[rwab+]+$)|.*/(?1:")/}@ => '${}',
|
||||
# %q@${3/(^[rwab+]+$)|.*/(?1:, ")/}@ => '${}',
|
||||
# %q@${3/^\s*$|(.*\S.*)/(?1:, )/}@ => '${}',
|
||||
# %q@${1:"${2:path/or/url/or/pipe}@ => '${}',
|
||||
# %q@${2:${1/([\w&&[^_]]+)|./\u$1/g}@ => '${}',
|
||||
# %q@${TM_SELECTED_TEXT/([\t ]*).*/$1/m}@ => '${}',
|
||||
# %q@${1:"${2:path/to/file}"}${3/(^[rwab+]+$)|.*/(?1:, ")/}@ => '${}',
|
||||
# %q@${3:${TM_SELECTED_TEXT/(\A.*)|(.+)|\n\z/(?1:$0:(?2:\t$0))/g}@ => '${}',
|
||||
# %q@${1:${TM_FILENAME/(?:\A|_)([A-Za-z0-9]+)(?:\.rb)?/(?2::\u$1)/g}@ => '${}',
|
||||
# %q@${1/(^(?<var>\s*[a-z_][a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:|)/}@ => '${}',
|
||||
# %q@${1/(^(?<var>\s*[a-z_][a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1: |)/}@ => '${}',
|
||||
# %q@${1/(^(?<var>\s*[a-z_][a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:| )/}@ => '${}',
|
||||
# %q@${2/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:|)/}@ => '${}',
|
||||
# %q@${1/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:|)/}@ => '${}',
|
||||
# %q@${2/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:|)/}@ => '${}',
|
||||
# %q@${1/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:|)/}@ => '${}',
|
||||
# %q@${2/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:| )/}@ => '${}',
|
||||
# %q@${1/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:| )/}@ => '${}',
|
||||
# %q@${2/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:| )/}@ => '${}',
|
||||
# %q@${1/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:| )/}@ => '${}',
|
||||
# %q@${2/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:| )/}@ => '${}'
|
||||
|
||||
}
|
||||
]
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user