Package: vim Version: 1:7.1.291-1 Severity: wishlist Tags: patch Hi,
I've been using vim to read debian-private archives on master. I like its syntax highlighting but have continually been annoyed that (a) I have to page-down through obvious spam, and (b) I have to view all of the headers to each mail message, most of which are completely uninteresting. I can't believe this doesn't exist already, but I can't find any plugin to implement folding for mbox format files. So I wrote one, see attached "fold-mail.vim". This folds mbox format files at two levels: 1) individual messages, and 2) the headers for each message. Author and subject of the message are displayed in the folding text at both levels. You may want to integrate into ftplugin/mail.vim. I wrote this as a quick hack in a couple hours, based only on ftplugin/debchangelog.vim and the online Vim documentation, so you may also want to do a sanity check on it first :-) best regards, -- Kevin B. McCarty <[EMAIL PROTECTED]> WWW: http://www.starplot.org/ WWW: http://people.debian.org/~kmccarty/ GPG: public key ID 4F83C751
if exists("g:mail_fold_enable")
setlocal foldmethod=expr
setlocal foldexpr=GetMboxFold(v:lnum)
setlocal foldtext=GetMboxFoldText()
endif
" {{{1 folding
function! s:getAuthor(zonestart, zoneend) " return author name if present,
" otherwise just email address
let linepos = a:zonestart
while linepos <= a:zoneend
let line = getline(linepos)
if line =~# '^From: '
if line =~ '^From: [^<> ][^<>]* <'
return substitute(line, '^From: ["]\?\([^<> ][^<>]*[^<>"]\)["]\? .*',
'\1', '')
else
return substitute(line, '^From: \(.*\)', '\1', '')
endif
endif
let linepos += 1
endwhile
return '[unknown author]'
endfunction
function! s:getSubject(zonestart, zoneend)
let linepos = a:zonestart
while linepos <= a:zoneend
let line = getline(linepos)
if line =~# '^Subject: '
return substitute(line, '^Subject: \(.*\)', '\1', '')
endif
let linepos += 1
endwhile
return '[no subject]'
endfunction
function! GetMboxFoldText()
if v:folddashes == '-' " whole mail msg folded:
" show number of lines as well as author & subject
let text = substitute(foldtext(), '^\([-+0-9 ]\+lines: \).*', '\1', '') .
s:getAuthor(v:foldstart, v:foldend)
while strlen(text) < 36
let text = text . ' '
endwhile
if strlen(text) > 36
let text = text[0 : 35]
endif
else " only headers folded, use full available space to show author & subject
let text = '+-- ' . s:getAuthor(v:foldstart, v:foldend)
endif
return text . ' -- ' . s:getSubject(v:foldstart, v:foldend) . ' '
endfunction
function! GetMboxFold(lnum)
let line = getline(a:lnum)
if line =~# '^From '
return '>1' " beginning of a message
endif
if line =~ '^[-a-zA-Z0-9]\+: '
if a:lnum > 0 && getline(a:lnum - 1) =~# '^From '
return '>2' " beginning of header block
else
return '='
endif
endif
if a:lnum > 0 && line =~ '^$'
return '<2'
else
return '='
endif
endfunction
" }}}
signature.asc
Description: OpenPGP digital signature

