Set TERMINFO before calling tput.
[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     setf perforce
8
9     " Clear the unnamed register.
10     let @" = ""
11     try
12       " Delete the spec blurb if it exists.
13       /^# A Perforce Change Spec/,/^# *(New changelists only\.)$/d
14       " If the blurb was deleted the text will be in the unnamed register.
15       if @" != ""
16         " Delete the blank line left above the remaining fields.
17         1
18         delete
19
20         " Allow closing an unmodified spec.
21         set nomod
22
23         try
24           /everything below this line is just the diff/
25
26           " We are submitting through git p4 so yank the diff.
27           normal j
28           normal yG
29           " Create a new window below the spec and paste the diff.
30           botright new
31           normal p
32         catch
33           " Get the files in the changelist.
34           let l:files = system("sed -n 's@^     \\(//.*\\)      #.*@\"\\1\"@p' " . bufname(""))
35           " Create a new window below the spec and read in a diff.
36           botright new
37           if l:files != ""
38             exe "r!env P4DIFF= p4 diff -du " .  substitute(l:files, "\n", " ", "g")
39           endif
40         endtry
41
42         setf diff
43
44         " Delete the blank line left above the diff.
45         1
46         delete
47         set nobuflisted
48         set buftype=nowrite
49         set bufhidden=hide
50         setlocal noswapfile
51         file [p4 diff\]
52
53         " Switch back to the top window and put the cursor by the description.
54         wincmd k
55         resize 10
56         normal G
57         ?^Description:
58         let @/ = ""
59         normal j
60         normal ^
61
62         " Set formatting.
63         se noexpandtab
64         se ts=8
65       endif
66     catch
67       " We get here if no blurb was deleted.  This is the case if we aren't 
68       " editing a change.
69     endtry
70   endif
71 endfun
72
73 " Expand the command line window so we don't have to press RETURN later.
74 let s:cmdheight = &cmdheight
75 set cmdheight=3
76
77 " Call and then discard our function.
78 call P4submit()
79 delfunction P4submit
80 " Don't expand tabs in the spec.
81 set noexpandtab
82
83 " Restore the command window.
84 exe "set cmdheight=" . s:cmdheight
85
86 " Close the scratch buffer.
87 if version >= 700
88   " Vim 7 lets us close the buffer by number.  The changelist is always in #1.
89   au BufWinLeave <buffer=1> qa!
90 else
91   " Prior versions can only do it by name.  Fall back to a temporary file.
92   au BufWinLeave /tmp/tmp.*.* qa!
93 endif