Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
perl.vim185 linesDownload Raw Back to indent
1" Vim indent file2" Language:      Perl3" Maintainer:    vim-perl <vim-perl@googlegroups.com> (need to be subscribed to post)4" Homepage:      https://github.com/vim-perl/vim-perl5" Bugs/requests: https://github.com/vim-perl/vim-perl/issues6" License:       Vim License (see :help license)7" Last Change:   2022 Jun 148 9" Suggestions and improvements by :10"   Aaron J. Sherman (use syntax for hints)11"   Artem Chuprina (play nice with folding)12 13" TODO things that are not or not properly indented (yet) :14" - Continued statements15"     print "foo",16"       "bar";17"     print "foo"18"       if bar();19" - Multiline regular expressions (m//x)20" (The following probably needs modifying the perl syntax file)21" - qw() lists22" - Heredocs with terminators that don't match \I\i*23 24" Only load this indent file when no other was loaded.25if exists("b:did_indent")26    finish27endif28let b:did_indent = 129 30" Is syntax highlighting active ?31let b:indent_use_syntax = has("syntax")32 33setlocal indentexpr=GetPerlIndent()34setlocal indentkeys+=0=,0),0],0=or,0=and35if !b:indent_use_syntax36    setlocal indentkeys+=0=EO37endif38 39let b:undo_indent = "setl inde< indk<"40 41let s:cpo_save = &cpo42set cpo-=C43 44function! GetPerlIndent()45 46    " Get the line to be indented47    let cline = getline(v:lnum)48 49    " Indent POD markers to column 050    if cline =~ '^\s*=\L\@!'51        return 052    endif53 54    " Get current syntax item at the line's first char55    let csynid = ''56    if b:indent_use_syntax57        let csynid = synIDattr(synID(v:lnum,1,0),"name")58    endif59 60    " Don't reindent POD and heredocs61    if csynid == "perlPOD" || csynid == "perlHereDoc" || csynid =~ "^pod"62        return indent(v:lnum)63    endif64 65    " Indent end-of-heredocs markers to column 066    if b:indent_use_syntax67        " Assumes that an end-of-heredoc marker matches \I\i* to avoid68        " confusion with other types of strings69        if csynid == "perlStringStartEnd" && cline =~ '^\I\i*$'70            return 071        endif72    else73        " Without syntax hints, assume that end-of-heredocs markers begin with EO74        if cline =~ '^\s*EO'75            return 076        endif77    endif78 79    " Now get the indent of the previous perl line.80 81    " Find a non-blank line above the current line.82    let lnum = prevnonblank(v:lnum - 1)83    " Hit the start of the file, use zero indent.84    if lnum == 085        return 086    endif87    let line = getline(lnum)88    let ind = indent(lnum)89    " Skip heredocs, POD, and comments on 1st column90    if b:indent_use_syntax91        let skippin = 292        while skippin93            let synid = synIDattr(synID(lnum,1,0),"name")94            if (synid == "perlStringStartEnd" && line =~ '^\I\i*$')95                        \ || (skippin != 2 && synid == "perlPOD")96                        \ || (skippin != 2 && synid == "perlHereDoc")97                        \ || synid == "perlComment"98                        \ || synid =~ "^pod"99                let lnum = prevnonblank(lnum - 1)100                if lnum == 0101                    return 0102                endif103                let line = getline(lnum)104                let ind = indent(lnum)105                let skippin = 1106            else107                let skippin = 0108            endif109        endwhile110    else111        if line =~ "^EO"112            let lnum = search("<<[\"']\\=EO", "bW")113            let line = getline(lnum)114            let ind = indent(lnum)115        endif116    endif117 118    " Indent blocks enclosed by {}, (), or []119    if b:indent_use_syntax120        " Find a real opening brace121        " NOTE: Unlike Perl character classes, we do NOT need to escape the122        " closing brackets with a backslash.  Doing so just puts a backslash123        " in the character class and causes sorrow.  Instead, put the closing124        " bracket as the first character in the class.125        let braceclass = '[][(){}]'126        let bracepos = match(line, braceclass, matchend(line, '^\s*[])}]'))127        while bracepos != -1128            let synid = synIDattr(synID(lnum, bracepos + 1, 0), "name")129            " If the brace is highlighted in one of those groups, indent it.130            " 'perlHereDoc' is here only to handle the case '&foo(<<EOF)'.131            if synid == ""132                        \ || synid == "perlMatchStartEnd"133                        \ || synid == "perlHereDoc"134                        \ || synid == "perlBraces"135                        \ || synid == "perlStatementIndirObj"136                        \ || synid == "perlSubDeclaration"137                        \ || synid =~ "^perlFiledescStatement"138                        \ || synid =~ '^perl\(Sub\|Block\|Package\)Fold'139                let brace = strpart(line, bracepos, 1)140                if brace == '(' || brace == '{' || brace == '['141                    let ind = ind + shiftwidth()142                else143                    let ind = ind - shiftwidth()144                endif145            endif146            let bracepos = match(line, braceclass, bracepos + 1)147        endwhile148        let bracepos = matchend(cline, '^\s*[])}]')149        if bracepos != -1150            let synid = synIDattr(synID(v:lnum, bracepos, 0), "name")151            if synid == ""152                        \ || synid == "perlMatchStartEnd"153                        \ || synid == "perlBraces"154                        \ || synid == "perlStatementIndirObj"155                        \ || synid =~ '^perl\(Sub\|Block\|Package\)Fold'156                let ind = ind - shiftwidth()157            endif158        endif159    else160        if line =~ '[{[(]\s*\(#[^])}]*\)\=$'161            let ind = ind + shiftwidth()162        endif163        if cline =~ '^\s*[])}]'164            let ind = ind - shiftwidth()165        endif166    endif167 168    " Indent lines that begin with 'or' or 'and'169    if cline =~ '^\s*\(or\|and\)\>'170        if line !~ '^\s*\(or\|and\)\>'171            let ind = ind + shiftwidth()172        endif173    elseif line =~ '^\s*\(or\|and\)\>'174        let ind = ind - shiftwidth()175    endif176 177    return ind178 179endfunction180 181let &cpo = s:cpo_save182unlet s:cpo_save183 184" vim:ts=8:sts=4:sw=4:expandtab:ft=vim185 
codekingpro/portable-devtools · Team Ai