Sublime Forum

Getting the current build system?

#1

Is it possibly to get the currently selected build system somehow?

1 Like

#2

If you’re referring to the Build System (when you press Ctrl-B), then choose the Tools menu, Build System, and the one that is currently in use will be ticked. (If you mean to open this file, then it’s in your Packages folder with the extension ‘sublime-build’.)

If you’re referring to your ST Build then choosing the Help menu, About Sublime Text 2, will show it. Alternatively, press Ctrl-’ (apostrophe) as soon as you start ST and this detail appears at the top of the Console. Andy.

0 Likes

#3

In the context of the forum (Plugin Development), I suppose quarnster want a way to get the build system from a plugin.

I’m pretty sure there isn’t anything in the API and as command doesn’t return anything there’s no luck either this way.
Maybe there’s something in the view.settings() but without knowing the name of the settings, there’s no way to get it.

0 Likes

#4

Yeah I mean getting the build system from a plugin.

0 Likes

#5

It’s been some time :blush: is there some way to retrieve the active build system now?

0 Likes

#6

Na, you can do it manually, though. Have a look here: https://github.com/math2001/MarkdownCodeBuilder/blob/7f8a0cf7c9f779c9fd59b35e5a7015d93497520b/functions.py#L9

It doesn’t take into consideration the variants though, but it’s not hard to implement.

Build system from the current project aren’t taken into consideration too, but, again, it can be fixed.

0 Likes

#7

That only returns the possible build systems for the build system selection, not what is actually selected. Besides, you can override the build in the menu.

1 Like

#8

I screwed around a bit and here is my attempt:


_BUILD_SYS_HANDLES = dict()

def get_build_system(window):
    buildhandle = _BUILD_SYS_HANDLES[window.id()]
    if isinstance(buildhandle, int):
        return window.project_data()['build_systems'][buildhandle]
    elif isinstance(buildhandle, str) and buildhandle != "":
        return sublime.decode_value(sublime.load_resource(buildhandle))

class BuildSystemWatcher(sublime_plugin.EventListener):
    def on_window_command(self, window, command_name, args):
        if command_name != 'set_build_system':
            return None
        index = args.get('index', None)
        global _BUILD_SYS_HANDLES
        if not index is None:
            _BUILD_SYS_HANDLES[window.id()] = index
        else:
            _BUILD_SYS_HANDLES[window.id()] = args.get('file', None)
        print(_BUILD_SYS_HANDLES) # debug

This almost works… It works when the user selects a build system after the plugin is loaded. On startup however, every window gets its selected build system in some way and that doesn’t get caught by this event listener. So, this is pretty much unreliable.

If Sublime Text would issue the “select_build_system” command for each of its windows after all the plugins are loaded, this would actually work.

0 Likes