summaryrefslogtreecommitdiffstats
path: root/ftplugin/debcontrol.vim
diff options
context:
space:
mode:
authorAdam Stankiewicz <sheerun@sher.pl>2020-10-06 18:54:19 +0200
committerAdam Stankiewicz <sheerun@sher.pl>2020-10-06 18:54:19 +0200
commitbc9757916ed09763d96283ee62dbed58bd713a11 (patch)
tree07fbb58e9a4f4cbf5206d89f61e4d570e64d2c1a /ftplugin/debcontrol.vim
parentc6fa4d2bf5eb5301f4d3f123031cf34839a5508d (diff)
downloadvim-polyglot-bc9757916ed09763d96283ee62dbed58bd713a11.tar.gz
vim-polyglot-bc9757916ed09763d96283ee62dbed58bd713a11.zip
Add all vim filetypes
Diffstat (limited to 'ftplugin/debcontrol.vim')
-rw-r--r--ftplugin/debcontrol.vim74
1 files changed, 74 insertions, 0 deletions
diff --git a/ftplugin/debcontrol.vim b/ftplugin/debcontrol.vim
new file mode 100644
index 00000000..47128050
--- /dev/null
+++ b/ftplugin/debcontrol.vim
@@ -0,0 +1,74 @@
+if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'debcontrol') == -1
+
+" Vim filetype plugin file (GUI menu and folding)
+" Language: Debian control files
+" Maintainer: Debian Vim Maintainers
+" Former Maintainer: Pierre Habouzit <madcoder@debian.org>
+" Last Change: 2018-01-28
+" URL: https://salsa.debian.org/vim-team/vim-debian/blob/master/ftplugin/debcontrol.vim
+
+" Do these settings once per buffer
+if exists('b:did_ftplugin')
+ finish
+endif
+let b:did_ftplugin=1
+
+" {{{1 Local settings (do on every load)
+if exists('g:debcontrol_fold_enable')
+ setlocal foldmethod=expr
+ setlocal foldexpr=DebControlFold(v:lnum)
+ setlocal foldtext=DebControlFoldText()
+endif
+setlocal textwidth=0
+
+" Clean unloading
+let b:undo_ftplugin = 'setlocal tw< foldmethod< foldexpr< foldtext<'
+
+" }}}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)
+ if line ==# ''
+ return 'unknown'
+ endif
+ endwhile
+ return substitute(line, '^'.a:f.': *', '', '')
+endfunction
+
+function! DebControlFoldText()
+ if v:folddashes ==# '-' " debcontrol entry fold
+ let type = substitute(getline(v:foldstart), ':.*', '', '')
+ if type ==# 'Source'
+ 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
+ if getline(a:l) =~# '^Source:'
+ return '>1'
+ endif
+
+ if getline(a:l) =~# '^Package:'
+ return '>1'
+ endif
+
+ return '='
+endfunction
+
+" }}}1
+
+endif