Home Download Buy Blog Forum Support

[buildSystem] args to keymap

[buildSystem] args to keymap

Postby farfromrefuge on Thu Apr 12, 2012 1:34 pm

hi,

i am writing my own buildSystem

i want to have multiple command keys like so
Code: Select all
[
    { "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
farfromrefuge
 
Posts: 38
Joined: Mon Oct 19, 2009 11:49 am

Re: [buildSystem] args to keymap

Postby bizoo on Thu Apr 12, 2012 1:46 pm

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 ?
bizoo
 
Posts: 879
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland

Re: [buildSystem] args to keymap

Postby farfromrefuge on Fri Apr 13, 2012 9:10 am

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: Select all
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!")         
farfromrefuge
 
Posts: 38
Joined: Mon Oct 19, 2009 11:49 am

Re: [buildSystem] args to keymap

Postby bizoo on Fri Apr 13, 2012 10:38 am

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: Select all
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: Select all
>>> window.run_command('example', {'test':'true'})
test = true
args = ()
kwargs = {}


Code: Select all
import sublime, sublime_plugin

class ExampleCommand(sublime_plugin.WindowCommand):
    def run(self, *args, **kwargs):
        print "args =", args
        print "kwargs =", kwargs

Code: Select all
>>> window.run_command('example', {'test':'true'})
args = ()
kwargs = {'test': u'true'}
bizoo
 
Posts: 879
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland

Re: [buildSystem] args to keymap

Postby farfromrefuge on Fri Apr 13, 2012 1:47 pm

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
Code: Select all
args = ()
kwargs = {'working_dir': u'/Volumes/data/dev/akylas/amouseserver'}

So my args in the keymap wont go through
farfromrefuge
 
Posts: 38
Joined: Mon Oct 19, 2009 11:49 am

Re: [buildSystem] args to keymap

Postby bizoo on Fri Apr 13, 2012 2:57 pm

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:
Code: Select all
{
        "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.
bizoo
 
Posts: 879
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland

Re: [buildSystem] args to keymap

Postby farfromrefuge on Fri Apr 13, 2012 3:12 pm

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 :P
farfromrefuge
 
Posts: 38
Joined: Mon Oct 19, 2009 11:49 am

Re: [buildSystem] args to keymap

Postby bizoo on Fri Apr 13, 2012 3:30 pm

:?:
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?
bizoo
 
Posts: 879
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland

Re: [buildSystem] args to keymap

Postby farfromrefuge on Mon Apr 16, 2012 9:27 am

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 ....
Attachments
AkylasMake.zip
(1.73 KiB) Downloaded 175 times
farfromrefuge
 
Posts: 38
Joined: Mon Oct 19, 2009 11:49 am

Re: [buildSystem] args to keymap

Postby bizoo on Tue Apr 17, 2012 7:33 am

farfromrefuge wrote:I was sure i run my command using my keymap, but actually i think it s using ST2 build command.

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.
bizoo
 
Posts: 879
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland

Next

Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 13 guests