How about this?
import sublime_plugin
import sublime
class DissectThisFileCommand(sublime_plugin.TextCommand):
def run(self, _, tokens=["INCLUDE", "SETTINGS", "MAIN LOOP"]):
comment_regions = self.view.find_by_selector("comment.line")
self.active_token = None
self.start = 0
self.end = 0
self.tokens = tokens
for multiline_regions in comment_regions:
regions = self.view.split_by_newlines(multiline_regions)
for region in regions:
self._handle_region(region)
def _handle_region(self, region):
comment = self.view.substr(region).strip()
if self.active_token:
if comment == "//{}_END".format(self.active_token):
view = self.view.window().new_file()
view.settings().set("syntax",
self.view.settings().get("syntax"))
view.set_name("{}_{}".format(self.view.name(),
self.active_token))
characters = self.view.substr(sublime.Region(self.start,
region.a - 1))
view.run_command("append", {"characters": characters})
self.active_token = None
else:
for token in self.tokens:
if comment == "//{}".format(token):
self.start = region.b + 1
self.active_token = token
break
Go to Tools -> Developer -> New Plugin and save this python script in your Packages/User directory.
To run it, open your C file, open the console, and type this:
>>> view.run_command("dissect_this_file")
(or bind it to a keybinding, or put it in the command palette, or …)