Home Download Buy Blog Forum Support

Binding a key to a succession of commands

Binding a key to a succession of commands

Postby wledoux on Fri Aug 19, 2011 10:06 am

Hi everyone,

While the Find panel is opened, I wanted F3 to close that panel before going to the next match.
The only thing that I got to work was this:
Code: Select all
import sublime,sublime_plugin
class findNextHidePanelCommand(sublime_plugin.WindowCommand):
   def run(self):
      self.window.run_command("hide_panel")
      self.window.run_command("find_next")


Code: Select all
keymap FILE:
   { "keys": ["f3"], "command": "find_next_hide_panel", "context":
      [{"key": "panel", "operand": "find"}, {"key": "panel_has_focus"}]
   },


Is there a simpler way to do this, for example inside of the keymap file ?

Thank you for you help
William.
Last edited by wledoux on Fri Aug 19, 2011 10:33 am, edited 1 time in total.
wledoux
 
Posts: 17
Joined: Wed Mar 23, 2011 5:29 pm

Re: Binding a key to a succession of commands

Postby iamntz on Fri Aug 19, 2011 10:12 am

You can always record a macro (ctrl+q)...
Take a look at the Default folder and .sublime-macro files.
iamntz
 
Posts: 918
Joined: Fri Apr 29, 2011 8:52 am
Location: Romania

Re: Binding a key to a succession of commands

Postby wledoux on Fri Aug 19, 2011 10:22 am

iamntz wrote:You can always record a macro (ctrl+q)...
Take a look at the Default folder and .sublime-macro files.

This is the first solution I tried. Since I did not find how to store a recorded macro in a file, I created a .sublime_macro file containing the following:
Code: Select all
[
   {"command": "hide_panel"},
   {"command": "find_next"}
]

But when I tried it, I had errors in the output
Code: Select all
Unknown macro command hide_panel
Unknown macro command find_next
wledoux
 
Posts: 17
Joined: Wed Mar 23, 2011 5:29 pm

Re: Binding a key to a succession of commands

Postby iamntz on Fri Aug 19, 2011 10:31 am

After you record a macro, you go to tools->save macro.
iamntz
 
Posts: 918
Joined: Fri Apr 29, 2011 8:52 am
Location: Romania

Re: Binding a key to a succession of commands

Postby wledoux on Fri Aug 19, 2011 11:00 am

I tried the save macro menu, but no explorer window appeared, and I understand now that it was because the macro failed to record.
So how do you proceed for recording such a macro ?
I tried:
  • Open the Find panel and make a valid search
  • press ctrl+q (status = "starting to record macro")
  • press F3 to find the next match
  • press echap to close the find panel
  • press ctrl+q (status is "starting to record macro" again...)
wledoux
 
Posts: 17
Joined: Wed Mar 23, 2011 5:29 pm

Re: Binding a key to a succession of commands

Postby wledoux on Tue Aug 23, 2011 7:51 am

Should I conclude that this was the easier way to do it, after all ?
I was expecting something like the code below to work, but It executed only one of the commands (the last one if I remember correctly).

Code: Select all
{ "keys": ["f3"], "command": "find_next", "command": "hide_panel", "context":
      [{"key": "panel", "operand": "find"}, {"key": "panel_has_focus"}]
},
wledoux
 
Posts: 17
Joined: Wed Mar 23, 2011 5:29 pm


Return to Technical Support

Who is online

Users browsing this forum: Exabot [Bot], Yahoo [Bot] and 15 guests