Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
gdscript.vim149 linesDownload Raw Back to indent
1vim9script2 3# Vim indent file4# Language: gdscript (Godot game engine)5# Maintainer: Maxim Kim <habamax@gmail.com>6# Based on python indent file.7 8if exists("b:did_indent")9    finish10endif11b:did_indent = 112 13var undo_opts = "setl indentexpr< indentkeys< lisp< autoindent<"14 15if exists('b:undo_indent')16    b:undo_indent ..= "|" .. undo_opts17else18    b:undo_indent = undo_opts19endif20 21setlocal nolisp22setlocal autoindent23setlocal indentexpr=GDScriptIndent()24setlocal indentkeys+=<:>,=elif,=except25 26 27def GDScriptIndent(): number28    # If this line is explicitly joined: If the previous line was also joined,29    # line it up with that one, otherwise add two 'shiftwidth'30    if getline(v:lnum - 1) =~ '\\$'31        if v:lnum > 1 && getline(v:lnum - 2) =~ '\\$'32            return indent(v:lnum - 1)33        endif34        return indent(v:lnum - 1) + (shiftwidth() * 2)35    endif36 37    # If the start of the line is in a string don't change the indent.38    if has('syntax_items') && synIDattr(synID(v:lnum, 1, 1), "name") =~ "String$"39        return -140    endif41 42    # Search backwards for the previous non-empty line.43    var plnum = prevnonblank(v:lnum - 1)44 45    if plnum == 046        # This is the first non-empty line, use zero indent.47        return 048    endif49 50    var plindent = indent(plnum)51    var plnumstart = plnum52 53    # Get the line and remove a trailing comment.54    # Use syntax highlighting attributes when possible.55    var pline = getline(plnum)56    var pline_len = strlen(pline)57    if has('syntax_items')58        # If the last character in the line is a comment, do a binary search for59        # the start of the comment.  synID() is slow, a linear search would take60        # too long on a long line.61        if synIDattr(synID(plnum, pline_len, 1), "name") =~ "\\(Comment\\|Todo\\)$"62            var min = 163            var max = pline_len64            while min < max65                var col = (min + max) / 266                if synIDattr(synID(plnum, col, 1), "name") =~ "\\(Comment\\|Todo\\)$"67                    max = col68                else69                    min = col + 170                endif71            endwhile72            pline = strpart(pline, 0, min - 1)73        endif74    else75        var col = 076        while col < pline_len77            if pline[col] == '#'78                pline = strpart(pline, 0, col)79                break80            endif81            col = col + 182        endwhile83    endif84 85 86    # When "inside" parenthesis: If at the first line below the parenthesis add87    # one 'shiftwidth' ("inside" is simplified and not really checked)88    # my_var = (89    #     a90    #     + b91    #     + c92    # )93    if pline =~ '[({\[]\s*$'94        return indent(plnum) + shiftwidth()95    endif96 97 98    # If the previous line ended with a colon, indent this line99    if pline =~ ':\s*$'100        return plindent + shiftwidth()101    endif102 103    # If the previous line was a stop-execution statement...104    if getline(plnum) =~ '^\s*\(break\|continue\|raise\|return\|pass\)\>'105        # See if the user has already dedented106        if indent(v:lnum) > indent(plnum) - shiftwidth()107            # If not, recommend one dedent108            return indent(plnum) - shiftwidth()109        endif110        # Otherwise, trust the user111        return -1112    endif113 114    # If the current line begins with a keyword that lines up with "try"115    if getline(v:lnum) =~ '^\s*\(except\|finally\)\>'116        var lnum = v:lnum - 1117        while lnum >= 1118            if getline(lnum) =~ '^\s*\(try\|except\)\>'119                var ind = indent(lnum)120                if ind >= indent(v:lnum)121                    return -1   # indent is already less than this122                endif123                return ind      # line up with previous try or except124            endif125            lnum = lnum - 1126        endwhile127        return -1               # no matching "try"!128    endif129 130 131    # If the current line begins with a header keyword, dedent132    if getline(v:lnum) =~ '^\s*\(elif\|else\)\>'133 134        # Unless the previous line was a one-liner135        if getline(plnumstart) =~ '^\s*\(for\|if\|try\)\>'136            return plindent137        endif138 139        # Or the user has already dedented140        if indent(v:lnum) <= plindent - shiftwidth()141            return -1142        endif143 144        return plindent - shiftwidth()145    endif146 147    return -1148enddef149 
codekingpro/portable-devtools · Team Ai