private void VBAutoIndentNeeded(object sender, AutoIndentEventArgs args)
{
//end of block
if (Regex.IsMatch(args.LineText, @"^\s*(End|EndIf|Next|Loop)\b", RegexOptions.IgnoreCase))
{
args.Shift = -args.TabLength;
args.ShiftNextLines = -args.TabLength;
return;
}
//start of declaration
if (Regex.IsMatch(args.LineText,
@"\b(Class|Property|Enum|Structure|Sub|Function|Namespace|Interface|Get)\b|(Set\s*\()",
RegexOptions.IgnoreCase))
{
args.ShiftNextLines = args.TabLength;
return;
}
// then ...
if (Regex.IsMatch(args.LineText, @"\b(Then)\s*\S+", RegexOptions.IgnoreCase))
return;
//start of operator block
if (Regex.IsMatch(args.LineText, @"^\s*(If|While|For|Do|Try|With|Using|Select)\b", RegexOptions.IgnoreCase))
{
args.ShiftNextLines = args.TabLength;
return;
}
//Statements else, elseif, case etc
if (Regex.IsMatch(args.LineText, @"^\s*(Else|ElseIf|Case|Catch|Finally)\b", RegexOptions.IgnoreCase))
{
args.Shift = -args.TabLength;
return;
}
//Char _
if (args.PrevLineText.TrimEnd().EndsWith("_"))
{
args.Shift = args.TabLength;
}
}