Last active
April 24, 2016 02:39
-
-
Save daanzu/4b0992715d461ded8b5f61fe776740d0 to your computer and use it in GitHub Desktop.
Sublime Text plugin to select block at cursor, in various languages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Sublime Text plugin to select block at cursor, in various languages | |
# https://gist.github.com/daanzu/4b0992715d461ded8b5f61fe776740d0 | |
# view.run_command("select_block") | |
# view.settings().get('syntax') | |
import sublime, sublime_plugin | |
class SelectBlockCommand(sublime_plugin.TextCommand): | |
def run(self, edit): | |
self.view.run_command('expand_selection', {'to': 'indentation'}) | |
selection = self.view.sel() | |
for region in selection: | |
syntax = self.view.settings().get('syntax') | |
# if 'Python.' in syntax: begin_offset, end_offset = 1, 0 | |
# elif 'Ruby.' in syntax: begin_offset, end_offset = 1, 1 | |
# elif 'Slim.' in syntax: begin_offset, end_offset = 1, 0 | |
# elif 'JavaScript.' in syntax: begin_offset, end_offset = 1, 1 | |
# else: begin_offset, end_offset = 0, 0 | |
scope_name = self.view.scope_name(region.begin()) | |
scope = scope_name.split() | |
if 'source.python' in scope: begin_offset, end_offset = 1, 0 | |
elif 'source.ruby' in scope: begin_offset, end_offset = 1, 1 | |
elif 'text.slim' in scope: begin_offset, end_offset = 1, 0 | |
elif 'source.js' in scope: begin_offset, end_offset = 1, 1 | |
else: begin_offset, end_offset = 0, 0 | |
# print("begin_offset={} end_offset={} syntax={} scope={} scope_name={}".format(begin_offset, end_offset, syntax, scope, scope_name)) | |
selection.add(self.view.full_line(sublime.Region(region.begin()-begin_offset, region.end()-1+end_offset))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment