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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 20 additions & 2 deletions doc/editorconfig.txt
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,28 @@ file:

return 0 " Return 0 to show no error happened
endfunction

<
If the plugin is installed with a plugin manager that loads it while parsing
the |vimrc|, then we can immediately add this hook:
>
call editorconfig#AddNewHook(function('FiletypeHook'))
<
And add the following code to your .editorconfig file:
If the plugin is installed as part of a Vim 8 |package|, it will not be loaded
until after the |vimrc| file has been parsed. This may be the case with some
other plugin managers too. As a result, the above call to add the hook will not
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

<
Alternatively, to avoid the autocommand, or to work with versions of vim older
than 8.1.0729 where |SourcePost| is not available, then we can add a
plugin/editorconfig.vim file to an |after-directory|. This will be run at the
end of vim startup, and should contain the original call command to add the
hook. The definition of the FiletypeHook function can either remain in the
|vimrc| or be moved to the after file.

Now add the following code to your .editorconfig file:
>
[*.m]
vim_filetype = objc
Expand Down