perl.vim 4.0 KB

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