Fixed.
[elisp/epg.git] / epa.el
diff --git a/epa.el b/epa.el
index 66e0d3a..2e5811e 100644 (file)
--- a/epa.el
+++ b/epa.el
@@ -186,7 +186,7 @@ the separate window."
     (define-key keymap "r" 'epa-delete-keys)
     (define-key keymap "i" 'epa-import-keys)
     (define-key keymap "o" 'epa-export-keys)
-    (define-key keymap "g" 'epa-list-keys)
+    (define-key keymap "g" 'revert-buffer)
     (define-key keymap "n" 'next-line)
     (define-key keymap "p" 'previous-line)
     (define-key keymap " " 'scroll-up)
@@ -269,6 +269,8 @@ the separate window."
   ;; if buffer-file-name is not set.
   (font-lock-set-defaults)
   (make-local-variable 'epa-exit-buffer-function)
+  (make-local-variable 'revert-buffer-function)
+  (setq revert-buffer-function 'epa--revert-buffer)
   (run-hooks 'epa-key-list-mode-hook))
 
 (defun epa-key-mode ()
@@ -330,43 +332,6 @@ If ARG is non-nil, mark the current line."
   (interactive)
   (funcall epa-exit-buffer-function))
 
-;;;###autoload
-(defun epa-list-keys (&optional name mode)
-  "List all keys matched with NAME from the keyring.
-If MODE is non-nil, it reads the private keyring.  Otherwise, it
-reads the public keyring."
-  (interactive
-   (if current-prefix-arg
-       (let ((name (read-string "Pattern: "
-                               (if epa-list-keys-arguments
-                                   (car epa-list-keys-arguments)))))
-        (list (if (equal name "") nil name)
-              (y-or-n-p "Secret keys? ")))
-     (or epa-list-keys-arguments (list nil nil))))
-  (unless (and epa-keys-buffer
-              (buffer-live-p epa-keys-buffer))
-    (setq epa-keys-buffer (generate-new-buffer "*Keys*")))
-  (set-buffer epa-keys-buffer)
-  (epa-key-list-mode)
-  (let ((inhibit-read-only t)
-       buffer-read-only
-       (point (point-min))
-       (context (epg-make-context epa-protocol)))
-    (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--insert-keys context name 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))
-  (goto-char (point-min))
-  (pop-to-buffer (current-buffer)))
-
 (defun epa--insert-keys (context name mode)
   (save-excursion
     (save-restriction
@@ -392,6 +357,58 @@ reads the public keyring."
                                 'start-open t
                                 'end-open t)))))
 
+(defun epa--list-keys (name secret)
+  (unless (and epa-keys-buffer
+              (buffer-live-p epa-keys-buffer))
+    (setq epa-keys-buffer (generate-new-buffer "*Keys*")))
+  (set-buffer epa-keys-buffer)
+  (epa-key-list-mode)
+  (let ((inhibit-read-only t)
+       buffer-read-only
+       (point (point-min))
+       (context (epg-make-context epa-protocol)))
+    (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--insert-keys context name secret)
+    (widget-setup)
+    (set-keymap-parent (current-local-map) widget-keymap))
+  (make-local-variable 'epa-list-keys-arguments)
+  (setq epa-list-keys-arguments (list name secret))
+  (goto-char (point-min))
+  (pop-to-buffer (current-buffer)))
+
+;;;###autoload
+(defun epa-list-keys (&optional name)
+  "List all keys matched with NAME from the public keyring."
+  (interactive
+   (if current-prefix-arg
+       (let ((name (read-string "Pattern: "
+                               (if epa-list-keys-arguments
+                                   (car epa-list-keys-arguments)))))
+        (list (if (equal name "") nil name)))
+     (list nil)))
+  (epa--list-keys name nil))
+
+;;;###autoload
+(defun epa-list-secret-keys (&optional name)
+  "List all keys matched with NAME from the private keyring."
+  (interactive
+   (if current-prefix-arg
+       (let ((name (read-string "Pattern: "
+                               (if epa-list-keys-arguments
+                                   (car epa-list-keys-arguments)))))
+        (list (if (equal name "") nil name)))
+     (list nil)))
+  (epa--list-keys name t))
+
+(defun epa--revert-buffer (&optional ignore-auto noconfirm)
+  (apply #'epa--list-keys epa-list-keys-arguments))
+
 (defun epa--marked-keys ()
   (or (save-excursion
        (set-buffer epa-keys-buffer)
@@ -442,19 +459,7 @@ If SECRET is non-nil, list secret keys instead of public keys."
                      "Click here or \\[exit-recursive-edit] to finish")
                     "OK")
       (insert "\n\n")
-      (if names
-         (while names
-           (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)
-             (if (get-text-property (point) 'epa-list-keys)
-                 (epa-mark)))
-         (epa--insert-keys context nil nil)))
+      (epa--insert-keys context names secret)
       (widget-setup)
       (set-keymap-parent (current-local-map) widget-keymap)
       (setq epa-exit-buffer-function #'abort-recursive-edit)