-
-
Save seanlilmateus/2657555 to your computer and use it in GitHub Desktop.
Snippet generator for RubyMotion ctags (UltiSnips)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Generate ctags with `rake ctags` | |
Run snipper.rb | |
Move motion.snippets into ~/.vim/UltiSnips/ruby/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'FileUtils' | |
File.open('motion.snippets', 'w') do |snippets_file| | |
snippets = {} | |
File.read('tags').each_line do |line| | |
next unless line.match /^\w+:/ | |
line =~ /^(([^:]*):([^\s]*))\s.*/ | |
snippet = $1 | |
method = $2 | |
args = $3 | |
args = args.split(":") | |
snippets[snippet] = {:snippet => snippet, :method => method, :args => args} | |
end | |
snippets.keys.sort.each do |key| | |
snippet = key | |
method = snippets[key][:method] | |
args = snippets[key][:args] | |
named_args = "" | |
last_arg = 1 | |
args.each_with_index do |arg, i| | |
named_args += ", #{arg}: ${#{i+2}}" | |
last_arg += 1 | |
end | |
snippets_file.write("snippet #{snippet}\n\t#{method}(${1}#{named_args})${#{last_arg + 1}}\nendsnippet\n") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment