* epa.el (epa-list-keys-1): Add 'epa-list-keys property to keylist
[elisp/epg.git] / epa.el
diff --git a/epa.el b/epa.el
index 089aee0..043ffd6 100644 (file)
--- a/epa.el
+++ b/epa.el
     (setq epa-keys-buffer (generate-new-buffer "*Keys*")))
   (set-buffer epa-keys-buffer)
   (let ((inhibit-read-only t)
-       buffer-read-only)
-    (erase-buffer)
+       buffer-read-only
+       (point (point-min)))
+    (unless (get-text-property point 'epa-list-keys)
+      (setq point (next-single-property-change point 'epa-list-keys)))
+    (when point
+      (delete-region point
+                    (or (next-single-property-change point 'epa-list-keys)
+                        (point-max)))
+      (goto-char point))
     (epa-list-keys-1 name mode)
     (epa-keys-mode))
   (make-local-variable 'epa-list-keys-arguments)
   (pop-to-buffer (current-buffer)))
 
 (defun epa-list-keys-1 (name mode)
-  (let ((inhibit-read-only t)
-       buffer-read-only
-       (keys (epg-list-keys name mode))
-       point)
-    (while keys
-      (setq point (point))
-      (insert "  ")
-      (put-text-property point (point) 'epa-key (car keys))
-      (widget-create 'epa-key :value (car keys))
-      (insert "\n")
-      (setq keys (cdr keys)))))
+  (save-restriction
+    (narrow-to-region (point) (point))
+    (let ((inhibit-read-only t)
+         buffer-read-only
+         (keys (epg-list-keys name mode))
+         point)
+      (while keys
+       (setq point (point))
+       (insert "  ")
+       (put-text-property point (point) 'epa-key (car keys))
+       (widget-create 'epa-key :value (car keys))
+       (insert "\n")
+       (setq keys (cdr keys))))      
+    (put-text-property (point-min) (point-max) 'epa-list-keys t)))
 
 (defun epa-marked-keys ()
   (or (save-excursion
        (beginning-of-line)
        (get-text-property (point) 'epa-key))))
 
-(defun epa-select-keys (prompt &optional names)
+(defun epa-select-keys (prompt &optional names mode)
   (save-excursion
     (unless (and epa-keys-buffer
                 (buffer-live-p epa-keys-buffer))
       (erase-buffer)
       (insert prompt "\n")
       (widget-create 'link
+                    :notify (lambda (&rest ignore) (abort-recursive-edit))
+                    :help-echo
+                    (substitute-command-keys
+                     "Click here or \\[abort-recursive-edit] to cancel")
+                    "Cancel")
+      (widget-create 'link
                     :notify (lambda (&rest ignore) (exit-recursive-edit))
                     :help-echo
                     (substitute-command-keys
       (if names
          (while names
            (setq point (point))
-           (epa-list-keys-1 (car names) nil)
+           (epa-list-keys-1 (car names) mode)
            (goto-char point)
            (epa-mark)
            (goto-char (point-max))
            (setq names (cdr names)))
-       (epa-list-keys-1 nil nil))
+       (epa-list-keys-1 nil mode))
       (epa-keys-mode)
       (goto-char (point-min))
       (pop-to-buffer (current-buffer))
   (interactive "fFile: ")
   (let* ((context (epg-make-context))
         (plain (if (equal (file-name-extension file) "sig")
-                   (file-name-sans-extension file)))
-        signature)
+                   (file-name-sans-extension file))))
     (message "Verifying %s..." (file-name-nondirectory file))
     (epg-verify-file context file plain)
-    (setq signature (reverse (epg-context-result-for context 'verify)))
-    (with-output-to-temp-buffer "*epa-verify-file*"
-      (set-buffer standard-output)
-      (while signature
-       (insert (format "%s: %s %s %s\n"
-                       (epg-signature-status (car signature))
-                       (epg-signature-key-id (car signature))
-                       (epg-signature-user-id (car signature))
-                       (epg-signature-validity (car signature))))
-       (setq signature (cdr signature))))
-    (shrink-window-if-larger-than-buffer
-     (get-buffer-window "*epa-verify-file*"))
-    (message "Verifying %s...done" (file-name-nondirectory file))))
+    (message "Verifying %s...done" (file-name-nondirectory file))
+    (message "%s"
+            (epg-verify-result-to-string
+             (epg-context-result-for context 'verify)))))
 
 (defun epa-sign-file (file detached)
   (interactive
 (defun epa-encrypt-file (file recipients)
   (interactive
    (list (expand-file-name (read-file-name "File: "))
-        (mapcar (lambda (key)
-                  (epg-sub-key-id
-                   (car (epg-key-sub-key-list key))))
-                (epa-select-keys "Select recipents for encryption.
-If no one is selected, symmetric encryption will be performed.  "))))
+        (epa-select-keys "Select recipents for encryption.
+If no one is selected, symmetric encryption will be performed.  ")))
   (let ((cipher (concat file ".gpg"))
        (context (epg-make-context)))
     (message "Encrypting %s..." (file-name-nondirectory file))
-    (epg-encrypt-file context
-                     file
-                     recipients
-                     cipher)
+    (epg-encrypt-file context file recipients cipher)
     (message "Encrypting %s...done" (file-name-nondirectory file))))
 
 (defun epa-delete-keys (keys)
@@ -493,7 +493,7 @@ If no one is selected, symmetric encryption will be performed.  "))))
   (interactive "fFile: ")
   (let ((context (epg-make-context)))
     (message "Importing %s..." (file-name-nondirectory file))
-    (epg-import-keys-from-file context file)
+    (epg-import-keys-from-file context (expand-file-name file))
     (apply #'epa-list-keys epa-list-keys-arguments)
     (message "Importing %s...done" (file-name-nondirectory file))))
 
@@ -505,7 +505,7 @@ If no one is selected, symmetric encryption will be performed.  "))))
        (error "No keys selected"))
      (setq default-name
           (expand-file-name
-           (concat (epg-sub-key-id (epg-key-sub-key-list (car keys)))
+           (concat (epg-sub-key-id (car (epg-key-sub-key-list (car keys))))
                    ".gpg")
            default-directory))
      (list keys