diff options
author | Aleksandr Vityazev <avityazev@disroot.org> | 2024-02-15 22:51:24 +0300 |
---|---|---|
committer | Eli Zaretskii <eliz@gnu.org> | 2024-02-17 11:27:09 +0200 |
commit | 6477be93bd8a29cba8ce383f9ea3fba23c45f225 (patch) | |
tree | 06d2f72ce65cc41ccabb70bda4491ce762a90ca8 /lisp/epa.el | |
parent | 84e4f1259b54442f52183c1ccee72a417e0a2658 (diff) | |
download | emacs-6477be93bd8a29cba8ce383f9ea3fba23c45f225.tar.gz |
Make key selection method configurable in EPA.
* lisp/epa.el (epa-keys-select-method): New defcustom.
(epa--select-keys-in-minibuffer): New function.
(epa-select-keys): Use new option and function.
* etc/NEWS: Announce it.
* doc/misc/epa.texi (Key Management): Document it.
(Bug#69133)
Diffstat (limited to 'lisp/epa.el')
-rw-r--r-- | lisp/epa.el | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/lisp/epa.el b/lisp/epa.el index 53da3bf6cce..b2593bc62ba 100644 --- a/lisp/epa.el +++ b/lisp/epa.el @@ -73,6 +73,16 @@ The command `epa-mail-encrypt' uses this." :group 'epa :version "24.4") +(defcustom epa-keys-select-method 'buffer + "Method used to select keys in `epa-select-keys'. +If the value is \\='buffer, the default, keys are selected via a +pop-up buffer. If the value is \\='minibuffer, keys are selected +via the minibuffer instead, using `completing-read-multiple'." + :type '(choice (const :tag "Read keys from a pop-up buffer" buffer) + (const :tag "Read keys from minibuffer" minibuffer)) + :group 'epa + :version "30.1") + ;;; Faces (defgroup epa-faces nil @@ -450,6 +460,25 @@ q trust status questionable. - trust status unspecified. (epa--marked-keys)) (kill-buffer epa-keys-buffer))))) +(defun epa--select-keys-in-minibuffer (prompt keys) + (let* ((prompt (pcase-let ((`(,first ,second ,third) + (string-split prompt "\\.")) + (hint "(separated by comma)")) + (if third + (format "%s %s. %s: " first hint second) + (format "%s %s: " first hint)))) + (keys-alist + (seq-map + (lambda (key) + (cons (substring-no-properties + (epa--button-key-text key)) + key)) + keys)) + (selected-keys (completing-read-multiple prompt keys-alist))) + (seq-map + (lambda (key) (cdr (assoc key keys-alist))) + selected-keys))) + ;;;###autoload (defun epa-select-keys (context prompt &optional names secret) "Display a user's keyring and ask him to select keys. @@ -459,7 +488,9 @@ 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 names secret))) - (epa--select-keys prompt keys))) + (pcase epa-keys-select-method + ('minibuffer (epa--select-keys-in-minibuffer prompt keys)) + (_ (epa--select-keys prompt keys))))) ;;;; Key Details |