797033031638968e74d04f23490b2fc8149fecd5
[profile.git] / .vim / script / p4
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! P4submit()
4   " There's no point doing this if the spec is readonly.  That probably means 
5   " it's a submitted change.
6   if ! &ro
7     " Clear the unnamed register.
8     let @" = ""
9     try
10       " Delete the spec blurb if it exists.
11       /^# A Perforce Change Spec/,/^$/d
12       " If the blurb was deleted the text will be in the unnamed register.
13       if @" != ""
14         " Allow closing an unmodified spec.
15         set nomod
16
17         " Create a new window, move it below the spec and read in a diff.
18         botright new
19         r!p4 diff
20         setf diff
21
22         " Delete the blank line left above the diff.
23         1
24         delete
25         set nobuflisted
26         set buftype=nofile
27         set bufhidden=hide
28         setlocal noswapfile
29
30         " Switch back to the top window and put the cursor by the description.
31         wincmd k
32         resize 10
33         exe "normal G"
34         ?<enter description here>
35         let @/ = ""
36       endif
37     catch
38       " We get here if no blurb was deleted.  This is the case if we aren't 
39       " editing a change.
40     endtry
41   endif
42 endfun
43
44 " Expand the command line window so we don't have to press RETURN later.
45 let s:cmdheight = &cmdheight
46 set cmdheight=2
47
48 " Call and then discard our function.
49 call P4submit()
50 delfunction P4submit
51 " Don't expand tabs in the spec.
52 set noexpandtab
53
54 " Restore the command window.
55 exe "set cmdheight=" . s:cmdheight
56
57 " Close the scratch buffer.
58 au BufWinLeave <buffer=1> qa!