* EasyPG: Version 0.0.12 released.
[elisp/epg.git] / epa-file.el
index 7c75f7c..898a4e9 100644 (file)
@@ -55,6 +55,11 @@ does that automatically."
   :type 'boolean
   :group 'epa-file)
 
+(defcustom epa-file-select-keys nil
+  "If non-nil, always asks user to select recipients."
+  :type 'boolean
+  :group 'epa-file)
+
 (defvar epa-file-encrypt-to nil
   "*Recipient(s) used for encrypting files.
 May either be a string or a list of strings.")
@@ -79,13 +84,15 @@ May either be a string or a list of strings.")
 
 (defvar epa-file-passphrase-alist nil)
 
-(if (fboundp 'encode-coding-string)
-    (defalias 'epa-file--encode-coding-string 'encode-coding-string)
-  (defalias 'epa-file--encode-coding-string 'identity))
+(eval-and-compile
+  (if (fboundp 'encode-coding-string)
+      (defalias 'epa-file--encode-coding-string 'encode-coding-string)
+    (defalias 'epa-file--encode-coding-string 'identity)))
 
-(if (fboundp 'decode-coding-string)
-    (defalias 'epa-file--decode-coding-string 'decode-coding-string)
-  (defalias 'epa-file--decode-coding-string 'identity))
+(eval-and-compile
+  (if (fboundp 'decode-coding-string)
+      (defalias 'epa-file--decode-coding-string 'decode-coding-string)
+    (defalias 'epa-file--decode-coding-string 'identity)))
 
 (defun epa-file-name-regexp-update ()
   (interactive)
@@ -213,6 +220,8 @@ May either be a string or a list of strings.")
           file))
     (epg-context-set-progress-callback context
                                       #'epa-progress-callback-function)
+    (epg-context-set-armor context epa-armor)
+    (epg-context-set-textmode context epa-textmode)
     (condition-case error
        (setq string
              (epg-encrypt-string
@@ -221,14 +230,15 @@ May either be a string or a list of strings.")
                   (epa-file--encode-coding-string start coding-system)
                 (epa-file--encode-coding-string (buffer-substring start end)
                                                 coding-system))
-              (if (local-variable-p 'epa-file-encrypt-to)
-                  (if epa-file-encrypt-to
-                      (epg-list-keys context recipients))
-                (epa-select-keys
-                 context
-                 "Select recipents for encryption.
+              (if (or epa-file-select-keys
+                      (not (local-variable-p 'epa-file-encrypt-to)))
+                  (epa-select-keys
+                   context
+                   "Select recipents for encryption.
 If no one is selected, symmetric encryption will be performed.  "
-                 recipients))))
+                   recipients)
+                (if epa-file-encrypt-to
+                    (epg-list-keys context recipients)))))
       (error
        (if (setq entry (assoc file epa-file-passphrase-alist))
           (setcdr entry nil))
@@ -258,6 +268,16 @@ If no one is selected, symmetric encryption will be performed.  "
           epa-file-inhibit-auto-save)
       (auto-save-mode 0)))
 
+(defun epa-file-select-keys ()
+  "Select recipients for encryption."
+  (interactive)
+  (make-local-variable 'epa-file-encrypt-to)
+  (setq epa-file-encrypt-to
+       (epa-select-keys
+        (epg-make-context)
+        "Select recipents for encryption.
+If no one is selected, symmetric encryption will be performed.  ")))
+
 ;;;###autoload
 (defun epa-file-enable ()
   (interactive)