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