blob: 8561c8c58c4545ac9629f78b1593c83eb3fb83e1 [file] [log] [blame]
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001" Vim indent file
Bram Moolenaar543b7ef2013-06-01 14:50:56 +02002" 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
Bram Moolenaar3ec574f2017-06-13 18:12:01 +02006" Last Change: 2017 Jun 13
Bram Moolenaar543b7ef2013-06-01 14:50:56 +02007" Contributors: Andy Lester <andy@petdance.com>
8" Hinrik Örn Sigurðsson <hinrik.sig@gmail.com>
Bram Moolenaar00a927d2010-05-14 23:24:24 +02009"
Bram Moolenaar543b7ef2013-06-01 14:50:56 +020010" Adapted from indent/perl.vim by Rafael Garcia-Suarez <rgarciasuarez@free.fr>
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011
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=GetPerl6Indent()
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
Bram Moolenaar00a927d2010-05-14 23:24:24 +020050let s:cpo_save = &cpo
51set cpo-=C
52
Bram Moolenaar543b7ef2013-06-01 14:50:56 +020053function! GetPerl6Indent()
Bram Moolenaar00a927d2010-05-14 23:24:24 +020054
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 " Don't reindent coments on first column
64 if cline =~ '^#'
65 return 0
66 endif
67
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
73
74 " Don't reindent POD and heredocs
75 if csynid =~ "^p6Pod"
76 return indent(v:lnum)
77 endif
78
79
80 " Now get the indent of the previous perl line.
81
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
108
109 if line =~ '[<«\[{(]\s*\(#[^)}\]»>]*\)\=$'
Bram Moolenaar3ec574f2017-06-13 18:12:01 +0200110 let ind = ind + shiftwidth()
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200111 endif
112 if cline =~ '^\s*[)}\]»>]'
Bram Moolenaar3ec574f2017-06-13 18:12:01 +0200113 let ind = ind - shiftwidth()
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200114 endif
115
116 " Indent lines that begin with 'or' or 'and'
117 if cline =~ '^\s*\(or\|and\)\>'
118 if line !~ '^\s*\(or\|and\)\>'
Bram Moolenaar3ec574f2017-06-13 18:12:01 +0200119 let ind = ind + shiftwidth()
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200120 endif
121 elseif line =~ '^\s*\(or\|and\)\>'
Bram Moolenaar3ec574f2017-06-13 18:12:01 +0200122 let ind = ind - shiftwidth()
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200123 endif
124
125 return ind
126
127endfunction
128
129let &cpo = s:cpo_save
130unlet s:cpo_save
131
132" vim:ts=8:sts=4:sw=4:expandtab:ft=vim