Skip to content

Instantly share code, notes, and snippets.

@markalfred
Created December 24, 2014 16:31
Show Gist options
  • Save markalfred/4602a64effeb07195f72 to your computer and use it in GitHub Desktop.
Save markalfred/4602a64effeb07195f72 to your computer and use it in GitHub Desktop.
Determine the best "other" Sublime Text pane.
def determine_output_pane(self):
"""
When the user performs some action which results in a file being
opened or generated in a new tab, we should place that "output"
code in an adjacent pane. This method will determine the correct
pane to place the output in.
It will use a tab to the right, if one exists in the current row.
If not, output is placed in the adjacent tab to the left. Output
should always be adjacent, and should never be on a different row,
if a grid-style layout is in use.
"""
active_group = self.window.active_group()
num_groups = self.window.num_groups()
layout = self.window.get_layout()
cells = layout['cells']
cols = layout['cols']
if num_groups == 1:
# Only pane. Create a new one.
self.window.run_command('set_layout', {
"cols": [0.0, 0.5, 1.0],
"rows": [0.0, 1.0],
"cells": [[0, 0, 1, 1], [1, 0, 2, 1]]
})
return 1
elif active_group == num_groups - 1:
# Last pane in window. Use the previous one.
return active_group - 1
elif len(cols) > 2 and cells[active_group][2] == len(cols) - 1:
# Last pane in row. Use the previous one.
return active_group - 1
else:
# Otherwise, use the next one.
return active_group + 1
# Example Usage:
def run(self):
output_pane = self.determine_output_pane()
output_view = self.window.open_file(output_file_path)
self.window.set_view_index(output_view, output_pane, 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment