annotate runtime/indent/perl.vim @ 1966:43a60ac87145 v7.2.263

updated for version 7.2-263
author vimboss
date Wed, 23 Sep 2009 15:35:48 +0000
parents c8ec93ec75dc
children 71899235e72d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 " Vim indent file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 " Language: Perl
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 " Author: Rafael Garcia-Suarez <rgarciasuarez@free.fr>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4 " URL: http://rgarciasuarez.free.fr/vim/indent/perl.vim
508
c8ec93ec75dc updated for version 7.0143
vimboss
parents: 416
diff changeset
5 " Last Change: 2005 Sep 07
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 " Suggestions and improvements by :
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 " Aaron J. Sherman (use syntax for hints)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9 " Artem Chuprina (play nice with folding)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 " TODO things that are not or not properly indented (yet) :
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 " - Continued statements
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 " print "foo",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 " "bar";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 " print "foo"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 " if bar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 " - Multiline regular expressions (m//x)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 " (The following probably needs modifying the perl syntax file)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 " - qw() lists
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 " - Heredocs with terminators that don't match \I\i*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 " Only load this indent file when no other was loaded.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 if exists("b:did_indent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 let b:did_indent = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 " Is syntax highlighting active ?
508
c8ec93ec75dc updated for version 7.0143
vimboss
parents: 416
diff changeset
29 let b:indent_use_syntax = has("syntax")
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 setlocal indentexpr=GetPerlIndent()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 setlocal indentkeys+=0=,0),0=or,0=and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 if !b:indent_use_syntax
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 setlocal indentkeys+=0=EO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 " Only define the function once.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 if exists("*GetPerlIndent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41
416
3da34f87c760 updated for version 7.0109
vimboss
parents: 7
diff changeset
42 let s:cpo_save = &cpo
3da34f87c760 updated for version 7.0109
vimboss
parents: 7
diff changeset
43 set cpo-=C
3da34f87c760 updated for version 7.0109
vimboss
parents: 7
diff changeset
44
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 function GetPerlIndent()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 " Get the line to be indented
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 let cline = getline(v:lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 " Indent POD markers to column 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 if cline =~ '^\s*=\L\@!'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 return 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 " Don't reindent coments on first column
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 if cline =~ '^#.'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 return 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 " Get current syntax item at the line's first char
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 let csynid = ''
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 if b:indent_use_syntax
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 let csynid = synIDattr(synID(v:lnum,1,0),"name")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 " Don't reindent POD and heredocs
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 if csynid == "perlPOD" || csynid == "perlHereDoc" || csynid =~ "^pod"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 return indent(v:lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 " Indent end-of-heredocs markers to column 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72 if b:indent_use_syntax
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73 " Assumes that an end-of-heredoc marker matches \I\i* to avoid
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 " confusion with other types of strings
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75 if csynid == "perlStringStartEnd" && cline =~ '^\I\i*$'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 return 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79 " Without syntax hints, assume that end-of-heredocs markers begin with EO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80 if cline =~ '^\s*EO'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81 return 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85 " Now get the indent of the previous perl line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 " Find a non-blank line above the current line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88 let lnum = prevnonblank(v:lnum - 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89 " Hit the start of the file, use zero indent.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90 if lnum == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 return 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93 let line = getline(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94 let ind = indent(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95 " Skip heredocs, POD, and comments on 1st column
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96 if b:indent_use_syntax
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
97 let skippin = 2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98 while skippin
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
99 let synid = synIDattr(synID(lnum,1,0),"name")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
100 if (synid == "perlStringStartEnd" && line =~ '^\I\i*$')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101 \ || (skippin != 2 && synid == "perlPOD")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102 \ || (skippin != 2 && synid == "perlHereDoc")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103 \ || synid == "perlComment"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 \ || synid =~ "^pod"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105 let lnum = prevnonblank(lnum - 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106 if lnum == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 return 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109 let line = getline(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110 let ind = indent(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111 let skippin = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
112 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
113 let skippin = 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
117 if line =~ "^EO"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118 let lnum = search("<<[\"']\\=EO", "bW")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
119 let line = getline(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120 let ind = indent(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
123
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124 " Indent blocks enclosed by {} or ()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125 if b:indent_use_syntax
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126 " Find a real opening brace
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127 let bracepos = match(line, '[(){}]', matchend(line, '^\s*[)}]'))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128 while bracepos != -1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129 let synid = synIDattr(synID(lnum, bracepos + 1, 0), "name")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130 " If the brace is highlighted in one of those groups, indent it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131 " 'perlHereDoc' is here only to handle the case '&foo(<<EOF)'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132 if synid == ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133 \ || synid == "perlMatchStartEnd"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134 \ || synid == "perlHereDoc"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
135 \ || synid =~ "^perlFiledescStatement"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
136 \ || synid =~ '^perl\(Sub\|BEGINEND\|If\)Fold'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
137 let brace = strpart(line, bracepos, 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138 if brace == '(' || brace == '{'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
139 let ind = ind + &sw
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141 let ind = ind - &sw
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
142 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
143 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
144 let bracepos = match(line, '[(){}]', bracepos + 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
145 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
146 let bracepos = matchend(cline, '^\s*[)}]')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147 if bracepos != -1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
148 let synid = synIDattr(synID(v:lnum, bracepos, 0), "name")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
149 if synid == ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
150 \ || synid == "perlMatchStartEnd"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
151 \ || synid =~ '^perl\(Sub\|BEGINEND\|If\)Fold'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
152 let ind = ind - &sw
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
153 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
154 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
155 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
156 if line =~ '[{(]\s*\(#[^)}]*\)\=$'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
157 let ind = ind + &sw
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
158 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
159 if cline =~ '^\s*[)}]'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
160 let ind = ind - &sw
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
161 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
162 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
163
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
164 " Indent lines that begin with 'or' or 'and'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
165 if cline =~ '^\s*\(or\|and\)\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
166 if line !~ '^\s*\(or\|and\)\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
167 let ind = ind + &sw
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
168 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
169 elseif line =~ '^\s*\(or\|and\)\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
170 let ind = ind - &sw
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
171 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
172
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
173 return ind
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
174
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
175 endfunction
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
176
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
177 let &cpo = s:cpo_save
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
178 unlet s:cpo_save
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
179
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
180 " vim:ts=8:sts=2:sw=2