Split when using python-tools package


When using python-tools ctrl+alt+g keybind to go to definition: is there a way for opening the code where the definition is, but splitted to the right instead of in the same pane overlapping the current code I’m reading?

Thanks in advance!


You just have to split the editor before you run the python-tools command, because it targets whichever TextEditor is currently active. Just add this to your init.coffee and then attach it to a keybinding (such as ctrl-alt-g).

atom.commands.add "atom-text-editor", "custom:split-and-go-to-python-def", ->
  editor = atom.workspace.getActiveTextEditor()
  # Quit if the active editor isn't Python. If you want to expand this command to support other languages, you can change this into a smarter conditional.
  return unless editor.getGrammar() == atom.grammars.grammarForScopeName("source.python")

  atom.workspace.getActivePane().splitRight({copyActiveItem: true})

  newEditor = atom.workspace.getActiveTextEditor()
  atom.commands.dispatch newEditor.element, "python-tools:goto-definition"


Thank you @DamnedScholar !

That worked perfectly. I attached it to the keybind alt-q instead and keep the alt-ctrl-g as it was.

Couple of things to add though, just to improve the behaviour of this keybind:

  1. It also splits the current code I’m reading. So in the new pane I do have the definition and the main code as well.

  2. Every time I enter the keybind it opens a new splitted pane, even if there is one already opened. It would be more useful if it opens only one new splitted pane and then everytime you go to a new definition, it overlaps the previous one.

It is my first contact with coffee scripting, I’ll try to figure this out myself but tips are welcome!



You can use JavaScript if you know it better.