Indeed, although that one is useless if you want to do something like wrap the current statement in an "if" or "while" or similar. "Expand Selection to Brackets" will actually include the lines containing the brackets, so you can't use it to select the
contents of a block.
Sublime also has "Expand Selection to Scope", except it doesn't really work that well: First invocation it chooses the current symbol, on 2nd the current brace block except the braces, on 3rd the braces themselves, and so on.
And it also has "Expand Selection to Indentation", but I don't see use for it in cases where you want to manipulate blocks of code, since it nearly always doesn't select what you want.
What I'd like is a command, let's call it "Expand Selection to Statement or Block", that:
* On 1st invocation, selects the current line.
int foo(int bar) {
bar = mogrify(bar);
if (bar > 0) {
slartibartfast = 42;
[[baz = bar + 1;]] # <-- [[ selection ]]
print_report();
}
return bar;
}
* On 2nd invocation, expands to the current contiguous set of lines, bounded by either empty lines or language-specific block (usually braces, or in Ruby's case, "if/while/..." until "end"), but not including the boundary:
int foo(int bar) {
bar = mogrify(bar);
if (bar > 0) {
slartibartfast = 42;
[[baz = bar + 1;
print_report();]]
}
return bar;
}
* On 3rd invocation, expands to the current contents of the block, excluding braces and excluding the lines containing the braces.
int foo(int bar) {
bar = mogrify(bar);
if (bar > 0) {
[[slartibartfast = 42;
baz = bar + 1;
print_report();]]
}
return bar;
}
* On 4rd invocation, expands to the enveloping statement that uses the block:
int foo(int bar) {
bar = mogrify(bar);
[[if (bar > 0) {
slartibartfast = 42;
baz = bar + 1;
print_report();
}]]
return bar;
}
* On 5th invocation, it would continue to step 2, ie., looking for more lines that are contiguous with the current selection:
int foo(int bar) {
bar = mogrify(bar);
[[if (bar > 0) {
slartibartfast = 42;
baz = bar + 1;
print_report();
}
return bar;]]
}
* And so on. Eventually it will get to the entire function declaration.
Combined with a "wrap selection in braces"-type command (that indented the selection, wrapped it in braces, and placed the caret at the beginning so you could start typing something like "if (...) {") you would have a fairly powerful block-manipulating shortcut.
It would probably be quite trivial to write such a plugin. I might try my hand at this. Not sure how much language sensitivity it would need, might be doable without anything at all.