Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | " Vim filetype plugin file |
Bram Moolenaar | 543b7ef | 2013-06-01 14:50:56 +0200 | [diff] [blame] | 2 | " Language: Perl |
| 3 | " Maintainer: vim-perl <vim-perl@googlegroups.com> |
Bram Moolenaar | 2c7f8c5 | 2020-04-20 19:52:53 +0200 | [diff] [blame] | 4 | " Homepage: https://github.com/vim-perl/vim-perl |
| 5 | " Bugs/requests: https://github.com/vim-perl/vim-perl/issues |
Bram Moolenaar | 8c1b8cb | 2022-06-14 17:41:28 +0100 | [diff] [blame] | 6 | " License: Vim License (see :help license) |
| 7 | " Last Change: 2021 Nov 10 |
dkearns | 4e554d2 | 2023-09-09 03:16:03 +1000 | [diff] [blame] | 8 | " 2023 Sep 07 by Vim Project (safety check: don't execute perl |
| 9 | " from current directory) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10 | |
| 11 | if exists("b:did_ftplugin") | finish | endif |
| 12 | let b:did_ftplugin = 1 |
| 13 | |
| 14 | " Make sure the continuation lines below do not cause problems in |
| 15 | " compatibility mode. |
| 16 | let s:save_cpo = &cpo |
| 17 | set cpo-=C |
| 18 | |
Bram Moolenaar | 543b7ef | 2013-06-01 14:50:56 +0200 | [diff] [blame] | 19 | setlocal formatoptions-=t |
| 20 | setlocal formatoptions+=crqol |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 21 | setlocal keywordprg=perldoc\ -f |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 22 | |
| 23 | setlocal comments=:# |
| 24 | setlocal commentstring=#%s |
| 25 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 26 | " Provided by Ned Konz <ned at bike-nomad dot com> |
| 27 | "--------------------------------------------- |
Bram Moolenaar | 83c465c | 2005-12-16 21:53:56 +0000 | [diff] [blame] | 28 | setlocal include=\\<\\(use\\\|require\\)\\> |
Bram Moolenaar | 8c1b8cb | 2022-06-14 17:41:28 +0100 | [diff] [blame] | 29 | " '+' is removed to support plugins in Catalyst or DBIx::Class |
| 30 | " where the leading plus indicates a fully-qualified module name. |
| 31 | setlocal includeexpr=substitute(substitute(substitute(substitute(v:fname,'+','',''),'::','/','g'),'->\*','',''),'$','.pm','') |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 32 | setlocal define=[^A-Za-z_] |
Bram Moolenaar | 37c64c7 | 2017-09-19 22:06:03 +0200 | [diff] [blame] | 33 | setlocal iskeyword+=: |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 34 | |
| 35 | " The following line changes a global variable but is necessary to make |
Bram Moolenaar | 37c64c7 | 2017-09-19 22:06:03 +0200 | [diff] [blame] | 36 | " gf and similar commands work. Thanks to Andrew Pimlott for pointing |
Bram Moolenaar | 8c1b8cb | 2022-06-14 17:41:28 +0100 | [diff] [blame] | 37 | " out the problem. |
| 38 | let s:old_isfname = &isfname |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 39 | set isfname+=: |
Bram Moolenaar | 8c1b8cb | 2022-06-14 17:41:28 +0100 | [diff] [blame] | 40 | let s:new_isfname = &isfname |
| 41 | |
| 42 | augroup 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" |
| 46 | augroup END |
| 47 | |
| 48 | " Undo the stuff we changed. |
| 49 | let b:undo_ftplugin = "setlocal fo< kp< com< cms< inc< inex< def< isk<" . |
| 50 | \ " | let &isfname = '" . s:old_isfname . "'" |
| 51 | |
| 52 | if get(g:, 'perl_fold', 0) |
| 53 | setlocal foldmethod=syntax |
| 54 | let b:undo_ftplugin .= " | setlocal fdm<" |
| 55 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 56 | |
| 57 | " Set this once, globally. |
| 58 | if !exists("perlpath") |
Christian Brabandt | f7ac0ef | 2023-09-06 20:41:25 +0200 | [diff] [blame] | 59 | " safety check: don't execute perl binary by default |
D. Ben Knoble | cd8a3ea | 2023-11-04 05:11:17 -0400 | [diff] [blame] | 60 | if dist#vim#IsSafeExecutable('perl', 'perl') |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 61 | try |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 62 | 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 Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 68 | catch /E145:/ |
| 69 | let perlpath = ".,," |
| 70 | endtry |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 71 | 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 |
| 76 | endif |
| 77 | |
Bram Moolenaar | 543b7ef | 2013-06-01 14:50:56 +0200 | [diff] [blame] | 78 | " 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. |
| 81 | if &l:path == "" |
| 82 | if &g:path == "" |
| 83 | let &l:path=perlpath |
| 84 | else |
| 85 | let &l:path=&g:path.",".perlpath |
| 86 | endif |
| 87 | else |
| 88 | let &l:path=&l:path.",".perlpath |
| 89 | endif |
Bram Moolenaar | 8c1b8cb | 2022-06-14 17:41:28 +0100 | [diff] [blame] | 90 | |
| 91 | let b:undo_ftplugin .= " | setlocal pa<" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 92 | "--------------------------------------------- |
| 93 | |
Bram Moolenaar | 8c1b8cb | 2022-06-14 17:41:28 +0100 | [diff] [blame] | 94 | " Change the browse dialog to show mainly Perl-related files |
| 95 | if (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" |
| 101 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 102 | |
Bram Moolenaar | 8c1b8cb | 2022-06-14 17:41:28 +0100 | [diff] [blame] | 103 | " Proper matching for matchit plugin |
| 104 | if 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" |
| 108 | endif |
Bram Moolenaar | 543b7ef | 2013-06-01 14:50:56 +0200 | [diff] [blame] | 109 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 110 | " Restore the saved compatibility options. |
| 111 | let &cpo = s:save_cpo |
Bram Moolenaar | 8c1b8cb | 2022-06-14 17:41:28 +0100 | [diff] [blame] | 112 | unlet s:save_cpo s:old_isfname s:new_isfname |