#798 C++ etc code-folding comments should be harder to trigger


Currently, you can denote a foldable region for any of the languages that use the C++ lexer with
the sequences "//{" and "//}" anywhere in a comment.

The problem is that if you have a block of code
if (test) {
.... actions

and comment it out with a substitution like

where S denotes the leading white space for the if stmt,
you end up with this code:

//if (test) {
// .... actions

So now the final line of the commented block closes a fold level, but
the start of the block doesn't open one. This asymmetry breaks
code folding.

The problem is that the code is taking two common constructs in C++/C/JS/etc.
code: "//" to start a comment, and "{" or "}" to start or end a scope, and interpreting
their concatenation as something different. This typically isn't a problem with
the triple-brace fold region used in other languages, because well-written code
is unlikely to use sequences like "{{{" or "}}}" to open or close three scopes
(ok, machine-generated code could emit "}}}", but that's not the kind of code
we're talking about here).

The problem reminds me a bit of a gotcha Fortran programmers used to run
into when they ported their code to C, and simply changed all by-reference
vars to pointers. Fortranners do a lot of math, and would invariably do something
like this:

double someFunc(double *a, double *b, double *c, /* ... more args */) {
/* some prelim code */
return bessel(*a+*b/*c*PI+42.0);

and wonder why they got compiler errors. (Note the typical
stereotype that Fortran people avoided using spaces whenever possible
as well)

I realize the C++ lexer has used single-brace fold regions for a long time (the oldest
version I have on hand is 174), but I recommend replacing them with "{{{" and "}}}"
anywhere in COMMENTLINE states, not just immediately after "//".

Ref Komodo bug http://bugs.activestate.com/show_bug.cgi?id=89637


  • Eric Promislow

    Eric Promislow - 2011-03-25

    I submitted this -- I didn't realize I wasn't logged in to sf until a few microseconds after I pressed 'submit'

  • Neil Hodgson

    Neil Hodgson - 2011-03-25

    You can change the strings used for folding comments with the properties fold.cpp.explicit.start and fold.cpp.explicit.end.

    Changing the default in Scintilla would not be compatible with the current files of users who have used folding comments.

  • Neil Hodgson

    Neil Hodgson - 2011-03-25
    • assigned_to: nobody --> nyamatongwe
    • priority: 5 --> 4
    • milestone: --> Won't_Implement
  • Eric Promislow

    Eric Promislow - 2011-03-28

    Thanks for pointing that out, Neil.

    We're still on 2.02. So this will happen once we upgrade Scintilla.

  • Nobody/Anonymous

    oGobLD <a href="http://ufpkrkktiiiz.com/">ufpkrkktiiiz</a>, [url=http://bcdcfppimyhc.com/]bcdcfppimyhc[/url], [link=http://kknlrmpqfqeo.com/]kknlrmpqfqeo[/link], http://mpjfysknfrtn.com/

  • Nobody/Anonymous

    AwTHzM <a href="http://lutdsjifuaul.com/">lutdsjifuaul</a>, [url=http://vgpzwhiggofy.com/]vgpzwhiggofy[/url], [link=http://wyffijecmcca.com/]wyffijecmcca[/link], http://pguvysqjdanw.com/

  • Neil Hodgson

    Neil Hodgson - 2011-05-25
    • status: open --> closed

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks