402634db45d40d56243e5e5d4983f2b8bceaf91f
[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         " Create a new window, move it below the spec and read in a diff.
19         botright new
20         r!p4 diff
21         setf diff
22
23         " Delete the blank line left above the diff.
24         1
25         delete
26         set nobuflisted
27         set buftype=nowrite
28         set bufhidden=hide
29         setlocal noswapfile
30         file [p4 diff]
31
32         " Switch back to the top window and put the cursor by the description.
33         wincmd k
34         resize 10
35         exe "normal G"
36         ?<enter description here>
37         let @/ = ""
38       endif
39     catch
40       " We get here if no blurb was deleted.  This is the case if we aren't 
41       " editing a change.
42     endtry
43   endif
44 endfun
45
46 " Expand the command line window so we don't have to press RETURN later.
47 let s:cmdheight = &cmdheight
48 set cmdheight=2
49
50 " Call and then discard our function.
51 call P4submit()
52 delfunction P4submit
53 " Don't expand tabs in the spec.
54 set noexpandtab
55
56 " Restore the command window.
57 exe "set cmdheight=" . s:cmdheight
58
59 " Close the scratch buffer.
60 if version >= 700
61   " Vim 7 lets us close the buffer by number.  The changelist is always in #1.
62   au BufWinLeave <buffer=1> qa!
63 else
64   " Prior versions can only do it by name.  Fall back to a temporary file.
65   au BufWinLeave /tmp/tmp.*.* qa!
66 endif