X-Git-Url: https://git.ao2.it/vim/signature_block.vim.git/blobdiff_plain/1daf3e7746444aa9bcadc17e02e3e9c18b420b1f..ca50e1dde406cfa064bf6a52194a016bcda760d1:/plugin/signature_block.vim diff --git a/plugin/signature_block.vim b/plugin/signature_block.vim index cc6223c..2c09fb7 100644 --- a/plugin/signature_block.vim +++ b/plugin/signature_block.vim @@ -15,22 +15,40 @@ " map R :call ReplaceAllSignatures('~/.signature') " " " Append a signature block to all e-mails -" autocmd FileType mail silent call AddSignature('~/.signature') | w +" autocmd FileType mail if AddSignature('~/.signature') | w | endif " -" " Append a signature block to cover letters generated with git-format-patch -" autocmd BufRead 0000-cover-letter.patch silent call AddSignature('~/.signature') | w +" " Replace the git version with a signature in cover letters generated with git-format-patch +" autocmd BufRead 0000-cover-letter.patch if ReplaceLastSignature('~/.signature') | w | endif " autocmd BufRead 0000-cover-letter.patch autocmd! BufRead 0000-cover-letter.patch " " References: " http://en.wikipedia.org/wiki/Signature_block " http://tools.ietf.org/html/rfc1855 " +" The latest version of this script is available at these locations: +" https://git.ao2.it/vim/signature_block.vim.git +" http://www.vim.org/scripts/script.php?script_id=2872 +" https://github.com/vim-scripts/signature_block.vim +" "--------------------------------------------------------------------------- if exists("g:loaded_signaturePlugin") | finish | endif let g:loaded_signaturePlugin = 1 +" Function: SigFileReadable() +" Purpose: Check if the signature file is readable +"--------------------------------------------------------------------------- +func! SigFileReadable(sigfile) + let filename = expand(a:sigfile) + if !filereadable(filename) + echoerr "E484: Can't open file " . filename + return v:false + endif + + return v:true +endfunc + "--------------------------------------------------------------------------- " Function: AppendSignature() " Purpose: Append a signature block at the end of message @@ -49,6 +67,10 @@ endfunc " Purpose: Add a signature block if there isn't one already "--------------------------------------------------------------------------- func! AddSignature(sigfile) + if !SigFileReadable(a:sigfile) + return v:false + endif + " Save current cursor position in mark 'z' normal mz @@ -63,6 +85,8 @@ func! AddSignature(sigfile) " restore cursor position from mark 'z' if the mark is still valid silent! normal `z + + return v:true endfunc @@ -71,6 +95,10 @@ endfunc " Purpose: Replace all signature blocks in the message "--------------------------------------------------------------------------- func! ReplaceAllSignatures(sigfile) + if !SigFileReadable(a:sigfile) + return v:false + endif + " Save current cursor position in mark 'z' normal mz @@ -82,9 +110,11 @@ func! ReplaceAllSignatures(sigfile) endtry call AppendSignature(a:sigfile) - + " restore cursor position from mark 'z' if the mark is still valid silent! normal `z + + return v:true endfunc @@ -93,6 +123,10 @@ endfunc " Purpose: Replace only the last signature block in the message "--------------------------------------------------------------------------- func! ReplaceLastSignature(sigfile) + if !SigFileReadable(a:sigfile) + return v:false + endif + " Save current cursor position in mark 'z' normal mz @@ -104,7 +138,9 @@ func! ReplaceLastSignature(sigfile) endtry call AppendSignature(a:sigfile) - + " restore cursor position from mark 'z' if the mark is still valid silent! normal `z + + return v:true endfunc