diff options
author | kudah <kudahkukarek@gmail.com> | 2013-04-18 05:40:40 +0300 |
---|---|---|
committer | kudah <kudahkukarek@gmail.com> | 2013-04-18 05:40:40 +0300 |
commit | 1ac16b89d6cc78457b3c95098cf5eb9cb5dd8690 (patch) | |
tree | 72bed11f271c7fb32169d70cc0466902fa3b887d | |
parent | f8c4e47342ff6837f2832fe0afee300d585a84a7 (diff) | |
download | scintilla-mirror-1ac16b89d6cc78457b3c95098cf5eb9cb5dd8690.tar.gz |
Fold indented imports.
-rw-r--r-- | lexers/LexHaskell.cxx | 47 |
1 files changed, 39 insertions, 8 deletions
diff --git a/lexers/LexHaskell.cxx b/lexers/LexHaskell.cxx index 570e79b46..834cc1655 100644 --- a/lexers/LexHaskell.cxx +++ b/lexers/LexHaskell.cxx @@ -75,6 +75,14 @@ static inline bool IsAnOperatorChar(const int ch) { || ch == '^' || ch == '|' || ch == '~' || ch == '\\'); } +static inline bool IsCommentBlockStyle(int style) { + return (style >= SCE_HA_COMMENTBLOCK && style <= SCE_HA_COMMENTBLOCK3); +} + +static inline bool IsCommentStyle(int style) { + return (style >= SCE_HA_COMMENTLINE && style <= SCE_HA_COMMENTBLOCK3); +} + struct OptionsHaskell { bool magicHash; bool allowQuotes; @@ -84,6 +92,7 @@ struct OptionsHaskell { bool foldComment; bool foldCompact; bool foldImports; + bool foldIndentedImports; OptionsHaskell() { magicHash = true; allowQuotes = true; @@ -93,6 +102,7 @@ struct OptionsHaskell { foldComment = false; foldCompact = false; foldImports = false; + foldIndentedImports = true; } }; @@ -132,6 +142,10 @@ struct OptionSetHaskell : public OptionSet<OptionsHaskell> { DefineProperty("fold.haskell.imports", &OptionsHaskell::foldImports, "Set to 1 to enable folding of import declarations"); + DefineProperty("fold.haskell.imports.indented", &OptionsHaskell::foldIndentedImports, + "Set this property to 0 to disable folding imports not starting at " + "column 0 when fold.haskell.imports=1"); + DefineWordListSets(haskellWordListDesc); } }; @@ -152,9 +166,30 @@ class LexerHaskell : public ILexer { } } - inline bool LineContainsImport(int line, Accessor &styler) { + bool LineContainsImport(const int line, Accessor &styler) { if (options.foldImports) { - return styler.Match(styler.LineStart(line), "import"); + int currentPos = styler.LineStart(line); + int style = styler.StyleAt(currentPos); + + if (options.foldIndentedImports) { + int ch = styler.SafeGetCharAt(currentPos); + int eol_pos = styler.LineStart(line + 1) - 1; + + while(currentPos < eol_pos) { + ch = styler[currentPos]; + style = styler.StyleAt(currentPos); + + if (ch == ' ' || ch == '\t' + || IsCommentBlockStyle(style)) { + currentPos++; + } else { + break; + } + } + } + + return (style == SCE_HA_KEYWORD + && styler.Match(currentPos, "import")); } else { return false; } @@ -585,10 +620,6 @@ void SCI_METHOD LexerHaskell::Lex(unsigned int startPos, int length, int initSty sc.Complete(); } -static inline bool IsCommentStyle(int style) { - return (style >= SCE_HA_COMMENTLINE && style <= SCE_HA_COMMENTBLOCK3); -} - static bool LineStartsWithACommentOrPreprocessor(int line, Accessor &styler) { int pos = styler.LineStart(line); int eol_pos = styler.LineStart(line + 1) - 1; @@ -660,8 +691,8 @@ void SCI_METHOD LexerHaskell::Fold(unsigned int startPos, int length, int // ini } if (firstImportLine != lineCurrent) { indentCurrentLevel++; - indentCurrent = indentCurrentLevel | indentCurrentMask; } + indentCurrent = indentCurrentLevel | indentCurrentMask; } // Process all characters to end of requested range @@ -707,8 +738,8 @@ void SCI_METHOD LexerHaskell::Fold(unsigned int startPos, int length, int // ini } if (firstImportLine != lineNext) { indentNextLevel++; - indentNext = indentNextLevel | indentNextMask; } + indentNext = indentNextLevel | indentNextMask; } const int levelBeforeComments = Maximum(indentCurrentLevel,indentNextLevel); |