Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | " Vim indent file |
Bram Moolenaar | 8c1b8cb | 2022-06-14 17:41:28 +0100 | [diff] [blame] | 2 | " Language: Perl |
Bram Moolenaar | 543b7ef | 2013-06-01 14:50:56 +0200 | [diff] [blame] | 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 Sep 24 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8 | |
Bram Moolenaar | 8c1b8cb | 2022-06-14 17:41:28 +0100 | [diff] [blame] | 9 | if exists("b:did_ftplugin") | finish | endif |
| 10 | let b:did_ftplugin = 1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 11 | |
Bram Moolenaar | 8c1b8cb | 2022-06-14 17:41:28 +0100 | [diff] [blame] | 12 | " Make sure the continuation lines below do not cause problems in |
| 13 | " compatibility mode. |
| 14 | let s:save_cpo = &cpo |
Bram Moolenaar | b635633 | 2005-07-18 21:40:44 +0000 | [diff] [blame] | 15 | set cpo-=C |
| 16 | |
Bram Moolenaar | 8c1b8cb | 2022-06-14 17:41:28 +0100 | [diff] [blame] | 17 | setlocal formatoptions-=t |
| 18 | setlocal formatoptions+=crqol |
| 19 | setlocal keywordprg=perldoc\ -f |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 20 | |
Bram Moolenaar | 8c1b8cb | 2022-06-14 17:41:28 +0100 | [diff] [blame] | 21 | setlocal comments=:# |
| 22 | setlocal commentstring=#%s |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 23 | |
Bram Moolenaar | 8c1b8cb | 2022-06-14 17:41:28 +0100 | [diff] [blame] | 24 | " Provided by Ned Konz <ned at bike-nomad dot com> |
| 25 | "--------------------------------------------- |
| 26 | setlocal include=\\<\\(use\\\|require\\)\\> |
| 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','') |
| 30 | setlocal define=[^A-Za-z_] |
| 31 | setlocal iskeyword+=: |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 32 | |
Bram Moolenaar | 8c1b8cb | 2022-06-14 17:41:28 +0100 | [diff] [blame] | 33 | " The following line changes a global variable but is necessary to make |
| 34 | " gf and similar commands work. Thanks to Andrew Pimlott for pointing |
| 35 | " out the problem. |
| 36 | let s:old_isfname = &isfname |
| 37 | set isfname+=: |
| 38 | let s:new_isfname = &isfname |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 39 | |
Bram Moolenaar | 8c1b8cb | 2022-06-14 17:41:28 +0100 | [diff] [blame] | 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 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 45 | |
Bram Moolenaar | 8c1b8cb | 2022-06-14 17:41:28 +0100 | [diff] [blame] | 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 |
| 54 | |
| 55 | " Set this once, globally. |
| 56 | if !exists("perlpath") |
| 57 | if executable("perl") |
| 58 | try |
| 59 | if &shellxquote != '"' |
| 60 | let perlpath = system('perl -e "print join(q/,/,@INC)"') |
| 61 | else |
| 62 | let perlpath = system("perl -e 'print join(q/,/,@INC)'") |
| 63 | endif |
| 64 | let perlpath = substitute(perlpath,',.$',',,','') |
| 65 | catch /E145:/ |
| 66 | let perlpath = ".,," |
| 67 | endtry |
Bram Moolenaar | 9de9997 | 2010-08-09 22:33:06 +0200 | [diff] [blame] | 68 | else |
Bram Moolenaar | 8c1b8cb | 2022-06-14 17:41:28 +0100 | [diff] [blame] | 69 | " If we can't call perl to get its path, just default to using the |
| 70 | " current directory and the directory of the current file. |
| 71 | let perlpath = ".,," |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 72 | endif |
Bram Moolenaar | 8c1b8cb | 2022-06-14 17:41:28 +0100 | [diff] [blame] | 73 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 74 | |
Bram Moolenaar | 8c1b8cb | 2022-06-14 17:41:28 +0100 | [diff] [blame] | 75 | " Append perlpath to the existing path value, if it is set. Since we don't |
| 76 | " use += to do it because of the commas in perlpath, we have to handle the |
| 77 | " global / local settings, too. |
| 78 | if &l:path == "" |
| 79 | if &g:path == "" |
| 80 | let &l:path=perlpath |
Bram Moolenaar | 9de9997 | 2010-08-09 22:33:06 +0200 | [diff] [blame] | 81 | else |
Bram Moolenaar | 8c1b8cb | 2022-06-14 17:41:28 +0100 | [diff] [blame] | 82 | let &l:path=&g:path.",".perlpath |
Bram Moolenaar | 9de9997 | 2010-08-09 22:33:06 +0200 | [diff] [blame] | 83 | endif |
Bram Moolenaar | 8c1b8cb | 2022-06-14 17:41:28 +0100 | [diff] [blame] | 84 | else |
| 85 | let &l:path=&l:path.",".perlpath |
| 86 | endif |
Bram Moolenaar | 9de9997 | 2010-08-09 22:33:06 +0200 | [diff] [blame] | 87 | |
Bram Moolenaar | 8c1b8cb | 2022-06-14 17:41:28 +0100 | [diff] [blame] | 88 | let b:undo_ftplugin .= " | setlocal pa<" |
| 89 | "--------------------------------------------- |
Bram Moolenaar | 9de9997 | 2010-08-09 22:33:06 +0200 | [diff] [blame] | 90 | |
Bram Moolenaar | 8c1b8cb | 2022-06-14 17:41:28 +0100 | [diff] [blame] | 91 | " Change the browse dialog to show mainly Perl-related files |
| 92 | if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter") |
| 93 | let b:browsefilter = "Perl Source Files (*.pl)\t*.pl\n" . |
| 94 | \ "Perl Modules (*.pm)\t*.pm\n" . |
| 95 | \ "Perl Documentation Files (*.pod)\t*.pod\n" . |
| 96 | \ "All Files (*.*)\t*.*\n" |
| 97 | let b:undo_ftplugin .= " | unlet! b:browsefilter" |
| 98 | endif |
Bram Moolenaar | 9de9997 | 2010-08-09 22:33:06 +0200 | [diff] [blame] | 99 | |
Bram Moolenaar | 8c1b8cb | 2022-06-14 17:41:28 +0100 | [diff] [blame] | 100 | " Proper matching for matchit plugin |
| 101 | if exists("loaded_matchit") && !exists("b:match_words") |
| 102 | let b:match_skip = 's:comment\|string\|perlQQ\|perlShellCommand\|perlHereDoc\|perlSubstitution\|perlTranslation\|perlMatch\|perlFormatField' |
| 103 | let b:match_words = '\<if\>:\<elsif\>:\<else\>' |
| 104 | let b:undo_ftplugin .= " | unlet! b:match_words b:match_skip" |
| 105 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 106 | |
Bram Moolenaar | 8c1b8cb | 2022-06-14 17:41:28 +0100 | [diff] [blame] | 107 | " Restore the saved compatibility options. |
| 108 | let &cpo = s:save_cpo |
| 109 | unlet s:save_cpo s:old_isfname s:new_isfname |