Created
July 3, 2014 11:07
-
-
Save ammojamo/360b00560d715dd7350e to your computer and use it in GitHub Desktop.
ST2 Insert Special Symbol Plugin
This file contains hidden or 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 | |
import unicodedata | |
class InsertSpecialSymbolCommand(sublime_plugin.TextCommand): | |
DEBUG = True | |
replacements = dict((unicodedata.name(L).split()[-1].lower(), L) for L in map(unichr, range(945, 970))) | |
@staticmethod | |
def debug(string): | |
if InsertSpecialSymbolCommand.DEBUG: print(string) | |
def run(self, edit): | |
""" Replaces the selected word with an appropriate symbol """ | |
view = self.view | |
for cursor in view.sel(): | |
wordRegion = view.word(cursor) | |
word = view.substr(wordRegion) | |
symbol = self.replacements.get(word.lower(), None) | |
if symbol is not None: | |
view.replace(edit, wordRegion, symbol if word[0].islower() else symbol.upper()) | |
else: | |
InsertSpecialSymbolCommand.debug("Substitution not available for '%s'." % word) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Based on code found at http://stackoverflow.com/questions/21290849/replacing-words-with-greek-letters-in-sublimetext