2017-08-21 19:38:43 +00:00
|
|
|
import sublime
|
|
|
|
import sublime_plugin
|
2013-07-16 03:03:57 +00:00
|
|
|
|
|
|
|
class MerlinToTextCommand(sublime_plugin.TextCommand):
|
2017-08-21 19:38:43 +00:00
|
|
|
|
2013-07-16 03:03:57 +00:00
|
|
|
def is_enabled(self):
|
|
|
|
scope = self.view.scope_name(0)
|
|
|
|
lang = scope.split(' ')[0]
|
|
|
|
return lang == 'source.asm.65816.merlin'
|
|
|
|
|
|
|
|
def run(self, edit):
|
|
|
|
view = self.view
|
|
|
|
all = sublime.Region(0, view.size())
|
|
|
|
text = view.substr(all)
|
|
|
|
|
|
|
|
#
|
|
|
|
# good idea but the string is treated as utf8 and this blows.
|
|
|
|
#
|
|
|
|
|
|
|
|
# create the translation table, stripping high-bytes.
|
2017-08-21 19:38:43 +00:00
|
|
|
table = list(map(lambda x: chr(x & 0x7f), range(256)))
|
2013-07-16 03:03:57 +00:00
|
|
|
#
|
|
|
|
# high ' ' is actually a tab.
|
|
|
|
table[ord(' ') | 0x80] = '\t'
|
|
|
|
|
|
|
|
# line conversion
|
|
|
|
table[ord('\r')] = '\n'
|
|
|
|
table[ord('\r') | 0x80] = '\n'
|
|
|
|
#
|
|
|
|
# convert to a string.
|
|
|
|
#table = ''.join(table);
|
|
|
|
#
|
|
|
|
#text = text.translate(table)
|
|
|
|
|
2017-08-21 19:38:43 +00:00
|
|
|
data = map(lambda x: table[ord(text[x])], range(len(text)))
|
2013-07-16 03:03:57 +00:00
|
|
|
|
|
|
|
text = ''.join(data)
|
|
|
|
|
|
|
|
view.replace(edit, all, text)
|