blob: b107a7258523a35b584904661f199a5c4f8a8d36 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim indent file
Bram Moolenaar8c1b8cb2022-06-14 17:41:28 +01002" Language: Perl
Bram Moolenaar543b7ef2013-06-01 14:50:56 +02003" 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 Sep 24
Bram Moolenaar071d4272004-06-13 20:20:40 +00008
Bram Moolenaar8c1b8cb2022-06-14 17:41:28 +01009if exists("b:did_ftplugin") | finish | endif
10let b:did_ftplugin = 1
Bram Moolenaar071d4272004-06-13 20:20:40 +000011
Bram Moolenaar8c1b8cb2022-06-14 17:41:28 +010012" Make sure the continuation lines below do not cause problems in
13" compatibility mode.
14let s:save_cpo = &cpo
Bram Moolenaarb6356332005-07-18 21:40:44 +000015set cpo-=C
16
Bram Moolenaar8c1b8cb2022-06-14 17:41:28 +010017setlocal formatoptions-=t
18setlocal formatoptions+=crqol
19setlocal keywordprg=perldoc\ -f
Bram Moolenaar071d4272004-06-13 20:20:40 +000020
Bram Moolenaar8c1b8cb2022-06-14 17:41:28 +010021setlocal comments=:#
22setlocal commentstring=#%s
Bram Moolenaar071d4272004-06-13 20:20:40 +000023
Bram Moolenaar8c1b8cb2022-06-14 17:41:28 +010024" Provided by Ned Konz <ned at bike-nomad dot com>
25"---------------------------------------------
26setlocal 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.
29setlocal includeexpr=substitute(substitute(substitute(substitute(v:fname,'+','',''),'::','/','g'),'->\*','',''),'$','.pm','')
30setlocal define=[^A-Za-z_]
31setlocal iskeyword+=:
Bram Moolenaar071d4272004-06-13 20:20:40 +000032
Bram Moolenaar8c1b8cb2022-06-14 17:41:28 +010033" 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.
36let s:old_isfname = &isfname
37set isfname+=:
38let s:new_isfname = &isfname
Bram Moolenaar071d4272004-06-13 20:20:40 +000039
Bram Moolenaar8c1b8cb2022-06-14 17:41:28 +010040augroup 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
Bram Moolenaar071d4272004-06-13 20:20:40 +000045
Bram Moolenaar8c1b8cb2022-06-14 17:41:28 +010046" 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
54
55" Set this once, globally.
56if !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 Moolenaar9de99972010-08-09 22:33:06 +020068 else
Bram Moolenaar8c1b8cb2022-06-14 17:41:28 +010069 " 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 Moolenaar071d4272004-06-13 20:20:40 +000072 endif
Bram Moolenaar8c1b8cb2022-06-14 17:41:28 +010073endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000074
Bram Moolenaar8c1b8cb2022-06-14 17:41:28 +010075" 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.
78if &l:path == ""
79 if &g:path == ""
80 let &l:path=perlpath
Bram Moolenaar9de99972010-08-09 22:33:06 +020081 else
Bram Moolenaar8c1b8cb2022-06-14 17:41:28 +010082 let &l:path=&g:path.",".perlpath
Bram Moolenaar9de99972010-08-09 22:33:06 +020083 endif
Bram Moolenaar8c1b8cb2022-06-14 17:41:28 +010084else
85 let &l:path=&l:path.",".perlpath
86endif
Bram Moolenaar9de99972010-08-09 22:33:06 +020087
Bram Moolenaar8c1b8cb2022-06-14 17:41:28 +010088let b:undo_ftplugin .= " | setlocal pa<"
89"---------------------------------------------
Bram Moolenaar9de99972010-08-09 22:33:06 +020090
Bram Moolenaar8c1b8cb2022-06-14 17:41:28 +010091" Change the browse dialog to show mainly Perl-related files
92if (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"
98endif
Bram Moolenaar9de99972010-08-09 22:33:06 +020099
Bram Moolenaar8c1b8cb2022-06-14 17:41:28 +0100100" Proper matching for matchit plugin
101if 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"
105endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000106
Bram Moolenaar8c1b8cb2022-06-14 17:41:28 +0100107" Restore the saved compatibility options.
108let &cpo = s:save_cpo
109unlet s:save_cpo s:old_isfname s:new_isfname