|
1 | 1 | " Name: autoload/gnupg.vim |
2 | | -" Last Change: 2020 Nov 09 |
| 2 | +" Last Change: 2020 Nov 11 |
3 | 3 | " Maintainer: James McCoy <jamessan@jamessan.com> |
4 | 4 | " Original Author: Markus Braun <markus.braun@krawel.de> |
5 | 5 | " Summary: Vim plugin for transparent editing of gpg encrypted files. |
@@ -685,7 +685,8 @@ function gnupg#edit_recipients() |
685 | 685 | augroup GPGRecipients |
686 | 686 | au! * <buffer> |
687 | 687 | " add a autocommand to regenerate the recipients after a write |
688 | | - autocmd BufHidden,BufUnload,BufWriteCmd <buffer> call s:GPGFinishRecipientsBuffer() |
| 688 | + autocmd BufHidden,BufWriteCmd <buffer> call s:GPGFinishRecipientsBuffer() |
| 689 | + autocmd BufUnload <buffer> exe 'au! GPGRecipients * <buffer='. expand('<abuf>') .'>' |
689 | 690 | augroup END |
690 | 691 |
|
691 | 692 | " put some comments to the scratch buffer |
@@ -768,8 +769,14 @@ function s:GPGFinishRecipientsBuffer() |
768 | 769 |
|
769 | 770 | " go to buffer before doing work |
770 | 771 | if (bufnr("%") != expand("<abuf>")) |
771 | | - " switch to scratch buffer window |
772 | | - execute 'silent! ' . bufwinnr(expand("<afile>:p")) . "wincmd w" |
| 772 | + let winnr = bufwinnr(expand('<afile>:p')) |
| 773 | + if winnr >= 0 |
| 774 | + " switch to scratch buffer window |
| 775 | + execute 'silent! ' . winnr . "wincmd w" |
| 776 | + else |
| 777 | + call s:GPGDebug(3, '<<<<<<<< Leaving s:GPGFinishRecipientsBuffer() early because buffer is not displayed') |
| 778 | + return |
| 779 | + endif |
773 | 780 | endif |
774 | 781 |
|
775 | 782 | " get the recipients from the scratch buffer |
@@ -861,7 +868,8 @@ function gnupg#edit_options() |
861 | 868 | augroup GPGOptions |
862 | 869 | au! * <buffer> |
863 | 870 | " add a autocommand to regenerate the options after a write |
864 | | - autocmd BufHidden,BufUnload,BufWriteCmd <buffer> call s:GPGFinishOptionsBuffer() |
| 871 | + autocmd BufHidden,BufWriteCmd <buffer> call s:GPGFinishOptionsBuffer() |
| 872 | + autocmd BufUnload <buffer> exe 'au! GPGOptions * <buffer='. expand('<abuf>') .'>' |
865 | 873 | augroup END |
866 | 874 |
|
867 | 875 | " put some comments to the scratch buffer |
@@ -913,8 +921,14 @@ function s:GPGFinishOptionsBuffer() |
913 | 921 |
|
914 | 922 | " go to buffer before doing work |
915 | 923 | if (bufnr("%") != expand("<abuf>")) |
916 | | - " switch to scratch buffer window |
917 | | - execute 'silent! ' . bufwinnr(expand("<afile>:p")) . "wincmd w" |
| 924 | + let winnr = bufwinnr(expand('<afile>:p')) |
| 925 | + if winnr >= 0 |
| 926 | + " switch to scratch buffer window |
| 927 | + execute 'silent! ' . winnr . "wincmd w" |
| 928 | + else |
| 929 | + call s:GPGDebug(3, '<<<<<<<< Leaving s:GPGFinishOptionsBuffer() early because buffer is not displayed') |
| 930 | + return |
| 931 | + endif |
918 | 932 | endif |
919 | 933 |
|
920 | 934 | " clear options and unknownOptions |
|
0 commit comments