robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
db210dd2a4
master
1" Vim indent file 2" Language: Perl 6 3" Maintainer: vim-perl <vim-perl@googlegroups.com> (need to be subscribed to post) 4" 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 7" 2023 Aug 28 by Vim Project (undo_indent) 8" Contributors: Andy Lester <andy@petdance.com> 9" Hinrik Örn Sigurðsson <hinrik.sig@gmail.com> 10" 11" Adapted from indent/perl.vim by Rafael Garcia-Suarez <rgarciasuarez@free.fr> 12 13" Suggestions and improvements by : 14" Aaron J. Sherman (use syntax for hints) 15" Artem Chuprina (play nice with folding) 16" TODO: 17" This file still relies on stuff from the Perl 5 syntax file, which Perl 6 18" does not use. 19" 20" Things that are not or not properly indented (yet) : 21" - Continued statements 22" print "foo", 23" "bar"; 24" print "foo" 25" if bar(); 26" - Multiline regular expressions (m//x) 27" (The following probably needs modifying the perl syntax file) 28" - qw() lists 29" - Heredocs with terminators that don't match \I\i* 30 31" Only load this indent file when no other was loaded. 32if exists ( "b:did_indent" ) 33finish 34endif 35let b: did_indent = 1 36 37" Is syntax highlighting active ? 38let b: indent_use_syntax = has ( "syntax" ) 39 40setlocal indentexpr = GetRakuIndent () 41 42" we reset it first because the Perl 5 indent file might have been loaded due 43" to a .pl/pm file extension, and indent files don't clean up afterwards 44setlocal indentkeys & 45 46setlocal indentkeys += 0=,0),0],0>,0»,0=or,0=and 47if ! b: indent_use_syntax 48setlocal indentkeys += 0=EO 49endif 50 51let b: undo_indent = "setlocal indentexpr< indentkeys<" 52 53let s: cpo_save = & cpo 54set cpo -= C 55 56function ! GetRakuIndent () 57 58" Get the line to be indented 59let cline = getline ( v: lnum ) 60 61" Indent POD markers to column 0 62if cline =~ '^\s*=\L\@!' 63return 0 64endif 65 66" Get current syntax item at the line's first char 67let csynid = '' 68if b: indent_use_syntax 69let csynid = synIDattr ( synID ( v: lnum , 1 , 0 ), "name" ) 70endif 71 72" Don't reindent POD and heredocs 73if csynid =~ "^rakuPod" 74return indent ( v: lnum ) 75endif 76 77 78" Now get the indent of the previous perl line. 79 80" Find a non-blank line above the current line. 81let lnum = prevnonblank ( v: lnum - 1 ) 82" Hit the start of the file, use zero indent. 83if lnum == 0 84return 0 85endif 86let line = getline ( lnum ) 87let ind = indent ( lnum ) 88" Skip heredocs, POD, and comments on 1st column 89if b: indent_use_syntax 90let skippin = 2 91while skippin 92let synid = synIDattr ( synID ( lnum , 1 , 0 ), "name" ) 93if ( synid =~ "^rakuPod" || synid =~ "rakuComment" ) 94let lnum = prevnonblank ( lnum - 1 ) 95if lnum == 0 96return 0 97endif 98let line = getline ( lnum ) 99let ind = indent ( lnum ) 100let skippin = 1 101else 102let skippin = 0 103endif 104endwhile 105endif 106 107if line =~ '[<«\[{(]\s*\(#[^)}\]»>]*\)\=$' 108let ind = ind + & sw 109endif 110if cline =~ '^\s*[)}\]»>]' 111let ind = ind - & sw 112endif 113 114" Indent lines that begin with 'or' or 'and' 115if cline =~ '^\s*\(or\|and\)\>' 116if line !~ '^\s*\(or\|and\)\>' 117let ind = ind + & sw 118endif 119elseif line =~ '^\s*\(or\|and\)\>' 120let ind = ind - & sw 121endif 122 123return ind 124 125endfunction 126 127let & cpo = s: cpo_save 128unlet s: cpo_save 129 130" vim:ts=8:sts=4:sw=4:expandtab:ft=vim