blob: 3f9b49ec7723a5df15cd3626c0eadd1291a2ee35 [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>
Bram Moolenaar2c7f8c52020-04-20 19:52:53 +02004" Homepage: https://github.com/vim-perl/vim-perl
5" Bugs/requests: https://github.com/vim-perl/vim-perl/issues
6" Last Change: 2020 Apr 15
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
Bram Moolenaar11e3c5b2021-04-21 18:09:37 +020039setlocal indentexpr=GetRakuIndent()
Bram Moolenaar00a927d2010-05-14 23:24:24 +020040
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 Moolenaar11e3c5b2021-04-21 18:09:37 +020053function! GetRakuIndent()
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
Bram Moolenaar00a927d2010-05-14 23:24:24 +020063 " Get current syntax item at the line's first char
64 let csynid = ''
65 if b:indent_use_syntax
66 let csynid = synIDattr(synID(v:lnum,1,0),"name")
67 endif
68
69 " Don't reindent POD and heredocs
Bram Moolenaar11e3c5b2021-04-21 18:09:37 +020070 if csynid =~ "^rakuPod"
Bram Moolenaar00a927d2010-05-14 23:24:24 +020071 return indent(v:lnum)
72 endif
73
74
75 " Now get the indent of the previous perl line.
76
77 " Find a non-blank line above the current line.
78 let lnum = prevnonblank(v:lnum - 1)
79 " Hit the start of the file, use zero indent.
80 if lnum == 0
81 return 0
82 endif
83 let line = getline(lnum)
84 let ind = indent(lnum)
85 " Skip heredocs, POD, and comments on 1st column
86 if b:indent_use_syntax
87 let skippin = 2
88 while skippin
89 let synid = synIDattr(synID(lnum,1,0),"name")
Bram Moolenaar11e3c5b2021-04-21 18:09:37 +020090 if (synid =~ "^rakuPod" || synid =~ "rakuComment")
Bram Moolenaar00a927d2010-05-14 23:24:24 +020091 let lnum = prevnonblank(lnum - 1)
92 if lnum == 0
93 return 0
94 endif
95 let line = getline(lnum)
96 let ind = indent(lnum)
97 let skippin = 1
98 else
99 let skippin = 0
100 endif
101 endwhile
102 endif
103
104 if line =~ '[<«\[{(]\s*\(#[^)}\]»>]*\)\=$'
Bram Moolenaar11e3c5b2021-04-21 18:09:37 +0200105 let ind = ind + &sw
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200106 endif
107 if cline =~ '^\s*[)}\]»>]'
Bram Moolenaar11e3c5b2021-04-21 18:09:37 +0200108 let ind = ind - &sw
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200109 endif
110
111 " Indent lines that begin with 'or' or 'and'
112 if cline =~ '^\s*\(or\|and\)\>'
113 if line !~ '^\s*\(or\|and\)\>'
Bram Moolenaar11e3c5b2021-04-21 18:09:37 +0200114 let ind = ind + &sw
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200115 endif
116 elseif line =~ '^\s*\(or\|and\)\>'
Bram Moolenaar11e3c5b2021-04-21 18:09:37 +0200117 let ind = ind - &sw
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200118 endif
119
120 return ind
121
122endfunction
123
124let &cpo = s:cpo_save
125unlet s:cpo_save
126
127" vim:ts=8:sts=4:sw=4:expandtab:ft=vim