Check that the signature file is readable before appending it.
This changes the behavior of the script when the signature file is NOT
readable:
- before this change the old signature would be removed even if the
new one could not be read;
- after this change the buffer content would not be changed if the new
signature could not be read.
let g:loaded_signaturePlugin = 1
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
"---------------------------------------------------------------------------
" Function: AppendSignature()
" Purpose: Append a signature block at the end of message
" Purpose: Add a signature block if there isn't one already
"---------------------------------------------------------------------------
func! AddSignature(sigfile)
" 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
" Save current cursor position in mark 'z'
normal mz
" restore cursor position from mark 'z' if the mark is still valid
silent! normal `z
" restore cursor position from mark 'z' if the mark is still valid
silent! normal `z
" Purpose: Replace all signature blocks in the message
"---------------------------------------------------------------------------
func! ReplaceAllSignatures(sigfile)
" 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
" Save current cursor position in mark 'z'
normal mz
" restore cursor position from mark 'z' if the mark is still valid
silent! normal `z
" restore cursor position from mark 'z' if the mark is still valid
silent! normal `z
" Purpose: Replace only the last signature block in the message
"---------------------------------------------------------------------------
func! ReplaceLastSignature(sigfile)
" 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
" Save current cursor position in mark 'z'
normal mz
" restore cursor position from mark 'z' if the mark is still valid
silent! normal `z
" restore cursor position from mark 'z' if the mark is still valid
silent! normal `z