Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | " Vim filetype plugin file |
Bram Moolenaar | 48c3f4e | 2022-08-08 15:42:38 +0100 | [diff] [blame] | 2 | " Language: PHP |
| 3 | " Maintainer: Doug Kearns <dougkearns@gmail.com> |
| 4 | " Previous Maintainer: Dan Sharp |
Doug Kearns | 93197fd | 2024-01-14 20:59:02 +0100 | [diff] [blame] | 5 | " Last Change: 2024 Jan 14 |
Riley Bruins | 0a08306 | 2024-06-03 20:40:45 +0200 | [diff] [blame] | 6 | " Last Change: 2024 May 23 by Riley Bruins <ribru17@gmail.com> ('commentstring') |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7 | |
Bram Moolenaar | 48c3f4e | 2022-08-08 15:42:38 +0100 | [diff] [blame] | 8 | if exists("b:did_ftplugin") |
| 9 | finish |
| 10 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 11 | |
| 12 | " Make sure the continuation lines below do not cause problems in |
| 13 | " compatibility mode. |
Bram Moolenaar | 9a7224b | 2012-04-30 15:56:52 +0200 | [diff] [blame] | 14 | let s:keepcpo= &cpo |
| 15 | set cpo&vim |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 16 | |
| 17 | " Define some defaults in case the included ftplugins don't set them. |
| 18 | let s:undo_ftplugin = "" |
Doug Kearns | 93197fd | 2024-01-14 20:59:02 +0100 | [diff] [blame] | 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 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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") |
Bram Moolenaar | 48c3f4e | 2022-08-08 15:42:38 +0100 | [diff] [blame] | 32 | " let b:undo_ftplugin = "setlocal comments< commentstring< formatoptions< omnifunc<" |
| 33 | let s:undo_ftplugin = b:undo_ftplugin |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 34 | endif |
| 35 | if exists("b:browsefilter") |
Bram Moolenaar | 48c3f4e | 2022-08-08 15:42:38 +0100 | [diff] [blame] | 36 | " let b:undo_ftplugin ..= " | unlet! b:browsefilter b:html_set_browsefilter" |
| 37 | let s:browsefilter = b:browsefilter |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 38 | endif |
| 39 | if exists("b:match_words") |
Bram Moolenaar | 48c3f4e | 2022-08-08 15:42:38 +0100 | [diff] [blame] | 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 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 42 | endif |
Bram Moolenaar | c81e5e7 | 2007-05-05 18:24:42 +0000 | [diff] [blame] | 43 | if exists("b:match_skip") |
Bram Moolenaar | 48c3f4e | 2022-08-08 15:42:38 +0100 | [diff] [blame] | 44 | unlet b:match_skip |
Bram Moolenaar | c81e5e7 | 2007-05-05 18:24:42 +0000 | [diff] [blame] | 45 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 46 | |
Bram Moolenaar | 48c3f4e | 2022-08-08 15:42:38 +0100 | [diff] [blame] | 47 | setlocal comments=s1:/*,mb:*,ex:*/,://,:# |
Riley Bruins | 0a08306 | 2024-06-03 20:40:45 +0200 | [diff] [blame] | 48 | setlocal commentstring=/*\ %s\ */ |
Bram Moolenaar | 48c3f4e | 2022-08-08 15:42:38 +0100 | [diff] [blame] | 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:# |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 58 | endif |
| 59 | |
Bram Moolenaar | 48c3f4e | 2022-08-08 15:42:38 +0100 | [diff] [blame] | 60 | if exists('&omnifunc') |
| 61 | setlocal omnifunc=phpcomplete#CompletePHP |
| 62 | endif |
| 63 | |
| 64 | setlocal suffixesadd=.php |
| 65 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 66 | " ### |
| 67 | " Provided by Mikolaj Machowski <mikmach at wp dot pl> |
| 68 | setlocal include=\\\(require\\\|include\\\)\\\(_once\\\)\\\? |
Bram Moolenaar | c1a11ed | 2008-06-24 22:09:24 +0000 | [diff] [blame] | 69 | " Disabled changing 'iskeyword', it breaks a command such as "*" |
| 70 | " setlocal iskeyword+=$ |
| 71 | |
Bram Moolenaar | 48c3f4e | 2022-08-08 15:42:38 +0100 | [diff] [blame] | 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" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 119 | endif |
| 120 | " ### |
| 121 | |
Bram Moolenaar | 48c3f4e | 2022-08-08 15:42:38 +0100 | [diff] [blame] | 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 |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 127 | endif |
| 128 | |
Bram Moolenaar | 48c3f4e | 2022-08-08 15:42:38 +0100 | [diff] [blame] | 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\)\>', "|") |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 134 | |
Bram Moolenaar | 48c3f4e | 2022-08-08 15:42:38 +0100 | [diff] [blame] | 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 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 143 | |
Bram Moolenaar | 48c3f4e | 2022-08-08 15:42:38 +0100 | [diff] [blame] | 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 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 153 | |
| 154 | " Restore the saved compatibility options. |
Bram Moolenaar | 9a7224b | 2012-04-30 15:56:52 +0200 | [diff] [blame] | 155 | let &cpo = s:keepcpo |
| 156 | unlet s:keepcpo |
Bram Moolenaar | 48c3f4e | 2022-08-08 15:42:38 +0100 | [diff] [blame] | 157 | |
| 158 | " vim: nowrap sw=2 sts=2 ts=8 noet: |