neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

debcontrol.vim (1920B)


      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
      9 if exists('b:did_ftplugin')
     10  finish
     11 endif
     12 let b:did_ftplugin=1
     13 
     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()
     19 endif
     20 setlocal textwidth=0
     21 
     22 setlocal comments=:#
     23 setlocal commentstring=#\ %s
     24 
     25 " Clean unloading
     26 let b:undo_ftplugin = 'setlocal tw< foldmethod< foldexpr< foldtext< comments< commentstring<'
     27 
     28 " }}}1
     29 
     30 " {{{1 folding
     31 
     32 function! 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.': *', '', '')
     43 endfunction
     44 
     45 function! 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()
     57 endfunction
     58 
     59 function! 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 '='
     71 endfunction
     72 
     73 " }}}1