2007-08-02 Adrian Aichner <adrian@xemacs.org>
[elisp/epg.git] / epa-file.el
index f3bbaee..a6a800e 100644 (file)
@@ -152,15 +152,19 @@ May either be a string or a list of strings.")
   (if (and visit (or beg end))
       (error "Attempt to visit less than an entire file"))
   (setq file (expand-file-name file))
-  (let ((local-copy (epa-file-run-real-handler #'file-local-copy (list file)))
-       (context (epg-make-context))
-       string length entry)
+  (let* ((local-copy
+         (condition-case inl
+             (epa-file-run-real-handler #'file-local-copy (list file))
+           (error)))
+        (local-file (or local-copy file))
+        (context (epg-make-context))
+        string length entry)
     (if visit
        (setq buffer-file-name file))
     (epg-context-set-passphrase-callback
      context
      (cons #'epa-file-passphrase-callback-function
-          file))
+          local-file))
     (epg-context-set-progress-callback context
                                       #'epa-progress-callback-function)
     (unwind-protect
@@ -168,7 +172,7 @@ May either be a string or a list of strings.")
          (if replace
              (goto-char (point-min)))
          (condition-case error
-             (setq string (epg-decrypt-file context file nil))
+             (setq string (epg-decrypt-file context local-file nil))
            (error
             (if (setq entry (assoc file epa-file-passphrase-alist))
                 (setcdr entry nil))
@@ -220,6 +224,7 @@ 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)
     (condition-case error
        (setq string
              (epg-encrypt-string
@@ -229,7 +234,8 @@ May either be a string or a list of strings.")
                 (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)))
+                      (not (local-variable-p 'epa-file-encrypt-to
+                                             (current-buffer))))
                   (epa-select-keys
                    context
                    "Select recipents for encryption.
@@ -264,7 +270,8 @@ If no one is selected, symmetric encryption will be performed.  "
   (if (and buffer-file-name
           (string-match epa-file-name-regexp buffer-file-name)
           epa-file-inhibit-auto-save)
-      (auto-save-mode 0)))
+      (auto-save-mode 0))
+  (set-buffer-modified-p nil))
 
 (defun epa-file-select-keys ()
   "Select recipients for encryption."