From 1537043c19880bb8324b2c85463c136a4955e89a Mon Sep 17 00:00:00 2001 From: James McCoy Date: Wed, 11 Nov 2020 13:11:13 -0500 Subject: [PATCH 1/3] Start new bug fix release --- plugin/gnupg.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/gnupg.vim b/plugin/gnupg.vim index f94c0a7..4b89e70 100644 --- a/plugin/gnupg.vim +++ b/plugin/gnupg.vim @@ -1,5 +1,5 @@ " Name: gnupg.vim -" Last Change: 2020 Nov 09 +" Last Change: 2020 Nov 11 " Maintainer: James McCoy " Original Author: Markus Braun " Summary: Vim plugin for transparent editing of gpg encrypted files. @@ -15,7 +15,7 @@ if (exists("g:loaded_gnupg") || &cp || exists("#GnuPG")) finish endif -let g:loaded_gnupg = '2.7.0' +let g:loaded_gnupg = '2.7.1-dev' " check for correct vim version {{{2 if (v:version < 702) From 6b56cdcedac4345e7b07b11d5b3545b69d4fd68a Mon Sep 17 00:00:00 2001 From: James McCoy Date: Wed, 11 Nov 2020 13:04:00 -0500 Subject: [PATCH 2/3] Clear GPGOptions/GPGRecipients autocommands on BufUnload The BufHidden autocommand will have already called the respective Finish function. Clearing the autocommands during BufUnload ensures they don't inadvertently run when Vim is shutting down. Closes jamessan/vim-gnupg#104 --- autoload/gnupg.vim | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/autoload/gnupg.vim b/autoload/gnupg.vim index f9247b2..c35661a 100644 --- a/autoload/gnupg.vim +++ b/autoload/gnupg.vim @@ -1,5 +1,5 @@ " Name: autoload/gnupg.vim -" Last Change: 2020 Nov 09 +" Last Change: 2020 Nov 11 " Maintainer: James McCoy " Original Author: Markus Braun " Summary: Vim plugin for transparent editing of gpg encrypted files. @@ -685,7 +685,8 @@ function gnupg#edit_recipients() augroup GPGRecipients au! * " add a autocommand to regenerate the recipients after a write - autocmd BufHidden,BufUnload,BufWriteCmd call s:GPGFinishRecipientsBuffer() + autocmd BufHidden,BufWriteCmd call s:GPGFinishRecipientsBuffer() + autocmd BufUnload exe 'au! GPGRecipients * ') .'>' augroup END " put some comments to the scratch buffer @@ -861,7 +862,8 @@ function gnupg#edit_options() augroup GPGOptions au! * " add a autocommand to regenerate the options after a write - autocmd BufHidden,BufUnload,BufWriteCmd call s:GPGFinishOptionsBuffer() + autocmd BufHidden,BufWriteCmd call s:GPGFinishOptionsBuffer() + autocmd BufUnload exe 'au! GPGOptions * ') .'>' augroup END " put some comments to the scratch buffer From 84fc2454384c1f65e58060f75b81456d4d40dee2 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Wed, 11 Nov 2020 13:06:05 -0500 Subject: [PATCH 3/3] Return early from Finish functions when buffer is not displayed When bufwinnr() returns -1, the buffer isn't currently displayed. In this case, we need to return so the contents of a different buffer aren't used for recipients/options. --- autoload/gnupg.vim | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/autoload/gnupg.vim b/autoload/gnupg.vim index c35661a..2dae193 100644 --- a/autoload/gnupg.vim +++ b/autoload/gnupg.vim @@ -769,8 +769,14 @@ function s:GPGFinishRecipientsBuffer() " go to buffer before doing work if (bufnr("%") != expand("")) - " switch to scratch buffer window - execute 'silent! ' . bufwinnr(expand(":p")) . "wincmd w" + let winnr = bufwinnr(expand(':p')) + if winnr >= 0 + " switch to scratch buffer window + execute 'silent! ' . winnr . "wincmd w" + else + call s:GPGDebug(3, '<<<<<<<< Leaving s:GPGFinishRecipientsBuffer() early because buffer is not displayed') + return + endif endif " get the recipients from the scratch buffer @@ -915,8 +921,14 @@ function s:GPGFinishOptionsBuffer() " go to buffer before doing work if (bufnr("%") != expand("")) - " switch to scratch buffer window - execute 'silent! ' . bufwinnr(expand(":p")) . "wincmd w" + let winnr = bufwinnr(expand(':p')) + if winnr >= 0 + " switch to scratch buffer window + execute 'silent! ' . winnr . "wincmd w" + else + call s:GPGDebug(3, '<<<<<<<< Leaving s:GPGFinishOptionsBuffer() early because buffer is not displayed') + return + endif endif " clear options and unknownOptions