summaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
Diffstat (limited to 'runtime')
-rw-r--r--runtime/doc/indent.txt12
-rw-r--r--runtime/doc/todo.txt3
-rw-r--r--runtime/indent/php.vim116
3 files changed, 84 insertions, 47 deletions
diff --git a/runtime/doc/indent.txt b/runtime/doc/indent.txt
index 4282ba23b..637847321 100644
--- a/runtime/doc/indent.txt
+++ b/runtime/doc/indent.txt
@@ -1,4 +1,4 @@
-*indent.txt* For Vim version 7.3c. Last change: 2010 Mar 27
+*indent.txt* For Vim version 7.3c. Last change: 2010 Jul 30
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -549,7 +549,7 @@ those useless characters first with a command like: >
:%s /\r$//g
Or, you can simply |:let| the variable PHP_removeCRwhenUnix to 1 and the
-script will silently remove them when Vim loads a PHP file (at each |BufRead|).
+script will silently remove them when Vim loads a PHP file (at each|BufRead|).
OPTIONS: ~
@@ -557,7 +557,7 @@ PHP indenting can be altered in several ways by modifying the values of some
variables:
*php-comment*
-To not enable auto-formatting of comments by default (if you want to use your
+To not enable auto-formating of comments by default (if you want to use your
own 'formatoptions'): >
:let g:PHP_autoformatcomment = 0
@@ -584,6 +584,10 @@ For example, with N = 1, this will give:
(Notice the extra indent between the PHP container markers and the code)
-------------
+To indent PHP tags as the surrounding code: >
+ :let g:PHP_outdentphpescape = 0
+-------------
+
To automatically remove '\r' characters when the 'fileformat' is set to Unix: >
:let g:PHP_removeCRwhenUnix = 1
-------------
@@ -609,7 +613,7 @@ NOTE: Indenting will be a bit slower if this option is used because some
To indent 'case:' and 'default:' statements in switch() blocks: >
:let g:PHP_vintage_case_default_indent = 1
-(By default they are indented at the same level than the 'switch()' to avoid
+(Since in PHP braces are not required inside 'case/default' blocks, by default they are indented at the same level than the 'switch()' to avoid
unnecessary indentation)
diff --git a/runtime/doc/todo.txt b/runtime/doc/todo.txt
index 4d1068d61..443b4372e 100644
--- a/runtime/doc/todo.txt
+++ b/runtime/doc/todo.txt
@@ -77,6 +77,9 @@ Results in E670. (Tony Mechelynck, 2010 May 2)
":helpgrep" does not put the cursor in the correct column when preceded by
accented character. (Tony Mechelynck, 2010 Apr 15)
+Patch: Let rare word highlighting overrule good word highlighting.
+(Jakson A. Aquino, 2010 Jul 30)
+
Better Czech keymap. (Stepnem, 2010 May 4) Use if no response from Jiri
Tobisek.
diff --git a/runtime/indent/php.vim b/runtime/indent/php.vim
index 9f1a1ed9d..bc196ed3c 100644
--- a/runtime/indent/php.vim
+++ b/runtime/indent/php.vim
@@ -2,12 +2,13 @@
" Language: PHP
" Author: John Wellesz <John.wellesz (AT) teaser (DOT) fr>
" URL: http://www.2072productions.com/vim/indent/php.vim
-" Last Change: 2008 November 22nd
-" Newsletter: http://www.2072productions.com/?to=php-indent-for-vim-newsletter.php
-" Version: 1.30
+" Last Change: 2010 Jully 26th
+" Newsletter: http://www.2072productions.com/?to=php-indent-for-vim-newsletter.php
+" Version: 1.33
"
"
-" If you find a bug, please e-mail me at John.wellesz (AT) teaser (DOT) fr
+" If you find a bug, please report it on GitHub:
+" http://github.com/2072/PHP-Indenting-for-VIm/issues
" with an example of code that breaks the algorithm.
"
"
@@ -15,7 +16,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 Lutz Eymers (http://www.ipdienste.net/data/php.vim ) or with the
" script by Peter Hodge (http://www.vim.org/scripts/script.php?script_id=1571 )
" the later is bunbdled by default with Vim 7.
"
@@ -68,8 +69,15 @@ else
let b:PHP_autoformatcomment = 1
endif
-if exists("PHP_vintage_case_default_indent")
- let b:PHP_vintage_case_default_indent = PHP_vintage_case_default_indent
+if exists("PHP_outdentphpescape")
+ let b:PHP_outdentphpescape = PHP_outdentphpescape
+else
+ let b:PHP_outdentphpescape = 1
+endif
+
+
+if exists("PHP_vintage_case_default_indent") && PHP_vintage_case_default_indent
+ let b:PHP_vintage_case_default_indent = 1
else
let b:PHP_vintage_case_default_indent = 0
endif
@@ -108,12 +116,11 @@ endif
if exists("*GetPhpIndent")
call ResetPhpOptions()
- finish " XXX
+ finish
endif
let s:endline= '\s*\%(//.*\|#.*\|/\*.*\*/\s*\)\=$'
let s:PHP_startindenttag = '<?\%(.*?>\)\@!\|<script[^>]*>\%(.*<\/script>\)\@!'
-"setlocal debug=msg " XXX
function! GetLastRealCodeLNum(startline) " {{{
@@ -164,8 +171,8 @@ function! GetLastRealCodeLNum(startline) " {{{
endif
- elseif lastline =~? '^\a\w*;\=$' && lastline !~? s:notPhpHereDoc " XXX 0607
- let tofind=substitute( lastline, '\(\a\w*\);\=', '<<<''\\=\1''\\=$', '') " XXX 0607
+ elseif lastline =~? '^\a\w*;\=$' && lastline !~? s:notPhpHereDoc
+ let tofind=substitute( lastline, '\(\a\w*\);\=', '<<<''\\=\1''\\=$', '')
while getline(lnum) !~? tofind && lnum > 1
let lnum = lnum - 1
endwhile
@@ -174,7 +181,7 @@ function! GetLastRealCodeLNum(startline) " {{{
endif
endwhile
- if lnum==1 && getline(lnum)!~ '<?'
+ if lnum==1 && getline(lnum) !~ '<?'
let lnum=0
endif
@@ -198,7 +205,7 @@ function! Skippmatch2()
endif
endfun
-function! Skippmatch() " {{{
+function! Skippmatch() " {{{
let synname = synIDattr(synID(line("."), col("."), 0), "name")
if synname == "Delimiter" || synname == "phpRegionDelimiter" || synname =~# "^phpParent" || synname == "phpArrayParens" || synname =~# '^php\%(Block\|Brace\)' || synname == "javaScriptBraces" || synname =~# "^phpComment" && b:UserIsTypingComment
return 0
@@ -243,7 +250,7 @@ function! FindTheIfOfAnElse (lnum, StopAfterFirstPrevElse) " {{{
if getline(beforeelse) !~# '^\s*if\>' && beforeelse>1 || s:iftoskip && beforeelse>1
- if s:iftoskip && getline(beforeelse) =~# '^\s*if\>'
+ if s:iftoskip && getline(beforeelse) =~# '^\s*if\>'
let s:iftoskip = s:iftoskip - 1
endif
@@ -255,6 +262,36 @@ function! FindTheIfOfAnElse (lnum, StopAfterFirstPrevElse) " {{{
endfunction " }}}
+let s:defaultORcase = '^\s*\%(default\|case\).*:'
+
+function! FindTheSwitchIndent (lnum) " {{{
+
+
+ let test = GetLastRealCodeLNum(a:lnum - 1)
+
+ if test <= 1
+ return indent(1) - &sw * b:PHP_vintage_case_default_indent
+ end
+
+ if getline(test) =~ '^\s*}'
+ let test = FindOpenBracket(test)
+
+ if getline(test) =~ '^\s*{'
+ let test = GetLastRealCodeLNum(GetLastRealCodeLNum(test - 1) - 1)
+ endif
+ endif
+
+ if getline(test) =~# '^\s*switch\>'
+ return indent(test)
+ elseif getline(test) =~# s:defaultORcase
+ return indent(test) - &sw * b:PHP_vintage_case_default_indent
+ else
+ return FindTheSwitchIndent(test)
+ endif
+
+endfunction "}}}
+
+
function! IslinePHP (lnum, tofind) " {{{
let cline = getline(a:lnum)
@@ -278,7 +315,7 @@ function! IslinePHP (lnum, tofind) " {{{
endfunction " }}}
let s:notPhpHereDoc = '\%(break\|return\|continue\|exit\|else\)'
-let s:blockstart = '\%(\%(\%(}\s*\)\=else\%(\s\+\)\=\)\=if\>\|else\>\|while\>\|switch\>\|for\%(each\)\=\>\|declare\>\|class\>\|interface\>\|abstract\>\|try\>\|catch\>\)'
+let s:blockstart = '\%(\%(\%(}\s*\)\=else\%(\s\+\)\=\)\=if\>\|else\>\|while\>\|switch\>\|case\>\|default\>\|for\%(each\)\=\>\|declare\>\|class\>\|interface\>\|abstract\>\|try\>\|catch\>\)'
let s:autoresetoptions = 0
if ! s:autoresetoptions
@@ -286,7 +323,7 @@ if ! s:autoresetoptions
endif
function! ResetPhpOptions()
- if ! b:optionsset && &filetype == "php"
+ if ! b:optionsset && &filetype == "php"
if b:PHP_autoformatcomment
setlocal comments=s1:/*,mb:*,ex:*/,://,:#
@@ -324,7 +361,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.30)'
+ echom 'Large indenting detected, speed optimizations engaged (v1.33)'
endif
let b:PHP_indentbeforelast = b:PHP_lastindented
endif
@@ -383,7 +420,7 @@ function! GetPhpIndent()
let lnum = lnum - 1
endwhile
- let b:InPHPcode_tofind = substitute( getline(lnum), '^.*<<<''\=\(\a\w*\)''\=$', '^\\s*\1;\\=$', '') " XXX 0607
+ let b:InPHPcode_tofind = substitute( getline(lnum), '^.*<<<''\=\(\a\w*\)''\=$', '^\\s*\1;\\=$', '')
endif
else
let b:InPHPcode = 0
@@ -399,7 +436,7 @@ function! GetPhpIndent()
if b:InPHPcode_tofind!=""
if cline =~? b:InPHPcode_tofind
- let b:InPHPcode = 1
+ let b:InPHPcode = 1
let b:InPHPcode_tofind = ""
let b:UserIsTypingComment = 0
if cline =~ '\*/'
@@ -436,9 +473,9 @@ function! GetPhpIndent()
let b:InPHPcode_and_script = 1
endif
- elseif last_line =~? '<<<''\=\a\w*''\=$' " XXX 0607
+ elseif last_line =~? '<<<''\=\a\w*''\=$'
let b:InPHPcode = 0
- let b:InPHPcode_tofind = substitute( last_line, '^.*<<<''\=\(\a\w*\)''\=$', '^\\s*\1;\\=$', '') " XXX 0607
+ let b:InPHPcode_tofind = substitute( last_line, '^.*<<<''\=\(\a\w*\)''\=$', '^\\s*\1;\\=$', '')
elseif !UserIsEditing && cline =~ '^\s*/\*\%(.*\*/\)\@!' && getline(v:lnum + 1) !~ '^\s*\*'
let b:InPHPcode = 0
@@ -488,15 +525,15 @@ function! GetPhpIndent()
" Things always indented at col 1 (PHP delimiter: <?, ?>, Heredoc end) {{{
- if cline =~# '^\s*<?' && cline !~ '?>'
+ if cline =~# '^\s*<?' && cline !~ '?>' && b:PHP_outdentphpescape
return 0
endif
- if cline =~ '^\s*?>' && cline !~# '<?'
+ if cline =~ '^\s*?>' && cline !~# '<?' && b:PHP_outdentphpescape
return 0
endif
- if cline =~? '^\s*\a\w*;$\|^\a\w*$' && cline !~? s:notPhpHereDoc " XXX 0607
+ if cline =~? '^\s*\a\w*;$\|^\a\w*$' && cline !~? s:notPhpHereDoc
return 0
endif " }}}
@@ -539,9 +576,8 @@ function! GetPhpIndent()
endif
endif
- let defaultORcase = '^\s*\%(default\|case\).*:'
- if last_line =~ '[;}]'.endline && last_line !~ '^)' && last_line !~# defaultORcase " Added && last_line !~ '^)' on 2007-12-30
+ if last_line =~ '[;}]'.endline && last_line !~ '^)' && last_line !~# s:defaultORcase
if ind==b:PHP_default_indenting
return b:PHP_default_indenting
elseif b:PHP_indentinghuge && ind==b:PHP_CurrentIndentLevel && cline !~# '^\s*\%(else\|\%(case\|default\).*:\|[})];\=\)' && last_line !~# '^\s*\%(\%(}\s*\)\=else\)' && getline(GetLastRealCodeLNum(lnum - 1))=~';'.endline
@@ -551,13 +587,15 @@ function! GetPhpIndent()
let LastLineClosed = 0
- let terminated = '\%(;\%(\s*?>\)\=\|<<<''\=\a\w*''\=$\|^\s*}\)'.endline " XXX 0607
+ let terminated = '\%(;\%(\s*?>\)\=\|<<<''\=\a\w*''\=$\|^\s*}\)'.endline
let unstated = '\%(^\s*'.s:blockstart.'.*)\|\%(//.*\)\@<!\<e'.'lse\>\)'.endline
if ind != b:PHP_default_indenting && cline =~# '^\s*else\%(if\)\=\>'
let b:PHP_CurrentIndentLevel = b:PHP_default_indenting
return indent(FindTheIfOfAnElse(v:lnum, 1))
+ elseif cline =~# s:defaultORcase
+ return FindTheSwitchIndent(v:lnum) + &sw * b:PHP_vintage_case_default_indent
elseif cline =~ '^\s*)\=\s*{'
let previous_line = last_line
let last_line_num = lnum
@@ -580,10 +618,10 @@ function! GetPhpIndent()
endwhile
elseif last_line =~# unstated && cline !~ '^\s*);\='.endline
- let ind = ind + &sw " we indent one level further when the preceding line is not stated
+ let ind = ind + &sw
return ind
- elseif (ind != b:PHP_default_indenting || last_line =~ '^)' ) && last_line =~ terminated " Added || last_line =~ '^)' on 2007-12-30 (array indenting [rpblem broke other things)
+ elseif (ind != b:PHP_default_indenting || last_line =~ '^)' ) && last_line =~ terminated
let previous_line = last_line
let last_line_num = lnum
let LastLineClosed = 1
@@ -616,7 +654,7 @@ function! GetPhpIndent()
let previous_line = getline(last_line_num)
- if previous_line =~# defaultORcase.'\|{'.endline
+ if previous_line =~# s:defaultORcase.'\|{'.endline
break
endif
@@ -636,15 +674,12 @@ function! GetPhpIndent()
let ind = indent(last_match)
let b:PHP_CurrentIndentLevel = b:PHP_default_indenting
- if cline =~# defaultORcase
- let ind = ind - &sw
- endif
return ind
endif
endif
let plinnum = GetLastRealCodeLNum(lnum - 1)
- let pline = getline(plinnum)
+ let AntepenultimateLine = getline(plinnum)
let last_line = substitute(last_line,"\\(//\\|#\\)\\(\\(\\([^\"']*\\([\"']\\)[^\"']*\\5\\)\\+[^\"']*$\\)\\|\\([^\"']*$\\)\\)",'','')
@@ -658,13 +693,13 @@ function! GetPhpIndent()
if !LastLineClosed
- if last_line =~# '[{(]'.endline || last_line =~? '\h\w*\s*(.*,$' && pline !~ '[,(]'.endline
+ if last_line =~# '[{(]'.endline || last_line =~? '\h\w*\s*(.*,$' && AntepenultimateLine !~ '[,(]'.endline
if !b:PHP_BracesAtCodeLevel || last_line !~# '^\s*{'
let ind = ind + &sw
endif
- if b:PHP_BracesAtCodeLevel || b:PHP_vintage_case_default_indent == 1 || cline !~# defaultORcase
+ if b:PHP_BracesAtCodeLevel || b:PHP_vintage_case_default_indent == 1
let b:PHP_CurrentIndentLevel = ind
return ind
@@ -677,15 +712,13 @@ function! GetPhpIndent()
if openedparent != lnum
let ind = indent(openedparent)
endif
+
elseif last_line =~ '^\s*'.s:blockstart
let ind = ind + &sw
- elseif last_line =~# defaultORcase && cline !~# defaultORcase
- let ind = ind + &sw
-
- elseif pline =~ '\%(;\%(\s*?>\)\=\|<<<''\=\a\w*''\=$\|^\s*}\|{\)'.endline . '\|' . defaultORcase && cline !~# defaultORcase
+ elseif AntepenultimateLine =~ '\%(;\%(\s*?>\)\=\|<<<''\=\a\w*''\=$\|^\s*}\|{\)'.endline . '\|' . s:defaultORcase
let ind = ind + &sw
endif
@@ -693,9 +726,6 @@ function! GetPhpIndent()
if cline =~ '^\s*);\='
let ind = ind - &sw
- elseif cline =~# defaultORcase && last_line !~# defaultORcase
- let ind = ind - &sw
-
endif
let b:PHP_CurrentIndentLevel = ind