Added Perforce plugin.
[profile.git] / .vim / ftplugin / perforce.vim
1 " Perforce spec filetype plugin file
2 " Language:       Perforce Spec File
3 " Maintainer:     Hari Krishna Dara <hari_vim at yahoo dot com>
4 " Last Change:    13-Jan-2006 @ 17:38
5 " Since Version:  1.4
6 " Revision:       1.0.6
7 " Plugin Version: 2.1
8 " Download From:
9 "     http://vim.sourceforge.net/scripts/script.php?script_id=240
10 " TODO:
11
12 " Only do this when not done yet for this buffer
13 "if exists("b:did_ftplugin")
14 "  finish
15 "endif
16
17 " Don't load another plugin for this buffer
18 let b:did_ftplugin = 1
19
20 " Set some options suitable for pure text editing.
21 setlocal tabstop=8
22 setlocal softtabstop=0
23 setlocal shiftwidth=8
24 setlocal noexpandtab
25 setlocal autoindent
26 setlocal formatoptions=tcqnl
27 setlocal comments=:#,fb:-
28 setlocal wrapmargin=0
29 setlocal textwidth=80
30 let b:undo_ftplugin = 'setl ts< sts< sw< et< ai< fo< com< wm< tw<'
31
32 if !exists("loaded_perforce_ftplugin")
33 let s:patterns{'Change'}   = '\%(^Description:\s*\_s\?\s*\)\zs\S\|^Description:'
34 let s:patterns{'Branch'}   = '\%(^View:\s*\_s\?\s*\)\zs\S\|^View:'
35 let s:patterns{'Label'}    = '\%(^View:\s*\_s\?\s*\)\zs\S\|^View:'
36 let s:patterns{'Client'}   = '\%(^View:\s*\_s\?\s*\)\zs\S\|^View:'
37 let s:patterns{'Job'}      = '\%(^Job:\s\+\)\@<=new\>\|\%(^Description:\s*\_s\?\s*\)\zs\S\|^Description:'
38 let s:patterns{'Job_Spec'} = '^Fields:'
39 let s:patterns{'User'}     = '^User:'
40 let s:patterns{'Depot'}    = '\%(^Description:\s*\_s\?\s*\)\zs\S\|^Description:'
41 let s:patterns{'Group'}    = '\%(^Users:\s*\_s\?\s*\)\zs\S\|^Users:'
42 " Position cursor on the most appropriate line based on the type of spec being
43 " edited.
44 function! s:PositionLine()
45   let specPattern = '^# A Perforce \(.*\) Specification.$'
46   if getline(1) =~ specPattern
47     let spec = substitute(substitute(getline(1), specPattern, '\1', ''), ' ',
48           \ '_', 'g')
49     if spec != "" && exists('s:patterns'. spec) &&
50           \ search(s:patterns{spec}, 'w') != 0
51       let b:p4Pattern = s:patterns{spec}
52       normal! zz
53     endif
54   endif
55 endfunction
56 let loaded_perforce_ftplugin=1
57 endif
58
59 call s:PositionLine()