From 38819aedae8a153aa7dde70bf50f3c3b97ade9aa Mon Sep 17 00:00:00 2001 From: Kevin MacMartin Date: Tue, 28 Oct 2014 14:28:04 -0400 Subject: [PATCH] Redetect filetype after saving as new name + wrap autocmd with check --- vim/config/settings.vim | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/vim/config/settings.vim b/vim/config/settings.vim index 8921781..ccc8ef0 100644 --- a/vim/config/settings.vim +++ b/vim/config/settings.vim @@ -84,17 +84,25 @@ set timeout timeoutlen=500 "how long before timing out for mappings set ttimeout ttimeoutlen=100 "how long before timing out for terminal key codes - "enable the auto-creation of missing folders in a save path - if !exists('*s:MakeNewDir') - function s:MakeNewDir(fullpath, buf) - if empty(getbufvar(a:buf,'&buftype')) && a:fullpath!~#'\v^\w+\:\/' - let dirpath=fnamemodify(a:fullpath,':h') - if !isdirectory(dirpath)|call mkdir(dirpath,'p')|endif - endif - endfunction - augroup WriteDir + if has('autocmd') + "enable the auto-creation of missing folders in a save path + if !exists('*s:MakeNewDir') + function s:MakeNewDir(fullpath, buf) + if empty(getbufvar(a:buf,'&buftype')) && a:fullpath!~#'\v^\w+\:\/' + let dirpath=fnamemodify(a:fullpath,':h') + if !isdirectory(dirpath)|call mkdir(dirpath,'p')|endif + endif + endfunction + augroup WriteDir + autocmd! + autocmd BufWritePre * :call s:MakeNewDir(expand(''),+expand('')) + augroup END + endif + + "update the current filetype when a file is renamed + augroup RenameCheckFiletype autocmd! - autocmd BufWritePre * :call s:MakeNewDir(expand(''),+expand('')) + autocmd BufFilePost * filetype detect augroup END endif "}}}