X-Git-Url: https://git.madduck.net/etc/vim.git/blobdiff_plain/722c98341ccc6f3b0e0afc2e12c665fafaed32fb..352d9aaa76c748c8f12f3f23cfc939607eb81284:/.vim/after/ftplugin/mail.vim?ds=sidebyside diff --git a/.vim/after/ftplugin/mail.vim b/.vim/after/ftplugin/mail.vim index 8be9fd2..da47898 100644 --- a/.vim/after/ftplugin/mail.vim +++ b/.vim/after/ftplugin/mail.vim @@ -1,6 +1,92 @@ setlocal textwidth=68 -setlocal formatoptions-=n setlocal formatoptions-=o setlocal formatoptions-=r "setlocal spell + +" Dynamically set format options, depending on where you are in a +" mail, idea from Teemu Likonen: +" http://groups.google.com/group/vim_use/msg/f59e5c1adc6be2b3 + +let d_fo = &fo +let s:defaults = 'setlocal tw=68 ts=2 sts=2 sw=2 fo='.d_fo +execute s:defaults +let b:MailAreaDetect=1 + +"nnoremap ma1 :call MailAreaDetect_On() +" \ echo 'MailAreaDetect On' +"nnoremap ma0 :call MailAreaDetect_Off() +" \ echo 'MailAreaDetect Off' + +nnoremap :call MailAreaDetect_Switch(0) +inoremap :call MailAreaDetect_Switch(1) + +function! s:MailAreaDetect_Switch(vmode) + if b:MailAreaDetect + silent call MailAreaDetect_Off() + let b:MailAreaDetect=0 + echo 'MailAreaDetect Off' + if a:vmode + sleep 1 + endif + else + silent call MailAreaDetect_On() + let b:MailAreaDetect=1 + echo 'MailAreaDetect On' + if a:vmode + sleep 1 + endif + endif +endfu + + +function! s:MailAreaDetect_On() + silent autocmd! MailAreaDetect CursorMoved,CursorMoved + \ call AreaOptions() + let b:MailAreaDetect=1 +endfunction + +function! s:MailAreaDetect_Off() + silent autocmd! MailAreaDetect + execute s:defaults + let b:MailAreaDetect=0 +endfunction + +augroup MailAreaDetect + autocmd! + call MailAreaDetect_On() +augroup END + +function! s:AreaOptions() + execute s:defaults + if CheckArea('\v^From( |: ).*\n','\v^$') + "echo 'Header' + setlocal fo-=a fo-=w fo-=t sts=0 sw=2 noet + elseif getline('.') =~ '\m^\s*>' + "echo 'Quotation' + setlocal fo-=a fo-=w + elseif CheckArea('\m^--- .*\n^+++ ','\v(^$|\n^-- $)') + "echo 'Patch' + setlocal fo-=a fo-=w fo-=t sts=0 sw=2 noet + elseif CheckArea('^-- $','^$') + "echo 'Signature' + setlocal fo-=a fo-=w fo-=t sts=0 sw=2 noet + else + "echo 'My text' + setlocal fo+=aw et + endif +endfunction + +function! s:CheckArea(start, end) + return (search(a:start,'bcnW')-line('.')) > + \ (search(a:end,'bnW')-line('.')) +endfunction + +augroup tsperrorinsert + au! +augroup END +match none /\s\+$/ +augroup listinsert + au! +augroup END +set nolist