Fold Margin Style Box Tree
-
-
Each built-in language defines its own rules for folding in Notepad++ (specifically, in the Lexilla library that Notepad++ uses). They were not designed in a way that allow their rules to be extended by users (and the Notepad++ developer doesn’t have any influence over the design of Lexilla, so cannot add that feature).
The User Defined Languages (UDL) that users create do allow defining keywords for folding, so a pair like OPEN:
Sub
and CLOSE:"End Sub"
would be doable (the quotes are needed when there is a space in the “keyword”)You haven’t said what language your code is in, though given the style and Workbooks & Range keywords, I am guessing it is Excel VBA, and thus would use the Visual Basic language in Notepad++.
And while your snippet folding looks wrong, you didn’t give us
enoughtext that we could copy/paste to replicate your problem. And when I manually type a small snippet with reasonable VBA, it folds correctly.Ah, there, if I replicate your horrendous indentation which the Excel VBA editor would have autocorrected for you,
Sub NameHere() Set HelpBookP = 5 Set HelpBookP = 5 if a=b then rem xyz end if Range("K1:K5") End Sub
Then it renders with weird folding, like:
Whereas if I properly indent, then it renders the folding reasonably:
Sub NameHere() ' here is reasonable Set HelpBookP = 5 Set HelpBookQ = 6 if a=b then rem xyz end if Range("K1:K5") End Sub
But if I do something “silly” like add a blank line between the sub and the first command or remark, then it does mess up the rendering of the fold box:
… though if I click on the invisible open-fold on the Sub line, it does allow me to fold:
Since VBA (unlike Python) doesn’t actually consider whitespace as significant, I agree that the folding logic is wrong. I will work on confirming using the SciTE editor (which is the testbed “editor” for the Scintilla/Lexilla libraries) – if I can, I will create an issue with the Lexilla folks
update: confirmed in SciTE, and reported as issue #307
-
@PeterJones Thank You.
I’m using excel vba exported to “Choose a Book.bas”
in Notepad++ I use “Visual Basic” Language.:-
Sub Get_Selected_File_Properties2() Set HelpBookPath = Workbooks("HelpBook.xlsm").Worksheets("StartSheet") Set HomeBookPath = Workbooks("Testing Get File Info 09.xlsm").Worksheets("StartSheet") 'Workbooks("HelpBook.xlsm").Worksheets("StartSheet").Range("k4:k33").Copy HelpBookPath.Range("k4:k33").Copy Workbooks("Testing Get File Info 09.xlsm").Worksheets("sheet1").Range("c4:c33").PasteSpecial Paste:=xlPasteAll Range("k1").Select 'Workbooks("Testing Get File Info 09.xlsm").Worksheets("StartSheet").Range("k4:k33").PasteSpecial Paste:=xlPasteAll HomeBookPath.Range("k4:k33").PasteSpecial Paste:=xlPasteAll HomeBookPath.Range("a1").Select ' HomeBookPath.Activate ' Worksheets("StartSheet").Activate ' Range("a1").Select if bill = "aa" Then msgbox "if" end If End sub
I hope this Helps.
in conclusion, if the ‘Fold Margin’ cannot be Edited, Added to, then What’s it for?PS, I have created my own Language for ‘CNC Gcode Language’ so I Love Notepad++
—
moderator added code markdown around text; please don’t forget to use the
</>
button to mark example text as “code” so that characters don’t get changed by the forum -
@Francis-Robinson said:
if the ‘Fold Margin’ cannot be Edited, Added to, then What’s it for?
Is this a serious question?
-
@Francis-Robinson said:
[big section of code, without marking it as code]
I had to use moderator power to edit your post to add the ``` lines around your example code, because the forum uses many programming characters for formatting, so it was unreadable.
Further, you posted the same post twice (so I deleted one of them), despite the fact that when you posted, the forum gave you a big box:
… That box explained that until you earn enough upvotes, every post has to go through a “post queue”… and sometimes, it might be a few hours until there is a moderator available to approve a post. If you don’t see your post right away, just be patient and wait for it to appear.in conclusion, if the ‘Fold Margin’ cannot be Edited, Added to, then What’s it for?
For built-in programming languages, the “Fold Margin” is for folding code using the definitions of folding that were baked into the syntax highlighter when the library was compiled. Not all languages use “keywords” for folding, and each language requires separate custom logic to be able to determine where and when to do the folding.
And saying “but it should also allow me to add keyword folding” isn’t overly helpful: they would have had to think of that when they were first implementing the folding; and every built-in language would have had to code that additional folding rule separately (because the library uses a different set of functions for each built-in language, because, once again, every language has its own rules).
No one has asked the Lexilla project to add custom folding to every language; or, possibly, if someone did request it, their team rejected it. (I haven’t looked through their entire history to know which is the case)
That said, they have now been informed that their original choice for code folding in Visual Basic is not sufficient. It is now up to them to choose whether to implement it, or whether to wait for some volunteer from the wild who has the skill and the interest to completely rewrite the folding for the Visual Basic lexer for their library.
And in the mean time, if you want to use code folding in Visual Basic, make sure that you use clean indentation, rather than randomly indenting/outdenting (that’s good coding practice, anyway, regardless of limitations of the tool you are using).
-
@Alan-Kilborn
Yes. -
@AlanRobbo-69 said in Fold Margin Style Box Tree:
@Alan-Kilborn
Yes.@AlanRobbo-69 is a different username than @Francis-Robinson – are you the same person? If so, please use one account for posting, so the conversation don’t get confused.
Alan’s incredulity is that that you seem to think that Fold Margin has no purpose, just because you cannot customize it for built-in languages. That’s an interpretation that he cannot fathom. I understand it’s annoying to you, because you found a bug, but if the Lexilla library had properly implemented the right folding rules for VB, you wouldn’t think it needed to be customizable in order to serve a purpose – so I think your “cause - effect” pair of “it’s not customizable - thus, it doesn’t serve a purpose” is fallacious. You had bad data, so you came to a bad conclusion; it happens. If you wanted to say at this point, “fold margin for Visual Basic does not serve my needs, because it is currently broken” that’s completely reasonable (but a very different statement than you made). And my response to such a hypothetical statement would be, “that’s too bad; hopefully ScintillaOrg will fix Lexilla, so that Notepad++ can be updated. too; until then, I guess you won’t be able to fold, unless you cleanly indent your code; sorry.”