'formatoptions' changed for PHP files?

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

'formatoptions' changed for PHP files?

Robert Webb-2
Hi,

Summary:
    - Why are the "owb" options added to 'formatoptions' whenever I
      edit a PHP file?
    - How do I stop it?
    - The "b" and "w" options don't work well together.

Somehow whenever I edit a .php file, 'formatoptions' is set to 2qrowcb.
But when I edit HTML files, it is set to 2tcrq, as I want.  I have no
idea where the extra "owb" options have come from, and it took me a
while to figure out why I couldn't format text properly anymore.  "w"
is particularly narty when you're not expecting it!

The only relevant lines in my .vimrc appear to be:

    syntax on
    filetype plugin indent on
    autocmd!
    autocmd BufRead * set tw=79 nocin nosi fo=2tcrq infercase

I presume one of the syntax, file type, or completion plugins for PHP
is changing my setting, but I can't see where they do this, and I
can't imagine why someone would expect most users to want any of the
"owb" options set by default.

Even if I add this to my .vimrc:
    augroup filetype
    au BufNewFile,BufRead *.php,*.inc   set fo=2tcrq
    augroup END
It makes no difference.  How do I get rid of the "owb" options??

Maybe I should contact the author of the PHP file type plugin?  But I
don't know whether it's there, or the syntax plugin, or the completion
plugin, or one of the included plugins such as HTML etc, and after
looking around I couldn't find anywhere that changed the 'fo' setting.

Having "b" set unexpectedly is very confusing, especially in
combination with "w".  "w" not only uses trailing white-space in a
line to indicate a continuing paragraph, but it also actively leaves
trailing white space when a line is wrapped.  Makes sense, except that
I typically delete any trailing white space I happen to find (which
then stops formatting from working), and usually wonder how it got
there in the first place.  Never knew an option could cause it to
happen!

In combination with "b" though it's worse.  If you append to a line
that is shorter than 'textwidth' but has a traling space, and the word
is long enough to continue past 'tw' (as it often will be in the
middle of a paragraph), then the line doesn't get wrapped.  I think
'b' should really wrap in that case.  Appending after a trailing space
should count the same as if you entered the space yourself, otherwise
the combo of "b" and "w" is more or less useless.

Thanks,
Rob.

--

Robert Webb <[hidden email]>,
MineSweeper3D - Take Minesweeper to a whole new dimension!
http://www.software3d.com/Mines3D
Reply | Threaded
Open this post in threaded view
|

Re: 'formatoptions' changed for PHP files?

A.J.Mechelynck
Robert Webb wrote:

> Hi,
>
> Summary:
>     - Why are the "owb" options added to 'formatoptions' whenever I
>       edit a PHP file?
>     - How do I stop it?
>     - The "b" and "w" options don't work well together.
>
> Somehow whenever I edit a .php file, 'formatoptions' is set to 2qrowcb.
> But when I edit HTML files, it is set to 2tcrq, as I want.  I have no
> idea where the extra "owb" options have come from, and it took me a
> while to figure out why I couldn't format text properly anymore.  "w"
> is particularly narty when you're not expecting it!
>
> The only relevant lines in my .vimrc appear to be:
>
>     syntax on
>     filetype plugin indent on
>     autocmd!
>     autocmd BufRead * set tw=79 nocin nosi fo=2tcrq infercase
>
> I presume one of the syntax, file type, or completion plugins for PHP
> is changing my setting, but I can't see where they do this, and I
> can't imagine why someone would expect most users to want any of the
> "owb" options set by default.
>
> Even if I add this to my .vimrc:
>     augroup filetype
>     au BufNewFile,BufRead *.php,*.inc   set fo=2tcrq
>     augroup END
> It makes no difference.  How do I get rid of the "owb" options??
>
> Maybe I should contact the author of the PHP file type plugin?  But I
> don't know whether it's there, or the syntax plugin, or the completion
> plugin, or one of the included plugins such as HTML etc, and after
> looking around I couldn't find anywhere that changed the 'fo' setting.
>
> Having "b" set unexpectedly is very confusing, especially in
> combination with "w".  "w" not only uses trailing white-space in a
> line to indicate a continuing paragraph, but it also actively leaves
> trailing white space when a line is wrapped.  Makes sense, except that
> I typically delete any trailing white space I happen to find (which
> then stops formatting from working), and usually wonder how it got
> there in the first place.  Never knew an option could cause it to
> happen!
>
> In combination with "b" though it's worse.  If you append to a line
> that is shorter than 'textwidth' but has a traling space, and the word
> is long enough to continue past 'tw' (as it often will be in the
> middle of a paragraph), then the line doesn't get wrapped.  I think
> 'b' should really wrap in that case.  Appending after a trailing space
> should count the same as if you entered the space yourself, otherwise
> the combo of "b" and "w" is more or less useless.
>
> Thanks,
> Rob.
>
> --
>
> Robert Webb <[hidden email]>,
> MineSweeper3D - Take Minesweeper to a whole new dimension!
> http://www.software3d.com/Mines3D
>

see $VIMRUNTIME/indent/php.vim (1.23, 2006 Apr 30) lines 42-43, 98-102 and 312-323

        :let g:PHP_autoformatcomment = 0


Best regards,
Tony.
Reply | Threaded
Open this post in threaded view
|

RE: 'formatoptions' changed for PHP files?

Robert Webb-2
Tony wrote:

> > - Why are the "owb" options added to 'formatoptions' whenever I
> >   edit a PHP file?
> > - How do I stop it?
> > - The "b" and "w" options don't work well together.
>
> see $VIMRUNTIME/indent/php.vim (1.23, 2006 Apr 30) lines 42-43,
> 98-102 and 312-323
>
> :let g:PHP_autoformatcomment = 0

Ah thanks!  That fixes things for me.

Generally though, how would a typical user ever discover that?

And surely the default when editing PHP files should not include the
"w" option?

I was not aware of the "w" option, but it leads to really unexpected
results when you don't know about it.  It gives the impression that
sometimes formatting works and sometimes it doesn't, depending on the
invisible white space at the end of a line.

Thanks,
Rob.

--

Robert Webb <[hidden email]>,
Want to make polyhedra?
http://www.software3d.com/Stella.html
Reply | Threaded
Open this post in threaded view
|

Re: 'formatoptions' changed for PHP files?

A.J.Mechelynck
Robert Webb wrote:

> Tony wrote:
>
>>> - Why are the "owb" options added to 'formatoptions' whenever I
>>>   edit a PHP file?
>>> - How do I stop it?
>>> - The "b" and "w" options don't work well together.
>> see $VIMRUNTIME/indent/php.vim (1.23, 2006 Apr 30) lines 42-43,
>> 98-102 and 312-323
>>
>> :let g:PHP_autoformatcomment = 0
>
> Ah thanks!  That fixes things for me.
>
> Generally though, how would a typical user ever discover that?
[...]

As I did, by inspecting the php.vim scripts in the various subdirectories of
$VIMRUNTIME. In this case I searched on \<fo in order to catch both 'fo' and
'formatoptions'. For instance:

        :vimgrep /\<fo/g $VIMRUNTIME/**/php.vim

and to make quickfix navigation easier, I have in my vimrc:

        map   <F2>      :cn<CR>
        map   <S-F2>    :cN<CR>

Once the "right" script had been found, closer inspection found the lines
listed in my earlier post.


Best regards,
Tony.
Reply | Threaded
Open this post in threaded view
|

Re: 'formatoptions' changed for PHP files?

James Vega-3
In reply to this post by Robert Webb-2
On Mon, Nov 20, 2006 at 05:01:04PM +1100, Robert Webb wrote:

> Tony wrote:
>
> > > - Why are the "owb" options added to 'formatoptions' whenever I
> > >   edit a PHP file?
> > > - How do I stop it?
> > > - The "b" and "w" options don't work well together.
> >
> > see $VIMRUNTIME/indent/php.vim (1.23, 2006 Apr 30) lines 42-43,
> > 98-102 and 312-323
> >
> > :let g:PHP_autoformatcomment = 0
>
> Ah thanks!  That fixes things for me.
>
> Generally though, how would a typical user ever discover that?
":verbose set formatoptions?" is another method a user could use.
Prepending :set with the verbose command tells you where the option was
last set.

James
--
GPG Key: 1024D/61326D40 2003-09-02 James Vega <[hidden email]>

signature.asc (204 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

RE: 'formatoptions' changed for PHP files?

Robert Webb-2
In reply to this post by A.J.Mechelynck
> > Generally though, how would a typical user ever discover that?
>
> As I did, by inspecting the php.vim scripts in the various
> subdirectories of $VIMRUNTIME. In this case I searched on \<fo in
> order to catch both 'fo' and 'formatoptions'. For instance:
>
> :vimgrep /\<fo/g $VIMRUNTIME/**/php.vim
>
> and to make quickfix navigation easier, I have in my vimrc:
>
> map   <F2>      :cn<CR>
> map   <S-F2>    :cN<CR>

I consider myself to know a fair bit more about vim than the average
user (I think I might have even been the one who added the 'fo' and
'comments' options in the first place!), but haven't kept up with the
latest features in the last year or two.  I knew :vimgrep existed, but
have never studied how to use it and continue to use my own grep
macros instead.

> ":verbose set formatoptions?" is another method a user could use.
> Prepending :set with the verbose command tells you where the option
> was last set.

Another command I didn't know about.  That may come in handy, thanks!

My point though is that the average user surely doesn't know about
:verbose, nor :vimgrep, nor should they be expected to understand the
directory structure under $VIMRUNTIME etc.  I think the experience for
new users, or even non-expert users, should be as fluent as possible,
and is sometimes forgotten on this list.  New features are great, but
should not impinge on the usability for people who don't know about
them.

With this in mind, I still think that "w" should not be added to 'fo'
for PHP files, and possibly the default should be not to change 'fo'
at all.  It feels especially odd that my own autocmds for files of
that type are overwritten.  Surely the user's autocmds should take
precedence over a general-purpose default?  Although I imagine this
might be something where it is hard to alter the order of events
without other consequences.

Rob.

--

Robert Webb <[hidden email]>,
MineSweeper3D - Take Minesweeper to a whole new dimension!
http://www.software3d.com/Mines3D
Reply | Threaded
Open this post in threaded view
|

Re: 'formatoptions' changed for PHP files?

Benji Fisher
On Tue, Nov 21, 2006 at 02:55:25PM +1100, Robert Webb wrote:
> > > Generally though, how would a typical user ever discover that?
> >
[snip]

> > ":verbose set formatoptions?" is another method a user could use.
> > Prepending :set with the verbose command tells you where the option
> > was last set.
>
> Another command I didn't know about.  That may come in handy, thanks!
>
> My point though is that the average user surely doesn't know about
> :verbose, nor :vimgrep, nor should they be expected to understand the
> directory structure under $VIMRUNTIME etc.  I think the experience for
> new users, or even non-expert users, should be as fluent as possible,
> and is sometimes forgotten on this list.  New features are great, but
> should not impinge on the usability for people who don't know about
> them.

     As you say, :verbose is very handy.  As such, it comes up
frequently on the vim users' list.  In an alternate universe where I do
not need sleep, I am working on a "trouble-shooting" section of the
users' manual that will mention this. ;)

> With this in mind, I still think that "w" should not be added to 'fo'
> for PHP files, and possibly the default should be not to change 'fo'
> at all.  It feels especially odd that my own autocmds for files of
> that type are overwritten.  Surely the user's autocmds should take
> precedence over a general-purpose default?  Although I imagine this
> might be something where it is hard to alter the order of events
> without other consequences.

     I agree that new features should follow the principle of least
surprise.  In this case, that would mean changing the default for the
PHP indent script.  This is at the discretion of the maintainer of that
script, John Wellesz, so I am cc'ing him on this message.

> Robert Webb <[hidden email]>,
> MineSweeper3D - Take Minesweeper to a whole new dimension!
> http://www.software3d.com/Mines3D

     Just what I need, another time sink! ;)

HTH --Benji Fisher
Reply | Threaded
Open this post in threaded view
|

Re: 'formatoptions' changed for PHP files?

James Vega-3
In reply to this post by Robert Webb-2
On Tue, Nov 21, 2006 at 02:55:25PM +1100, Robert Webb wrote:
> > ":verbose set formatoptions?" is another method a user could use.
> > Prepending :set with the verbose command tells you where the option
> > was last set.
>
> Another command I didn't know about.  That may come in handy, thanks!
>
> My point though is that the average user surely doesn't know about
> :verbose, nor :vimgrep, nor should they be expected to understand the
> directory structure under $VIMRUNTIME etc.

This is why filetype detection, filetype plugins, and filetype indent
are not turned on by default.  They change the behavior of Vim 'behind
the back of the user' and may confuse new users.  A lot of Linux
distributions (and maybe Vim's example vimrc) turn these on by default
since it's generally useful but I do agree that it can cause frustration
if you don't understand what's going on.

James
--
GPG Key: 1024D/61326D40 2003-09-02 James Vega <[hidden email]>

signature.asc (204 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

RE: 'formatoptions' changed for PHP files?

John Wellesz
In reply to this post by Benji Fisher
Hi,

>      As you say, :verbose is very handy.  As such, it comes up
> frequently on the vim users' list.  In an alternate universe where I do
> not need sleep, I am working on a "trouble-shooting" section of the
> users' manual that will mention this. ;)
>
> > With this in mind, I still think that "w" should not be added to 'fo'
> > for PHP files, and possibly the default should be not to change 'fo'
> > at all.  It feels especially odd that my own autocmds for files of
> > that type are overwritten.  Surely the user's autocmds should take
> > precedence over a general-purpose default?  Although I imagine this
> > might be something where it is hard to alter the order of events
> > without other consequences.
>
>      I agree that new features should follow the principle of least
> surprise.  In this case, that would mean changing the default for the
> PHP indent script.  This is at the discretion of the maintainer of that
> script, John Wellesz, so I am cc'ing him on this message.


In fact, there is an option to disable the comment auto-formatting of the PHP indent script; it will let the 'fo' intact:

" Options: PHP_autoformatcomment = 0 to not enable auto-formatting of comment by
"    default, if set to 0, this script will let the 'formatoptions' setting intact.
"

It's set to 1 by default, I've chosen to enable this option by default because else, no one would ever use this clever comment
auto-formatting feature ; that's the problem with 'new' features (all these options exists since at least Vim 6), almost no-one uses
them :/

This script sets the following flags to fo: (this is an extract of the commented version of the script)

if b:PHP_autoformatcomment

            " Set the comment setting to something correct for PHP
            setlocal comments=s1:/*,mb:*,ex:*/,://,:#
           
            " disable Auto-wrap of text
            setlocal formatoptions-=t
            " Allow formatting of comments with "gq"
            setlocal formatoptions+=q
            " Insert comment leader after hitting <Enter>
            setlocal formatoptions+=r
            " Insert comment leader after hitting o or O in normal mode
            setlocal formatoptions+=o
            " Uses trailing white spaces to detect paragraphs
            setlocal formatoptions+=w
            " Autowrap comments using textwidth
            setlocal formatoptions+=c
            " Do not wrap if you modify a line after textwidth
            setlocal formatoptions+=b
        endif

Have a nice day,

John








> > Robert Webb <[hidden email]>,
> > MineSweeper3D - Take Minesweeper to a whole new dimension!
> > http://www.software3d.com/Mines3D
>
>      Just what I need, another time sink! ;)
>
> HTH --Benji Fisher