home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / runtime / ftplugin / gitcommit.vim < prev    next >
Encoding:
Text File  |  2012-05-31  |  2.1 KB  |  68 lines

  1. " Vim filetype plugin
  2. " Language:    git commit file
  3. " Maintainer:    Tim Pope <vimNOSPAM@tpope.org>
  4. " Last Change:    2012 April 7
  5.  
  6. " Only do this when not done yet for this buffer
  7. if (exists("b:did_ftplugin"))
  8.   finish
  9. endif
  10.  
  11. runtime! ftplugin/git.vim
  12. let b:did_ftplugin = 1
  13.  
  14. setlocal nomodeline
  15.  
  16. let b:undo_ftplugin = 'setl modeline<'
  17.  
  18. if &textwidth == 0
  19.   " make sure that log messages play nice with git-log on standard terminals
  20.   setlocal textwidth=72
  21.   let b:undo_ftplugin .= "|setl tw<"
  22. endif
  23.  
  24. if exists("g:no_gitcommit_commands") || v:version < 700
  25.   finish
  26. endif
  27.  
  28. if !exists("b:git_dir")
  29.   let b:git_dir = expand("%:p:h")
  30. endif
  31.  
  32. command! -bang -bar -buffer -complete=custom,s:diffcomplete -nargs=* DiffGitCached :call s:gitdiffcached(<bang>0,b:git_dir,<f-args>)
  33.  
  34. function! s:diffcomplete(A,L,P)
  35.   let args = ""
  36.   if a:P <= match(a:L." -- "," -- ")+3
  37.     let args = args . "-p\n--stat\n--shortstat\n--summary\n--patch-with-stat\n--no-renames\n-B\n-M\n-C\n"
  38.   end
  39.   if exists("b:git_dir") && a:A !~ '^-'
  40.     let tree = fnamemodify(b:git_dir,':h')
  41.     if strpart(getcwd(),0,strlen(tree)) == tree
  42.       let args = args."\n".system("git diff --cached --name-only")
  43.     endif
  44.   endif
  45.   return args
  46. endfunction
  47.  
  48. function! s:gitdiffcached(bang,gitdir,...)
  49.   let tree = fnamemodify(a:gitdir,':h')
  50.   let name = tempname()
  51.   let git = "git"
  52.   if strpart(getcwd(),0,strlen(tree)) != tree
  53.     let git .= " --git-dir=".(exists("*shellescape") ? shellescape(a:gitdir) : '"'.a:gitdir.'"')
  54.   endif
  55.   if a:0
  56.     let extra = join(map(copy(a:000),exists("*shellescape") ? 'shellescape(v:val)' : "'\"'.v:val.'\"'"))
  57.   else
  58.     let extra = "-p --stat=".&columns
  59.   endif
  60.   call system(git." diff --cached --no-color --no-ext-diff ".extra." > ".(exists("*shellescape") ? shellescape(name) : name))
  61.   exe "pedit ".(exists("*fnameescape") ? fnameescape(name) : name)
  62.   wincmd P
  63.   let b:git_dir = a:gitdir
  64.   command! -bang -bar -buffer -complete=custom,s:diffcomplete -nargs=* DiffGitCached :call s:gitdiffcached(<bang>0,b:git_dir,<f-args>)
  65.   nnoremap <buffer> <silent> q :q<CR>
  66.   setlocal buftype=nowrite nobuflisted noswapfile nomodifiable filetype=git
  67. endfunction
  68.