robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
eaaf3d9048
master
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' ) 10finish 11endif 12let b: did_ftplugin = 1 13 14" {{{1 Local settings (do on every load) 15if exists ( 'g:debcontrol_fold_enable' ) 16setlocal foldmethod = expr 17setlocal foldexpr = DebControlFold (v:lnum) 18setlocal 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 ) 33let line = getline ( a: lnum ) 34let fwdsteps = 0 35while line !~ '^' . a: f . ':' 36let fwdsteps += 1 37let line = getline ( a: lnum + fwdsteps ) 38if line ==# '' 39return 'unknown' 40endif 41endwhile 42return substitute ( line , '^' . a: f . ': *' , '' , '' ) 43endfunction 44 45function ! DebControlFoldText () 46if v: folddashes ==# '-' " debcontrol entry fold 47let type = substitute ( getline ( v: foldstart ), ':.*' , '' , '' ) 48if type ==# 'Source' 49let ftext = substitute ( foldtext (), ' *Source: *' , ' ' , '' ) 50return ftext . ' -- ' . s: getField ( 'Maintainer' , v: foldstart ) . ' ' 51endif 52let arch = s: getField ( 'Architecture' , v: foldstart ) 53let ftext = substitute ( foldtext (), ' *Package: *' , ' [' . arch . '] ' , '' ) 54return ftext . ': ' . s: getField ( 'Description' , v: foldstart ) . ' ' 55endif 56return foldtext () 57endfunction 58 59function ! DebControlFold ( l ) 60 61" This is for not merging blank lines around folds to them 62if getline ( a: l ) =~# '^Source:' 63return '>1' 64endif 65 66if getline ( a: l ) =~# '^Package:' 67return '>1' 68endif 69 70return '=' 71endfunction 72 73" }}}1