From a0d9227977a2bf21249016616dce50842a997d61 Mon Sep 17 00:00:00 2001 From: Don Ho Date: Thu, 13 Nov 2014 02:07:46 +0000 Subject: [PATCH] [NEW_FEATURE] Smart Indent (in progress). git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@1289 f5eea248-9336-0410-98b8-ebc06183d4e3 --- PowerEditor/src/Notepad_plus.cpp | 67 ++++++++++---------------------- 1 file changed, 20 insertions(+), 47 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index fe7b571aa..7179a941e 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -2276,55 +2276,28 @@ bool Notepad_plus::isConditionExprLine(int lineNumber) int startPos = _pEditView->execute(SCI_POSITIONFROMLINE, lineNumber); int endPos = _pEditView->execute(SCI_GETLINEENDPOSITION, lineNumber); - _pEditView->execute(SCI_SETSEARCHFLAGS, SCFIND_REGEXP | SCFIND_POSIX); - _pEditView->execute(SCI_SETTARGETSTART, startPos); - _pEditView->execute(SCI_SETTARGETEND, endPos); - - /* - LangType type = _pEditView->getCurrentBuffer()->getLangType(); - - if (type == L_HTML || type == L_PHP || type == L_ASP || type == L_JSP) - mask = INDIC2_MASK; - else if (type == L_PS) - mask = 16; - */ - const char ifExpr[] = ""; - const char elseExpr[] = ""; - const char forLoopExpr[] = ""; - const char whileLoopExpr[] = ""; - - int posFound = _pEditView->execute(SCI_SEARCHINTARGET, strlen(ifExpr), (LPARAM)ifExpr); - if (posFound != -1 && posFound != -2) - { - //int start = int(_pEditView->execute(SCI_GETTARGETSTART)); - int end = int(_pEditView->execute(SCI_GETTARGETEND)); - if (end == endPos) - return true; - } - - posFound = _pEditView->execute(SCI_SEARCHINTARGET, strlen(elseExpr), (LPARAM)elseExpr); - if (posFound != -1 && posFound != -2) - { - int end = int(_pEditView->execute(SCI_GETTARGETEND)); - if (end == endPos) - return true; - } - - posFound = _pEditView->execute(SCI_SEARCHINTARGET, strlen(forLoopExpr), (LPARAM)forLoopExpr); - if (posFound != -1 && posFound != -2) - { - int end = int(_pEditView->execute(SCI_GETTARGETEND)); - if (end == endPos) - return true; + _pEditView->execute(SCI_SETSEARCHFLAGS, SCFIND_REGEXP | SCFIND_POSIX); + _pEditView->execute(SCI_SETTARGETSTART, startPos); + _pEditView->execute(SCI_SETTARGETEND, endPos); + + /* + LangType type = _pEditView->getCurrentBuffer()->getLangType(); + + if (type == L_HTML || type == L_PHP || type == L_ASP || type == L_JSP) + mask = INDIC2_MASK; + else if (type == L_PS) + mask = 16; + */ + const char ifElseForWhileExpr[] = "((else[ \t]+)?if|for|while)[ \t]*[(].*[)][ \t]*|else[ \t]*"; + + int posFound = _pEditView->execute(SCI_SEARCHINTARGET, strlen(ifElseForWhileExpr), (LPARAM)ifElseForWhileExpr); + if (posFound != -1 && posFound != -2) + { + int end = int(_pEditView->execute(SCI_GETTARGETEND)); + if (end == endPos) + return true; } - posFound = _pEditView->execute(SCI_SEARCHINTARGET, strlen(whileLoopExpr), (LPARAM)whileLoopExpr); - if (posFound != -1 && posFound != -2) - { - int end = int(_pEditView->execute(SCI_GETTARGETEND)); - if (end == endPos) - return true; - } return false; }