perl.vim 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. " Vim filetype plugin file
  2. " Language: Perl
  3. " Maintainer: vim-perl <vim-perl@googlegroups.com>
  4. " Homepage: https://github.com/vim-perl/vim-perl
  5. " Bugs/requests: https://github.com/vim-perl/vim-perl/issues
  6. " License: Vim License (see :help license)
  7. " Last Change: 2021 Nov 10
  8. " 2023 Sep 07 by Vim Project (safety check: don't execute perl
  9. " from current directory)
  10. " 2024 Jan 14 by Vim Project (browsefilter)
  11. if exists("b:did_ftplugin") | finish | endif
  12. let b:did_ftplugin = 1
  13. " Make sure the continuation lines below do not cause problems in
  14. " compatibility mode.
  15. let s:save_cpo = &cpo
  16. set cpo-=C
  17. setlocal formatoptions-=t
  18. setlocal formatoptions+=crqol
  19. setlocal keywordprg=perldoc\ -f
  20. setlocal comments=:#
  21. setlocal commentstring=#%s
  22. " Provided by Ned Konz <ned at bike-nomad dot com>
  23. "---------------------------------------------
  24. setlocal include=\\<\\(use\\\|require\\)\\>
  25. " '+' is removed to support plugins in Catalyst or DBIx::Class
  26. " where the leading plus indicates a fully-qualified module name.
  27. setlocal includeexpr=substitute(substitute(substitute(substitute(v:fname,'+','',''),'::','/','g'),'->\*','',''),'$','.pm','')
  28. setlocal define=[^A-Za-z_]
  29. setlocal iskeyword+=:
  30. " The following line changes a global variable but is necessary to make
  31. " gf and similar commands work. Thanks to Andrew Pimlott for pointing
  32. " out the problem.
  33. let s:old_isfname = &isfname
  34. set isfname+=:
  35. let s:new_isfname = &isfname
  36. augroup perl_global_options
  37. au!
  38. exe "au BufEnter * if &filetype == 'perl' | let &isfname = '" . s:new_isfname . "' | endif"
  39. exe "au BufLeave * if &filetype == 'perl' | let &isfname = '" . s:old_isfname . "' | endif"
  40. augroup END
  41. " Undo the stuff we changed.
  42. let b:undo_ftplugin = "setlocal fo< kp< com< cms< inc< inex< def< isk<" .
  43. \ " | let &isfname = '" . s:old_isfname . "'"
  44. if get(g:, 'perl_fold', 0)
  45. setlocal foldmethod=syntax
  46. let b:undo_ftplugin .= " | setlocal fdm<"
  47. endif
  48. " Set this once, globally.
  49. if !exists("perlpath")
  50. " safety check: don't execute perl binary by default
  51. if dist#vim#IsSafeExecutable('perl', 'perl')
  52. try
  53. if &shellxquote != '"'
  54. let perlpath = system('perl -e "print join(q/,/,@INC)"')
  55. else
  56. let perlpath = system("perl -e 'print join(q/,/,@INC)'")
  57. endif
  58. let perlpath = substitute(perlpath,',.$',',,','')
  59. catch /E145:/
  60. let perlpath = ".,,"
  61. endtry
  62. else
  63. " If we can't call perl to get its path, just default to using the
  64. " current directory and the directory of the current file.
  65. let perlpath = ".,,"
  66. endif
  67. endif
  68. " Append perlpath to the existing path value, if it is set. Since we don't
  69. " use += to do it because of the commas in perlpath, we have to handle the
  70. " global / local settings, too.
  71. if &l:path == ""
  72. if &g:path == ""
  73. let &l:path=perlpath
  74. else
  75. let &l:path=&g:path.",".perlpath
  76. endif
  77. else
  78. let &l:path=&l:path.",".perlpath
  79. endif
  80. let b:undo_ftplugin .= " | setlocal pa<"
  81. "---------------------------------------------
  82. " Change the browse dialog to show mainly Perl-related files
  83. if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
  84. let b:browsefilter = "Perl Source Files (*.pl)\t*.pl\n" .
  85. \ "Perl Modules (*.pm)\t*.pm\n" .
  86. \ "Perl Documentation Files (*.pod)\t*.pod\n"
  87. if has("win32")
  88. let b:browsefilter .= "All Files (*.*)\t*\n"
  89. else
  90. let b:browsefilter .= "All Files (*)\t*\n"
  91. endif
  92. let b:undo_ftplugin .= " | unlet! b:browsefilter"
  93. endif
  94. " Proper matching for matchit plugin
  95. if exists("loaded_matchit") && !exists("b:match_words")
  96. let b:match_skip = 's:comment\|string\|perlQQ\|perlShellCommand\|perlHereDoc\|perlSubstitution\|perlTranslation\|perlMatch\|perlFormatField'
  97. let b:match_words = '\<if\>:\<elsif\>:\<else\>'
  98. let b:undo_ftplugin .= " | unlet! b:match_words b:match_skip"
  99. endif
  100. " Restore the saved compatibility options.
  101. let &cpo = s:save_cpo
  102. unlet s:save_cpo s:old_isfname s:new_isfname