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