Skip to content

Instantly share code, notes, and snippets.

@hanshasselberg
Created October 1, 2010 04:55
Show Gist options
  • Save hanshasselberg/605761 to your computer and use it in GitHub Desktop.
Save hanshasselberg/605761 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
def format_method text, line
line.match /^(\s*)/
spaces = $1
text.match /^(\s*)([\w\d\s\_]+)\s*\((.*)\)/
formatted = "#{$2}(\n#{spaces}\t"
formatted += $3.
gsub(" ", "").
gsub(",", ",\n#{spaces}\t").
gsub('=>', ' => ').
gsub('{', '{ ').
gsub('}', ' }').
gsub('[', '[ ').gsub(']', ' ]')
formatted += "\n#{spaces})"
formatted
end
def main selected_text, line
if selected_text.match /^[\w\d\_]+\((.*)\)$/
puts format_method(selected_text, line)
else
puts selected_text
end
end
# main 'do( a, b, c )', ' do( a, b, c )'
main ENV['TM_SELECTED_TEXT'], ENV['TM_CURRENT_LINE']
@hanshasselberg
Copy link
Author

This script formats a method call from

do_something_very_fancy(with_a_lot_and, very_long_parameters, so_it_exceeds_78_character_length)

to

do_something_very_fancy(
    with_a_lot_and,
    very_long_parameters,
    so_it_exceeds_78_character_length
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment