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

move all mail ftplugin stuff to after
[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
103
104 nmap <buffer> <C-P><F1> :w<CR>:%!mailplate --keep-unknown official<CR>
105 nmap <buffer> <C-P><F2> :w<CR>:%!mailplate --keep-unknown tahi<CR>
106 nmap <buffer> <C-P><F3> :w<CR>:%!mailplate --keep-unknown pmvm<CR>
107 nmap <buffer> <C-P><F4> :w<CR>:%!mailplate --keep-unknown pobox<CR>
108 nmap <buffer> <C-P><F5> :w<CR>:%!mailplate --keep-unknown debian<CR>
109 nmap <buffer> <C-P><F6> :w<CR>:%!mailplate --keep-unknown debconf<CR>
110 nmap <buffer> <C-P><F7> :w<CR>:%!mailplate --keep-unknown uniwh<CR>
111 nmap <buffer> <C-P><F8> :w<CR>:%!mailplate --keep-unknown mtfk<CR>
112 nmap <buffer> <C-P><F9> :w<CR>:%!mailplate --keep-unknown sudetia<CR>
113 nmap <buffer> <C-P><F12> :w<CR>:%!mailplate --keep-unknown private<CR>
114 nmap <buffer> <F1> :w<CR>:%!mailplate --auto --keep-unknown 2>/dev/null<CR>
115
116 " change subject line
117 " Before: Subject: old
118 " After : Subject: New (was: old)
119 " http://strcat.de/wiki/dotfiles#vim
120 " map ,sw 1G/^Subject: <CR>:s/Re:/was:/<CR>Wi (<C-O>$)<ESC>0Whi
121 map <Leader>ns 1G/^Subject: /<CR>:s,\(Subject: \)\(Re: \)*\(.*\)$,\1 (was: \3),<CR>:set nohls<CR>f li
122
123 " Delete 'was' in the Subject.
124 " Before: Subject: New (was: old)
125 " After : Subject: New
126 " http://strcat.de/wiki/dotfiles#vim
127 map <Leader>dw 1G/^Subject: /<CR>:s, *(was: .*)$<CR>:set nohls<CR>f l
128
129 " http://dollyfish.net.nz/blog/2008-04-01/mutt-and-vim-custom-autocompletion
130 fun! LBDBCompleteFn(findstart, base)
131   let line = getline('.')
132   if a:findstart
133     " locate the start of the word
134     let start = col('.') - 1
135     while start > 0 && line[start - 1] =~ '[^:,]'
136       let start -= 1
137     endwhile
138     while start < col('.') && line[start] =~ '[:, ]'
139       let start += 1
140     endwhile
141     return start
142   else
143     let res = []
144     let query = substitute(a:base, '"', '', 'g')
145     let query = substitute(query, '\s*<.*>\s*', '', 'g')
146     for m in LbdbQuery(query)
147       call complete_add(printf('"%s" <%s>', escape(m[0], '"'), m[1]))
148       if complete_check()
149         break
150       endif
151     endfor
152     return res
153   endif
154 endfun
155 set completefunc=LBDBCompleteFn
156
157 " And this magic by James Vega, which ensures that we only complete with lbdb
158 " on the recipient lines of the mail header.
159 inoremap <expr> <C-n> DelegateCompletion(1)
160 inoremap <expr> <C-p> DelegateCompletion(0)
161
162 fun! DelegateCompletion(next)
163   if getline('.') =~? '^\%(To\|B\=Cc\):'
164     return "\x18\x15"
165   elseif a:next
166     return "\x0e"
167   else
168     return "\x10"
169   endif
170 endfun