internal void TrimTrailingWhitespace(TextDocument doc)
 {
     foreach (var cursor in doc.FindMatches(_package.UsePOSIXRegEx ? @":b+\n" : @"[ \t]+\r?\n"))
     {
         cursor.Delete(_trailingWhitespaces.Match(cursor.GetLine()).Length);
     }
 }
        /// <summary>
        /// A series of tab widths from 2 to 8 are scored according to the leading spaces already present
        /// on the current document.
        /// </summary>
        /// <returns>A tally of all indent widths and their respective scores.</returns>
        private int[] TallyIndentationScores()
        {
            const string pattern           = @"^( )+(?=[^ \t])";
            var          leadingSpaces     = new Regex(pattern, RegexOptions.Compiled);
            var          indentWidthScores = new int[8];

            foreach (var spaces in _textDoc.FindMatches(pattern)
                     .Select(editPoint => editPoint.GetLine())
                     .Select(line => leadingSpaces.Match(line).Length))
            {
                for (var i = 2; i <= 8; i++)
                {
                    if (i > spaces)
                    {
                        break;
                    }
                    if (spaces % i == 0)
                    {
                        indentWidthScores[i - 1] += spaces;
                    }
                }
            }
            return(indentWidthScores);
        }