Skip to content

Closes issue #71 #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Origami.sublime-settings
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".
*
* 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')
* The name of the tmLanguage file is what you want.
* Ex// ["json", "python"]
*/
"syntax_grouping": false,
"enabled_syntaxes": [],


/**
* The "saved_layouts" key holds a list of previously
* saved layout settings. These can be set using the
Expand Down
2 changes: 2 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ You can have Origami automatically zoom the active pane by setting `origami_auto

Origami can also automatically close a pane for you once you've closed the last file in it. Just set `origami_auto_close_empty_panes` to true in your user preferences.

Origami can also automatically move files of the same syntax into the same pane group when opening them. Set `syntax_grouping` to `true` in your user or project settings. If you only want specific syntax types to be automatically grouped, you can selectively enable them using the `enabled_syntaxes` list in your user or project settings. (If you don't know the syntax name to use, you can open the Sublime console with <kbd>CTRL</kbd>+<kbd>~</kbd> and type `sublime.active_window().active_view().settings().get('syntax')`. Copy the name of the _tmLanguage_ file without the path parameters.

Install
-------

Expand Down
61 changes: 61 additions & 0 deletions origami.py
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))
Expand Down Expand Up @@ -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):
"""
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."

Expand Down Expand Up @@ -763,3 +785,42 @@ 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):
pt = view.sel()[0].end()
scopes = view.scope_name(pt)
if scopes:
for scope in scopes.strip().split(" "):
if "source." in scope:
return scope[7:].lower()

if "text.html." in scope:
return scope[10:].lower()

if "text." in scope:
return scope[5:].lower()
else:
# fallback to path search if scopes are not available
syntax_path = view.settings().get('syntax')
return os.path.splitext(os.path.basename(syntax_path))[0].lower()

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:
w.set_view_index(view, group, 0)
w.focus_view(view)