Mercurial > vim
annotate runtime/ftplugin/gitcommit.vim @ 17082:76f837f6d427
Added tag v8.1.1540 for changeset 81b791a843bc17d7accd7530cdf1f71d13e4db43
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 15 Jun 2019 16:15:06 +0200 |
parents | 43efa4f5a8ea |
children | 5c40013d45ee |
rev | line source |
---|---|
1619 | 1 " Vim filetype plugin |
2034 | 2 " Language: git commit file |
3 " Maintainer: Tim Pope <vimNOSPAM@tpope.org> | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4681
diff
changeset
|
4 " Last Change: 2016 Aug 29 |
1619 | 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 | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4681
diff
changeset
|
14 setlocal comments=:# commentstring=#\ %s |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4681
diff
changeset
|
15 setlocal nomodeline tabstop=8 formatoptions+=tl textwidth=72 |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4681
diff
changeset
|
16 setlocal formatoptions-=c formatoptions-=r formatoptions-=o formatoptions-=q |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4681
diff
changeset
|
17 let b:undo_ftplugin = 'setl modeline< tabstop< formatoptions< tw< com< cms<' |
1619 | 18 |
19 if exists("g:no_gitcommit_commands") || v:version < 700 | |
20 finish | |
21 endif | |
22 | |
23 if !exists("b:git_dir") | |
2202 | 24 let b:git_dir = expand("%:p:h") |
1619 | 25 endif |
26 | |
27 command! -bang -bar -buffer -complete=custom,s:diffcomplete -nargs=* DiffGitCached :call s:gitdiffcached(<bang>0,b:git_dir,<f-args>) | |
28 | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4681
diff
changeset
|
29 let b:undo_ftplugin = b:undo_ftplugin . "|delc DiffGitCached" |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4681
diff
changeset
|
30 |
1619 | 31 function! s:diffcomplete(A,L,P) |
2202 | 32 let args = "" |
33 if a:P <= match(a:L." -- "," -- ")+3 | |
34 let args = args . "-p\n--stat\n--shortstat\n--summary\n--patch-with-stat\n--no-renames\n-B\n-M\n-C\n" | |
35 end | |
36 if exists("b:git_dir") && a:A !~ '^-' | |
37 let tree = fnamemodify(b:git_dir,':h') | |
38 if strpart(getcwd(),0,strlen(tree)) == tree | |
39 let args = args."\n".system("git diff --cached --name-only") | |
1619 | 40 endif |
2202 | 41 endif |
42 return args | |
1619 | 43 endfunction |
44 | |
45 function! s:gitdiffcached(bang,gitdir,...) | |
2202 | 46 let tree = fnamemodify(a:gitdir,':h') |
47 let name = tempname() | |
48 let git = "git" | |
49 if strpart(getcwd(),0,strlen(tree)) != tree | |
50 let git .= " --git-dir=".(exists("*shellescape") ? shellescape(a:gitdir) : '"'.a:gitdir.'"') | |
51 endif | |
52 if a:0 | |
53 let extra = join(map(copy(a:000),exists("*shellescape") ? 'shellescape(v:val)' : "'\"'.v:val.'\"'")) | |
54 else | |
55 let extra = "-p --stat=".&columns | |
56 endif | |
3465 | 57 call system(git." diff --cached --no-color --no-ext-diff ".extra." > ".(exists("*shellescape") ? shellescape(name) : name)) |
2202 | 58 exe "pedit ".(exists("*fnameescape") ? fnameescape(name) : name) |
59 wincmd P | |
60 let b:git_dir = a:gitdir | |
61 command! -bang -bar -buffer -complete=custom,s:diffcomplete -nargs=* DiffGitCached :call s:gitdiffcached(<bang>0,b:git_dir,<f-args>) | |
3465 | 62 nnoremap <buffer> <silent> q :q<CR> |
2202 | 63 setlocal buftype=nowrite nobuflisted noswapfile nomodifiable filetype=git |
1619 | 64 endfunction |