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

disable snacks.dashboard
[etc/lazyvim.git] / .config / lazyvim / ftplugin / mail.vim
1 setlocal textwidth=68
2 setlocal formatoptions-=o
3 setlocal formatoptions-=r
4 setlocal formatoptions-=l
5 setlocal formatoptions+=a
6 setlocal formatoptions+=w
7 setlocal formatoptions+=n
8 setlocal formatexpr=
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 "     else
41 "         silent call <SID>MailAreaDetect_On()
42 "         let b:MailAreaDetect=1
43 "         echo 'MailAreaDetect On'
44 "     endif
45 " endfu
46 "
47 " function! s:MailAreaDetect_On()
48 "     silent autocmd! MailAreaDetect CursorMoved,CursorMoved
49 "         \ <buffer> call <SID>AreaOptions()
50 "     let b:MailAreaDetect=1
51 " endfunction
52 "
53 " function! s:MailAreaDetect_Off()
54 "     silent autocmd! MailAreaDetect
55 "     execute s:defaults
56 "     let b:MailAreaDetect=0
57 " endfunction
58 "
59 " augroup MailAreaDetect
60 "     autocmd!
61 "     call <SID>MailAreaDetect_On()
62 " augroup END
63 "
64 " function! s:AreaOptions()
65 "     execute s:defaults
66 "
67 "     let s:synCur = synIDattr(synID(line("."),1,0),"name")
68 "     let s:synNext = synIDattr(synID(line(".")+1,1,0),"name")
69 "
70 "     if s:synNext =~ '^mailQuote' && s:synCur == '' && getline('.') =~ '^.'
71 "       " elseif getline('.') =~ '^\s*[^>]' && getline(line('.')+1) =~ '\m^\s*>'
72 "       setlocal fo-=a
73 "       "echo 'Quotation leader (fo='.&fo.')'
74 "     elseif s:synCur =~ '^mailQuote'
75 "       " elseif getline('.') =~ '\m^\s*>'
76 "       setlocal fo-=a
77 "       "echo 'Quotation (fo='.&fo.')'
78 "     elseif <SID>CheckArea('\m^--- .*\n^+++ ','\v(^$|\n^-- $)')
79 "       setlocal fo-=a fo-=w fo-=t noet
80 "       "echo 'Patch (fo='.&fo.')'
81 "     elseif s:synCur == '' && s:synNext =~ '^mailSignature'
82 "       " elseif getline(line('.')+1) =~ '\m^-- $'
83 "       setlocal fo-=a fo-=w fo-=t
84 "       "echo 'Last line before signature (fo='.&fo.')'
85 "     elseif s:synCur =~ '^mailSignature'
86 "       " elseif <SID>CheckArea('^-- $','^$')
87 "       setlocal fo-=a fo-=w fo-=t
88 "       "echo 'Signature (fo='.&fo.')'
89 "     elseif s:synCur =~ '^mail'
90 "       " if <SID>CheckArea('\v^From( |: ).*\n','\v^$')
91 "       setlocal fo-=a fo-=w fo-=t
92 "       "echo 'Header (fo='.&fo.')'
93 "     else
94 "       "echo 'My text (fo='.&fo.')'
95 "     endif
96 " endfunction
97 "
98 " function! s:CheckArea(start, end)
99 "     return (search(a:start,'bcnW')-line('.')) >
100 "         \ (search(a:end,'bnW')-line('.'))
101 " endfunction
102
103 " function! FixQuotes()
104 "   let l:i = 0
105 "   let l:lineNxt = getline(l:i)
106 "   let l:synNxt = synIDattr(synID(l:i,1,0),"name")
107 "   while l:i < line('$')-1
108 "     let l:lineCur = l:lineNxt
109 "     let l:synCur = l:synNxt
110 "     let l:lineNxt = getline(l:i+1)
111 "     let l:synNxt = synIDattr(synID(l:i+1,1,0),"name")
112 "     if l:synCur =~ '^mailQuote' && l:lineCur =~ '\w.*\S$' &&
113 "           \ l:synNxt =~ '^mailQuote' && l:lineNxt =~ '\w'
114 "       call setline(l:i, l:lineCur . ' ')
115 "     endif
116 "     let l:i += 1
117 "   endwhile
118 " endfunction
119 "
120 " augroup fixquotes
121 "   au!
122 "   autocmd BufWinEnter $TMPDIR/mutt-* call FixQuotes()
123 " augroup END
124
125 nmap <buffer> <C-P><F1> :w<CR>:%!mailplate --keep-unknown official<CR>
126 nmap <buffer> <C-P><F2> :w<CR>:%!mailplate --keep-unknown pobox<CR>
127 nmap <buffer> <C-P><F3> :w<CR>:%!mailplate --keep-unknown tahi<CR>
128 nmap <buffer> <C-P><F4> :w<CR>:%!mailplate --keep-unknown toni<CR>
129
130 nmap <buffer> <C-P><F5> :w<CR>:%!mailplate --keep-unknown kbkg<CR>
131 nmap <buffer> <C-P><F6> :w<CR>:%!mailplate --keep-unknown krafftwerk<CR>
132 nmap <buffer> <C-P><F7> :w<CR>:%!mailplate --keep-unknown siby<CR>
133 nmap <buffer> <C-P><F8> :w<CR>:%!mailplate --keep-unknown debian<CR>
134
135 nmap <buffer> <C-P><F9> :w<CR>:%!mailplate --keep-unknown uniwh<CR>
136 nmap <buffer> <C-P><F10> :w<CR>:%!mailplate --keep-unknown mtfk<CR>
137 nmap <buffer> <C-P><F11> :w<CR>:%!mailplate --keep-unknown sudetia<CR>
138 nmap <buffer> <C-P><F12> :w<CR>:%!mailplate --keep-unknown default<CR>
139 nmap <buffer> <F1> :w<CR>:%!mailplate --auto --keep-unknown 2>/dev/null<CR>
140
141 " change subject line
142 " Before: Subject: old
143 " After : Subject: New (was: old)
144 " http://strcat.de/wiki/dotfiles#vim
145 " map ,sw 1G/^Subject: <CR>:s/Re:/was:/<CR>Wi (<C-O>$)<ESC>0Whi
146 map <Leader>ns 1G/^Subject: /<CR>:s,\(Subject: \)\(Re: \)*\(.*\)$,\1 (was: \3),<CR>:set nohls<CR>f li
147
148 " Delete 'was' in the Subject.
149 " Before: Subject: New (was: old)
150 " After : Subject: New
151 " http://strcat.de/wiki/dotfiles#vim
152 map <Leader>dw 1G/^Subject: /<CR>:s, *(was: .*)$<CR>:set nohls<CR>f l
153
154 " packadd lbdbq
155 "
156 " http://dollyfish.net.nz/blog/2008-04-01/mutt-and-vim-custom-autocompletion
157 " fun! LBDBCompleteFn(findstart, base)
158 "   let line = getline('.')
159 "   if a:findstart
160 "     " locate the start of the word
161 "     let start = col('.') - 1
162 "     while start > 0 && line[start - 1] =~ '[^:,]'
163 "       let start -= 1
164 "     endwhile
165 "     while start < col('.') && line[start] =~ '[:, ]'
166 "       let start += 1
167 "     endwhile
168 "     return start
169 "   else
170 "     let res = []
171 "     let query = substitute(a:base, '"', '', 'g')
172 "     let query = substitute(query, '\s*<.*>\s*', '', 'g')
173 "     for m in LbdbQuery(query)
174 "       call complete_add(printf('"%s" <%s>', escape(m[0], '"'), m[1]))
175 "       if complete_check()
176 "         break
177 "       endif
178 "     endfor
179 "     return res
180 "   endif
181 " endfun
182 " setlocal completefunc=LBDBCompleteFn
183
184 " And this magic by James Vega, which ensures that we only complete with lbdb
185 " on the recipient lines of the mail header.
186 " inoremap <expr> <C-n> DelegateCompletion(1)
187 " inoremap <expr> <C-p> DelegateCompletion(0)
188
189 " fun! DelegateCompletion(next)
190 "   if getline('.') =~? '^\%(To\|B\=Cc\):'
191 "     return "\x18\x15"
192 "   elseif a:next
193 "     return "\x0e"
194 "   else
195 "     return "\x10"
196 "   endif
197 " endfun
198
199 function! WriteMailBackup()
200     let l:tmpdir = fnameescape(expand('$TMPDIR')) || '/tmp'
201     let l:tgtdir = l:tmpdir . '/mail-backups'
202     call mkdir(l:tgtdir, "p", 0o700)
203     let l:modified = &modified
204     let l:filename = l:tgtdir . '/' . strftime('%Y-%m-%d-%H%M%S') . '.msg'
205     exe 'silent update! ' . l:filename
206     if 0 && l:modified
207       echo 'Backup written to ' . l:filename
208     endif
209 endfunction
210 autocmd BufWritePre <buffer> call WriteMailBackup()
211
212 let g:markdown_in_mail = 1
213 runtime! ftplugin/markdown.vim
214
215 runtime! greeting_abbrevs.vim