Sublime Forum

Tips on making a buildsystem plugin

#1

Hi,

I would like to achieve the following:

get a window in sublimetext that displays 10 different build targets my project has.
when I doubleclick on one, I want a ‘buildsystem’ job to start, with the clicked item as argument, instead of $file,
followed by sublime properly picking up compile errors etc from the build tools stdout/stderr

I assume I’ll need to write a plugin for this, and am hoping someone can give me a few pointers in the right direction.

Thanks, Lucas

0 Likes

#2

I think the key is to use the “target” option in the .sublime-build file. This way you inherit all the goodness of the built-in ST2 build system—in particular, if you set any option in that file, it gets passed as an argument to your custom build command. But, you can do pretty much whatever you want in your command.

Start by studying the exec.py file in the Default directory. There’s some funky async processing stuff that goes on there; it took me a while to figure it out. But, it’s a great blueprint.

You can also take a look at the makePDF.py file in my LaTeX plugin (of course, disregarding all LaTeX-specific stuff).

0 Likes

#3

This is a partially tested solution:

Create a xxx.sublime-build file with a custom target command:

{ "target": "oracle_execute_list", "selector": "source.plsql.oracle" }

Create a plugin with your command that show a list of choice and call another command with the choice as argument (or directly call the exec command, see after):

[code]import sublime, sublime_plugin

class OracleExecuteListCommand(sublime_plugin.WindowCommand):
instance_list = “DEVELOP/DEVELOP@DEV1252A”, “PCS/PCS@DEV1252A”, “DEMO_MAS_F/DEMO_MAS_F@T1002U”]

def run(self, *args, **kwargs):
    print args, kwargs
    self.window.show_quick_panel(self.instance_list , self._quick_panel_callback)

def _quick_panel_callback(self, index):
    if (index > -1):
        self.window.run_command("oracle_exec", {"dsn": self.instance_list[index]})

[/code]

This part is not tested cos my oracle_exec command is not relevant for you.
Create a command that run the build command (look at exec.py for arguments description), something like that:

[code]import sublime, sublime_plugin

class OracleExecCommand(sublime_plugin.WindowCommand):
def run(self, dsn):
cmd = “sqlplus.exe”, “-s”, dsn, “@”, sublime.packages_path()+"\RunSQL.sql", self.window.active_view().file_name()]
file_regex = “^\(.+?/([0-9]+):([0-9]+)\) [0-9]+:[0-9]+ (.+)$”

	self.window.run_command("exec", {"cmd": cmd, "file_regex": file_regex})

[/code]
Good luck!

1 Like