Menu

#650 Some comment command issues

Undefined
open
nobody
None
Undefined
2018-05-02
2018-03-22
raynebc
No

As reported by rogeriodec here:
http://forums.codeblocks.org/index.php/topic,22518.msg153173

If a selected block of code includes some lines that are already comments, ie:

//x = 1;
y = 1;

the result of the "Edit>Toggle comment" command is that both lines are commented instead of un-commenting the lines that were already comments.

I also see that if a line is commented using three forward slashes (CodeBlocks displays these comments in bold text for emphasis), ie:

///x = 1;

Using the toggle comment or uncomment functions on that line results in:

/x = 1;

If the Edit>Comment function is used on a line that is already commented beginning with two forward slashes:

//x = 1;

It prefixes the line with another two forward slashes even though it may be better to skip editing of that line.

Discussion

  • Teodor Petrov

    Teodor Petrov - 2018-03-22

    The last explained problem is really something done by design and must not be changed. Because the idea is that only one level of comments should be added or removed. And this must happen without magical conditions. It is done to make it possible to comment and uncomment reliably code which contains mixture of code and comments. If we do some magic we might remove comments where this is not a good idea and we could break code. For example you have some block of code where you have commented some lines to test the code without them. After some testing you decide that you want to comment a bigger block. At the moment you can select the block and use the comment operation. This adds a comment for the entire block. If you later decide you want to restore the code in the original variant you can use the uncomment command for the block and then the whole comment (one level) would be removed and you'll end with the original code where the first block of code is still commented.

     
    • Rogerio

      Rogerio - 2018-03-22

      Okay, but just to make it clear, Notepad ++ and other editors make the correct inversion, ie in a multiple selection, which is like comment turns normal line and what is like normal line turns comment.
      I've suggested this improvement to standardize behavior between editors and because it's also the most logical action to take in the editor in this case.

       
      • Teodor Petrov

        Teodor Petrov - 2018-03-22

        The behaviour of toggle is probably fine to be changed, but not the behaviour of the comment and uncomment commands.

         
  • Adam Kessler

    Adam Kessler - 2018-03-26

    I see the same behavior in Code::Blocks 17.12 on Windows 10 Version 1709 after following the example outlined in the issue. It may be worthwhile to try the comment and uncomment features on different types of comments, such as block comments, or single line comments with different numbers of slashes to get a better understanding of the behavior of the "Edit->Comment" and "Edit->Uncomment" featuers in Code::Blocks.

     
  • bluehazzard

    bluehazzard - 2018-05-02

    "Edit->Comment" adds "//" at the beginning of the line and
    "Edit->Uncomment" deletes "//" at the beginning of the line if present.
    This is intended behaviour and i am strongly against anything more complex for this logik!

    attached is a patch that fixes the toggle problem.
    It toggles only if the line starts with a comment, but not if in the middle is a comment. I don't think it would make sense to implement more logic about this...

    edit: if i talk about "//" or "comment" i mean the string defined as "line comment" by the lexer

     

    Last edit: bluehazzard 2018-05-02
  • bluehazzard

    bluehazzard - 2018-05-02

    About the ?bug? with "///" i am not sure what to do...

     
  • raynebc

    raynebc - 2018-05-02

    If the line begins with more than 2 forward slashes, it might be best to remove all the slashes from the beginning of the line so that it truly converts to a non-commented line. Programmers that are using the comment on/off/toggle functions will probably have to be willing to live with the limitation that it's unreasonable to expect CodeBlocks to remember whethera line used to have more than 2 slashes when it was previously a commented line.

     
  • bluehazzard

    bluehazzard - 2018-05-02

    the thing is, that the current code is language agnostic... If in some language the line comment begins with % this code will work too. I am not that happy by adding some special logic for c/c++ only....

     
  • raynebc

    raynebc - 2018-05-02

    In that case it can be a known limitation that it won't work for "non-standardized" commenting methods or something. Or whatever language specific logic there is to detect a comment could be programmed to know that any plural number of consecutive forward slashses is a comment until end of line if that's even considered worthwhile.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.