blob: 8c6a80eb4f9454eb9510661ec0f847277f0ac293 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim filetype plugin file
Bram Moolenaar543b7ef2013-06-01 14:50:56 +02002" Language: Perl
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
Bram Moolenaar8c1b8cb2022-06-14 17:41:28 +01006" License: Vim License (see :help license)
7" Last Change: 2021 Nov 10
dkearns4e554d22023-09-09 03:16:03 +10008" 2023 Sep 07 by Vim Project (safety check: don't execute perl
9" from current directory)
Doug Kearns93197fd2024-01-14 20:59:02 +010010" 2024 Jan 14 by Vim Project (browsefilter)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011
12if exists("b:did_ftplugin") | finish | endif
13let b:did_ftplugin = 1
14
15" Make sure the continuation lines below do not cause problems in
16" compatibility mode.
17let s:save_cpo = &cpo
18set cpo-=C
19
Bram Moolenaar543b7ef2013-06-01 14:50:56 +020020setlocal formatoptions-=t
21setlocal formatoptions+=crqol
Bram Moolenaare37d50a2008-08-06 17:06:04 +000022setlocal keywordprg=perldoc\ -f
Bram Moolenaar071d4272004-06-13 20:20:40 +000023
24setlocal comments=:#
25setlocal commentstring=#%s
26
Bram Moolenaar071d4272004-06-13 20:20:40 +000027" Provided by Ned Konz <ned at bike-nomad dot com>
28"---------------------------------------------
Bram Moolenaar83c465c2005-12-16 21:53:56 +000029setlocal include=\\<\\(use\\\|require\\)\\>
Bram Moolenaar8c1b8cb2022-06-14 17:41:28 +010030" '+' is removed to support plugins in Catalyst or DBIx::Class
31" where the leading plus indicates a fully-qualified module name.
32setlocal includeexpr=substitute(substitute(substitute(substitute(v:fname,'+','',''),'::','/','g'),'->\*','',''),'$','.pm','')
Bram Moolenaar071d4272004-06-13 20:20:40 +000033setlocal define=[^A-Za-z_]
Bram Moolenaar37c64c72017-09-19 22:06:03 +020034setlocal iskeyword+=:
Bram Moolenaar071d4272004-06-13 20:20:40 +000035
36" The following line changes a global variable but is necessary to make
Bram Moolenaar37c64c72017-09-19 22:06:03 +020037" gf and similar commands work. Thanks to Andrew Pimlott for pointing
Bram Moolenaar8c1b8cb2022-06-14 17:41:28 +010038" out the problem.
39let s:old_isfname = &isfname
Bram Moolenaar071d4272004-06-13 20:20:40 +000040set isfname+=:
Bram Moolenaar8c1b8cb2022-06-14 17:41:28 +010041let s:new_isfname = &isfname
42
43augroup perl_global_options
44 au!
45 exe "au BufEnter * if &filetype == 'perl' | let &isfname = '" . s:new_isfname . "' | endif"
46 exe "au BufLeave * if &filetype == 'perl' | let &isfname = '" . s:old_isfname . "' | endif"
47augroup END
48
49" Undo the stuff we changed.
50let b:undo_ftplugin = "setlocal fo< kp< com< cms< inc< inex< def< isk<" .
51 \ " | let &isfname = '" . s:old_isfname . "'"
52
53if get(g:, 'perl_fold', 0)
54 setlocal foldmethod=syntax
55 let b:undo_ftplugin .= " | setlocal fdm<"
56endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000057
58" Set this once, globally.
59if !exists("perlpath")
Christian Brabandtf7ac0ef2023-09-06 20:41:25 +020060 " safety check: don't execute perl binary by default
D. Ben Knoblecd8a3ea2023-11-04 05:11:17 -040061 if dist#vim#IsSafeExecutable('perl', 'perl')
Bram Moolenaar446cb832008-06-24 21:56:24 +000062 try
Bram Moolenaar071d4272004-06-13 20:20:40 +000063 if &shellxquote != '"'
64 let perlpath = system('perl -e "print join(q/,/,@INC)"')
65 else
66 let perlpath = system("perl -e 'print join(q/,/,@INC)'")
67 endif
68 let perlpath = substitute(perlpath,',.$',',,','')
Bram Moolenaar446cb832008-06-24 21:56:24 +000069 catch /E145:/
70 let perlpath = ".,,"
71 endtry
Bram Moolenaar071d4272004-06-13 20:20:40 +000072 else
73 " If we can't call perl to get its path, just default to using the
74 " current directory and the directory of the current file.
75 let perlpath = ".,,"
76 endif
77endif
78
Bram Moolenaar543b7ef2013-06-01 14:50:56 +020079" Append perlpath to the existing path value, if it is set. Since we don't
80" use += to do it because of the commas in perlpath, we have to handle the
81" global / local settings, too.
82if &l:path == ""
83 if &g:path == ""
84 let &l:path=perlpath
85 else
86 let &l:path=&g:path.",".perlpath
87 endif
88else
89 let &l:path=&l:path.",".perlpath
90endif
Bram Moolenaar8c1b8cb2022-06-14 17:41:28 +010091
92let b:undo_ftplugin .= " | setlocal pa<"
Bram Moolenaar071d4272004-06-13 20:20:40 +000093"---------------------------------------------
94
Bram Moolenaar8c1b8cb2022-06-14 17:41:28 +010095" Change the browse dialog to show mainly Perl-related files
96if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
97 let b:browsefilter = "Perl Source Files (*.pl)\t*.pl\n" .
98 \ "Perl Modules (*.pm)\t*.pm\n" .
Doug Kearns93197fd2024-01-14 20:59:02 +010099 \ "Perl Documentation Files (*.pod)\t*.pod\n"
100 if has("win32")
101 let b:browsefilter .= "All Files (*.*)\t*\n"
102 else
103 let b:browsefilter .= "All Files (*)\t*\n"
104 endif
Bram Moolenaar8c1b8cb2022-06-14 17:41:28 +0100105 let b:undo_ftplugin .= " | unlet! b:browsefilter"
106endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000107
Bram Moolenaar8c1b8cb2022-06-14 17:41:28 +0100108" Proper matching for matchit plugin
109if exists("loaded_matchit") && !exists("b:match_words")
110 let b:match_skip = 's:comment\|string\|perlQQ\|perlShellCommand\|perlHereDoc\|perlSubstitution\|perlTranslation\|perlMatch\|perlFormatField'
111 let b:match_words = '\<if\>:\<elsif\>:\<else\>'
112 let b:undo_ftplugin .= " | unlet! b:match_words b:match_skip"
113endif
Bram Moolenaar543b7ef2013-06-01 14:50:56 +0200114
Bram Moolenaar071d4272004-06-13 20:20:40 +0000115" Restore the saved compatibility options.
116let &cpo = s:save_cpo
Bram Moolenaar8c1b8cb2022-06-14 17:41:28 +0100117unlet s:save_cpo s:old_isfname s:new_isfname