2014-07-10 21:05:51 -07:00
|
|
|
" Vim filetype plugin file (GUI menu and folding)
|
|
|
|
" Language: Debian control files
|
2018-10-28 06:05:39 -07:00
|
|
|
" Maintainer: Debian Vim Maintainers
|
2014-07-10 21:05:51 -07:00
|
|
|
" Former Maintainer: Pierre Habouzit <madcoder@debian.org>
|
2024-05-25 14:21:30 -07:00
|
|
|
" Last Change: 2024 May 25
|
2023-02-03 01:18:18 -07:00
|
|
|
" URL: https://salsa.debian.org/vim-team/vim-debian/blob/main/ftplugin/debcontrol.vim
|
2014-07-10 21:05:51 -07:00
|
|
|
|
|
|
|
" Do these settings once per buffer
|
2018-10-29 00:43:13 -07:00
|
|
|
if exists('b:did_ftplugin')
|
2014-07-10 21:05:51 -07:00
|
|
|
finish
|
|
|
|
endif
|
|
|
|
let b:did_ftplugin=1
|
|
|
|
|
|
|
|
" {{{1 Local settings (do on every load)
|
2018-10-29 00:43:13 -07:00
|
|
|
if exists('g:debcontrol_fold_enable')
|
2014-07-10 21:05:51 -07:00
|
|
|
setlocal foldmethod=expr
|
|
|
|
setlocal foldexpr=DebControlFold(v:lnum)
|
|
|
|
setlocal foldtext=DebControlFoldText()
|
|
|
|
endif
|
|
|
|
setlocal textwidth=0
|
|
|
|
|
2024-05-25 14:21:30 -07:00
|
|
|
setlocal comments=:#
|
|
|
|
setlocal commentstring=#\ %s
|
|
|
|
|
2014-07-10 21:05:51 -07:00
|
|
|
" Clean unloading
|
2024-05-25 14:21:30 -07:00
|
|
|
let b:undo_ftplugin = 'setlocal tw< foldmethod< foldexpr< foldtext< comments< commentstring<'
|
2014-07-10 21:05:51 -07:00
|
|
|
|
|
|
|
" }}}1
|
|
|
|
|
|
|
|
" {{{1 folding
|
|
|
|
|
|
|
|
function! s:getField(f, lnum)
|
|
|
|
let line = getline(a:lnum)
|
|
|
|
let fwdsteps = 0
|
|
|
|
while line !~ '^'.a:f.':'
|
|
|
|
let fwdsteps += 1
|
|
|
|
let line = getline(a:lnum + fwdsteps)
|
2018-10-29 00:43:13 -07:00
|
|
|
if line ==# ''
|
2014-07-10 21:05:51 -07:00
|
|
|
return 'unknown'
|
|
|
|
endif
|
|
|
|
endwhile
|
|
|
|
return substitute(line, '^'.a:f.': *', '', '')
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! DebControlFoldText()
|
2018-10-29 00:43:13 -07:00
|
|
|
if v:folddashes ==# '-' " debcontrol entry fold
|
2014-07-10 21:05:51 -07:00
|
|
|
let type = substitute(getline(v:foldstart), ':.*', '', '')
|
2018-10-29 00:43:13 -07:00
|
|
|
if type ==# 'Source'
|
2014-07-10 21:05:51 -07:00
|
|
|
let ftext = substitute(foldtext(), ' *Source: *', ' ', '')
|
|
|
|
return ftext . ' -- ' . s:getField('Maintainer', v:foldstart) . ' '
|
|
|
|
endif
|
|
|
|
let arch = s:getField('Architecture', v:foldstart)
|
|
|
|
let ftext = substitute(foldtext(), ' *Package: *', ' [' . arch . '] ', '')
|
|
|
|
return ftext . ': ' . s:getField('Description', v:foldstart) . ' '
|
|
|
|
endif
|
|
|
|
return foldtext()
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! DebControlFold(l)
|
|
|
|
|
|
|
|
" This is for not merging blank lines around folds to them
|
2018-10-29 00:43:13 -07:00
|
|
|
if getline(a:l) =~# '^Source:'
|
2014-07-10 21:05:51 -07:00
|
|
|
return '>1'
|
|
|
|
endif
|
|
|
|
|
2018-10-29 00:43:13 -07:00
|
|
|
if getline(a:l) =~# '^Package:'
|
2014-07-10 21:05:51 -07:00
|
|
|
return '>1'
|
|
|
|
endif
|
|
|
|
|
|
|
|
return '='
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" }}}1
|