Margin fold collapsing for code blocks - Visual Studio Style



  • Hi! I’m a Visual Studio programmer and I love Notepad++ but I just can’t get used to the way that it handles collapsing the margin fold for code blocks. I’m used to putting my curly brackets on separate lines instead of adding the opening bracket to the end of the line.

    Notepad++ does this just fine:

    function void DoThing(int Number) {
    //Do cool stuff here
    }

    While I’m used to doing it like this:

    function void DoThing(int Number)
    {
    //Do cool stuff here too
    }

    It’s just a formatting preference really. I can do it my usual way in Notepad++ but then it collapses the code blocks into the bracket instead of into the function declaration line.

    Is there a plugin to “fix” this for me? I’ve checked through the settings and all I can find is how to change the style of the collapse box, which I don’t really mind too much. My gripe is really that it collapses the code block into the bracket line instead of into the function declaration line.

    Any help/suggestions would be amazing.



  • Hello, Gryffydd David,

    I’m not a C/C++/C# programmer at all :-(( So, my answer may seem a nonsense for you !!

    But what about this ugly work-around ?!

    function void DoThing(int Number)  //{
    {
    //Do cool stuff here too
    }  //}
    

    More seriously, I suppose that code folding is handled by the editing component of N++ : Scintilla and it would be necessary to rewrite part of the C/C+/C# lexer !

    Anyway, I do hope that I’m wrong in that matter and that you’ll get more solid replies from the Community !

    Best regards,

    guy038



  • Your suggested workaound unfortunately isn’t. While the commented brackets are matched correctly and highlighted, they are not recognized as foldable.

    I don’t know if your supposition about Scintilla is correct or not. It would be nice if someone could answer that so we would know where to post our complaint in the right place.



  • I too find this to be a problem.

    I am in process of reorganizing some PHP code (in a—long since past support date—purchased package) into more comprehensible modules to simplify some customizing I want to do. There are numerous functions coded in the form:

    function DoThing(
    argument_1, // explanation (Seems like good coding practice.)

    argument_n) // explanation
    {
    good stuff
    }

    A principal advantage of syntax folding is the ability to easily copy and move a folded syntactical block (class, function, etc.). Language syntax awareness in an editor is generally understood as the ability to recognize important language elements such as “function” and understand their syntax. Other syntax aware editors I have used can fold at that level of awareness. However, I presently have only npp as a PHP-aware editor that can fold. Alas, full awareness of PHP language constructs appears to be not quite there in npp. (interestingly, “syntax folding” is mentioned in the very first item in the npp features list.)

    There are similar problems with folding of simplified PHP “if” statements without brackets. (Single statement if) If no brackets exist, there is no fold block at all. It is apparent that the only PHP syntax recognized is that code blocks appear inside brackets.

    I don’t consider these folding oddities merely a formatting preference. Having to select more lines than the folded block in order to get the entire actual syntactic piece (or do the syntactical analysis myself, visually) is obviously messier and more tedious than it should be.



  • Apparently, this is indeed a Scintilla issue. I found via Google search, a feature request thread titled “Fold { on relevant line”.
    https://sourceforge.net/p/scintilla/feature-requests/8/?page=0

    Note that this request is request number eight (8) and the date is fifteen (15) years ago! When an open request in a list currently numbering in four digits is numbered with a single digit, you can probably deduce no solution is likely anytime soon.

    Seems to me the only general solution for scintilla is to trigger fold start on the list of “foldable” language structures, and base fold ends on a multiline regex pattern that encompasses the language syntax definition of the structure. (That is, the one the language parser understands)


Log in to reply