Sublime Forum

[buildSystem] args to keymap

#1

hi,

i am writing my own buildSystem

i want to have multiple command keys like so


    { "keys": "super+b"], "command": "ak_make", "args": {"test": "true"}},
    { "keys": "super+shift+b"], "command": "ak_make" , "args": {"test": "false"}}
]

ak_make is a window command
My idea is to use args to pass args to my AkMake window command.
But my args are not passed through to my AkMake class.
i only get “working_dir” which is set in my .sublime-build

any idea?

Thanks

0 Likes

#2

Giving us the code of ak_make would help us to help you.

Don’t understand what you want to do exactly…
Do you want to replace build command by your own command or want to change the target of the build command (http://readthedocs.org/docs/sublime-text-unofficial-documentation/en/latest/reference/build_systems.html#options) ?

Maybe the code from https://github.com/bizoo/MultiTaskBuild could help ?

0 Likes

#3

You are right, with the code it will be easier
As you can see the command open a quick panel. What i want is to add shortcuts to directly do one of the possibility of the quickpanel. This is for “easy” use.
so for example :

  • “super+b”: quickpanel
  • “super+shift+b”: build in debug

thanks

[code]import sublime, sublime_plugin
import os

def get_setting(key, default=None):
try:
s = sublime.active_window().active_view().settings()
if s.has(“akylasmake_%s” % key):
return s.get(“akylasmake_%s” % key)
except:
pass
return sublime.load_settings(“AkylasMake.sublime-settings”).get(key, default)

THIRDPARTIES = get_setting(“3rdparties”, “”)

class AkMakeCommand(sublime_plugin.WindowCommand):
mode_list = “cmake”, “build”,“clean”,“run”]
config_list = “release”,“debug”]
# platform_list = “ipad”,“iphone”, “android”, “web”]

mode = ''
config = ''
wdir = ''
# platform = ''
# notes = ''

def run(self, *args, **kwargs):
	# p = self.window.active_view().file_name()
    self.wdir = kwargs'working_dir']
    self.window.show_quick_panel(self.mode_list , self._mode_list_callback)

def prebuild(self):
    build = self.wdir + '/build_dest/' + self.config
    self.window.run_command("exec",{"cmd":'mkdir', '-p', build]})


def launchMake(self):
    sublime.log_commands(True)
    sublime.active_window().run_command("show_panel", {"panel": "console", "toggle": True})
    self.prebuild()
    build = self.wdir + '/build_dest/' + self.config

    if (self.mode == 'cmake'):
        parameters = "cmake","-G","Unix Makefiles", self.wdir, "-DCMAKE_BUILD_TYPE=" + self.config]
    else:
        parameters = "make","-C",build]
    if (self.mode == 'clean'):
        parameters.append("clean")

    print THIRDPARTIES
    self.window.run_command("exec",{"cmd":parameters, "working_dir":build, "env":{"THIRDPARTIES_DIR":THIRDPARTIES}})

def _mode_list_callback(self, index):
    if (index > -1):
        self.mode = self.mode_list[index]
        self.window.show_quick_panel(self.config_list , self._config_list_callback)

def _config_list_callback(self, index):
    if (index > -1):	
        self.config = self.config_list[index]
        self.launchMake()

# def _release_note_on_change(self, entry):
         # sublime.error_message("dont know the meaning ...!")
     
# def _release_note_on_cancel(self):
         # sublime.error_message("operation cancelled!")			

[/code]

0 Likes

#4

If I understand you correctly, you expect your test parameter to be available in the args list, but it will never be the case.
You need to declare test as a parameter in the run method, or access it by kwargs:

[code]import sublime, sublime_plugin

class ExampleCommand(sublime_plugin.WindowCommand):
def run(self, test, *args, **kwargs):
print “test =”, test
print “args =”, args
print “kwargs =”, kwargs[/code]

>>> window.run_command('example', {'test':'true'}) test = true args = () kwargs = {}

[code]import sublime, sublime_plugin

class ExampleCommand(sublime_plugin.WindowCommand):
def run(self, *args, **kwargs):
print “args =”, args
print “kwargs =”, kwargs[/code]

>>> window.run_command('example', {'test':'true'}) args = () kwargs = {'test': u'true'}

0 Likes

#5

Yes that s my problem,
in a build system my test parameter doesnt get through!
I suppose it s because i dont do the “window.run_command” myself. It s done by ST
By doing exactly what you do the only parameter that comes through using my keymap is “working_dir” from my .sublime-build.
so by doing the print like you do i only get that

args = ()
kwargs = {'working_dir': u'/Volumes/data/dev/akylas/amouseserver'}

So my args in the keymap wont go through

0 Likes

#6

I’m lost… There is no working_dir param in your keybindings.

Do you call your command from keybindings or from a sublime-build file like:

{ "cmd": "python", "-u", "$file"], "file_regex": "^ ]*File \"(...*?)\", line ([0-9]*)", "selector": "source.python", "test": "true", "target": "ak_make" }
If you want to run a ST2 build, you must run the “build” command but I don’t think you can add parameter to this command. Parameters must be in the sublime-build file.

0 Likes

#7

working_dir is not set in the key bidding but in the sublime-build!
And apparently you are right i cant put parameters in the key bidding. Thats my problem!
Thus i dont know how to do what i want. I dont even think i can use two different targets that would call the same function with a different parameter.

That s why i need help :stuck_out_tongue:

0 Likes

#8

:question:
How do you run your command, by keymaps as your first post or using ST2 build command?
I don’t understand how working_dir parameter could magically be defined using the keymaps of your first post?

0 Likes

#9

Ok it s gonna be easier with the plugin itself.
But you just made a point!
I was sure i run my command using my keymap, but actually i think it s using ST2 build command.
The keymap is the same …
AkylasMake.zip (1.73 KB)

0 Likes

#10

The AkylasMake.sublime-keymap must be renamed Default.sublime-keymap or Default (OS).sublime-keymap

But calling directly “ak_make” command doesn’t read your sublime-build file.
You must call the “build” command that call your “ak_make” with the sublime-build arguments.

But actually FWIK there’s no way to give your own arguments when calling “build” command, so you have to put your own arguments in the sublime-build file which means a lot of sublime-build files.
I make a request to allow “build” command to have arguments forwarded to the target command http://www.sublimetext.com/forum/viewtopic.php?f=3&t=6926&start=0.

Wait and see.

0 Likes

#11

Ok i ll rename my keymap file.

But there is something i dont get, you say that by doing [cmd+b] i dont call my sublime-build. But then i dont get why the working_dir i put in my sublime-build get passed to my ak_make command…
any idea?

To be true i am lost between my sublime-build and my keymap …

Thanks for the support anyway

0 Likes

#12

Your keymaps wasn’t used because the file have the wrong name, before renaming the keymaps file, you actually call the standard “build” command.
To know which command is triggered, open the console and type:

sublime.log_commands(True)

After that, each command running by ST2 is reported to the console.

0 Likes

#13

Ok you are right, and now i see that keymap is not what i want at all.
Why? Because a have multiple buildsystems and started to implement them thinking i could do a [super+b] in each one of them. If like only the currently set build system plugin was running!
Which is wrong.
So i think that what i want is customizable sublime-build where you could set your keymap and have more than one :s

0 Likes