codekingpro/portable-devtools
115k
1" Vim filetype plugin file2" Language: PHP3" Maintainer: Doug Kearns <dougkearns@gmail.com>4" Previous Maintainer: Dan Sharp5" Last Change: 2024 Jan 146" Last Change: 2024 May 23 by Riley Bruins <ribru17@gmail.com> ('commentstring')7 8if exists("b:did_ftplugin")9 finish10endif11 12" Make sure the continuation lines below do not cause problems in13" compatibility mode.14let s:keepcpo= &cpo15set cpo&vim16 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")21 let s:browsefilter ..= "All Files (*.*)\t*\n"22else23 let s:browsefilter ..= "All Files (*)\t*\n"24endif25let s:match_words = ""26 27runtime! ftplugin/html.vim ftplugin/html_*.vim ftplugin/html/*.vim28let b:did_ftplugin = 129 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<"33 let s:undo_ftplugin = b:undo_ftplugin34endif35if exists("b:browsefilter")36" let b:undo_ftplugin ..= " | unlet! b:browsefilter b:html_set_browsefilter"37 let s:browsefilter = b:browsefilter38endif39if exists("b:match_words")40" let b:undo_ftplugin ..= " | unlet! b:match_ignorecase b:match_words b:html_set_match_words"41 let s:match_words = b:match_words42endif43if exists("b:match_skip")44 unlet b:match_skip45endif46 47setlocal comments=s1:/*,mb:*,ex:*/,://,:#48setlocal commentstring=/*\ %s\ */49setlocal formatoptions+=l formatoptions-=t50 51if get(g:, "php_autocomment", 1)52 setlocal formatoptions+=croq53 " NOTE: set g:PHP_autoformatcomment = 0 to prevent the indent plugin from54 " overriding this 'comments' value 55 setlocal comments-=:#56 " space after # comments to exclude attributes57 setlocal comments+=b:#58endif59 60if exists('&omnifunc')61 setlocal omnifunc=phpcomplete#CompletePHP62endif63 64setlocal suffixesadd=.php65 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")75 let b:match_ignorecase = 176 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 phpRegion81 " matchgroups, without a "php" prefix, so use the stack to test for the82 " outer phpRegion group. This also means the closing ?> tag which is83 " outside of the matched region just uses the Delimiter group for the84 " 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 support99 " '<\_s*script\_s*language\_s*=\_s*[''"]\=\_s*php\_s*[''"]\=\_s*>:<\_s*\_s*/\_s*script\_s*>,' ..100 " '<%:%>,' ..101 else102 let b:match_skip = "PhpMatchSkip('php')"103 return s:match_words104 endif105 endfunction106 endif107 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 Delimiter112 return name =~? 'comment\|string' || name !~? 'php\|delimiter'113 else " php114 return name =~? 'comment\|string\|php'115 endif116 endfunction117 endif118 let b:undo_ftplugin ..= " | unlet! b:match_skip"119endif120" ###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")124 let b:browsefilter = "PHP Files (*.php)\t*.php\n" ..125 \ "PHP Test Files (*.phpt)\t*.phpt\n" ..126 \ s:browsefilter127endif128 129if !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\)\>', "|")134 135 function! s:Jump(pattern, count, flags)136 normal! m'137 for i in range(a:count)138 if !search(a:pattern, a:flags)139 break140 endif141 endfor142 endfunction143 144 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 endfor150endif151 152let b:undo_ftplugin ..= " | " .. s:undo_ftplugin153 154" Restore the saved compatibility options.155let &cpo = s:keepcpo156unlet s:keepcpo157 158" vim: nowrap sw=2 sts=2 ts=8 noet:159 