Home Download Buy Blog Forum Support

Tips on making a buildsystem plugin

Tips on making a buildsystem plugin

Postby ljmeijer on Fri Jul 08, 2011 9:33 pm


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
Posts: 1
Joined: Fri Jul 08, 2011 9:31 pm

Re: Tips on making a buildsystem plugin

Postby Marciano on Mon Jul 11, 2011 7:26 am

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).
Posts: 146
Joined: Fri Sep 18, 2009 2:55 am

Re: Tips on making a buildsystem plugin

Postby bizoo on Mon Jul 11, 2011 1:09 pm

This is a partially tested solution:

Create a xxx.sublime-build file with a custom target command:
Code: Select all
   "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: Select all
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]})

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: Select all
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})

Good luck!
Posts: 958
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland

Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 2 guests