/// <summary>
        /// This function sets the indentlevel in a range of lines.
        /// </summary>
        public override void IndentLines(TextArea textArea, int begin, int end)
        {
            if (textArea.Document.TextEditorProperties.IndentStyle != IndentStyle.Smart)
            {
                base.IndentLines(textArea, begin, end);
                return;
            }
            int cursorPos       = textArea.Caret.Position.Y;
            int oldIndentLength = 0;

            if (cursorPos >= begin && cursorPos <= end)
            {
                oldIndentLength = GetIndentation(textArea, cursorPos).Length;
            }

            IndentationSettings set = new IndentationSettings();

            set.IndentString = Tab.GetIndentationString(textArea.Document);
            IndentationReformatter r   = new IndentationReformatter();
            DocumentAccessor       acc = new DocumentAccessor(textArea.Document, begin, end);

            r.Reformat(acc, set);

            if (cursorPos >= begin && cursorPos <= end)
            {
                int newIndentLength = GetIndentation(textArea, cursorPos).Length;
                if (oldIndentLength != newIndentLength)
                {
                    // fix cursor position if indentation was changed
                    int newX = textArea.Caret.Position.X - oldIndentLength + newIndentLength;
                    textArea.Caret.Position = new TextLocation(Math.Max(newX, 0), cursorPos);
                }
            }
        }
        /// <summary>
        /// Define PHP specific smart indenting for a line :)
        /// </summary>
        protected override int SmartIndentLine(TextArea textArea, int lineNr)
        {
            if (lineNr <= 0)
            {
                return(AutoIndentLine(textArea, lineNr));
            }

            string oldText = textArea.Document.GetText(textArea.Document.GetLineSegment(lineNr));

            DocumentAccessor acc = new DocumentAccessor(textArea.Document, lineNr, lineNr);

            IndentationSettings set = new IndentationSettings();

            set.IndentString    = Tab.GetIndentationString(textArea.Document);
            set.LeaveEmptyLines = false;

            IndentationReformatter r = new IndentationReformatter();

            r.Reformat(acc, set);

            string t = acc.Text;

            if (t.Length == 0)
            {
                // use AutoIndentation for new lines in comments / verbatim strings.
                return(AutoIndentLine(textArea, lineNr));
            }
            else
            {
                int newIndentLength = t.Length - t.TrimStart().Length;
                int oldIndentLength = oldText.Length - oldText.TrimStart().Length;
                if (oldIndentLength != newIndentLength && lineNr == textArea.Caret.Position.Y)
                {
                    // fix cursor position if indentation was changed
                    int newX = textArea.Caret.Position.X - oldIndentLength + newIndentLength;
                    textArea.Caret.Position = new TextLocation(Math.Max(newX, 0), lineNr);
                }
                return(newIndentLength);
            }
        }