multiple same named buffer variables

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

multiple same named buffer variables

Ivan Villanueva-2
Hello,
in the vim manual (section 41.11) it is recommended to use at the beginning
of a ftplugin:

    if exists("b:did_ftplugin")
        finish
    endif
    let b:did_ftplugin = 1

I wonder if that is correct, because what if you have for the same file type
different plugins with that lines ? Only one ftplugin would be executed,
wouldn't it ?

Iv�n Villanueva
Reply | Threaded
Open this post in threaded view
|

Re: multiple same named buffer variables

A.J.Mechelynck
----- Original Message -----
From: "Ivan Villanueva" <[hidden email]>
To: "vim mailing list" <[hidden email]>
Sent: Monday, July 25, 2005 6:59 PM
Subject: multiple same named buffer variables


> Hello,
> in the vim manual (section 41.11) it is recommended to use at the
> beginning
> of a ftplugin:
>
>    if exists("b:did_ftplugin")
>        finish
>    endif
>    let b:did_ftplugin = 1
>
> I wonder if that is correct, because what if you have for the same file
> type
> different plugins with that lines ? Only one ftplugin would be executed,
> wouldn't it ?
>
> Iv�n Villanueva

For a single filetype, let's say "foobar", there can be at most one
"$VIMRUNTIME/ftplugin/foobar.vim". If you have a
"$VIM/vimfiles/ftplugin/foobar.vim" it is meant as a full replacement of the
above, and if you have a "$HOME/.vim/ftplugin/foobar.vim" it is meant as a
replacement for either or both of the above, so in that case all three of
them should have the lines in question and only the one which comes first in
'runtimepath' is executed. That is intentional.

If you have a "$VIM/vimfiles/after/ftplugin/foobar.vim", its purpose is to
be executed after the one "full" plugin from one of the three locations
above, and it should not contain the lines you mention. Similarly for
"$HOME/.vim/after/ftpugin/foobar.vim" which comes after the previous one (if
present) and after the "full plugin".

But all doesn't stop there though. A later development is allowing several
ftplugins with different names for the same filetype. So you might have

    $VIM/vimfiles/ftplugin/foobar_baz.vim
    $VIM/vimfiles/ftplugin/foobar/bau.vim
    $HOME/.vim/ftplugin/foobar/bat.vim
    $HOME/.vim/ftplugin/foobar/baw.vim
    $HOME/.vim/ftplugin/foobar_baz.vim

If you want to load several scripts for the same filetype, only one of them
may test and set the general "b:did_ftplugin" variable. Other scripts to be
loaded with it should either not use that test at all, or (to allow
disabling them by a newer version earlier in 'runtimepath') test a variable
with a different name, for instance "b:did_ftplugin_foobar_baz", which, in
the example above, would load the script in the $HOME tree and not that in
the $VIM tree. (Any "$VIM/vimfiles/after/ftplugin/foobar_baz.vim" would
still run.)


Best regards,
Tony.


Reply | Threaded
Open this post in threaded view
|

Re: multiple same named buffer variables

Ivan Villanueva-2
On Mon, Jul 25, 2005 at 07:32:11PM +0200, Tony Mechelynck wrote:

> ----- Original Message ----- From: "Ivan Villanueva" <[hidden email]>
> To: "vim mailing list" <[hidden email]>
> Sent: Monday, July 25, 2005 6:59 PM
> Subject: multiple same named buffer variables
>
>
> >Hello,
> >in the vim manual (section 41.11) it is recommended to use at the beginning
> >of a ftplugin:
> >   if exists("b:did_ftplugin")
> >       finish
> >   endif
> >   let b:did_ftplugin = 1
> >I wonder if that is correct, because what if you have for the same file type
> >different plugins with that lines ? Only one ftplugin would be executed,
> >wouldn't it ?
> >Iv�n Villanueva
>
> For a single filetype, let's say "foobar", there can be at most one "$VIMRUNTIME/ftplugin/foobar.vim".
Thanks for the answer.

IMHO the documentation doesn't say that "ftplugin" should be changed for the
name of the file.

Iv�n Villanueva
Reply | Threaded
Open this post in threaded view
|

Re: multiple same named buffer variables

A.J.Mechelynck
----- Original Message -----
From: "Ivan Villanueva" <[hidden email]>
To: "vim mailing list" <[hidden email]>
Sent: Tuesday, July 26, 2005 10:11 PM
Subject: Re: multiple same named buffer variables


> On Mon, Jul 25, 2005 at 07:32:11PM +0200, Tony Mechelynck wrote:
>> ----- Original Message ----- From: "Ivan Villanueva"
>> <[hidden email]>
>> To: "vim mailing list" <[hidden email]>
>> Sent: Monday, July 25, 2005 6:59 PM
>> Subject: multiple same named buffer variables
>>
>>
>> >Hello,
>> >in the vim manual (section 41.11) it is recommended to use at the
>> >beginning
>> >of a ftplugin:
>> >   if exists("b:did_ftplugin")
>> >       finish
>> >   endif
>> >   let b:did_ftplugin = 1
>> >I wonder if that is correct, because what if you have for the same file
>> >type
>> >different plugins with that lines ? Only one ftplugin would be executed,
>> >wouldn't it ?
>> >Iv�n Villanueva
>>
>> For a single filetype, let's say "foobar", there can be at most one
>> "$VIMRUNTIME/ftplugin/foobar.vim".
> Thanks for the answer.
>
> IMHO the documentation doesn't say that "ftplugin" should be changed for
> the
> name of the file.
>
> Iv�n Villanueva

In most cases it shouldn't. The exception is the rare case where you have
several plugins from different sources (not one plugin and one or more
"after" customizations) which must all be run when a certain filetype is
detected.

Best regards,
Tony.


Reply | Threaded
Open this post in threaded view
|

Re: multiple same named buffer variables

Charles E Campbell Jr
(snipped a bit for brevity)

 ----- Original Message ----- From: "Ivan Villanueva"

> in the vim manual (section 41.11) it is recommended to use at the
> beginning of a ftplugin:
>
>   if exists("b:did_ftplugin")
>       finish
>   endif
>   let b:did_ftplugin = 1
>
> I wonder if that is correct, because what if you have for the same file
> type different plugins with that lines ? Only one ftplugin would be
> executed, wouldn't it?

Quoting Tony Mechelynck <[hidden email]>:
> For a single filetype, let's say "foobar", there can be at most one
> "$VIMRUNTIME/ftplugin/foobar.vim".

Quoting Ivan Villanueva:
> IMHO the documentation doesn't say that "ftplugin" should be changed for
> the name of the file.

Quoting Tony Mechelynck <[hidden email]>:
> In most cases it shouldn't. The exception is the rare case where you have
> several plugins from different sources (not one plugin and one or more
> "after" customizations) which must all be run when a certain filetype is
> detected.

Of course one may use whatever variable name one wants.

...
   if exists("b:did_ftplugin1")
       finish
   endif
   let b:did_ftplugin1 = 1
...
   if exists("b:did_ftplugin2")
       finish
   endif
   let b:did_ftplugin2 = 1
...

Regards,
Chip Campbell

Reply | Threaded
Open this post in threaded view
|

Re: multiple same named buffer variables

A.J.Mechelynck
----- Original Message -----
From: <[hidden email]>
To: <[hidden email]>
Sent: Tuesday, July 26, 2005 11:07 PM
Subject: Re: multiple same named buffer variables


> (snipped a bit for brevity)
>
> ----- Original Message ----- From: "Ivan Villanueva"
>> in the vim manual (section 41.11) it is recommended to use at the
>> beginning of a ftplugin:
>>
>>   if exists("b:did_ftplugin")
>>       finish
>>   endif
>>   let b:did_ftplugin = 1
>>
>> I wonder if that is correct, because what if you have for the same file
>> type different plugins with that lines ? Only one ftplugin would be
>> executed, wouldn't it?
>
> Quoting Tony Mechelynck <[hidden email]>:
>> For a single filetype, let's say "foobar", there can be at most one
>> "$VIMRUNTIME/ftplugin/foobar.vim".
>
> Quoting Ivan Villanueva:
>> IMHO the documentation doesn't say that "ftplugin" should be changed for
>> the name of the file.
>
> Quoting Tony Mechelynck <[hidden email]>:
>> In most cases it shouldn't. The exception is the rare case where you have
>> several plugins from different sources (not one plugin and one or more
>> "after" customizations) which must all be run when a certain filetype is
>> detected.
>
> Of course one may use whatever variable name one wants.
>
> ...
>   if exists("b:did_ftplugin1")
>       finish
>   endif
>   let b:did_ftplugin1 = 1
> ...
>   if exists("b:did_ftplugin2")
>       finish
>   endif
>   let b:did_ftplugin2 = 1
> ...
>
> Regards,
> Chip Campbell

Well, yes; only, alternate versions of a plugin (in, say,
$VIMRUNTIME/ftplugin and $VIM/vimfiles/ftplugin) should use the same name in
order that sourcing the one should disable the other. And remember that it's
a Bad_Thing (TM) to alter anything in or under $VIMRUNTIME except as the
result of a Vim install or upgrade. In most "common" cases, the name
b:did_ftplugin is OK; and since it is buffer-local, there is no possible
clash between plugins for different files.

Best regards,
Tony.