PYENV prompt.
[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 nomodified
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 ro
48         set nomodified
49         set nomodifiable
50         set nobuflisted
51         set buftype=help
52         setlocal noswapfile
53         file [p4 diff\]
54         " Map q to quit easily.
55         nnoremap <silent> <buffer> q <C-W>q
56
57         " Switch back to the top window and put the cursor by the description.
58         wincmd k
59         resize 10
60         normal G
61         ?^Description:
62         let @/ = ""
63         normal j
64         normal ^
65
66         " Set formatting.
67         se noexpandtab
68         se ts=8
69       endif
70     catch
71       " We get here if no blurb was deleted.  This is the case if we aren't 
72       " editing a change.
73     endtry
74   endif
75 endfun
76
77 " Expand the command line window so we don't have to press RETURN later.
78 let s:cmdheight = &cmdheight
79 set cmdheight=3
80
81 " Call and then discard our function.
82 call P4submit()
83 delfunction P4submit
84 " Don't expand tabs in the spec.
85 set noexpandtab
86
87 " Restore the command window.
88 exe "set cmdheight=" . s:cmdheight
89
90 " Close the scratch buffer.
91 if version >= 700
92   " Vim 7 lets us close the buffer by number.  The changelist is always in #1.
93   au BufWinLeave <buffer=1> qa!
94 else
95   " Prior versions can only do it by name.  Fall back to a temporary file.
96   au BufWinLeave /tmp/tmp.*.* qa!
97 endif