1 "---------------------------------------------------------------------------
2 " Vim global plugin for adding and manipulating signature blocks in e-mails
3 " Maintainer: Antonio Ospite <ospite@studenti.unina.it>
5 " Last Change: 2009-11-24
6 " License: This script is free software; you can redistribute it and/or
7 " modify it under the terms of the GNU General Public License.
10 " Drop this file into your $HOME/.vim/plugin directory.
13 " map <Leader>s :call AppendSignature('~/.signature')<CR>
14 " map <Leader>r :call ReplaceLastSignature('~/.signature')<CR>
15 " map <Leader>R :call ReplaceAllSignatures('~/.signature')<CR>
17 " " Append a signature block to all e-mails
18 " autocmd FileType mail silent call AddSignature('~/.signature') | w
20 " " Append a signature block to cover letters generated with git-format-patch
21 " autocmd BufRead 0000-cover-letter.patch silent call AddSignature('~/.signature') | w
22 " autocmd BufRead 0000-cover-letter.patch autocmd! BufRead 0000-cover-letter.patch
25 " http://en.wikipedia.org/wiki/Signature_block
26 " http://tools.ietf.org/html/rfc1855
28 "---------------------------------------------------------------------------
30 if exists("g:loaded_signaturePlugin") | finish | endif
31 let g:loaded_signaturePlugin = 1
34 "---------------------------------------------------------------------------
35 " Function: AppendSignature()
36 " Purpose: Append a signature block at the end of message
37 "---------------------------------------------------------------------------
38 func! AppendSignature(sigfile)
39 " Add the signature marker at the end of the file
42 " Append the signature block file at the end of the file
43 exe '$r ' . fnameescape(a:sigfile)
47 "---------------------------------------------------------------------------
48 " Function: AddSignature()
49 " Purpose: Add a signature block if there isn't one already
50 "---------------------------------------------------------------------------
51 func! AddSignature(sigfile)
52 " Save current cursor position in mark 'z'
55 " Append a signature block only if there isn't one already
58 catch /^Vim\%((\a\+)\)\=:E486/ " catch error E486 (search command failed)
59 " put an extra newline
61 call AppendSignature(a:sigfile)
64 " restore cursor position from mark 'z' if the mark is still valid
69 "---------------------------------------------------------------------------
70 " Function: ReplaceAllSignatures()
71 " Purpose: Replace all signature blocks in the message
72 "---------------------------------------------------------------------------
73 func! ReplaceAllSignatures(sigfile)
74 " Save current cursor position in mark 'z'
78 " delete from the FIRST signature marker '^-- $' down to
81 catch /^Vim\%((\a\+)\)\=:E486/ " catch error E486 (search command failed)
84 call AppendSignature(a:sigfile)
86 " restore cursor position from mark 'z' if the mark is still valid
91 "---------------------------------------------------------------------------
92 " Function: ReplaceLastSignature()
93 " Purpose: Replace only the last signature block in the message
94 "---------------------------------------------------------------------------
95 func! ReplaceLastSignature(sigfile)
96 " Save current cursor position in mark 'z'
100 " delete from the LAST signature marker '^-- $' down to
101 " the end of the file
103 catch /^Vim\%((\a\+)\)\=:E486/ " catch error E486 (search command failed)
106 call AppendSignature(a:sigfile)
108 " restore cursor position from mark 'z' if the mark is still valid