robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Christian Clasonvim-patch:0076ddc: runtime(debian): update Debian runtime files (vim/vim#14849)eaaf3d9048

master
1.9 KiB73 linesraw
1" Vim filetype plugin file (GUI menu and folding)
2" Language:     Debian control files
3" Maintainer:   Debian Vim Maintainers
4" Former Maintainer:    Pierre Habouzit <madcoder@debian.org>
5" Last Change:  2024 May 25
6" URL:          https://salsa.debian.org/vim-team/vim-debian/blob/main/ftplugin/debcontrol.vim
7
8" Do these settings once per buffer
9if exists('b:did_ftplugin')
10  finish
11endif
12let b:did_ftplugin=1
13
14" {{{1 Local settings (do on every load)
15if exists('g:debcontrol_fold_enable')
16  setlocal foldmethod=expr
17  setlocal foldexpr=DebControlFold(v:lnum)
18  setlocal foldtext=DebControlFoldText()
19endif
20setlocal textwidth=0
21
22setlocal comments=:#
23setlocal commentstring=#\ %s
24
25" Clean unloading
26let b:undo_ftplugin = 'setlocal tw< foldmethod< foldexpr< foldtext< comments< commentstring<'
27
28" }}}1
29
30" {{{1 folding
31
32function! s:getField(f, lnum)
33  let line = getline(a:lnum)
34  let fwdsteps = 0
35  while line !~ '^'.a:f.':'
36    let fwdsteps += 1
37    let line = getline(a:lnum + fwdsteps)
38    if line ==# ''
39      return 'unknown'
40    endif
41  endwhile
42  return substitute(line, '^'.a:f.': *', '', '')
43endfunction
44
45function! DebControlFoldText()
46  if v:folddashes ==# '-'  " debcontrol entry fold
47    let type = substitute(getline(v:foldstart), ':.*', '', '')
48    if type ==# 'Source'
49      let ftext = substitute(foldtext(), ' *Source: *', ' ', '')
50      return ftext . ' -- ' . s:getField('Maintainer', v:foldstart) . ' '
51    endif
52    let arch  = s:getField('Architecture', v:foldstart)
53    let ftext = substitute(foldtext(), ' *Package: *', ' [' . arch . '] ', '')
54    return ftext . ': ' . s:getField('Description', v:foldstart) . ' '
55  endif
56  return foldtext()
57endfunction
58
59function! DebControlFold(l)
60
61  " This is for not merging blank lines around folds to them
62  if getline(a:l) =~# '^Source:'
63    return '>1'
64  endif
65
66  if getline(a:l) =~# '^Package:'
67    return '>1'
68  endif
69
70  return '='
71endfunction
72
73" }}}1