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

2ecfa74114d9b1b4a9411eb0a81be19b632647dc
[etc/vim.git] / .vim / after / ftplugin / mail.vim
1 setlocal textwidth=68
2 setlocal formatoptions-=o
3 setlocal formatoptions-=r
4 setlocal formatoptions+=a
5 setlocal formatoptions+=w
6
7 "setlocal spell
8
9 augroup tsperrorinsert
10   au!
11 augroup END
12 match none /\s*$/
13 augroup listinsert
14   au!
15 augroup END
16 setlocal list
17
18 " Dynamically set format options, depending on where you are in a
19 " mail, idea from Teemu Likonen:
20 " http://groups.google.com/group/vim_use/msg/f59e5c1adc6be2b3
21
22 let s:defaults = "setlocal fo=".&fo
23 " tw=".&tw." ts=".&ts." sts=".&sts." sw=".&sw." fo=".&fo
24 execute s:defaults
25 let b:MailAreaDetect=1
26
27 nnoremap <buffer><silent> <F9> :call <SID>MailAreaDetect_Switch(0)<CR>
28 inoremap <buffer><silent> <F9> <C-\><C-O>:call <SID>MailAreaDetect_Switch(1)<CR>
29
30 function! s:MailAreaDetect_Switch(vmode)
31     if b:MailAreaDetect
32         silent call <SID>MailAreaDetect_Off()
33         let b:MailAreaDetect=0
34         echo 'MailAreaDetect Off'
35         if a:vmode
36             sleep 1
37         endif
38     else
39         silent call <SID>MailAreaDetect_On()
40         let b:MailAreaDetect=1
41         echo 'MailAreaDetect On'
42         if a:vmode
43             sleep 1
44         endif
45     endif
46 endfu
47
48 function! s:MailAreaDetect_On()
49     silent autocmd! MailAreaDetect CursorMoved,CursorMoved
50         \ <buffer> call <SID>AreaOptions()
51     let b:MailAreaDetect=1
52 endfunction
53
54 function! s:MailAreaDetect_Off()
55     silent autocmd! MailAreaDetect
56     execute s:defaults
57     let b:MailAreaDetect=0
58 endfunction
59
60 augroup MailAreaDetect
61     autocmd!
62     call <SID>MailAreaDetect_On()
63 augroup END
64
65 function! s:AreaOptions()
66     execute s:defaults
67
68     let s:synCur = synIDattr(synID(line("."),1,0),"name")
69     let s:synNext = synIDattr(synID(line(".")+1,1,0),"name")
70
71     if s:synNext =~ '^mailQuote' && s:synCur == '' && getline('.') =~ '^.'
72       " elseif getline('.') =~ '^\s*[^>]' && getline(line('.')+1) =~ '\m^\s*>'
73       setlocal fo-=a
74       "echo 'Quotation leader (fo='.&fo.')'
75     elseif s:synCur =~ '^mailQuote'
76       " elseif getline('.') =~ '\m^\s*>'
77       setlocal fo-=a
78       "echo 'Quotation (fo='.&fo.')'
79     elseif <SID>CheckArea('\m^--- .*\n^+++ ','\v(^$|\n^-- $)')
80       setlocal fo-=a fo-=w fo-=t noet
81       "echo 'Patch (fo='.&fo.')'
82     elseif s:synCur == '' && s:synNext =~ '^mailSignature'
83       " elseif getline(line('.')+1) =~ '\m^-- $'
84       setlocal fo-=a fo-=w fo-=t
85       "echo 'Last line before signature (fo='.&fo.')'
86     elseif s:synCur =~ '^mailSignature'
87       " elseif <SID>CheckArea('^-- $','^$')
88       setlocal fo-=a fo-=w fo-=t
89       "echo 'Signature (fo='.&fo.')'
90     elseif s:synCur =~ '^mail'
91       " if <SID>CheckArea('\v^From( |: ).*\n','\v^$')
92       setlocal fo-=a fo-=w fo-=t
93       "echo 'Header (fo='.&fo.')'
94     else
95       "echo 'My text (fo='.&fo.')'
96     endif
97 endfunction
98
99 function! s:CheckArea(start, end)
100     return (search(a:start,'bcnW')-line('.')) >
101         \ (search(a:end,'bnW')-line('.'))
102 endfunction
103
104 function! FixQuotes()
105   let l:i = 0
106   let l:lineNxt = getline(l:i)
107   let l:synNxt = synIDattr(synID(l:i,1,0),"name")
108   while l:i < line('$')-1
109     let l:lineCur = l:lineNxt
110     let l:synCur = l:synNxt
111     let l:lineNxt = getline(l:i+1)
112     let l:synNxt = synIDattr(synID(l:i+1,1,0),"name")
113     if l:synCur =~ '^mailQuote' && l:lineCur =~ '\w.*\S$' &&
114           \ l:synNxt =~ '^mailQuote' && l:lineNxt =~ '\w'
115       call setline(l:i, l:lineCur . ' ')
116     endif
117     let l:i += 1
118   endwhile
119 endfunction
120
121 augroup fixquotes
122   au!
123   autocmd BufWinEnter $TMPDIR/mutt-* call FixQuotes()
124 augroup END
125
126 nmap <buffer> <C-P><F1> :w<CR>:%!mailplate --keep-unknown official<CR>
127 nmap <buffer> <C-P><F2> :w<CR>:%!mailplate --keep-unknown tahi<CR>
128 nmap <buffer> <C-P><F3> :w<CR>:%!mailplate --keep-unknown pmvm<CR>
129 nmap <buffer> <C-P><F4> :w<CR>:%!mailplate --keep-unknown pobox<CR>
130 nmap <buffer> <C-P><F5> :w<CR>:%!mailplate --keep-unknown debian<CR>
131 nmap <buffer> <C-P><F6> :w<CR>:%!mailplate --keep-unknown debconf<CR>
132 nmap <buffer> <C-P><F7> :w<CR>:%!mailplate --keep-unknown uniwh<CR>
133 nmap <buffer> <C-P><F8> :w<CR>:%!mailplate --keep-unknown mtfk<CR>
134 nmap <buffer> <C-P><F9> :w<CR>:%!mailplate --keep-unknown sudetia<CR>
135 nmap <buffer> <C-P><F12> :w<CR>:%!mailplate --keep-unknown private<CR>
136 nmap <buffer> <F1> :w<CR>:%!mailplate --auto --keep-unknown 2>/dev/null<CR>
137
138 " change subject line
139 " Before: Subject: old
140 " After : Subject: New (was: old)
141 " http://strcat.de/wiki/dotfiles#vim
142 " map ,sw 1G/^Subject: <CR>:s/Re:/was:/<CR>Wi (<C-O>$)<ESC>0Whi
143 map <Leader>ns 1G/^Subject: /<CR>:s,\(Subject: \)\(Re: \)*\(.*\)$,\1 (was: \3),<CR>:set nohls<CR>f li
144
145 " Delete 'was' in the Subject.
146 " Before: Subject: New (was: old)
147 " After : Subject: New
148 " http://strcat.de/wiki/dotfiles#vim
149 map <Leader>dw 1G/^Subject: /<CR>:s, *(was: .*)$<CR>:set nohls<CR>f l
150
151 " http://dollyfish.net.nz/blog/2008-04-01/mutt-and-vim-custom-autocompletion
152 fun! LBDBCompleteFn(findstart, base)
153   let line = getline('.')
154   if a:findstart
155     " locate the start of the word
156     let start = col('.') - 1
157     while start > 0 && line[start - 1] =~ '[^:,]'
158       let start -= 1
159     endwhile
160     while start < col('.') && line[start] =~ '[:, ]'
161       let start += 1
162     endwhile
163     return start
164   else
165     let res = []
166     let query = substitute(a:base, '"', '', 'g')
167     let query = substitute(query, '\s*<.*>\s*', '', 'g')
168     for m in LbdbQuery(query)
169       call complete_add(printf('"%s" <%s>', escape(m[0], '"'), m[1]))
170       if complete_check()
171         break
172       endif
173     endfor
174     return res
175   endif
176 endfun
177 set completefunc=LBDBCompleteFn
178
179 " And this magic by James Vega, which ensures that we only complete with lbdb
180 " on the recipient lines of the mail header.
181 inoremap <expr> <C-n> DelegateCompletion(1)
182 inoremap <expr> <C-p> DelegateCompletion(0)
183
184 fun! DelegateCompletion(next)
185   if getline('.') =~? '^\%(To\|B\=Cc\):'
186     return "\x18\x15"
187   elseif a:next
188     return "\x0e"
189   else
190     return "\x10"
191   endif
192 endfun