1 " Vim filetype plugin file (GUI menu and folding)
2 " Language: Debian control files
3 " Maintainer: Debian Vim Maintainers <pkg-vim-maintainers@lists.alioth.debian.org>
4 " Former Maintainer: Pierre Habouzit <madcoder@debian.org>
5 " Last Change: 2008-03-08
6 " URL: http://hg.debian.org/hg/pkg-vim/vim/raw-file/tip/runtime/ftplugin/debcontrol.vim
8 " Do these settings once per buffer
9 if exists("b:did_ftplugin")
14 " {{{1 Local settings (do on every load)
15 if exists("g:debcontrol_fold_enable")
16 setlocal foldmethod=expr
17 setlocal foldexpr=DebControlFold(v:lnum)
18 setlocal foldtext=DebControlFoldText()
23 let b:undo_ftplugin = "setlocal tw< foldmethod< foldexpr< foldtext<"
29 function! s:getField(f, lnum)
30 let line = getline(a:lnum)
32 while line !~ '^'.a:f.':'
34 let line = getline(a:lnum + fwdsteps)
39 return substitute(line, '^'.a:f.': *', '', '')
42 function! DebControlFoldText()
43 if v:folddashes == '-' " debcontrol entry fold
44 let type = substitute(getline(v:foldstart), ':.*', '', '')
46 let ftext = substitute(foldtext(), ' *Source: *', ' ', '')
47 return ftext . ' -- ' . s:getField('Maintainer', v:foldstart) . ' '
49 let arch = s:getField('Architecture', v:foldstart)
50 let ftext = substitute(foldtext(), ' *Package: *', ' [' . arch . '] ', '')
51 return ftext . ': ' . s:getField('Description', v:foldstart) . ' '
56 function! DebControlFold(l)
58 " This is for not merging blank lines around folds to them
59 if getline(a:l) =~ '^Source:'
63 if getline(a:l) =~ '^Package:'