1" Vim indent file 2" Language: Perl 6 3" Maintainer: vim-perl <[email protected]> 4" Homepage: https://github.com/vim-perl/vim-perl 5" Bugs/requests: https://github.com/vim-perl/vim-perl/issues 6" Last Change: 2020 Apr 15 7" Contributors: Andy Lester <[email protected]> 8" Hinrik Örn Sigurðsson <[email protected]> 9" 10" Adapted from indent/perl.vim by Rafael Garcia-Suarez <[email protected]> 11 12" Suggestions and improvements by : 13" Aaron J. Sherman (use syntax for hints) 14" Artem Chuprina (play nice with folding) 15" TODO: 16" This file still relies on stuff from the Perl 5 syntax file, which Perl 6 17" does not use. 18" 19" Things that are not or not properly indented (yet) : 20" - Continued statements 21" print "foo", 22" "bar"; 23" print "foo" 24" if bar(); 25" - Multiline regular expressions (m//x) 26" (The following probably needs modifying the perl syntax file) 27" - qw() lists 28" - Heredocs with terminators that don't match \I\i* 29 30" Only load this indent file when no other was loaded. 31if exists("b:did_indent") 32 finish 33endif 34let b:did_indent = 1 35 36" Is syntax highlighting active ? 37let b:indent_use_syntax = has("syntax") 38 39setlocal indentexpr=GetRakuIndent() 40 41" we reset it first because the Perl 5 indent file might have been loaded due 42" to a .pl/pm file extension, and indent files don't clean up afterwards 43setlocal indentkeys& 44 45setlocal indentkeys+=0=,0),0],0>,0»,0=or,0=and 46if !b:indent_use_syntax 47 setlocal indentkeys+=0=EO 48endif 49 50let s:cpo_save = &cpo 51set cpo-=C 52 53function! GetRakuIndent() 54 55 " Get the line to be indented 56 let cline = getline(v:lnum) 57 58 " Indent POD markers to column 0 59 if cline =~ '^\s*=\L\@!' 60 return 0 61 endif 62 63 " Get current syntax item at the line's first char 64 let csynid = '' 65 if b:indent_use_syntax 66 let csynid = synIDattr(synID(v:lnum,1,0),"name") 67 endif 68 69 " Don't reindent POD and heredocs 70 if csynid =~ "^rakuPod" 71 return indent(v:lnum) 72 endif 73 74 75 " Now get the indent of the previous perl line. 76 77 " Find a non-blank line above the current line. 78 let lnum = prevnonblank(v:lnum - 1) 79 " Hit the start of the file, use zero indent. 80 if lnum == 0 81 return 0 82 endif 83 let line = getline(lnum) 84 let ind = indent(lnum) 85 " Skip heredocs, POD, and comments on 1st column 86 if b:indent_use_syntax 87 let skippin = 2 88 while skippin 89 let synid = synIDattr(synID(lnum,1,0),"name") 90 if (synid =~ "^rakuPod" || synid =~ "rakuComment") 91 let lnum = prevnonblank(lnum - 1) 92 if lnum == 0 93 return 0 94 endif 95 let line = getline(lnum) 96 let ind = indent(lnum) 97 let skippin = 1 98 else 99 let skippin = 0 100 endif 101 endwhile 102 endif 103 104 if line =~ '[<«\[{(]\s*\(#[^)}\]»>]*\)\=$' 105 let ind = ind + &sw 106 endif 107 if cline =~ '^\s*[)}\]»>]' 108 let ind = ind - &sw 109 endif 110 111 " Indent lines that begin with 'or' or 'and' 112 if cline =~ '^\s*\(or\|and\)\>' 113 if line !~ '^\s*\(or\|and\)\>' 114 let ind = ind + &sw 115 endif 116 elseif line =~ '^\s*\(or\|and\)\>' 117 let ind = ind - &sw 118 endif 119 120 return ind 121 122endfunction 123 124let &cpo = s:cpo_save 125unlet s:cpo_save 126 127" vim:ts=8:sts=4:sw=4:expandtab:ft=vim 128