]> git.phdru.name Git - dotfiles.git/blobdiff - .vimrc
.mailcap: Give djview higher priority
[dotfiles.git] / .vimrc
diff --git a/.vimrc b/.vimrc
index 470a8007fe54115fb94e4006a4d2e7b2a59abc32..0ff6ea1ec534ac8bde907caba3e627d601bb0d86 100644 (file)
--- a/.vimrc
+++ b/.vimrc
@@ -343,7 +343,9 @@ function! SetupEncoding(encoding)
 
    call RestorePosition()
    let b:encoding_set = 1
-   execute "edit ++enc=" . a:encoding
+   if len(expand('%'))
+      execute "edit ++enc=" . a:encoding
+   endif
 endfunction
 
 
@@ -584,25 +586,28 @@ endif
 " From Tip 212:
 " http://vim.wikia.com/wiki/Setting_file_attributes_without_reloading_a_buffer
 
-function! SetExecutableBit(x)
-   if !executable('chmod')
-      return
-   endif
-   checktime
-   let fname = expand("%:p")
-   execute "au FileChangedShell " . fname . " :echo"
-   if a:x
-      silent !chmod a+x %
-   else
-      silent !chmod a-x %
-   endif
-   if v:shell_error
-      echoerr 'Error running chmod: ' . v:shell_error
-   endif
-   checktime
-   execute "au! FileChangedShell " . fname
-endfunction
-command! Xbit if executable(expand("%:p")) | call SetExecutableBit(0) | else | call SetExecutableBit(1) | endif
+if executable('chmod')
+   function! SetExecutableBit(x)
+      checktime
+      " Avoid 'Reload Y/N?' question
+      autocmd FileChangedShell <buffer> call _BufChangedCB()
+      let fx = executable(expand("%:p"))
+      if a:x && !fx
+         silent !chmod a+x %
+      elseif !a:x && fx
+         silent !chmod a-x %
+      endif
+      if v:shell_error
+         echoerr 'Error running chmod: ' . v:shell_error
+      endif
+      checktime
+   endfunction
+   function! _BufChangedCB()
+      autocmd! FileChangedShell <buffer>
+   endfunction
+   command! ToggleXbit if executable(expand("%:p")) | call SetExecutableBit(0) | else | call SetExecutableBit(1) | endif
+endif
+
 
 " ----------
 " From http://slobin.pp.ru/vim/_vimrc.html