views:

76

answers:

2
/* Suppose I have a multi-line comment with hard line-breaks
 * that are roughly uniform on the right side of the text,
 * and I want to add text to a line in order to make the
 * comment a bit more descriptive.
 */

Now, most unfortunately, I need to add text to one of the top lines.

/* Suppose I have a multi-line comment with hard line-breaks (here is some added text for happy fun time)
 * that are roughly uniform on the right side of the text,
 * and I want to add text to a line in order to make the
 * comment a bit more descriptive.
 */

It takes O(n) time (n being the number of lines) to fix each line so that they roughly line up again. The computer should do this, not me.

Are there tools to deal with this in our IDEs? What are they called?

+4  A: 

emacs supports the command fill-paragraph which is typically mapped to meta-q.

Output from fill-paragraph on your second paragraph of text:

/* Suppose I have a multi-line comment with hard line-breaks (here is
 * some added text for happy fun time) that are roughly uniform on the
 * right side of the text, and I want to add text to a line in order
 * to make the comment a bit more descriptive.
 */
Alex B
Unfortunately I don't use emacs, but it looks like this is the only editor which supports this kind of thing.
Fragsworth
For most of my java development, I use IntelliJ. However, I still do pull out emacs to do some tasks that emacs is really good at.
Alex B
+2  A: 

Eclipse has this built in (at least, I think it's what you want). When you type a comment, you then type Ctrl+Shift+F and it will format either all your code, or just the section of code that you have highlighted.

I just tested it now and it aligned all my comments for me.

JasCav
I think that he's looking for the solution to change the line length as well rather than just line them up so that they are mostly aligned on the right as well as precisely aligned on the left.
Jacob G
@Jacob G - Ah, I didn't understand that. Good call. (Seems like Peter also went through the same thought process I did.)
JasCav