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