> Thanks, but what I meant was that it doesn't seem like I should need a
> workaround at all.  Somewhere vim is applying custom formatoptions to
> php files.  Since vim is smart enough to determine that a .inc file
> should have filetype=php if it starts with <?php, shouldn't it apply
> the custom formatoptions as well in those cases?  To me, the current
> behavior seems unexpected.  I'm happy to file a bug report if others
> agree.

Yes, Ian, you're right, it should be setting the formatoptions correctly
simply by having the filetype set correctly.

It isn't because of a bug in indent/php.vim.

The attached patch fixes it, and I'm CCing the maintainer so he can
incorporate this or a similar fix into the official version.

To explain the problem: the indent script was endeavouring to make sure
options got re-set (set again) when filetype was reinforced or a file
reloaded by defining an autocommand. However, the autocommand was based
on filename, not on filetype, so it didn't always work. Simply changing
it to be a strictly filetype-based autocommand doesn't work, as the
filetype autocommands have already fired when the script is loaded, so
it must also call ResetOptions directly. To allow for this, the function
must be defined before it is called, so things get moved around a bit.
In my patch I also took the liberty of renaming ResetOptions to
ResetPhpOptions to avoid name clashes in the global namespace, and fixed
an apparent typo in a variable name: rest->reset.

Can you please acknowledge you've got this, John?

Cheers,

Ben.




--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

--- indent/php.vim~     2008-10-29 10:48:47.000000000 +1100
+++ indent/php.vim      2008-10-29 10:56:19.000000000 +1100
@@ -317,13 +317,7 @@
 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:autorestoptions = 0
-if ! s:autorestoptions
-    au BufWinEnter,Syntax      *.php,*.php3,*.php4,*.php5      call 
ResetOptions()
-    let s:autorestoptions = 1
-endif
-
-function! ResetOptions()
+function! ResetPhpOptions()
     if ! b:optionsset
        if b:PHP_autoformatcomment
 
@@ -341,6 +335,13 @@
     endif
 endfunc
 
+let s:autoresetoptions = 0
+if ! s:autoresetoptions
+    au FileType        php     call ResetPhpOptions()
+    call ResetPhpOptions()
+    let s:autoresetoptions = 1
+endif
+
 function! GetPhpIndent()
 
     let b:GetLastRealCodeLNum_ADD = 0

Reply via email to