r681 - /trunk/runtime/ftplugin/debcontrol.vim

madcoder at users.alioth.debian.org madcoder at users.alioth.debian.org
Wed May 17 09:54:47 UTC 2006


Author: madcoder
Date: Wed May 17 09:54:46 2006
New Revision: 681

URL: http://svn.debian.org/wsvn/?sc=1&rev=681
Log:
my own ftplugin to fold debcontrols. I've it since ages, put it online


Added:
    trunk/runtime/ftplugin/debcontrol.vim

Added: trunk/runtime/ftplugin/debcontrol.vim
URL: http://svn.debian.org/wsvn/trunk/runtime/ftplugin/debcontrol.vim?rev=681&op=file
==============================================================================
--- trunk/runtime/ftplugin/debcontrol.vim (added)
+++ trunk/runtime/ftplugin/debcontrol.vim Wed May 17 09:54:46 2006
@@ -1,0 +1,67 @@
+" Vim filetype plugin file (GUI menu and folding)
+" Language:	Debian control files
+" Maintainer:	Pierre Habouzit <madcoder at debian.org>
+" Last Change:  17. Mai 2006
+" URL:		http://svn.debian.org/wsvn/pkg-vim/trunk/runtime/ftplugin/debccontrol.vim?op=file
+
+" 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)
+setlocal foldmethod=expr
+setlocal foldexpr=DebControlFold(v:lnum)
+setlocal foldtext=DebControlFoldText()
+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




More information about the pkg-vim-maintainers mailing list