unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#69133: [PATCH] Make key selection method configurable in EPA.
@ 2024-02-14 19:47 Aleksandr Vityazev via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-02-15  6:07 ` Eli Zaretskii
  0 siblings, 1 reply; 4+ messages in thread
From: Aleksandr Vityazev via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-02-14 19:47 UTC (permalink / raw)
  To: 69133

[-- Attachment #1: Type: text/plain, Size: 234 bytes --]

Tags: patch


Hi,

Currently in epa.el it is possible to select keys only through a
separate buffer, I think adding the option to select via minibuffer
would be a nice addition. The current behavior is set to default. Any
comments?



[-- Attachment #2: 0001-Make-key-selection-method-configurable-in-EPA.patch --]
[-- Type: text/patch, Size: 3172 bytes --]

From 95e277514bc7b92858b92dacca66683dd31e6da2 Mon Sep 17 00:00:00 2001
Message-ID: <95e277514bc7b92858b92dacca66683dd31e6da2.1707939800.git.avityazev@disroot.org>
From: Aleksandr Vityazev <avityazev@disroot.org>
Date: Wed, 14 Feb 2024 22:43:04 +0300
Subject: [PATCH] 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: Document it.
---
 etc/NEWS    |  8 ++++++++
 lisp/epa.el | 30 +++++++++++++++++++++++++++++-
 2 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/etc/NEWS b/etc/NEWS
index e6b1d424499..6cd7c82b69f 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1352,6 +1352,14 @@ characters, such as ½ (U+00BD VULGAR FRACTION ONE HALF), are also
 recognized as rational fractions.  They have been since 2004, but it
 looks like it was never mentioned in the NEWS, or even the manual.

+** EasyPG
+
+---
+*** New user option 'epa-keys-select-method'
+This allows the user to customize the key selection method, a minibuffer
+or buffer option is available, which is set by default and was used in
+all earlier versions.
+
 \f
 * New Modes and Packages in Emacs 30.1

diff --git a/lisp/epa.el b/lisp/epa.el
index 53da3bf6cce..f78866c6eef 100644
--- a/lisp/epa.el
+++ b/lisp/epa.el
@@ -73,6 +73,18 @@ epa-mail-aliases
   :group 'epa
   :version "24.4")

+(defcustom epa-keys-select-method 'buffer
+  "Method used to select keys.
+It can have two values: buffer or minibuffer.
+Can have two values: buffer or minibuffer.  In the first case, the keys
+can be selected via a pop-up buffer. In the second case, the keys
+can be selected via a minibuffer and `completing-read-multiple' will be
+used."
+  :type '(choice (const :tag "Read keys from buffer" buffer)
+		 (const :tag "Read keys from minibuffer" minibuffer))
+  :group 'epa
+  :version "30.1")
+
 ;;; Faces

 (defgroup epa-faces nil
@@ -450,6 +462,19 @@ epa--select-keys
 	    (epa--marked-keys))
         (kill-buffer epa-keys-buffer)))))

+(defun epa--select-keys-in-minibuffer (prompt keys)
+  (let* ((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 +484,10 @@ epa-select-keys
 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
+      ('buffer (epa--select-keys prompt keys))
+      ('minibuffer (epa--select-keys-in-minibuffer prompt keys))
+      (_ (error "Wrong method for key selection is specified")))))

 ;;;; Key Details

--
2.41.0

[-- Attachment #3: Type: text/plain, Size: 38 bytes --]


-- 
Best regards,
Aleksandr Vityazev

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* bug#69133: [PATCH] Make key selection method configurable in EPA.
  2024-02-14 19:47 bug#69133: [PATCH] Make key selection method configurable in EPA Aleksandr Vityazev via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-02-15  6:07 ` Eli Zaretskii
  2024-02-15 20:22   ` Aleksandr Vityazev via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 4+ messages in thread
From: Eli Zaretskii @ 2024-02-15  6:07 UTC (permalink / raw)
  To: Aleksandr Vityazev; +Cc: 69133

> Date: Wed, 14 Feb 2024 22:47:08 +0300
> From:  Aleksandr Vityazev via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
> 
> Currently in epa.el it is possible to select keys only through a
> separate buffer, I think adding the option to select via minibuffer
> would be a nice addition. The current behavior is set to default. Any
> comments?

Thanks, some comments below,

> --- a/etc/NEWS
> +++ b/etc/NEWS
> @@ -1352,6 +1352,14 @@ characters, such as ½ (U+00BD VULGAR FRACTION ONE HALF), are also
>  recognized as rational fractions.  They have been since 2004, but it
>  looks like it was never mentioned in the NEWS, or even the manual.
> 
> +** EasyPG
> +
> +---
> +*** New user option 'epa-keys-select-method'

Heading lines in NEWS should end with a period.

> +This allows the user to customize the key selection method, a minibuffer
> +or buffer option is available, which is set by default and was used in
> +all earlier versions.

This sentence is too complex.  Suggest to reword as two sentences:

  This allows the user to customize the key selection method, which
  can be either by using a pop-up buffer or from the minibuffer.  The
  pop-up buffer method is the default, which preserves previous
  behavior.

Also, why did you decide not to document this in the manual?  epa.el
has its own manual, so how about adding this option to it?

> +(defcustom epa-keys-select-method 'buffer
> +  "Method used to select keys.
> +It can have two values: buffer or minibuffer.
> +Can have two values: buffer or minibuffer.  In the first case, the keys
> +can be selected via a pop-up buffer. In the second case, the keys
> +can be selected via a minibuffer and `completing-read-multiple' will be
> +used."

The doc string could also be simplified.  Like this, for example:

    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'.

This avoids explaining the values twice (first what they are, then
what they do), and also mentions the default value.

Please also make sure comments, doc strings, and commit log messages
leave two spaces between sentences, per our conventions.  You had a
couple of problems with that in the patch, which my suggested
rephrasing fixed, but please keep this in mind in the future.

> +  :type '(choice (const :tag "Read keys from buffer" buffer)
                                 ^^^^^^^^^^^^^^^^^^^^^
This should probably say "...from a pop-up buffer".

>  (defun epa-select-keys (context prompt &optional names secret)
>    "Display a user's keyring and ask him to select keys.
> @@ -459,7 +484,10 @@ epa-select-keys
>  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
> +      ('buffer (epa--select-keys prompt keys))
> +      ('minibuffer (epa--select-keys-in-minibuffer prompt keys))
> +      (_ (error "Wrong method for key selection is specified")))))

Hmm... are you assuming users know how to input multiple strings from
the minibuffer, in particular what is the value of crm-separator?  the
function epa--select-keys inserts some instructions into the pop-up
buffer, but this new function you propose just shows the prompt and
nothing else.  Should it somehow help the user with the job of typing
the keys at the prompt?

Also, maybe instead of signaling an error for a value that's neither
'buffer' nor 'minibuffer', we should treat such values as 'buffer'?





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#69133: [PATCH] Make key selection method configurable in EPA.
  2024-02-15  6:07 ` Eli Zaretskii
@ 2024-02-15 20:22   ` Aleksandr Vityazev via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-02-17  9:32     ` Eli Zaretskii
  0 siblings, 1 reply; 4+ messages in thread
From: Aleksandr Vityazev via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-02-15 20:22 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 69133

[-- Attachment #1: Type: text/plain, Size: 4215 bytes --]



Thanks, added the fixes, attached the version 2 patch

On 2024-02-15 08:07, Eli Zaretskii wrote:

>> Date: Wed, 14 Feb 2024 22:47:08 +0300
>> From:  Aleksandr Vityazev via "Bug reports for GNU Emacs,
>>  the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
>> 
>> Currently in epa.el it is possible to select keys only through a
>> separate buffer, I think adding the option to select via minibuffer
>> would be a nice addition. The current behavior is set to default. Any
>> comments?
>
> Thanks, some comments below,
>
>> --- a/etc/NEWS
>> +++ b/etc/NEWS
>> @@ -1352,6 +1352,14 @@ characters, such as ½ (U+00BD VULGAR FRACTION ONE HALF), are also
>>  recognized as rational fractions.  They have been since 2004, but it
>>  looks like it was never mentioned in the NEWS, or even the manual.
>> 
>> +** EasyPG
>> +
>> +---
>> +*** New user option 'epa-keys-select-method'
>
> Heading lines in NEWS should end with a period.
>

Fixed

>> +This allows the user to customize the key selection method, a minibuffer
>> +or buffer option is available, which is set by default and was used in
>> +all earlier versions.
>
> This sentence is too complex.  Suggest to reword as two sentences:
>
>   This allows the user to customize the key selection method, which
>   can be either by using a pop-up buffer or from the minibuffer.  The
>   pop-up buffer method is the default, which preserves previous
>   behavior.
>

Applied

> Also, why did you decide not to document this in the manual?  epa.el
> has its own manual, so how about adding this option to it?

Added

>
>> +(defcustom epa-keys-select-method 'buffer
>> +  "Method used to select keys.
>> +It can have two values: buffer or minibuffer.
>> +Can have two values: buffer or minibuffer.  In the first case, the keys
>> +can be selected via a pop-up buffer. In the second case, the keys
>> +can be selected via a minibuffer and `completing-read-multiple' will be
>> +used."
>
> The doc string could also be simplified.  Like this, for example:
>
>     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'.
>
Applied

> This avoids explaining the values twice (first what they are, then
> what they do), and also mentions the default value.
>
> Please also make sure comments, doc strings, and commit log messages
> leave two spaces between sentences, per our conventions.  You had a
> couple of problems with that in the patch, which my suggested
> rephrasing fixed, but please keep this in mind in the future.
>
>> +  :type '(choice (const :tag "Read keys from buffer" buffer)
>                                  ^^^^^^^^^^^^^^^^^^^^^
> This should probably say "...from a pop-up buffer".

Fixed
>
>>  (defun epa-select-keys (context prompt &optional names secret)
>>    "Display a user's keyring and ask him to select keys.
>> @@ -459,7 +484,10 @@ epa-select-keys
>>  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
>> +      ('buffer (epa--select-keys prompt keys))
>> +      ('minibuffer (epa--select-keys-in-minibuffer prompt keys))
>> +      (_ (error "Wrong method for key selection is specified")))))
>


> Hmm... are you assuming users know how to input multiple strings from
> the minibuffer, in particular what is the value of crm-separator?  the
> function epa--select-keys inserts some instructions into the pop-up
> buffer, but this new function you propose just shows the prompt and
> nothing else.  Should it somehow help the user with the job of typing
> the keys at the prompt?

The crm-separator is "[ \t]*,[ \t]*", so I added a "(comma separated)"
hint that will be in all prompts.

>
> Also, maybe instead of signaling an error for a value that's neither
> 'buffer' nor 'minibuffer', we should treat such values as 'buffer'?

Agree, fixed


[-- Attachment #2: patch-v2 --]
[-- Type: text/x-patch, Size: 4160 bytes --]

From 479c4ca5c8c97b5b9a8b64a0ba7fdbdc0f5ae299 Mon Sep 17 00:00:00 2001
Message-ID: <479c4ca5c8c97b5b9a8b64a0ba7fdbdc0f5ae299.1708026698.git.avityazev@disroot.org>
From: Aleksandr Vityazev <avityazev@disroot.org>
Date: Thu, 15 Feb 2024 22:51:24 +0300
Subject: [PATCH] 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.
---
 doc/misc/epa.texi |  7 +++++++
 etc/NEWS          |  8 ++++++++
 lisp/epa.el       | 33 ++++++++++++++++++++++++++++++++-
 3 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/doc/misc/epa.texi b/doc/misc/epa.texi
index 27a9e2b0ebb..cd6da1dadba 100644
--- a/doc/misc/epa.texi
+++ b/doc/misc/epa.texi
@@ -289,6 +289,13 @@ Cryptographic operations on regions
 you answered yes, it will let you select the signing keys.
 @end deffn

+You can change the default method that is used to select keys with the
+variable @code{epa-file-select-keys}.
+
+@defvar epa-keys-select-method
+Method used to select keys in @code{epa-select-keys}.
+@end defvar
+
 @node Cryptographic operations on files
 @section Cryptographic Operations on Files
 @cindex cryptographic operations on files
diff --git a/etc/NEWS b/etc/NEWS
index e6b1d424499..ba609680c24 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1352,6 +1352,14 @@ characters, such as ½ (U+00BD VULGAR FRACTION ONE HALF), are also
 recognized as rational fractions.  They have been since 2004, but it
 looks like it was never mentioned in the NEWS, or even the manual.

+** EasyPG
+
++++
+*** New user option 'epa-keys-select-method'.
+This allows the user to customize the key selection method, which can be
+either by using a pop-up buffer or from the minibuffer.  The pop-up
+buffer method is the default, which preserves previous behavior.
+
 \f
 * New Modes and Packages in Emacs 30.1

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 @@ epa-mail-aliases
   :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 @@ epa--select-keys
 	    (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,6 +488,8 @@ epa-select-keys
 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


--
2.41.0

[-- Attachment #3: Type: text/plain, Size: 37 bytes --]

-- 
Best regards,
Aleksandr Vityazev

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* bug#69133: [PATCH] Make key selection method configurable in EPA.
  2024-02-15 20:22   ` Aleksandr Vityazev via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-02-17  9:32     ` Eli Zaretskii
  0 siblings, 0 replies; 4+ messages in thread
From: Eli Zaretskii @ 2024-02-17  9:32 UTC (permalink / raw)
  To: Aleksandr Vityazev; +Cc: 69133-done

> From: Aleksandr Vityazev <avityazev@disroot.org>
> Cc: 69133@debbugs.gnu.org
> Date: Thu, 15 Feb 2024 23:22:29 +0300
> 
> Thanks, added the fixes, attached the version 2 patch

Thanks, installed on master, and closing the bug.





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-02-17  9:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-14 19:47 bug#69133: [PATCH] Make key selection method configurable in EPA Aleksandr Vityazev via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-02-15  6:07 ` Eli Zaretskii
2024-02-15 20:22   ` Aleksandr Vityazev via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-02-17  9:32     ` Eli Zaretskii

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).