I played with the fold strings and can nothing other say than you better remove
"While" and
"End While" from the Open respectively Close Fold Strings and contact IDM support by email.
I found out that with language marker
VB_LANG or
VBSCRIPT_LANG internally the following Open/Close Fold Strings are set:
"If" "For" "Select Case" "Else" "ElseIf" "Do While"
"End If" "Next" "Else" "ElseIf" "End Select" "Loop"
But according to your examples this is not enough. Better would be:
/Open Fold Strings = "Class" "Function" "Sub" "Structure" "#Region" "#If" "#Else" "Try" "Catch" "For" "With" "Select Case" "If" "ElseIf" "Else" "Do" "While"
/Close Fold Strings = "End Class" "End Function" "End Sub" "End Structure" "#End Region" "#End If" "#Else" "End Try" "End Catch" "Next" "End With" "End Select" "End If" "ElseIf" "Else" "Loop" "End While"
But with
"While" as open fold string
Do While and
Loop While are a problem. In other languages like in HTML it is possible that more than one open/close fold string can be on the same line, for example <div class="body"><div class="header">. Therefore the code folding engine interprets
Do While as start of 2 blocks for folding and
Loop While as close for 1 block and open for 1 other block with the result that everything below is interpreted wrong. Also normally the order of open/close fold strings defined in the wordfile (or internally) is not important and therefore it is not possible to define open/close fold strings which are parts of other, longer open/close fold strings.
That's the reason why every try to get your examples fold correct must fail. A solution would be that
VB_LANG is used and with this keyword the code folding engine uses additionally 2 rules:
- The code folding engine searches in a line for open/close fold string in the order as defined in the wordfile (or internally).
- Scanning a line for open/fold is stopped after first open or close fold string is found.
With these 2 special code folding rules enabled by language marker keyword
VB_LANG or
VBSCRIPT_LANG and perhaps also with
PUREBASIC_LANG the open/close fold strings as written above would work.
Alternatively second special rule would not be needed when first rule is implemented and following is defined in the wordfile:
/Open Fold Strings = "Class" "Function" "Sub" "Structure" "#Region" "#If" "#Else" "Try" "Catch" "For" "With" "Select Case" "If" "ElseIf" "Else" "Do While" "Do" "While"
/Close Fold Strings = "End Class" "End Function" "End Sub" "End Structure" "#End Region" "#End If" "#Else" "End Try" "End Catch" "Next" "End With" "End Select" "End If" "ElseIf" "Else" "Loop While" "Loop" "End While"
The order of the open/close fold strings is very important here because
"Do" is just a part of
"Do While" and
"Loop" and
"While" are parts of
"Loop While".
While playing with the code folding engine I get a better understanding how it probably works internally and now I understand why it must fail for case sections.
"Case" is start of a block and at the same time also the end of the block above, EXCEPT when block above starts with
"Select Case" - 1st special rule. Additionally
"Case Else" is the close fold string for the case block above - 2nd special rule. And the block starting with
"Select Case" or last block with just
"Case" ends with
"End Select" - 3rd special rule. And last
"End Select" is at the same time also the end of the block starting with
"Select Case" - 4th special rule. So to get case conditions correct folding completely these 4 special rules must be implemented for syntax highlighting of files using a wordfile with
VB_LANG or
VBSCRIPT_LANG.
The same problem for case conditions exists for C/C++. A
switch block starts with
{ and ends with
}. Inside this block there are the
case and
default keywords. The same 4 rules would be necessary for C/C++ to get the entire
switch block with its subblocks correct folded. Just the strings are different in comparison to BASIC languages.
Conclusion: Send an email with this text as enhancement request to IDM support. Add for the developers a sample file containing as much foldable blocks nested (using all open/fold strings) as possible with comments what should fold.
PS: I have sent an email to IDM about the problem that function list and highlighting of a file is updated automatically when the wordfile used is updated and saved in the same instance of UltraEdit and the highlighted file gets back the focus, but the code folding engine is not executed in this case. I found out that simply using
File - Revert to Saved of the not modified sample file works also for forcing the code folding engine to rescan the file with the updated open/fold strings. I have assigned key F4 to command
Revert to Saved, but non for the highlighting languages and therefore pressing F4 was the best method for me to force the code folding engine to rescan the current sample file with the updated open/close fold strings.