MarcWeber / vim-addon-manager

manage and install vim plugins (including their dependencies) in a sane way. If you have any trouble contact me. Usually I reply within 24 hours
Other
660 stars 59 forks source link

Plugin not autoloaded depending on filetype #55

Closed gabriellima closed 12 years ago

gabriellima commented 12 years ago

Hi. I have my own autoload.vim (customized, but very very poor)(I don't know well VimL)

I tryed to do the following:

let plugins = { 
     \ 'always': [ 'github:scrooloose/nerdcommenter', 'github:scrooloose/nerdtree', 'github:tpope/vim-repeat', 'github:tpope/vim-surround', 'github:tpope/   vim-unimpaired', 'github:godlygeek/tabular', 'github:garbas/vim-snipmate', 'github:honza/snipmate-snippets' ],
      \ 'python' : ['github:vim-scripts/pythonhelper', ],
      \ 'javascript' : ['jsbeautify'],
      \ }

The 'always' is working fine. Today I added some to the 'python', and when opened my python file it really cloned the repo (like expected), but not activated it.

Everytime I open any python file, I have to do :ActivateAddons github-vim-scripts-pythonhelper

Could anybody help?

Thanks in advance. :)

MarcWeber commented 12 years ago

This is not a VAM issue. Its a vim-addon-MarcWeber issue if at all - and that's a "private repo" which can serve as example. The keys are not related to filetypes. So recommend either reading the code and README or write your own custom way to load plugins lazily (if its worth the effort at all).

gabriellima commented 12 years ago

Marc, I made a mistake. I'm using the addon the correct way, the line that loads based on filetype is on my .vimrc (sorry to mention this), it's this line:

autocmd FileType * call vim_addon_GabrielLima#Activate([strtrans(&ft)])

which let addons be loadedbased on filetype (where &ft is the filetype, but I'm REALLY sure you know that based on your skills).

The problem is this:

The addon is only loaded when:

But opening it the straight way (vim my_file.py) does not load the addon.

Could you give anyother tip?

Thanks in advance

MarcWeber commented 12 years ago

Excerpts from gabriellima's message of Tue Feb 14 20:14:00 +0100 2012:

autocmd FileType * call vim_addon_GabrielLima#Activate([strtrans(&ft)]) I only use "all" for now. You may want to try debugging: autocmd FileType * debug call vim_addon_GabrielLima#Activate([strtrans(&ft)]) then you can debug the function step by step: c = continue s = step into function n = next step you can always use echo to debug vars and arguments.

And as I said: Is it really worth the effort?

gabriellima commented 12 years ago

I'll try this and come back with news.

About your question ('worth the effort'): It's that I'd like to open any filetype, and have its plugins loaded.

For now, I think (and will try) that any other plugin I add to my "python plugins list" will load correctly. So I think this is a pontual problem.

I'll come back with news.

Thanks again for attention @MarcWeber. You're a good man.

gabriellima commented 12 years ago

@MarcWeber I think I found the "problem".

I debug as you said, and found that:

When I exec vam#ActivateAddons(["github-vim-scripts-pythonhelper"]) before file is opened, the command used in the middle of vam#ActivateAddons is: vam#GlobThenSource(rtp.'/ftdetect/*.vim')

And when I exec the same command after the file is opened, the command used in the middle of vam#ActivateAddons is: vam#GlobThenSource(rtp.'/plugin/**/*.vim')

And only in this last call there are files to load (as this plugin only have plugin/**/*.vim files...

I even tried to run call vam#GlobThenSource(rtp.'/plugin/**/*.vim') right after the first command, and it worked!

This is all because of the check if !has('vim_starting') before choosing which folder path (ftdetect/*.vim or plugin/**/*.vim) to use.

EDIT:

I made more tests, and found that moving the pythonhelper plugin to the always key in the plugins dict make it load correctly.

Instead, moving all plugins to the python key in the dict made none of them being loaded...

I found that the difference in both steps (about placing plugins in the always or the python key) is that:

In the middle of the steps, when executing call call('vam#ActivateRecursively', args) (where args is a list with all plugin names in both tries...):

But I don't know WHERE this plugins were loaded, as I was debugging step by step....

I think its worth the effort to only have plugins loaded based on my call (filetype, anything else...) (that was my second intention when found VAM, after thinking that VAM is the best way to manage plugins).

Thanks in advance!!!

MarcWeber commented 12 years ago

And when I exec the same command after the file is opened, the command used in the middle of vam#ActivateAddons is: vam#GlobThenSource(rtp.'/plugin/**/*.vim')

do e! (reload the file) - but it kinda sucks - and may cause loops. Thus do bufdo e! in those plugins - but it still sucks.

Seriously: Benchmark how long loading this plugin always takes for you.

if you have much in plugin/.vim the fix is to use autoload/ files.

First tell me how much time loading that plugin takes (tlib has benchmarking functions you can use, also see VAM-kr which contains a sample in comments in autoload/* for json parsing) Also vim has benchmarking built in.

Sum times for each .vim file. Then I'll judge whether I want to continue giving support for something which is insane IMHO. You should not over optimize your setup. Will take more time than providing value to you IHMO

First proof that its worth the effort.

Marc Weber

gabriellima commented 12 years ago

As this will proove your point about taking time to solve something that maybe (like you said) don't have too much time to load, I think I'll stay as is with this.

By the way, the e! tip did not work. But I'll let my plugins be always in the always key of the dict.

Sometime, when I have 10+ plugins added there, I'll re-read this issue, make a benchmark, and come back with more news.

Really thank you for attention, Marc.

MarcWeber commented 12 years ago

See latest commits. zk came up with a way and asked for it as well. You may want to try the experimental samples.

gabriellima commented 12 years ago

I'll try to look at it @6f42a9f0fd2da723b8af4816b36e23dfcaa26e31 as soon as possible.

Thanks again for giving attention to this question.

gabriellima commented 12 years ago

Marc, I tried to do the benchmark you asked, but the line

au FileType * for l in values(filter(copy(ft_addons), string(expand('<amatch>')).' =~ v:key')) | call vam#ActivateAddons(l) | endfor

did not load plugins based on the opened filetype. What am I doing wrong?

let ft_addons = { 
     \ 'always': ['github:scrooloose/nerdcommenter', 'github:scrooloose/nerdtree', 'github:tpope/vim-repeat', 'github:tpope/vim-surround', 'github:tpope/vim-unimpaired', 'github:godlygeek/tabular', 'github:garbas/vim-snipmate', 'github:honza/snipmate-snippets', 'github:goatslacker/mango.vim', 'github:xolox/vim-  session'],
      \ 'python' : ['github:vim-scripts/pythonhelper'],
      \ 'javascript' : ['jsbeautify'],
      \ }
MarcWeber commented 12 years ago

Excerpts from gabriellima's message of Tue Feb 28 04:17:37 +0100 2012:

did not load plugins based on the opened filetype. What am I doing wrong? What do you get/ what do you expect?

I've tested this:

let ft_addons = { \ '^\%(c|cpp)$': [ 'plugin-for-c-development' ], \ 'javascript': [ 'plugin-for-javascript' ] \ } au FileType * for l in values(filter(copy(ft_addons), string(expand('')).' =~ v:key')) | call vam#ActivateAddons(l) | endfor

If you open a .c file you're getting messages about plugin-for-c-development not being known by VAM.

gabriellima commented 12 years ago

It "worked", Marc. But only when opening files after opening vim.

If I open the file directly, like: vim ~/my_file.py, it doesn't load the "python" addons.

It only loads if I open vim first, and then: :e ~/my_file.py

Do you have any clue for this?

Another question: I'd like to have an 'always' key (like on that old days...), so that every addon on that key would be loaded always (not depending on FileType).

I think this line solves this issue: au BufNewFile,BufRead * for l in values(filter(copy(ft_addons), '"always". =~ v:key')) | call vam#ActivateAddons(l) | endfor

but only after the issue about opening vim first is solved.

Also, if you have another better idea (and I'm pretty sure you have) to load the always addons, I'd like to know :)

Thank you in advance.

MarcWeber commented 12 years ago

Can you try this? http://mawercer.de/~marc/patch.patch

It think its Vim "delaying" loading plugins until .vimrc has been processed.

If this does not help I don't know. And I'd rather work on the vim homepage that fixing this right now.

Marc Weber

gabriellima commented 12 years ago

Yes, it worked. Thanks!

Could you help me just with the always part? I'm not figuring it out correctly.

   let ft_addons = { 
    \ 'always': [ 'github:scrooloose/nerdtree', 'github:goatslacker/mango.vim' ],
    \ 'python': [ 'github:vim-scripts/pythonhelper' ],
    \ 'javascript': [ 'plugin-for-javascript' ]
  \ }

Tried with: au VimEnter * for l in values(filter(copy(ft_addons), string('always'). '=~ v:key')) | call vam#ActivateAddons(l,{'force_loading_plugins_now':1}) | endfor

but with a color mango too much after this command, vim raised error that couldn't file the colorscheme, although I could open NerdTree.

gabriellima commented 12 years ago

Solved. Just removed the autocmd from the start of the line. Sorry for this noob question.

For other users that may be interested, my final setting result:

let ft_addons = { 
    \ 'always': [ 'github:scrooloose/nerdcommenter', 'github:scrooloose/nerdtree', 'github:tpope/vim-repeat', 'github:tpope/vim-surround', 'github:tpope/vim-unimpaired', 'github:godlygeek/tabular', 'github:garbas/vim-snipmate', 'github:honza/snipmate-snippets', 'github:goatslacker/mango.vim', 'github:xolox/vim-session' ],
    \ 'python': [ 'github:vim-scripts/pythonhelper' ],
    \ 'javascript': [ 'plugin-for-javascript' ]
\ }
call vam#ActivateAddons(ft_addons['always'], {'auto_install': 1}) 
au FileType * for l in values(filter(copy(ft_addons), string(expand('<amatch>')).' =~ v:key')) | call vam#ActivateAddons(l,{'force_loading_plugins_now':1, 'auto_install': 1}) | endfor

" When editing a file, always jump to the last known cursor position.
au BufReadPost *
  \ if line("'\"") > 0 && line("'\"") <= line("$") |
  \   exe "normal g`\"" |
  \ endif

Thank you @MarcWeber!!

MarcWeber commented 12 years ago

You're welcome. Keep sharing your ideas.