Subject: bug#21947: 24.5; epa: option for always replace encrypted text without asking

From: Christian Schwarzgruber <[email-masked]>
Date: Wed, 18 Nov 2015 22:39:43 +0100

I made all the changes, hope I did it the way you guys want it (see inline patch).

I tested all possible options, with `epa-decrypt-region', as well as
epa-verify-region.

Daiki Ueno <[email-masked]> writes:

> Christian Schwarzgruber <[email-masked]> writes:
>
>> When I get a new encrypted email and I hit `C-c C-e d' (epa-mail-decrypt) epa
>> asks, if I want replace the original text. Which in my opinion is a bit
>> superfluous in this case. This will become especially unpleasant once the
>> auto-decrypt functionality is implemented in mu/mu4e.
>
> That sounds reasonable.
>
>> So I patched epa.el and added a boolean `defcustom', when set to `t',
>> the text will always be replaced without asking.
>
> I tend to make this a choice of three: never (nil), ask (a symbol),
> always (t).  Would that make sense?
>
> Also please adjust `epa-verify-region' as well.
>
> Regards,

Regards,
--
Christian Schwarzgruber
>From 9041f5bbe05cbf28dafdfb31f6f731e9ea7e023c Mon Sep 17 00:00:00 2001
From: Christian Schwarzgruber <[email-masked]>
Date: Sun, 15 Nov 2015 22:31:41 +0100
Subject: [PATCH] lisp/epa.el: add `defcustom' to replace original text

Possible options are: `ask', `always', `never'. Default is `ask'.
---
 lisp/epa.el | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/lisp/epa.el b/lisp/epa.el
index 9f112c4..794fa5f 100644
--- a/lisp/epa.el
+++ b/lisp/epa.el
@@ -34,6 +34,15 @@ epa
   :link '(custom-manual "(epa) Top")
   :group 'epg)
 
+(defcustom epa-replace-original-text 'ask
+  "Whether the original text shall be replaced by the decrypted.
+
+Possible options are: `never', `ask' and `always'."
+  :type '(choice (const :tag "never" nil)
+		 (const ask)
+		 (const :tag "always" t))
+  :group 'epa)
+
 (defcustom epa-popup-info-window t
   "If non-nil, display status information from epa commands in another window."
   :type 'boolean
@@ -872,7 +881,11 @@ epa-decrypt-region
 	  (with-current-buffer (funcall make-buffer-function)
 	    (let ((inhibit-read-only t))
 	      (insert plain)))
-	(if (y-or-n-p "Replace the original text? ")
+	(if (cond
+	     ((eq 'ask epa-replace-original-text)
+	      (y-or-n-p "Replace the original text? "))
+	     ((null epa-replace-original-text) nil)
+	     (t t))
 	    (let ((inhibit-read-only t))
 	      (delete-region start end)
 	      (goto-char start)
@@ -968,7 +981,11 @@ epa-verify-region
 		 (or coding-system-for-read
 		     (get-text-property start 'epa-coding-system-used)
 		     'undecided)))
-    (if (y-or-n-p "Replace the original text? ")
+    (if (cond
+	 ((eq 'ask epa-replace-original-text)
+	  (y-or-n-p "Replace the original text? "))
+	 ((null epa-replace-original-text) nil)
+	 (t t))
 	(let ((inhibit-read-only t)
 	      buffer-read-only)
 	  (delete-region start end)
-- 
2.5.0