When `checktime` is called in an autocommand
it doesn't trigger FileChangedShell immediately.
Instead it waits until the end of the autocommand.
So we have to remove FileChangedShell autocommand
when it's triggered, not inside SetExecutableBit function
called from an autocommand.
checktime
let fname = expand("%:p")
let fx = executable(fname)
- execute "au FileChangedShell " . fname . " :echo"
+ execute "au FileChangedShell <buffer> call _BufChangedCB()"
if a:x && !fx
!chmod a+x %
elseif !a:x && fx
echoerr 'Error running chmod: ' . v:shell_error
endif
checktime
- execute "au! FileChangedShell " . fname
+ endfunction
+ function! _BufChangedCB()
+ execute "au! FileChangedShell <buffer>"
endfunction
command! ToggleXbit if executable(expand("%:p")) | call SetExecutableBit(0) | else | call SetExecutableBit(1) | endif
endif