Added missing (interactive).
[elisp/epg.git] / epa.el
diff --git a/epa.el b/epa.el
index 2af91fc..ca47d02 100644 (file)
--- a/epa.el
+++ b/epa.el
@@ -743,12 +743,18 @@ Don't use this command in Lisp programs!"
       (message "Decrypting...")
       (setq plain (epg-decrypt-string context (buffer-substring start end)))
       (message "Decrypting...done")
-      (delete-region start end)
-      (goto-char start)
-      (insert (epa--decode-coding-string plain
-                                        (or coding-system-for-read
-                                            (get-text-property
-                                             start 'epa-coding-system-used))))
+      (setq plain (epa--decode-coding-string
+                  plain
+                  (or coding-system-for-read
+                      (get-text-property start 'epa-coding-system-used))))
+      (if (y-or-n-p "Replace the text in the region? ")
+         (let ((inhibit-read-only t)
+               buffer-read-only)
+           (delete-region start end)
+           (goto-char start)
+           (insert plain))
+       (let ((epa-popup-info-window t))
+         (epa-display-info plain)))
       (if (epg-context-result-for context 'verify)
          (epa-display-info (epg-verify-result-to-string
                             (epg-context-result-for context 'verify)))))))
@@ -843,6 +849,7 @@ Don't use this command in Lisp programs!"
   "Verify OpenPGP cleartext signed messages in the current buffer.
 
 Don't use this command in Lisp programs!"
+  (interactive)
   (epa-verify-cleartext-in-region (point-min) (point-max)))
 
 ;;;###autoload
@@ -905,7 +912,7 @@ If no one is selected, default secret key is used.  "
 
 Don't use this command in Lisp programs!"
   (interactive
-   (progn
+   (save-excursion
      (goto-char (point-min))
      (if (and (or (eq major-mode 'mail-mode)
                  (eq (derived-mode-class major-mode) 'mail-mode))
@@ -976,45 +983,47 @@ If no one is selected, symmetric encryption will be performed.  "))))
 
 Don't use this command in Lisp programs!"
   (interactive
-   (let (recipients)
-     (goto-char (point-min))
-     (when (or (eq major-mode 'mail-mode)
-              (eq (derived-mode-class major-mode) 'mail-mode))
-       (save-restriction
-        (narrow-to-region (point)
-                          (progn
-                            (search-forward mail-header-separator nil 0)
-                            (match-beginning 0)))
-        (setq recipients
-              (mail-strip-quoted-names
-               (mapconcat #'identity
-                          (nconc (mail-fetch-field "to" nil nil t)
-                                 (mail-fetch-field "cc" nil nil t)
-                                 (mail-fetch-field "bcc" nil nil t))
-                          ","))))
-       (if recipients
-          (setq recipients (delete "" (split-string recipients "[ \t\n]+"))))
+   (save-excursion
+     (let (recipients)
        (goto-char (point-min))
-       (if (search-forward mail-header-separator nil t)
-          (forward-line)))
-     (setq epa-last-coding-system-specified
-          (or coding-system-for-write
-              (epa--select-safe-coding-system (point) (point-max))))
-     (list (point) (point-max)
-          (if current-prefix-arg
-              (epa-select-keys
-               (epg-make-context epa-protocol)
-               "Select recipients for encryption.
+       (when (or (eq major-mode 'mail-mode)
+                (eq (derived-mode-class major-mode) 'mail-mode))
+        (save-restriction
+          (narrow-to-region (point)
+                            (progn
+                              (search-forward mail-header-separator nil 0)
+                              (match-beginning 0)))
+          (setq recipients
+                (mail-strip-quoted-names
+                 (mapconcat #'identity
+                            (nconc (mail-fetch-field "to" nil nil t)
+                                   (mail-fetch-field "cc" nil nil t)
+                                   (mail-fetch-field "bcc" nil nil t))
+                            ","))))
+        (if recipients
+            (setq recipients (delete "" (split-string recipients "[ \t\n]+"))))
+        (goto-char (point-min))
+        (if (search-forward mail-header-separator nil t)
+            (forward-line)))
+       (setq epa-last-coding-system-specified
+            (or coding-system-for-write
+                (epa--select-safe-coding-system (point) (point-max))))
+       (list (point) (point-max)
+            (if current-prefix-arg
+                (epa-select-keys
+                 (epg-make-context epa-protocol)
+                 "Select recipients for encryption.
 If no one is selected, symmetric encryption will be performed.  "
-               recipients)
-            (if recipients
-                (delq nil
-                      (apply #'nconc
-                             (mapcar
-                              (lambda (recipient)
-                                (epg-list-keys (epg-make-context epa-protocol)
-                                               (concat "<" recipient ">")))
-                              recipients))))))))
+                 recipients)
+              (if recipients
+                  (delq nil
+                        (apply #'nconc
+                               (mapcar
+                                (lambda (recipient)
+                                  (epg-list-keys
+                                   (epg-make-context epa-protocol)
+                                   (concat "<" recipient ">")))
+                                recipients)))))))))
   (epa-encrypt-region start end recipients))
 
 ;;;###autoload
@@ -1074,6 +1083,37 @@ Don't use this command in Lisp programs!"
                           (epg-context-result-for context 'import))))))
 
 ;;;###autoload
+(defun epa-import-armor-in-region (start end)
+  "Import keys in the OpenPGP armor format in the current region
+between START and END.
+
+Don't use this command in Lisp programs!"
+  (interactive "r")
+  (save-excursion
+    (save-restriction
+      (narrow-to-region start end)
+      (goto-char start)
+      (let (armor-start armor-end)
+       (while (re-search-forward
+               "-----BEGIN \\(PGP \\(PUBLIC\\|PRIVATE\\) KEY BLOCK\\)-----$"
+               nil t)
+         (setq armor-start (match-beginning 0)
+               armor-end (re-search-forward
+                          (concat "^-----END " (match-string 1) "-----$")
+                          nil t))
+         (unless armor-end
+           (error "No armor tail"))
+         (epa-import-keys-region armor-start armor-end))))))
+
+;;;###autoload
+(defun epa-import ()
+  "Import keys in the OpenPGP armor format in the current buffer.
+
+Don't use this command in Lisp programs!"
+  (interactive)
+  (epa-import-armor-in-region (point-min) (point-max)))
+
+;;;###autoload
 (defun epa-export-keys (keys file)
   "Export selected KEYS to FILE.