Simplified prompt.
[elisp/epg.git] / epa-file.el
index a924aa7..1f939c1 100644 (file)
@@ -60,6 +60,14 @@ 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))
+
+(if (fboundp 'decode-coding-string)
+    (defalias 'epa-file--decode-coding-string 'decode-coding-string)
+  (defalias 'epa-file--decode-coding-string 'identity))
+
 (defun epa-file-passphrase-callback-function (context key-id file)
   (if (and epa-file-cache-passphrase-for-symmetric-encryption
           (eq key-id 'SYM))
@@ -104,8 +112,8 @@ May either be a string or a list of strings.")
           (point-min) (point-max)
           (substring file 0 (string-match epa-file-name-regexp file))
           visit beg end replace)))
-    (insert (decode-coding-string string (or coding-system-for-read
-                                            'undecided)))))
+    (insert (epa-file--decode-coding-string string (or coding-system-for-read
+                                                      'undecided)))))
 
 (defvar last-coding-system-used)
 (defun epa-file-insert-file-contents (file &optional visit beg end replace)
@@ -156,10 +164,9 @@ May either be a string or a list of strings.")
       (error "Can't append to the file."))
   (setq file (expand-file-name file))
   (let* ((coding-system (or coding-system-for-write
-                           (if (boundp 'last-coding-system-used)
-                               (condition-case nil
-                                   (write-region (point-min) (point-max) "/")
-                                 (error last-coding-system-used))
+                           (if (fboundp 'select-safe-coding-system)
+                               (select-safe-coding-system
+                                (point-min) (point-max))
                              buffer-file-coding-system)))
         (context (epg-make-context))
         (coding-system-for-write 'binary)
@@ -175,9 +182,9 @@ May either be a string or a list of strings.")
              (epg-encrypt-string
               context
               (if (stringp start)
-                  (encode-coding-string start coding-system)
-                (encode-coding-string (buffer-substring start end)
-                                      coding-system))
+                  (epa-file--encode-coding-string start coding-system)
+                (epa-file--encode-coding-string (buffer-substring start end)
+                                                coding-system))
               (unless (assoc file epa-file-passphrase-alist)
                 (epa-select-keys
                  context