From 28e0be4cd2986049ed135522ab29bc77ab338429 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Thu, 25 Aug 2016 21:30:16 -0400 Subject: [PATCH] Maintain 'readonly' if it's already set If the user is using "vim -R"/":view", then the opened buffer should have 'readonly' set, even if permissions would otherwise allow editing. Closes jamessan/vim-gnupg#67 Signed-off-by: James McCoy --- plugin/gnupg.vim | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/plugin/gnupg.vim b/plugin/gnupg.vim index 15bd931..07b10ea 100644 --- a/plugin/gnupg.vim +++ b/plugin/gnupg.vim @@ -1,5 +1,5 @@ " Name: gnupg.vim -" Last Change: 2016 Apr 24 +" Last Change: 2016 Aug 25 " Maintainer: James McCoy " Original Author: Markus Braun " Summary: Vim plugin for transparent editing of gpg encrypted files. @@ -599,7 +599,10 @@ function s:GPGDecrypt(bufread) 1mark [ $mark ] let &undolevels = levels - let &readonly = filereadable(filename) && filewritable(filename) == 0 + " The buffer should be readonly if + " - 'readonly' is already set (e.g., when using view/vim -R) + " - permissions don't allow writing + let &readonly = &readonly || (filereadable(filename) && filewritable(filename) == 0) " call the autocommand for the file minus .gpg$ silent execute ':doautocmd BufReadPost ' . autocmd_filename call s:GPGDebug(2, 'called BufReadPost autocommand for ' . autocmd_filename)