vim

Fork of vim, an acceptable text editor
git clone git://git.laack.co/vim.git
Log | Files | Refs | README | LICENSE

php.vim (5559B)


      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 
      8 if exists("b:did_ftplugin")
      9   finish
     10 endif
     11 
     12 " Make sure the continuation lines below do not cause problems in
     13 " compatibility mode.
     14 let s:keepcpo= &cpo
     15 set cpo&vim
     16 
     17 " Define some defaults in case the included ftplugins don't set them.
     18 let s:undo_ftplugin = ""
     19 let s:browsefilter = "HTML Files (*.html, *.htm)\t*.html;*.htm\n"
     20 if has("win32")
     21     let s:browsefilter ..= "All Files (*.*)\t*\n"
     22 else
     23     let s:browsefilter ..= "All Files (*)\t*\n"
     24 endif
     25 let s:match_words = ""
     26 
     27 runtime! ftplugin/html.vim ftplugin/html_*.vim ftplugin/html/*.vim
     28 let b:did_ftplugin = 1
     29 
     30 " Override our defaults if these were set by an included ftplugin.
     31 if exists("b:undo_ftplugin")
     32 " let b:undo_ftplugin = "setlocal comments< commentstring< formatoptions< omnifunc<"
     33   let s:undo_ftplugin = b:undo_ftplugin
     34 endif
     35 if exists("b:browsefilter")
     36 " let b:undo_ftplugin ..= " | unlet! b:browsefilter b:html_set_browsefilter"
     37   let s:browsefilter = b:browsefilter
     38 endif
     39 if 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_words
     42 endif
     43 if exists("b:match_skip")
     44   unlet b:match_skip
     45 endif
     46 
     47 setlocal comments=s1:/*,mb:*,ex:*/,://,:#
     48 setlocal commentstring=/*\ %s\ */
     49 setlocal formatoptions+=l formatoptions-=t
     50 
     51 if 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:#
     58 endif
     59 
     60 if exists('&omnifunc')
     61   setlocal omnifunc=phpcomplete#CompletePHP
     62 endif
     63 
     64 setlocal suffixesadd=.php
     65 
     66 " ###
     67 " Provided by Mikolaj Machowski <mikmach at wp dot pl>
     68 setlocal include=\\\(require\\\|include\\\)\\\(_once\\\)\\\?
     69 " Disabled changing 'iskeyword', it breaks a command such as "*"
     70 " setlocal iskeyword+=$
     71 
     72 let b:undo_ftplugin = "setlocal include< suffixesadd<"
     73 
     74 if 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"
    119 endif
    120 " ###
    121 
    122 " Change the :browse e filter to primarily show PHP-related files.
    123 if (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
    127 endif
    128 
    129 if !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 	break
    140       endif
    141     endfor
    142   endfunction
    143 
    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   endfor
    150 endif
    151 
    152 let b:undo_ftplugin ..= " | " .. s:undo_ftplugin
    153 
    154 " Restore the saved compatibility options.
    155 let &cpo = s:keepcpo
    156 unlet s:keepcpo
    157 
    158 " vim: nowrap sw=2 sts=2 ts=8 noet: