Now I know the problem.
You are keeping HL classes to be not be changed when a new markup class introduced. aren't you?
Modularity = a module no need to be changed when another module introduced.
current situation = all foldable HL need to be changed to reflect of new markup born.
Now, let see what are the constraints:
* user should able to configure HL + Markup behaviors via IDE's editor options.
* HL should not changed too much (even shall not changed) when a new markup introduced.
* Ideally, Markup class is general purpose, not designed for specific programming language.
* FoldConfig is no longer for expand/collapse things only. It became more general purpose.
And what are NOT be constraints:
- FoldConfigs may/ may not attached to HL. it can be independent class, can be looked up using TypeInfo.
- configurations per markup should / should not multiply of available markup.
- known markups may / may not available at a time.
(But configurations for each markup can be created & destroyed anytime)
So, from above thought this is my idea:
+ Extract the markup config into a new class/record.
Purpose: modularity, keep HL in it's own business.
It should apply to configure MarkupWordGroup, and any newer markup.
This way, new introduced markup would not change any HL.
The final amount of configurable things would be: (HL count * eachHL.configCount) * know markup class.
Pascal.configcount := ord(cfbtIfthen{last}) - ord(cfbtBeginEnd{first})
known markup class := [MarkupWordGroup, MarkupNestedColoring, ..., MarkupNewerClassIntroducedLater]
HL count := [ Pascal, JS, XML, HTML, PHP, ...]
You can see, additional new Markup class will only need additional config, but no change will be needed for each HL.
Note:
1) I don't know whether FoldConfig will be completely detached from HL, because fmFold may still needed by other module (such gutter, TextBuffer, etc.).
2) when a "new" config created, it will not require the markup instance exist,
but we only need the count of them for displaying / playing with them.
It will be similar of registering new type of TGraphic, but that TGRaphic ancestor instance are not required to be exist, just only need to register the class.