php.vim 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. " Vim filetype plugin file
  2. " Language: PHP
  3. " Maintainer: Doug Kearns <dougkearns@gmail.com>
  4. " Previous Maintainer: Dan Sharp
  5. " Last Changed: 2022 Jul 20
  6. if exists("b:did_ftplugin")
  7. finish
  8. endif
  9. " Make sure the continuation lines below do not cause problems in
  10. " compatibility mode.
  11. let s:keepcpo= &cpo
  12. set cpo&vim
  13. " Define some defaults in case the included ftplugins don't set them.
  14. let s:undo_ftplugin = ""
  15. let s:browsefilter = "HTML Files (*.html, *.htm)\t*.html;*.htm\n" ..
  16. \ "All Files (*.*)\t*.*\n"
  17. let s:match_words = ""
  18. runtime! ftplugin/html.vim ftplugin/html_*.vim ftplugin/html/*.vim
  19. let b:did_ftplugin = 1
  20. " Override our defaults if these were set by an included ftplugin.
  21. if exists("b:undo_ftplugin")
  22. " let b:undo_ftplugin = "setlocal comments< commentstring< formatoptions< omnifunc<"
  23. let s:undo_ftplugin = b:undo_ftplugin
  24. endif
  25. if exists("b:browsefilter")
  26. " let b:undo_ftplugin ..= " | unlet! b:browsefilter b:html_set_browsefilter"
  27. let s:browsefilter = b:browsefilter
  28. endif
  29. if exists("b:match_words")
  30. " let b:undo_ftplugin ..= " | unlet! b:match_ignorecase b:match_words b:html_set_match_words"
  31. let s:match_words = b:match_words
  32. endif
  33. if exists("b:match_skip")
  34. unlet b:match_skip
  35. endif
  36. setlocal comments=s1:/*,mb:*,ex:*/,://,:#
  37. setlocal commentstring=/*%s*/
  38. setlocal formatoptions+=l formatoptions-=t
  39. if get(g:, "php_autocomment", 1)
  40. setlocal formatoptions+=croq
  41. " NOTE: set g:PHP_autoformatcomment = 0 to prevent the indent plugin from
  42. " overriding this 'comments' value
  43. setlocal comments-=:#
  44. " space after # comments to exclude attributes
  45. setlocal comments+=b:#
  46. endif
  47. if exists('&omnifunc')
  48. setlocal omnifunc=phpcomplete#CompletePHP
  49. endif
  50. setlocal suffixesadd=.php
  51. " ###
  52. " Provided by Mikolaj Machowski <mikmach at wp dot pl>
  53. setlocal include=\\\(require\\\|include\\\)\\\(_once\\\)\\\?
  54. " Disabled changing 'iskeyword', it breaks a command such as "*"
  55. " setlocal iskeyword+=$
  56. let b:undo_ftplugin = "setlocal include< suffixesadd<"
  57. if exists("loaded_matchit") && exists("b:html_set_match_words")
  58. let b:match_ignorecase = 1
  59. let b:match_words = 'PhpMatchWords()'
  60. if !exists("*PhpMatchWords")
  61. function! PhpMatchWords()
  62. " The PHP syntax file uses the Delimiter syntax group for the phpRegion
  63. " matchgroups, without a "php" prefix, so use the stack to test for the
  64. " outer phpRegion group. This also means the closing ?> tag which is
  65. " outside of the matched region just uses the Delimiter group for the
  66. " end match.
  67. let stack = synstack(line('.'), col('.'))
  68. let php_region = !empty(stack) && synIDattr(stack[0], "name") =~# '\<php'
  69. if php_region || getline(".") =~ '.\=\%.c\&?>'
  70. let b:match_skip = "PhpMatchSkip('html')"
  71. return '<?php\|<?=\=:?>,' ..
  72. \ '\<if\>:\<elseif\>:\<else\>:\<endif\>,' ..
  73. \ '\<switch\>:\<case\>:\<break\>:\<continue\>:\<endswitch\>,' ..
  74. \ '\<while\>.\{-})\s*\::\<break\>:\<continue\>:\<endwhile\>,' ..
  75. \ '\<do\>:\<break\>:\<continue\>:\<while\>,' ..
  76. \ '\<for\>:\<break\>:\<continue\>:\<endfor\>,' ..
  77. \ '\<foreach\>:\<break\>:\<continue\>:\<endforeach\>,' ..
  78. \ '\%(<<<\s*\)\@<=''\=\(\h\w*\)''\=:^\s*\1\>'
  79. " TODO: these probably aren't worth adding and really need syntax support
  80. " '<\_s*script\_s*language\_s*=\_s*[''"]\=\_s*php\_s*[''"]\=\_s*>:<\_s*\_s*/\_s*script\_s*>,' ..
  81. " '<%:%>,' ..
  82. else
  83. let b:match_skip = "PhpMatchSkip('php')"
  84. return s:match_words
  85. endif
  86. endfunction
  87. endif
  88. if !exists("*PhpMatchSkip")
  89. function! PhpMatchSkip(skip)
  90. let name = synIDattr(synID(line('.'), col('.'), 1), 'name')
  91. if a:skip == "html"
  92. " ?> in line comments will also be correctly matched as Delimiter
  93. return name =~? 'comment\|string' || name !~? 'php\|delimiter'
  94. else " php
  95. return name =~? 'comment\|string\|php'
  96. endif
  97. endfunction
  98. endif
  99. let b:undo_ftplugin ..= " | unlet! b:match_skip"
  100. endif
  101. " ###
  102. " Change the :browse e filter to primarily show PHP-related files.
  103. if (has("gui_win32") || has("gui_gtk")) && exists("b:html_set_browsefilter")
  104. let b:browsefilter = "PHP Files (*.php)\t*.php\n" ..
  105. \ "PHP Test Files (*.phpt)\t*.phpt\n" ..
  106. \ s:browsefilter
  107. endif
  108. if !exists("no_plugin_maps") && !exists("no_php_maps")
  109. " Section jumping: [[ and ]] provided by Antony Scriven <adscriven at gmail dot com>
  110. let s:function = '\%(abstract\s\+\|final\s\+\|private\s\+\|protected\s\+\|public\s\+\|static\s\+\)*function'
  111. let s:class = '\%(abstract\s\+\|final\s\+\)*class'
  112. let s:section = escape('^\s*\zs\%(' .. s:function .. '\|' .. s:class .. '\|interface\|trait\|enum\)\>', "|")
  113. function! s:Jump(pattern, count, flags)
  114. normal! m'
  115. for i in range(a:count)
  116. if !search(a:pattern, a:flags)
  117. break
  118. endif
  119. endfor
  120. endfunction
  121. for mode in ["n", "o", "x"]
  122. exe mode .. "noremap <buffer> <silent> ]] <Cmd>call <SID>Jump('" .. s:section .. "', v:count1, 'W')<CR>"
  123. exe mode .. "noremap <buffer> <silent> [[ <Cmd>call <SID>Jump('" .. s:section .. "', v:count1, 'bW')<CR>"
  124. let b:undo_ftplugin ..= " | sil! exe '" .. mode .. "unmap <buffer> ]]'" ..
  125. \ " | sil! exe '" .. mode .. "unmap <buffer> [['"
  126. endfor
  127. endif
  128. let b:undo_ftplugin ..= " | " .. s:undo_ftplugin
  129. " Restore the saved compatibility options.
  130. let &cpo = s:keepcpo
  131. unlet s:keepcpo
  132. " vim: nowrap sw=2 sts=2 ts=8 noet: