Skip to content

Instantly share code, notes, and snippets.

@ammojamo
Created July 3, 2014 11:07
Show Gist options
  • Save ammojamo/360b00560d715dd7350e to your computer and use it in GitHub Desktop.
Save ammojamo/360b00560d715dd7350e to your computer and use it in GitHub Desktop.
ST2 Insert Special Symbol Plugin
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)
@ammojamo
Copy link
Author

ammojamo commented Jul 3, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment