blob: c63bd3f9c70c0cb5c2edbc75db5eb24a25deb228 [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)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010
11if exists("b:did_ftplugin") | finish | endif
12let b:did_ftplugin = 1
13
14" Make sure the continuation lines below do not cause problems in
15" compatibility mode.
16let s:save_cpo = &cpo
17set cpo-=C
18
Bram Moolenaar543b7ef2013-06-01 14:50:56 +020019setlocal formatoptions-=t
20setlocal formatoptions+=crqol
Bram Moolenaare37d50a2008-08-06 17:06:04 +000021setlocal keywordprg=perldoc\ -f
Bram Moolenaar071d4272004-06-13 20:20:40 +000022
23setlocal comments=:#
24setlocal commentstring=#%s
25
Bram Moolenaar071d4272004-06-13 20:20:40 +000026" Provided by Ned Konz <ned at bike-nomad dot com>
27"---------------------------------------------
Bram Moolenaar83c465c2005-12-16 21:53:56 +000028setlocal include=\\<\\(use\\\|require\\)\\>
Bram Moolenaar8c1b8cb2022-06-14 17:41:28 +010029" '+' is removed to support plugins in Catalyst or DBIx::Class
30" where the leading plus indicates a fully-qualified module name.
31setlocal includeexpr=substitute(substitute(substitute(substitute(v:fname,'+','',''),'::','/','g'),'->\*','',''),'$','.pm','')
Bram Moolenaar071d4272004-06-13 20:20:40 +000032setlocal define=[^A-Za-z_]
Bram Moolenaar37c64c72017-09-19 22:06:03 +020033setlocal iskeyword+=:
Bram Moolenaar071d4272004-06-13 20:20:40 +000034
35" The following line changes a global variable but is necessary to make
Bram Moolenaar37c64c72017-09-19 22:06:03 +020036" gf and similar commands work. Thanks to Andrew Pimlott for pointing
Bram Moolenaar8c1b8cb2022-06-14 17:41:28 +010037" out the problem.
38let s:old_isfname = &isfname
Bram Moolenaar071d4272004-06-13 20:20:40 +000039set isfname+=:
Bram Moolenaar8c1b8cb2022-06-14 17:41:28 +010040let s:new_isfname = &isfname
41
42augroup perl_global_options
43 au!
44 exe "au BufEnter * if &filetype == 'perl' | let &isfname = '" . s:new_isfname . "' | endif"
45 exe "au BufLeave * if &filetype == 'perl' | let &isfname = '" . s:old_isfname . "' | endif"
46augroup END
47
48" Undo the stuff we changed.
49let b:undo_ftplugin = "setlocal fo< kp< com< cms< inc< inex< def< isk<" .
50 \ " | let &isfname = '" . s:old_isfname . "'"
51
52if get(g:, 'perl_fold', 0)
53 setlocal foldmethod=syntax
54 let b:undo_ftplugin .= " | setlocal fdm<"
55endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000056
57" Set this once, globally.
58if !exists("perlpath")
Christian Brabandtf7ac0ef2023-09-06 20:41:25 +020059 " safety check: don't execute perl binary by default
D. Ben Knoblecd8a3ea2023-11-04 05:11:17 -040060 if dist#vim#IsSafeExecutable('perl', 'perl')
Bram Moolenaar446cb832008-06-24 21:56:24 +000061 try
Bram Moolenaar071d4272004-06-13 20:20:40 +000062 if &shellxquote != '"'
63 let perlpath = system('perl -e "print join(q/,/,@INC)"')
64 else
65 let perlpath = system("perl -e 'print join(q/,/,@INC)'")
66 endif
67 let perlpath = substitute(perlpath,',.$',',,','')
Bram Moolenaar446cb832008-06-24 21:56:24 +000068 catch /E145:/
69 let perlpath = ".,,"
70 endtry
Bram Moolenaar071d4272004-06-13 20:20:40 +000071 else
72 " If we can't call perl to get its path, just default to using the
73 " current directory and the directory of the current file.
74 let perlpath = ".,,"
75 endif
76endif
77
Bram Moolenaar543b7ef2013-06-01 14:50:56 +020078" Append perlpath to the existing path value, if it is set. Since we don't
79" use += to do it because of the commas in perlpath, we have to handle the
80" global / local settings, too.
81if &l:path == ""
82 if &g:path == ""
83 let &l:path=perlpath
84 else
85 let &l:path=&g:path.",".perlpath
86 endif
87else
88 let &l:path=&l:path.",".perlpath
89endif
Bram Moolenaar8c1b8cb2022-06-14 17:41:28 +010090
91let b:undo_ftplugin .= " | setlocal pa<"
Bram Moolenaar071d4272004-06-13 20:20:40 +000092"---------------------------------------------
93
Bram Moolenaar8c1b8cb2022-06-14 17:41:28 +010094" Change the browse dialog to show mainly Perl-related files
95if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
96 let b:browsefilter = "Perl Source Files (*.pl)\t*.pl\n" .
97 \ "Perl Modules (*.pm)\t*.pm\n" .
98 \ "Perl Documentation Files (*.pod)\t*.pod\n" .
99 \ "All Files (*.*)\t*.*\n"
100 let b:undo_ftplugin .= " | unlet! b:browsefilter"
101endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000102
Bram Moolenaar8c1b8cb2022-06-14 17:41:28 +0100103" Proper matching for matchit plugin
104if exists("loaded_matchit") && !exists("b:match_words")
105 let b:match_skip = 's:comment\|string\|perlQQ\|perlShellCommand\|perlHereDoc\|perlSubstitution\|perlTranslation\|perlMatch\|perlFormatField'
106 let b:match_words = '\<if\>:\<elsif\>:\<else\>'
107 let b:undo_ftplugin .= " | unlet! b:match_words b:match_skip"
108endif
Bram Moolenaar543b7ef2013-06-01 14:50:56 +0200109
Bram Moolenaar071d4272004-06-13 20:20:40 +0000110" Restore the saved compatibility options.
111let &cpo = s:save_cpo
Bram Moolenaar8c1b8cb2022-06-14 17:41:28 +0100112unlet s:save_cpo s:old_isfname s:new_isfname