~ubuntu-branches/ubuntu/maverick/vim/maverick

« back to all changes in this revision

Viewing changes to runtime/indent/php.vim

  • Committer: Bazaar Package Importer
  • Author(s): Steve Langasek
  • Date: 2009-05-04 11:13:42 UTC
  • mfrom: (1.1.8 upstream) (0.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090504111342-60miqybsixdpc345
Tags: 2:7.2.148-2ubuntu1
* Merge from Debian unstable, remaining changes:
  - debian/runtime/vimrc: "syntax on" is a sane default for non-tiny vim.
  - runtime/syntax/debcontrol.vim:
    + Add "metapackages" to the list of valid sections.
  - runtime/syntax/grub.vim:
    + Add Ubuntu-specific 'quiet' keyword.
  - Drop vim-lesstif package and lesstif2-dev build-dependency.
  - Enable Python interpreter on basic builds.
  - Disable autoindent, line-wrapping, and backup files by default.
* Dropped changes, merged in Debian:
  - Add jaunty, karmic to the list of valid suites.
  - runtime/syntax/debsources.vim:
    + Add "jaunty" to debsourcesDistrKeyword
  - Create a .pot file for translations.
* Drop gutsy from the list of valid distro series, it's been EOLed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
" Language:     PHP
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
7
 
" Version:      1.28
8
 
"
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.
11
 
"
12
 
"  ---> The change log and all the comments have been removed from this file.
13
 
"
14
 
"  For a complete change log and fully commented code, download the script on
15
 
"  2072productions.com at the URI provided above.
 
7
" Version:      1.30
 
8
"
16
9
"
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.
28
21
"
29
22
"
30
23
"       In the case you have syntax errors in your script such as HereDoc end
33
26
"       they are followed by a ';').
34
27
"
35
28
"
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
39
 
" '\s*$' correctly.
40
 
" So you have to remove those useless characters first with a command like:
41
 
"
42
 
" :%s /\r$//g
43
 
"
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).
46
 
"
47
 
"
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.
50
 
"
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.
53
 
"
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
57
 
"                  won't be correct!
58
 
"
59
 
" Options: PHP_BracesAtCodeLevel = 1 to indent the '{' and '}' at the same
60
 
"                  level than the code they contain.
61
 
"                  Exemple:
62
 
"                       Instead of:
63
 
"                               if ($foo)
64
 
"                               {
65
 
"                                       foo();
66
 
"                               }
67
 
"
68
 
"                       You will write:
69
 
"                               if ($foo)
70
 
"                                       {
71
 
"                                       foo();
72
 
"                                       }
73
 
"
74
 
"                       NOTE: The script will be a bit slower if you use this option because
75
 
"                       some optimizations won't be available.
76
 
"
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
79
 
"
 
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
 
32
"       '\s*$' correctly.
 
33
"       So you have to remove those useless characters first with a command like:
 
34
"
 
35
"       :%s /\r$//g
 
36
"
 
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).
 
39
"
 
40
" Options: See :help php-indent for available options.
 
41
 
80
42
 
81
43
if exists("b:did_indent")
82
44
    finish
145
107
endif
146
108
 
147
109
if exists("*GetPhpIndent")
 
110
    call ResetPhpOptions()
148
111
    finish " XXX
149
112
endif
150
113
 
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\>\)'
319
282
 
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
324
286
endif
325
287
 
326
 
function! ResetOptions()
327
 
    if ! b:optionsset
 
288
function! ResetPhpOptions()
 
289
    if ! b:optionsset && &filetype == "php" 
328
290
        if b:PHP_autoformatcomment
329
291
 
330
292
            setlocal comments=s1:/*,mb:*,ex:*/,://,:#
341
303
    endif
342
304
endfunc
343
305
 
 
306
call ResetPhpOptions()
 
307
 
344
308
function! GetPhpIndent()
345
309
 
346
310
    let b:GetLastRealCodeLNum_ADD = 0
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)'
364
328
        endif
365
329
        let b:PHP_indentbeforelast = b:PHP_lastindented
366
330
    endif
693
657
 
694
658
    if !LastLineClosed
695
659
 
 
660
 
696
661
        if last_line =~# '[{(]'.endline || last_line =~? '\h\w*\s*(.*,$' && pline !~ '[,(]'.endline
697
662
 
698
663
            if !b:PHP_BracesAtCodeLevel || last_line !~# '^\s*{'
715
680
        elseif last_line =~ '^\s*'.s:blockstart
716
681
            let ind = ind + &sw
717
682
 
718
 
        elseif last_line =~# defaultORcase
 
683
        elseif last_line =~# defaultORcase && cline !~# defaultORcase
719
684
            let ind = ind + &sw
720
685
 
721
686
 
722
 
        elseif pline =~ '\%(;\%(\s*?>\)\=\|<<<''\=\a\w*''\=$\|^\s*}\|{\)'.endline . '\|' . defaultORcase
 
687
        elseif pline =~ '\%(;\%(\s*?>\)\=\|<<<''\=\a\w*''\=$\|^\s*}\|{\)'.endline . '\|' . defaultORcase && cline !~# defaultORcase
723
688
 
724
689
            let ind = ind + &sw
725
690
        endif