mirror of
https://github.com/ksherlock/65816.tmbundle.git
synced 2025-02-08 01:30:36 +00:00
Sublime script to convert Merin to ASCII
This commit is contained in:
parent
f855579eca
commit
73bc944d20
6
Default (OSX).sublime-keymap
Normal file
6
Default (OSX).sublime-keymap
Normal file
@ -0,0 +1,6 @@
|
||||
[
|
||||
{
|
||||
"keys": ["super+ctrl+m"],
|
||||
"command": "merlin_to_text"
|
||||
}
|
||||
]
|
7
Default.sublime-commands
Normal file
7
Default.sublime-commands
Normal file
@ -0,0 +1,7 @@
|
||||
[
|
||||
{
|
||||
"caption": "Merlin To Text",
|
||||
"command": "merlin_to_text"
|
||||
}
|
||||
]
|
||||
|
37
merlin-to-text.py
Normal file
37
merlin-to-text.py
Normal file
@ -0,0 +1,37 @@
|
||||
import sublime, sublime_plugin
|
||||
|
||||
class MerlinToTextCommand(sublime_plugin.TextCommand):
|
||||
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.
|
||||
table = map(lambda x: chr(x & 0x7f), xrange(256))
|
||||
#
|
||||
# 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)
|
||||
|
||||
data = map(lambda x: table[ord(text[x])], xrange(len(text)))
|
||||
|
||||
text = ''.join(data)
|
||||
|
||||
view.replace(edit, all, text)
|
Loading…
x
Reference in New Issue
Block a user