Install vim74
[msysgit.git] / share / vim / vim74 / indent / perl6.vim
blobff2a579f0a6b8ae0fd4b95c0cc7e9c68f7e635b1
1 " Vim indent file
2 " Language:      Perl 6
3 " Maintainer:    vim-perl <vim-perl@googlegroups.com>
4 " Homepage:      http://github.com/vim-perl/vim-perl
5 " Bugs/requests: http://github.com/vim-perl/vim-perl/issues
6 " Last Change:   2013-07-21
7 " Contributors:  Andy Lester <andy@petdance.com>
8 "                Hinrik Örn Sigurðsson <hinrik.sig@gmail.com>
10 " Adapted from indent/perl.vim by Rafael Garcia-Suarez <rgarciasuarez@free.fr>
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.
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*
30 " Only load this indent file when no other was loaded.
31 if exists("b:did_indent")
32     finish
33 endif
34 let b:did_indent = 1
36 " Is syntax highlighting active ?
37 let b:indent_use_syntax = has("syntax")
39 setlocal indentexpr=GetPerl6Indent()
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
43 setlocal indentkeys&
45 setlocal indentkeys+=0=,0),0],0>,0»,0=or,0=and
46 if !b:indent_use_syntax
47     setlocal indentkeys+=0=EO
48 endif
50 let s:cpo_save = &cpo
51 set cpo-=C
53 function! GetPerl6Indent()
55     " Get the line to be indented
56     let cline = getline(v:lnum)
58     " Indent POD markers to column 0
59     if cline =~ '^\s*=\L\@!'
60         return 0
61     endif
63     " Don't reindent coments on first column
64     if cline =~ '^#'
65         return 0
66     endif
68     " Get current syntax item at the line's first char
69     let csynid = ''
70     if b:indent_use_syntax
71         let csynid = synIDattr(synID(v:lnum,1,0),"name")
72     endif
74     " Don't reindent POD and heredocs
75     if csynid =~ "^p6Pod"
76         return indent(v:lnum)
77     endif
80     " Now get the indent of the previous perl line.
82     " Find a non-blank line above the current line.
83     let lnum = prevnonblank(v:lnum - 1)
84     " Hit the start of the file, use zero indent.
85     if lnum == 0
86         return 0
87     endif
88     let line = getline(lnum)
89     let ind = indent(lnum)
90     " Skip heredocs, POD, and comments on 1st column
91     if b:indent_use_syntax
92         let skippin = 2
93         while skippin
94             let synid = synIDattr(synID(lnum,1,0),"name")
95             if (synid =~ "^p6Pod" || synid =~ "p6Comment")
96                 let lnum = prevnonblank(lnum - 1)
97                 if lnum == 0
98                     return 0
99                 endif
100                 let line = getline(lnum)
101                 let ind = indent(lnum)
102                 let skippin = 1
103             else
104                 let skippin = 0
105             endif
106         endwhile
107     endif
109         if line =~ '[<«\[{(]\s*\(#[^)}\]»>]*\)\=$'
110             let ind = ind + &sw
111         endif
112         if cline =~ '^\s*[)}\]»>]'
113             let ind = ind - &sw
114         endif
116     " Indent lines that begin with 'or' or 'and'
117     if cline =~ '^\s*\(or\|and\)\>'
118         if line !~ '^\s*\(or\|and\)\>'
119             let ind = ind + &sw
120         endif
121     elseif line =~ '^\s*\(or\|and\)\>'
122         let ind = ind - &sw
123     endif
125     return ind
127 endfunction
129 let &cpo = s:cpo_save
130 unlet s:cpo_save
132 " vim:ts=8:sts=4:sw=4:expandtab:ft=vim