问题
After I applied Atom Beautify on my code using Uncrustify, the trailing comments are aligned as follow:
unsigned int redLEDValue = 0; // redLED
unsigned int blueLEDValue = 0; // blueLED
unsigned int greenLEDValue = 0; // greenLED
unsigned int redSensorValue = 0; // redSensor
unsigned int blueSensorValue = 0; // blueSensor
unsigned int greenSensorValue = 0; // greenSensor
There is only once space between the semicolon and the trailing comment, but I want to have at least 2 spaces between them. I'm using Atom 1.12.9, Atom Beautify 0.29.16, and Uncrustify 0.64. Here is my Uncrustify config.
Is there any way to increase the gap? I've already set align_right_cmt_span = 4
but no hope. Thanks in advance.
回答1:
You have to enable adding spaces first with the option:
sp_before_tr_emb_cmt = add
sp_before_tr_emb_cmt: Controls the spaces before a trailing or embedded comment
Than you can adjust the amount of spaces with:
sp_num_before_tr_emb_cmt = 2
sp_num_before_tr_emb_cmt: Number of spaces before a trailing or embedded comment
Edit:
Uncrustify has also an aligning function for trailing comments which is applied after the spacing functionalities. The aligning function is controlled by those three options:
align_right_cmt_span = 1 # unsigned number
The span for aligning comments that end lines (0=don't align)
align_right_cmt_gap = 10 # number
If a trailing comment is more than this number of columns away from the text it follows, it will qualify for being aligned. This has to be > 0 to do anything. A negative value [will] force comments which are stuck to the previous token (gap=0) into alignment with the others.
align_right_cmt_at_col = 80 # unsigned number
Align trailing comment at or beyond column N; 'pulls in' comments as a bonus side effect (0=ignore)
Note:
- The functionality is enabled if
align_right_cmt_span
is greater than 0. - Contrary to its description
align_right_cmt_gap
is enabled if it is 0. All numeric options are initially set to 0 as default values. - If
align_right_cmt_at_col
is less than the column of the last char before the beginning of the comment the comment will be indented to one space after the last char.
来源:https://stackoverflow.com/questions/41526950/uncrustify-how-do-i-align-trailing-comments-by-two-space-gap