Created
September 6, 2021 14:01
-
-
Save yzhong52/a47530db9d75a878a085096c82172bce to your computer and use it in GitHub Desktop.
Sublime Text Plugin - format
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 | |
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