Skip to content

Instantly share code, notes, and snippets.

@yzhong52
Created September 6, 2021 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yzhong52/a47530db9d75a878a085096c82172bce to your computer and use it in GitHub Desktop.
Save yzhong52/a47530db9d75a878a085096c82172bce to your computer and use it in GitHub Desktop.
Sublime Text Plugin - format
import sublime
import sublime_plugin
def format(input):
output = ""
counter = 0
SPACE = ' '
for char in input:
if char in "([{":
counter += 1
output += char + '\n' + SPACE * counter
elif char in ")]}":
counter -= 1
output += '\n' + SPACE * counter + char
elif char == ',':
output += char + '\n' + SPACE * counter
elif char not in ' \n':
output += char
return output
class ExampleCommand(sublime_plugin.TextCommand):
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment