From d7361d413caacc8de227804aad1dc139a2ce83d3 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Wed, 30 May 2012 21:02:40 -0400 Subject: [PATCH] Clear undo history as the last step of BufReadCmd After opening a file, an immediate "u"/":undo" would remove the entire contents of the buffer. Even worse, this would not set 'modified', so there would be no indication that wasn't the actual initial state of the buffer. Discarding undo history for a buffer requires a few steps, including making a change. Luckily, a change is already being made (deleting the extra line left after ":r !" the decrypted file), so discarding undo history can piggy-back on top of that. Signed-off-by: James McCoy --- plugin/gnupg.vim | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/plugin/gnupg.vim b/plugin/gnupg.vim index e621f25..8816e58 100644 --- a/plugin/gnupg.vim +++ b/plugin/gnupg.vim @@ -1,5 +1,5 @@ " Name: gnupg.vim -" Last Change: 2011 Nov 23 +" Last Change: 2012 May 30 " Maintainer: James McCoy " Original Author: Markus Braun " Summary: Vim plugin for transparent editing of gpg encrypted files. @@ -453,15 +453,33 @@ function s:GPGDecrypt() call s:GPGDebug(3, "<<<<<<<< Leaving s:GPGDecrypt()") endfunction +" Function: s:GPGBufReadPost() {{{2 +" +" Handle functionality specific to opening a file for reading rather than +" reading the contents of a file into a buffer +" function s:GPGBufReadPost() call s:GPGDebug(3, ">>>>>>>> Entering s:GPGBufReadPost()") + " In order to make :undo a no-op immediately after the buffer is read, + " we need to do this dance with 'undolevels'. Actually discarding the undo + " history requires performing a change after setting 'undolevels' to -1 and, + " luckily, we have one we need to do (delete the extra line from the :r + " command) + let levels = &undolevels + set undolevels=-1 silent 1delete + let &undolevels = levels " call the autocommand for the file minus .gpg$ execute ':doautocmd BufReadPost ' . fnameescape(expand(':r')) call s:GPGDebug(2, 'called autocommand for ' . fnameescape(expand(':r'))) call s:GPGDebug(3, "<<<<<<<< Leaving s:GPGBufReadPost()") endfunction +" Function: s:GPGBufWritePre() {{{2 +" +" Handle functionality specific to saving an entire buffer to a file rather +" than saving a partial buffer +" function s:GPGBufWritePre() call s:GPGDebug(3, ">>>>>>>> Entering s:GPGBufWritePre()") " call the autocommand for the file minus .gpg$