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.
4 " There's no point doing this if the spec is readonly. That probably means
5 " it's a submitted change.
9 " Clear the unnamed register.
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.
16 " Delete the blank line left above the remaining fields.
20 " Allow closing an unmodified spec.
24 /everything below this line is just the diff/
26 " We are submitting through git p4 so yank the diff.
29 " Create a new window below the spec and paste the diff.
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.
38 exe "r!env P4DIFF= p4 diff -du " . substitute(l:files, "\n", " ", "g")
44 " Delete the blank line left above the diff.
52 " Map q to quit easily.
53 nnoremap <silent> <buffer> q <C-W>q
55 " Vim 7.4 really doesn't want us to quit windows from a script.
61 " Switch back to the top window and put the cursor by the description.
75 " We get here if no blurb was deleted. This is the case if we aren't
81 " Expand the command line window so we don't have to press RETURN later.
82 let s:cmdheight = &cmdheight
85 " Call and then discard our function.
88 " Don't expand tabs in the spec.
91 " Restore the command window.
92 exe "set cmdheight=" . s:cmdheight
94 " Close the scratch buffer.
96 " Vim 7 lets us close the buffer by number. The changelist is always in #1.
97 au BufWinLeave <buffer=1> qa!
99 " Prior versions can only do it by name. Fall back to a temporary file.
100 au BufWinLeave /tmp/tmp.*.* qa!