Created
August 24, 2012 10:07
-
-
Save gimenete/3448719 to your computer and use it in GitHub Desktop.
SublimeText2 plugin for escaping code. Useful for languages that don't support heredoc
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
Show hidden characters
[ | |
{ | |
"keys": ["command+ctrl+e"], "command": "escape_code" | |
} | |
] |
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 | |
# Transforms the selected text by escaping especial characters (\t, \n, \r,...) | |
# Made following this tutorial | |
# http://net.tutsplus.com/tutorials/python-tutorials/how-to-create-a-sublime-text-2-plugin/ | |
# SublimeText2 API reference http://www.sublimetext.com/docs/2/api_reference.html | |
class EscapeCodeCommand(sublime_plugin.TextCommand): | |
def run(self, edit): | |
for region in self.view.sel(): | |
content = self.view.substr(region) | |
content = content.replace('\\', '\\\\') | |
content = content.replace('\t', '\\t') | |
content = content.replace('\r', '\\r') | |
content = content.replace('\n', '\\n') | |
content = content.replace('\b', '\\b') | |
content = content.replace('\f', '\\f') | |
content = content.replace('\'', '\\\'') | |
content = content.replace('\"', '\\\"') | |
self.view.replace(edit, region, content) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment