Linux – Geany comment block format

ccommentsgeanylinux

I'm trying to figure out where the comment block style is defined in Geany for C files.

By this I mean when I select a block of text and hit ctrl-e, each line in the block of text
is pre-pended (at it's indentation level) by a //~

A problem comes from the extra space. On blank lines I get //~ but I also have trim-trailing white-space enabled when I save the files, so I get the following sequence.

void aprinter(uint8_t * buf) {
    uint16_t length = sizeof(*buf) / sizeof(buf[0]);

    printf("len: %d;\n", length);

    uint16_t i;
    for (i = 0; i < length; i++) {
        printf("buf[%d]: 0x%02x;\n", i, buf[i]);
    }

}

I want to comment out the guts of this function so I select it and hit ctrl-e

void aprinter(uint8_t * buf) {
    //~ uint16_t length = sizeof(*buf) / sizeof(buf[0]);
//~ 
    //~ printf("len: %d;\n", length);
//~ 
    //~ uint16_t i;
    //~ for (i = 0; i < length; i++) {
        //~ printf("buf[%d]: 0x%02x;\n", i, buf[i]);
    //~ }
}

I save the code in this state and later come back to uncomment the lines, ctrl-e again gives me this

void aprinter(uint8_t * buf) {
    uint16_t length = sizeof(*buf) / sizeof(buf[0]);
//~ //~
    printf("len: %d;\n", length);
//~ //~
    uint16_t i;
    for (i = 0; i < length; i++) {
        printf("buf[%d]: 0x%02x;\n", i, buf[i]);
    }
}

I'd really like to get Geany to use the same syntax as eclipse (prepend //), since I flip back and forth between the two and have no way to uncomment blocks in one that were created by the other.

I'd be happy to just remove the trailing space however, to get rid of these bogus //~ //~ lines.

Another ugly feature of the geany code block comments is that if you have a block of commented code inside a larger block that you are now commenting out, it will uncomment the internal block.

I grep'd the configuration file paths (/usr/share/geany and ~/.config/geany) and didn't find //~


EDIT:

after all of that searching I just stumbled onto the 'comment toggle marker' option under
Edit -> Preferences -> Editor -> Features

I would still be interested in a way to have the comments added to the beginning of the line rather than at the indent level.

Best Answer

I'm trying to figure out where the comment block style is defined in Geany for C files.

All color definitions and other filetype specific settings are stored in the filetype definition files. Those settings are colors for syntax highlighting, general settings like comment characters or word delimiter characters as well as compiler and linker settings.

...

Comment_single

  • A character or string which is used to comment code. If you want to use multiline comments only, don't set this but rather comment_open and comment_close.

  • Single-line comments are used in priority over multiline comments to comment a line, e.g. with the Comment/Uncomment line command.

    Example: comment_single=//

comment_open

  • A character or string which is used to comment code. You need to also set comment_close to really use multiline comments. If you want to use single-line comments, prefer setting comment_single.

  • Multiline comments are used in priority over single-line comments to comment a block, e.g. template comments.

    Example: comment_open=/*

comment_close

  • If multiline comments are used, this is the character or string to close the comment.

    Example: comment_close=*/

comment_use_indent

  • Set this to false if a comment character or string should start at column 0 of a line. If set to true it uses any indentation of the line.

    Note: Comment indentation

    comment_use_indent=true would generate this if a line is commented (e.g. with Ctrl-D):

    #command_example();

  • comment_use_indent=false would generate this if a line is commented (e.g. with Ctrl-D):

    # command_example();

  • Note: This setting only works for single line comments (like '//', '#' or ';').

    Example: comment_use_indent=true

Source Filetype definition files


I would still be interested in a way to have the comments added to the beginning of the line rather than at the indent level.

Use comment_use_indent=false

Related Question