Author: arekm Date: Sat Jun 18 09:42:59 2005 GMT Module: SOURCES Tag: HEAD ---- Log message: - up to 1.12
---- Files affected: SOURCES: php.vim (1.3 -> 1.4) ---- Diffs: ================================================================ Index: SOURCES/php.vim diff -u SOURCES/php.vim:1.3 SOURCES/php.vim:1.4 --- SOURCES/php.vim:1.3 Sun Mar 6 22:53:55 2005 +++ SOURCES/php.vim Sat Jun 18 11:42:53 2005 @@ -2,8 +2,18 @@ " Language: PHP " Author: John Wellesz <John.wellesz (AT) teaser (DOT) fr> " URL: http://www.2072productions.com/vim/indent/php.vim -" Last Change: 2005 February 10th -" Version: 1.10 +" Last Change: 2005 May 31th +" Version: 1.12 +" +" Changes: 1.12 - The bug involving searchpair() and utf-8 encoding in Vim 6.3 will +" not make this script to hang but you'll have to be +" careful to not write '/* */' comments with other '/*' +" inside the comments else the indentation won't be correct. +" NOTE: This is true only if you are using utf-8 and vim 6.3. +" +" Changes: 1.11 - If the "case" of a "switch" wasn't alone on its line +" and if the "switch" was at col 0 (or at default indenting) +" the lines following the "case" were not indented. " " Changes: 1.10 - Lines beginning by a single or double quote were " not indented in some cases. @@ -77,32 +87,6 @@ " should. " That will be corrected in the next version. " -" Changes: improvements with regard to the original version (0.5) by Miles Lott (whose this script was inspired): -" - Commented part of code or non PHP code no longer break the -" indent algorithm, the content of those parts are indented -" separatly -" - corrected a strange thing (a part of code was duplicated) -> -" the last version couldn't work. -" - Folds can be used without problem -" - multilevel non bracked structures are indented (like -" in C) -" Exemple: -" if (!isset($History_lst_sel)) -" if (!isset($blabla)) -" if (!isset($bloum)) { -" $History_lst_sel=0; -" } else -" $foo="truc"; -" else $bla= "foo"; -" $command_hist = TRUE; -" -" - "array( 'blabla'," lines no longer break the indent of the -" following lines -" - the options php_noindent_switch and php_indent_shortopentags have been removed -" (couldn't find any reason why one would want to use them) -" - PHP open and close tags are always set to col 1 as for the -" immediate following php code -" " If you find a bug, please e-mail me at John.wellesz (AT) teaser (DOT) fr " with an example of code that break the algorithm. " @@ -146,6 +130,18 @@ " MUST remove CR when the fileformat is UNIX else the indentation " won't be correct... +setlocal nosmartindent +setlocal nolisp + +"This will prevent a bug involving searchpair(), its 'r' flag, utf-8 and vim 6.3 +"from occurring but will forbid you to write other '/*' inside a '/* */' comment. +if version <= 603 && &encoding == 'utf-8' + let s:searchpairflags = 'bW' +else + let s:searchpairflags = 'bWr' +endif + + if &fileformat == "unix" && exists("PHP_removeCRwhenUnix") && PHP_removeCRwhenUnix let myul=&ul silent! %s/\r$//g @@ -177,20 +173,23 @@ endif let b:did_indent = 1 -setlocal nosmartindent +setlocal nosmartindent setlocal nolisp +setlocal nocindent +setlocal autoindent + setlocal indentexpr=GetPhpIndent() setlocal indentkeys=0{,0},0),:,!^F,o,O,e,*<Return>,=?>,=<?,=*/ " Only define the function once. if exists("*GetPhpIndent") - finish + finish " XXX endif let s:endline= '\s*\%(//.*\|#.*\|/\*.*\*/\s*\)\=$' let s:PHP_startindenttag = '<?\%(.*?>\)[EMAIL PROTECTED]|<script[^>]*>\%(.*<\/script>\)[EMAIL PROTECTED]' -" setlocal debug=msg +"setlocal debug=msg " XXX function! GetLastRealCodeLNum(startline) " {{{ @@ -212,8 +211,10 @@ let lnum = lnum - 1 elseif lastline =~ '\*/\s*$' " skip multiline comments call cursor(lnum, 1) - call search('\*/\zs', 'W') - let lnum = searchpair('/\*\zs', '', '\*/\zs', 'bWr', '') " find the most outside /* + call search('\*/\zs', 'W') " positition the cursor after the first */ + let lnum = searchpair('/\*', '', '\*/\zs', s:searchpairflags, '') " find the most outside /* + "echo 'lnum skipnonphp= ' . lnum + "call getchar() let lastline = getline(lnum) if lastline =~ '^\s*/\*' " if line contains nothing but comment @@ -225,8 +226,8 @@ elseif lastline =~? '\%(//\s*\|?>.*\)\@<!<?\%(php\)\=\s*$\|^\s*<script\>' " skip non php code " call cursor(lnum, 1) - " call search('<?\zs', 'W') - " let lnum = searchpair('?>\zs', '', '<?\zs', 'bW', 'getline(".") =~ "<?.*?>"') " find the most outside /* + " call search('<?', 'W') + " let lnum = searchpair('?>', '', '<?\zs', 'bW', 'getline(".") =~ "<?.*?>"') " let lastline = getline(lnum) while lastline !~ '\(<?.*\)\@<!?>' && lnum > 1 @@ -470,7 +471,7 @@ if cline =~ '\*/' " End comment tags must be indented like start comment tags call cursor(v:lnum, 1) call search('\*/\zs', 'W') - let lnum = searchpair('/\*\zs', '', '\*/\zs', 'bWr', '') " find the most outside /* + let lnum = searchpair('/\*', '', '\*/\zs', s:searchpairflags, '') " find the most outside /* return indent(lnum) elseif cline =~? '<script\>' " a more accurate test is useless since there isn't any other possibility let b:InPHPcode_and_script = 1 @@ -576,7 +577,7 @@ " if optimized mode is active and nor current or previous line are an 'else' " or the end of a possible bracketless thing then indent the same as the previous " line - if last_line =~ '[;}]'.endline + if last_line =~ '[;}]'.endline && last_line !~# '^\s*\%(default\|case\).*:' 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 @@ -596,7 +597,7 @@ if UserIsEditing && cline =~ '\*/' " End comment tags must be indented like start comment tags call cursor(v:lnum, 1) call search('\*/\zs', 'W') - let lnum = searchpair('/\*\zs', '', '\*/\zs', 'bWr', '') " find the most outside /* + let lnum = searchpair('/\*', '', '\*/\zs', s:searchpairflags, '') " find the most outside /* return indent(lnum) endif @@ -730,7 +731,7 @@ let pline = getline(plinnum) " previous to last line " REMOVE comments at end of line before treatment - " the first par of the regex removes // from the end of line when they are + " the first part of the regex removes // from the end of line when they are " followed by a number of '"' which is a multiple of 2. The second part " removes // that are not followed by any '"' " Sorry for this unreadable thing... ================================================================ ---- CVS-web: http://cvs.pld-linux.org/SOURCES/php.vim?r1=1.3&r2=1.4&f=u _______________________________________________ pld-cvs-commit mailing list [email protected] http://lists.pld-linux.org/mailman/listinfo/pld-cvs-commit
