Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Diff of /lexers/LexPO.cxx [c51738] .. [602a6c] Maximize Restore

  Switch to unified view

a/lexers/LexPO.cxx b/lexers/LexPO.cxx
...
...
96
        // whether we should enter a new state
96
        // whether we should enter a new state
97
        if (sc.state == SCE_PO_DEFAULT) {
97
        if (sc.state == SCE_PO_DEFAULT) {
98
            // forward to the first non-white character on the line
98
            // forward to the first non-white character on the line
99
            bool atLineStart = sc.atLineStart;
99
            bool atLineStart = sc.atLineStart;
100
            if (atLineStart) {
100
            if (atLineStart) {
101
              // reset line state if it is set to comment state so empty lines don't get
102
              // comment line state, and the folding code folds comments separately,
103
              // and anyway the styling don't use line state for comments
104
              if (curLineState == SCE_PO_COMMENT)
105
                  curLineState = SCE_PO_DEFAULT;
106
              
101
                while (sc.More() && ! sc.atLineEnd && isspacechar(sc.ch))
107
                while (sc.More() && ! sc.atLineEnd && isspacechar(sc.ch))
102
                    sc.Forward();
108
                    sc.Forward();
103
            }
109
            }
104
            
110
            
105
            if (atLineStart && sc.ch == '#') {
111
            if (atLineStart && sc.ch == '#') {
...
...
140
        }
146
        }
141
    }
147
    }
142
    sc.Complete();
148
    sc.Complete();
143
}
149
}
144
150
151
static int FindNextNonEmptyLineState(unsigned int startPos, Accessor &styler) {
152
  unsigned int length = styler.Length();
153
  for (unsigned int i = startPos; i < length; i++) {
154
      if (! isspacechar(styler[i])) {
155
          return styler.GetLineState(styler.GetLine(i));
156
      }
157
  }
158
  return 0;
159
}
160
161
static void FoldPODoc(unsigned int startPos, int length, int, WordList *[], Accessor &styler) {
162
  if (! styler.GetPropertyInt("fold"))
163
      return;
164
  bool foldCompact = styler.GetPropertyInt("fold.compact") != 0;
165
  bool foldComment = styler.GetPropertyInt("fold.comment") != 0;
166
  
167
  unsigned int endPos = startPos + length;
168
  int curLine = styler.GetLine(startPos);
169
  int lineState = styler.GetLineState(curLine);
170
  int nextLineState = lineState;
171
  int level = styler.LevelAt(curLine) & SC_FOLDLEVELNUMBERMASK;
172
  int nextLevel = level;
173
  int visible = 0;
174
  int chNext = styler[startPos];
175
  
176
  for (unsigned int i = startPos; i < endPos; i++) {
177
      int ch = chNext;
178
      chNext = styler.SafeGetCharAt(i+1);
179
      
180
      if (! isspacechar(ch)) {
181
          visible++;
182
      } else if ((ch == '\r' && chNext != '\n') || ch == '\n' || i+1 >= endPos) {
183
          int lvl = level;
184
          int nextLine = curLine + 1;
185
          
186
          nextLineState = styler.GetLineState(nextLine);
187
          if ((lineState != SCE_PO_COMMENT || foldComment) &&
188
                  nextLineState == lineState &&
189
                  FindNextNonEmptyLineState(i, styler) == lineState)
190
              nextLevel = SC_FOLDLEVELBASE + 1;
191
          else
192
              nextLevel = SC_FOLDLEVELBASE;
193
          
194
          if (nextLevel > level)
195
              lvl |= SC_FOLDLEVELHEADERFLAG;
196
          if (visible == 0 && foldCompact)
197
              lvl |= SC_FOLDLEVELWHITEFLAG;
198
          
199
          styler.SetLevel(curLine, lvl);
200
          
201
          lineState = nextLineState;
202
          curLine = nextLine;
203
          level = nextLevel;
204
          visible = 0;
205
      }
206
  }
207
}
208
145
static const char *const poWordListDesc[] = {
209
static const char *const poWordListDesc[] = {
146
    0
210
    0
147
};
211
};
148
212
149
LexerModule lmPO(SCLEX_PO, ColourisePODoc, "po", 0, poWordListDesc);
213
LexerModule lmPO(SCLEX_PO, ColourisePODoc, "po", FoldPODoc, poWordListDesc);