sourcing of plugins in wrong order

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

sourcing of plugins in wrong order

enk

Hi,
when I open a php file, both ~/.vim/ftplugin/php.vim and
~/.vim/ftplugin/html.vim are sourced. And in that order, which makes
the latter override the former. I have the same problem with C++ and
C.

I see the stuff in $VIMRUNTIME/ftplugin/ runtimes the others, but can
I get it the other way round without tampering with the global files?

Kind regards,
Erik Wognsen

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

Reply | Threaded
Open this post in threaded view
|

Re: sourcing of plugins in wrong order

Benjamin Fritz

On May 20, 2:22 am, Erik Wognsen <[hidden email]> wrote:
> Hi,
> when I open a php file, both ~/.vim/ftplugin/php.vim and
> ~/.vim/ftplugin/html.vim are sourced. And in that order, which makes
> the latter override the former. I have the same problem with C++ and
> C.
>
> I see the stuff in $VIMRUNTIME/ftplugin/ runtimes the others, but can
> I get it the other way round without tampering with the global files?
>

What do you mean? php.vim sources html.vim VERY early in the file,
before it sets any options. html.vim is not sourced after php.vim, it
is sourced DURING the execution of php.vim. It is php.vim that
overrides html.vim, not the other way around.
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

enk
Reply | Threaded
Open this post in threaded view
|

Re: sourcing of plugins in wrong order

enk

You're right. But the problem is still there.

I moved my whole ~/.vim tree and created a new one with just these two files:

~/.vim/ftplugin/html.vim
~/.vim/ftplugin/php.vim

containing one line each:

nn <buffer> <F2> Ahtml<esc>
nn <buffer> <F2> Aphp<esc>

respectively. Now I edit a php file and press F2....

I get "html" :-(


On Wed, May 20, 2009 at 16:51, Ben Fritz <[hidden email]> wrote:

>
> On May 20, 2:22 am, Erik Wognsen <[hidden email]> wrote:
>> Hi,
>> when I open a php file, both ~/.vim/ftplugin/php.vim and
>> ~/.vim/ftplugin/html.vim are sourced. And in that order, which makes
>> the latter override the former. I have the same problem with C++ and
>> C.
>>
>> I see the stuff in $VIMRUNTIME/ftplugin/ runtimes the others, but can
>> I get it the other way round without tampering with the global files?
>>
>
> What do you mean? php.vim sources html.vim VERY early in the file,
> before it sets any options. html.vim is not sourced after php.vim, it
> is sourced DURING the execution of php.vim. It is php.vim that
> overrides html.vim, not the other way around.
> >
>

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

Reply | Threaded
Open this post in threaded view
|

Re: sourcing of plugins in wrong order

Gary Johnson-4

On 2009-05-21, Erik Wognsen wrote:

> On Wed, May 20, 2009 at 16:51, Ben Fritz <[hidden email]> wrote:
> >
> > On May 20, 2:22 am, Erik Wognsen <[hidden email]> wrote:
> >> Hi,
> >> when I open a php file, both ~/.vim/ftplugin/php.vim and
> >> ~/.vim/ftplugin/html.vim are sourced. And in that order, which makes
> >> the latter override the former. I have the same problem with C++ and
> >> C.
> >>
> >> I see the stuff in $VIMRUNTIME/ftplugin/ runtimes the others, but can
> >> I get it the other way round without tampering with the global files?
> >>
> >
> > What do you mean? php.vim sources html.vim VERY early in the file,
> > before it sets any options. html.vim is not sourced after php.vim, it
> > is sourced DURING the execution of php.vim. It is php.vim that
> > overrides html.vim, not the other way around.

> You're right. But the problem is still there.
>
> I moved my whole ~/.vim tree and created a new one with just these two files:
>
> ~/.vim/ftplugin/html.vim
> ~/.vim/ftplugin/php.vim
>
> containing one line each:
>
> nn <buffer> <F2> Ahtml<esc>
> nn <buffer> <F2> Aphp<esc>
>
> respectively. Now I edit a php file and press F2....
>
> I get "html" :-(

Right.  When you open a php file, vim loads all the php.vim files[1]
in your 'runtimepath', typically (for Unix):

    $HOME/.vim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,$HOME/.vim/after

So in your case, vim will load, in this order,

    ~/.vim/ftplugin/php.vim
    $VIMRUNTIME/ftplugin/php.vim

That second file contains this line:

    runtime! ftplugin/html.vim ftplugin/html_*.vim ftplugin/html/*.vim

which will cause vim to load

    ~/.vim/ftplugin/html.vim
    $VIMRUNTIME/ftplugin/html.vim

thereby leaving <F2> set to add "html".

To do what you want to do, a better place to put your customizations
is in the ~/.vim/after/ftplugin directory, i.e., in the files

    ~/.vim/after/ftplugin/html.vim
    ~/.vim/after/ftplugin/php.vim

The loading order for all these plugins would then be:

    ~/.vim/ftplugin/php.vim
    $VIMRUNTIME/ftplugin/php.vim
    ~/.vim/ftplugin/html.vim
    $VIMRUNTIME/ftplugin/html.vim
    ~/.vim/after/ftplugin/html.vim
    ~/.vim/after/ftplugin/php.vim


BTW, the convention is this group is to bottom post, not top post.

Regards,
Gary

----------
[1]  This is a simplification, but adequate for the current purpose.
See ":help ftplugin-name" for more.



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

enk
Reply | Threaded
Open this post in threaded view
|

Re: sourcing of plugins in wrong order

enk

> Right.  When you open a php file, vim loads all the php.vim files[1]
> in your 'runtimepath', typically (for Unix):
>
>    $HOME/.vim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,$HOME/.vim/after
>
> So in your case, vim will load, in this order,
>
>    ~/.vim/ftplugin/php.vim
>    $VIMRUNTIME/ftplugin/php.vim
>
> That second file contains this line:
>
>    runtime! ftplugin/html.vim ftplugin/html_*.vim ftplugin/html/*.vim
>
> which will cause vim to load
>
>    ~/.vim/ftplugin/html.vim
>    $VIMRUNTIME/ftplugin/html.vim
>
> thereby leaving <F2> set to add "html".
>
> To do what you want to do, a better place to put your customizations
> is in the ~/.vim/after/ftplugin directory, i.e., in the files
>
>    ~/.vim/after/ftplugin/html.vim
>    ~/.vim/after/ftplugin/php.vim
>
> The loading order for all these plugins would then be:
>
>    ~/.vim/ftplugin/php.vim
>    $VIMRUNTIME/ftplugin/php.vim
>    ~/.vim/ftplugin/html.vim
>    $VIMRUNTIME/ftplugin/html.vim
>    ~/.vim/after/ftplugin/html.vim
>    ~/.vim/after/ftplugin/php.vim

Thanks for the explanation!

It makes me wonder: Does it ever serve a purpose to use
~/.vim/ftplugin/ instead of ~/.vim/after/ftplugin/ ?

> BTW, the convention is this group is to bottom post, not top post.

Sorry, back on track..

/Erik

> Regards,
> Gary
>

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

Reply | Threaded
Open this post in threaded view
|

Re: sourcing of plugins in wrong order

Gary Johnson-4

On 2009-05-21, Erik Wognsen wrote:

> It makes me wonder: Does it ever serve a purpose to use
> ~/.vim/ftplugin/ instead of ~/.vim/after/ftplugin/ ?

The only purpose I can think of would be to _replace_ a global
filetype plugin with either your own or a more recent version from
vim.sf.net.  By adding the appropriate code to a plugin in
~/.vim/ftplugin, you can prevent the code in the global plugin from
being executed.  (See ":help ftplugin-overrule" and ":help
ftplugin".)

Otherwise, whether you're making changes to the settings made by a
global filetype plugin or creating your own filetype plugin for a
file type for which there is no global filetype plugin, you might as
well just put it in ~/.vim/after/ftplugin.

Regards,
Gary



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

enk
Reply | Threaded
Open this post in threaded view
|

Re: sourcing of plugins in wrong order

enk

>> It makes me wonder: Does it ever serve a purpose to use
>> ~/.vim/ftplugin/ instead of ~/.vim/after/ftplugin/ ?
>
> The only purpose I can think of would be to _replace_ a global
> filetype plugin with either your own or a more recent version from
> vim.sf.net.  By adding the appropriate code to a plugin in
> ~/.vim/ftplugin, you can prevent the code in the global plugin from
> being executed.  (See ":help ftplugin-overrule" and ":help
> ftplugin".)
>
> Otherwise, whether you're making changes to the settings made by a
> global filetype plugin or creating your own filetype plugin for a
> file type for which there is no global filetype plugin, you might as
> well just put it in ~/.vim/after/ftplugin.

Thanks..

I think it would have been more logical to source ~/.vim/ftplugin as
"after", though, and then if you wanted the pre-sourcing, you could
stick it in ~/.vim/before/ftplugin.

/Erik

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