blob: f03f14512ad84c30d71697f0a1cc4af49e115a0f [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim filetype plugin file
Bram Moolenaar48c3f4e2022-08-08 15:42:38 +01002" Language: PHP
3" Maintainer: Doug Kearns <dougkearns@gmail.com>
4" Previous Maintainer: Dan Sharp
Doug Kearns93197fd2024-01-14 20:59:02 +01005" Last Change: 2024 Jan 14
Bram Moolenaar071d4272004-06-13 20:20:40 +00006
Bram Moolenaar48c3f4e2022-08-08 15:42:38 +01007if exists("b:did_ftplugin")
8 finish
9endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010
11" Make sure the continuation lines below do not cause problems in
12" compatibility mode.
Bram Moolenaar9a7224b2012-04-30 15:56:52 +020013let s:keepcpo= &cpo
14set cpo&vim
Bram Moolenaar071d4272004-06-13 20:20:40 +000015
16" Define some defaults in case the included ftplugins don't set them.
17let s:undo_ftplugin = ""
Doug Kearns93197fd2024-01-14 20:59:02 +010018let s:browsefilter = "HTML Files (*.html, *.htm)\t*.html;*.htm\n"
19if has("win32")
20 let s:browsefilter ..= "All Files (*.*)\t*\n"
21else
22 let s:browsefilter ..= "All Files (*)\t*\n"
23endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000024let s:match_words = ""
25
26runtime! ftplugin/html.vim ftplugin/html_*.vim ftplugin/html/*.vim
27let b:did_ftplugin = 1
28
29" Override our defaults if these were set by an included ftplugin.
30if exists("b:undo_ftplugin")
Bram Moolenaar48c3f4e2022-08-08 15:42:38 +010031" let b:undo_ftplugin = "setlocal comments< commentstring< formatoptions< omnifunc<"
32 let s:undo_ftplugin = b:undo_ftplugin
Bram Moolenaar071d4272004-06-13 20:20:40 +000033endif
34if exists("b:browsefilter")
Bram Moolenaar48c3f4e2022-08-08 15:42:38 +010035" let b:undo_ftplugin ..= " | unlet! b:browsefilter b:html_set_browsefilter"
36 let s:browsefilter = b:browsefilter
Bram Moolenaar071d4272004-06-13 20:20:40 +000037endif
38if exists("b:match_words")
Bram Moolenaar48c3f4e2022-08-08 15:42:38 +010039" let b:undo_ftplugin ..= " | unlet! b:match_ignorecase b:match_words b:html_set_match_words"
40 let s:match_words = b:match_words
Bram Moolenaar071d4272004-06-13 20:20:40 +000041endif
Bram Moolenaarc81e5e72007-05-05 18:24:42 +000042if exists("b:match_skip")
Bram Moolenaar48c3f4e2022-08-08 15:42:38 +010043 unlet b:match_skip
Bram Moolenaarc81e5e72007-05-05 18:24:42 +000044endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000045
Bram Moolenaar48c3f4e2022-08-08 15:42:38 +010046setlocal comments=s1:/*,mb:*,ex:*/,://,:#
47setlocal commentstring=/*%s*/
48setlocal formatoptions+=l formatoptions-=t
49
50if get(g:, "php_autocomment", 1)
51 setlocal formatoptions+=croq
52 " NOTE: set g:PHP_autoformatcomment = 0 to prevent the indent plugin from
53 " overriding this 'comments' value
54 setlocal comments-=:#
55 " space after # comments to exclude attributes
56 setlocal comments+=b:#
Bram Moolenaar071d4272004-06-13 20:20:40 +000057endif
58
Bram Moolenaar48c3f4e2022-08-08 15:42:38 +010059if exists('&omnifunc')
60 setlocal omnifunc=phpcomplete#CompletePHP
61endif
62
63setlocal suffixesadd=.php
64
Bram Moolenaar071d4272004-06-13 20:20:40 +000065" ###
66" Provided by Mikolaj Machowski <mikmach at wp dot pl>
67setlocal include=\\\(require\\\|include\\\)\\\(_once\\\)\\\?
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000068" Disabled changing 'iskeyword', it breaks a command such as "*"
69" setlocal iskeyword+=$
70
Bram Moolenaar48c3f4e2022-08-08 15:42:38 +010071let b:undo_ftplugin = "setlocal include< suffixesadd<"
72
73if exists("loaded_matchit") && exists("b:html_set_match_words")
74 let b:match_ignorecase = 1
75 let b:match_words = 'PhpMatchWords()'
76
77 if !exists("*PhpMatchWords")
78 function! PhpMatchWords()
79 " The PHP syntax file uses the Delimiter syntax group for the phpRegion
80 " matchgroups, without a "php" prefix, so use the stack to test for the
81 " outer phpRegion group. This also means the closing ?> tag which is
82 " outside of the matched region just uses the Delimiter group for the
83 " end match.
84 let stack = synstack(line('.'), col('.'))
85 let php_region = !empty(stack) && synIDattr(stack[0], "name") =~# '\<php'
86 if php_region || getline(".") =~ '.\=\%.c\&?>'
87 let b:match_skip = "PhpMatchSkip('html')"
88 return '<?php\|<?=\=:?>,' ..
89 \ '\<if\>:\<elseif\>:\<else\>:\<endif\>,' ..
90 \ '\<switch\>:\<case\>:\<break\>:\<continue\>:\<endswitch\>,' ..
91 \ '\<while\>.\{-})\s*\::\<break\>:\<continue\>:\<endwhile\>,' ..
92 \ '\<do\>:\<break\>:\<continue\>:\<while\>,' ..
93 \ '\<for\>:\<break\>:\<continue\>:\<endfor\>,' ..
94 \ '\<foreach\>:\<break\>:\<continue\>:\<endforeach\>,' ..
95 \ '\%(<<<\s*\)\@<=''\=\(\h\w*\)''\=:^\s*\1\>'
96
97 " TODO: these probably aren't worth adding and really need syntax support
98 " '<\_s*script\_s*language\_s*=\_s*[''"]\=\_s*php\_s*[''"]\=\_s*>:<\_s*\_s*/\_s*script\_s*>,' ..
99 " '<%:%>,' ..
100 else
101 let b:match_skip = "PhpMatchSkip('php')"
102 return s:match_words
103 endif
104 endfunction
105 endif
106 if !exists("*PhpMatchSkip")
107 function! PhpMatchSkip(skip)
108 let name = synIDattr(synID(line('.'), col('.'), 1), 'name')
109 if a:skip == "html"
110 " ?> in line comments will also be correctly matched as Delimiter
111 return name =~? 'comment\|string' || name !~? 'php\|delimiter'
112 else " php
113 return name =~? 'comment\|string\|php'
114 endif
115 endfunction
116 endif
117 let b:undo_ftplugin ..= " | unlet! b:match_skip"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000118endif
119" ###
120
Bram Moolenaar48c3f4e2022-08-08 15:42:38 +0100121" Change the :browse e filter to primarily show PHP-related files.
122if (has("gui_win32") || has("gui_gtk")) && exists("b:html_set_browsefilter")
123 let b:browsefilter = "PHP Files (*.php)\t*.php\n" ..
124 \ "PHP Test Files (*.phpt)\t*.phpt\n" ..
125 \ s:browsefilter
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000126endif
127
Bram Moolenaar48c3f4e2022-08-08 15:42:38 +0100128if !exists("no_plugin_maps") && !exists("no_php_maps")
129 " Section jumping: [[ and ]] provided by Antony Scriven <adscriven at gmail dot com>
130 let s:function = '\%(abstract\s\+\|final\s\+\|private\s\+\|protected\s\+\|public\s\+\|static\s\+\)*function'
131 let s:class = '\%(abstract\s\+\|final\s\+\)*class'
132 let s:section = escape('^\s*\zs\%(' .. s:function .. '\|' .. s:class .. '\|interface\|trait\|enum\)\>', "|")
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000133
Bram Moolenaar48c3f4e2022-08-08 15:42:38 +0100134 function! s:Jump(pattern, count, flags)
135 normal! m'
136 for i in range(a:count)
137 if !search(a:pattern, a:flags)
138 break
139 endif
140 endfor
141 endfunction
Bram Moolenaar071d4272004-06-13 20:20:40 +0000142
Bram Moolenaar48c3f4e2022-08-08 15:42:38 +0100143 for mode in ["n", "o", "x"]
144 exe mode .. "noremap <buffer> <silent> ]] <Cmd>call <SID>Jump('" .. s:section .. "', v:count1, 'W')<CR>"
145 exe mode .. "noremap <buffer> <silent> [[ <Cmd>call <SID>Jump('" .. s:section .. "', v:count1, 'bW')<CR>"
146 let b:undo_ftplugin ..= " | sil! exe '" .. mode .. "unmap <buffer> ]]'" ..
147 \ " | sil! exe '" .. mode .. "unmap <buffer> [['"
148 endfor
149endif
150
151let b:undo_ftplugin ..= " | " .. s:undo_ftplugin
Bram Moolenaar071d4272004-06-13 20:20:40 +0000152
153" Restore the saved compatibility options.
Bram Moolenaar9a7224b2012-04-30 15:56:52 +0200154let &cpo = s:keepcpo
155unlet s:keepcpo
Bram Moolenaar48c3f4e2022-08-08 15:42:38 +0100156
157" vim: nowrap sw=2 sts=2 ts=8 noet: