robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
0bb2f5cc08
master
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 8if exists ( "b:did_ftplugin" ) 9finish 10endif 11 12" Make sure the continuation lines below do not cause problems in 13" compatibility mode. 14let s: keepcpo = & cpo 15set cpo & vim 16 17" Define some defaults in case the included ftplugins don't set them. 18let s: undo_ftplugin = "" 19let s: browsefilter = "HTML Files (*.html, *.htm)\t*.html;*.htm\n" 20if has ( "win32" ) 21let s: browsefilter ..= "All Files (*.*)\t*\n" 22else 23let s: browsefilter ..= "All Files (*)\t*\n" 24endif 25let s: match_words = "" 26 27runtime ! ftplugin/html[.]{vim,lua} ftplugin/html_*.{vim,lua} ftplugin/html/*.{vim,lua} 28let b: did_ftplugin = 1 29 30" Override our defaults if these were set by an included ftplugin. 31if exists ( "b:undo_ftplugin" ) 32" let b:undo_ftplugin = "setlocal comments< commentstring< formatoptions< omnifunc<" 33let s: undo_ftplugin = b: undo_ftplugin 34endif 35if exists ( "b:browsefilter" ) 36" let b:undo_ftplugin ..= " | unlet! b:browsefilter b:html_set_browsefilter" 37let s: browsefilter = b: browsefilter 38endif 39if exists ( "b:match_words" ) 40" let b:undo_ftplugin ..= " | unlet! b:match_ignorecase b:match_words b:html_set_match_words" 41let s: match_words = b: match_words 42endif 43if exists ( "b:match_skip" ) 44unlet b: match_skip 45endif 46 47setlocal comments = s1:/*,mb:*,ex:*/,://,:# 48setlocal commentstring = /*\ %s\ */ 49setlocal formatoptions += lformatoptions -= t 50 51if get ( g:, "php_autocomment" , 1 ) 52setlocal formatoptions += croq 53" NOTE: set g:PHP_autoformatcomment = 0 to prevent the indent plugin from 54" overriding this 'comments' value 55setlocal comments -= :# 56" space after # comments to exclude attributes 57setlocal comments += b:# 58endif 59 60if exists ( '&omnifunc' ) 61setlocal omnifunc = phpcomplete#CompletePHP 62endif 63 64setlocal suffixesadd = .php 65 66" ### 67" Provided by Mikolaj Machowski <mikmach at wp dot pl> 68setlocal include = \\\(require\\\|include\\\)\\\(_once\\\)\\\? 69" Disabled changing 'iskeyword', it breaks a command such as "*" 70" setlocal iskeyword+=$ 71 72let b: undo_ftplugin = "setlocal include< suffixesadd<" 73 74if exists ( "loaded_matchit" ) && exists ( "b:html_set_match_words" ) 75let b: match_ignorecase = 1 76let b: match_words = 'PhpMatchWords()' 77 78if ! exists ( "*PhpMatchWords" ) 79function ! 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. 85let stack = synstack ( line ( '.' ), col ( '.' )) 86let php_region = ! empty ( stack ) && synIDattr ( stack [ 0 ], "name" ) =~# '\<php' 87if php_region || getline ( "." ) =~ '.\=\%.c\&?>' 88let b: match_skip = "PhpMatchSkip('html')" 89return '<?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" '<%:%>,' .. 101else 102let b: match_skip = "PhpMatchSkip('php')" 103return s: match_words 104endif 105endfunction 106endif 107if ! exists ( "*PhpMatchSkip" ) 108function ! PhpMatchSkip ( skip ) 109let name = synIDattr ( synID ( line ( '.' ), col ( '.' ), 1 ), 'name' ) 110if a: skip == "html" 111" ?> in line comments will also be correctly matched as Delimiter 112return name =~? 'comment\|string' || name !~? 'php\|delimiter' 113else " php 114return name =~? 'comment\|string\|php' 115endif 116endfunction 117endif 118let b: undo_ftplugin ..= " | unlet! b:match_skip" 119endif 120" ### 121 122" Change the :browse e filter to primarily show PHP-related files. 123if ( has ( "gui_win32" ) || has ( "gui_gtk" )) && exists ( "b:html_set_browsefilter" ) 124let b: browsefilter = "PHP Files (*.php)\t*.php\n" .. 125 \"PHP Test Files (*.phpt)\t*.phpt\n" .. 126 \s: browsefilter 127endif 128 129if ! exists ( "no_plugin_maps" ) && ! exists ( "no_php_maps" ) 130" Section jumping: [[ and ]] provided by Antony Scriven <adscriven at gmail dot com> 131let s: function = '\%(abstract\s\+\|final\s\+\|private\s\+\|protected\s\+\|public\s\+\|static\s\+\)*function' 132let s: class = '\%(abstract\s\+\|final\s\+\)*class' 133let s: section = escape ( '^\s*\zs\%(' .. s: function .. '\|' .. s: class .. '\|interface\|trait\|enum\)\>' , "|" ) 134 135function ! s: Jump ( pattern , count , flags ) 136normal ! m' 137for i in range ( a: count ) 138if ! search ( a: pattern , a: flags ) 139break 140endif 141endfor 142endfunction 143 144for mode in [ "n" , "o" , "x" ] 145exe mode .. "noremap <buffer> <silent> ]] <Cmd>call <SID>Jump('" .. s: section .. "', v:count1, 'W')<CR>" 146exe mode .. "noremap <buffer> <silent> [[ <Cmd>call <SID>Jump('" .. s: section .. "', v:count1, 'bW')<CR>" 147let b: undo_ftplugin ..= " | sil! exe '" .. mode .. "unmap <buffer> ]]'" .. 148 \" | sil! exe '" .. mode .. "unmap <buffer> [['" 149endfor 150endif 151 152let b: undo_ftplugin ..= " | " .. s: undo_ftplugin 153 154" Restore the saved compatibility options. 155let & cpo = s: keepcpo 156unlet s: keepcpo 157 158" vim: nowrap sw=2 sts=2 ts=8 noet: