3
3
" Author: John Wellesz <John.wellesz (AT) teaser (DOT) fr>
4
4
" URL: http://www.2072productions.com/vim/indent/php.vim
5
" Last Change: 2008 June 7th
5
" Last Change: 2008 November 22nd
6
6
" Newsletter: http://www.2072productions.com/?to=php-indent-for-vim-newsletter.php
9
" If you find a bug, please e-mail me at John.wellesz (AT) teaser (DOT) fr
10
" with an example of code that breaks the algorithm.
12
" ---> The change log and all the comments have been removed from this file.
14
" For a complete change log and fully commented code, download the script on
15
" 2072productions.com at the URI provided above.
17
10
" If you find a bug, please e-mail me at John.wellesz (AT) teaser (DOT) fr
18
11
" with an example of code that breaks the algorithm.
24
17
" NOTE: This script must be used with PHP syntax ON and with the php syntax
25
18
" script by Lutz Eymers (http://www.isp.de/data/php.vim ) or with the
26
19
" script by Peter Hodge (http://www.vim.org/scripts/script.php?script_id=1571 )
27
" the later is bunbdled by default with vim 7.
20
" the later is bunbdled by default with Vim 7.
30
23
" In the case you have syntax errors in your script such as HereDoc end
33
26
" they are followed by a ';').
36
" NOTE: If you are editing file in Unix file format and that (by accident)
37
" there are '\r' before new lines, this script won't be able to proceed
38
" correctly and will make many mistakes because it won't be able to match
40
" So you have to remove those useless characters first with a command like:
44
" or simply 'let' the option PHP_removeCRwhenUnix to 1 and the script will
45
" silently remove them when VIM load this script (at each bufread).
48
" Options: PHP_autoformatcomment = 0 to not enable autoformating of comment by
49
" default, if set to 0, this script will let the 'formatoptions' setting intact.
51
" Options: PHP_default_indenting = # of sw (default is 0), # of sw will be
52
" added to the indent of each line of PHP code.
54
" Options: PHP_removeCRwhenUnix = 1 to make the script automatically remove CR
55
" at end of lines (by default this option is unset), NOTE that you
56
" MUST remove CR when the fileformat is UNIX else the indentation
59
" Options: PHP_BracesAtCodeLevel = 1 to indent the '{' and '}' at the same
60
" level than the code they contain.
74
" NOTE: The script will be a bit slower if you use this option because
75
" some optimizations won't be available.
77
" Options: PHP_vintage_case_default_indent = 1 (defaults to 0) to add a meaningless indent
78
" befaore 'case:' and 'default":' statement in switch block
29
" NOTE: If you are editing files in Unix file format and that (by accident)
30
" there are '\r' before new lines, this script won't be able to proceed
31
" correctly and will make many mistakes because it won't be able to match
33
" So you have to remove those useless characters first with a command like:
37
" or simply 'let' the option PHP_removeCRwhenUnix to 1 and the script will
38
" silently remove them when VIM load this script (at each bufread).
40
" Options: See :help php-indent for available options.
81
43
if exists("b:did_indent")
317
280
let s:notPhpHereDoc = '\%(break\|return\|continue\|exit\|else\)'
318
281
let s:blockstart = '\%(\%(\%(}\s*\)\=else\%(\s\+\)\=\)\=if\>\|else\>\|while\>\|switch\>\|for\%(each\)\=\>\|declare\>\|class\>\|interface\>\|abstract\>\|try\>\|catch\>\)'
320
let s:autorestoptions = 0
321
if ! s:autorestoptions
322
au BufWinEnter,Syntax *.php,*.php3,*.php4,*.php5 call ResetOptions()
323
let s:autorestoptions = 1
283
let s:autoresetoptions = 0
284
if ! s:autoresetoptions
285
let s:autoresetoptions = 1
326
function! ResetOptions()
288
function! ResetPhpOptions()
289
if ! b:optionsset && &filetype == "php"
328
290
if b:PHP_autoformatcomment
330
292
setlocal comments=s1:/*,mb:*,ex:*/,://,:#
360
324
if !b:PHP_indentinghuge && b:PHP_lastindented > b:PHP_indentbeforelast
361
325
if b:PHP_indentbeforelast
362
326
let b:PHP_indentinghuge = 1
363
echom 'Large indenting detected, speed optimizations engaged (v1.28)'
327
echom 'Large indenting detected, speed optimizations engaged (v1.30)'
365
329
let b:PHP_indentbeforelast = b:PHP_lastindented
715
680
elseif last_line =~ '^\s*'.s:blockstart
716
681
let ind = ind + &sw
718
elseif last_line =~# defaultORcase
683
elseif last_line =~# defaultORcase && cline !~# defaultORcase
719
684
let ind = ind + &sw
722
elseif pline =~ '\%(;\%(\s*?>\)\=\|<<<''\=\a\w*''\=$\|^\s*}\|{\)'.endline . '\|' . defaultORcase
687
elseif pline =~ '\%(;\%(\s*?>\)\=\|<<<''\=\a\w*''\=$\|^\s*}\|{\)'.endline . '\|' . defaultORcase && cline !~# defaultORcase
724
689
let ind = ind + &sw