OSDN Git Service

No need to specify --disable-gpg-test even if gpg has version < 1.4.3.
[epg/epg.git] / epa.el
diff --git a/epa.el b/epa.el
index bc9cf4f..a188e46 100644 (file)
--- a/epa.el
+++ b/epa.el
   "The EasyPG Assistant"
   :group 'epg)
 
-(defcustom epa-protocol 'OpenPGP
-  "The default protocol."
-  :type '(choice (const :tag "OpenPGP" OpenPGP)
-                (const :tag "CMS" CMS))
-  :group 'epa)
-
-(defcustom epa-armor nil
-  "If non-nil, epa commands create ASCII armored output."
-  :type 'boolean
-  :group 'epa)
-
-(defcustom epa-textmode nil
-  "If non-nil, epa commands treat input files as text."
-  :type 'boolean
-  :group 'epa)
-
 (defcustom epa-popup-info-window t
   "If non-nil, status information from epa commands is displayed on
 the separate window."
@@ -168,6 +152,22 @@ the separate window."
     (17 . ?D)
     (20 . ?G)))
 
+(defvar epa-protocol 'OpenPGP
+  "*The default protocol.
+The value can be either OpenPGP or CMS.
+
+You should bind this variable with `let', but do not set it globally.")
+
+(defvar epa-armor nil
+  "*If non-nil, epa commands create ASCII armored output.
+
+You should bind this variable with `let', but do not set it globally.")
+
+(defvar epa-textmode nil
+  "*If non-nil, epa commands treat input files as text.
+
+You should bind this variable with `let', but do not set it globally.")
+
 (defvar epa-keys-buffer nil)
 (defvar epa-key-buffer-alist nil)
 (defvar epa-key nil)
@@ -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)
@@ -196,7 +196,7 @@ the separate window."
 
 (defvar epa-key-mode-map
   (let ((keymap (make-sparse-keymap)))
-    (define-key keymap "q" 'bury-buffer)
+    (define-key keymap "q" 'epa-exit-buffer)
     keymap))
 
 (defvar epa-info-mode-map
@@ -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--key-list-revert-buffer)
   (run-hooks 'epa-key-list-mode-hook))
 
 (defun epa-key-mode ()
@@ -330,12 +332,11 @@ If ARG is non-nil, mark the current line."
   (interactive)
   (funcall epa-exit-buffer-function))
 
-(defun epa--insert-keys (context name mode)
+(defun epa--insert-keys (keys)
   (save-excursion
     (save-restriction
       (narrow-to-region (point) (point))
-      (let ((keys (epg-list-keys context name mode))
-           point)
+      (let (point)
        (while keys
          (setq point (point))
          (insert "  ")
@@ -372,11 +373,11 @@ 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 secret)
+    (epa--insert-keys (epg-list-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 mode))
+  (setq epa-list-keys-arguments (list name secret))
   (goto-char (point-min))
   (pop-to-buffer (current-buffer)))
 
@@ -389,7 +390,7 @@ If ARG is non-nil, mark the current line."
                                (if epa-list-keys-arguments
                                    (car epa-list-keys-arguments)))))
         (list (if (equal name "") nil name)))
-     (or epa-list-keys-arguments (list nil nil))))
+     (list nil)))
   (epa--list-keys name nil))
 
 ;;;###autoload
@@ -401,9 +402,12 @@ If ARG is non-nil, mark the current line."
                                (if epa-list-keys-arguments
                                    (car epa-list-keys-arguments)))))
         (list (if (equal name "") nil name)))
-     (or epa-list-keys-arguments (list nil nil))))
+     (list nil)))
   (epa--list-keys name t))
 
+(defun epa--key-list-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)
@@ -420,14 +424,7 @@ If ARG is non-nil, mark the current line."
          (if key
              (list key))))))
 
-;;;###autoload
-(defun epa-select-keys (context prompt &optional names secret)
-  "Display a user's keyring and ask him to select keys.
-CONTEXT is an epg-context.
-PROMPT is a string to prompt with.
-NAMES is a list of strings to be matched with keys.  If it is nil, all
-the keys are listed.
-If SECRET is non-nil, list secret keys instead of public keys."
+(defun epa--select-keys (prompt keys)
   (save-excursion
     (unless (and epa-keys-buffer
                 (buffer-live-p epa-keys-buffer))
@@ -454,19 +451,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 keys)
       (widget-setup)
       (set-keymap-parent (current-local-map) widget-keymap)
       (setq epa-exit-buffer-function #'abort-recursive-edit)
@@ -480,6 +465,19 @@ If SECRET is non-nil, list secret keys instead of public keys."
          (delete-window (get-buffer-window epa-keys-buffer)))
       (kill-buffer epa-keys-buffer))))
 
+;;;###autoload
+(defun epa-select-keys (context prompt &optional names secret)
+  "Display a user's keyring and ask him to select keys.
+CONTEXT is an epg-context.
+PROMPT is a string to prompt with.
+NAMES is a list of strings to be matched with keys.  If it is nil, all
+the keys are listed.
+If SECRET is non-nil, list secret keys instead of public keys."
+  (let ((keys (epg-list-keys context name secret)))
+    (if (> (length keys) 1)
+       (epa--select-keys prompt keys)
+      keys)))
+
 (defun epa--format-fingerprint-1 (fingerprint unit-size block-size)
   (let ((unit 0))
     (with-temp-buffer