]> git.madduck.net Git - etc/vim.git/blobdiff - .vim/after/ftplugin/mail.vim

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

numbered list regexp improvements
[etc/vim.git] / .vim / after / ftplugin / mail.vim
index 8be9fd2c4525a13cb221b6f0c71e47b88d1b22b0..da478989182d6c0693832aeea794542fd8c95213 100644 (file)
@@ -1,6 +1,92 @@
 setlocal textwidth=68
 setlocal textwidth=68
-setlocal formatoptions-=n
 setlocal formatoptions-=o
 setlocal formatoptions-=r
 
 "setlocal spell
 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 <buffer> <LocalLeader>ma1 :call <SID>MailAreaDetect_On()
+"    \ <bar> echo 'MailAreaDetect On'<CR>
+"nnoremap <buffer> <LocalLeader>ma0 :call <SID>MailAreaDetect_Off()
+"    \ <bar> echo 'MailAreaDetect Off'<CR>
+
+nnoremap <buffer><silent> <F9> :call <SID>MailAreaDetect_Switch(0)<CR>
+inoremap <buffer><silent> <F9> <C-\><C-O>:call <SID>MailAreaDetect_Switch(1)<CR>
+
+function! s:MailAreaDetect_Switch(vmode)
+    if b:MailAreaDetect
+       silent call <SID>MailAreaDetect_Off()
+        let b:MailAreaDetect=0
+       echo 'MailAreaDetect Off'
+        if a:vmode
+            sleep 1
+        endif
+    else
+       silent call <SID>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
+        \ <buffer> call <SID>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 <SID>MailAreaDetect_On()
+augroup END
+
+function! s:AreaOptions()
+    execute s:defaults
+    if <SID>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 <SID>CheckArea('\m^--- .*\n^+++ ','\v(^$|\n^-- $)')
+        "echo 'Patch'
+        setlocal fo-=a fo-=w fo-=t sts=0 sw=2 noet
+    elseif <SID>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