From: Iain Patterson Date: Fri, 10 Jul 2009 15:17:59 +0000 (+0100) Subject: New Vim script for P4 merge. X-Git-Url: http://git.iain.cx/?a=commitdiff_plain;h=f1c41dc95f2d4fe411e00c35b0b7571178a149a1;p=profile.git New Vim script for P4 merge. --- diff --git a/.profile.d/p4.bashrc b/.profile.d/p4.bashrc index 94cd19c..b4134c0 100644 --- a/.profile.d/p4.bashrc +++ b/.profile.d/p4.bashrc @@ -13,7 +13,11 @@ else export P4EDITOR=vim fi if [ -z "$DISPLAY" ]; then - export P4MERGE="vim -o -c '3wincmd j' -c 'wincmd L'" + if [ -e "$HOME/.vim/script/p4" ]; then + export P4MERGE="vim -S '$HOME/.vim/script/p4'" + else + export P4MERGE="vim -o -c '3wincmd j' -c 'wincmd L'" + fi else export P4MERGE="p4merge" fi diff --git a/.vim/script/merge b/.vim/script/merge new file mode 100644 index 0000000..ad7c083 --- /dev/null +++ b/.vim/script/merge @@ -0,0 +1,83 @@ +" Define the function we'll use. It's easier to do this than to faff about +" trying to run a sequence of normal mode commands. +fun! P4merge() + " There should be four arguments: + " 0. The original file (tmp.xxx). + " 1. Their version (tmp.yyy). + " 2. My version (original filename). + " 3. The merged version (tmp.zzz). + + if argc() != 4 + return + endif + + let l:filename = fnameescape(fnamemodify(argv(2), ":h")) + + " Make sure the window is big enough for diffs. + if &columns < 165 + let &columns=(&columns * 2) + endif + + " Mark the buffer for the original file. + set ro + set nomodifiable + set nobuflisted + set buftype=nowrite + set bufhidden=hide + setlocal noswapfile + exe "file \[ORIG:" . l:filename . "\]" + diffthis + 1 + + " Split the buffer for my version. + split +buffer\ 3 + set ro + set nomodifiable + set nobuflisted + set buftype=nowrite + set bufhidden=hide + setlocal noswapfile + exe "file \[YOURS:" . l:filename . "\]" + diffthis + 1 + + " Split the buffer for their version and put it below. + split +buffer\ 2 + wincmd J + set ro + set nomodifiable + set nobuflisted + set buftype=nowrite + set bufhidden=hide + setlocal noswapfile + exe "file \[THEIRS:" . l:filename . "\]" + diffthis + 1 + + " Split the buffer for the merged version and put it at the side. + split +buffer\ 4 + wincmd L + se modifiable + 1 +endfun + +" Expand the command line window so we don't have to press RETURN later. +let s:cmdheight = &cmdheight +set cmdheight=3 + +" Call and then discard our function. +call P4merge() +delfunction P4merge + +" Restore the command window. +exe "set cmdheight=" . s:cmdheight + +" Close the scratch buffer. +if version >= 700 + " Vim 7 lets us close the buffer by number. The merge is always in #4. + au BufWinLeave qa! +else + " Prior versions can only do it by name. Fall back to a temporary file. + au BufWinLeave /tmp/tmp.*.* qa! +endif +