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