diff runtime/ftplugin/debchangelog.vim @ 844:d3bbb5dd3913 v7.0f02

updated for version 7.0f02
author vimboss
date Thu, 27 Apr 2006 00:02:13 +0000
parents 66080ac5dab7
children 0fe7765dcb8e
line wrap: on
line diff
--- a/runtime/ftplugin/debchangelog.vim
+++ b/runtime/ftplugin/debchangelog.vim
@@ -1,7 +1,9 @@
-" Vim filetype plugin file
+" Vim filetype plugin file (GUI menu and folding)
 " Language:	Debian Changelog
 " Maintainer:	Michael Piefel <piefel@informatik.hu-berlin.de>
-" Last Change:	15 August 2005
+"		Stefano Zacchiroli <zack@debian.org>
+" Last Change:	25 April 2006
+" License:	GNU GPL, version 2.1 or later
 
 if exists("g:did_changelog_ftplugin")
   finish
@@ -10,6 +12,8 @@ endif
 " Don't load another plugin (this is global)
 let g:did_changelog_ftplugin = 1
 
+" {{{1 GUI menu
+
 " Helper functions returning various data.
 " Returns full name, either from $DEBFULLNAME or debianfullname.
 " TODO Is there a way to determine name from anywhere else?
@@ -204,3 +208,47 @@ augroup END
 setlocal tw=78
 setlocal comments=f:* 
 let b:undo_ftplugin = "setlocal tw< comments<"
+
+" }}}
+" {{{1 folding
+
+setlocal foldmethod=expr
+set foldexpr=GetDebChangelogFold(v:lnum)
+setlocal foldtext=DebChangelogFoldText()
+
+" look for an author name searching backward from a given line number
+function! s:getAuthor(lnum)
+  let line = getline(a:lnum)
+  let backsteps = 0
+  while line !~ '^ --'
+    let backsteps += 1
+    let line = getline(a:lnum - backsteps)
+  endwhile
+  let author = substitute(line, '^ --\s*\([^<]\+\)\s*.*', '\1', '')
+  return author
+endfunction
+
+function! DebChangelogFoldText()
+  if v:folddashes == '-'  " changelog entry fold
+    return foldtext() . ' -- ' . s:getAuthor(v:foldend) . ' '
+  endif
+  return foldtext()
+endfunction
+
+function! GetDebChangelogFold(lnum)
+  let line = getline(a:lnum)
+  if line =~ '^\w\+'
+    return '>1' " beginning of a changelog entry
+  endif
+  if line =~ '^\s\+\[.*\]'
+    return '>2' " beginning of an author-specific chunk
+  endif
+  if line =~ '^ --'
+    return '1'
+  endif
+  return '='
+endfunction
+
+" }}}
+
+" vim: set foldmethod=marker: