Sublime Forum

Key shortcut for acessing build variants?

#1

I upgraded to the latest version of ST2 and was pleased to find that build variants were now built in. I had been using the MultiTaskBuild package, which worked very well until the new update. I have converted my build system to the new format as shown below.
My problem is that I cannot access the build variant list as described by the documentation (http://docs.sublimetext.info/en/latest/reference/build_systems.html#variants).
I believe the culprit is the default keymapping for OSX which appears to attempt to run the build variant “run” instead of showing the list of build variants like the documentation says it should:

{ "keys": "super+shift+b"], "command": "build", "args": {"variant": "Run"} },

With the MultiTaskBuild package, the “CMD+B” would show a list of variants to choose from. How can I make the new build system setup in Sublime do the same?

{
    "file_regex": "^(..^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
    "working_dir": "${file_path}/../",
    "selector": "source.c",
    "cmd": "make", "${file_base_name}"],

    "variants":
    
        { 
            "cmd": "make", "clean"],
            "name": "Clean"
        },

        { 
            "cmd": "make", "load"],
            "name": "Load"
        }
    ]
}
0 Likes

Combine variants and platforms in a single build system
#2

A fix was committed a few minutes ago.

The build variants list is available in the Command Palette under the name "Build: "

[quote=“Creepr”]
With the MultiTaskBuild package, the “CMD+B” would show a list of variants to choose from. How can I make the new build system setup in Sublime do the same?[/quote]

You can create a keybinding to show the Command Palette with only the Build entries:

{ "keys": "ctrl+alt+shift+b"], "command": "show_overlay", "args": {"overlay": "command_palette", "text": "Build: "} }

I asked Jon if it was possible to automatically open the Command Palette when there is only variants and no “base” cmd in a build-file, but it didn’t answer yet.
So I do it myself with the code below. If you save it to your user folder, it override the default exec command and add this behavior for all build file.
Alternatively, you can give it another name (like “ExecMenuCommand”) and use it as target command for your build file.

[code]execmod = import(“exec”)

class ExecCommand(execmod.ExecCommand):
def run(self, cmd=], *args, **kwargs):
if not cmd and not kwargs.get(“kill”, False):
# if cmd is empty, open the command_palette with the available build list
self.window.run_command(“show_overlay”, {“overlay”: “command_palette”, “text”: "Build: " + kwargs.get(“prefix”, “”)})
else:
# if there is a cmd, run the standard exec command
super(ExecCommand, self).run(cmd, *args, **kwargs)[/code]

0 Likes

#3

I tried to call the “show_overlay” command directly but it can not be found from build systems. So I had to wrap it in another command that only calls this very command.

Commit here: github.com/FichteFoll/AAAPackag … 60cdfb2aa5

Though, you should consider that the variants also have the “overlay” and “text” parameter then. If you don’t expect these parameters you should either add them manually or just remember that they are in the **kwargs if you plan to use this dict.

0 Likes