1
0
Fork 0
mirror of https://github.com/vim/vim synced 2025-03-16 06:47:52 +01:00
vim/runtime/ftplugin/debcontrol.vim

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

74 lines
1.9 KiB
VimL
Raw Normal View History

2008-06-24 22:58:06 +00:00
" Vim filetype plugin file (GUI menu and folding)
2010-05-14 23:24:24 +02:00
" Language: Debian control files
2018-02-09 22:00:53 +01:00
" Maintainer: Debian Vim Maintainers
2010-05-14 23:24:24 +02:00
" Former Maintainer: Pierre Habouzit <madcoder@debian.org>
" Last Change: 2024 May 25
2023-02-02 13:59:48 +00:00
" URL: https://salsa.debian.org/vim-team/vim-debian/blob/main/ftplugin/debcontrol.vim
2008-06-24 22:58:06 +00:00
" Do these settings once per buffer
2018-05-06 17:57:30 +02:00
if exists('b:did_ftplugin')
2008-06-24 22:58:06 +00:00
finish
endif
let b:did_ftplugin=1
" {{{1 Local settings (do on every load)
2018-05-06 17:57:30 +02:00
if exists('g:debcontrol_fold_enable')
2008-06-24 22:58:06 +00:00
setlocal foldmethod=expr
setlocal foldexpr=DebControlFold(v:lnum)
setlocal foldtext=DebControlFoldText()
endif
setlocal textwidth=0
setlocal comments=:#
setlocal commentstring=#\ %s
2008-06-24 22:58:06 +00:00
" Clean unloading
let b:undo_ftplugin = 'setlocal tw< foldmethod< foldexpr< foldtext< comments< commentstring<'
2008-06-24 22:58:06 +00: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-05-06 17:57:30 +02:00
if line ==# ''
2008-06-24 22:58:06 +00:00
return 'unknown'
endif
endwhile
return substitute(line, '^'.a:f.': *', '', '')
endfunction
function! DebControlFoldText()
2018-05-06 17:57:30 +02:00
if v:folddashes ==# '-' " debcontrol entry fold
2008-06-24 22:58:06 +00:00
let type = substitute(getline(v:foldstart), ':.*', '', '')
2018-05-06 17:57:30 +02:00
if type ==# 'Source'
2008-06-24 22:58:06 +00: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-05-06 17:57:30 +02:00
if getline(a:l) =~# '^Source:'
2008-06-24 22:58:06 +00:00
return '>1'
endif
2018-05-06 17:57:30 +02:00
if getline(a:l) =~# '^Package:'
2008-06-24 22:58:06 +00:00
return '>1'
endif
return '='
endfunction
" }}}1