Last active
December 30, 2015 13:29
-
-
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)
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
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