Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FileType for load autocmd FileType settings. #7

Closed
wants to merge 2 commits into from

Conversation

heavenshell
Copy link
Contributor

Hi, nice plugin I like it. But I've got a problem.

I use jedi.vim which is auto complete for Python.
I've Downloaded jedi.vim to ~/.vim/ftbundle/python/ and then open python file.
But jedi.vim did not work at GUI MacVim.app.
(CUI MacVim works well)

unbundle.vim did not load autocmd FileType when ftbundle plugin loaded.

jedi.vim defined autocmd FileType python at https://github.com/davidhalter/jedi-vim/blob/master/plugin/jedi.vim#L49
(One of the example using autocmd FileType)

IMHO unbundle.vim is heavily related with filetype. A lot of FileType plugin defined autocmd FileType.

So, I add FileType to doautoall.

Please check and include.

Regards,

@sunaku
Copy link
Owner

sunaku commented Jan 10, 2013

Thanks for the patch.

But I have one concern: Unftbundle() ends up calling itself because the doautoall FileType inside Unftbundle() triggers the autocmd FileType call Unftbundle() directive near the bottom of unbundle.vim. Thankfully, the recursion is not infinite. 😅

Also, the BufRead event should have caused set filetype=python when you opened a *.py file. I wonder why this does not occur in MacVim GUI? 🍎

@heavenshell
Copy link
Contributor Author

Hi, thanks for quick reply.

Also, the BufRead event should have caused set filetype=python when you opened a *.py file. I wonder why this does not occur in MacVim GUI?

I reproduced in Windows GUI/CUI Vim following steps(I use old Windows XP).

  1. Startup Vim
  2. At this point, filetype does not set because nothing in buffer
  3. Type :set ft=python to change filetype
  4. Now unbundle.vim did not load autocmd FileType.

Sorry, I hava no idea why CUI MacVim works ok :-(

Regards,

@heavenshell
Copy link
Contributor Author

Hi,

I continute to look into this problem. I think another plugin conflict to jedi.vim.
Would you please wait to merge or it's ok to reject this patch.
If this problem occuerd by unbundle.vim, I'll report you.

I applicate your kindness.

Regards,

@sunaku
Copy link
Owner

sunaku commented Jan 11, 2013

Sure, I will wait. There's no hurry. 😇

@heavenshell
Copy link
Contributor Author

HI,
I catch up this problem.

The reason why this problem occured by filetype plugin on before unbundle.vim load.

If filetype plugin on set before unbundle.vim, need to reload filetype for execute autocmd FileType.
Because filetype plugin on execute autocmd FileType once.

Following code is a sample to check autocmd behavior.

autocmd!
set nocompatible

filetype indent plugin on
filetype off
filetype indent plugin on

autocmd FileType vim call s:Sample()

function! s:Sample()
  echomsg 'sample'
endfunction

This script echo sample once.

A lot of Japanese Vim user favor to use Vim-Kaoriya package which are included Original Vim binary + additional plugins + some patches.
This package contains vimrc_example.vim and load before $HOME/.vimrc load.
And vimrc_example.vim conatines filetype plugin indent on.

FYI Vim detect $VIM/{vimrc,.vimrc,_vimrc} load it and then load $HOME/.vimrc.
Using this package, filetype indnt plugin always on.

So autocmd FileType already executed before unbundle.vim load.

Followings are use-cases of filetype state when unbundle.vim loaded.

  1. filetype plugin:OFF -> Did not set filetype plugin on before. This case is OK to load autocmd FileType because unbundle.vim set fietype plugin indent on at last.
  2. filetype plugin:ON -> autocmd FileType already executed. So need to reload autocmd FileType
  3. filetype plugin:(on) -> filetype is off but already executed filetype plugin on before. So need to reload autocmd FileType

I update my patch.
Checking filetype loaded or not, if filetype is OFF, nothings to do.
Otherwise set filetype again to execute autocmd FileType.

BTW I reported MacVim CUI works ok before, sorry that was my probrem.
I aliased vim to vim -u $HOME/.vimrc to not load example_vimrc.vim :-p

Please check.

Regards,

@sunaku
Copy link
Owner

sunaku commented Jan 15, 2013

Thanks for the explanation and updated patch! ✨

What if we turn off filetype detection before turning it on?

diff --git a/unbundle.vim b/unbundle.vim
index 09b47bd..b25b91f 100644
--- a/unbundle.vim
+++ b/unbundle.vim
@@ -49,5 +49,6 @@ augroup Unftbundle
   autocmd!
   autocmd FileType * call Unftbundle(expand('<amatch>'))
 augroup END
 runtime! ftbundle/*/*/ftdetect/*.vim
+filetype off
 filetype plugin indent on

Would that solve the problem?

@heavenshell
Copy link
Contributor Author

Hi, thank you for comment.

Would that solve the problem?

No.
If already filetype plugin on before unbundle.vim, 2nd filetype plugin on did not execute autocmd FileType.
IMHO this is Vim's spec.
Please see :h filetype-off.

You can see filetype info to type :filetype.

  1. start Vim $ vim -u NONE -U NONE -N
  2. type :filetype
  3. shows filetype detection:OFF plugin:OFF indent:OFF
  4. type :filetype plugin on and :filetype
  5. shows filetype detection:ON plugin:ON indent:OFF
  6. type :filetype off and :filetype
    7 shows filetype detection:OFF plugin:(on) indent:OFF
    plugin:(on) means Vim caches filetype plugin flag.
    So autocmd FileType did not execute again.

Regards,

@sunaku
Copy link
Owner

sunaku commented Jan 16, 2013

Thanks for the detailed analysis! 👍

Since Vim is caching the filetype plugin flag at step 7, let's try turning off all filetype flags:

diff --git a/unbundle.vim b/unbundle.vim
index 09b47bd..b25b91f 100644
--- a/unbundle.vim
+++ b/unbundle.vim
@@ -49,5 +49,6 @@ augroup Unftbundle
   autocmd!
   autocmd FileType * call Unftbundle(expand('<amatch>'))
 augroup END
 runtime! ftbundle/*/*/ftdetect/*.vim
+filetype plugin indent off
 filetype plugin indent on

Does that solve it?

By the way, I am asking you these additional questions because I think the solution can be made shorter (less lines of code). Thanks for your patience.

@heavenshell
Copy link
Contributor Author

Hi,

Great, it's works!
Very nice 👍

By the way, I am asking you these additional questions because I think the solution can be made shorter (less lines of code). Thanks for your patience.

Totally agree with you.

Thank you for solving problem.

@sunaku
Copy link
Owner

sunaku commented Jan 16, 2013

Merged as c854f6a. Thanks for your contribution! 😺

@sunaku sunaku closed this Jan 16, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants