Make GPGEdit* commands more robust.

This commit is contained in:
Markus Braun 2006-12-14 10:03:19 +00:00
parent ac21a24b3d
commit 621813ef6e

View File

@ -25,17 +25,15 @@
" "
" :GPGEditRecipients " :GPGEditRecipients
" Opens a scratch buffer to change the list of recipients. Recipients that " Opens a scratch buffer to change the list of recipients. Recipients that
" are unknown (not in your public key) are highlighted and have a " are unknown (not in your public key) are highlighted and have
" prepended "!". Closing the buffer with :x or :bd makes the changes " a prepended "!". Closing the buffer makes the changes permanent.
" permanent.
" "
" :GPGViewRecipients " :GPGViewRecipients
" Prints the list of recipients. " Prints the list of recipients.
" "
" :GPGEditOptions " :GPGEditOptions
" Opens a scratch buffer to change the options for encryption (symmetric, " Opens a scratch buffer to change the options for encryption (symmetric,
" asymmetric, signing). Closing the buffer with :x or :bd makes the " asymmetric, signing). Closing the buffer makes the changes permanent.
" changes permanent.
" WARNING: There is no check of the entered options, so you need to know " WARNING: There is no check of the entered options, so you need to know
" what you are doing. " what you are doing.
" "
@ -168,8 +166,6 @@ fun s:GPGDecrypt()
let &shellredir=s:shellredir let &shellredir=s:shellredir
let &shell=s:shellsave let &shell=s:shellsave
echom ">>>" . s:GPGCommand . " --decrypt --dry-run --batch --no-use-agent --logger-fd 1 \"" . filename . "\"" . "<<<"
echom ">>>" . output . "<<<"
" check if the file is symmetric/asymmetric encrypted " check if the file is symmetric/asymmetric encrypted
if (match(output, "gpg: [^ ]\\+ encrypted data") >= 0) if (match(output, "gpg: [^ ]\\+ encrypted data") >= 0)
" file is symmetric encrypted " file is symmetric encrypted
@ -379,14 +375,25 @@ fun s:GPGEditRecipients()
if (match(bufname("%"), "^\\(GPGRecipients_\\|GPGOptions_\\)") != 0 && match(bufname("%"), "\.\\(gpg\\|asc\\|pgp\\)$") >= 0) if (match(bufname("%"), "^\\(GPGRecipients_\\|GPGOptions_\\)") != 0 && match(bufname("%"), "\.\\(gpg\\|asc\\|pgp\\)$") >= 0)
" save buffer name " save buffer name
let buffername=escape(bufname("%"), ' *?\"'."'") let buffername=bufname("%")
let editbuffername="GPGRecipients_" . buffername let editbuffername="GPGRecipients_" . buffername
" create scratch buffer
exe 'silent! split ' . editbuffername
" check if this buffer exists " check if this buffer exists
if (bufexists(editbuffername)) if (!bufexists(editbuffername))
" create scratch buffer
exe 'silent! split ' . escape(editbuffername, ' *?\"'."'")
" add a autocommand to regenerate the recipients after a write
autocmd BufHidden,BufUnload <buffer> call s:GPGFinishRecipientsBuffer()
else
if (bufwinnr(editbuffername) >= 0)
" switch to scratch buffer window
exe 'silent! ' . bufwinnr(editbuffername) . "wincmd w"
else
" split scratch buffer window
exe 'silent! sbuffer ' . escape(editbuffername, ' *?\"'."'")
endi
" empty the buffer " empty the buffer
silent normal! 1GdG silent normal! 1GdG
endi endi
@ -406,7 +413,7 @@ fun s:GPGEditRecipients()
silent put ='GPG: Please edit the list of recipients, one recipient per line' silent put ='GPG: Please edit the list of recipients, one recipient per line'
silent put ='GPG: Unknown recipients have a prepended \"!\"' silent put ='GPG: Unknown recipients have a prepended \"!\"'
silent put ='GPG: Lines beginning with \"GPG:\" are removed automatically' silent put ='GPG: Lines beginning with \"GPG:\" are removed automatically'
silent put ='GPG: Use :x or :bd to close this buffer' silent put ='GPG: Closing this buffer commits changes'
silent put ='GPG: ----------------------------------------------------------------------' silent put ='GPG: ----------------------------------------------------------------------'
" put the recipients in the scratch buffer " put the recipients in the scratch buffer
@ -456,11 +463,6 @@ fun s:GPGEditRecipients()
" jump to the first recipient " jump to the first recipient
silent normal! G silent normal! G
" add a autocommand to regenerate the recipients after a write
augroup GPGEditRecipients
augroup END
execute 'au GPGEditRecipients BufHidden ' . editbuffername . ' call s:GPGFinishRecipientsBuffer()'
endi endi
endf endf
@ -481,8 +483,7 @@ fun s:GPGFinishRecipientsBuffer()
let GPGUnknownRecipients="" let GPGUnknownRecipients=""
" delete the autocommand " delete the autocommand
exe "au! GPGEditRecipients * " . escape(bufname("%"), ' *?\"'."'") autocmd! * <buffer>
let currentline=1 let currentline=1
let recipient=getline(currentline) let recipient=getline(currentline)
@ -570,14 +571,25 @@ fun s:GPGEditOptions()
if (match(bufname("%"), "^\\(GPGRecipients_\\|GPGOptions_\\)") != 0 && match(bufname("%"), "\.\\(gpg\\|asc\\|pgp\\)$") >= 0) if (match(bufname("%"), "^\\(GPGRecipients_\\|GPGOptions_\\)") != 0 && match(bufname("%"), "\.\\(gpg\\|asc\\|pgp\\)$") >= 0)
" save buffer name " save buffer name
let buffername=escape(bufname("%"), ' *?\"'."'") let buffername=bufname("%")
let editbuffername="GPGOptions_" . buffername let editbuffername="GPGOptions_" . buffername
" create scratch buffer
exe 'silent! split ' . editbuffername
" check if this buffer exists " check if this buffer exists
if (bufexists(editbuffername)) if (!bufexists(editbuffername))
" create scratch buffer
exe 'silent! split ' . escape(editbuffername, ' *?\"'."'")
" add a autocommand to regenerate the options after a write
autocmd BufHidden,BufUnload <buffer> call s:GPGFinishOptionsBuffer()
else
if (bufwinnr(editbuffername) >= 0)
" switch to scratch buffer window
exe 'silent! ' . bufwinnr(editbuffername) . "wincmd w"
else
" split scratch buffer window
exe 'silent! sbuffer ' . escape(editbuffername, ' *?\"'."'")
endi
" empty the buffer " empty the buffer
silent normal! 1GdG silent normal! 1GdG
endi endi
@ -600,7 +612,7 @@ fun s:GPGEditOptions()
silent put ='GPG: Please edit the list of options, one option per line' silent put ='GPG: Please edit the list of options, one option per line'
silent put ='GPG: Please refer to the gpg documentation for valid options' silent put ='GPG: Please refer to the gpg documentation for valid options'
silent put ='GPG: Lines beginning with \"GPG:\" are removed automatically' silent put ='GPG: Lines beginning with \"GPG:\" are removed automatically'
silent put ='GPG: Use :x or :bd to close this buffer' silent put ='GPG: Closing this buffer commits changes'
silent put ='GPG: ----------------------------------------------------------------------' silent put ='GPG: ----------------------------------------------------------------------'
" put the options in the scratch buffer " put the options in the scratch buffer
@ -621,11 +633,6 @@ fun s:GPGEditOptions()
" jump to the first option " jump to the first option
silent normal! G silent normal! G
" add a autocommand to regenerate the options after a write
augroup GPGEditOptions
augroup END
execute 'au GPGEditOptions BufHidden ' . editbuffername . ' call s:GPGFinishOptionsBuffer()'
" define highlight " define highlight
if (has("syntax") && exists("g:syntax_on")) if (has("syntax") && exists("g:syntax_on"))
syntax match GPGComment "^GPG:.*$" syntax match GPGComment "^GPG:.*$"
@ -652,8 +659,7 @@ fun s:GPGFinishOptionsBuffer()
let GPGUnknownOptions="" let GPGUnknownOptions=""
" delete the autocommand " delete the autocommand
exe "au! GPGEditOptions * " . escape(bufname("%"), ' *?\"'."'") autocmd! * <buffer>
let currentline=1 let currentline=1
let option=getline(currentline) let option=getline(currentline)