예제 #1
0
 public override int FormatSpan(IVsTextLines buffer, TextSpan[] ts)
 {
     foreach (TextSpan span in ts)
     {
         // Set the indentation of each line in the snippet to match the first
         // line.
         LanguagePreferences prefs = Source.LanguageService.Preferences;
         char indentChar           = prefs.InsertTabs ? '\t' : ' ';
         int  level = CMakeParsing.GetIndentationLevel(
             Source.GetLine(span.iStartLine), indentChar);
         for (int i = span.iStartLine + 1; i <= span.iEndLine; ++i)
         {
             Source.SetText(i, 0, i, 0, new string(indentChar, level));
         }
     }
     return(VSConstants.S_OK);
 }
예제 #2
0
        public override bool HandleSmartIndent()
        {
            // If the line contains an outer opening parenthesis, intent by one level.
            // If the line contains an outer closing parenthesis, unindent to match the
            // level of the corresponding opening parenthesis.  In all other cases,
            // match the indentation level of the previous line.
            LanguagePreferences prefs = Source.LanguageService.Preferences;
            char indentChar           = prefs.InsertTabs ? '\t' : ' ';
            int  line;
            int  col;

            TextView.GetCaretPos(out line, out col);
            List <string> lines    = Source.GetLines().ToList();
            int           prevLine = CMakeParsing.GetLastNonEmptyLine(lines, line - 1);
            int           level    = CMakeParsing.GetIndentationLevel(lines[prevLine], indentChar);
            int           lineToMatch;

            if (CMakeParsing.ShouldIndent(lines, prevLine))
            {
                level += prefs.InsertTabs ? 1 : prefs.IndentSize;
            }
            else if (CMakeParsing.ShouldUnindent(lines, prevLine, out lineToMatch))
            {
                if (lineToMatch < 0)
                {
                    level = 0;
                }
                else
                {
                    level = CMakeParsing.GetIndentationLevel(lines[lineToMatch], indentChar);
                }
            }
            int oldIndentLen = 0;

            while (oldIndentLen < lines[line].Length &&
                   lines[line][oldIndentLen] == indentChar)
            {
                oldIndentLen++;
            }
            Source.SetText(line, 0, line, oldIndentLen, new string(indentChar, level));
            TextView.PositionCaretForEditing(line, level);
            return(true);
        }