Thyrum / vim-stabs

A vim plugin to use tabs for indentation and spaces for alignment
GNU General Public License v3.0
14 stars 5 forks source link

Improper alignment of comments #7

Open f1r35pirit opened 2 months ago

f1r35pirit commented 2 months ago

When I use stabs = hotkey on this (properly aligned) code:

typedef struct {
»›››fru_field_type_t type; /**< The encoding type of the field.
»›››                        *
»›››                        * Takes any of the \p field_type_t values
»›››                        */
»›››char val[FRU_FIELDMAXARRAY]; ///< The decoded C-string representation of the field value
} fru_decoded_field_t;

I get this (indentation instead of alignment):

typedef struct {
»›››fru_field_type_t type; /**< The encoding type of the field.
»›››»›››»›››»›››»›››»›››»›››*
»›››»›››»›››»›››»›››»›››»›››* Takes any of the \p field_type_t values
»›››»›››»›››»›››»›››»›››»›››*/
»›››char val[FRU_FIELDMAXARRAY]; ///< The decoded C-string representation of the field value
} fru_decoded_field_t;

Where »››› is visualization of a TAB symbol in my ViM.

Also, when I push Enter at the end of an open comment block, I get this:

typedef struct {
»›››fru_field_type_t type; /**< The encoding type of the field.
»›››»›››»›››»›››»›››»›››»››› _

Where _ is the cursor position. That is, the cursor is positioned one position to the right from the above asterisk, and the asterisk is not repeated. I would expect the asterisk to be repeated, and the cursor put two positions to the right from it.

smemsh commented 2 months ago

does this work correctly without stabs? this seems to be more an issue with vim's internal cindent. have you tried playing with cinoptions?

f1r35pirit commented 2 months ago

What do you suggest I put in cinoptions for "tabs for indentation, spaces for alignment" to work correctly in all cases on c and c++ files?

smemsh commented 2 months ago

My mistake, I thought that stabs didn't override = but now I see that it does end up calling StabsFixAlign() on the range. I can reproduce your example and it does seem like it should fill with spaces (after the first tab used for alignment). It has the same issue with ordinary <CR> after an unfinished comment, which also would end up calling the same function as =.

Looking at the code, I noticed that the = remap is only used for normal mode. Are you using visual mode to select the line range? In any case, even with =<motion> (such as =_ to do the single line under the cursor), it still doesn't work right. The function sets big based on the last character in the line, which probably doesn't make sense for comments.

I tried for a while to fix it, but ran out of time. I think it can be fixed, but would take longer than I have at the moment. I might get to it at some point if nobody beats me to it, but not for a while.