Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 1 | " Vim indent file |
Bram Moolenaar | 543b7ef | 2013-06-01 14:50:56 +0200 | [diff] [blame] | 2 | " 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 Moolenaar | 3ec574f | 2017-06-13 18:12:01 +0200 | [diff] [blame] | 6 | " Last Change: 2017 Jun 13 |
Bram Moolenaar | 543b7ef | 2013-06-01 14:50:56 +0200 | [diff] [blame] | 7 | " Contributors: Andy Lester <andy@petdance.com> |
| 8 | " Hinrik Örn Sigurðsson <hinrik.sig@gmail.com> |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 9 | " |
Bram Moolenaar | 543b7ef | 2013-06-01 14:50:56 +0200 | [diff] [blame] | 10 | " Adapted from indent/perl.vim by Rafael Garcia-Suarez <rgarciasuarez@free.fr> |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 11 | |
| 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. |
| 31 | if exists("b:did_indent") |
| 32 | finish |
| 33 | endif |
| 34 | let b:did_indent = 1 |
| 35 | |
| 36 | " Is syntax highlighting active ? |
| 37 | let b:indent_use_syntax = has("syntax") |
| 38 | |
| 39 | setlocal 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 |
| 43 | setlocal indentkeys& |
| 44 | |
| 45 | setlocal indentkeys+=0=,0),0],0>,0»,0=or,0=and |
| 46 | if !b:indent_use_syntax |
| 47 | setlocal indentkeys+=0=EO |
| 48 | endif |
| 49 | |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 50 | let s:cpo_save = &cpo |
| 51 | set cpo-=C |
| 52 | |
Bram Moolenaar | 543b7ef | 2013-06-01 14:50:56 +0200 | [diff] [blame] | 53 | function! GetPerl6Indent() |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 54 | |
| 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 Moolenaar | 3ec574f | 2017-06-13 18:12:01 +0200 | [diff] [blame] | 110 | let ind = ind + shiftwidth() |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 111 | endif |
| 112 | if cline =~ '^\s*[)}\]»>]' |
Bram Moolenaar | 3ec574f | 2017-06-13 18:12:01 +0200 | [diff] [blame] | 113 | let ind = ind - shiftwidth() |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 114 | endif |
| 115 | |
| 116 | " Indent lines that begin with 'or' or 'and' |
| 117 | if cline =~ '^\s*\(or\|and\)\>' |
| 118 | if line !~ '^\s*\(or\|and\)\>' |
Bram Moolenaar | 3ec574f | 2017-06-13 18:12:01 +0200 | [diff] [blame] | 119 | let ind = ind + shiftwidth() |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 120 | endif |
| 121 | elseif line =~ '^\s*\(or\|and\)\>' |
Bram Moolenaar | 3ec574f | 2017-06-13 18:12:01 +0200 | [diff] [blame] | 122 | let ind = ind - shiftwidth() |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 123 | endif |
| 124 | |
| 125 | return ind |
| 126 | |
| 127 | endfunction |
| 128 | |
| 129 | let &cpo = s:cpo_save |
| 130 | unlet s:cpo_save |
| 131 | |
| 132 | " vim:ts=8:sts=4:sw=4:expandtab:ft=vim |