Sublime Forum

The command palette and menu items

#1

I’m creating a custom package and I would like to place some menu items inside the command palette but I can’t seem to figure out how to expose them. Namely I am looking for all the items inside Tools > Build Systems. I’ve looked at the Main.sublime-menu but I can’t figure it out. How can I expose this menu item to the command palette? In my custom package I tried:

[code]//Default.sublime-commands

{ "caption": "Build System", "command": "build_system" }

][/code]

[code]
//Default.sublime-keymap

{ 
    "keys": "f9"], "command": "show_overlay", 
    "args": {"overlay": "command_palette", "text": "Build System"} 
}

][/code]

1 Like

#2

Anyone?

1 Like

#3

I might go look at some other plugins that add things to the command palette. Main.sublime-menu controls the menus, whereas a .sublime-commands file is for the command palette. Or try sublimetext.info.

1 Like

#4

Ok I figured it out. The command palette can only be populated by existing commands that run in sublime. The way you can view which commands that are being run in sublime is to open up the console(CTR + ~) and type in sublime.log_command(True)

Now whenever you do anything that makes sublime trigger a command or anything really, it will log that action in the console. Armed with this knowledge, we we go to Tools > Build System and click on the build system type we want, say, C++, we get:

command: set_build_system {“file”: “Packages/C++/C++.sublime-build”}

Sweet! Knowing this we can go to our .sublime-commands file(you can call it Default.sublime-commands) and type. Tip: pay close attention to the “caption” it’s what we will use to tie our .sublime-command file with our .sublime-keymap file.

     {
           "caption": "Set Build System: C++", "command": "set_build_system", 
           "args": { "file":"Packages/C++/C++.sublime-build" } 
     }


]

Let’s add another one:

[code]
{
“caption”: “Set Build System: C++”, “command”: “set_build_system”,
“args”: { “file”:“Packages/C++/C++.sublime-build” }
},

{
       "caption": "Set Build System: Python", "command": "set_build_system", 
       "args": { "file":"Packages/Python/Python.sublime-build" } 
}

][/code]

Now that we have exposed these two commands in our .sublime-commands file. We can create a shortcut for it in our .sublime-keymap file. I call mine Deafault.sublime-keymap:

     {
            "keys": "f8"], "command": "show_overlay",
            "args": {"overlay": "command_palette", "text": "Set Build System:"}
     }
]

Notice the “text” key. Look familiar? This is how you connect your key binding to your command. Save press F8 and boom! You have our own custom command palette menu. Enjoy!

PS: you can put your .sublime-commands/.sublime-keymap files in your User package or add to any existing ones if you have them there if you just want to customize your sublime text 2 without making a custom package.

4 Likes

#5

This was a tremendous help pencilking, thank you for posting what you found.

I wanted to mention that for me, the command was sublime.log_commands(True).

Sublime amazes me more every day!

2 Likes