I believe the problem you're having is due to the command being registered with
-buffer, which means it's only available in buffers of filetype "elm" and for some reason are not available in the autocmd.
Why that is happening, I can't really tell... The event you're using (
BufWritePost) is a buffer-specific example and I'd also expect it to run while the buffer is still around... But I might be wrong about that part perhaps...
It's not the case that this will be evaluated in a filetype
vim context, the autocmd commands are only really evaluated when called, not when they're defined. So not really sure what's going on there...
I can try to suggest a workaround though.
The definition of the
ElmMake command reads:
command -buffer -nargs=? -complete=file ElmMake call elm#Make(<f-args>)
So calling it without any arguments should be the equivalent to:
So just call that directly from your autocmd instead. The function definition is global and should work from any context.
For best practice, put it in an
augroup block, so it gets properly updated when you reload your vimrc:
au BufWritePost *.elm call elm#Make()
Hopefully that will solve the problem!