diff options
| author | nyamatongwe <unknown> | 2005-06-10 02:32:28 +0000 | 
|---|---|---|
| committer | nyamatongwe <unknown> | 2005-06-10 02:32:28 +0000 | 
| commit | dd5e4173115169a809727d0b1a1a1ffd51b0a101 (patch) | |
| tree | 490eb274860a49d0285219178eb3f7d6667f0afc /src/LexBash.cxx | |
| parent | 56abafdc67761908f128c150f460510b86bec161 (diff) | |
| download | scintilla-mirror-dd5e4173115169a809727d0b1a1a1ffd51b0a101.tar.gz | |
Patch from Kein-Hong Man improves folding.
Diffstat (limited to 'src/LexBash.cxx')
| -rw-r--r-- | src/LexBash.cxx | 41 | 
1 files changed, 27 insertions, 14 deletions
| diff --git a/src/LexBash.cxx b/src/LexBash.cxx index 809a396da..64c9bad2a 100644 --- a/src/LexBash.cxx +++ b/src/LexBash.cxx @@ -2,7 +2,7 @@  /** @file LexBash.cxx   ** Lexer for Bash.   **/ -// Copyright 2004 by Neil Hodgson <neilh@scintilla.org> +// Copyright 2004-2005 by Neil Hodgson <neilh@scintilla.org>  // Adapted from LexPerl by Kein-Hong Man <mkh@pl.jaring.my> 2004  // The License.txt file describes the conditions under which this software may be distributed. @@ -144,9 +144,9 @@ static void ColouriseBashDoc(unsigned int startPos, int length, int initStyle,  		char *Delimiter;	// the Delimiter, 256: sizeof PL_tokenbuf  		HereDocCls() {  			State = 0; -			Quote = 0; -			Quoted = false; -			Indent = 0; +            Quote = 0; +            Quoted = false; +            Indent = 0;  			DelimiterLength = 0;  			Delimiter = new char[HERE_DELIM_MAX];  			Delimiter[0] = '\0'; @@ -585,6 +585,19 @@ static void ColouriseBashDoc(unsigned int startPos, int length, int initStyle,  	styler.ColourTo(lengthDoc - 1, state);  } +static bool IsCommentLine(int line, Accessor &styler) { +	int pos = styler.LineStart(line); +	int eol_pos = styler.LineStart(line + 1) - 1; +	for (int i = pos; i < eol_pos; i++) { +		char ch = styler[i]; +		if (ch == '#') +			return true; +		else if (ch != ' ' && ch != '\t') +			return false; +	} +	return false; +} +  static void FoldBashDoc(unsigned int startPos, int length, int, WordList *[],                              Accessor &styler) {  	bool foldComment = styler.GetPropertyInt("fold.comment") != 0; @@ -602,16 +615,16 @@ static void FoldBashDoc(unsigned int startPos, int length, int, WordList *[],  		int style = styleNext;  		styleNext = styler.StyleAt(i + 1);  		bool atEOL = (ch == '\r' && chNext != '\n') || (ch == '\n'); -		if (foldComment && (style == SCE_SH_COMMENTLINE)) { -			if ((ch == '/') && (chNext == '/')) { -				char chNext2 = styler.SafeGetCharAt(i + 2); -				if (chNext2 == '{') { -					levelCurrent++; -				} else if (chNext2 == '}') { -					levelCurrent--; -				} -			} -		} +        // Comment folding +		if (foldComment && atEOL && IsCommentLine(lineCurrent, styler)) +        { +            if (!IsCommentLine(lineCurrent - 1, styler) +                && IsCommentLine(lineCurrent + 1, styler)) +                levelCurrent++; +            else if (IsCommentLine(lineCurrent - 1, styler) +                     && !IsCommentLine(lineCurrent+1, styler)) +                levelCurrent--; +        }  		if (style == SCE_C_OPERATOR) {  			if (ch == '{') {  				levelCurrent++; | 
