Created
May 10, 2012 13:13
-
-
Save shayarnett/2652913 to your computer and use it in GitHub Desktop.
Snippet generator for RubyMotion ctags
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 | |
Put resulting ruby.snippets file where your snippet plugin can pick it up. (I'm using snipmate) |
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('ruby.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}}\n") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment