I have the following function in an autoload file:
function! closet#FindSkeletonForFile() if exists('b:closet_skeleton') return 0 endif let b:closet_skeleton = s:closet.find_skeleton_for_file(expand('%:p'), &filetype) if b:closet_skeleton !=# '' let cpopts = &cpoptions set cpoptions-=a echom "Here goes the read:" execute '0read '.fnameescape(b:closet_skeleton) let &cpoptions = cpopts return 1 endif return 0 endfunction
This is triggered by a BufNewFile autocommand, and it appears to be working. The autocmd is in my
plugin/closet.vim file, and looks like this:
augroup closet autocmd! autocmd BufNewFile * call closet#FindSkeletonForFile() augroup END
When I invoke
vi foo.vim (a file that does not exist) I get an empty buffer, some of my earlier code identifies valid skeletons, I get a confirm dialog, the filename is returned, and the
s:closet.find_skeleton_for_file(...) function returns the correct value.
echom outputs to the message log, and when I run
:mess in the new vim window, I see this:
Messages maintainer: Bram Moolenaar <Bram@vim.org> Here goes the read: "~/Code/aghast/vim-closet/Closet/plugin.vim" 28L, 448C Press ENTER or type command to continue
This tells me that the dummy plugin is being read somewhere, since those line/character numbers are what I see when I edit the dummy file.
foo.vim buffer doesn't get changed! Since I can see the code being run correctly (many, many :echom statements) I'm pretty sure it's just down to getting that
0read statement to ... well, read!
Can someone clue me in on the obvious thing I've missed?