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