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

Update FiletypeHook example for installation as Vim 8 package. #162

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bcbnz
Copy link

@bcbnz bcbnz commented Dec 10, 2020

Packages are loaded after vimrc is parsed, so we can't add the hook immediately. Suggest using either an autocommand or a file in an after-directory to add the hook instead.

Fixes: #161 -- note rather than only one method as I suggested in the issue, I've gone with three here. The autocommand might not work for other plugin managers (if they source the file before getting to the autocommand, it won't be triggered). Using the after-directory feels less nice to me, but I included it for anybody who doesn't want to use autocommands or has an older version of vim which doesn't support the SourcePost event.

First time I've tried editing vim help files, hopefully I got all the syntax correct! It appeared to work for me :).

Packages are loaded after vimrc is parsed, so we can't add the hook immediately.
Suggest using either an autocommand or a file in an after-directory to add the
hook instead.

Fixes: editorconfig#161
@xuhdev
Copy link
Member

xuhdev commented Jul 21, 2021

@cxw42 Could you help review this, please? I don't use Vim8 much these days and it's hard for me to review.

@cxw42 cxw42 self-requested a review July 27, 2021 01:27
work as the function will not have been loaded yet. Instead, we can use the
|SourcePost| autocommand event to add the hook after the plugin is loaded:
>
autocmd SourcePost */plugin/editorconfig.vim call editorconfig#AddNewHook(function('FiletypeHook'))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks reasonable to me. However, could you use the VimEnter event instead? That way it would not depend on the filename. I don't think the filename will ever change, but I'd rather not add that restriction if we don't have to.

I tried this just now and it worked (vim 8.1, Ubuntu package ver. 2:8.1.2269-1ubuntu5):

let g:CrazyCount = 0
function MyCrazyHook(config)
  echom "Crazy!"
  let g:CrazyCount = g:CrazyCount+1
  return 0
endfunction

let g:EditorConfig_verbose = 1

augroup ectest
  autocmd!
  autocmd VimEnter * call editorconfig#AddNewHook(function('MyCrazyHook'))
augroup END

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.

Installing hooks when using Vim8 plugin
3 participants