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)

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.