Skip to content

Commit

Permalink
Merlin FIXS command. needed since I encountered some expanded merlin …
Browse files Browse the repository at this point in the history
…source code too big to load in merlin.

also adds ; before comments.
  • Loading branch information
ksherlock committed Dec 8, 2019
1 parent 09b757b commit 3c99a37
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Default.sublime-commands
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
"caption": "Merlin MacGen",
"command": "merlin_mac_gen"
},
{
"caption": "Merlin Fix Space",
"command": "merlin_fixs"
},
{
"caption": "ORCA/M MacGen",
"command": "orca_mac_gen"
Expand Down
86 changes: 86 additions & 0 deletions merlin-fixs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import sublime
import sublime_plugin

SPACE = [" ", "\t"]
QUOTES = ["'", '"']


#
# need to do something clever for ; comments to put in comment field?
#
def fixs(s):

f = 0
q = None
sp = False
comment = False

rv = ''
if not len(s): return s
if s[0] == "*": comment = True
if s[0] == ";": comment = True ; rv = "\t\t\t"
for c in s:

if comment:
if c == "\t": c = " "
rv += c
continue

if q:
rv += c
if c == q: q = None
continue

if c in QUOTES:
rv += c
q = c
sp = False
continue

if c in SPACE:
if sp: continue
f += 1
c = "\t"
sp = True
rv += c
continue

if sp:
if c == ';':
comment = True
rv += "\t" * (3-f)
elif f == 3:
comment = True
rv += "; "
sp = False
rv += c

return rv;


class MerlinFixs(sublime_plugin.TextCommand):

def is_enabled(self):
scope = self.view.scope_name(0)
lang = scope.split(' ')[0]
return lang == 'source.asm.65816.merlin' or lang == "source.linker.merlin"


def run(self, edit):
view = self.view
all = sublime.Region(0, view.size())

# disable space indentation.
view.settings().set('translate_tabs_to_spaces', False)

data = []
for r in view.lines(all):
text = view.substr(r).rstrip()

data.append(fixs(text))


data.append('')
text = '\n'.join(data)

view.replace(edit, all, text)

0 comments on commit 3c99a37

Please sign in to comment.