[vim/vim] Inconsistant plugin sourcing order (#8362)

9 views
Skip to first unread message

Romain Lafourcade

unread,
Jun 11, 2021, 3:13:10 AM6/11/21
to vim/vim, Subscribed

Describe the bug

Optional plugins added with :packadd! foo are not sourced in the prescribed order.

To Reproduce

  1. Create the following directory structure:

    pack/brands/start/adidas/plugin/adidas.vim
    pack/brands/start/nike/plugin/nike.vim
    pack/brands/start/puma/plugin/puma.vim
    
  2. Start Vim and do: :filter brands scriptnames:

      9: ~/.vim/pack/brands/start/adidas/plugin/adidas.vim
     10: ~/.vim/pack/brands/start/nike/plugin/nike.vim
     11: ~/.vim/pack/brands/start/puma/plugin/puma.vim
    

Plugins are sourced in filesystem order, which seems intuitive enough.

  1. Rename pack/brands/start to pack/brands/opt:

    pack/brands/opt/adidas/plugin/adidas.vim
    pack/brands/opt/nike/plugin/nike.vim
    pack/brands/opt/puma/plugin/puma.vim
    
  2. Add the following at the top of $MYVIMRC:

    filetype on
    packadd! adidas
    packadd! nike
    packadd! puma
    finish
    
  3. Start Vim and do :filter brands scriptnames:

      9: ~/.vim/pack/brands/start/puma/plugin/puma.vim
     10: ~/.vim/pack/brands/start/nike/plugin/nike.vim
     11: ~/.vim/pack/brands/start/adidas/plugin/adidas.vim
    

Plugins are sourced in reverse :packadd order, which is not documented and rather counter-intuitive.

Expected behavior

Sourcing order should be the same as :packadd order:

     9: ~/.vim/pack/brands/start/adidas/plugin/adidas.vim
    10: ~/.vim/pack/brands/start/nike/plugin/nike.vim
    11: ~/.vim/pack/brands/start/puma/plugin/puma.vim

Environment

  • Vim version: 8.0.1365, 8.2.2681
  • OS: mac0S 10.14.16
  • Terminal: Irrelevant (happens in both GUI and TUI)


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.

Bram Moolenaar

unread,
Jun 11, 2021, 1:21:39 PM6/11/21
to vim/vim, Subscribed

This to be expected, ":packadd!" does not load the pack, that is postponed. Thus the order can change. And the implementation prepends the directory to 'runtimepath', thus the order is reversed.
I'll add a note in the documentation. In general the order doesn't matter anyway.

Romain Lafourcade

unread,
Jun 11, 2021, 2:26:46 PM6/11/21
to vim/vim, Subscribed

And the implementation prepends the directory to 'runtimepath', thus the order is reversed.

The directories are added to &rtp in the same order in both cases, though:

[…]

/Users/romainl/.vim/pack/brands/start/puma,

/Users/romainl/.vim/pack/brands/start/nike,

/Users/romainl/.vim/pack/brands/start/adidas,

[…]

and:

[…]

/Users/romainl/.vim/pack/brands/opt/puma,

/Users/romainl/.vim/pack/brands/opt/nike,

/Users/romainl/.vim/pack/brands/opt/adidas,

[…]

and yet the plugins are sourced in different orders:

  • the same as &rtp when using opt and :packadd!,
  • the reverse of &rtp when using start.

which I can't explain.

In general the order doesn't matter anyway.

"In general", maybe, but apparently not in some specific cases involving popular plugins.

Bram Moolenaar

unread,
Jun 11, 2021, 4:10:18 PM6/11/21
to vim/vim, Subscribed

In the first case the packs are added when found, and the directory is added in 'runtimepath' in that order.
When using packadd! the directories are added to 'runtimepath' and only later the packs are added, when finding plugins in 'runtimepath'.

Romain Lafourcade

unread,
Jun 11, 2021, 4:55:19 PM6/11/21
to vim/vim, Subscribed

The problem with this is that, when adding those directories manually to &rtp, the plugins are sourced in the order they were added: you add adidas, then nike, then puma and they are sourced in that order.

If I can expect the outcome for the following snippet:

let rtp1 = &rtp->split(',')->filter({ idx, val -> val !~ "after$" })
let rtp2 = &rtp->split(',')->filter({ idx, val -> val =~ "after$" })

call add(rtp1, '/Users/romainl/.vim/pack/brands/foo/nike')
call add(rtp1, '/Users/romainl/.vim/pack/brands/foo/adidas')
call add(rtp1, '/Users/romainl/.vim/pack/brands/foo/puma')

let &rtp = (rtp1 + rtp2)->join(',')

to be that the plugins are sourced in the specified order, why can't I expect the same outcome for the following snippet?

:packadd! nike
:packadd! adidas
:packadd! puma
Reply all
Reply to author
Forward
0 new messages