Feature Suggestion: Commenting out start and end of a code block

I use ctrl-slash and ctrl-shift-slash commands all the time, but I often find myself searching for the closing bracket of the line I just commented out. For example, lets say I have this code block:

if(x.size() > 0){
// bunch of stuff goes in here
.......

}

So you comment out the opening if statement like:

// if(x.size() > 0){

Then you have to go find the closing bracket and comment it out. This is particularly painful in things like a jsp page where they're generally quite long and harder to read.

So my suggestion would be something that would comment out the opening and closing bracket with one key sequence like "ctrl-alt-slash" or something.

4 comments
Comment actions Permalink

+1

I find myself in this situation a lot, too. And the fact that parsing kicks in and you end up with massive red is undesirable.

RRS

0
Comment actions Permalink

Yet another argument for putting the opening brace on a new line ;) (Sorry, I couldn't resist)

In all seriousness, how intelligent should such a feature be? What happens in the event of an if/else? Does it need to change the else to an if and comment out the else? What about a chain of else if? Or does it only work for a standalone if?

An alternate way to do this is to:
1. 2. shift+end 3. shift+]]>
4. ctrlshift/

Then you get

/*if (x.size() > 0) */{

}

The remaining braces don't affect anything. Unless you have a variable in scope you want to use outside the braces.

And if you want to do it in one keystroke, record the above as a macro (Tools | Start Macro Recording). Name the macro and then assign ctrlaltslash, or the keystroke of chose to it. Running the same macro on a commented out if line results in it getting uncommented. You now have your desired functionality (or very close to it).

0
Comment actions Permalink

p.s. if you want it so that the opening /* of the comment appears to the far left like the standard "comment out" features, hit the home key twice in step 1.

0

Please sign in to leave a comment.