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 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8 | |
| 9 | if exists("b:did_ftplugin") | finish | endif |
| 10 | let b:did_ftplugin = 1 |
| 11 | |
| 12 | " Make sure the continuation lines below do not cause problems in |
| 13 | " compatibility mode. |
| 14 | let s:save_cpo = &cpo |
| 15 | set cpo-=C |
| 16 | |
Bram Moolenaar | 543b7ef | 2013-06-01 14:50:56 +0200 | [diff] [blame] | 17 | setlocal formatoptions-=t |
| 18 | setlocal formatoptions+=crqol |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 19 | setlocal keywordprg=perldoc\ -f |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 20 | |
| 21 | setlocal comments=:# |
| 22 | setlocal commentstring=#%s |
| 23 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 24 | " Provided by Ned Konz <ned at bike-nomad dot com> |
| 25 | "--------------------------------------------- |
Bram Moolenaar | 83c465c | 2005-12-16 21:53:56 +0000 | [diff] [blame] | 26 | setlocal include=\\<\\(use\\\|require\\)\\> |
Bram Moolenaar | 8c1b8cb | 2022-06-14 17:41:28 +0100 | [diff] [blame] | 27 | " '+' is removed to support plugins in Catalyst or DBIx::Class |
| 28 | " where the leading plus indicates a fully-qualified module name. |
| 29 | setlocal includeexpr=substitute(substitute(substitute(substitute(v:fname,'+','',''),'::','/','g'),'->\*','',''),'$','.pm','') |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 30 | setlocal define=[^A-Za-z_] |
Bram Moolenaar | 37c64c7 | 2017-09-19 22:06:03 +0200 | [diff] [blame] | 31 | setlocal iskeyword+=: |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 32 | |
| 33 | " The following line changes a global variable but is necessary to make |
Bram Moolenaar | 37c64c7 | 2017-09-19 22:06:03 +0200 | [diff] [blame] | 34 | " gf and similar commands work. Thanks to Andrew Pimlott for pointing |
Bram Moolenaar | 8c1b8cb | 2022-06-14 17:41:28 +0100 | [diff] [blame] | 35 | " out the problem. |
| 36 | let s:old_isfname = &isfname |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 37 | set isfname+=: |
Bram Moolenaar | 8c1b8cb | 2022-06-14 17:41:28 +0100 | [diff] [blame] | 38 | let s:new_isfname = &isfname |
| 39 | |
| 40 | augroup 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" |
| 44 | augroup END |
| 45 | |
| 46 | " Undo the stuff we changed. |
| 47 | let b:undo_ftplugin = "setlocal fo< kp< com< cms< inc< inex< def< isk<" . |
| 48 | \ " | let &isfname = '" . s:old_isfname . "'" |
| 49 | |
| 50 | if get(g:, 'perl_fold', 0) |
| 51 | setlocal foldmethod=syntax |
| 52 | let b:undo_ftplugin .= " | setlocal fdm<" |
| 53 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 54 | |
| 55 | " Set this once, globally. |
| 56 | if !exists("perlpath") |
Christian Brabandt | 816fbcc | 2023-08-31 23:52:30 +0200 | [diff] [blame] | 57 | " safety check: don't execute perl from current directory |
Anton Sharonov | 67c951d | 2023-09-05 21:03:27 +0200 | [diff] [blame] | 58 | 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 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 |
Anton Sharonov | 67c951d | 2023-09-05 21:03:27 +0200 | [diff] [blame] | 76 | unlet s:tmp_cwd |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 77 | endif |
| 78 | |
Bram Moolenaar | 543b7ef | 2013-06-01 14:50:56 +0200 | [diff] [blame] | 79 | " 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. |
| 82 | if &l:path == "" |
| 83 | if &g:path == "" |
| 84 | let &l:path=perlpath |
| 85 | else |
| 86 | let &l:path=&g:path.",".perlpath |
| 87 | endif |
| 88 | else |
| 89 | let &l:path=&l:path.",".perlpath |
| 90 | endif |
Bram Moolenaar | 8c1b8cb | 2022-06-14 17:41:28 +0100 | [diff] [blame] | 91 | |
| 92 | let b:undo_ftplugin .= " | setlocal pa<" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 93 | "--------------------------------------------- |
| 94 | |
Bram Moolenaar | 8c1b8cb | 2022-06-14 17:41:28 +0100 | [diff] [blame] | 95 | " Change the browse dialog to show mainly Perl-related files |
| 96 | if (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" |
| 102 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 103 | |
Bram Moolenaar | 8c1b8cb | 2022-06-14 17:41:28 +0100 | [diff] [blame] | 104 | " Proper matching for matchit plugin |
| 105 | if 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" |
| 109 | endif |
Bram Moolenaar | 543b7ef | 2013-06-01 14:50:56 +0200 | [diff] [blame] | 110 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 111 | " Restore the saved compatibility options. |
| 112 | let &cpo = s:save_cpo |
Bram Moolenaar | 8c1b8cb | 2022-06-14 17:41:28 +0100 | [diff] [blame] | 113 | unlet s:save_cpo s:old_isfname s:new_isfname |