php.vim 5.4 KB

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