]> code.delx.au - gnu-emacs/blobdiff - lisp/epa-file.el
* mh-e.texi (VERSION, EDITION, UPDATED, UPDATE-MONTH): Update for
[gnu-emacs] / lisp / epa-file.el
index 24480ce3c76f47933af60ee6a271b2954f6fd6de..5de768b426e363fffcfb305aa9ae1df71a8550ed 100644 (file)
@@ -1,5 +1,5 @@
-;;; epa-file.el --- the EasyPG Assistant, transparent file encryption
-;; Copyright (C) 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+;;; epa-file.el --- the EasyPG Assistant, transparent file encryption -*- lexical-binding: t -*-
+;; Copyright (C) 2006-2013 Free Software Foundation, Inc.
 
 ;; Author: Daiki Ueno <ueno@unixuser.org>
 ;; Keywords: PGP, GnuPG
@@ -36,8 +36,15 @@ way."
   :group 'epa-file)
 
 (defcustom epa-file-select-keys nil
-  "If non-nil, always asks user to select recipients."
-  :type 'boolean
+  "Control whether or not to pop up the key selection dialog.
+
+If t, always asks user to select recipients.
+If nil, query user only when `epa-file-encrypt-to' is not set.
+If neither t nor nil, doesn't ask user.  In this case, symmetric
+encryption is used."
+  :type '(choice (const :tag "Ask always" t)
+                (const :tag "Ask when recipients are not set" nil)
+                (const :tag "Don't ask" silent))
   :group 'epa-file)
 
 (defvar epa-file-passphrase-alist nil)
@@ -67,10 +74,11 @@ way."
                        (cons entry
                              epa-file-passphrase-alist)))
                (setq passphrase (epa-passphrase-callback-function context
-                                                                  key-id nil))
+                                                                  key-id
+                                                                  file))
                (setcdr entry (copy-sequence passphrase))
                passphrase))))
-    (epa-passphrase-callback-function context key-id nil)))
+    (epa-passphrase-callback-function context key-id file)))
 
 ;;;###autoload
 (defun epa-file-handler (operation &rest args)
@@ -129,8 +137,10 @@ way."
      context
      (cons #'epa-file-passphrase-callback-function
           local-file))
-    (epg-context-set-progress-callback context
-                                      #'epa-progress-callback-function)
+    (epg-context-set-progress-callback
+     context
+     (cons #'epa-progress-callback-function
+          (format "Decrypting %s" file)))
     (unwind-protect
        (progn
          (if replace
@@ -158,12 +168,17 @@ way."
          (if (or beg end)
              (setq string (substring string (or beg 0) end)))
          (save-excursion
-           (save-restriction
-             (narrow-to-region (point) (point))
-             (epa-file-decode-and-insert string file visit beg end replace)
-             (setq length (- (point-max) (point-min))))
-           (if replace
-               (delete-region (point) (point-max)))
+           ;; If visiting, bind off buffer-file-name so that
+           ;; file-locking will not ask whether we should
+           ;; really edit the buffer.
+           (let ((buffer-file-name
+                  (if visit nil buffer-file-name)))
+             (save-restriction
+               (narrow-to-region (point) (point))
+               (epa-file-decode-and-insert string file visit beg end replace)
+               (setq length (- (point-max) (point-min))))
+             (if replace
+                 (delete-region (point) (point-max))))
            (if visit
                (set-visited-file-modtime))))
       (if (and local-copy
@@ -198,8 +213,10 @@ way."
      context
      (cons #'epa-file-passphrase-callback-function
           file))
-    (epg-context-set-progress-callback context
-                                      #'epa-progress-callback-function)
+    (epg-context-set-progress-callback
+     context
+     (cons #'epa-progress-callback-function
+          (format "Encrypting %s" file)))
     (epg-context-set-armor context epa-armor)
     (condition-case error
        (setq string
@@ -212,12 +229,13 @@ way."
                         end (point-max)))
                 (epa-file--encode-coding-string (buffer-substring start end)
                                                 coding-system))
-              (if (or epa-file-select-keys
-                      (not (local-variable-p 'epa-file-encrypt-to
-                                             (current-buffer))))
+              (if (or (eq epa-file-select-keys t)
+                      (and (null epa-file-select-keys)
+                           (not (local-variable-p 'epa-file-encrypt-to
+                                                  (current-buffer)))))
                   (epa-select-keys
                    context
-                   "Select recipents for encryption.
+                   "Select recipients for encryption.
 If no one is selected, symmetric encryption will be performed.  "
                    recipients)
                 (if epa-file-encrypt-to
@@ -255,7 +273,7 @@ If no one is selected, symmetric encryption will be performed.  "
           (epg-sub-key-id (car (epg-key-sub-key-list key))))
        (epa-select-keys
         (epg-make-context)
-        "Select recipents for encryption.
+        "Select recipients for encryption.
 If no one is selected, symmetric encryption will be performed.  "))))
 
 ;;;###autoload
@@ -284,5 +302,4 @@ If no one is selected, symmetric encryption will be performed.  "))))
 
 (provide 'epa-file)
 
-;; arch-tag: 5715152f-0eb1-4dbc-9008-07098775314d
 ;;; epa-file.el ends here