37 m_editor->InsertText(nPosition, sText);
38 return sText.length();
56 if (nLastLine <= 0 || nLastLine >
m_editor->GetLineCount())
57 nLastLine =
m_editor->GetLineCount();
63 int nIndentCount = nFirstLine > 0 ?
m_editor->GetLineIndentation(nFirstLine) / 4 : 0;
64 int nCurrentIndent = 0;
66 int singleLineIndent = 0;
67 int nLastSingleIndent = 0;
71 for (
int i = nFirstLine; i < nLastLine; i++)
73 nLastSingleIndent = singleLineIndent;
75 int pos =
m_editor->PositionFromLine(i);
85 if (pos >
m_editor->GetLineEndPosition(i) - 1)
92 nLastSingleIndent = 0;
95 if (!nCurrentIndent && singleLineIndent < 0)
98 m_editor->SetLineIndentation(i, 4 * (nIndentCount - 1));
100 else if (!nCurrentIndent)
101 m_editor->SetLineIndentation(i, 4 * (nIndentCount + nLastSingleIndent));
102 else if (nCurrentIndent < 0)
104 nIndentCount += nCurrentIndent;
105 m_editor->SetLineIndentation(i, 4 * nIndentCount);
109 m_editor->SetLineIndentation(i, 4 * nIndentCount);
110 nIndentCount += nCurrentIndent;
114 &&
m_editor->GetCurrentPos() - pos < nIndentCount
116 &&
m_editor->GetTextRange(pos,
m_editor->GetLineEndPosition(i)).find_first_not_of(
" \t\n\r") == string::npos)
117 m_editor->GotoPos(pos + nIndentCount);
162 int nIndentCount = 0;
164 int nLineStart =
m_editor->PositionFromLine(nLine);
165 int nLineEnd =
m_editor->GetLineEndPosition(nLine);
168 for (
int i = nLineStart; i < nLineEnd; i++)
171 if (
m_editor->GetStyleAt(i) == wxSTC_NSCR_COMMAND ||
m_editor->GetStyleAt(i) == wxSTC_NSCR_PROCEDURE_COMMANDS)
173 wxString word =
m_editor->GetTextRange(i,
m_editor->WordEndPosition(i + 1,
true));
180 singleLineIndent = -1;
190 if (
m_editor->GetCharAt(i) ==
'<' &&
m_editor->FindText(i, nLineEnd,
">") != -1)
192 word =
m_editor->GetTextRange(i,
m_editor->WordEndPosition(i + 2,
true) + 1);
201 i += word.length() - 1;
205 if (
m_editor->GetStyleAt(i) == wxSTC_NSCR_OPERATORS &&
m_editor->GetTextRange(i, i + 2) ==
"\\\\")
206 singleLineIndent = 1;
224 int nIndentCount = 0;
226 int nLineStart =
m_editor->PositionFromLine(nLine);
227 int nLineEnd =
m_editor->GetLineEndPosition(nLine);
229 for (
int i = nLineStart; i < nLineEnd; i++)
231 if (
m_editor->GetStyleAt(i) == wxSTC_MATLAB_KEYWORD)
233 wxString word =
m_editor->GetTextRange(i,
m_editor->WordEndPosition(i + 1,
true));
240 singleLineIndent = -1;
245 if (
m_editor->GetStyleAt(i) == wxSTC_MATLAB_OPERATOR &&
m_editor->GetTextRange(i, i + 3) ==
"...")
246 singleLineIndent = 1;
264 int nIndentCount = 0;
266 int nLineStart =
m_editor->PositionFromLine(nLine);
267 int nLineEnd =
m_editor->GetLineEndPosition(nLine);
269 for (
int i = nLineStart; i < nLineEnd; i++)
271 if (
m_editor->GetStyleAt(i) == wxSTC_C_OPERATOR)
280 if (
m_editor->GetStyleAt(i) == wxSTC_C_WORD)
282 wxString word =
m_editor->GetTextRange(i,
m_editor->WordEndPosition(i + 1,
true));
284 if (word ==
"private" || word ==
"protected" || word ==
"public" || word ==
"case" || word ==
"default")
285 singleLineIndent = -1;
287 if (word ==
"if" || word ==
"else" || word ==
"for" || word ==
"while")
288 singleLineIndent = 1;
316 if (nLastLine <= 0 || nLastLine >
m_editor->GetLineCount())
317 nLastLine =
m_editor->GetLineCount();
347 int nFirstPosition =
m_editor->PositionFromLine(nFirstLine);
348 int nLastPosition =
m_editor->GetLineEndPosition(nLastLine);
351 for (
int i = nFirstPosition; i < nLastPosition; i++)
362 if (
m_editor->GetStyleAt(i) == wxSTC_NSCR_OPERATOR_KEYWORDS
363 || (
m_editor->GetStyleAt(i) == wxSTC_NSCR_OPERATORS &&
m_editor->GetTextRange(i, i + 1) ==
"<>"))
365 for (; i < nLastPosition; i++)
367 if ((
m_editor->GetStyleAt(i) != wxSTC_NSCR_STRING && (
m_editor->GetCharAt(i) ==
' '
375 if (
m_editor->GetStyleAt(i) == wxSTC_NSCR_OPERATORS)
377 int currentChar =
m_editor->GetCharAt(i);
378 int prevChar =
m_editor->GetCharAt(i - 1);
379 int nextChar =
m_editor->GetCharAt(i + 1);
380 static std::string sParens =
"(){}[]";
382 if (currentChar ==
'(' &&
m_editor->GetStyleAt(i - 1) == wxSTC_NSCR_COMMAND)
384 else if (currentChar ==
'('
385 && (
m_editor->GetStyleAt(i - 1) == wxSTC_NSCR_FUNCTION
386 ||
m_editor->GetStyleAt(i - 1) == wxSTC_NSCR_CUSTOM_FUNCTION
387 ||
m_editor->GetStyleAt(i - 1) == wxSTC_NSCR_PROCEDURES
388 ||
m_editor->GetStyleAt(i - 1) == wxSTC_NSCR_METHOD
389 ||
m_editor->GetStyleAt(i - 1) == wxSTC_NSCR_PREDEFS))
394 else if (sParens.find(currentChar) != std::string::npos)
396 else if (currentChar ==
',' && nextChar !=
' ')
398 else if (currentChar ==
'?' && nextChar != currentChar && prevChar != currentChar)
406 else if (currentChar ==
'<' || currentChar ==
'>' || currentChar ==
'!' || currentChar ==
'=')
408 static std::string sLeadingChars =
" (=+-!*/^<>:|";
410 if (currentChar ==
'='
411 && (
m_editor->GetStyleAt(i - 1) == wxSTC_NSCR_OPTION
412 ||
m_editor->GetStyleAt(i - 1) == wxSTC_NSCR_OPTION
413 ||
m_editor->GetStyleAt(i - 1) == wxSTC_NSCR_COMMAND))
419 && currentChar !=
'!'
420 && !(currentChar ==
'>' && prevChar ==
'<')
421 &&
m_editor->GetStyleAt(i - 1) != wxSTC_NSCR_OPTION
422 &&
m_editor->GetStyleAt(i + 1) != wxSTC_NSCR_OPTION)
425 if (sLeadingChars.find(prevChar) == std::string::npos && !(currentChar ==
'<' && nextChar ==
'>'))
429 nLastPosition +=
formatOperators(i, prevChar, currentChar, nextChar,
true);
432 if (
m_editor->GetStyleAt(i) == wxSTC_NSCR_COMMAND)
436 while (
m_editor->GetStyleAt(i + 1) == wxSTC_NSCR_COMMAND)
439 wxString command =
m_editor->GetTextRange(nPos1, i + 1);
440 int nCurrentLineStart =
m_editor->PositionFromLine(
m_editor->LineFromPosition(nPos1));
441 int nCurrentLineEnd =
m_editor->GetLineEndPosition(
m_editor->LineFromPosition(nPos1));
443 if (command ==
"global" || command ==
"load" || command ==
"append")
448 else if (command ==
"set")
450 for (; i <= nCurrentLineEnd; i++)
452 if (
m_editor->GetStyleAt(i) == wxSTC_NSCR_OPERATORS &&
m_editor->GetCharAt(i) ==
'[')
454 int bracepos =
m_editor->BraceMatch(i);
458 for (; i < bracepos; i++)
470 || command ==
"elseif"
472 || command ==
"switch"
473 || command ==
"while")
476 parens =
m_editor->FindText(i, nCurrentLineEnd,
"(");
480 parens =
m_editor->BraceMatch(parens);
484 int nextVisibleCharAfterParens =
m_editor->GetTextRange(parens + 1, nCurrentLineEnd).find_first_not_of(
" \r\n\t");
486 if (nextVisibleCharAfterParens != wxNOT_FOUND
493 else if (command ==
"else" || command ==
"try")
495 int nextVisibleCharAfterCommand =
m_editor->GetTextRange(i + 1, nCurrentLineEnd).find_first_not_of(
" \r\n\t");
497 if (nextVisibleCharAfterCommand != wxNOT_FOUND
502 else if (command ==
"case" || command ==
"default" || command ==
"catch")
504 int nColon =
m_editor->FindText(i, nCurrentLineEnd,
":");
505 int nextVisibleCharAfterColon =
m_editor->GetTextRange(nColon + 1, nCurrentLineEnd).find_first_not_of(
" \r\n\t");
507 if (nextVisibleCharAfterColon != wxNOT_FOUND
516 if (
m_editor->GetTextRange(nCurrentLineStart, nPos1).find_first_not_of(
" \t") != std::string::npos)
525 if (nIndentationLevel <= 0)
527 int nLine =
m_editor->LineFromPosition(i);
528 int position =
m_editor->PositionFromLine(nLine - 1);
530 while (
m_editor->GetCharAt(position) ==
' ' ||
m_editor->GetCharAt(position) ==
'\t')
534 &&
m_editor->GetLine(nLine - 1).find_first_not_of(
" \t\r\n") != std::string::npos
551 if (nIndentationLevel <= 0)
553 int nLine =
m_editor->LineFromPosition(i);
555 if (nLine < m_editor->GetLineCount() - 1
556 &&
m_editor->GetLine(nLine + 1).find_first_not_of(
" \t\r\n") != std::string::npos)
562 if (
m_editor->GetStyleAt(i) == wxSTC_NSCR_STRING)
585 int nFirstPosition =
m_editor->PositionFromLine(nFirstLine);
586 int nLastPosition =
m_editor->GetLineEndPosition(nLastLine);
587 int nIndentationLevel = -1;
589 for (
int i = nFirstPosition; i < nLastPosition; i++)
591 if (
m_editor->GetStyleAt(i) == wxSTC_MATLAB_COMMENT)
598 if (
m_editor->GetStyleAt(i) == wxSTC_MATLAB_OPERATOR)
600 int currentChar =
m_editor->GetCharAt(i);
601 int prevChar =
m_editor->GetCharAt(i - 1);
602 int nextChar =
m_editor->GetCharAt(i + 1);
603 static std::string sParens =
"(){}[]";
605 if (currentChar ==
'('
606 && (
m_editor->GetStyleAt(i - 1) == wxSTC_MATLAB_IDENTIFIER
607 ||
m_editor->GetStyleAt(i - 1) == wxSTC_MATLAB_KEYWORD))
612 else if (sParens.find(currentChar) != string::npos)
614 else if (currentChar ==
',' && nextChar !=
' ')
616 else if (currentChar ==
'?' && nextChar != currentChar && prevChar != currentChar)
624 else if (currentChar ==
'<' || currentChar ==
'>' || currentChar ==
'~' || currentChar ==
'=')
626 static std::string sLeadingChars =
" (=+-*/^<>:~";
628 if (nextChar !=
' ' && nextChar !=
'=' && nextChar !=
'>' && currentChar !=
'~' && !(currentChar ==
'>' && prevChar ==
'<'))
631 if (sLeadingChars.find(prevChar) == string::npos && !(currentChar ==
'<' && nextChar ==
'>'))
635 nLastPosition +=
formatOperators(i, prevChar, currentChar, nextChar,
false);
638 if (
m_editor->GetStyleAt(i) == wxSTC_MATLAB_KEYWORD)
642 while (
m_editor->GetStyleAt(i + 1) == wxSTC_MATLAB_KEYWORD)
645 wxString command =
m_editor->GetTextRange(nPos1, i + 1);
646 int nCurrentLineStart =
m_editor->PositionFromLine(
m_editor->LineFromPosition(nPos1));
647 int nCurrentLineEnd =
m_editor->GetLineEndPosition(
m_editor->LineFromPosition(nPos1));
650 || command ==
"elseif"
651 || command ==
"switch"
654 || command ==
"while")
656 if (
m_editor->GetCharAt(i + 1) !=
' ')
661 while (
m_editor->GetCharAt(parens) ==
' ')
664 if (parens !=
'(' && parens !=
'[' && parens !=
'{')
669 parens =
m_editor->BraceMatch(parens);
673 if (
m_editor->GetTextRange(parens + 1, nCurrentLineEnd).find_first_not_of(
" \r\n\t") != string::npos)
679 parens =
m_editor->FindText(i, nCurrentLineEnd,
";");
683 if (
m_editor->GetTextRange(parens + 1, nCurrentLineEnd).find_first_not_of(
" \r\n\t") != string::npos)
688 else if (command ==
"else")
690 if (
m_editor->GetTextRange(i + 1, nCurrentLineEnd).find_first_not_of(
" \r\n\t") != string::npos)
697 || command ==
"elseif"
698 || command ==
"switch"
701 || command ==
"otherwise"
703 || command ==
"catch"
704 || command ==
"until"
705 || command ==
"while"
708 if (
m_editor->GetTextRange(nCurrentLineStart, nPos1).find_first_not_of(
" \t") != string::npos)
717 || command ==
"while"
720 || command ==
"function"
721 || command ==
"switch"
722 || command ==
"case")
724 if (nIndentationLevel <= 0)
726 int nLine =
m_editor->LineFromPosition(i);
727 int position =
m_editor->PositionFromLine(nLine - 1);
729 while (
m_editor->GetCharAt(position) ==
' ' ||
m_editor->GetCharAt(position) ==
'\t')
733 &&
m_editor->GetLine(nLine - 1).find_first_not_of(
" \t\r\n") != string::npos
734 &&
m_editor->GetStyleAt(
m_editor->PositionFromLine(nLine - 1)) != wxSTC_MATLAB_COMMENT
735 &&
m_editor->GetStyleAt(position) != wxSTC_MATLAB_COMMENT)
745 if (command ==
"end")
749 if (nIndentationLevel <= 0)
751 int nLine =
m_editor->LineFromPosition(i);
753 if (nLine < m_editor->GetLineCount() - 1
754 &&
m_editor->GetLine(nLine + 1).find_first_not_of(
" \t\r\n") != string::npos)
760 if (
m_editor->GetStyleAt(i) == wxSTC_MATLAB_STRING)
783 int nFirstPosition =
m_editor->PositionFromLine(nFirstLine);
784 int nLastPosition =
m_editor->GetLineEndPosition(nLastLine);
785 int nIndentationLevel = -1;
787 for (
int i = nFirstPosition; i < nLastPosition; i++)
797 if (
m_editor->GetStyleAt(i) == wxSTC_C_OPERATOR)
799 int currentChar =
m_editor->GetCharAt(i);
800 int prevChar =
m_editor->GetCharAt(i - 1);
801 int nextChar =
m_editor->GetCharAt(i + 1);
802 int nCurrentLineStart =
m_editor->PositionFromLine(
m_editor->LineFromPosition(i));
803 int nCurrentLineEnd =
m_editor->GetLineEndPosition(
m_editor->LineFromPosition(i));
804 static std::string sParens =
"()[]";
806 if (currentChar ==
'-' && nextChar ==
'>')
812 if (currentChar ==
'(' &&
m_editor->GetStyleAt(i - 1) == wxSTC_C_WORD)
814 else if (currentChar ==
'('
815 && (
m_editor->GetStyleAt(i - 1) == wxSTC_C_WORD2))
820 else if (sParens.find(currentChar) != string::npos)
822 else if (currentChar ==
'{' || currentChar ==
'}')
824 if (currentChar ==
'{')
827 if (currentChar ==
'}')
830 if (
m_editor->GetTextRange(i + 1, nCurrentLineEnd).find_first_not_of(
" \t\r\n") != string::npos)
836 if (
m_editor->GetTextRange(nCurrentLineStart, i).find_first_not_of(
" \t") != string::npos)
842 else if (currentChar ==
',' && nextChar !=
' ')
844 else if (currentChar ==
'?' && nextChar != currentChar && prevChar != currentChar)
852 else if (currentChar ==
'<' || currentChar ==
'>' || currentChar ==
'!' || currentChar ==
'=')
854 static std::string sLeadingChars =
" (=+-!*/^<>:";
856 if (currentChar ==
'<'
857 && (
m_editor->GetStyleAt(i - 1) == wxSTC_C_WORD ||
m_editor->GetStyleAt(i - 1) == wxSTC_C_WORD))
860 if (currentChar ==
'>'
861 && (
m_editor->GetStyleAt(i - 1) == wxSTC_C_WORD ||
m_editor->GetStyleAt(i + 1) == wxSTC_C_WORD))
867 && currentChar !=
'!'
868 && !(currentChar ==
'>' && prevChar ==
'<'))
871 if (sLeadingChars.find(prevChar) == string::npos && !(currentChar ==
'<' && nextChar ==
'>'))
875 nLastPosition +=
formatOperators(i, prevChar, currentChar, nextChar,
false);
878 if (
m_editor->GetStyleAt(i) == wxSTC_C_WORD)
882 while (
m_editor->GetStyleAt(i + 1) == wxSTC_C_WORD)
885 wxString command =
m_editor->GetTextRange(nPos1, i + 1);
886 int nCurrentLineStart =
m_editor->PositionFromLine(
m_editor->LineFromPosition(nPos1));
887 int nCurrentLineEnd =
m_editor->GetLineEndPosition(
m_editor->LineFromPosition(nPos1));
890 || command ==
"switch"
892 || command ==
"while")
895 parens =
m_editor->FindText(i, nCurrentLineEnd,
"(");
899 parens =
m_editor->BraceMatch(parens);
903 int nextVisibleCharAfterParens =
m_editor->GetTextRange(parens + 1, nCurrentLineEnd).find_first_not_of(
" \r\n\t;");
905 if (nextVisibleCharAfterParens != wxNOT_FOUND
912 else if (command ==
"else")
914 int nextVisibleCharAfterCommand =
m_editor->GetTextRange(i + 1, nCurrentLineEnd).find_first_not_of(
" \r\n\t");
916 if (nextVisibleCharAfterCommand != wxNOT_FOUND
925 || command ==
"while"
929 if (command ==
"while" &&
m_editor->GetTextRange(i + 1, nCurrentLineEnd).find(
';') != string::npos)
932 if (command ==
"if" &&
m_editor->GetTextRange(nCurrentLineStart, i).find(
"else") != string::npos)
935 if (nIndentationLevel <= 0)
937 int nLine =
m_editor->LineFromPosition(i);
938 int position =
m_editor->PositionFromLine(nLine - 1);
940 while (
m_editor->GetCharAt(position) ==
' ' ||
m_editor->GetCharAt(position) ==
'\t')
944 &&
m_editor->GetLine(nLine - 1).find_first_not_of(
" \t\r\n") != string::npos
956 if (
m_editor->GetStyleAt(i) == wxSTC_C_STRING)
975 int nParens =
m_editor->BraceMatch(pos);
980 for (; pos < nParens; pos++)
982 if (
m_editor->GetStyleAt(pos) == operatorStyleNum)
984 char currentChar =
m_editor->GetCharAt(pos);
985 char nextChar =
m_editor->GetCharAt(pos + 1);
986 char prevChar =
m_editor->GetCharAt(pos - 1);
988 if (currentChar ==
',' && nextChar !=
' ')
994 if (currentChar ==
'=' && nextChar !=
' ' &&
m_editor->GetStyleAt(pos + 1) != operatorStyleNum)
1000 if (currentChar ==
'=' && prevChar !=
' ' &&
m_editor->GetStyleAt(pos - 1) != operatorStyleNum)
1028 if (currentChar ==
'+' || currentChar ==
'-')
1031 && nextChar != currentChar
1037 &&
m_editor->GetCharAt(pos - 2) !=
','
1038 &&
m_editor->GetCharAt(pos - 2) !=
'='
1039 && (!isNSCR || (
m_editor->GetStyleAt(pos + 1) != wxSTC_NSCR_COMMAND
1040 &&
m_editor->GetStyleAt(pos + 1) != wxSTC_NSCR_OPTION
1041 &&
m_editor->GetStyleAt(pos - 1) != wxSTC_NSCR_COMMAND
1042 &&
m_editor->GetStyleAt(pos - 1) != wxSTC_NSCR_OPTION
1043 && nextChar !=
'>')))
1047 && prevChar != currentChar
1048 && nextChar != currentChar
1054 else if (currentChar ==
'&' || currentChar ==
'|')
1056 if (nextChar !=
' ' && nextChar != currentChar && (!isNSCR || nextChar !=
'>'))
1059 if (prevChar !=
' ' && prevChar != currentChar)
1062 else if ((currentChar ==
'*' || currentChar ==
'/' || currentChar ==
'^')
1065 && nextChar != currentChar
1066 && prevChar != currentChar)
1084 int style =
m_editor->GetStyleAt(pos);
1086 char prevChar =
m_editor->GetCharAt(pos - 1);
1087 char nextChar =
m_editor->GetCharAt(pos + 1);
1089 if (
m_editor->GetStyleAt(pos + 1) != style
1090 &&
m_editor->GetLineEndPosition(
m_editor->LineFromPosition(pos)) != pos + 1
1099 if (
m_editor->GetStyleAt(pos - 1) != style
1105 && (!isNSCR || !(prevChar ==
'=' &&
m_editor->GetStyleAt(pos - 2) == wxSTC_NSCR_OPTION)))
bool isStyleType(StyleType _type, int nPos)
Determine the syntax style type at the selected position.
int getBlockID(const wxString &word)
This function returns the block ID.
int isBlockStart(const wxString &sWord, bool allowIntermediate=false)
This function returns true, if a passed word corresponds to a control flow statement block start.
int isBlockMiddle(const wxString &sWord)
This function returns, whether a word matches to a block middle statement (e.g. elseif).
int isBlockEnd(const wxString &sWord)
This function returns true, if a passed word corresponds to a control flow statement block end.
FileFilterType getFileType()