blob: 9342799b5667584b535ee9c54c90116e185192e2 [file] [log] [blame]
Bram Moolenaara7241f52008-06-24 20:39:31 +00001" Vim filetype plugin
Bram Moolenaar5c736222010-01-06 20:54:52 +01002" Language: git commit file
3" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00004" Last Change: 2022 Jan 05
Bram Moolenaara7241f52008-06-24 20:39:31 +00005
6" Only do this when not done yet for this buffer
7if (exists("b:did_ftplugin"))
8 finish
9endif
10
Bram Moolenaara7241f52008-06-24 20:39:31 +000011let b:did_ftplugin = 1
12
Bram Moolenaar89bcfda2016-08-30 23:26:57 +020013setlocal nomodeline tabstop=8 formatoptions+=tl textwidth=72
Bram Moolenaarc08ee742019-12-05 22:47:25 +010014setlocal formatoptions-=c formatoptions-=r formatoptions-=o formatoptions-=q formatoptions+=n
15setlocal formatlistpat+=\\\|^\\s*[-*+]\\s\\+
Bram Moolenaar2f0936c2022-01-08 21:51:59 +000016setlocal include=^+++
17setlocal includeexpr=substitute(v:fname,'^[bi]/','','')
Bram Moolenaarc08ee742019-12-05 22:47:25 +010018
Bram Moolenaar2f0936c2022-01-08 21:51:59 +000019let b:undo_ftplugin = 'setl modeline< tabstop< formatoptions< tw< com< cms< formatlistpat< inc< inex<'
Bram Moolenaara7241f52008-06-24 20:39:31 +000020
Bram Moolenaar2f0936c2022-01-08 21:51:59 +000021let s:l = search('\C\m^[#;@!$%^&|:] -\{24,\} >8 -\{24,\}$', 'cnW', '', 100)
22let &l:comments = ':' . (matchstr(getline(s:l ? s:l : '$'), '^[#;@!$%^&|:]\S\@!') . '#')[0]
23let &l:commentstring = &l:comments[1] . ' %s'
24unlet s:l
25
26if exists("g:no_gitcommit_commands")
Bram Moolenaara7241f52008-06-24 20:39:31 +000027 finish
28endif
29
Bram Moolenaar2f0936c2022-01-08 21:51:59 +000030command! -bang -bar -buffer -complete=custom,s:diffcomplete -nargs=* DiffGitCached :call s:gitdiffcached(<bang>0, <f-args>)
Bram Moolenaara7241f52008-06-24 20:39:31 +000031
Bram Moolenaar89bcfda2016-08-30 23:26:57 +020032let b:undo_ftplugin = b:undo_ftplugin . "|delc DiffGitCached"
33
Bram Moolenaar2f0936c2022-01-08 21:51:59 +000034function! s:diffcomplete(A, L, P) abort
Bram Moolenaar7a329912010-05-21 12:05:36 +020035 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
Bram Moolenaar2f0936c2022-01-08 21:51:59 +000039 if a:A !~ '^-' && !empty(getftype('.git'))
40 let args = args."\n".system("git diff --cached --name-only")
Bram Moolenaar7a329912010-05-21 12:05:36 +020041 endif
42 return args
Bram Moolenaara7241f52008-06-24 20:39:31 +000043endfunction
44
Bram Moolenaar2f0936c2022-01-08 21:51:59 +000045function! s:gitdiffcached(bang, ...) abort
Bram Moolenaar7a329912010-05-21 12:05:36 +020046 let name = tempname()
Bram Moolenaar7a329912010-05-21 12:05:36 +020047 if a:0
Bram Moolenaar2f0936c2022-01-08 21:51:59 +000048 let extra = join(map(copy(a:000), 'shellescape(v:val)'))
Bram Moolenaar7a329912010-05-21 12:05:36 +020049 else
50 let extra = "-p --stat=".&columns
51 endif
Bram Moolenaar2f0936c2022-01-08 21:51:59 +000052 call system("git diff --cached --no-color --no-ext-diff ".extra." > ".shellescape(name))
53 exe "pedit " . fnameescape(name)
Bram Moolenaar7a329912010-05-21 12:05:36 +020054 wincmd P
Bram Moolenaar2f0936c2022-01-08 21:51:59 +000055 command! -bang -bar -buffer -complete=custom,s:diffcomplete -nargs=* DiffGitCached :call s:gitdiffcached(<bang>0, <f-args>)
Bram Moolenaar7a329912010-05-21 12:05:36 +020056 setlocal buftype=nowrite nobuflisted noswapfile nomodifiable filetype=git
Bram Moolenaara7241f52008-06-24 20:39:31 +000057endfunction