From 3c99a37d4fec8f8b1b6a5094f988a86b5258a6d5 Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Sun, 8 Dec 2019 12:27:54 -0500 Subject: [PATCH] Merlin FIXS command. needed since I encountered some expanded merlin source code too big to load in merlin. also adds ; before comments. --- Default.sublime-commands | 4 ++ merlin-fixs.py | 86 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 merlin-fixs.py diff --git a/Default.sublime-commands b/Default.sublime-commands index 163ecad..eb63b94 100644 --- a/Default.sublime-commands +++ b/Default.sublime-commands @@ -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" diff --git a/merlin-fixs.py b/merlin-fixs.py new file mode 100644 index 0000000..5c12843 --- /dev/null +++ b/merlin-fixs.py @@ -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) \ No newline at end of file