Don't try to diff jobs or other non-file stuff.
[profile.git] / .vim / script / p4
1 " $Id$ vim: se syntax=vim:
2 " Define the function we'll use.  It's easier to do this than to faff about 
3 " trying to run a sequence of normal mode commands.
4 fun! P4submit()
5   " There's no point doing this if the spec is readonly.  That probably means 
6   " it's a submitted change.
7   if ! &ro
8     " Clear the unnamed register.
9     let @" = ""
10     try
11       " Delete the spec blurb if it exists.
12       /^# A Perforce Change Spec/,/^$/d
13       " If the blurb was deleted the text will be in the unnamed register.
14       if @" != ""
15         " Allow closing an unmodified spec.
16         set nomod
17
18         " Get the files in the changelist.
19         let l:files = system("sed -n 's@        \(//.*\)        #.*@@p' " . bufname(""))
20
21         " Create a new window, move it below the spec and read in a diff.
22         botright new
23         exe "r!env P4DIFF= p4 diff -du " .  substitute(l:files, "\n", "", "g")
24         setf diff
25
26         " Delete the blank line left above the diff.
27         1
28         delete
29         set nobuflisted
30         set buftype=nowrite
31         set bufhidden=hide
32         setlocal noswapfile
33         file [p4 diff]
34
35         " Switch back to the top window and put the cursor by the description.
36         wincmd k
37         resize 10
38         exe "normal G"
39         ?<enter description here>
40         let @/ = ""
41       endif
42     catch
43       " We get here if no blurb was deleted.  This is the case if we aren't 
44       " editing a change.
45     endtry
46   endif
47 endfun
48
49 " Expand the command line window so we don't have to press RETURN later.
50 let s:cmdheight = &cmdheight
51 set cmdheight=3
52
53 " Call and then discard our function.
54 call P4submit()
55 delfunction P4submit
56 " Don't expand tabs in the spec.
57 set noexpandtab
58
59 " Restore the command window.
60 exe "set cmdheight=" . s:cmdheight
61
62 " Close the scratch buffer.
63 if version >= 700
64   " Vim 7 lets us close the buffer by number.  The changelist is always in #1.
65   au BufWinLeave <buffer=1> qa!
66 else
67   " Prior versions can only do it by name.  Fall back to a temporary file.
68   au BufWinLeave /tmp/tmp.*.* qa!
69 endif