diff options
Diffstat (limited to 'lexers/LexMatlab.cxx')
-rw-r--r-- | lexers/LexMatlab.cxx | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/lexers/LexMatlab.cxx b/lexers/LexMatlab.cxx index ca5e4d908..45f0b6926 100644 --- a/lexers/LexMatlab.cxx +++ b/lexers/LexMatlab.cxx @@ -18,6 +18,9 @@ ** ** Changes by John Donoghue 2016/11/15 ** - update matlab code folding + ** + ** Changes by John Donoghue 2017/01/18 + ** - update matlab block comment detection **/ // Copyright 1998-2001 by Neil Hodgson <neilh@scintilla.org> // The License.txt file describes the conditions under which this software may be distributed. @@ -73,6 +76,15 @@ static int CheckKeywordFoldPoint(char *str) { return 0; } +static bool IsSpaceToEOL(Sci_Position startPos, Accessor &styler) { + Sci_Position line = styler.GetLine(startPos); + Sci_Position eol_pos = styler.LineStart(line + 1) - 1; + for (Sci_Position i = startPos; i < eol_pos; i++) { + char ch = styler[i]; + if(!IsASpace(ch)) return false; + } + return true; +} static void ColouriseMatlabOctaveDoc( Sci_PositionU startPos, Sci_Position length, int initStyle, @@ -180,7 +192,7 @@ static void ColouriseMatlabOctaveDoc( } } else if (sc.state == SCE_MATLAB_COMMENT) { // end or start of a nested a block comment? - if( IsCommentChar(sc.ch) && sc.chNext == '}' && nonSpaceColumn == column) { + if( IsCommentChar(sc.ch) && sc.chNext == '}' && nonSpaceColumn == column && IsSpaceToEOL(sc.currentPos+2, styler)) { if(commentDepth > 0) commentDepth --; curLine = styler.GetLine(sc.currentPos); @@ -192,7 +204,7 @@ static void ColouriseMatlabOctaveDoc( transpose = false; } } - else if( IsCommentChar(sc.ch) && sc.chNext == '{' && nonSpaceColumn == column) + else if( IsCommentChar(sc.ch) && sc.chNext == '{' && nonSpaceColumn == column && IsSpaceToEOL(sc.currentPos+2, styler)) { commentDepth ++; @@ -214,8 +226,11 @@ static void ColouriseMatlabOctaveDoc( if (sc.state == SCE_MATLAB_DEFAULT) { if (IsCommentChar(sc.ch)) { // ncrement depth if we are a block comment - if(sc.chNext == '{' && nonSpaceColumn == column) - commentDepth ++; + if(sc.chNext == '{' && nonSpaceColumn == column) { + if(IsSpaceToEOL(sc.currentPos+2, styler)) { + commentDepth ++; + } + } curLine = styler.GetLine(sc.currentPos); styler.SetLineState(curLine, commentDepth); sc.SetState(SCE_MATLAB_COMMENT); @@ -284,13 +299,13 @@ static void FoldMatlabOctaveDoc(Sci_PositionU startPos, Sci_Position length, int style = styleNext; styleNext = styler.StyleAt(i + 1); bool atEOL = (ch == '\r' && chNext != '\n') || (ch == '\n'); - + // a line that starts with a comment if (style == SCE_MATLAB_COMMENT && IsComment(ch) && visibleChars == 0) { - // start/end of block comment - if (chNext == '{') + // start/end of block comment + if (chNext == '{' && IsSpaceToEOL(i+2, styler)) levelNext ++; - if (chNext == '}') + if (chNext == '}' && IsSpaceToEOL(i+2, styler)) levelNext --; } // keyword @@ -303,7 +318,7 @@ static void FoldMatlabOctaveDoc(Sci_PositionU startPos, Sci_Position length, int if (styleNext != SCE_MATLAB_KEYWORD) { word[wordlen] = '\0'; wordlen = 0; - + levelNext += CheckKeywordFoldPoint(word); } } |