MCPcopy Create free account
hub / github.com/ProgerXP/Notepad2e / FoldLuaDoc

Function FoldLuaDoc

scintilla/lexers/LexLua.cxx:367–439  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

365}
366
367static void FoldLuaDoc(unsigned int startPos, int length, int /* initStyle */, WordList *[],
368 Accessor &styler) {
369 unsigned int lengthDoc = startPos + length;
370 int visibleChars = 0;
371 int lineCurrent = styler.GetLine(startPos);
372 int levelPrev = styler.LevelAt(lineCurrent) & SC_FOLDLEVELNUMBERMASK;
373 int levelCurrent = levelPrev;
374 char chNext = styler[startPos];
375 bool foldCompact = styler.GetPropertyInt("fold.compact", 1) != 0;
376 int styleNext = styler.StyleAt(startPos);
377
378 for (unsigned int i = startPos; i < lengthDoc; i++) {
379 char ch = chNext;
380 chNext = styler.SafeGetCharAt(i + 1);
381 int style = styleNext;
382 styleNext = styler.StyleAt(i + 1);
383 bool atEOL = (ch == '\r' && chNext != '\n') || (ch == '\n');
384 if (style == SCE_LUA_WORD) {
385 if (ch == 'i' || ch == 'd' || ch == 'f' || ch == 'e' || ch == 'r' || ch == 'u') {
386 char s[10] = "";
387 for (unsigned int j = 0; j < 8; j++) {
388 if (!iswordchar(styler[i + j])) {
389 break;
390 }
391 s[j] = styler[i + j];
392 s[j + 1] = '\0';
393 }
394
395 if ((strcmp(s, "if") == 0) || (strcmp(s, "do") == 0) || (strcmp(s, "function") == 0) || (strcmp(s, "repeat") == 0)) {
396 levelCurrent++;
397 }
398 if ((strcmp(s, "end") == 0) || (strcmp(s, "elseif") == 0) || (strcmp(s, "until") == 0)) {
399 levelCurrent--;
400 }
401 }
402 } else if (style == SCE_LUA_OPERATOR) {
403 if (ch == '{' || ch == '(') {
404 levelCurrent++;
405 } else if (ch == '}' || ch == ')') {
406 levelCurrent--;
407 }
408 } else if (style == SCE_LUA_LITERALSTRING || style == SCE_LUA_COMMENT) {
409 if (ch == '[') {
410 levelCurrent++;
411 } else if (ch == ']') {
412 levelCurrent--;
413 }
414 }
415
416 if (atEOL) {
417 int lev = levelPrev;
418 if (visibleChars == 0 && foldCompact) {
419 lev |= SC_FOLDLEVELWHITEFLAG;
420 }
421 if ((levelCurrent > levelPrev) && (visibleChars > 0)) {
422 lev |= SC_FOLDLEVELHEADERFLAG;
423 }
424 if (lev != styler.LevelAt(lineCurrent)) {

Callers

nothing calls this directly

Calls 8

iswordcharFunction · 0.85
isspacecharFunction · 0.85
GetLineMethod · 0.80
LevelAtMethod · 0.80
GetPropertyIntMethod · 0.80
SafeGetCharAtMethod · 0.80
StyleAtMethod · 0.45
SetLevelMethod · 0.45

Tested by

no test coverage detected