Slightly bugfixed version of fold-mail.vim attached, use this one as a starting point rather than the original.
This one doesn't try to do folding if the mbox file doesn't start with a "From" header. Also it deals correctly with blank header fields that have no space immediately after the header name (like "Subject:" rather than "Subject: ") and accounts for line numbers in Vim starting at 1 (not 0). In case a license statement is necessary: I hereby release the attached file fold-mail.vim to the public domain. 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
" disable folding if there is no From header (presumably only one
" mail message in the file)
setlocal foldexpr=getline(1)=~#'^From\ '?GetMboxFold(v:lnum):'0'
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 : 34] . '>'
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 > 1 && getline(a:lnum - 1) =~# '^From '
return '>2' " beginning of header block
else
return '='
endif
endif
if a:lnum > 1 && line =~ '^$'
return '<2'
endif
return '='
endfunction
silent! foldopen! " unfold the entry the cursor is on (usually the first one)
" }}}
signature.asc
Description: OpenPGP digital signature

