223d0f081607718b49c5f8e8a226b50a7585212c
[profile.git] / .vim / script / svn
1 " Define the function we'll use.  It's easier to do this than to faff about 
2 " trying to run a sequence of normal mode commands.
3 fun! SVNcommit()
4   " Allow closing an unmodified spec.
5   set nomod
6
7   " Get the modified files.  Discount new files.
8   let l:files = system("sed -n '1,/^$/d;/^[MR]..../{s//\"/;s/$/\"/p;}' " . bufname(""))
9
10   if l:files == ""
11     return
12   endif
13
14   " Create a new window, move it below the spec and read in a diff.
15   botright new
16   exe "r!svn diff " . substitute(l:files, "\n", " ", "g")
17   setf diff
18
19   " Delete the blank line left above the diff.
20   1
21   delete
22   se nobuflisted
23   set buftype=nowrite
24   set bufhidden=hide
25   setlocal noswapfile
26   file [svn diff\]
27   " Map q to quit easily.
28   nnoremap <silent> <buffer> q <C-W>q
29
30   " Vim 7.4 really doesn't want us to quit windows from a script.
31   try
32     au QuitPre * qa!
33   catch
34   endtry
35
36   " Switch back to the top window.
37   wincmd k
38 endfun
39
40 " Expand the command line window so we don't have to press RETURN later.
41 let s:cmdheight = &cmdheight
42 se cmdheight=3
43
44 " Call and then discard our function.
45 call SVNcommit()
46 delfunction SVNcommit
47
48 " Restore the command window.
49 exe "se cmdheight=" . s:cmdheight
50
51 " Close the scratch buffer.
52 if version >= 700
53   " Vim 7 lets us close the buffer by number.  The changelist is always in #1.
54   au BufWinLeave <buffer=1> qa!
55 else
56   " Prior versions can only do it by name.  Fall back to a temporary file.
57   au BufWinLeave /tmp/tmp.*.* qa!
58 endif