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