GPGDecrypt: Handle (un)encrypted files consistently
In the refactor to use the *Cmd events, an unencrypted file was simply :read into the buffer. This incorrectly caused an extra blank line to be added to the top of the buffer. The handling of encrypted files properly handles this, as well as triggering BufRead(Pre,Post) events. Instead of returning early for unencrypted files, go through the same steps as for encrypted files (minus the encryption specific steps), thus preserving the content of the original file.
This commit is contained in:
parent
be052843ef
commit
d279115bcd
@ -562,19 +562,18 @@ function s:GPGDecrypt(bufread)
|
|||||||
echohl GPGWarning
|
echohl GPGWarning
|
||||||
echom "File is not encrypted, all GPG functions disabled!"
|
echom "File is not encrypted, all GPG functions disabled!"
|
||||||
echohl None
|
echohl None
|
||||||
exe printf('%sr %s', silent, fnameescape(filename))
|
|
||||||
call s:GPGDebug(3, "<<<<<<<< Leaving s:GPGDecrypt()")
|
|
||||||
return
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
let bufname = b:GPGEncrypted ? autocmd_filename : fnameescape(filename)
|
||||||
if a:bufread
|
if a:bufread
|
||||||
silent execute ':doautocmd BufReadPre ' . autocmd_filename
|
silent execute ':doautocmd BufReadPre ' . bufname
|
||||||
call s:GPGDebug(2, 'called BufReadPre autocommand for ' . autocmd_filename)
|
call s:GPGDebug(2, 'called BufReadPre autocommand for ' . bufname)
|
||||||
else
|
else
|
||||||
silent execute ':doautocmd FileReadPre ' . autocmd_filename
|
silent execute ':doautocmd FileReadPre ' . bufname
|
||||||
call s:GPGDebug(2, 'called FileReadPre autocommand for ' . autocmd_filename)
|
call s:GPGDebug(2, 'called FileReadPre autocommand for ' . bufname)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
if b:GPGEncrypted
|
||||||
" check if the message is armored
|
" check if the message is armored
|
||||||
if (match(output, "gpg: armor header") >= 0)
|
if (match(output, "gpg: armor header") >= 0)
|
||||||
call s:GPGDebug(1, "this file is armored")
|
call s:GPGDebug(1, "this file is armored")
|
||||||
@ -601,6 +600,9 @@ function s:GPGDecrypt(bufread)
|
|||||||
call s:GPGDebug(3, "<<<<<<<< Leaving s:GPGDecrypt()")
|
call s:GPGDebug(3, "<<<<<<<< Leaving s:GPGDecrypt()")
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
else
|
||||||
|
execute silent 'read' fnameescape(filename)
|
||||||
|
endif
|
||||||
|
|
||||||
if a:bufread
|
if a:bufread
|
||||||
" In order to make :undo a no-op immediately after the buffer is read,
|
" In order to make :undo a no-op immediately after the buffer is read,
|
||||||
@ -621,19 +623,21 @@ function s:GPGDecrypt(bufread)
|
|||||||
" - permissions don't allow writing
|
" - permissions don't allow writing
|
||||||
let &readonly = &readonly || (filereadable(filename) && filewritable(filename) == 0)
|
let &readonly = &readonly || (filereadable(filename) && filewritable(filename) == 0)
|
||||||
" call the autocommand for the file minus .gpg$
|
" call the autocommand for the file minus .gpg$
|
||||||
silent execute ':doautocmd BufReadPost ' . autocmd_filename
|
silent execute ':doautocmd BufReadPost ' . bufname
|
||||||
call s:GPGDebug(2, 'called BufReadPost autocommand for ' . autocmd_filename)
|
call s:GPGDebug(2, 'called BufReadPost autocommand for ' . bufname)
|
||||||
else
|
else
|
||||||
" call the autocommand for the file minus .gpg$
|
" call the autocommand for the file minus .gpg$
|
||||||
silent execute ':doautocmd FileReadPost ' . autocmd_filename
|
silent execute ':doautocmd FileReadPost ' . bufname
|
||||||
call s:GPGDebug(2, 'called FileReadPost autocommand for ' . autocmd_filename)
|
call s:GPGDebug(2, 'called FileReadPost autocommand for ' . bufname)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
if b:GPGEncrypted
|
||||||
" Allow the user to define actions for GnuPG buffers
|
" Allow the user to define actions for GnuPG buffers
|
||||||
silent doautocmd User GnuPG
|
silent doautocmd User GnuPG
|
||||||
|
|
||||||
" refresh screen
|
" refresh screen
|
||||||
redraw!
|
redraw!
|
||||||
|
endif
|
||||||
|
|
||||||
call s:GPGDebug(3, "<<<<<<<< Leaving s:GPGDecrypt()")
|
call s:GPGDebug(3, "<<<<<<<< Leaving s:GPGDecrypt()")
|
||||||
endfunction
|
endfunction
|
||||||
|
Loading…
x
Reference in New Issue
Block a user