* epg.el (epg-export-keys-to-file): Fixed a typo.
[elisp/epg.git] / epa.el
diff --git a/epa.el b/epa.el
index 9731a5f..c59706b 100644 (file)
--- a/epa.el
+++ b/epa.el
@@ -238,6 +238,14 @@ the separate window."
          (epg-sub-key-id (car (epg-key-sub-key-list
                                (widget-get widget :value))))))
 
+(if (fboundp 'encode-coding-string)
+    (defalias 'epa--encode-coding-string 'encode-coding-string)
+  (defalias 'epa--encode-coding-string 'identity))
+
+(if (fboundp 'decode-coding-string)
+    (defalias 'epa--decode-coding-string 'decode-coding-string)
+  (defalias 'epa--decode-coding-string 'identity))
+
 (defun epa-keys-mode ()
   "Major mode for `epa-list-keys'."
   (kill-all-local-variables)
@@ -247,13 +255,11 @@ the separate window."
        truncate-lines t
        buffer-read-only t)
   (use-local-map epa-keys-mode-map)
-  (set-keymap-parent (current-local-map) widget-keymap)
   (make-local-variable 'font-lock-defaults)
   (setq font-lock-defaults '(epa-font-lock-keywords t))
   ;; In XEmacs, auto-initialization of font-lock is not effective
   ;; if buffer-file-name is not set.
   (font-lock-set-defaults)
-  (widget-setup)
   (make-local-variable 'epa-exit-buffer-function)
   (run-hooks 'epa-keys-mode-hook))
 
@@ -344,14 +350,16 @@ If ARG is non-nil, mark the current line."
                     (or (next-single-property-change point 'epa-list-keys)
                         (point-max)))
       (goto-char point))
-    (epa-insert-keys context name mode)
-    (epa-keys-mode))
+    (epa--insert-keys context name mode)
+    (epa-keys-mode)
+    (widget-setup)
+    (set-keymap-parent (current-local-map) widget-keymap))
   (make-local-variable 'epa-list-keys-arguments)
   (setq epa-list-keys-arguments (list name mode protocol))
   (goto-char (point-min))
   (pop-to-buffer (current-buffer)))
 
-(defun epa-insert-keys (context name mode)
+(defun epa--insert-keys (context name mode)
   (save-excursion
     (save-restriction
       (narrow-to-region (point) (point))
@@ -424,18 +432,20 @@ If SECRET is non-nil, list secret keys instead of public keys."
       (insert "\n\n")
       (if names
          (while names
-           (epa-insert-keys context (car names) secret)
+           (epa--insert-keys context (car names) secret)
            (if (get-text-property (point) 'epa-list-keys)
                (epa-mark))
            (goto-char (point-max))
            (setq names (cdr names)))
        (if secret
            (progn
-             (epa-insert-keys context nil secret)
+             (epa--insert-keys context nil secret)
              (if (get-text-property (point) 'epa-list-keys)
                  (epa-mark)))
-         (epa-insert-keys context nil nil)))
+         (epa--insert-keys context nil nil)))
       (epa-keys-mode)
+      (widget-setup)
+      (set-keymap-parent (current-local-map) widget-keymap)
       (setq epa-exit-buffer-function #'abort-recursive-edit)
       (goto-char (point-min))
       (pop-to-buffer (current-buffer)))
@@ -582,7 +592,8 @@ If SECRET is non-nil, list secret keys instead of public keys."
                                       #'epa-progress-callback-function)
     (message "Decrypting %s..." (file-name-nondirectory file))
     (epg-decrypt-file context file plain)
-    (message "Decrypting %s...done" (file-name-nondirectory file))
+    (message "Decrypting %s...wrote %s" (file-name-nondirectory file)
+            (file-name-nondirectory plain))
     (if (epg-context-result-for context 'verify)
        (epa-display-info (epg-verify-result-to-string
                           (epg-context-result-for context 'verify))))))
@@ -612,10 +623,26 @@ If SECRET is non-nil, list secret keys instead of public keys."
         (epa-select-keys (epg-make-context) "Select keys for signing.
 If no one is selected, default secret key is used.  "
                          nil t)
-        (if (y-or-n-p "Make a detached signature? ")
-            'detached
-          (if (y-or-n-p "Make a cleartext signature? ")
-              'clear))))
+        (catch 'done
+          (while t
+            (message "Signature type (n,c,d,?) ")
+            (let ((c (read-char)))
+              (cond ((eq c ?c)
+                     (throw 'done 'clear))
+                    ((eq c ?d)
+                     (throw 'done 'detached))
+                    ((eq c ??)
+                     (with-output-to-temp-buffer "*Help*"
+                       (save-excursion
+                         (set-buffer standard-output)
+                         (insert "\
+n - Create a normal signature
+c - Create a cleartext signature
+d - Create a detached signature
+? - Show this help
+"))))
+                    (t
+                     (throw 'done nil))))))))
   (let ((signature (concat file
                           (if (or epa-armor
                                   (not (memq mode '(nil t normal detached))))
@@ -633,7 +660,8 @@ If no one is selected, default secret key is used.  "
                                       #'epa-progress-callback-function)
     (message "Signing %s..." (file-name-nondirectory file))
     (epg-sign-file context file signature mode)
-    (message "Signing %s...done" (file-name-nondirectory file))))
+    (message "Signing %s...wrote %s" (file-name-nondirectory file)
+            (file-name-nondirectory signature))))
 
 ;;;###autoload
 (defun epa-encrypt-file (file recipients)
@@ -652,7 +680,8 @@ If no one is selected, symmetric encryption will be performed.  ")))
                                       #'epa-progress-callback-function)
     (message "Encrypting %s..." (file-name-nondirectory file))
     (epg-encrypt-file context file recipients cipher)
-    (message "Encrypting %s...done" (file-name-nondirectory file))))
+    (message "Encrypting %s...wrote %s" (file-name-nondirectory file)
+            (file-name-nondirectory cipher))))
 
 ;;;###autoload
 (defun epa-decrypt-region (start end)
@@ -672,7 +701,7 @@ Don't use this command in Lisp programs!"
       (message "Decrypting...done")
       (delete-region start end)
       (goto-char start)
-      (insert (decode-coding-string plain coding-system-for-read))
+      (insert (epa--decode-coding-string plain coding-system-for-read))
       (if (epg-context-result-for context 'verify)
          (epa-display-info (epg-verify-result-to-string
                             (epg-context-result-for context 'verify)))))))
@@ -715,7 +744,7 @@ Don't use this command in Lisp programs!"
     (epg-context-set-progress-callback context
                                       #'epa-progress-callback-function)
     (epg-verify-string context
-                      (encode-coding-string
+                      (epa--encode-coding-string
                        (buffer-substring start end)
                        coding-system-for-write))
     (if (epg-context-result-for context 'verify)
@@ -757,15 +786,33 @@ Don't use this command in Lisp programs!"
         (epa-select-keys (epg-make-context) "Select keys for signing.
 If no one is selected, default secret key is used.  "
                          nil t)
-        (if (y-or-n-p "Make a detached signature? ")
-            'detached
-          (if (y-or-n-p "Make a cleartext signature? ")
-              'clear))))
+        (catch 'done
+          (while t
+            (message "Signature type (n,c,d,?) ")
+            (let ((c (read-char)))
+              (cond ((eq c ?c)
+                     (throw 'done 'clear))
+                    ((eq c ?d)
+                     (throw 'done 'detached))
+                    ((eq c ??)
+                     (with-output-to-temp-buffer "*Help*"
+                       (save-excursion
+                         (set-buffer standard-output)
+                         (insert "\
+n - Create a normal signature
+c - Create a cleartext signature
+d - Create a detached signature
+? - Show this help
+"))))
+                    (t
+                     (throw 'done nil))))))))
   (save-excursion
     (let ((context (epg-make-context))
          signature)
-      (epg-context-set-armor context epa-armor)
-      (epg-context-set-textmode context epa-textmode)
+      ;;(epg-context-set-armor context epa-armor)
+      (epg-context-set-armor context t)
+      ;;(epg-context-set-textmode context epa-textmode)
+      (epg-context-set-textmode context t)
       (epg-context-set-signers context signers)
       (epg-context-set-passphrase-callback context
                                           #'epa-passphrase-callback-function)
@@ -773,13 +820,13 @@ If no one is selected, default secret key is used.  "
                                         #'epa-progress-callback-function)
       (message "Signing...")
       (setq signature (epg-sign-string context
-                                      (encode-coding-string
+                                      (epa--encode-coding-string
                                        (buffer-substring start end)
                                        coding-system-for-write)
                                       mode))
       (message "Signing...done")
       (delete-region start end)
-      (insert (decode-coding-string signature coding-system-for-read)))))
+      (insert (epa--decode-coding-string signature coding-system-for-read)))))
 
 ;;;###autoload
 (defun epa-encrypt-region (start end recipients)
@@ -793,15 +840,17 @@ If no one is selected, symmetric encryption will be performed.  ")))
   (save-excursion
     (let ((context (epg-make-context))
          cipher)
-      (epg-context-set-armor context epa-armor)
-      (epg-context-set-textmode context epa-textmode)
+      ;;(epg-context-set-armor context epa-armor)
+      (epg-context-set-armor context t)
+      ;;(epg-context-set-textmode context epa-textmode)
+      (epg-context-set-textmode context t)
       (epg-context-set-passphrase-callback context
                                           #'epa-passphrase-callback-function)
       (epg-context-set-progress-callback context
                                         #'epa-progress-callback-function)
       (message "Encrypting...")
       (setq cipher (epg-encrypt-string context
-                                      (encode-coding-string
+                                      (epa--encode-coding-string
                                        (buffer-substring start end)
                                        coding-system-for-write)
                                       recipients))
@@ -877,6 +926,18 @@ Don't use this command in Lisp programs!"
     (message "Exporting to %s...done" (file-name-nondirectory file))))
 
 ;;;###autoload
+(defun epa-insert-keys (keys)
+  "Insert selected KEYS after the point.
+
+Don't use this command in Lisp programs!"
+  (interactive
+   (list (epa-select-keys (epg-make-context) "Select keys to export.  ")))
+  (let ((context (epg-make-context)))
+    ;;(epg-context-set-armor context epa-armor)
+    (epg-context-set-armor context t)
+    (insert (epg-export-keys-to-string context keys))))
+
+;;;###autoload
 (defun epa-sign-keys (keys &optional local)
   "Sign selected KEYS.
 If a prefix-arg is specified, the signature is marked as non exportable.