Home Download Buy Blog Forum Support

Use entire scope as input in plugin

Use entire scope as input in plugin

Postby andrewheiss on Mon Jul 23, 2012 2:55 am

One of the nice things about Textmate was the ability to pipe the contents of an entire scope into a command, like so:


You could then specify the scope to be used, such as "meta.class.python" or whatever.

I'm trying to write a small plugin that will pipe the entire current scope in as the input for the plugin (for example (not exactly what I'm trying to do, but close), a function that lets you comment out an entire Python class without selecting it all)

Using the current selection(s) as input is quite easy:

Code: Select all
import sublime, sublime_plugin
import re

class DoStuffWithSelection(sublime_plugin.TextCommand):
    def run(self, edit):
        for region in self.view.sel():
            if not region.empty():
                changed = region  # Do something to the selection
                self.view.replace(edit, region, changed)  # Replace the selection

I've scoured the Sublime Text plugin API for some way to do something like `for region in self.view.scope()`, but without success.

Is there a way, then, to use the contents of the current scope under the cursor as input for a plugin function? Or, even better, a way to use the entire scope if there isn't a selection, but use the selection if there is one.

Posts: 1
Joined: Mon Jul 23, 2012 2:34 am

Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 4 guests