-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Adds AutoSwitchPane EventListener to auto-group files by syntax
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,22 @@ | ||
{ | ||
/** | ||
* The "syntax_grouping" key determines if you want | ||
* Origami to attempt to group files with the same syntax | ||
* into the same pane. The default if "false". | ||
This comment has been minimized.
Sorry, something went wrong. |
||
* | ||
* The "enabled_syntaxes" key holds a list of syntaxes | ||
* that qualify for grouping. Each syntax should be entered as | ||
* a string. A blank list means all syntaxes qualify. If you are | ||
* unsure of the correct syntax name, you can open the Sublime console | ||
* and enter the following command: | ||
* sublime.active_window().active_view().settings().get('syntax') | ||
This comment has been minimized.
Sorry, something went wrong.
adzenith
|
||
* The name of the tmLanguage file is what you want. | ||
* Ex// ["json", "python"] | ||
*/ | ||
"syntax_grouping": false, | ||
"enabled_syntaxes": [], | ||
This comment has been minimized.
Sorry, something went wrong.
adzenith
|
||
|
||
|
||
/** | ||
* The "saved_layouts" key holds a list of previously | ||
* saved layout settings. These can be set using the | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
from __future__ import division | ||
import sublime, sublime_plugin | ||
import copy | ||
import os | ||
from functools import partial | ||
|
||
XMIN, YMIN, XMAX, YMAX = list(range(4)) | ||
|
@@ -62,6 +63,27 @@ def fixed_set_layout_no_focus_change(window, layout): | |
active_group = window.active_group() | ||
window.set_layout(layout) | ||
|
||
def get_setting(view, key, default=None): | ||
This comment has been minimized.
Sorry, something went wrong.
adzenith
|
||
""" | ||
Get a Sublime Text setting value, starting in the project-specific | ||
settings file, then the user-specific settings file, and finally | ||
the package-specific settings file. Also accepts an optional default. | ||
""" | ||
try: | ||
settings = view.settings() | ||
if settings.has('Origami'): | ||
s = settings.get('Origami').get(key) | ||
if s and len(s) > 0: | ||
return s | ||
else: | ||
pass | ||
else: | ||
pass | ||
except: | ||
pass | ||
global_settings = sublime.load_settings('Origami.sublime-settings') | ||
return global_settings.get(key, default) | ||
|
||
class PaneCommand(sublime_plugin.WindowCommand): | ||
"Abstract base class for commands." | ||
|
||
|
@@ -763,3 +785,29 @@ def on_activated(self, view): | |
self.running = True | ||
|
||
sublime.set_timeout(lambda: self.delayed_zoom(view, fraction), 0) | ||
|
||
class AutoSwitchPane(sublime_plugin.EventListener): | ||
def get_syntax_name(self, view): | ||
syntax_path = view.settings().get('syntax') | ||
syntax_name = os.path.splitext(os.path.basename(syntax_path))[0].lower() | ||
This comment has been minimized.
Sorry, something went wrong.
adzenith
|
||
return syntax_name | ||
|
||
def on_load(self, view): | ||
syntax_grouping = get_setting(view, 'syntax_grouping') | ||
enabled_syntaxes = [s.lower() for s in get_setting(view, 'enabled_syntaxes')] | ||
|
||
if syntax_grouping: | ||
w = sublime.active_window() | ||
view = w.active_view() | ||
views = w.views() | ||
current_syntax = self.get_syntax_name(view) | ||
|
||
if views and (len(enabled_syntaxes) == 0 or current_syntax in enabled_syntaxes): | ||
for v in views: | ||
syntax = self.get_syntax_name(v) | ||
group = w.get_view_index(v)[0] | ||
|
||
if syntax and syntax == current_syntax: | ||
This comment has been minimized.
Sorry, something went wrong. |
||
w.set_view_index(view, group, 0) | ||
w.focus_view(view) | ||
|
Should say "is" instead of "if" 🍬