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 if AddSignature('~/.signature') | w | endif
20 " " Replace the git version with a signature in cover letters generated with git-format-patch
21 " autocmd BufRead 0000-cover-letter.patch if ReplaceLastSignature('~/.signature') | w | endif
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 " The latest version of this script is available at these locations:
29 " https://git.ao2.it/vim/signature_block.vim.git
30 " http://www.vim.org/scripts/script.php?script_id=2872
31 " https://github.com/vim-scripts/signature_block.vim
33 "---------------------------------------------------------------------------
35 if exists("g:loaded_signaturePlugin") | finish | endif
36 let g:loaded_signaturePlugin = 1
39 " Function: SigFileReadable()
40 " Purpose: Check if the signature file is readable
41 "---------------------------------------------------------------------------
42 func! SigFileReadable(sigfile)
43 let filename = expand(a:sigfile)
44 if !filereadable(filename)
45 echoerr "E484: Can't open file " . filename
52 "---------------------------------------------------------------------------
53 " Function: AppendSignature()
54 " Purpose: Append a signature block at the end of message
55 "---------------------------------------------------------------------------
56 func! AppendSignature(sigfile)
57 " Add the signature marker at the end of the file
60 " Append the signature block file at the end of the file
61 exe '$r ' . fnameescape(a:sigfile)
65 "---------------------------------------------------------------------------
66 " Function: AddSignature()
67 " Purpose: Add a signature block if there isn't one already
68 "---------------------------------------------------------------------------
69 func! AddSignature(sigfile)
70 if !SigFileReadable(a:sigfile)
74 " Save current cursor position in mark 'z'
77 " Append a signature block only if there isn't one already
80 catch /^Vim\%((\a\+)\)\=:E486/ " catch error E486 (search command failed)
81 " put an extra newline
83 call AppendSignature(a:sigfile)
86 " restore cursor position from mark 'z' if the mark is still valid
93 "---------------------------------------------------------------------------
94 " Function: ReplaceAllSignatures()
95 " Purpose: Replace all signature blocks in the message
96 "---------------------------------------------------------------------------
97 func! ReplaceAllSignatures(sigfile)
98 if !SigFileReadable(a:sigfile)
102 " Save current cursor position in mark 'z'
106 " delete from the FIRST signature marker '^-- $' down to
107 " the end of the file
109 catch /^Vim\%((\a\+)\)\=:E486/ " catch error E486 (search command failed)
112 call AppendSignature(a:sigfile)
114 " restore cursor position from mark 'z' if the mark is still valid
121 "---------------------------------------------------------------------------
122 " Function: ReplaceLastSignature()
123 " Purpose: Replace only the last signature block in the message
124 "---------------------------------------------------------------------------
125 func! ReplaceLastSignature(sigfile)
126 if !SigFileReadable(a:sigfile)
130 " Save current cursor position in mark 'z'
134 " delete from the LAST signature marker '^-- $' down to
135 " the end of the file
137 catch /^Vim\%((\a\+)\)\=:E486/ " catch error E486 (search command failed)
140 call AppendSignature(a:sigfile)
142 " restore cursor position from mark 'z' if the mark is still valid