Skip to content

[Feature Request] UDL folding regions by indentation level (or otherwise), and folding-related styling #9734

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
AGuyWhoSkis opened this issue Apr 6, 2021 · 2 comments
Labels
udl Everything related to User Defined Language

Comments

@AGuyWhoSkis
Copy link

I love use notepad++ for taking notes. I categorize notes by indentation level, because the YAML language format then lets me fold sections by category. You can see the advantages in this video.

This technique is so powerful that I could write an 800 page textbook, indent it by chapters, sections, definitions, etc., and despite being a single 10,000+ line file, it would still be easy to navigate, view, and edit.

It's not likely that many people use this "feature" in similar ways, but I think this idea is strong enough to warrant at least some consideration to implement it as a more fleshed out (and intended) feature.

Similar ideas relating to configurable UDL folding behaviour have been suggested:

@TomMars
Copy link

TomMars commented Apr 22, 2021

It's been a long time people asking for this feature and I hope they will work on it.
Folding regions by indentation is very useful for things like huge lists or tupples in Python.

Devs can you add this feature to the user lexer please ?

@ArkadiuszMichalski ArkadiuszMichalski added the udl Everything related to User Defined Language label Apr 26, 2021
@KnIfER
Copy link

KnIfER commented May 1, 2021

In LexUser.cxx ( the general Lexer for UDLs ), I tested some code in the empty FoldUserDoc function:

static void FoldUserDoc_Markdown(Sci_PositionU startPos, Sci_Position length, int /* initStyle */
    , WordList *[], Accessor &styler) 
{

    Sci_PositionU position=startPos
        , lnEd
        , lenDoc = startPos+length;
    Sci_Position ln = styler.GetLine(position);

    int markedLevel=0;
    int prevLevelMarked=(styler.GetLevel(ln-1)&SC_FOLDLEVELNUMBERMASK)-SC_FOLDLEVELBASE;

    position = styler.LineStart(ln-1);
    lnEd = styler.LineEnd(ln-1);
    markedLevel=0;
    // count #
    for(int i=position; i<=lnEd; i++){
        if (styler[i]!='#') {
            break;
        }
        else {
            markedLevel++;
        }
    }
    if (markedLevel)
    {
        prevLevelMarked = markedLevel;
    }
    position=startPos;

    // iterate all lines
    for(; position<lenDoc; ln++) {
        position = styler.LineStart(ln+0); // line end
        lnEd = styler.LineStart(ln+1)-1; // line start
        if(lnEd>=lenDoc) lnEd = lenDoc-1; // sanity check
        
        markedLevel=0;
        bool isEmpty=true;
        bool findOpening=true;
        // count #
        int i=position;
        for(; i<=lnEd; i++){
            if (findOpening)
            {
                if (styler[i]=='#') {
                    markedLevel++;
                    if (isEmpty)
                    {
                        isEmpty=false;
                    }
                }
                else {
                    findOpening=false;
                }
                continue;
            }
            if (!(isEmpty=isspacechar(styler[i]))) 
            {
                break;
            }
        }

        int lv = (prevLevelMarked) + SC_FOLDLEVELBASE;

        if(markedLevel) lv = markedLevel-1+SC_FOLDLEVELBASE;

        if(markedLevel) lv |= SC_FOLDLEVELHEADERFLAG;
        if(isEmpty) lv |= SC_FOLDLEVELWHITEFLAG;

        styler.SetLevel(ln, lv);

        if (markedLevel>0)
        {
            prevLevelMarked = markedLevel;
        }
    }
}

The result:

image

Folding for Markdown!

Reference: LexIndent.cxx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
udl Everything related to User Defined Language
Projects
None yet
Development

No branches or pull requests

4 participants