Regression.
[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         " Get the files in the changelist.
24         let l:files = system("sed -n 's@^       \\(//.*\\)      #.*@\\1@p' " . bufname(""))
25         " Create a new window, move it below the spec and read in a diff.
26         botright new
27         if l:files != ""
28           exe "r!env P4DIFF= p4 diff -du " .  substitute(l:files, "\n", " ", "g")
29         endif
30
31         setf diff
32
33         " Delete the blank line left above the diff.
34         1
35         delete
36         set nobuflisted
37         set buftype=nowrite
38         set bufhidden=hide
39         setlocal noswapfile
40
41         " Change directory so "file [p4 diff]" doesn't try to cd somewhere.
42         let l:cwd=getcwd()
43         cd /
44         file [p4 diff]
45         cd l:cwd
46
47         " Switch back to the top window and put the cursor by the description.
48         wincmd k
49         resize 10
50         exe "normal G"
51         ?<enter description here>
52         let @/ = ""
53       endif
54     catch
55       " We get here if no blurb was deleted.  This is the case if we aren't 
56       " editing a change.
57     endtry
58   endif
59 endfun
60
61 " Expand the command line window so we don't have to press RETURN later.
62 let s:cmdheight = &cmdheight
63 set cmdheight=3
64
65 " Call and then discard our function.
66 call P4submit()
67 delfunction P4submit
68 " Don't expand tabs in the spec.
69 set noexpandtab
70
71 " Restore the command window.
72 exe "set cmdheight=" . s:cmdheight
73
74 " Close the scratch buffer.
75 if version >= 700
76   " Vim 7 lets us close the buffer by number.  The changelist is always in #1.
77   au BufWinLeave <buffer=1> qa!
78 else
79   " Prior versions can only do it by name.  Fall back to a temporary file.
80   au BufWinLeave /tmp/tmp.*.* qa!
81 endif