Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
fish.vim86 linesDownload Raw Back to indent
1" Vim indent file2" Language:     fish3" Maintainer:   Nicholas Boyle (github.com/nickeb96)4" Repository:   https://github.com/nickeb96/fish.vim5" Last Change:  February 4, 20236"               2023 Aug 28 by Vim Project (undo_indent)7 8if exists("b:did_indent")9    finish10endif11let b:did_indent = 112 13setlocal indentexpr=GetFishIndent(v:lnum)14setlocal indentkeys+==end,=else,=case15 16let b:undo_indent = "setlocal indentexpr< indentkeys<"17 18function s:PrevCmdStart(linenum)19    let l:linenum = a:linenum20    " look for the first line that isn't a line continuation21    while l:linenum > 1 && getline(l:linenum - 1) =~# '\\$'22        let l:linenum = l:linenum - 123    endwhile24    return l:linenum25endfunction26 27function GetFishIndent(lnum)28    let l:shiftwidth = shiftwidth()29 30    let l:prevlnum = prevnonblank(a:lnum - 1)31    if l:prevlnum ==# 032        return 033    endif34 35    " if the previous line ended with a line continuation36    if getline(a:lnum - 1) =~# '\\$'37        if a:lnum ==# 0 || getline(a:lnum - 2) !~# '\\$'38            " this is the first line continuation in a chain, so indent it39            return indent(a:lnum - 1) + l:shiftwidth40        else41            " use the same indentation as the previous continued line42            return indent(a:lnum - 1)43        endif44    endif45 46    let l:prevlnum = s:PrevCmdStart(l:prevlnum)47 48    let l:prevline = getline(l:prevlnum)49    if l:prevline =~# '^\s*\(begin\|if\|else\|while\|for\|function\|case\|switch\)\>'50        let l:indent = l:shiftwidth51    else52        let l:indent = 053    endif54 55    let l:line = getline(a:lnum)56    if l:line =~# '^\s*end\>'57        " find end's matching start58        let l:depth = 159        let l:currentlnum = a:lnum60        while l:depth > 0 && l:currentlnum > 061            let l:currentlnum = s:PrevCmdStart(prevnonblank(l:currentlnum - 1))62            let l:currentline = getline(l:currentlnum)63            if l:currentline =~# '^\s*end\>'64                let l:depth = l:depth + 165            elseif l:currentline =~# '^\s*\(begin\|if\|while\|for\|function\|switch\)\>'66                let l:depth = l:depth - 167            endif68        endwhile69        if l:currentline =~# '^\s*switch\>'70            return indent(l:currentlnum)71        else72            return indent(l:prevlnum) + l:indent - l:shiftwidth73        endif74    elseif l:line =~# '^\s*else\>'75        return indent(l:prevlnum) + l:indent - l:shiftwidth76    elseif l:line =~# '^\s*case\>'77        if getline(l:prevlnum) =~# '^\s*switch\>'78            return indent(l:prevlnum) + l:indent79        else80            return indent(l:prevlnum) + l:indent - l:shiftwidth81        endif82    else83        return indent(l:prevlnum) + l:indent84    endif85endfunction86 
codekingpro/portable-devtools · Team Ai