]> git.madduck.net Git - etc/vim.git/blob - .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:

editor config depending on mail area detection
[etc/vim.git] / .vim / after / ftplugin / mail.vim
1 setlocal textwidth=68
2 setlocal formatoptions-=o
3 setlocal formatoptions-=r
4
5 "setlocal spell
6
7 " Dynamically set format options, depending on where you are in a
8 " mail, idea from Teemu Likonen:
9 " http://groups.google.com/group/vim_use/msg/f59e5c1adc6be2b3
10
11 let d_fo = &fo
12 let s:defaults = 'setlocal tw=68 ts=2 sts=2 sw=2 fo='.d_fo
13 execute s:defaults
14 let b:MailAreaDetect=1
15
16 "nnoremap <buffer> <LocalLeader>ma1 :call <SID>MailAreaDetect_On()
17 "    \ <bar> echo 'MailAreaDetect On'<CR>
18 "nnoremap <buffer> <LocalLeader>ma0 :call <SID>MailAreaDetect_Off()
19 "    \ <bar> echo 'MailAreaDetect Off'<CR>
20
21 nnoremap <buffer><silent> <F9> :call <SID>MailAreaDetect_Switch(0)<CR>
22 inoremap <buffer><silent> <F9> <C-\><C-O>:call <SID>MailAreaDetect_Switch(1)<CR>
23
24 function! s:MailAreaDetect_Switch(vmode)
25     if b:MailAreaDetect
26         silent call <SID>MailAreaDetect_Off()
27         let b:MailAreaDetect=0
28         echo 'MailAreaDetect Off'
29         if a:vmode
30             sleep 1
31         endif
32     else
33         silent call <SID>MailAreaDetect_On()
34         let b:MailAreaDetect=1
35         echo 'MailAreaDetect On'
36         if a:vmode
37             sleep 1
38         endif
39     endif
40 endfu
41
42
43 function! s:MailAreaDetect_On()
44     silent autocmd! MailAreaDetect CursorMoved,CursorMoved
45         \ <buffer> call <SID>AreaOptions()
46     let b:MailAreaDetect=1
47 endfunction
48
49 function! s:MailAreaDetect_Off()
50     silent autocmd! MailAreaDetect
51     execute s:defaults
52     let b:MailAreaDetect=0
53 endfunction
54
55 augroup MailAreaDetect
56     autocmd!
57     call <SID>MailAreaDetect_On()
58 augroup END
59
60 function! s:AreaOptions()
61     execute s:defaults
62     if <SID>CheckArea('\v^From( |: ).*\n','\v^$')
63         "echo 'Header'
64         setlocal fo-=a fo-=w fo-=t sts=0 sw=2 noet
65     elseif getline('.') =~ '\m^\s*>'
66         "echo 'Quotation'
67         setlocal fo-=a fo-=w
68     elseif <SID>CheckArea('\m^--- .*\n^+++ ','\v(^$|\n^-- $)')
69         "echo 'Patch'
70         setlocal fo-=a fo-=w fo-=t sts=0 sw=2 noet
71     elseif <SID>CheckArea('^-- $','^$')
72         "echo 'Signature'
73         setlocal fo-=a fo-=w fo-=t sts=0 sw=2 noet
74     else
75         "echo 'My text'
76         setlocal fo+=aw et
77     endif
78 endfunction
79
80 function! s:CheckArea(start, end)
81     return (search(a:start,'bcnW')-line('.')) >
82         \ (search(a:end,'bnW')-line('.'))
83 endfunction