0

I have "Super+Alt+left" to set the layout so that the left pane is wider (66%) of the screen:

current ST2 layout

I would also like the same key stroke to focus on the left tab so that I can start typing immediately without a click or Ctrl + 0.

Here's what I tried. I added a new plugin:

import sublime, sublime_plugin

class ExpandAndFocusLeftPane(sublime_plugin.TextCommand):
  def run(self, edit):
    self.view.run_command("focus_group", "args": {"group": 0})
    self.view.run_command("set_layout", "args": {
       "cols": [0.0, 0.66, 1.0],
      "rows": [0.0, 1.0],
      "cells": [[0, 0, 1, 1], [1, 0, 2, 1]]
      })

And I bound "Super+Alt+Left" to this new command.

{
  "keys": ["super+alt+left"],
  "command": "expand_and_focus_left_pane",
  "args":
  {
    "cols": [0.0, 0.66, 1.0],
    "rows": [0.0, 1.0],
    "cells": [[0, 0, 1, 1], [1, 0, 2, 1]]
  }
},

But it still does not do what i want it to do. Any ideas ?

2
  • Are you seeing any effect from this key combination at all? Double-check your Default (OSX).sublime-keymap files (both Default and User) to make sure you haven't assigned this combo anywhere else. Commented May 9, 2013 at 13:52
  • yes, I am seeing effect from this key binding . Commented May 10, 2013 at 5:20

1 Answer 1

1

First, you have to check if the "focus_group" and "set_layout" commands work as expected. Open the console (View->Show Console) and try this:

view.run_command("focus_group", "args": {"group": 0})

You'll get a:

  File "<string>", line 1
    view.run_command("focus_group", "args": {"group": 0})
                                          ^
SyntaxError: invalid syntax   

If you change it to

view.run_command("focus_group", {"group": 0}) 

it won't work. That's because "focus_group" and "set_layout" are window commands, so this will work:

window.run_command("focus_group", {"group": 0})
window.run_command("set_layout", { "cols": [0.0, 0.66, 1.0], "rows": [0.0, 1.0],  "cells": [[0, 0, 1, 1], [1, 0, 2, 1]] })

So your plugin should extend sublime_plugin.WindowCommand and use self.window:

class ExpandAndFocusLeftPaneCommand(sublime_plugin.WindowCommand):
    def run(self):
        self.window.run_command("focus_group", {"group": 0})
        self.window.run_command("set_layout", {
           "cols": [0.0, 0.66, 1.0],
          "rows": [0.0, 1.0],
          "cells": [[0, 0, 1, 1], [1, 0, 2, 1]]
        })

And ExpandAndFocusLeftPane should be ExpandAndFocusLeftPaneCommand.

Sign up to request clarification or add additional context in comments.

4 Comments

What name should I use to save the plugin file? In which directory? Is there a convention?
And finally, how do I set up the Key binding for this command?
@gprasant { "keys": ["super+alt+left"], "command": "expand_and_focus_left_pane" } should work. You can test it using window.run_command("expand_and_focus_left_pane")
@gprasant Go to Preferences->Browse Packages, and there create a directory (eg: ExpandPane) and put the plugin file there (make sure it ends with .py)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.