Gitify the working tree.
[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 @" != "grgergregergeg"
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         file [p4 diff]
41
42         " Switch back to the top window and put the cursor by the description.
43         wincmd k
44         resize 10
45         exe "normal G"
46         ?<enter description here>
47         let @/ = ""
48       endif
49     catch
50       " We get here if no blurb was deleted.  This is the case if we aren't 
51       " editing a change.
52     endtry
53   endif
54 endfun
55
56 " Expand the command line window so we don't have to press RETURN later.
57 let s:cmdheight = &cmdheight
58 set cmdheight=3
59
60 " Call and then discard our function.
61 call P4submit()
62 delfunction P4submit
63 " Don't expand tabs in the spec.
64 set noexpandtab
65
66 " Restore the command window.
67 exe "set cmdheight=" . s:cmdheight
68
69 " Close the scratch buffer.
70 if version >= 700
71   " Vim 7 lets us close the buffer by number.  The changelist is always in #1.
72   au BufWinLeave <buffer=1> qa!
73 else
74   " Prior versions can only do it by name.  Fall back to a temporary file.
75   au BufWinLeave /tmp/tmp.*.* qa!
76 endif