blob: 03368a7af3c48e12019a3d478ef61eab9716834b [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)
Riley Bruins0a083062024-06-03 20:40:45 +020011" 2024 May 24 by Riley Bruins <ribru17@gmail.com> ('commentstring')
Bram Moolenaar071d4272004-06-13 20:20:40 +000012
13if exists("b:did_ftplugin") | finish | endif
14let b:did_ftplugin = 1
15
16" Make sure the continuation lines below do not cause problems in
17" compatibility mode.
18let s:save_cpo = &cpo
19set cpo-=C
20
Bram Moolenaar543b7ef2013-06-01 14:50:56 +020021setlocal formatoptions-=t
22setlocal formatoptions+=crqol
Bram Moolenaare37d50a2008-08-06 17:06:04 +000023setlocal keywordprg=perldoc\ -f
Bram Moolenaar071d4272004-06-13 20:20:40 +000024
25setlocal comments=:#
Riley Bruins0a083062024-06-03 20:40:45 +020026setlocal commentstring=#\ %s
Bram Moolenaar071d4272004-06-13 20:20:40 +000027
Bram Moolenaar071d4272004-06-13 20:20:40 +000028" Provided by Ned Konz <ned at bike-nomad dot com>
29"---------------------------------------------
Bram Moolenaar83c465c2005-12-16 21:53:56 +000030setlocal include=\\<\\(use\\\|require\\)\\>
Bram Moolenaar8c1b8cb2022-06-14 17:41:28 +010031" '+' is removed to support plugins in Catalyst or DBIx::Class
32" where the leading plus indicates a fully-qualified module name.
33setlocal includeexpr=substitute(substitute(substitute(substitute(v:fname,'+','',''),'::','/','g'),'->\*','',''),'$','.pm','')
Bram Moolenaar071d4272004-06-13 20:20:40 +000034setlocal define=[^A-Za-z_]
Bram Moolenaar37c64c72017-09-19 22:06:03 +020035setlocal iskeyword+=:
Bram Moolenaar071d4272004-06-13 20:20:40 +000036
37" The following line changes a global variable but is necessary to make
Bram Moolenaar37c64c72017-09-19 22:06:03 +020038" gf and similar commands work. Thanks to Andrew Pimlott for pointing
Bram Moolenaar8c1b8cb2022-06-14 17:41:28 +010039" out the problem.
40let s:old_isfname = &isfname
Bram Moolenaar071d4272004-06-13 20:20:40 +000041set isfname+=:
Bram Moolenaar8c1b8cb2022-06-14 17:41:28 +010042let s:new_isfname = &isfname
43
44augroup perl_global_options
45 au!
46 exe "au BufEnter * if &filetype == 'perl' | let &isfname = '" . s:new_isfname . "' | endif"
47 exe "au BufLeave * if &filetype == 'perl' | let &isfname = '" . s:old_isfname . "' | endif"
48augroup END
49
50" Undo the stuff we changed.
51let b:undo_ftplugin = "setlocal fo< kp< com< cms< inc< inex< def< isk<" .
52 \ " | let &isfname = '" . s:old_isfname . "'"
53
54if get(g:, 'perl_fold', 0)
55 setlocal foldmethod=syntax
56 let b:undo_ftplugin .= " | setlocal fdm<"
57endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000058
59" Set this once, globally.
60if !exists("perlpath")
Christian Brabandtf7ac0ef2023-09-06 20:41:25 +020061 " safety check: don't execute perl binary by default
D. Ben Knoblecd8a3ea2023-11-04 05:11:17 -040062 if dist#vim#IsSafeExecutable('perl', 'perl')
Bram Moolenaar446cb832008-06-24 21:56:24 +000063 try
Bram Moolenaar071d4272004-06-13 20:20:40 +000064 if &shellxquote != '"'
65 let perlpath = system('perl -e "print join(q/,/,@INC)"')
66 else
67 let perlpath = system("perl -e 'print join(q/,/,@INC)'")
68 endif
69 let perlpath = substitute(perlpath,',.$',',,','')
Bram Moolenaar446cb832008-06-24 21:56:24 +000070 catch /E145:/
71 let perlpath = ".,,"
72 endtry
Bram Moolenaar071d4272004-06-13 20:20:40 +000073 else
74 " If we can't call perl to get its path, just default to using the
75 " current directory and the directory of the current file.
76 let perlpath = ".,,"
77 endif
78endif
79
Bram Moolenaar543b7ef2013-06-01 14:50:56 +020080" Append perlpath to the existing path value, if it is set. Since we don't
81" use += to do it because of the commas in perlpath, we have to handle the
82" global / local settings, too.
83if &l:path == ""
84 if &g:path == ""
85 let &l:path=perlpath
86 else
87 let &l:path=&g:path.",".perlpath
88 endif
89else
90 let &l:path=&l:path.",".perlpath
91endif
Bram Moolenaar8c1b8cb2022-06-14 17:41:28 +010092
93let b:undo_ftplugin .= " | setlocal pa<"
Bram Moolenaar071d4272004-06-13 20:20:40 +000094"---------------------------------------------
95
Bram Moolenaar8c1b8cb2022-06-14 17:41:28 +010096" Change the browse dialog to show mainly Perl-related files
97if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
98 let b:browsefilter = "Perl Source Files (*.pl)\t*.pl\n" .
99 \ "Perl Modules (*.pm)\t*.pm\n" .
Doug Kearns93197fd2024-01-14 20:59:02 +0100100 \ "Perl Documentation Files (*.pod)\t*.pod\n"
101 if has("win32")
102 let b:browsefilter .= "All Files (*.*)\t*\n"
103 else
104 let b:browsefilter .= "All Files (*)\t*\n"
105 endif
Bram Moolenaar8c1b8cb2022-06-14 17:41:28 +0100106 let b:undo_ftplugin .= " | unlet! b:browsefilter"
107endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000108
Bram Moolenaar8c1b8cb2022-06-14 17:41:28 +0100109" Proper matching for matchit plugin
110if exists("loaded_matchit") && !exists("b:match_words")
111 let b:match_skip = 's:comment\|string\|perlQQ\|perlShellCommand\|perlHereDoc\|perlSubstitution\|perlTranslation\|perlMatch\|perlFormatField'
112 let b:match_words = '\<if\>:\<elsif\>:\<else\>'
113 let b:undo_ftplugin .= " | unlet! b:match_words b:match_skip"
114endif
Bram Moolenaar543b7ef2013-06-01 14:50:56 +0200115
Bram Moolenaar071d4272004-06-13 20:20:40 +0000116" Restore the saved compatibility options.
117let &cpo = s:save_cpo
Bram Moolenaar8c1b8cb2022-06-14 17:41:28 +0100118unlet s:save_cpo s:old_isfname s:new_isfname