Read existing palette colour.
[profile.git] / .vim / script / merge
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! P4merge()
4   " There should be four arguments:
5   " 0. The original file (tmp.xxx).
6   " 1. Their version (tmp.yyy).
7   " 2. My version (original filename).
8   " 3. The merged version (tmp.zzz).
9
10   if argc() != 4
11     return
12   endif
13
14   let l:filename = fnameescape(fnamemodify(argv(2), ":h"))
15
16   " Make sure the window is big enough for diffs.
17   if &columns < 165
18     let &columns=(&columns * 2)
19   endif
20
21   " Mark the buffer for the original file.
22   set ro
23   set nomodifiable
24   set nobuflisted
25   set buftype=help
26   setlocal noswapfile
27   exe "file \[ORIG:" . l:filename . "\]"
28   diffthis
29   1
30
31   " Split the buffer for my version.
32   split +buffer\ 3
33   set ro
34   set nomodifiable
35   set nobuflisted
36   set buftype=help
37   setlocal noswapfile
38   exe "file \[YOURS:" . l:filename . "\]"
39   diffthis
40   1
41
42   " Split the buffer for their version and put it below.
43   split +buffer\ 2
44   wincmd J
45   set ro
46   set nomodifiable
47   set nobuflisted
48   set buftype=help
49   set bufhidden=hide
50   setlocal noswapfile
51   exe "file \[THEIRS:" . l:filename . "\]"
52   diffthis
53   1
54
55   " Split the buffer for the merged version and put it at the side.
56   split +buffer\ 4
57   wincmd L
58   se modifiable
59   1
60
61   try
62     au QuitPre * qa!
63   endtry
64   catch
65 endfun
66
67 " Expand the command line window so we don't have to press RETURN later.
68 let s:cmdheight = &cmdheight
69 set cmdheight=3
70
71 " Call and then discard our function.
72 call P4merge()
73 delfunction P4merge
74
75 " Restore the command window.
76 exe "set cmdheight=" . s:cmdheight
77
78 " Close the scratch buffer.
79 if version >= 700
80   " Vim 7 lets us close the buffer by number.  The merge is always in #4.
81   au BufWinLeave <buffer=4> qa!
82 else
83   " Prior versions can only do it by name.  Fall back to a temporary file.
84   au BufWinLeave /tmp/tmp.*.* qa!
85 endif
86