Home Download Buy Blog Forum Support

Keybindings with sequence and save

Keybindings with sequence and save

Postby Seldaek on Mon Oct 26, 2009 9:52 am

Heya,

I tried to use this to strip whitespace and then save automatically when I press ctrl+s, but somehow as soon as I save the snippet it fails to save. It runs the whitespace cleanup alright though, but doesn't seem to execute the save command. I tried just binding it to command="sequence save", this also fails to save the file. Is it expected ?

Code: Select all
<binding key="ctrl+s" command="sequence 'removeWhitespace trailing' 'removeWhitespace extra' 'save'" />


Cheers
Seldaek
 
Posts: 27
Joined: Mon Oct 26, 2009 9:50 am

Re: Keybindings with sequence and save

Postby jps on Mon Oct 26, 2009 12:51 pm

sequence only works on commands that operate on the view, while save is a window command, so it doesn't know what to do with it.

Your best bet is to write a quick python plugin to do this, something along the lines of:

Code: Select all
import sublime, sublimeplugin

class StripAndSaveCommand(sublimeplugin.WindowCommand):
   def run(self, window, args):
      window.activeView().runCommand('sequence', ['removeWhitespace trailing', 'removeWhitespace extra'])
      window.runCommand('save')


and then

Code: Select all
<binding key="ctrl+s" command="stripAndSave"/>
jps
Site Admin
 
Posts: 3067
Joined: Wed Mar 19, 2008 12:33 pm

Re: Keybindings with sequence and save

Postby jps on Mon Oct 26, 2009 12:52 pm

bah, beaten to it :)
jps
Site Admin
 
Posts: 3067
Joined: Wed Mar 19, 2008 12:33 pm

Re: Keybindings with sequence and save

Postby Seldaek on Mon Oct 26, 2009 1:28 pm

Alright thanks for the explanation, and thanks nonetheless jps for the example, my python is getting rusty and I'm just getting started with sublime so I much appreciate it.
Seldaek
 
Posts: 27
Joined: Mon Oct 26, 2009 9:50 am

Re: Keybindings with sequence and save

Postby gpfsmurf on Tue Oct 27, 2009 7:37 pm

How about changing 'sequence' to do something like this with each command:
Code: Select all
if view.canRunCommand(cmd):
    view.runCommand(cmd)
else:
    view.window().runCommand(cmd)
gpfsmurf
 
Posts: 211
Joined: Mon Jun 23, 2008 6:31 pm


Return to Technical Support

Who is online

Users browsing this forum: No registered users and 20 guests