Geany comment block format

2

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.

user3817250

Posted 2014-12-05T16:00:15.960

Reputation: 123

Answers

4

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

DavidPostill

Posted 2014-12-05T16:00:15.960

Reputation: 118 938

good information. However if you will see my EDIT, despite how often I've been pointed to the Filetype definition files the ~ part of the comment block was not defined there but was accessible through the gui Edit -> Preferences -> Editor -> Features -> comment toggle marker – user3817250 – 2014-12-05T16:48:47.970

"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." - try using comment_use_indent=false as described in my answer. – DavidPostill – 2014-12-05T16:51:41.913

Excellent. I should have taken a little more time absorbing that info. – user3817250 – 2014-12-05T16:55:52.033

1Can I have multiple block comments defined - for /* */ and {* *} ? – Michal Przybylowicz – 2015-06-05T12:24:55.860

1@MichałPrzybyłowicz Not as far as I know, but then most languages would only have one kind of block comment ... – DavidPostill – 2015-06-05T17:19:29.890

I agree. But tpl files are a mix of html and smarty syntax, so basically it has two kinds of block comments. – Michal Przybylowicz – 2015-06-05T18:52:21.807

so there is no way to comment blocks of code? /* */ – t q – 2015-11-03T22:23:02.680

@tq Yes, you can, see the answer. comment_open and comment_close – DavidPostill – 2015-11-03T22:31:24.460

@DavidPostill I am in Edit -> Preferences -> Editor -> Features and i dont see comment_open or comment_close – t q – 2015-11-03T22:45:21.403

1@tq "filetype specific settings are stored in the filetype definition files." – DavidPostill – 2015-11-03T22:47:24.123

@DavidPostill I see in filetypes.php there is comment_open=/* comment_close=*/ but when i comment lines in a php file I still get single line // comments – t q – 2015-11-03T23:12:31.090

@tq Single-line comments are used in priority over multiline comments to comment a line, e.g. with the Comment/Uncomment line command. – DavidPostill – 2015-11-03T23:27:19.920

Let us continue this discussion in chat.

– t q – 2015-11-03T23:29:32.157

@tq I don't have anything to add. Please ask a new question. – DavidPostill – 2015-11-03T23:31:51.347