Skip to content

Commit

Permalink
Update indent script to 1.35
Browse files Browse the repository at this point in the history
  • Loading branch information
hlissner committed Mar 9, 2013
1 parent 99ed976 commit 2129ebb
Showing 1 changed file with 39 additions and 18 deletions.
57 changes: 39 additions & 18 deletions indent/php.vim
Expand Up @@ -2,9 +2,17 @@
" Language: PHP
" Author: John Wellesz <John.wellesz (AT) teaser (DOT) fr>
" URL: http://www.2072productions.com/vim/indent/php.vim
" Last Change: 2010 July 26th
" Last Change: 2011 October 23rd
" Newsletter: http://www.2072productions.com/?to=php-indent-for-vim-newsletter.php
" Version: 1.33
" Version: 1.35
"
" Changes: 1.35 - New option: PHP_outdentSLComments to add extra
" indentation to single-line comments.
"
"
" Changes: 1.34 - Fix: string with /* would be treated as comment
" start when using single quote. (Thanks to Manic Chuang
" for the fix)
"
"
" Changes: 1.33 - Rewrote Switch(){case:default:} handling from
Expand Down Expand Up @@ -247,7 +255,7 @@
" NOTE: This script must be used with PHP syntax ON and with the php syntax
" script by Lutz Eymers (http://www.isp.de/data/php.vim ) or with the
" script by Peter Hodge (http://www.vim.org/scripts/script.php?script_id=1571 )
" the later is bundled by default with Vim 7.
" the later is bunbdled by default with Vim 7.
"
"
" In the case you have syntax errors in your script such as HereDoc end
Expand Down Expand Up @@ -303,6 +311,8 @@
" Options: PHP_vintage_case_default_indent = 1 (defaults to 0) to add a meaningless indent
" befaore 'case:' and 'default":' statement in switch blocks.
"
" Options: PHP_outdentSLComments = # of sw (defaults to 0) to outdent single line PHP
" comments (// and # or /**/).
"
" Remove all the comments from this file:
" :%s /^\s*".*\({{{\|xxx\)\@<!\n\c//g
Expand All @@ -324,13 +334,20 @@ let b:did_indent = 1
let php_sync_method = 0


" Apply PHP_default_indenting option
" Apply options

if exists("PHP_default_indenting")
let b:PHP_default_indenting = PHP_default_indenting * &sw
else
let b:PHP_default_indenting = 0
endif

if exists("PHP_outdentSLComments")
let b:PHP_outdentSLComments = PHP_outdentSLComments * &sw
else
let b:PHP_outdentSLComments = 0
endif

if exists("PHP_BracesAtCodeLevel")
let b:PHP_BracesAtCodeLevel = PHP_BracesAtCodeLevel
else
Expand Down Expand Up @@ -500,11 +517,13 @@ function! Skippmatch2()

let line = getline(".")

if line =~ '\%(".*\)\@<=/\*\%(.*"\)\@=' || line =~ '\%(\%(//\|#\).*\)\@<=/\*'
return 1
else
return 0
endif
" Skip opening /* if they are inside a string or preceded by a single
" line comment starter
if line =~ "\\([\"']\\).*/\\*.*\\1" || line =~ '\%(//\|#\).*/\*'
return 1
else
return 0
endif
endfun

function! Skippmatch() " {{{
Expand Down Expand Up @@ -717,7 +736,7 @@ function! GetPhpIndent()
if !b:PHP_indentinghuge && b:PHP_lastindented > b:PHP_indentbeforelast
if b:PHP_indentbeforelast
let b:PHP_indentinghuge = 1
echom 'Large indenting detected, speed optimizations engaged (v1.33)'
" echom 'Large indenting detected, speed optimizations engaged (v1.34)'
endif
let b:PHP_indentbeforelast = b:PHP_lastindented
endif
Expand All @@ -727,7 +746,7 @@ function! GetPhpIndent()
" status variable (we restart from scratch)
if b:InPHPcode_checked && prevnonblank(v:lnum - 1) != b:PHP_lastindented
if b:PHP_indentinghuge
echom 'Large indenting deactivated'
" echom 'Large indenting deactivated'
let b:PHP_indentinghuge = 0
let b:PHP_CurrentIndentLevel = b:PHP_default_indenting
endif
Expand Down Expand Up @@ -884,7 +903,9 @@ function! GetPhpIndent()

" Align correctly multi // or # lines
" Indent successive // or # comment the same way the first is {{{
let addSpecial = 0
if cline =~ '^\s*\%(//\|#\|/\*.*\*/\s*$\)'
let addSpecial = b:PHP_outdentSLComments
if b:PHP_LastIndentedWasComment == 1
return indent(real_PHP_lastindented)
endif
Expand Down Expand Up @@ -956,7 +977,7 @@ function! GetPhpIndent()

" Hit the start of the file, use default indent.
if lnum == 0
return b:PHP_default_indenting
return b:PHP_default_indenting + addSpecial
endif


Expand Down Expand Up @@ -998,9 +1019,9 @@ function! GetPhpIndent()
if last_line =~ '[;}]'.endline && last_line !~ '^)' && last_line !~# s:defaultORcase " Added && last_line !~ '^)' on 2007-12-30
if ind==b:PHP_default_indenting
" if no indentation for the previous line
return b:PHP_default_indenting
return b:PHP_default_indenting + addSpecial
elseif b:PHP_indentinghuge && ind==b:PHP_CurrentIndentLevel && cline !~# '^\s*\%(else\|\%(case\|default\).*:\|[})];\=\)' && last_line !~# '^\s*\%(\%(}\s*\)\=else\)' && getline(GetLastRealCodeLNum(lnum - 1))=~';'.endline
return b:PHP_CurrentIndentLevel
return b:PHP_CurrentIndentLevel + addSpecial
endif
endif

Expand Down Expand Up @@ -1056,7 +1077,7 @@ function! GetPhpIndent()
let ind = ind + &sw " we indent one level further when the preceding line is not stated
"echo "42"
"call getchar()
return ind
return ind + addSpecial

" If the last line is terminated by ';' or if it's a closing '}'
" We need to check if this isn't the end of a multilevel non '{}'
Expand Down Expand Up @@ -1169,7 +1190,7 @@ function! GetPhpIndent()
" from acting in some special cases
let b:PHP_CurrentIndentLevel = b:PHP_default_indenting

return ind
return ind + addSpecial
endif
" if nothing was done lets the old script continue
endif
Expand Down Expand Up @@ -1214,7 +1235,7 @@ function! GetPhpIndent()
" case and default are not indented inside blocks
let b:PHP_CurrentIndentLevel = ind

return ind
return ind + addSpecial
endif

" If the last line isn't empty and ends with a '),' then check if the
Expand Down Expand Up @@ -1263,7 +1284,7 @@ function! GetPhpIndent()
endif

let b:PHP_CurrentIndentLevel = ind
return ind
return ind + addSpecial
endfunction

" vim: set ts=8 sw=4 sts=4:

0 comments on commit 2129ebb

Please sign in to comment.