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

Function FoldRbDoc

scintilla/lexers/LexRuby.cxx:1674–1772  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1672 */
1673
1674static void FoldRbDoc(unsigned int startPos, int length, int initStyle,
1675 WordList *[], Accessor &styler) {
1676 const bool foldCompact = styler.GetPropertyInt("fold.compact", 1) != 0;
1677 bool foldComment = styler.GetPropertyInt("fold.comment") != 0;
1678
1679 synchronizeDocStart(startPos, length, initStyle, styler, // ref args
1680 false);
1681 unsigned int endPos = startPos + length;
1682 int visibleChars = 0;
1683 int lineCurrent = styler.GetLine(startPos);
1684 int levelPrev = startPos == 0 ? 0 : (styler.LevelAt(lineCurrent)
1685 & SC_FOLDLEVELNUMBERMASK
1686 & ~SC_FOLDLEVELBASE);
1687 int levelCurrent = levelPrev;
1688 char chNext = styler[startPos];
1689 int styleNext = styler.StyleAt(startPos);
1690 int stylePrev = startPos <= 1 ? SCE_RB_DEFAULT : styler.StyleAt(startPos - 1);
1691 bool buffer_ends_with_eol = false;
1692 for (unsigned int i = startPos; i < endPos; i++) {
1693 char ch = chNext;
1694 chNext = styler.SafeGetCharAt(i + 1);
1695 int style = styleNext;
1696 styleNext = styler.StyleAt(i + 1);
1697 bool atEOL = (ch == '\r' && chNext != '\n') || (ch == '\n');
1698 if (style == SCE_RB_COMMENTLINE) {
1699 if (foldComment && stylePrev != SCE_RB_COMMENTLINE) {
1700 if (chNext == '{') {
1701 levelCurrent++;
1702 } else if (chNext == '}' && levelCurrent > 0) {
1703 levelCurrent--;
1704 }
1705 }
1706 } else if (style == SCE_RB_OPERATOR) {
1707 if (strchr("[{(", ch)) {
1708 levelCurrent++;
1709 } else if (strchr(")}]", ch)) {
1710 // Don't decrement below 0
1711 if (levelCurrent > 0)
1712 levelCurrent--;
1713 }
1714 } else if (style == SCE_RB_WORD && styleNext != SCE_RB_WORD) {
1715 // Look at the keyword on the left and decide what to do
1716 char prevWord[MAX_KEYWORD_LENGTH + 1]; // 1 byte for zero
1717 prevWord[0] = 0;
1718 getPrevWord(i, prevWord, styler, SCE_RB_WORD);
1719 if (!strcmp(prevWord, "end")) {
1720 // Don't decrement below 0
1721 if (levelCurrent > 0)
1722 levelCurrent--;
1723 } else if ( !strcmp(prevWord, "if")
1724 || !strcmp(prevWord, "def")
1725 || !strcmp(prevWord, "class")
1726 || !strcmp(prevWord, "module")
1727 || !strcmp(prevWord, "begin")
1728 || !strcmp(prevWord, "case")
1729 || !strcmp(prevWord, "do")
1730 || !strcmp(prevWord, "while")
1731 || !strcmp(prevWord, "unless")

Callers

nothing calls this directly

Calls 9

synchronizeDocStartFunction · 0.85
getPrevWordFunction · 0.85
isspacecharFunction · 0.85
GetPropertyIntMethod · 0.80
GetLineMethod · 0.80
LevelAtMethod · 0.80
SafeGetCharAtMethod · 0.80
StyleAtMethod · 0.45
SetLevelMethod · 0.45

Tested by

no test coverage detected