]> 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:

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