comparison runtime/indent/perl.vim @ 29193:1e9e9d89f0ee

Update runtime files Commit: https://github.com/vim/vim/commit/d592deb336523a5448779ee3d4bba80334cff1f7 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Jun 17 15:42:40 2022 +0100 Update runtime files
author Bram Moolenaar <Bram@vim.org>
date Fri, 17 Jun 2022 16:45:04 +0200
parents d1fe80fb35e6
children d84610677553
comparison
equal deleted inserted replaced
29192:e4488cf0eff9 29193:1e9e9d89f0ee
4 " Homepage: https://github.com/vim-perl/vim-perl 4 " Homepage: https://github.com/vim-perl/vim-perl
5 " Bugs/requests: https://github.com/vim-perl/vim-perl/issues 5 " Bugs/requests: https://github.com/vim-perl/vim-perl/issues
6 " License: Vim License (see :help license) 6 " License: Vim License (see :help license)
7 " Last Change: 2021 Sep 24 7 " Last Change: 2021 Sep 24
8 8
9 if exists("b:did_ftplugin") | finish | endif 9 " Suggestions and improvements by :
10 let b:did_ftplugin = 1 10 " Aaron J. Sherman (use syntax for hints)
11 " Artem Chuprina (play nice with folding)
11 12
12 " Make sure the continuation lines below do not cause problems in 13 " TODO things that are not or not properly indented (yet) :
13 " compatibility mode. 14 " - Continued statements
14 let s:save_cpo = &cpo 15 " print "foo",
16 " "bar";
17 " print "foo"
18 " if bar();
19 " - Multiline regular expressions (m//x)
20 " (The following probably needs modifying the perl syntax file)
21 " - qw() lists
22 " - Heredocs with terminators that don't match \I\i*
23
24 " Only load this indent file when no other was loaded.
25 if exists("b:did_indent")
26 finish
27 endif
28 let b:did_indent = 1
29
30 " Is syntax highlighting active ?
31 let b:indent_use_syntax = has("syntax")
32
33 setlocal indentexpr=GetPerlIndent()
34 setlocal indentkeys+=0=,0),0],0=or,0=and
35 if !b:indent_use_syntax
36 setlocal indentkeys+=0=EO
37 endif
38
39 let b:undo_indent = "setl inde< indk<"
40
41 let s:cpo_save = &cpo
15 set cpo-=C 42 set cpo-=C
16 43
17 setlocal formatoptions-=t 44 function! GetPerlIndent()
18 setlocal formatoptions+=crqol
19 setlocal keywordprg=perldoc\ -f
20 45
21 setlocal comments=:# 46 " Get the line to be indented
22 setlocal commentstring=#%s 47 let cline = getline(v:lnum)
23 48
24 " Provided by Ned Konz <ned at bike-nomad dot com> 49 " Indent POD markers to column 0
25 "--------------------------------------------- 50 if cline =~ '^\s*=\L\@!'
26 setlocal include=\\<\\(use\\\|require\\)\\> 51 return 0
27 " '+' is removed to support plugins in Catalyst or DBIx::Class 52 endif
28 " where the leading plus indicates a fully-qualified module name.
29 setlocal includeexpr=substitute(substitute(substitute(substitute(v:fname,'+','',''),'::','/','g'),'->\*','',''),'$','.pm','')
30 setlocal define=[^A-Za-z_]
31 setlocal iskeyword+=:
32 53
33 " The following line changes a global variable but is necessary to make 54 " Get current syntax item at the line's first char
34 " gf and similar commands work. Thanks to Andrew Pimlott for pointing 55 let csynid = ''
35 " out the problem. 56 if b:indent_use_syntax
36 let s:old_isfname = &isfname 57 let csynid = synIDattr(synID(v:lnum,1,0),"name")
37 set isfname+=: 58 endif
38 let s:new_isfname = &isfname
39 59
40 augroup perl_global_options 60 " Don't reindent POD and heredocs
41 au! 61 if csynid == "perlPOD" || csynid == "perlHereDoc" || csynid =~ "^pod"
42 exe "au BufEnter * if &filetype == 'perl' | let &isfname = '" . s:new_isfname . "' | endif" 62 return indent(v:lnum)
43 exe "au BufLeave * if &filetype == 'perl' | let &isfname = '" . s:old_isfname . "' | endif" 63 endif
44 augroup END
45 64
46 " Undo the stuff we changed. 65 " Indent end-of-heredocs markers to column 0
47 let b:undo_ftplugin = "setlocal fo< kp< com< cms< inc< inex< def< isk<" . 66 if b:indent_use_syntax
48 \ " | let &isfname = '" . s:old_isfname . "'" 67 " Assumes that an end-of-heredoc marker matches \I\i* to avoid
68 " confusion with other types of strings
69 if csynid == "perlStringStartEnd" && cline =~ '^\I\i*$'
70 return 0
71 endif
72 else
73 " Without syntax hints, assume that end-of-heredocs markers begin with EO
74 if cline =~ '^\s*EO'
75 return 0
76 endif
77 endif
49 78
50 if get(g:, 'perl_fold', 0) 79 " Now get the indent of the previous perl line.
51 setlocal foldmethod=syntax
52 let b:undo_ftplugin .= " | setlocal fdm<"
53 endif
54 80
55 " Set this once, globally. 81 " Find a non-blank line above the current line.
56 if !exists("perlpath") 82 let lnum = prevnonblank(v:lnum - 1)
57 if executable("perl") 83 " Hit the start of the file, use zero indent.
58 try 84 if lnum == 0
59 if &shellxquote != '"' 85 return 0
60 let perlpath = system('perl -e "print join(q/,/,@INC)"') 86 endif
61 else 87 let line = getline(lnum)
62 let perlpath = system("perl -e 'print join(q/,/,@INC)'") 88 let ind = indent(lnum)
63 endif 89 " Skip heredocs, POD, and comments on 1st column
64 let perlpath = substitute(perlpath,',.$',',,','') 90 if b:indent_use_syntax
65 catch /E145:/ 91 let skippin = 2
66 let perlpath = ".,," 92 while skippin
67 endtry 93 let synid = synIDattr(synID(lnum,1,0),"name")
94 if (synid == "perlStringStartEnd" && line =~ '^\I\i*$')
95 \ || (skippin != 2 && synid == "perlPOD")
96 \ || (skippin != 2 && synid == "perlHereDoc")
97 \ || synid == "perlComment"
98 \ || synid =~ "^pod"
99 let lnum = prevnonblank(lnum - 1)
100 if lnum == 0
101 return 0
102 endif
103 let line = getline(lnum)
104 let ind = indent(lnum)
105 let skippin = 1
106 else
107 let skippin = 0
108 endif
109 endwhile
68 else 110 else
69 " If we can't call perl to get its path, just default to using the 111 if line =~ "^EO"
70 " current directory and the directory of the current file. 112 let lnum = search("<<[\"']\\=EO", "bW")
71 let perlpath = ".,," 113 let line = getline(lnum)
114 let ind = indent(lnum)
115 endif
72 endif 116 endif
73 endif
74 117
75 " Append perlpath to the existing path value, if it is set. Since we don't 118 " Indent blocks enclosed by {}, (), or []
76 " use += to do it because of the commas in perlpath, we have to handle the 119 if b:indent_use_syntax
77 " global / local settings, too. 120 " Find a real opening brace
78 if &l:path == "" 121 " NOTE: Unlike Perl character classes, we do NOT need to escape the
79 if &g:path == "" 122 " closing brackets with a backslash. Doing so just puts a backslash
80 let &l:path=perlpath 123 " in the character class and causes sorrow. Instead, put the closing
124 " bracket as the first character in the class.
125 let braceclass = '[][(){}]'
126 let bracepos = match(line, braceclass, matchend(line, '^\s*[])}]'))
127 while bracepos != -1
128 let synid = synIDattr(synID(lnum, bracepos + 1, 0), "name")
129 " If the brace is highlighted in one of those groups, indent it.
130 " 'perlHereDoc' is here only to handle the case '&foo(<<EOF)'.
131 if synid == ""
132 \ || synid == "perlMatchStartEnd"
133 \ || synid == "perlHereDoc"
134 \ || synid == "perlBraces"
135 \ || synid == "perlStatementIndirObj"
136 \ || synid =~ "^perlFiledescStatement"
137 \ || synid =~ '^perl\(Sub\|Block\|Package\)Fold'
138 let brace = strpart(line, bracepos, 1)
139 if brace == '(' || brace == '{' || brace == '['
140 let ind = ind + shiftwidth()
141 else
142 let ind = ind - shiftwidth()
143 endif
144 endif
145 let bracepos = match(line, braceclass, bracepos + 1)
146 endwhile
147 let bracepos = matchend(cline, '^\s*[])}]')
148 if bracepos != -1
149 let synid = synIDattr(synID(v:lnum, bracepos, 0), "name")
150 if synid == ""
151 \ || synid == "perlMatchStartEnd"
152 \ || synid == "perlBraces"
153 \ || synid == "perlStatementIndirObj"
154 \ || synid =~ '^perl\(Sub\|Block\|Package\)Fold'
155 let ind = ind - shiftwidth()
156 endif
157 endif
81 else 158 else
82 let &l:path=&g:path.",".perlpath 159 if line =~ '[{[(]\s*\(#[^])}]*\)\=$'
160 let ind = ind + shiftwidth()
161 endif
162 if cline =~ '^\s*[])}]'
163 let ind = ind - shiftwidth()
164 endif
83 endif 165 endif
84 else
85 let &l:path=&l:path.",".perlpath
86 endif
87 166
88 let b:undo_ftplugin .= " | setlocal pa<" 167 " Indent lines that begin with 'or' or 'and'
89 "--------------------------------------------- 168 if cline =~ '^\s*\(or\|and\)\>'
169 if line !~ '^\s*\(or\|and\)\>'
170 let ind = ind + shiftwidth()
171 endif
172 elseif line =~ '^\s*\(or\|and\)\>'
173 let ind = ind - shiftwidth()
174 endif
90 175
91 " Change the browse dialog to show mainly Perl-related files 176 return ind
92 if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
93 let b:browsefilter = "Perl Source Files (*.pl)\t*.pl\n" .
94 \ "Perl Modules (*.pm)\t*.pm\n" .
95 \ "Perl Documentation Files (*.pod)\t*.pod\n" .
96 \ "All Files (*.*)\t*.*\n"
97 let b:undo_ftplugin .= " | unlet! b:browsefilter"
98 endif
99 177
100 " Proper matching for matchit plugin 178 endfunction
101 if exists("loaded_matchit") && !exists("b:match_words")
102 let b:match_skip = 's:comment\|string\|perlQQ\|perlShellCommand\|perlHereDoc\|perlSubstitution\|perlTranslation\|perlMatch\|perlFormatField'
103 let b:match_words = '\<if\>:\<elsif\>:\<else\>'
104 let b:undo_ftplugin .= " | unlet! b:match_words b:match_skip"
105 endif
106 179
107 " Restore the saved compatibility options. 180 let &cpo = s:cpo_save
108 let &cpo = s:save_cpo 181 unlet s:cpo_save
109 unlet s:save_cpo s:old_isfname s:new_isfname 182
183 " vim:ts=8:sts=4:sw=4:expandtab:ft=vim