[SCM] vim-scripts packaging branch, master, updated. v20091011-30-gc476b42

James Vega jamessan at debian.org
Sun Aug 14 03:27:06 UTC 2011


The following commit has been merged in the master branch:
commit ed1162d11fa1f08e912e27107eb5d034c2bd31dd
Author: James Vega <jamessan at debian.org>
Date:   Sun Jun 26 16:06:14 2011 -0400

    Update gnupg.vim to 2.0
    
    Signed-off-by: James Vega <jamessan at debian.org>

diff --git a/debian/changelog b/debian/changelog
index 8d77222..bfcc9cb 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -9,9 +9,14 @@ vim-scripts (20091012) UNRELEASED; urgency=low
     - vcscommand: Update to 1.99.35
     - calendar: Update to 2.5
     - bufexplorer: Update to 7.2.8
-    - gnupg: Update to 3026
+    - gnupg: Update to 2.0
       + Fixes a bug when the user's shell is (t)csh and /bin/sh is dash.
         (Closes: #552085)
+      + Do not prompt the user when the same key exists in multiple keyrings.
+        (Closes: #566341)
+      + Improve error handling when gpg command fails to prevent file
+        truncation.  (Closes: #573440)
+      + Use --armor when saving a new *.asc file.  (Closes: #496667)
     - surround: Update to 1.90
     - NERD_commenter: Update to 2.3.0
     - xmledit: Update to 1.9.1
diff --git a/debian/vim-scripts.status b/debian/vim-scripts.status
index 382f414..e292eef 100644
--- a/debian/vim-scripts.status
+++ b/debian/vim-scripts.status
@@ -63,13 +63,13 @@ version:     6.3.2
 script_name: plugin/gnupg.vim
 addon:       gnupg
 description: transparent editing of gpg encrypted files
-script_url:  http://www.vim.org/scripts/script.php?script_id=661
-author:      Markus Braun
-author_url:  http://www.vim.org/account/profile.php?user_id=1120
-email:       markus.braun at krawel.de
-license:     GNU GPL, see /usr/share/common-licenses/GPL
+script_url:  http://www.vim.org/scripts/script.php?script_id=3645
+author:      James Vega
+author_url:  http://www.vim.org/account/profile.php?user_id=5603
+email:       vega.james at gmail.com
+license:     GNU GPL, see /usr/share/common-licenses/GPL-2
 disabledby:  let loaded_gnupg = 1
-version:     3026
+version:     2.0
 
 script_name: plugin/taglist.vim
 addon:       taglist
diff --git a/html/index.html b/html/index.html
index 1108311..7870ad7 100644
--- a/html/index.html
+++ b/html/index.html
@@ -50,7 +50,7 @@
    <li><a href="syntax_mkd.vim.html">syntax/mkd.vim.html</a></li>
   </ul>
   <p>
-  Page generated on Sun, 26 Jun 2011 14:32:18 -0400
+  Page generated on Sun, 26 Jun 2011 15:57:58 -0400
 .
   </p>
  </body>
diff --git a/html/plugin_gnupg.vim.html b/html/plugin_gnupg.vim.html
index 1eb6f76..ae11f82 100644
--- a/html/plugin_gnupg.vim.html
+++ b/html/plugin_gnupg.vim.html
@@ -3,7 +3,7 @@
 
 <head>
   <link rel="Stylesheet" type="text/css" href="/css/style.css" >
-  <title>gnupg - Plugin for transparent editing of gpg encrypted files. : vim online</title>
+  <title>gnupg.vim - Plugin for transparent editing of gpg encrypted files. : vim online</title>
   <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
   <meta name="KEYWORDS" content="Vim, Vi IMproved, text editor, home, documentation, tips, scripts, news">
   <link rel="shortcut icon" type="image/x-icon" href="/images/vim_shortcut.ico">
@@ -156,7 +156,7 @@
         <tr>
           <td valign="top">
 
-<span class="txth1">gnupg : Plugin for transparent editing of gpg encrypted files.</span> 
+<span class="txth1">gnupg.vim : Plugin for transparent editing of gpg encrypted files.</span> 
 
 <br>
 <br>
@@ -166,30 +166,36 @@
 <tr>
   <td class="lightbg"><b> script karma </b></td>
   <td>
-    Rating <b>1004/352</b>,
-    Downloaded by 7919  </td>
+    Rating <b>0/0</b>,
+    Downloaded by 0  </td>
+  <td class="lightbg">
+  <b> Comments, bugs, improvements </b>
+  </td>
+  <td>
+    <a href="http://vim.wikia.com/wiki/Script:3645">Vim wiki</a>
+  </td>  
 </tr>
 </table>
 <p>
 
 <table cellspacing="0" cellpadding="0" border="0">
 <tr><td class="prompt">created by</td></tr>
-<tr><td><a href="/account/profile.php?user_id=1120">Markus Braun</a></td></tr>
+<tr><td><a href="/account/profile.php?user_id=5603">James Vega</a></td></tr>
 <tr><td> </td></tr>
 <tr><td class="prompt">script type</td></tr>
 <tr><td>utility</td></tr>
 <tr><td> </td></tr>
 <tr><td class="prompt">description</td></tr>
-<tr><td>This script implements transparent editing of gpg encrypted files. The filename must have a ".gpg", ".pgp" or ".asc" suffix. When opening such a file the content is decrypted, when opening a new file the script will ask for the recipients of the encrypted file. The file content will be encrypted to all recipients before it is written. The script turns off viminfo and swapfile to increase security.
<br>
<br>Commands:
<br>
<br>  :GPGEditRecipients
<br>    Opens a scratch buffer to change the list of recipients. Recipients that
<br>    are unknown (not in your public key) are highlighted and have
<br>    a prepended "!". Closing the buffer makes the changes permanent.
<br>
<br>  :GPGViewRecipients
<br>    Prints the list of recipients.
<br>
<br>  :GPGEditOptions
<br>    Opens a scratch buffer to change the options for encryption (symmetric,
<br>    asymmetric, signing). Closing the buffer makes the changes permanent.
<br>    WARNING: There is no check of the entered options, so you need to know
<br>    what you are doing.
<br>
<br>  :GPGViewOptions
<br>    Prints the list of options.
<br>
<br>Variables:
<br>
<br>  g:GPGExecutable
<br>    If set used as gpg executable, otherwise the system chooses what is run
<br>    when "gpg" is called. Defaults to "gpg".
<br>
<br>  g:GPGUseAgent
<br>    If set to 0 a possible available gpg-agent won't be used. Defaults to 1.
<br>
<br>  g:GPGPreferSymmetric
<br>    If set to 1 symmetric encryption is preferred for new files. Defaults to 0.
<br>
<br>  g:GPGPreferArmor
<br>    If set to 1 armored data is preferred for new files. Defaults to 0.
<br>
<br>  g:GPGPreferSign
<br>    If set to 1 signed data is preferred for new files. Defaults to 0.
<br>
<br>  g:GPGDefaultRecipients
<br>    If set, these recipients are used as defaults when no other recipient is
<br>    defined. This variable is a Vim list. Default is unset.
<br>
<br>Known Issues:
<br>
<br>  In some cases gvim can't decryt files
<br>
<br>  This is caused by the fact that a running gvim has no TTY and thus gpg is
<br>  not able to ask for the passphrase by itself. This is a problem for Windows
<br>  and Linux versions of gvim and could not be solved unless a "terminal
<br>  emulation" is implemented for gvim. To circumvent this you have to use any
<br>  combination of gpg-agent and a graphical pinentry program:
<br>
<br>    - gpg-agent only:
<br>        you need to provide the passphrase for the needed key to gpg-agent
<br>        in a terminal before you open files with gvim which require this key.
<br>
<br>    - pinentry only:
<br>        you will get a popup window every time you open a file that needs to
<br>        be decrypted.
<br>
<br>    - gpgagent and pinentry:
<br>        you will get a popup window the first time you open a file that
<br>        needs to be decrypted.
<br></td></tr>
+<tr><td>This script implements transparent editing of gpg encrypted files. The filename must have a ".gpg", ".pgp" or ".asc" suffix. When opening such a file the content is decrypted, when opening a new file the script will ask for the recipients of the encrypted file. The file content will be encrypted to all recipients before it is written. The script turns off viminfo and swapfile to increase security.
<br>
<br>This is a continuation of the work initially done by Markus Braun in <a href="/scripts/script.php?script_id=661">vimscript #661</a>.  Development takes place at <a target="_blank" href="http://gitorious.org/vim-gnupg">http://gitorious.org/vim-gnupg</A>.
<br>
<br>Commands: 
<br>
<br>  :GPGEditRecipients 
<br>    Opens a scratch buffer to change the list of recipients. Recipients that 
<br>    are unknown (not in your public key) are highlighted and have 
<br>    a prepended "!". Closing the buffer makes the changes permanent. 
<br>
<br>  :GPGViewRecipients 
<br>    Prints the list of recipients. 
<br>
<br>  :GPGEditOptions 
<br>    Opens a scratch buffer to change the options for encryption (symmetric, 
<br>    asymmetric, signing). Closing the buffer makes the changes permanent. 
<br>    WARNING: There is no check of the entered options, so you need to know 
<br>    what you are doing. 
<br>
<br>  :GPGViewOptions 
<br>    Prints the list of options. 
<br>
<br>Variables: 
<br>
<br>  g:GPGExecutable 
<br>    If set used as gpg executable, otherwise the system chooses what is run 
<br>    when "gpg" is called. Defaults to "gpg". 
<br>
<br>  g:GPGUseAgent 
<br>    If set to 0 a possible available gpg-agent won't be used. Defaults to 1. 
<br>
<br>  g:GPGPreferSymmetric 
<br>    If set to 1 symmetric encryption is preferred for new files. Defaults to 0. 
<br>
<br>  g:GPGPreferArmor 
<br>    If set to 1 armored data is preferred for new files. Defaults to 0. 
<br>
<br>  g:GPGPreferSign 
<br>    If set to 1 signed data is preferred for new files. Defaults to 0. 
<br>
<br>  g:GPGDefaultRecipients 
<br>    If set, these recipients are used as defaults when no other recipient is 
<br>    defined. This variable is a Vim list. Default is unset. 
<br>
<br>Known Issues: 
<br>
<br>  In some cases gvim can't decryt files 
<br>
<br>  This is caused by the fact that a running gvim has no TTY and thus gpg is 
<br>  not able to ask for the passphrase by itself. This is a problem for Windows 
<br>  and Linux versions of gvim and could not be solved unless a "terminal 
<br>  emulation" is implemented for gvim. To circumvent this you have to use any 
<br>  combination of gpg-agent and a graphical pinentry program: 
<br>
<br>    - gpg-agent only: 
<br>        you need to provide the passphrase for the needed key to gpg-agent 
<br>        in a terminal before you open files with gvim which require this key. 
<br>
<br>    - pinentry only: 
<br>        you will get a popup window every time you open a file that needs to 
<br>        be decrypted. 
<br>
<br>    - gpgagent and pinentry: 
<br>        you will get a popup window the first time you open a file that 
<br>        needs to be decrypted. </td></tr>
 <tr><td> </td></tr>
 <tr><td class="prompt">install details</td></tr>
-<tr><td>Copy the gnupg.vim file to the $HOME/.vim/plugin directory. Refer to ':help add-plugin', ':help add-global-plugin' and ':help runtimepath' for more details about Vim plugins.
<br>
<br>From "man 1 gpg-agent":
<br>...
<br>You should always add the following lines to your .bashrc or whatever initialization file is used for all shell invocations:
<br>
<br>     GPG_TTY=`tty`
<br>     export GPG_TTY
<br>
<br>It is important that this environment variable always reflects the output of the tty command. For W32 systems this option is not required.
<br>...
<br>
<br>Most distributions provide software to ease handling of gpg and gpg-agent. Examples are keychain or seahorse.
<br></td></tr>
+<tr><td>Copy the gnupg.vim file to the $HOME/.vim/plugin directory. Refer to ':help add-plugin', ':help add-global-plugin' and ':help runtimepath' for more details about Vim plugins. 
<br>
<br>From "man 1 gpg-agent": 
<br>... 
<br>You should always add the following lines to your .bashrc or whatever initialization file is used for all shell invocations: 
<br>
<br>     GPG_TTY=`tty` 
<br>     export GPG_TTY 
<br>
<br>It is important that this environment variable always reflects the output of the tty command. For W32 systems this option is not required. 
<br>... 
<br>
<br>Most distributions provide software to ease handling of gpg and gpg-agent. Examples are keychain or seahorse.</td></tr>
 <tr><td> </td></tr>
 </table>
 
 <!-- rating table -->
 <form name="rating">
-<input type="hidden" name="script_id" value="661">
+<input type="hidden" name="script_id" value="3645">
 <table cellpadding="4" cellspacing="0" border="1" bordercolor="#000066">
 <tr>
   <td class="lightbg"><b>rate this script</b></td>
@@ -202,7 +208,7 @@
 </tr>
 </table>
 </form>
-<span class="txth2">script versions</span> (<a href="add_script_version.php?script_id=661">upload new version</a>)
+<span class="txth2">script versions</span> (<a href="add_script_version.php?script_id=3645">upload new version</a>)
 <p>
 Click on the package to download.
 <p>
@@ -217,84 +223,12 @@ Click on the package to download.
     <th valign="top">release notes</th>
 </tr>
 <tr>
-        <td class="rowodd" valign="top" nowrap><a href="download_script.php?src_id=12200">gnupg.vim</a></td>
-    <td class="rowodd" valign="top" nowrap><b>3026</b></td>
-    <td class="rowodd" valign="top" nowrap><i>2010-01-27</i></td>
-    <td class="rowodd" valign="top" nowrap>7.0</td>
-    <td class="rowodd" valign="top"><i><a href="/account/profile.php?user_id=1120">Markus Braun</a></i></td>
-    <td class="rowodd" valign="top" width="2000">- fix a bug by using a sh compatible setting for 'shellredir' on unix systems. when 'shell' was set to csh or tcsh by the user and the system has /bin/sh linked to dash the plugin didn't work.
<br></td>
-</tr>
-<tr>
-        <td class="roweven" valign="top" nowrap><a href="download_script.php?src_id=10833">gnupg.vim</a></td>
-    <td class="roweven" valign="top" nowrap><b>2782</b></td>
-    <td class="roweven" valign="top" nowrap><i>2009-06-15</i></td>
-    <td class="roweven" valign="top" nowrap>7.0</td>
-    <td class="roweven" valign="top"><i><a href="/account/profile.php?user_id=1120">Markus Braun</a></i></td>
-    <td class="roweven" valign="top" width="2000">- show more information (key id and creation time) of keys in GPGEditRecipients, GPGViewRecipients and during selecting in case of a ambiguous key.
<br></td>
-</tr>
-<tr>
-        <td class="rowodd" valign="top" nowrap><a href="download_script.php?src_id=10683">gnupg.vim</a></td>
-    <td class="rowodd" valign="top" nowrap><b>2773</b></td>
-    <td class="rowodd" valign="top" nowrap><i>2009-05-27</i></td>
-    <td class="rowodd" valign="top" nowrap>7.0</td>
-    <td class="rowodd" valign="top"><i><a href="/account/profile.php?user_id=1120">Markus Braun</a></i></td>
-    <td class="rowodd" valign="top" width="2000">- fix a bug in detecting windows platforms
<br>- added g:GPGPreferSign to sign encrypted files by default (thanks to Tim Swast).
<br></td>
-</tr>
-<tr>
-        <td class="roweven" valign="top" nowrap><a href="download_script.php?src_id=9142">gnupg.vim</a></td>
-    <td class="roweven" valign="top" nowrap><b>2276</b></td>
-    <td class="roweven" valign="top" nowrap><i>2008-08-18</i></td>
-    <td class="roweven" valign="top" nowrap>7.0</td>
-    <td class="roweven" valign="top"><i><a href="/account/profile.php?user_id=1120">Markus Braun</a></i></td>
-    <td class="roweven" valign="top" width="2000">- added support for default recipients via the variable g:GPGDefaultRecipients.
<br>- fixed an wrong error message with symmetric encryption and set recipients (thanks to Sebastian Luettich).
<br>- create a empty new buffer on leaving vim to wipe out sensitive data on console.
<br>- make sure senisitive data is never written unencrypted to disk.</td>
-</tr>
-<tr>
-        <td class="rowodd" valign="top" nowrap><a href="download_script.php?src_id=9058">gnupg.vim</a></td>
-    <td class="rowodd" valign="top" nowrap><b>2249</b></td>
-    <td class="rowodd" valign="top" nowrap><i>2008-07-31</i></td>
-    <td class="rowodd" valign="top" nowrap>7.0</td>
-    <td class="rowodd" valign="top"><i><a href="/account/profile.php?user_id=1120">Markus Braun</a></i></td>
-    <td class="rowodd" valign="top" width="2000">- rewritten lots of code to use lists feature of vim 7 instead of my own implementation
<br>- added a n option to change the name and location of GPG executable
<br>- try to get GPG_TTY dynamically.</td>
-</tr>
-<tr>
-        <td class="roweven" valign="top" nowrap><a href="download_script.php?src_id=8174">gnupg.vim</a></td>
-    <td class="roweven" valign="top" nowrap><b>1933</b></td>
-    <td class="roweven" valign="top" nowrap><i>2008-01-23</i></td>
-    <td class="roweven" valign="top" nowrap>6.0</td>
-    <td class="roweven" valign="top"><i><a href="/account/profile.php?user_id=1120">Markus Braun</a></i></td>
-    <td class="roweven" valign="top" width="2000">- changed parsin to work with gpg2 correctly
<br>- save/restore view of saved window
<br>- fix a bug when encoding and fileencoding is different
<br>- restructured autocommand triggers
<br>- added a debug command and debug messages</td>
-</tr>
-<tr>
-        <td class="rowodd" valign="top" nowrap><a href="download_script.php?src_id=6949">gnupg.vim</a></td>
-    <td class="rowodd" valign="top" nowrap><b>1605</b></td>
-    <td class="rowodd" valign="top" nowrap><i>2007-04-05</i></td>
-    <td class="rowodd" valign="top" nowrap>6.0</td>
-    <td class="rowodd" valign="top"><i><a href="/account/profile.php?user_id=1120">Markus Braun</a></i></td>
-    <td class="rowodd" valign="top" width="2000">- new plugin options to set preferences for symmetric/asymmetric and armor/binary files
<br>- fix for use with gvim. !! plugin works only in gvim if gpg-agent is available !!</td>
-</tr>
-<tr>
-        <td class="roweven" valign="top" nowrap><a href="download_script.php?src_id=6518">gnupg.vim</a></td>
-    <td class="roweven" valign="top" nowrap><b>1472</b></td>
-    <td class="roweven" valign="top" nowrap><i>2006-12-15</i></td>
-    <td class="roweven" valign="top" nowrap>6.0</td>
-    <td class="roweven" valign="top"><i><a href="/account/profile.php?user_id=1120">Markus Braun</a></i></td>
-    <td class="roweven" valign="top" width="2000">- support for symmetric encrypted files.
<br>- detection of various encryption options.
<br>- possibility to change gpg options using new commands GPGEditOptions and GPGViewOptions commands.
<br>- support editing files with '.gpg', '.pgp' and '.asc' suffixes (tanks to Richard Bronosky).
<br>- detection of unencrypted files.
<br>- support for windows systems (thanks to Erik Remmelzwaal).</td>
-</tr>
-<tr>
-        <td class="rowodd" valign="top" nowrap><a href="download_script.php?src_id=2108">gnupg.vim</a></td>
-    <td class="rowodd" valign="top" nowrap><b>1.27</b></td>
-    <td class="rowodd" valign="top" nowrap><i>2003-06-24</i></td>
-    <td class="rowodd" valign="top" nowrap>6.0</td>
-    <td class="rowodd" valign="top"><i><a href="/account/profile.php?user_id=1120">Markus Braun</a></i></td>
-    <td class="rowodd" valign="top" width="2000">updated documentation, that gnupg.vim only works for public/private-key encrypted files.</td>
-</tr>
-<tr>
-        <td class="roweven" valign="top" nowrap><a href="download_script.php?src_id=2029">gnupg.vim</a></td>
-    <td class="roweven" valign="top" nowrap><b>1.26</b></td>
-    <td class="roweven" valign="top" nowrap><i>2003-05-30</i></td>
-    <td class="roweven" valign="top" nowrap>6.0</td>
-    <td class="roweven" valign="top"><i><a href="/account/profile.php?user_id=1120">Markus Braun</a></i></td>
-    <td class="roweven" valign="top" width="2000">Initial upload</td>
+        <td class="rowodd" valign="top" nowrap><a href="download_script.php?src_id=15987">gnupg.vim</a></td>
+    <td class="rowodd" valign="top" nowrap><b>2.0</b></td>
+    <td class="rowodd" valign="top" nowrap><i>2011-06-26</i></td>
+    <td class="rowodd" valign="top" nowrap>7.2</td>
+    <td class="rowodd" valign="top"><i><a href="/account/profile.php?user_id=5603">James Vega</a></i></td>
+    <td class="rowodd" valign="top" width="2000">Initial upload</td>
 </tr>
 </table>
 <!-- finish off the framework -->
diff --git a/plugin/gnupg.vim b/plugin/gnupg.vim
index 09116d6..e68e964 100644
--- a/plugin/gnupg.vim
+++ b/plugin/gnupg.vim
@@ -1,10 +1,13 @@
 " Name:    gnupg.vim
-" Version: $Id: gnupg.vim 3026 2010-01-27 08:18:04Z mbr $
-" Author:  Markus Braun <markus.braun at krawel.de>
+" Last Change: 2011 June 26
+" Author:  James Vega <vega.james at gmail.com>
+" Original Author:  Markus Braun <markus.braun at krawel.de>
 " Summary: Vim plugin for transparent editing of gpg encrypted files.
-" Licence: This program is free software; you can redistribute it and/or
-"          modify it under the terms of the GNU General Public License.
-"          See http://www.gnu.org/copyleft/gpl.txt
+" License: This program is free software; you can redistribute it and/or
+"          modify it under the terms of the GNU General Public License
+"          as published by the Free Software Foundation; either version
+"          2 of the License, or (at your option) any later version.
+"          See http://www.gnu.org/copyleft/gpl-2.0.txt
 "
 " Section: Documentation {{{1
 "
@@ -71,7 +74,8 @@
 "     If set to 1 symmetric encryption is preferred for new files. Defaults to 0.
 "
 "   g:GPGPreferArmor
-"     If set to 1 armored data is preferred for new files. Defaults to 0.
+"     If set to 1 armored data is preferred for new files. Defaults to 0
+"     unless a "*.asc" file is being edited.
 "
 "   g:GPGPreferSign
 "     If set to 1 signed data is preferred for new files. Defaults to 0.
@@ -82,7 +86,7 @@
 "
 " Known Issues: {{{2
 "
-"   In some cases gvim can't decryt files
+"   In some cases gvim can't decrypt files
 
 "   This is caused by the fact that a running gvim has no TTY and thus gpg is
 "   not able to ask for the passphrase by itself. This is a problem for Windows
@@ -109,25 +113,28 @@
 "   - Erik Remmelzwaal for patch to enable windows support and patient beta
 "     testing.
 "   - Lars Becker for patch to make gpg2 working.
-"   - Thomas Arendsen Hein for patch to convert encoding of gpg output
+"   - Thomas Arendsen Hein for patch to convert encoding of gpg output.
 "   - Karl-Heinz Ruskowski for patch to fix unknown recipients and trust model
 "     and patient beta testing.
 "   - Giel van Schijndel for patch to get GPG_TTY dynamically.
 "   - Sebastian Luettich for patch to fix issue with symmetric encryption an set
 "     recipients.
-"   - Tim Swast for patch to generate signed files
+"   - Tim Swast for patch to generate signed files.
+"   - James Vega for patches for better '*.asc' handling, better filename
+"     escaping and better handling of multiple keyrings.
 "
 " Section: Plugin header {{{1
 
 " guard against multiple loads {{{2
-if (exists("g:loaded_gnupg") || &cp || exists("#BufReadPre#*.\(gpg\|asc\|pgp\)"))
+if (exists("g:loaded_gnupg") || &cp || exists("#BufReadCmd*.\(gpg\|asc\|pgp\)"))
   finish
 endif
-let g:loaded_gnupg = "$Revision: 3026 $"
+let g:loaded_gnupg = '2.0'
+let s:GPGInitRun = 0
 
 " check for correct vim version {{{2
-if (v:version < 700)
-  echohl ErrorMsg | echo 'plugin gnupg.vim requires Vim version >= 7.0' | echohl None
+if (v:version < 702)
+  echohl ErrorMsg | echo 'plugin gnupg.vim requires Vim version >= 7.2' | echohl None
   finish
 endif
 
@@ -136,19 +143,14 @@ endif
 augroup GnuPG
   autocmd!
 
-  " initialize the internal variables
-  autocmd BufNewFile,BufReadPre,FileReadPre      *.\(gpg\|asc\|pgp\) call s:GPGInit()
-  " force the user to edit the recipient list if he opens a new file and public
-  " keys are preferred
-  autocmd BufNewFile                             *.\(gpg\|asc\|pgp\) if (exists("g:GPGPreferSymmetric") && g:GPGPreferSymmetric == 0) | call s:GPGEditRecipients() | endif
   " do the decryption
-  autocmd BufReadPost,FileReadPost               *.\(gpg\|asc\|pgp\) call s:GPGDecrypt()
+  autocmd BufReadCmd,FileReadCmd                 *.\(gpg\|asc\|pgp\) call s:GPGInit()
+  autocmd BufReadCmd,FileReadCmd                 *.\(gpg\|asc\|pgp\) call s:GPGDecrypt()
+  autocmd BufReadCmd                             *.\(gpg\|asc\|pgp\) call s:GPGBufReadPost()
 
   " convert all text to encrypted text before writing
-  autocmd BufWritePre,FileWritePre               *.\(gpg\|asc\|pgp\) call s:GPGEncrypt()
-  " undo the encryption so we are back in the normal text, directly
-  " after the file has been written.
-  autocmd BufWritePost,FileWritePost             *.\(gpg\|asc\|pgp\) call s:GPGEncryptPost()
+  autocmd BufWriteCmd,FileWriteCmd               *.\(gpg\|asc\|pgp\) call s:GPGInit()
+  autocmd BufWriteCmd,FileWriteCmd               *.\(gpg\|asc\|pgp\) call s:GPGEncrypt()
 
   " cleanup on leaving vim
   autocmd VimLeave                               *.\(gpg\|asc\|pgp\) call s:GPGCleanup()
@@ -173,13 +175,23 @@ highlight default link GPGHighlightUnknownRecipient ErrorMsg
 function s:GPGInit()
   call s:GPGDebug(3, ">>>>>>>> Entering s:GPGInit()")
 
+  " we don't want a swap file, as it writes unencrypted data to disk
+  setl noswapfile
+
+  " if persistent undo is present, disable it for this buffer
+  if exists('+undofile')
+    setl noundofile
+  endif
+
+  " the rest only has to be run once
+  if s:GPGInitRun
+    return
+  endif
+
   " first make sure nothing is written to ~/.viminfo while editing
   " an encrypted file.
   set viminfo=
 
-  " we don't want a swap file, as it writes unencrypted data to disk
-  set noswapfile
-
   " check what gpg command to use
   if (!exists("g:GPGExecutable"))
     let g:GPGExecutable = "gpg --trust-model always"
@@ -197,7 +209,12 @@ function s:GPGInit()
 
   " check if armored files are preferred
   if (!exists("g:GPGPreferArmor"))
-    let g:GPGPreferArmor = 0
+    " .asc files should be armored as that's what the extension is used for
+    if expand('<afile>') =~ '\.asc$'
+      let g:GPGPreferArmor = 1
+    else
+      let g:GPGPreferArmor = 0
+    endif
   endif
 
   " check if signed files are preferred
@@ -230,16 +247,21 @@ function s:GPGInit()
     let s:GPGCommand = g:GPGExecutable . " --no-use-agent"
   endif
 
-  " don't use tty in gvim
+  " don't use tty in gvim except for windows: we get their a tty for free.
   " FIXME find a better way to avoid an error.
   "       with this solution only --use-agent will work
-  if (has("gui_running"))
+  if (has("gui_running") && !has("gui_win32"))
     let s:GPGCommand = s:GPGCommand . " --no-tty"
   endif
 
   " setup shell environment for unix and windows
   let s:shellredirsave = &shellredir
   let s:shellsave = &shell
+  let s:shelltempsave = &shelltemp
+  " noshelltemp isn't currently supported on Windows, but it doesn't cause any
+  " errors and this future proofs us against requiring changes if Windows
+  " gains noshelltemp functionality
+  let s:shelltemp = 0
   if (has("unix"))
     " unix specific settings
     let s:shellredir = ">%s 2>&1"
@@ -255,6 +277,7 @@ function s:GPGInit()
 
   call s:GPGDebug(3, "shellredirsave: " . s:shellredirsave)
   call s:GPGDebug(3, "shellsave: " . s:shellsave)
+  call s:GPGDebug(3, "shelltempsave: " . s:shelltempsave)
 
   call s:GPGDebug(3, "shell: " . s:shell)
   call s:GPGDebug(3, "shellcmdflag: " . &shellcmdflag)
@@ -284,6 +307,7 @@ function s:GPGInit()
   call s:GPGDebug(2, "hashing algorithms: " . s:GPGHash)
   call s:GPGDebug(2, "compression algorithms: " . s:GPGCompress)
   call s:GPGDebug(3, "<<<<<<<< Leaving s:GPGInit()")
+  let s:GPGInitRun = 1
 endfunction
 
 " Function: s:GPGCleanup() {{{2
@@ -307,11 +331,13 @@ endfunction
 function s:GPGDecrypt()
   call s:GPGDebug(3, ">>>>>>>> Entering s:GPGDecrypt()")
 
-  " switch to binary mode to read the encrypted file
-  set bin
-
   " get the filename of the current buffer
-  let filename = escape(expand("%:p"), '\"')
+  let filename = expand("<afile>:p")
+
+  " File doesn't exist yet, so nothing to decrypt
+  if empty(glob(filename))
+    return
+  endif
 
   " clear GPGEncrypted, GPGRecipients and GPGOptions
   let b:GPGEncrypted = 0
@@ -319,13 +345,15 @@ function s:GPGDecrypt()
   let b:GPGOptions = []
 
   " find the recipients of the file
-  let commandline = s:GPGCommand . " --verbose --decrypt --list-only --dry-run --batch --no-use-agent --logger-fd 1 \"" . filename . "\""
+  let commandline = s:GPGCommand . " --verbose --decrypt --list-only --dry-run --batch --no-use-agent --logger-fd 1 " . shellescape(filename)
   call s:GPGDebug(3, "command: " . commandline)
   let &shellredir = s:shellredir
   let &shell = s:shell
+  let &shelltemp = s:shelltemp
   let output = system(commandline)
   let &shellredir = s:shellredirsave
   let &shell = s:shellsave
+  let &shelltemp = s:shelltempsave
   call s:GPGDebug(3, "output: ". output)
 
   " check if the file is symmetric/asymmetric encrypted
@@ -379,7 +407,7 @@ function s:GPGDecrypt()
     echohl GPGWarning
     echom "File is not encrypted, all GPG functions disabled!"
     echohl None
-    set nobin
+    silent exe '.r ' . fnameescape(filename)
     call s:GPGDebug(3, "<<<<<<<< Leaving s:GPGDecrypt()")
     return
   endif
@@ -394,37 +422,39 @@ function s:GPGDecrypt()
   " since even with the --quiet option passphrase typos will be reported,
   " we must redirect stderr (using shell temporarily)
   call s:GPGDebug(1, "decrypting file")
-  let commandline = "'[,']!" . s:GPGCommand . " --quiet --decrypt " . s:stderrredirnull
+  let commandline = "r !" . s:GPGCommand . ' --quiet --decrypt ' . shellescape(filename, 1) . ' ' . s:stderrredirnull
   call s:GPGDebug(1, "command: " . commandline)
   let &shellredir = s:shellredir
   let &shell = s:shell
+  let &shelltemp = s:shelltemp
   execute commandline
   let &shellredir = s:shellredirsave
   let &shell = s:shellsave
+  let &shelltemp = s:shelltempsave
   if (v:shell_error) " message could not be decrypted
-    silent u
     echohl GPGError
     let blackhole = input("Message could not be decrypted! (Press ENTER)")
     echohl None
-    bwipeout
-    set nobin
+    silent bwipeout!
     call s:GPGDebug(3, "<<<<<<<< Leaving s:GPGDecrypt()")
     return
   endif
 
-  " turn off binary mode
-  set nobin
-
-  " call the autocommand for the file minus .gpg$
-  execute ":doautocmd BufReadPost " . escape(expand("%:r"), ' *?\"'."'")
-  call s:GPGDebug(2, "called autocommand for " . escape(expand("%:r"), ' *?\"'."'"))
-
   " refresh screen
   redraw!
 
   call s:GPGDebug(3, "<<<<<<<< Leaving s:GPGDecrypt()")
 endfunction
 
+function s:GPGBufReadPost()
+  call s:GPGDebug(3, ">>>>>>>> Entering s:GPGBufReadPost()")
+  silent 1delete
+  " call the autocommand for the file minus .gpg$
+  execute ':doautocmd BufReadPost ' . fnameescape(expand('<afile>:r'))
+  call s:GPGDebug(2, 'called autocommand for ' . fnameescape(expand('<afile>:r')))
+  call s:GPGDebug(3, "<<<<<<<< Leaving s:GPGBufReadPost()")
+endfunction
+
 " Function: s:GPGEncrypt() {{{2
 "
 " encrypts the buffer to all previous recipients
@@ -432,10 +462,6 @@ endfunction
 function s:GPGEncrypt()
   call s:GPGDebug(3, ">>>>>>>> Entering s:GPGEncrypt()")
 
-  " save window view
-  let s:GPGWindowView = winsaveview()
-  call s:GPGDebug(2, "saved window view " . string(s:GPGWindowView))
-
   " store encoding and switch to a safe one
   if (&fileencoding != &encoding)
     let s:GPGEncoding = &encoding
@@ -446,13 +472,10 @@ function s:GPGEncrypt()
     call s:GPGDebug(2, "encoding and fileencoding are the same (\"" . &encoding . "\"), not switching")
   endif
 
-  " switch buffer to binary mode
-  set bin
-
   " guard for unencrypted files
-  if (!exists("b:GPGEncrypted") || b:GPGEncrypted == 0)
+  if (exists("b:GPGEncrypted") && b:GPGEncrypted == 0)
     echohl GPGError
-    let blackhole = input("Message could not be encrypted! File might be empty! (Press ENTER)")
+    let blackhole = input("Message could not be encrypted! (Press ENTER)")
     echohl None
     call s:GPGDebug(3, "<<<<<<<< Leaving s:GPGEncrypt()")
     return
@@ -482,6 +505,10 @@ function s:GPGEncrypt()
     let options = options . " --" . option . " "
   endfor
 
+  if (!exists('b:GPGRecipients'))
+    let b:GPGRecipients = []
+  endif
+
   " check here again if all recipients are available in the keyring
   let [ recipients, unknownrecipients ] = s:GPGCheckRecipients(b:GPGRecipients)
 
@@ -501,57 +528,19 @@ function s:GPGEncrypt()
     for gpgid in recipients
       let options = options . " -r " . gpgid
     endfor
-  else
-    if (match(b:GPGOptions, "encrypt") >= 0)
-      echohl GPGError
-      echom "There are no recipients!!"
-      echom "Please use GPGEditRecipients to correct!!"
-      echo
-      echohl None
-    endif
   endif
 
   " encrypt the buffer
-  let commandline = "'[,']!" . s:GPGCommand . " --quiet --no-encrypt-to " . options . " " . s:stderrredirnull
+  let destfile = tempname()
+  let commandline = "'[,']w !" . s:GPGCommand . ' --quiet --no-encrypt-to ' . options . '>' . shellescape(destfile, 1) . ' ' . s:stderrredirnull
   call s:GPGDebug(1, "command: " . commandline)
   let &shellredir = s:shellredir
   let &shell = s:shell
+  let &shelltemp = s:shelltemp
   silent execute commandline
   let &shellredir = s:shellredirsave
   let &shell = s:shellsave
-  if (v:shell_error) " message could not be encrypted
-    " delete content of the buffer to be sure no data is written unencrypted
-    " content will be recovered in GPGEncryptPost()
-    silent normal! 1GdG
-
-    echohl GPGError
-    let blackhole = input("Message could not be encrypted! File might be empty! (Press ENTER)")
-    echohl None
-    call s:GPGDebug(3, "<<<<<<<< Leaving s:GPGEncrypt()")
-    return
-  endif
-
-  call s:GPGDebug(3, "<<<<<<<< Leaving s:GPGEncrypt()")
-endfunction
-
-" Function: s:GPGEncryptPost() {{{2
-"
-" undo changes don by encrypt, after writing
-"
-function s:GPGEncryptPost()
-  call s:GPGDebug(3, ">>>>>>>> Entering s:GPGEncryptPost()")
-
-  " guard for unencrypted files
-  if (exists("b:GPGEncrypted") && b:GPGEncrypted == 0)
-    call s:GPGDebug(3, "<<<<<<<< Leaving s:GPGEncryptPost()")
-    return
-  endif
-
-  " undo encryption of buffer content
-  silent u
-
-  " switch back from binary mode
-  set nobin
+  let &shelltemp = s:shelltempsave
 
   " restore encoding
   if (s:GPGEncoding != "")
@@ -559,14 +548,19 @@ function s:GPGEncryptPost()
     call s:GPGDebug(2, "restored encoding \"" . &encoding . "\"")
   endif
 
-  " restore window view
-  call winrestview(s:GPGWindowView)
-  call s:GPGDebug(2, "restored window view" . string(s:GPGWindowView))
-
-  " refresh screen
-  redraw!
+  if (v:shell_error) " message could not be encrypted
+    " Command failed, so clean up the tempfile
+    call delete(destfile)
+    echohl GPGError
+    let blackhole = input("Message could not be encrypted! (Press ENTER)")
+    echohl None
+    call s:GPGDebug(3, "<<<<<<<< Leaving s:GPGEncrypt()")
+    return
+  endif
 
-  call s:GPGDebug(3, "<<<<<<<< Leaving s:GPGEncryptPost()")
+  call rename(destfile, expand('<afile>'))
+  setl nomodified
+  call s:GPGDebug(3, "<<<<<<<< Leaving s:GPGEncrypt()")
 endfunction
 
 " Function: s:GPGViewRecipients() {{{2
@@ -638,7 +632,7 @@ function s:GPGEditRecipients()
     " check if this buffer exists
     if (!bufexists(editbuffername))
       " create scratch buffer
-      execute 'silent! split ' . escape(editbuffername, ' *?\"'."'")
+      execute 'silent! split ' . fnameescape(editbuffername)
 
       " add a autocommand to regenerate the recipients after a write
       autocmd BufHidden,BufUnload,BufWriteCmd <buffer> call s:GPGFinishRecipientsBuffer()
@@ -648,14 +642,14 @@ function s:GPGEditRecipients()
         execute 'silent! ' . bufwinnr(editbuffername) . "wincmd w"
       else
         " split scratch buffer window
-        execute 'silent! sbuffer ' . escape(editbuffername, ' *?\"'."'")
+        execute 'silent! sbuffer ' . fnameescape(editbuffername)
 
         " add a autocommand to regenerate the recipients after a write
         autocmd BufHidden,BufUnload,BufWriteCmd <buffer> call s:GPGFinishRecipientsBuffer()
       endif
 
       " empty the buffer
-      silent normal! 1GdG
+      silent %delete
     endif
 
     " Mark the buffer as a scratch buffer
@@ -702,7 +696,7 @@ function s:GPGEditRecipients()
     let syntaxPattern = "\\(nonexxistinwordinthisbuffer"
     for name in unknownrecipients
       let name = "!" . name
-      let syntaxPattern = syntaxPattern . "\\|" . name
+      let syntaxPattern = syntaxPattern . "\\|" . fnameescape(name)
       silent put =name
     endfor
     let syntaxPattern = syntaxPattern . "\\)"
@@ -720,10 +714,10 @@ function s:GPGEditRecipients()
     endif
 
     " delete the empty first line
-    silent normal! 1Gdd
+    silent 1delete
 
     " jump to the first recipient
-    silent normal! G
+    silent $
 
   endif
 
@@ -802,7 +796,7 @@ function s:GPGFinishRecipientsBuffer()
   endif
 
   " reset modified flag
-  set nomodified
+  setl nomodified
 
   call s:GPGDebug(3, "<<<<<<<< Leaving s:GPGFinishRecipientsBuffer()")
 endfunction
@@ -860,7 +854,7 @@ function s:GPGEditOptions()
     " check if this buffer exists
     if (!bufexists(editbuffername))
       " create scratch buffer
-      execute 'silent! split ' . escape(editbuffername, ' *?\"'."'")
+      execute 'silent! split ' . fnameescape(editbuffername)
 
       " add a autocommand to regenerate the options after a write
       autocmd BufHidden,BufUnload,BufWriteCmd <buffer> call s:GPGFinishOptionsBuffer()
@@ -870,14 +864,14 @@ function s:GPGEditOptions()
         execute 'silent! ' . bufwinnr(editbuffername) . "wincmd w"
       else
         " split scratch buffer window
-        execute 'silent! sbuffer ' . escape(editbuffername, ' *?\"'."'")
+        execute 'silent! sbuffer ' . fnameescape(editbuffername)
 
         " add a autocommand to regenerate the options after a write
         autocmd BufHidden,BufUnload,BufWriteCmd <buffer> call s:GPGFinishOptionsBuffer()
       endif
 
       " empty the buffer
-      silent normal! 1GdG
+      silent %delete
     endif
 
     " Mark the buffer as a scratch buffer
@@ -909,10 +903,10 @@ function s:GPGEditOptions()
     endfor
 
     " delete the empty first line
-    silent normal! 1Gdd
+    silent 1delete
 
     " jump to the first option
-    silent normal! G
+    silent $
 
     " define highlight
     if (has("syntax") && exists("g:syntax_on"))
@@ -975,7 +969,7 @@ function s:GPGFinishOptionsBuffer()
   call setbufvar(b:GPGCorrespondingTo, "&mod", 1)
 
   " reset modified flag
-  set nomodified
+  setl nomodified
 
   call s:GPGDebug(3, "<<<<<<<< Leaving s:GPGFinishOptionsBuffer()")
 endfunction
@@ -1025,7 +1019,7 @@ function s:GPGNameToID(name)
   call s:GPGDebug(3, ">>>>>>>> Entering s:GPGNameToID()")
 
   " ask gpg for the id for a name
-  let commandline = s:GPGCommand . " --quiet --with-colons --fixed-list-mode --list-keys \"" . a:name . "\""
+  let commandline = s:GPGCommand . " --quiet --with-colons --fixed-list-mode --list-keys " . shellescape(a:name)
   call s:GPGDebug(2, "command: ". commandline)
   let &shellredir = s:shellredir
   let &shell = s:shell
@@ -1045,30 +1039,37 @@ function s:GPGNameToID(name)
   let pubseen = 0
   let counter = 0
   let gpgids = []
+  let duplicates = {}
   let choices = "The name \"" . a:name . "\" is ambiguous. Please select the correct key:\n"
   for line in lines
-    let fields = split(line, ":")
-    " search for the next uid
-    if (pubseen == 1)
-      if (fields[0] == "uid")
-        let choices = choices . "   " . fields[9] . "\n"
-      else
-        let pubseen = 0
-      endif
-    endif
 
-    " search for the next pub
-    if (pubseen == 0)
-      if (fields[0] == "pub")
-        let identity = fields[4]
-        let gpgids += [identity]
-        if exists("*strftime")
-          let choices = choices . counter . ": ID: 0x" . identity . " created at " . strftime("%c", fields[5]) . "\n"
+    " check if this line has already been processed
+    if !has_key(duplicates, line)
+      let duplicates[line] = 1
+
+      let fields = split(line, ":")
+      " search for the next uid
+      if (pubseen == 1)
+        if (fields[0] == "uid")
+          let choices = choices . "   " . fields[9] . "\n"
         else
-          let choices = choices . counter . ": ID: 0x" . identity . "\n"
+          let pubseen = 0
+        endif
+      endif
+
+      " search for the next pub
+      if (pubseen == 0)
+        if (fields[0] == "pub")
+          let identity = fields[4]
+          let gpgids += [identity]
+          if exists("*strftime")
+            let choices = choices . counter . ": ID: 0x" . identity . " created at " . strftime("%c", fields[5]) . "\n"
+          else
+            let choices = choices . counter . ": ID: 0x" . identity . "\n"
+          endif
+          let counter = counter+1
+          let pubseen = 1
         endif
-        let counter = counter+1
-        let pubseen = 1
       endif
     endif
 
@@ -1084,7 +1085,7 @@ function s:GPGNameToID(name)
     endwhile
   endif
 
-  call s:GPGDebug(3, "<<<<<<<< Leaving s:GPGIDToName()")
+  call s:GPGDebug(3, "<<<<<<<< Leaving s:GPGNameToID()")
   return get(gpgids, answer, "")
 endfunction
 

-- 
vim-scripts packaging



More information about the pkg-vim-maintainers mailing list