New Feature to help with defining custom rules added (ST3 ONLY).
One of the slightly annoying things about BH is that if you want to try out a custom rule, or modify an existing one, you need to copy the whole default set of rules. If you do this in your User folder, new updates to BH rules will not be picked up until you rebase your rules.
Well, I set out to fix that with some new changes I will outline below:
Letâs say you have a custom language you want to have on your machine. Now, you can simply add it to one of the two settings arrays: âuser_scope_bracketsâ and âuser_bracketsâ:
[pre=#232628] âuser_scope_bracketsâ: ],
âuser_bracketsâ:
{
ânameâ: âmylangâ,
âopenâ: â^\s*\b(if|subr|bytemap|enum|command|for|while|macro|do)\bâ,
âcloseâ: â\b(e(?:if|subr|bytemap|enum|command|for|while|macro)|until)\bâ,
âstyleâ: âdefaultâ,
âscope_excludeâ: âstringâ, âcommentâ],
âplugin_libraryâ: âUser.bh_modules.mylangkeywordsâ,
âlanguage_filterâ: âwhitelistâ,
âlanguage_listâ: âmylangâ],
âenabledâ: true
}
],[/pre]
Letâs say you want to modify an existing rule, maybe just tweak the language list, all you have to do is use the same name and the item you want to change. Only that attribute will be overridden:
[pre=#232628] âuser_bracketsâ:
// Angle
{
ânameâ: âangleâ,
âlanguage_listâ:
âHTMLâ, âHTML 5â, âXMLâ, âPHPâ, âHTML (Rails)â,
âHTML (Jinja Templates)â, âHTML (Twig)â, âHTML+CFMLâ,
âColdFusionâ, âColdFusionCFCâ, âlaravel-bladeâ,
âHandlebarsâ, âAngularJSâ,
âSomeNewLanguageâ // <â New language
]
}
],[/pre]
Letâs say I want to insert a new rule between two rules. I can turn on debug mode and call the BracketHighlighter: (Debug) Filter Rules by Key then select position to see the current rule order and their postion index:
[pre=#232628]
{"name": "curly", "position": 0},
{"name": "round", "position": 1},
{"name": "square", "position": 2},
{"name": "html", "position": 3},
{"name": "cfml", "position": 4},
{"name": "php_angle", "position": 5},
{"name": "angle", "position": 6},
{"name": "cssedit_groups", "position": 7},
{"name": "ruby_embedded_html", "position": 8},
{"name": "ruby", "position": 9},
{"name": "c_compile_switch", "position": 10},
{"name": "php_keywords", "position": 11},
{"name": "erlang", "position": 12},
{"name": "bash", "position": 13},
{"name": "fish", "position": 14},
{"name": "mylang", "position": 15}
],
{"name": "py_single_quote", "position": 0},
{"name": "py_double_quote", "position": 1},
{"name": "single_quote", "position": 2},
{"name": "double_quote", "position": 3},
{"name": "jsregex", "position": 4},
{"name": "perlregex", "position": 5},
{"name": "rubyregex", "position": 6},
{"name": "mditalic", "position": 7},
{"name": "mdbold", "position": 8}
]
][/pre]
Then you can specify the position you want to insert at:
[pre=#232628] âuser_scope_bracketsâ: ],
âuser_bracketsâ:
{
ânameâ: âmylangâ,
âpositionâ: 4, // <-- New position
âopenâ: â^\s*\b(if|subr|bytemap|enum|command|for|while|macro|do)\bâ,
âcloseâ: â\b(e(?:if|subr|bytemap|enum|command|for|while|macro)|until)\bâ,
âstyleâ: âdefaultâ,
âscope_excludeâ: âstringâ, âcommentâ],
âplugin_libraryâ: âUser.bh_modules.mylangkeywordsâ,
âlanguage_filterâ: âwhitelistâ,
âlanguage_listâ: âmylangâ],
âenabledâ: true
}
],[/pre]
And if you run the debug command again, you will see that the position has changed:
[pre=#232628] {ânameâ: âcurlyâ, âpositionâ: 0},
{ânameâ: âroundâ, âpositionâ: 1},
{ânameâ: âsquareâ, âpositionâ: 2},
{ânameâ: âhtmlâ, âpositionâ: 3},
{ânameâ: âtrexâ, âpositionâ: 4}, // <-- New position
{ânameâ: âcfmlâ, âpositionâ: 5},
{ânameâ: âphp_angleâ, âpositionâ: 6},[/pre]
This can be used to adjust the position of default rules from your user settings as well as shown by overrides above.
So, unless you are forking BH to pull request a change to the default rules, you can now modify the rules all in these two settings without copying or touching the default rules:
[pre=#232628] âuser_scope_bracketsâ: ],
âuser_bracketsâ: ],[/pre]
This will allow you to make changes, but still receive new updated rules.
**Debug mode is a setting in the settings file. Toggling debug mode via command palette only changes the settings in memory, so when you save the settings file, it reverts back to the original. I choose not to save it automatically to the settings file so as not to regenerate the settings file and erase all the comments in the settings file. If you want to put the plugin in a more âhardâ debug mode, set âdebugâ to âtrueâ manually in your settings file.