Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
bst.vim74 linesDownload Raw Back to indent
1" Vim indent file2" Language:	bst3" Author:	Tim Pope <vimNOSPAM@tpope.info>4" Last Change:	2022 Mar 155 6if exists("b:did_indent")7    finish8endif9let b:did_indent = 110 11setlocal indentexpr=GetBstIndent(v:lnum)12setlocal cinkeys&13setlocal cinkeys-=0#14setlocal indentkeys&15let b:undo_indent = 'setlocal indentexpr< cinkeys< indentkeys<'16 17" Only define the function once.18if exists("*GetBstIndent")19    finish20endif21 22function! s:prevgood(lnum)23    " Find a non-blank line above the current line.24    " Skip over comments.25    let lnum = a:lnum26    while lnum > 027        let lnum = prevnonblank(lnum - 1)28        if getline(lnum) !~ '^\s*%.*$'29            break30        endif31    endwhile32    return lnum33endfunction34 35function! s:strip(lnum)36    let line = getline(a:lnum)37    let line = substitute(line,'"[^"]*"','""','g')38    let line = substitute(line,'%.*','','')39    let line = substitute(line,'^\s\+','','')40    return line41endfunction42 43function! s:count(string,char)44    let str = substitute(a:string,'[^'.a:char.']','','g')45    return strlen(str)46endfunction47 48function! GetBstIndent(lnum) abort49    if a:lnum == 150        return 051    endif52    let lnum = s:prevgood(a:lnum)53    if lnum <= 054        return indent(a:lnum - 1)55    endif56    let line = s:strip(lnum)57    let cline = s:strip(a:lnum)58    if cline =~ '^}' && exists("b:current_syntax")59        call cursor(a:lnum,indent(a:lnum))60        if searchpair('{','','}','bW',"synIDattr(synID(line('.'),col('.'),1),'name') =~? 'comment\\|string'")61            if col('.')+1 == col('$')62                return indent('.')63            else64                return virtcol('.')-165            endif66        endif67    endif68    let fakeline = substitute(line,'^}','','').matchstr(cline,'^}')69    let ind = indent(lnum)70    let ind = ind + shiftwidth() * s:count(line,'{')71    let ind = ind - shiftwidth() * s:count(fakeline,'}')72    return ind73endfunction74 
codekingpro/portable-devtools · Team Ai