php.vim 5.3 KB

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