Mercurial > vim
comparison runtime/indent/php.vim @ 42:c75153d791d0
updated for version 7.0026
author | vimboss |
---|---|
date | Wed, 29 Dec 2004 20:58:21 +0000 |
parents | 3fc0f57ecb91 |
children | ef254e0f2365 |
comparison
equal
deleted
inserted
replaced
41:f529edb9bab3 | 42:c75153d791d0 |
---|---|
1 " Vim indent file | 1 " Vim indent file |
2 " Language: PHP | 2 " Language: PHP |
3 " Author: Miles Lott <milos@groupwhere.org> | 3 " Author: Miles Lott <milos@groupwhere.org> |
4 " URL: http://milosch.dyndns.org/php.vim | 4 " URL: http://milosch.dyndns.org/php.vim |
5 " Last Change: 2004 May 18 | 5 " Last Change: 2004 May 18 |
6 " Version: 0.5 | 6 " Version: 0.4 |
7 " Notes: Close all switches with default:\nbreak; and it will look better. | 7 " Notes: Close all switches with default:\nbreak; and it will look better. |
8 " Also, open and close brackets should be alone on a line. | 8 " Also, open and close brackets should be alone on a line. |
9 " This is my preference, and the only way this will look nice. | 9 " This is my preference, and the only way this will look nice. |
10 " Try an older version if you care less about the formatting of | 10 " Try an older version if you care less about the formatting of |
11 " switch/case. It is nearly perfect for anyone regardless of your | 11 " switch/case. It is nearly perfect for anyone regardless of your |
12 " stance on brackets. | 12 " stance on brackets. |
13 " | 13 " |
14 " Changes: 0.5 - fix duplicate indent on open tag, and empty bracketed | 14 " Changes: Fixes for closing php tag, switch statement closure, and php_indent_shortopentags |
15 " statements. | |
16 " 0.4 - Fixes for closing php tag, switch statement closure, and php_indent_shortopentags | |
17 " option from Steffen Bruentjen <vim@kontraphon.de> | 15 " option from Steffen Bruentjen <vim@kontraphon.de> |
18 " | 16 " |
19 " Options: php_noindent_switch=1 -- do not try to indent switch/case statements (version 0.1 behavior) | 17 " Options: php_noindent_switch=1 -- do not try to indent switch/case statements (version 0.1 behavior) |
20 " php_indent_shortopentags=1 -- indent after short php open tags, too | 18 " php_indent_shortopentags=1 -- indent after short php open tags, too |
21 | 19 |
49 let line = getline(lnum) " last line | 47 let line = getline(lnum) " last line |
50 let cline = getline(v:lnum) " current line | 48 let cline = getline(v:lnum) " current line |
51 let pline = getline(lnum - 1) " previous to last line | 49 let pline = getline(lnum - 1) " previous to last line |
52 let ind = indent(lnum) | 50 let ind = indent(lnum) |
53 | 51 |
54 " Indent after php open tag | 52 " Indent after php open tags |
55 if line =~ '<?php' | 53 if line =~ '<?php' |
56 let ind = ind + &sw | 54 let ind = ind + &sw |
57 elseif exists('g:php_indent_shortopentags') | 55 " indent after short open tags |
58 " indent after short open tag | 56 endif |
57 if exists('g:php_indent_shortopentags') | |
59 if line =~ '<?' | 58 if line =~ '<?' |
60 let ind = ind + &sw | 59 let ind = ind + &sw |
61 endif | 60 endif |
62 endif | 61 endif |
63 " indent after php closing tag | |
64 if cline =~ '\M?>' | 62 if cline =~ '\M?>' |
65 let ind = ind - &sw | 63 let ind = ind - &sw |
66 endif | 64 endif |
67 | 65 |
68 if exists("b:php_noindent_switch") " version 1 behavior, diy switch/case,etc | 66 if exists("b:php_noindent_switch") " version 1 behavior, diy switch/case,etc |
72 endif | 70 endif |
73 if cline =~ '^\s*[)}]' | 71 if cline =~ '^\s*[)}]' |
74 let ind = ind - &sw | 72 let ind = ind - &sw |
75 endif | 73 endif |
76 return ind | 74 return ind |
77 else | 75 else " Try to indent switch/case statements as well |
78 " Search the matching bracket (with searchpair()) and set the indent of | |
79 " to the indent of the matching line. | |
80 if cline =~ '^\s*}' | |
81 call cursor(line('.'), 1) | |
82 let ind = indent(searchpair('{', '', '}', | |
83 'bW', 'synIDattr(synID(line("."), col("."), | |
84 0), "name") =~? "string"')) | |
85 return ind | |
86 endif | |
87 " Try to indent switch/case statements as well | |
88 " Indent blocks enclosed by {} or () or case statements, with some anal requirements | 76 " Indent blocks enclosed by {} or () or case statements, with some anal requirements |
89 if line =~ 'case.*:\|[{(]\s*\(#[^)}]*\)\=$' | 77 if line =~ 'case.*:\|[{(]\s*\(#[^)}]*\)\=$' |
90 let ind = ind + &sw | 78 let ind = ind + &sw |
91 " return if the current line is not another case statement of the previous line is a bracket open | 79 " return if the current line is not another case statement of the previous line is a bracket open |
92 if cline !~ '.*case.*:\|default:' || line =~ '[{(]\s*\(#[^)}]*\)\=$' | 80 if cline !~ '.*case.*:\|default:' || line =~ '[{(]\s*\(#[^)}]*\)\=$' |
102 endif | 90 endif |
103 endif | 91 endif |
104 " Search the matching bracket (with searchpair()) and set the indent of cline | 92 " Search the matching bracket (with searchpair()) and set the indent of cline |
105 " to the indent of the matching line. | 93 " to the indent of the matching line. |
106 if cline =~ '^\s*}' | 94 if cline =~ '^\s*}' |
107 call cursor(line('. '), 1) | 95 call cursor(line('.'), 1) |
108 let ind = indent(searchpair('{', '', '}', 'bW', 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"')) | 96 let ind = indent(searchpair('{', '', '}', 'bW', 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"')) |
109 return ind | 97 return ind |
110 endif | 98 endif |
111 | 99 |
112 if line =~ 'default:' | 100 if line =~ 'default:' |