blob: 4361097f3297c915774fe92ec174460c1150580f [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
Bram Moolenaar071d4272004-06-13 20:20:40 +00008
9if exists("b:did_ftplugin") | finish | endif
10let b:did_ftplugin = 1
11
12" Make sure the continuation lines below do not cause problems in
13" compatibility mode.
14let s:save_cpo = &cpo
15set cpo-=C
16
Bram Moolenaar543b7ef2013-06-01 14:50:56 +020017setlocal formatoptions-=t
18setlocal formatoptions+=crqol
Bram Moolenaare37d50a2008-08-06 17:06:04 +000019setlocal keywordprg=perldoc\ -f
Bram Moolenaar071d4272004-06-13 20:20:40 +000020
21setlocal comments=:#
22setlocal commentstring=#%s
23
Bram Moolenaar071d4272004-06-13 20:20:40 +000024" Provided by Ned Konz <ned at bike-nomad dot com>
25"---------------------------------------------
Bram Moolenaar83c465c2005-12-16 21:53:56 +000026setlocal include=\\<\\(use\\\|require\\)\\>
Bram Moolenaar8c1b8cb2022-06-14 17:41:28 +010027" '+' is removed to support plugins in Catalyst or DBIx::Class
28" where the leading plus indicates a fully-qualified module name.
29setlocal includeexpr=substitute(substitute(substitute(substitute(v:fname,'+','',''),'::','/','g'),'->\*','',''),'$','.pm','')
Bram Moolenaar071d4272004-06-13 20:20:40 +000030setlocal define=[^A-Za-z_]
Bram Moolenaar37c64c72017-09-19 22:06:03 +020031setlocal iskeyword+=:
Bram Moolenaar071d4272004-06-13 20:20:40 +000032
33" The following line changes a global variable but is necessary to make
Bram Moolenaar37c64c72017-09-19 22:06:03 +020034" gf and similar commands work. Thanks to Andrew Pimlott for pointing
Bram Moolenaar8c1b8cb2022-06-14 17:41:28 +010035" out the problem.
36let s:old_isfname = &isfname
Bram Moolenaar071d4272004-06-13 20:20:40 +000037set isfname+=:
Bram Moolenaar8c1b8cb2022-06-14 17:41:28 +010038let s:new_isfname = &isfname
39
40augroup perl_global_options
41 au!
42 exe "au BufEnter * if &filetype == 'perl' | let &isfname = '" . s:new_isfname . "' | endif"
43 exe "au BufLeave * if &filetype == 'perl' | let &isfname = '" . s:old_isfname . "' | endif"
44augroup END
45
46" Undo the stuff we changed.
47let b:undo_ftplugin = "setlocal fo< kp< com< cms< inc< inex< def< isk<" .
48 \ " | let &isfname = '" . s:old_isfname . "'"
49
50if get(g:, 'perl_fold', 0)
51 setlocal foldmethod=syntax
52 let b:undo_ftplugin .= " | setlocal fdm<"
53endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000054
55" Set this once, globally.
56if !exists("perlpath")
Christian Brabandt816fbcc2023-08-31 23:52:30 +020057 " safety check: don't execute perl from current directory
Anton Sharonov67c951d2023-09-05 21:03:27 +020058 let s:tmp_cwd = getcwd()
59 if executable("perl") && (fnamemodify(exepath("perl"), ":p:h") != s:tmp_cwd
60 \ || (index(split($PATH,has("win32")? ';' : ':'), s:tmp_cwd) != -1 && s:tmp_cwd != '.'))
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
Anton Sharonov67c951d2023-09-05 21:03:27 +020076 unlet s:tmp_cwd
Bram Moolenaar071d4272004-06-13 20:20:40 +000077endif
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" .
99 \ "Perl Documentation Files (*.pod)\t*.pod\n" .
100 \ "All Files (*.*)\t*.*\n"
101 let b:undo_ftplugin .= " | unlet! b:browsefilter"
102endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000103
Bram Moolenaar8c1b8cb2022-06-14 17:41:28 +0100104" Proper matching for matchit plugin
105if exists("loaded_matchit") && !exists("b:match_words")
106 let b:match_skip = 's:comment\|string\|perlQQ\|perlShellCommand\|perlHereDoc\|perlSubstitution\|perlTranslation\|perlMatch\|perlFormatField'
107 let b:match_words = '\<if\>:\<elsif\>:\<else\>'
108 let b:undo_ftplugin .= " | unlet! b:match_words b:match_skip"
109endif
Bram Moolenaar543b7ef2013-06-01 14:50:56 +0200110
Bram Moolenaar071d4272004-06-13 20:20:40 +0000111" Restore the saved compatibility options.
112let &cpo = s:save_cpo
Bram Moolenaar8c1b8cb2022-06-14 17:41:28 +0100113unlet s:save_cpo s:old_isfname s:new_isfname