" Vim indent file if exists("b:did_indent") finish endif let b:did_indent = 1 if !exists("g:mail_itemize_chars") let g:mail_itemize_chars='o*+-' endif let s:item_cap_re='^ *\(['.g:mail_itemize_chars.']\) .*$' let s:item_re='^ *['.g:mail_itemize_chars.'] ' let s:void_re='^\([>}].*\| *\)$' setlocal nocindent setlocal comments=n:},n:> setlocal nolisp setlocal nosmartindent setlocal noautoindent setlocal indentexpr=GetMailIndent() setlocal indentkeys=!^F,*,o,O, " Only define the function once. if exists("*GetMailIndent") finish endif function! s:GetItemIndent(lnum) let lnum = a:lnum let char = substitute(getline(lnum), s:item_cap_re, '\1', '') let maxind = 100 let lastind = -1 while lnum >= 1 let lnum = lnum - 1 let line = getline(lnum) let ind = indent(lnum) if line =~ s:void_re return lastind < 0 ? 2 : lastind end if ind < maxind let maxind = ind if line =~ s:item_re if lastind < 0 let lastind = ind + 4 end if char == substitute(line, s:item_cap_re, '\1', '') return ind end end end endwhile endfunction function GetMailIndent() if v:lnum <= 1 return 0 end let ind2 = indent(v:lnum - 2) let ind1 = indent(v:lnum - 1) let pre2 = getline(v:lnum - 2) let pre1 = getline(v:lnum - 1) let cur = getline(v:lnum) if cur =~ s:void_re || pre1 == '-- ' || cur =~ '-- ' return 0 endif let ind = ind1 if pre1 =~ s:item_re let ind = ind + 2 elseif pre2 =~ s:void_re || (ind2 <= 2 && pre2 =~ '[^a-zA-Z0-9]$') let ind = ind - 2 end let len = strlen(pre1) + strlen( substitute(cur, '^ *\([^ ]*\).*$', '\1', '') ) if pre1 =~ '[^a-zA-Z0-9]$' && len + 1 < &tw if ind1 <= 2 && pre1 !~ s:item_re let ind = 2 else let ind = 0 end end if cur =~ s:item_re let ind = s:GetItemIndent(v:lnum) end return ind endfunction " vim: set sts=2 sw=2: