Skip to content
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

Closes issue #71 #80

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

23maverick23
Copy link
Contributor

Adds AutoSwitchPane EventListener to auto-group files by syntax

I'm not sure if this is 100% what @fbm-static was looking for, but this seemed like a more practical approach to the underlying issue. When enabled, Origami will attempt to move loaded files of the same syntax into the same group (if available). You can also selectively enable this feature for specific syntax types in your User or Project settings files as well (in case that ever needs to happen). This feature is opt-in (e.g. disabled by default).

Let me know your thoughts. It should work in ST2 & ST3, although admittedly I was having some issues/inconsistencies with how ST2 wanted to deal with groups.

- Adds AutoSwitchPane EventListener to auto-group files by syntax
@FichteFoll
Copy link
Member

I would suggest using scope selectors instead of the path to the syntax file, but that's a preference thing I guess. I just find it easier to work with scopes compared to the long file paths.

@23maverick23
Copy link
Contributor Author

That's a good point - let me take a look at that. I saw a good example in SublimeCodeIntel - LN 411 that I may take a look at.

I'll update the PR and submit for code review. Thanks!

@FichteFoll
Copy link
Member

FYI, there is a match_selector and a score_selector method in the sublime API which would probably be handy.

- Update get_syntax_name to use scope if available
@adzenith
Copy link
Member

Sorry, I didn't get an e-mail that you'd pushed another commit! Let me take a look.

@adzenith
Copy link
Member

@FichteFoll: Will there be any concerns about nested scopes? Or are those avoided by checking at the last position of the file? I haven't worked with scopes or grammars a lot.

@adzenith
Copy link
Member

@23maverick23: This looks good! I know I made a lot of comments but I hope you know I appreciate your pull request 🍰
I also need to spend some time thinking about how the settings work.

@23maverick23
Copy link
Contributor Author

@adzenith Holy pull request comments! 😜 I love it!

  • Easy typo fix
  • Great point - I like view.settings().get('syntax')
  • I could definitely see a benefit in using a single setting, and changing the boolean to a "wildcard"; let me whip that up and submit an update
  • Great point with the settings naming convention - that's an easy fix; do you think it's beneficial to "deprecate" the saved_layouts naming convention and rename to origami_saved_layouts (we can make it backwards compatible, with a replace function)?
  • The get_setting() method isn't just getting user settings, it allows you to have per-project settings (using an Origami key inside your project settings file); I thought this was a nice feature in the case you want certain projects to have specific syntax groupings; do you think that's a bad feature?
  • Re: lowercase, the only reason I did that was to "normalize" the naming (in case someone wrote "JSON" when the syntax is "json"); I'm fine removing that if you think it could cause downstream effects
  • The catch for None is me being conservative; I can't think of a case when get_syntax_name would return None, except for some strange case where os.path.splitext or os.path.basename fails

Let me know if you have any other concerns. In the meantime, I'll get working on some updates!

@FichteFoll
Copy link
Member

@adzenith, I do it by getting the scope name at point 0 in the view, splitting the string (by spaces), extracting the firsts token and then running sublime.match_selector on it. I should have a code example for this in one of my repos but I'm on mobile right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants