예제 #1
0
        static void FormatCurrentLine()
        {
            int    currentLineNum = Npp.GetCaretLineNumber();
            string prevLineText   = Npp.GetLine(currentLineNum - 1).TrimEnd();

            if (prevLineText.EndsWith("{") || prevLineText.IsControlStatement())
            {
                Perform(InsertIndent);
            }
        }
        public static void FormatDocumentPrevLines()
        {
            int currentLineNum  = Npp.GetCaretLineNumber();
            int prevLineEnd     = Npp.GetLineStart(currentLineNum) - Environment.NewLine.Length;
            int topScrollOffset = currentLineNum - Npp.GetFirstVisibleLine();

            string code       = Npp.GetTextBetween(0, prevLineEnd);
            int    currentPos = Npp.GetCaretPosition();
            string newCode    = FormatCode(code, ref currentPos, Npp.GetCurrentFile());

            Npp.SetTextBetween(newCode, 0, prevLineEnd);

            //no need to set the caret as it is after the formatted text anyway

            Npp.SetFirstVisibleLine(Npp.GetLineNumber(currentPos) - topScrollOffset);
        }
예제 #3
0
        static void OnNewLine()
        {
            if (Config.Instance.FormatAsYouType)
            {
                int    currentLineNum = Npp.GetCaretLineNumber();
                string prevLineText   = Npp.GetLine(currentLineNum - 1).TrimEnd();

                if (prevLineText != "")
                {
                    SourceCodeFormatter.FormatDocumentPrevLines();
                }
            }

            //it conflicts with N++ auto-indent (at least from v6.9.2)
            //if (Config.Instance.SmartIndenting)
            //    FormatCurrentLine();
        }