Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any tools in IDEs to automatically fix comment formatting?

/* 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?

like image 472
Fragsworth Avatar asked Mar 08 '10 17:03

Fragsworth


People also ask

How do I tidy up code in Visual Studio?

You can also run code cleanup across your entire project or solution. Right-click on the project or solution name in Solution Explorer, select Analyze and Code Cleanup, and then select Run Code Cleanup.

How do I fix indentation in IntelliJ?

Open indentation settings in code style scheme Click the widget and select Configure Indents for 'Language'. In the dialog that opens, you can change settings for tabs and indents and also configure other code style settings. Click OK. Reformat the necessary part of your project to apply new indentation settings.

What is the use of #define in IDE?

#define is a useful C++ component that allows the programmer to give a name to a constant value before the program is compiled. Defined constants in arduino don't take up any program memory space on the chip. The compiler will replace references to these constants with the defined value at compile time.


2 Answers

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.
 */
like image 58
Alex B Avatar answered Oct 13 '22 00:10

Alex B


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.

like image 35
JasCav Avatar answered Oct 13 '22 00:10

JasCav