Skip to content

Instantly share code, notes, and snippets.

@KellyLSB
Last active December 30, 2015 13:29
Show Gist options
  • Save KellyLSB/7836185 to your computer and use it in GitHub Desktop.
Save KellyLSB/7836185 to your computer and use it in GitHub Desktop.
Change Ruby Symbol Keyed Hash Syntax on Save to the new Ruby 1.9.3 - 2.0 Syntax (Only changes symbol keys)
import sublime, sublime_plugin, os
class RubyPostProcess(sublime_plugin.EventListener):
def on_pre_save(self, view):
syntax = os.path.basename(view.settings().get('syntax'))
syntax = os.path.splitext(syntax)[0]
if syntax == "Ruby":
replacements = []
edit = view.begin_edit()
regions_result = view.find_all(r":([a-z_]+)[ ]*=>[ ]* ", sublime.IGNORECASE, "\\1: ", replacements)
for i, thisregion in reversed(list(enumerate(regions_result))):
view.replace(edit, thisregion, replacements[i])
view.end_edit(edit)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment