blob: 540653e0303b0773db9d9b2b67ea3e105247c16f [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
5" Last Changed: 2022 Jul 20
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 = ""
Bram Moolenaar48c3f4e2022-08-08 15:42:38 +010018let s:browsefilter = "HTML Files (*.html, *.htm)\t*.html;*.htm\n" ..
19 \ "All Files (*.*)\t*.*\n"
Bram Moolenaar071d4272004-06-13 20:20:40 +000020let s:match_words = ""
21
22runtime! ftplugin/html.vim ftplugin/html_*.vim ftplugin/html/*.vim
23let b:did_ftplugin = 1
24
25" Override our defaults if these were set by an included ftplugin.
26if exists("b:undo_ftplugin")
Bram Moolenaar48c3f4e2022-08-08 15:42:38 +010027" let b:undo_ftplugin = "setlocal comments< commentstring< formatoptions< omnifunc<"
28 let s:undo_ftplugin = b:undo_ftplugin
Bram Moolenaar071d4272004-06-13 20:20:40 +000029endif
30if exists("b:browsefilter")
Bram Moolenaar48c3f4e2022-08-08 15:42:38 +010031" let b:undo_ftplugin ..= " | unlet! b:browsefilter b:html_set_browsefilter"
32 let s:browsefilter = b:browsefilter
Bram Moolenaar071d4272004-06-13 20:20:40 +000033endif
34if exists("b:match_words")
Bram Moolenaar48c3f4e2022-08-08 15:42:38 +010035" let b:undo_ftplugin ..= " | unlet! b:match_ignorecase b:match_words b:html_set_match_words"
36 let s:match_words = b:match_words
Bram Moolenaar071d4272004-06-13 20:20:40 +000037endif
Bram Moolenaarc81e5e72007-05-05 18:24:42 +000038if exists("b:match_skip")
Bram Moolenaar48c3f4e2022-08-08 15:42:38 +010039 unlet b:match_skip
Bram Moolenaarc81e5e72007-05-05 18:24:42 +000040endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000041
Bram Moolenaar48c3f4e2022-08-08 15:42:38 +010042setlocal comments=s1:/*,mb:*,ex:*/,://,:#
43setlocal commentstring=/*%s*/
44setlocal formatoptions+=l formatoptions-=t
45
46if get(g:, "php_autocomment", 1)
47 setlocal formatoptions+=croq
48 " NOTE: set g:PHP_autoformatcomment = 0 to prevent the indent plugin from
49 " overriding this 'comments' value
50 setlocal comments-=:#
51 " space after # comments to exclude attributes
52 setlocal comments+=b:#
Bram Moolenaar071d4272004-06-13 20:20:40 +000053endif
54
Bram Moolenaar48c3f4e2022-08-08 15:42:38 +010055if exists('&omnifunc')
56 setlocal omnifunc=phpcomplete#CompletePHP
57endif
58
59setlocal suffixesadd=.php
60
Bram Moolenaar071d4272004-06-13 20:20:40 +000061" ###
62" Provided by Mikolaj Machowski <mikmach at wp dot pl>
63setlocal include=\\\(require\\\|include\\\)\\\(_once\\\)\\\?
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000064" Disabled changing 'iskeyword', it breaks a command such as "*"
65" setlocal iskeyword+=$
66
Bram Moolenaar48c3f4e2022-08-08 15:42:38 +010067let b:undo_ftplugin = "setlocal include< suffixesadd<"
68
69if exists("loaded_matchit") && exists("b:html_set_match_words")
70 let b:match_ignorecase = 1
71 let b:match_words = 'PhpMatchWords()'
72
73 if !exists("*PhpMatchWords")
74 function! PhpMatchWords()
75 " The PHP syntax file uses the Delimiter syntax group for the phpRegion
76 " matchgroups, without a "php" prefix, so use the stack to test for the
77 " outer phpRegion group. This also means the closing ?> tag which is
78 " outside of the matched region just uses the Delimiter group for the
79 " end match.
80 let stack = synstack(line('.'), col('.'))
81 let php_region = !empty(stack) && synIDattr(stack[0], "name") =~# '\<php'
82 if php_region || getline(".") =~ '.\=\%.c\&?>'
83 let b:match_skip = "PhpMatchSkip('html')"
84 return '<?php\|<?=\=:?>,' ..
85 \ '\<if\>:\<elseif\>:\<else\>:\<endif\>,' ..
86 \ '\<switch\>:\<case\>:\<break\>:\<continue\>:\<endswitch\>,' ..
87 \ '\<while\>.\{-})\s*\::\<break\>:\<continue\>:\<endwhile\>,' ..
88 \ '\<do\>:\<break\>:\<continue\>:\<while\>,' ..
89 \ '\<for\>:\<break\>:\<continue\>:\<endfor\>,' ..
90 \ '\<foreach\>:\<break\>:\<continue\>:\<endforeach\>,' ..
91 \ '\%(<<<\s*\)\@<=''\=\(\h\w*\)''\=:^\s*\1\>'
92
93 " TODO: these probably aren't worth adding and really need syntax support
94 " '<\_s*script\_s*language\_s*=\_s*[''"]\=\_s*php\_s*[''"]\=\_s*>:<\_s*\_s*/\_s*script\_s*>,' ..
95 " '<%:%>,' ..
96 else
97 let b:match_skip = "PhpMatchSkip('php')"
98 return s:match_words
99 endif
100 endfunction
101 endif
102 if !exists("*PhpMatchSkip")
103 function! PhpMatchSkip(skip)
104 let name = synIDattr(synID(line('.'), col('.'), 1), 'name')
105 if a:skip == "html"
106 " ?> in line comments will also be correctly matched as Delimiter
107 return name =~? 'comment\|string' || name !~? 'php\|delimiter'
108 else " php
109 return name =~? 'comment\|string\|php'
110 endif
111 endfunction
112 endif
113 let b:undo_ftplugin ..= " | unlet! b:match_skip"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000114endif
115" ###
116
Bram Moolenaar48c3f4e2022-08-08 15:42:38 +0100117" Change the :browse e filter to primarily show PHP-related files.
118if (has("gui_win32") || has("gui_gtk")) && exists("b:html_set_browsefilter")
119 let b:browsefilter = "PHP Files (*.php)\t*.php\n" ..
120 \ "PHP Test Files (*.phpt)\t*.phpt\n" ..
121 \ s:browsefilter
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000122endif
123
Bram Moolenaar48c3f4e2022-08-08 15:42:38 +0100124if !exists("no_plugin_maps") && !exists("no_php_maps")
125 " Section jumping: [[ and ]] provided by Antony Scriven <adscriven at gmail dot com>
126 let s:function = '\%(abstract\s\+\|final\s\+\|private\s\+\|protected\s\+\|public\s\+\|static\s\+\)*function'
127 let s:class = '\%(abstract\s\+\|final\s\+\)*class'
128 let s:section = escape('^\s*\zs\%(' .. s:function .. '\|' .. s:class .. '\|interface\|trait\|enum\)\>', "|")
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000129
Bram Moolenaar48c3f4e2022-08-08 15:42:38 +0100130 function! s:Jump(pattern, count, flags)
131 normal! m'
132 for i in range(a:count)
133 if !search(a:pattern, a:flags)
134 break
135 endif
136 endfor
137 endfunction
Bram Moolenaar071d4272004-06-13 20:20:40 +0000138
Bram Moolenaar48c3f4e2022-08-08 15:42:38 +0100139 for mode in ["n", "o", "x"]
140 exe mode .. "noremap <buffer> <silent> ]] <Cmd>call <SID>Jump('" .. s:section .. "', v:count1, 'W')<CR>"
141 exe mode .. "noremap <buffer> <silent> [[ <Cmd>call <SID>Jump('" .. s:section .. "', v:count1, 'bW')<CR>"
142 let b:undo_ftplugin ..= " | sil! exe '" .. mode .. "unmap <buffer> ]]'" ..
143 \ " | sil! exe '" .. mode .. "unmap <buffer> [['"
144 endfor
145endif
146
147let b:undo_ftplugin ..= " | " .. s:undo_ftplugin
Bram Moolenaar071d4272004-06-13 20:20:40 +0000148
149" Restore the saved compatibility options.
Bram Moolenaar9a7224b2012-04-30 15:56:52 +0200150let &cpo = s:keepcpo
151unlet s:keepcpo
Bram Moolenaar48c3f4e2022-08-08 15:42:38 +0100152
153" vim: nowrap sw=2 sts=2 ts=8 noet: